From 488d18534a90982a2d0c9dfb482831f672265262 Mon Sep 17 00:00:00 2001 From: Martin Schweiger Date: Thu, 21 Jul 2022 03:08:58 +0100 Subject: [PATCH] #192: Scenario editor: save page offers choice between default current state page and custom description. --- Src/Orbiter/Orbiter.cpp | 9 ++++-- Src/Orbiter/State.cpp | 20 +++++++------ Src/Orbiter/State.h | 5 ++-- Src/Plugin/ScnEditor/Editor.cpp | 18 ++++++++++-- Src/Plugin/ScnEditor/ScnEditor.rc | 49 ++++++++++++++++++++++--------- 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/Src/Orbiter/Orbiter.cpp b/Src/Orbiter/Orbiter.cpp index 0983ec370..d8296924e 100644 --- a/Src/Orbiter/Orbiter.cpp +++ b/Src/Orbiter/Orbiter.cpp @@ -1455,13 +1455,18 @@ VOID Orbiter::IncFOV (double dfov) //----------------------------------------------------------------------------- bool Orbiter::SaveScenario (const char *fname, const char *desc) { - pState->Update (desc); + pState->Update (); ofstream ofs (ScnPath (fname)); if (ofs) { // save scenario state - pState->Write (ofs, pConfig->CfgDebugPrm.bSaveExitScreen ? "CurrentState_img" : "CurrentState"); + if (desc) { + pState->Write(ofs, desc, 0); + } + else { + pState->Write(ofs, 0, pConfig->CfgDebugPrm.bSaveExitScreen ? "CurrentState_img" : "CurrentState"); + } g_camera->Write (ofs); if (g_pane) g_pane->Write (ofs); g_psys->Write (ofs); diff --git a/Src/Orbiter/State.cpp b/Src/Orbiter/State.cpp index 602728282..a161e120d 100644 --- a/Src/Orbiter/State.cpp +++ b/Src/Orbiter/State.cpp @@ -28,7 +28,6 @@ extern TimeData td; State::State () { - desc = 0; mjd = mjd0 = MJD (time (NULL)); // default to current system time strcpy (solsys, "Sol"); // default name memset (scenario, 0, 256); @@ -38,9 +37,8 @@ State::State () memset (playback, 0, 128); } -void State::Update (const char *_desc) +void State::Update () { - desc = _desc; mjd = td.MJD1; strcpy (focus, g_focusobj->Name()); } @@ -106,13 +104,15 @@ bool State::Read (const char *fname) return true; } -void State::Write (ostream &ofs, const char *help) const +void State::Write (ostream &ofs, const char *desc, const char *help) const { ofs.setf (ios::fixed, ios::floatfield); ofs.precision (10); // need very high precision MJD output if (desc) { ofs << "BEGIN_DESC" << endl; - ofs << desc << endl; // need to break lines + for (const char* c = desc; *c; c++) + if (*c != '\r') ofs << *c; // DOS madness! Get rid of CR so output stream can add it again ... + ofs << endl; ofs << "END_DESC" << endl << endl; } ofs << "BEGIN_ENVIRONMENT" << endl; @@ -122,10 +122,12 @@ void State::Write (ostream &ofs, const char *help) const ofs << " Context " << context << endl; if (script[0]) ofs << " Script " << script << endl; - if (scnhelp[0]) - ofs << " Help " << scnhelp << endl; - else if (help) - ofs << " Help " << help << endl; + if (!desc) { + if (scnhelp[0]) + ofs << " Help " << scnhelp << endl; + else if (help) + ofs << " Help " << help << endl; + } if (playback[0]) ofs << " Playback " << playback << endl; ofs << "END_ENVIRONMENT" << endl << endl; diff --git a/Src/Orbiter/State.h b/Src/Orbiter/State.h index 296fc9ae2..352a016ba 100644 --- a/Src/Orbiter/State.h +++ b/Src/Orbiter/State.h @@ -23,9 +23,9 @@ class State { const char *Focus() const { return focus; } const char *ScnHelp() const { return (scnhelp[0] ? scnhelp : 0); } const char *PlaybackDir() const { return (playback[0] ? playback : scenario); } - void Update (const char *_desc = 0); + void Update (); bool Read (const char *fname); - void Write (std::ostream &ofs, const char *help) const; + void Write (std::ostream &ofs, const char *desc, const char *help) const; // load/save scenario state private: @@ -38,7 +38,6 @@ class State { char focus[64]; // current focus vessel char scnhelp[128]; // scenario help file char playback[128]; // playback folder name, if applicable - const char *desc; }; diff --git a/Src/Plugin/ScnEditor/Editor.cpp b/Src/Plugin/ScnEditor/Editor.cpp index 078b7fa52..0c05ef73e 100644 --- a/Src/Plugin/ScnEditor/Editor.cpp +++ b/Src/Plugin/ScnEditor/Editor.cpp @@ -161,8 +161,12 @@ bool ScnEditor::SaveScenario (HWND hDlg) { char fname[256], desc[4096]; GetWindowText (GetDlgItem (hDlg, IDC_EDIT1), fname, 256); - GetWindowText (GetDlgItem (hDlg, IDC_EDIT2), desc, 4096); - return oapiSaveScenario (fname, desc); + if (SendDlgItemMessage(hDlg, IDC_RADIO1, BM_GETCHECK, 0, 0) == BST_CHECKED) { + return oapiSaveScenario(fname, 0); + } else { + GetWindowText(GetDlgItem(hDlg, IDC_EDIT2), desc, 4096); + return oapiSaveScenario(fname, desc); + } } void ScnEditor::InitDialog (HWND _hDlg) @@ -872,6 +876,8 @@ INT_PTR EditorTab_New::DlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar EditorTab_Save::EditorTab_Save (ScnEditor *editor) : ScnEditorTab (editor) { CreateTab (IDD_TAB_SAVE, EditorTab_Save::DlgProc); + SendDlgItemMessage(hTab, IDC_RADIO1, BM_SETCHECK, BST_CHECKED, 0); + SendDlgItemMessage(hTab, IDC_RADIO2, BM_SETCHECK, BST_UNCHECKED, 0); } char *EditorTab_Save::HelpTopic () @@ -884,6 +890,14 @@ INT_PTR EditorTab_Save::TabProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPa switch (uMsg) { case WM_COMMAND: switch (LOWORD (wParam)) { + case IDC_RADIO1: + if (HIWORD(wParam) == BN_CLICKED) + EnableWindow(GetDlgItem(hTab, IDC_EDIT2), FALSE); + return TRUE; + case IDC_RADIO2: + if (HIWORD(wParam) == BN_CLICKED) + EnableWindow(GetDlgItem(hTab, IDC_EDIT2), TRUE); + return TRUE; case IDC_BACK: SwitchTab (0); return TRUE; diff --git a/Src/Plugin/ScnEditor/ScnEditor.rc b/Src/Plugin/ScnEditor/ScnEditor.rc index 694ca190f..843182604 100644 --- a/Src/Plugin/ScnEditor/ScnEditor.rc +++ b/Src/Plugin/ScnEditor/ScnEditor.rc @@ -1,6 +1,3 @@ -// Copyright (c) Martin Schweiger -// Licensed under the MIT License - // Microsoft Visual C++ generated resource script. // #include "resource.h" @@ -16,13 +13,11 @@ #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// -// English (U.K.) resources +// English (United Kingdom) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) -#ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK #pragma code_page(1252) -#endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // @@ -257,12 +252,14 @@ FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN PUSHBUTTON "Cancel",IDC_BACK,52,221,50,14 GROUPBOX "",IDC_STATIC,-2,213,267,29 - LTEXT "Scenario file name:",IDC_STATIC,0,0,61,8 - EDITTEXT IDC_EDIT1,0,11,263,14,ES_AUTOHSCROLL - LTEXT "Description:",IDC_STATIC,0,35,38,8 - EDITTEXT IDC_EDIT2,0,46,263,167,ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL + EDITTEXT IDC_EDIT1,10,12,246,14,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT2,18,79,238,127,ES_MULTILINE | ES_WANTRETURN | WS_DISABLED | WS_VSCROLL PUSHBUTTON "Save",IDOK,0,221,50,14 PUSHBUTTON "Help",IDHELP,213,221,50,14 + GROUPBOX "Scenario file name",IDC_STATIC,0,0,263,33 + GROUPBOX "Description",IDC_STATIC,0,38,263,175 + CONTROL "Default ""Current state"" page",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,9,51,105,10 + CONTROL "Custom text:",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,9,65,55,10 END IDD_TAB_EDIT5 DIALOGEX 2, 2, 263, 235 @@ -446,7 +443,7 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO +GUIDELINES DESIGNINFO BEGIN IDD_EDITOR, DIALOG BEGIN @@ -455,6 +452,14 @@ BEGIN TOPMARGIN, 2 BOTTOMMARGIN, 237 END + + IDD_TAB_SAVE, DIALOG + BEGIN + END + + IDD_TAB_DATE, DIALOG + BEGIN + END END #endif // APSTUDIO_INVOKED @@ -491,17 +496,33 @@ END // IDB_PAUSE BITMAP "Bitmaps\\pause.bmp" + IDB_TREEICON_FOLDER1 BITMAP "Bitmaps\\Folder1.bmp" + IDB_TREEICON_FOLDER2 BITMAP "Bitmaps\\Folder2.bmp" + IDB_TREEICON_FILE1 BITMAP "Bitmaps\\File1.bmp" + IDB_TREEICON_FILE2 BITMAP "Bitmaps\\File2.bmp" + +///////////////////////////////////////////////////////////////////////////// +// +// AFX_DIALOG_LAYOUT +// + +IDD_TAB_SAVE AFX_DIALOG_LAYOUT +BEGIN + 0 +END + + ///////////////////////////////////////////////////////////////////////////// // // String Table // -STRINGTABLE +STRINGTABLE BEGIN IDS_ERR1 "Selected dock is already in use." IDS_ERR2 "Selected dock on target vessel is already in use." @@ -513,13 +534,13 @@ BEGIN IDS_PROP4 "Destroy vessel" END -STRINGTABLE +STRINGTABLE BEGIN IDS_INFO "SCENARIO EDITOR:\r\n\r\nCreate and delete spacecraft during the simulation - Edit position, orientation, orbital elements, surface location, fuel status and docking connections - Reset the simulation time.\r\n\r\nThe scenario editor can be opened by selecting the ""Scenario editor"" entry in the Custom Functions dialog (Ctrl-F4)." IDS_TYPE "Tools and dialogs" END -#endif // English (U.K.) resources +#endif // English (United Kingdom) resources /////////////////////////////////////////////////////////////////////////////