diff --git a/install/games/darkmod.game b/install/games/darkmod.game index 71bf5bc12e..e8768a641f 100644 --- a/install/games/darkmod.game +++ b/install/games/darkmod.game @@ -1,7 +1,7 @@ - + diff --git a/radiant/settings/GameManager.cpp b/radiant/settings/GameManager.cpp index 505903243a..114a84703b 100644 --- a/radiant/settings/GameManager.cpp +++ b/radiant/settings/GameManager.cpp @@ -12,6 +12,7 @@ #include "os/dir.h" #include "os/path.h" #include "os/fs.h" +#include "string/convert.h" #include "GameFileLoader.h" #include "wxutil/dialog/MessageBox.h" @@ -97,10 +98,12 @@ void Manager::constructPreferences() IPreferencePage& page = GetPreferenceSystem().getPage(_("Game")); ComboBoxValueList gameList; - for (GameMap::iterator i = _games.begin(); i != _games.end(); ++i) + + for (const GamePtr& game : _sortedGames) { - gameList.push_back(i->second->getKeyValue("name")); + gameList.push_back(game->getKeyValue("name")); } + page.appendCombo(_("Select a Game:"), RKEY_GAME_TYPE, gameList, true); page.appendPathEntry(_("Engine Path"), RKEY_ENGINE_PATH, true); page.appendEntry(_("Mod (fs_game)"), RKEY_FS_GAME); @@ -111,20 +114,21 @@ void Manager::initialise(const std::string& appPath) { // Scan the /games folder for .game files loadGameFiles(appPath); - if (_games.empty()) - { - // No game types available, bail out, the program would crash anyway on - // module load - wxutil::Messagebox::ShowFatalError( - _("GameManager: No valid game files found, can't continue."), NULL - ); - } + + if (_games.empty()) + { + // No game types available, bail out, the program would crash anyway on + // module load + wxutil::Messagebox::ShowFatalError( + _("GameManager: No valid game files found, can't continue."), NULL + ); + } // Add the settings widgets to the Preference Dialog, we might need it constructPreferences(); // Find the user's selected game from the XML registry, and attempt to find - // it in the set of available games. + // it in the set of available games. std::string gameType = GlobalRegistry().get(RKEY_GAME_TYPE); GameMap::iterator i = _games.find(gameType); @@ -132,7 +136,16 @@ void Manager::initialise(const std::string& appPath) { // We have at least one game type available, select the first // Store the name of the only game into the Registry - GlobalRegistry().set(RKEY_GAME_TYPE, _games.begin()->first); + rMessage() << "No game selected, will choose the highest ranked one." << std::endl; + + if (_sortedGames.empty()) + { + wxutil::Messagebox::ShowFatalError( + "GameManager: Sorted game list is empty, can't continue.", nullptr + ); + } + + GlobalRegistry().set(RKEY_GAME_TYPE, _sortedGames.front()->getName()); } // Load the value from the registry, there should be one selected at this point @@ -547,11 +560,29 @@ void Manager::loadGameFiles(const std::string& appPath) os::foreachItemInDirectory(gamePath, gameFileLoader); rMessage() << "GameManager: Found game definitions: " << std::endl; - for (GameMap::iterator i = _games.begin(); i != _games.end(); ++i) + + for (GameMap::value_type& pair : _games) { - rMessage() << " " << i->first << std::endl; + rMessage() << " " << pair.first << std::endl; } + // Populate the sorted games list + _sortedGames.clear(); + + // Sort the games by their index + std::multimap sortedGameMap; + + for (const GameMap::value_type& pair : _games) + { + int index = string::convert(pair.second->getKeyValue("index"), 9999); + sortedGameMap.insert(std::make_pair(index, pair.second)); + } + + for (const auto& pair : sortedGameMap) + { + _sortedGames.push_back(pair.second); + } + rMessage() << std::endl; } catch (os::DirectoryNotFoundException&) diff --git a/radiant/settings/GameManager.h b/radiant/settings/GameManager.h index cdfc83a66b..0fd12bf86f 100644 --- a/radiant/settings/GameManager.h +++ b/radiant/settings/GameManager.h @@ -1,5 +1,4 @@ -#ifndef GAMEMANAGER_H_ -#define GAMEMANAGER_H_ +#pragma once #include #include @@ -21,10 +20,15 @@ class Manager : public IGameManager // The map containing the named Game objects typedef std::map GameMap; + // A map sorted by game index, for display order and priority + typedef std::vector SortedGames; + private: // Map of named games GameMap _games; + // Map of indexed games + SortedGames _sortedGames; // The name of the current game, e.g. "Doom 3" std::string _currentGameName; @@ -146,5 +150,3 @@ class Manager : public IGameManager }; } // namespace game - -#endif /*GAMEMANAGER_H_*/