Skip to content

Commit

Permalink
Pass game to setup page constructor. Some cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 9, 2017
1 parent dfea33d commit f154501
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 123 deletions.
50 changes: 0 additions & 50 deletions radiant/settings/GameManager.cpp
Expand Up @@ -253,34 +253,6 @@ void Manager::constructPaths()
#endif
}

bool Manager::userWantsToCorrectSettings() const
{
#if 0
std::stringstream msg("<b>Warning:</b>\n");

if (!os::fileOrDirExists(_enginePath))
{
msg << fmt::format(_("Engine path \"{0}\" does not exist.\n"), _enginePath);
}

if (!_fsGame.empty() && !os::fileOrDirExists(_modPath))
{
msg << fmt::format(_("The fs_game folder \"{0}\" does not exist.\n"), _modPath);
}

if (!_fsGameBase.empty() && !os::fileOrDirExists(_modBasePath))
{
msg << fmt::format(_("The fs_game_base folder \"{0}\" does not exist.\n"), _modBasePath);
}

msg << _("Do you want to correct these settings?");

return wxutil::Messagebox::Show(_("Invalid Settings"),
msg.str(), ui::IDialog::MESSAGE_ASK, NULL) == ui::IDialog::RESULT_YES;
#endif
return false;
}

void Manager::initEnginePath()
{
// Try to retrieve a saved value for the engine path
Expand Down Expand Up @@ -336,16 +308,6 @@ void Manager::initEnginePath()
// Take this path and store it into the Registry, it's expected to be there
registry::setValue(RKEY_ENGINE_PATH, _enginePath);

#if 0
// Try to do something with the information currently in the Registry
// It should be enough to know the engine path and the fs_game.
constructPaths();
#endif
#if 0
// Check loop, continue, till the user specifies a valid setting
while (!settingsValid())
{
#endif
if (!settingsValid())
{
// Paths not valid, ask the user to select something
Expand Down Expand Up @@ -376,18 +338,6 @@ void Manager::initEnginePath()
}
}

#if 0
// After the dialog, the settings are located in the registry.
// Construct the paths with the settings found there
constructPaths();

if (!settingsValid() && !userWantsToCorrectSettings())
{
break;
}
}
#endif

// Register as observer, to get notified about future engine path changes
observeKey(RKEY_ENGINE_PATH);
observeKey(RKEY_FS_GAME);
Expand Down
17 changes: 1 addition & 16 deletions radiant/ui/prefdialog/GameSetupDialog.cpp
Expand Up @@ -64,23 +64,8 @@ void GameSetupDialog::initialiseControls()
wxPanel* container = new wxPanel(_book, wxID_ANY);
container->SetSizer(new wxBoxSizer(wxVERTICAL));

// Check the game setup dialog type
std::string type = GameSetupPageIdTech::TYPE();

xml::NodeList nodes = game->getLocalXPath("/gameSetup/dialog");

if (!nodes.empty())
{
std::string value = nodes[0].getAttributeValue("type");

if (!value.empty())
{
type = value;
}
}

// For each game type create a separate page in the choice book
GameSetupPage* page = GameSetupPage::CreatePageForType(type, container);
GameSetupPage* page = GameSetupPage::CreatePageForGame(game, container);
page->SetName("GameSetupPage");

// Store the game value as client data into the page object
Expand Down
30 changes: 23 additions & 7 deletions radiant/ui/prefdialog/GameSetupPage.cpp
Expand Up @@ -7,8 +7,9 @@
namespace ui
{

GameSetupPage::GameSetupPage(wxWindow* parent) :
wxPanel(parent, wxID_ANY)
GameSetupPage::GameSetupPage(wxWindow* parent, const game::IGamePtr& game) :
wxPanel(parent, wxID_ANY),
_game(game)
{}

// Static instance
Expand All @@ -18,28 +19,43 @@ void GameSetupPage::EnsureDefaultPages()
{
if (_registeredPages.empty())
{
_registeredPages[GameSetupPageIdTech::TYPE()] = [](wxWindow* parent)
_registeredPages[GameSetupPageIdTech::TYPE()] = [](wxWindow* parent, const game::IGamePtr& game)
{
return new GameSetupPageIdTech(parent);
return new GameSetupPageIdTech(parent, game);
};
}
}

GameSetupPage* GameSetupPage::CreatePageForType(const std::string& type, wxWindow* parent)
GameSetupPage* GameSetupPage::CreatePageForGame(const game::IGamePtr& game, wxWindow* parent)
{
EnsureDefaultPages();

// Check the game setup dialog type, default to idTech generic
std::string type = GameSetupPageIdTech::TYPE();

xml::NodeList nodes = game->getLocalXPath("/gameSetup/dialog");

if (!nodes.empty())
{
std::string value = nodes[0].getAttributeValue("type");

if (!value.empty())
{
type = value;
}
}

GameSetupPages::const_iterator found = _registeredPages.find(type);

if (found != _registeredPages.end())
{
return found->second(parent);
return found->second(parent, game);
}

rWarning() << "No Game Setup Page associated to type " << type <<
", will fall back to a generic idTech setup page." << std::endl;

return new GameSetupPageIdTech(parent);
return new GameSetupPageIdTech(parent, game);
}

}
11 changes: 8 additions & 3 deletions radiant/ui/prefdialog/GameSetupPage.h
@@ -1,5 +1,6 @@
#pragma once

