Skip to content

Commit

Permalink
#192: Scenario editor: save page offers choice between default curren…
Browse files Browse the repository at this point in the history
…t state page and custom description.
  • Loading branch information
mschweiger committed Jul 21, 2022
1 parent bc229e3 commit 488d185
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
9 changes: 7 additions & 2 deletions Src/Orbiter/Orbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 11 additions & 9 deletions Src/Orbiter/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions Src/Orbiter/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;

};

Expand Down
18 changes: 16 additions & 2 deletions Src/Plugin/ScnEditor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ()
Expand All @@ -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;
Expand Down
49 changes: 35 additions & 14 deletions Src/Plugin/ScnEditor/ScnEditor.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Martin Schweiger
// Licensed under the MIT License

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
Expand All @@ -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

/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -446,7 +443,7 @@ END
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
GUIDELINES DESIGNINFO
BEGIN
IDD_EDITOR, DIALOG
BEGIN
Expand All @@ -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

Expand Down Expand Up @@ -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."
Expand All @@ -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
/////////////////////////////////////////////////////////////////////////////


Expand Down

0 comments on commit 488d185

Please sign in to comment.