Skip to content

Commit

Permalink
Games are listed sorted by their index in the .game file now
Browse files Browse the repository at this point in the history
Select the TDM 2.0 game by default, with the fs_game set to empty
  • Loading branch information
codereader committed Jul 8, 2017
1 parent 5d4b8d8 commit 3c8ec7a
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 25 deletions.
2 changes: 1 addition & 1 deletion install/games/darkmod.game
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<game
type="doom3"
index="99"
index="10"
name="The Dark Mod 2.0 (Standalone)"
enginepath_win32="C:/games/darkmod/"
enginepath_linux="/usr/local/games/darkmod/"
Expand Down
2 changes: 1 addition & 1 deletion install/games/doom3-demo.game
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<game
index="99"
index="16"
name="Doom 3 Demo"
enginepath_win32="C:/games/doom3/"
enginepath_linux="/usr/local/games/doom3-demo/"
Expand Down
2 changes: 1 addition & 1 deletion install/games/doom3.game
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<game
type="doom3"
index="99"
index="15"
name="Doom 3"
enginepath_win32="C:/games/doom3/"
enginepath_linux="/usr/local/games/doom3/"
Expand Down
2 changes: 1 addition & 1 deletion install/games/quake3.game
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<game
type="quake3"
index="99"
index="20"
name="Quake 3"
enginepath_win32="C:/games/quake3/"
enginepath_linux="/usr/local/games/quake3/"
Expand Down
2 changes: 1 addition & 1 deletion install/games/quake4.game
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<game
type="quake4"
index="99"
index="25"
name="Quake 4"
enginepath_win32="C:/games/quake4/"
enginepath_linux="/usr/local/games/quake4/"
Expand Down
2 changes: 1 addition & 1 deletion install/games/xreal.game
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<game
type="doom3"
index="99"
index="30"
name="XreaL"
enginepath_win32="C:/games/XreaL/"
enginepath_linux="/usr/local/games/xreal/"
Expand Down
2 changes: 1 addition & 1 deletion install/user.xml
Expand Up @@ -5,7 +5,7 @@
<debug value="0" />
<game>
<type value="" />
<fs_game value="darkmod" />
<fs_game value="" />
</game>
<ui>
<commandsystem>
Expand Down
59 changes: 45 additions & 14 deletions radiant/settings/GameManager.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -111,28 +114,38 @@ void Manager::initialise(const std::string& appPath)
{
// Scan the <applicationpath>/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);

if (gameType.empty() || i == _games.end())
{
// 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
Expand Down Expand Up @@ -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<int, GamePtr> sortedGameMap;

for (const GameMap::value_type& pair : _games)
{
int index = string::convert<int>(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&)
Expand Down
10 changes: 6 additions & 4 deletions radiant/settings/GameManager.h
@@ -1,5 +1,4 @@
#ifndef GAMEMANAGER_H_
#define GAMEMANAGER_H_
#pragma once

#include <string>
#include <map>
Expand All @@ -21,10 +20,15 @@ class Manager : public IGameManager
// The map containing the named Game objects
typedef std::map<std::string, GamePtr> GameMap;

// A map sorted by game index, for display order and priority
typedef std::vector<GamePtr> 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;
Expand Down Expand Up @@ -146,5 +150,3 @@ class Manager : public IGameManager
};

} // namespace game

#endif /*GAMEMANAGER_H_*/

0 comments on commit 3c8ec7a

Please sign in to comment.