diff options
Diffstat (limited to 'src/setup')
-rw-r--r-- | src/setup/mainmenu.c | 11 | ||||
-rw-r--r-- | src/setup/mode.c | 137 | ||||
-rw-r--r-- | src/setup/mode.h | 3 |
3 files changed, 127 insertions, 24 deletions
diff --git a/src/setup/mainmenu.c b/src/setup/mainmenu.c index 5a5f72fc..90bda7de 100644 --- a/src/setup/mainmenu.c +++ b/src/setup/mainmenu.c @@ -173,7 +173,6 @@ void MainMenu(void) static void InitConfig(void) { - SetupMission(); InitBindings(); SetChatMacroDefaults(); @@ -240,15 +239,19 @@ static void RunGUI(void) TXT_SetDesktopTitle(PACKAGE_NAME " Setup ver " PACKAGE_VERSION); SetIcon(); - - MainMenu(); TXT_GUIMainLoop(); } -void D_DoomMain(void) +static void MissionSet(void) { InitConfig(); + MainMenu(); +} + +void D_DoomMain(void) +{ + SetupMission(MissionSet); RunGUI(); } diff --git a/src/setup/mode.c b/src/setup/mode.c index 4fc1b8b9..d5a396ac 100644 --- a/src/setup/mode.c +++ b/src/setup/mode.c @@ -22,9 +22,11 @@ #include <string.h> #include "config.h" +#include "textscreen.h" #include "doomtype.h" #include "d_mode.h" +#include "d_iwad.h" #include "i_system.h" #include "m_argv.h" #include "m_config.h" @@ -44,19 +46,48 @@ GameMission_t gamemission; typedef struct { + char *label; GameMission_t mission; + int mask; char *name; char *config_file; char *extra_config_file; } mission_config_t; -static mission_config_t config_files[] = +// Default mission to fall back on, if no IWADs are found at all: + +#define DEFAULT_MISSION (&mission_configs[0]) + +static mission_config_t mission_configs[] = { - { doom, "doom", "default.cfg", PROGRAM_PREFIX "doom.cfg" }, - { heretic, "heretic", "heretic.cfg", PROGRAM_PREFIX "heretic.cfg" }, - { hexen, "hexen", "hexen.cfg", PROGRAM_PREFIX "hexen.cfg" }, + { + "Doom", + doom, + IWAD_MASK_DOOM, + "doom", + "default.cfg", + PROGRAM_PREFIX "doom.cfg" + }, + { + "Heretic", + heretic, + IWAD_MASK_HERETIC, + "heretic", + "heretic.cfg", + PROGRAM_PREFIX "heretic.cfg" + }, + { + "Hexen", + hexen, + IWAD_MASK_HEXEN, + "hexen", + "hexen.cfg", + PROGRAM_PREFIX "hexen.cfg" + } }; +static GameSelectCallback game_selected_callback; + // Miscellaneous variables that aren't used in setup. static int showMessages = 1; @@ -123,18 +154,85 @@ static mission_config_t *GetMissionForName(char *name) { int i; - for (i=0; i<arrlen(config_files); ++i) + for (i=0; i<arrlen(mission_configs); ++i) { - if (!strcmp(config_files[i].name, name)) + if (!strcmp(mission_configs[i].name, name)) { - return &config_files[i]; + return &mission_configs[i]; } } return NULL; } -void SetupMission(void) +static void GameSelected(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(config)) +{ + TXT_CAST_ARG(mission_config_t, config); + + SetMission(config); + game_selected_callback(); +} + +static void OpenGameSelectDialog(GameSelectCallback callback) +{ + mission_config_t *mission; + txt_window_t *window; + iwad_t **iwads; + int num_games; + int i; + + window = TXT_NewWindow("Select game"); + + TXT_AddWidget(window, TXT_NewLabel("Select a game to configure:\n")); + num_games = 0; + + // Add a button for each game. + + for (i=0; i<arrlen(mission_configs); ++i) + { + // Do we have any IWADs for this game installed? + // If so, add a button. + + iwads = D_FindAllIWADs(mission_configs[i].mask); + + if (iwads[0] != NULL) + { + mission = &mission_configs[i]; + TXT_AddWidget(window, TXT_NewButton2(mission_configs[i].label, + GameSelected, + &mission_configs[i])); + ++num_games; + } + + free(iwads); + } + + TXT_AddWidget(window, TXT_NewStrut(0, 1)); + + // No IWADs found at all? Fall back to doom, then. + + if (num_games == 0) + { + TXT_CloseWindow(window); + SetMission(DEFAULT_MISSION); + callback(); + return; + } + + // Only one game? Use that game, and don't bother with a dialog. + + if (num_games == 1) + { + TXT_CloseWindow(window); + SetMission(mission); + callback(); + return; + } + + game_selected_callback = callback; +} + +void SetupMission(GameSelectCallback callback) { mission_config_t *config; char *mission_name; @@ -149,22 +247,23 @@ void SetupMission(void) p = M_CheckParm("-game"); - if (p > 0) + if (p > 0) { mission_name = myargv[p + 1]; - } - else - { - mission_name = "doom"; - } - config = GetMissionForName(mission_name); + config = GetMissionForName(mission_name); + + if (config == NULL) + { + I_Error("Invalid parameter - '%s'", mission_name); + } - if (config == NULL) + SetMission(config); + callback(); + } + else { - I_Error("Invalid parameter - '%s'", mission_name); + OpenGameSelectDialog(callback); } - - SetMission(config); } diff --git a/src/setup/mode.h b/src/setup/mode.h index c6d0dc66..a78a5bc2 100644 --- a/src/setup/mode.h +++ b/src/setup/mode.h @@ -24,9 +24,10 @@ #include "d_mode.h" +typedef void (*GameSelectCallback)(void); extern GameMission_t gamemission; -void SetupMission(void); +void SetupMission(GameSelectCallback callback); void InitBindings(void); #endif /* #ifndef SETUP_MODE_H */ |