Skip to content

Commit

Permalink
Separate content switching code to func for future
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Sep 18, 2023
1 parent e326942 commit 4c283f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
26 changes: 24 additions & 2 deletions Source/UserInterface/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,25 @@ void onMMInMissQuitButton(CShellWindow* pWnd, InterfaceEventCode code, int param
}
}

//game content

//TODO call this from load/ingame-load/replay menus to enable auto switching (provide initial_menu to current menu ID)
void switchGameContent(GAME_CONTENT selected, const std::string& initial_menu) {
if (selected == terGameContentBase) {
selected = terGameContentAvailable;
}
if (selected == terGameContentSelect) {
//Selected the already selected content, no need to restart
_shellIconManager.SwitchMenuScreens( SQSH_MM_CONTENT_CHOOSER_SCR, SQSH_MM_SINGLE_SCR );
} else {
//Set args and restart
std::vector<std::string> args;
args.emplace_back("tmp_initial_menu=" + initial_menu);
args.emplace_back("tmp_content_select=" + getGameContentEnumName(selected));
request_application_restart(&args);
_shellIconManager.SwitchMenuScreens( SQSH_MM_CONTENT_CHOOSER_SCR, RESTART_GAME );
}
}

//load game
int delLoadSaveAction(float, float) {
Expand All @@ -1884,15 +1903,18 @@ bool setupMissionToExec(int pos) {
return false;
}
checkMissionDescription(pos, savedGames, GT_SINGLE_PLAYER);
missionToExec = savedGames[pos];

MissionDescription& desc = savedGames[pos];

//Check if content is compatible
std::string missingContent = checkMissingContent(missionToExec);
std::string missingContent = checkMissingContent(desc);
if (!missingContent.empty()) {
setupOkMessageBox(nullptr, 0, missingContent, MBOX_BACK);
showMessageBox();
return false;
}

missionToExec = desc;

//Setup according to mission type
if (missionToExec.missionNumber == -1) {
Expand Down
2 changes: 2 additions & 0 deletions Source/UserInterface/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const char* getMapName(const char* keyStr);

void loadMapVector(std::vector<MissionDescription>& mapVector, const std::string& path, const std::string& mask, bool replay = false);

void switchGameContent(GAME_CONTENT selected, const std::string& initial_menu);

void checkMissionDescription(int index, std::vector<MissionDescription>& mVect, GameType gameType);

std::string checkMissingContent(const MissionDescription& mission);
Expand Down
16 changes: 1 addition & 15 deletions Source/UserInterface/Menu/SingleMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,7 @@ void selectedContentChooser() {
int pos = list->GetCurSel();
std::vector<GAME_CONTENT> contents = getGameContentEnums(terGameContentAvailable);
if (0 <= pos && pos < contents.size()) {
GAME_CONTENT selected = contents[pos];
if (selected == terGameContentBase) {
selected = terGameContentAvailable;
}
if (selected == terGameContentSelect) {
//Selected the already selected content, no need to restart
_shellIconManager.SwitchMenuScreens( SQSH_MM_CONTENT_CHOOSER_SCR, SQSH_MM_SINGLE_SCR );
} else {
//Set args and restart
std::vector<std::string> args;
args.emplace_back("tmp_initial_menu=SINGLE");
args.emplace_back(std::string("tmp_content_select=") + getGameContentEnumName(selected));
request_application_restart(&args);
_shellIconManager.SwitchMenuScreens( SQSH_MM_CONTENT_CHOOSER_SCR, RESTART_GAME );
}
switchGameContent(contents[pos], "SINGLE");
}
}

Expand Down

0 comments on commit 4c283f3

Please sign in to comment.