#include "igame.h"
#include <stdexcept>
#include <functional>
#include <map>
Expand All @@ -26,8 +27,12 @@ class GameSettingsInvalidException :
class GameSetupPage :
public wxPanel
{
protected:
// The game we're working on
game::IGamePtr _game;

public:
GameSetupPage(wxWindow* parent);
GameSetupPage(wxWindow* parent, const game::IGamePtr& game);

virtual ~GameSetupPage() {}

Expand Down Expand Up @@ -55,7 +60,7 @@ class GameSetupPage :
virtual std::string getModPath() = 0;

public:
typedef std::function<GameSetupPage*(wxWindow*)> CreateInstanceFunc;
typedef std::function<GameSetupPage*(wxWindow*, const game::IGamePtr&)> CreateInstanceFunc;

// Base class keeps a map of registered pages
typedef std::map<std::string, GameSetupPage::CreateInstanceFunc> GameSetupPages;
Expand All @@ -64,7 +69,7 @@ class GameSetupPage :
static void EnsureDefaultPages();

// Creates the setup page instance for the given type
static GameSetupPage* CreatePageForType(const std::string& type, wxWindow* parent);
static GameSetupPage* CreatePageForGame(const game::IGamePtr& game, wxWindow* parent);
};

}
36 changes: 2 additions & 34 deletions radiant/ui/prefdialog/GameSetupPageIdTech.cpp
Expand Up @@ -20,8 +20,8 @@
namespace ui
{

GameSetupPageIdTech::GameSetupPageIdTech(wxWindow* parent) :
GameSetupPage(parent),
GameSetupPageIdTech::GameSetupPageIdTech(wxWindow* parent, const game::IGamePtr& game) :
GameSetupPage(parent, game),
_fsGameEntry(nullptr),
_fsGameBaseEntry(nullptr),
_enginePathEntry(nullptr)
Expand Down Expand Up @@ -187,36 +187,4 @@ void GameSetupPageIdTech::constructPaths()
}
}

#if 0
wxTextCtrl* GameSetupPageIdTech::createEntry(const std::string& registryKey)
{
wxTextCtrl* entryWidget = new wxTextCtrl(this, wxID_ANY);

int minChars = static_cast<int>(std::max(_registryBuffer.get(registryKey).size(), std::size_t(30)));
entryWidget->SetMinClientSize(wxSize(entryWidget->GetCharWidth() * minChars, -1));

// Connect the registry key to the newly created input field
registry::bindWidgetToBufferedKey(entryWidget, registryKey, _registryBuffer, _resetValuesSignal);

return entryWidget;
}

wxutil::PathEntry* GameSetupPageIdTech::createPathEntry(const std::string& registryKey)
{
wxutil::PathEntry* entry = new wxutil::PathEntry(this, true);

// Connect the registry key to the newly created input field
registry::bindWidgetToBufferedKey(entry->getEntryWidget(), registryKey, _registryBuffer, _resetValuesSignal);

int minChars = static_cast<int>(std::max(GlobalRegistry().get(registryKey).size(), std::size_t(30)));

entry->getEntryWidget()->SetMinClientSize(
wxSize(entry->getEntryWidget()->GetCharWidth() * minChars, -1));

// Initialize entry
entry->setValue(registry::getValue<std::string>(registryKey));

return entry;
}
#endif
}
14 changes: 1 addition & 13 deletions radiant/ui/prefdialog/GameSetupPageIdTech.h
@@ -1,7 +1,6 @@
#pragma once

#include "GameSetupPage.h"
#include "registry/buffer.h"

class wxTextCtrl;
namespace wxutil { class PathEntry; }
Expand All @@ -17,13 +16,6 @@ class GameSetupPageIdTech :
public GameSetupPage
{
private:
// We're holding back any registry write operations until the user clicks OK
registry::Buffer _registryBuffer;

// A signal chain all registry key-bound widgets are connected with
// when emitted, the widgets reload the values from the registry.
sigc::signal<void> _resetValuesSignal;

wxTextCtrl* _fsGameEntry;
wxTextCtrl* _fsGameBaseEntry;
wxutil::PathEntry* _enginePathEntry;
Expand All @@ -33,7 +25,7 @@ class GameSetupPageIdTech :
std::string _modPath;

public:
GameSetupPageIdTech(wxWindow* parent);
GameSetupPageIdTech(wxWindow* parent, const game::IGamePtr& game);

static const char* TYPE();

Expand All @@ -47,10 +39,6 @@ class GameSetupPageIdTech :

private:
void constructPaths();
#if 0
wxTextCtrl* createEntry(const std::string& registryKey);
wxutil::PathEntry* createPathEntry(const std::string& registryKey);
#endif
};

}

0 comments on commit f154501

Please sign in to comment.