Switched to reference vars for game and settings to ensure consistency across windows. Also started to implement the dialogs for the metadata editor, and fixed a few crashes.

This commit is contained in:
WrinklyNinja
2013-05-09 21:25:10 +01:00
parent 4c97ff63b5
commit 7f27d27b76
8 changed files with 138 additions and 51 deletions
+3 -11
View File
@@ -43,27 +43,19 @@ namespace fs = boost::filesystem;
namespace boss {
void DetectGames(std::vector<unsigned int>& detected, std::vector<unsigned int>& undetected) {
std::vector<unsigned int> DetectGames() {
vector<unsigned int> detected;
if (Game(GAME_TES4, false).IsInstalled()) //Look for Oblivion.
detected.push_back(GAME_TES4);
else
undetected.push_back(GAME_TES4);
if (Game(GAME_NEHRIM, false).IsInstalled()) //Look for Nehrim.
detected.push_back(GAME_NEHRIM);
else
undetected.push_back(GAME_NEHRIM);
if (Game(GAME_TES5, false).IsInstalled()) //Look for Skyrim.
detected.push_back(GAME_TES5);
else
undetected.push_back(GAME_TES5);
if (Game(GAME_FO3, false).IsInstalled()) //Look for Fallout 3.
detected.push_back(GAME_FO3);
else
undetected.push_back(GAME_FO3);
if (Game(GAME_FONV, false).IsInstalled()) //Look for Fallout New Vegas.
detected.push_back(GAME_FONV);
else
undetected.push_back(GAME_FONV);
return detected;
}
Game::Game() {}
+1 -1
View File
@@ -40,7 +40,7 @@ namespace boss {
class Plugin;
void DetectGames(std::vector<unsigned int>& detected, std::vector<unsigned int>& undetected);
std::vector<unsigned int> DetectGames();
class Game {
public:
+44 -1
View File
@@ -37,7 +37,7 @@ END_EVENT_TABLE()
using namespace std;
Editor::Editor(const wxString title, wxFrame *parent) : wxFrame(parent, wxID_ANY, title) {
Editor::Editor(wxWindow *parent, const wxString& title) : wxFrame(parent, wxID_ANY, title) {
//Initialise child windows.
listBook = new wxNotebook(this, BOOK_Lists);
@@ -156,6 +156,7 @@ Editor::Editor(const wxString title, wxFrame *parent) : wxFrame(parent, wxID_ANY
bigBox->Add(mainBox, 2, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 10);
SetBackgroundColour(wxColour(255,255,255));
SetIcon(wxIconLocation("BOSS.exe"));
SetSizerAndFit(bigBox);
}
@@ -349,3 +350,45 @@ void Editor::ApplyCurrentPluginEdits() {
else
_editedPlugins.push_back(diff);
}
FileEditDialog::FileEditDialog(wxWindow *parent, const wxString& title) : wxDialog(parent, wxID_ANY, title) {
}
void FileEditDialog::SetValues(const std::string& name, const std::string& display, const std::string& condition) {
}
std::vector<std::string> FileEditDialog::GetValues() const {
vector<string> values;
return values;
}
MessageEditDialog::MessageEditDialog(wxWindow *parent, const wxString& title) : wxDialog(parent, wxID_ANY, title) {
}
void MessageEditDialog::SetValues(const std::string& type, const std::string& content, const std::string& condition, const std::string& language) {
}
std::vector<std::string> MessageEditDialog::GetValues() const {
vector<string> values;
return values;
}
TagEditDialog::TagEditDialog(wxWindow *parent, const wxString& title) : wxDialog(parent, wxID_ANY, title) {
}
void TagEditDialog::SetValues(const std::string& addRemove, const std::string& name, const std::string& condition) {
}
std::vector<std::string> TagEditDialog::GetValues() const {
vector<string> values;
return values;
}
+41 -1
View File
@@ -34,7 +34,7 @@
class Editor : public wxFrame {
public:
Editor(const wxString title, wxFrame *parent);
Editor(wxWindow *parent, const wxString& title);
void SetList(const std::vector<boss::Plugin>& basePlugins, const std::vector<boss::Plugin>& editedPlugins);
void IsSorted(bool sorted);
@@ -71,6 +71,46 @@ private:
std::vector<boss::Plugin> _basePlugins, _editedPlugins;
boss::Plugin currentPlugin;
//boss::Game& _game;
// YAML::Node& _settings; //BOSS Settings.
};
class FileEditDialog : public wxDialog {
public:
FileEditDialog(wxWindow *parent, const wxString& title);
void SetValues(const std::string& name, const std::string& display, const std::string& condition);
std::vector<std::string> GetValues() const;
private:
wxTextCtrl * _name;
wxTextCtrl * _display;
wxTextCtrl * _condition;
};
class MessageEditDialog : public wxDialog {
public:
MessageEditDialog(wxWindow *parent, const wxString& title);
void SetValues(const std::string& type, const std::string& content, const std::string& condition, const std::string& language);
std::vector<std::string> GetValues() const;
private:
wxChoice * _type;
wxTextCtrl * _content;
wxTextCtrl * _condition;
wxChoice * _language;
};
class TagEditDialog : public wxDialog {
public:
TagEditDialog(wxWindow *parent, const wxString& title);
void SetValues(const std::string& addRemove, const std::string& name, const std::string& condition);
std::vector<std::string> GetValues() const;
private:
wxChoice * _addRemove;
wxTextCtrl * _name;
wxTextCtrl * _condition;
};
#endif
+36 -29
View File
@@ -88,10 +88,9 @@ bool BossGUI::OnInit() {
}
//Load settings.
YAML::Node settings;
if (fs::exists(settings_path)) {
try {
settings = YAML::LoadFile(settings_path.string());
_settings = YAML::LoadFile(settings_path.string());
} catch (YAML::ParserException& e) {
//LOG_ERROR("Error: %s", e.getString().c_str());
wxMessageBox(
@@ -115,10 +114,10 @@ bool BossGUI::OnInit() {
gen.add_messages_domain("messages");
//Set the locale to get encoding and language conversions working correctly.
if (settings["Language"]) {
if (_settings["Language"]) {
string localeId = "";
wxLanguage lang;
if (settings["Language"].as<string>() == "eng") {
if (_settings["Language"].as<string>() == "eng") {
localeId = "en.UTF-8";
lang = wxLANGUAGE_ENGLISH;
}
@@ -146,9 +145,8 @@ bool BossGUI::OnInit() {
}
//Detect installed games.
vector<unsigned int> detected, undetected;
DetectGames(detected, undetected);
if (detected.empty())
_detectedGames = DetectGames();
if (_detectedGames.empty())
wxMessageBox(
translate("Error: None of the supported games were detected."),
translate("BOSS: Error"),
@@ -156,37 +154,40 @@ bool BossGUI::OnInit() {
NULL);
string target;
unsigned int targetGame;
if (settings["Game"] && settings["Game"].as<string>() != "auto")
target = settings["Game"].as<string>();
else if (settings["Last Game"] && settings["Last Game"].as<string>() != "auto")
target = settings["Last Game"].as<string>();
unsigned int targetGame = GAME_AUTODETECT;
if (_settings["Game"] && _settings["Game"].as<string>() != "auto")
target = _settings["Game"].as<string>();
else if (_settings["Last Game"] && _settings["Last Game"].as<string>() != "auto")
target = _settings["Last Game"].as<string>();
if (!target.empty()) {
for (size_t i=0, max=detected.size(); i < max; ++i) {
if (target == "oblivion" && detected[i] == GAME_TES4) {
for (size_t i=0, max=_detectedGames.size(); i < max; ++i) {
if (target == "oblivion" && _detectedGames[i] == GAME_TES4) {
targetGame = GAME_TES4;
break;
} else if (target == "nehrim" && detected[i] == GAME_NEHRIM) {
} else if (target == "nehrim" && _detectedGames[i] == GAME_NEHRIM) {
targetGame = GAME_NEHRIM;
break;
} else if (target == "skyrim" && detected[i] == GAME_TES5) {
} else if (target == "skyrim" && _detectedGames[i] == GAME_TES5) {
targetGame = GAME_TES5;
break;
} else if (target == "fallout3" && detected[i] == GAME_FO3) {
} else if (target == "fallout3" && _detectedGames[i] == GAME_FO3) {
targetGame = GAME_FO3;
break;
} else if (target == "falloutnv" && detected[i] == GAME_FONV) {
} else if (target == "falloutnv" && _detectedGames[i] == GAME_FONV) {
targetGame = GAME_FONV;
break;
}
}
if (targetGame == GAME_AUTODETECT)
targetGame = _detectedGames[0];
} else
targetGame = detected[0];
Game game(targetGame);
targetGame = _detectedGames[0];
_game = Game(targetGame);
//Create launcher window.
Launcher * launcher = new Launcher(wxT("BOSS"), settings, game, detected);
Launcher * launcher = new Launcher(wxT("BOSS"), _settings, _game, _detectedGames);
launcher->SetIcon(wxIconLocation("BOSS.exe"));
launcher->Show();
@@ -195,7 +196,7 @@ bool BossGUI::OnInit() {
return true;
}
Launcher::Launcher(const wxChar *title, const YAML::Node& settings, const Game& game, const vector<unsigned int>& detectedGames) : wxFrame(NULL, wxID_ANY, title), _game(game), _detectedGames(detectedGames), _settings(settings) {
Launcher::Launcher(const wxChar *title, YAML::Node& settings, Game& game, const vector<unsigned int>& detectedGames) : wxFrame(NULL, wxID_ANY, title), _game(game), _detectedGames(detectedGames), _settings(settings) {
//Initialise menu items.
wxMenuBar * MenuBar = new wxMenuBar();
@@ -267,6 +268,15 @@ Launcher::Launcher(const wxChar *title, const YAML::Node& settings, const Game&
//Called when the frame exits.
void Launcher::OnQuit(wxCommandEvent& event) {
//Save settings.
YAML::Emitter yout;
yout.SetIndent(2);
yout << _settings;
ofstream out(boss::settings_path.string().c_str());
out << yout.c_str();
out.close();
Close(true); // Tells the OS to quit running this process
}
@@ -482,8 +492,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) {
progDia->Destroy();
//Create editor window.
Editor *editor = new Editor(translate("BOSS: Metadata Editor"), this);
editor->SetIcon(wxIconLocation("BOSS.exe"));
Editor *editor = new Editor(this, translate("BOSS: Metadata Editor"));
//The 'plugins' list contains the merged plugin info, but we want to pass a vector of plugins with only masterlist info in its place, so have to construct that.
vector<boss::Plugin> pluginVec;
@@ -572,9 +581,8 @@ void Launcher::OnEditMetadata(wxCommandEvent& event) {
std::sort(ulist_plugins.begin(), ulist_plugins.end(), AlphaSortPlugins);
//Create editor window.
Editor *editor = new Editor(translate("BOSS: Metadata Editor"), this);
editor->SetIcon(wxIconLocation("BOSS.exe"));
Editor *editor = new Editor(this, translate("BOSS: Metadata Editor"));
//Pass plugin lists to editor window.
editor->SetList(plugins, ulist_plugins);
@@ -589,8 +597,7 @@ void Launcher::OnViewLastReport(wxCommandEvent& event) {
}
void Launcher::OnOpenSettings(wxCommandEvent& event) {
SettingsFrame *settings = new SettingsFrame(translate("BOSS: Settings"), this, _settings);
settings->SetIcon(wxIconLocation("BOSS.exe"));
SettingsFrame *settings = new SettingsFrame(this, translate("BOSS: Settings"), _settings);
settings->Show();
}
+8 -4
View File
@@ -36,11 +36,15 @@ public:
bool OnInit(); //Load settings, apply logging and language settings, check if BOSS is already running, detect games, set game to last game or to first detected game if auto, create launcher window.
private:
wxLocale * wxLoc;
boss::Game _game;
YAML::Node _settings;
std::vector<unsigned int> _detectedGames;
};
class Launcher : public wxFrame {
public:
Launcher(const wxChar *title, const YAML::Node& settings, const boss::Game& inGame, const std::vector<unsigned int>& inGames);
Launcher(const wxChar *title, YAML::Node& settings, boss::Game& inGame, const std::vector<unsigned int>& detectedGames);
void OnSortPlugins(wxCommandEvent& event);
void OnEditMetadata(wxCommandEvent& event);
@@ -57,9 +61,9 @@ private:
wxMenu * GameMenu;
wxButton * ViewButton;
std::vector<unsigned int> _detectedGames;
boss::Game _game;
YAML::Node _settings; //BOSS Settings.
boss::Game& _game;
YAML::Node& _settings; //BOSS Settings.
const std::vector<unsigned int>& _detectedGames;
void DisableUndetectedGames();
+3 -2
View File
@@ -32,7 +32,7 @@ END_EVENT_TABLE()
using namespace std;
SettingsFrame::SettingsFrame(const wxString title, wxFrame *parent, YAML::Node& settings) : wxFrame(parent, wxID_ANY, title), _settings(settings) {
SettingsFrame::SettingsFrame(wxWindow *parent, const wxString& title, YAML::Node& settings) : wxFrame(parent, wxID_ANY, title), _settings(settings) {
//Initialise drop-down list contents.
wxString DebugVerbosity[] = {
@@ -122,7 +122,7 @@ SettingsFrame::SettingsFrame(const wxString title, wxFrame *parent, YAML::Node&
bigBox->AddStretchSpacer(1);
bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Settings will be applied after BOSS is restarted.")), wholeItem);
bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Language changes will be applied after BOSS is restarted.")), wholeItem);
//Need to add 'OK' and 'Cancel' buttons.
wxBoxSizer * hbox = new wxBoxSizer(wxHORIZONTAL);
@@ -142,6 +142,7 @@ SettingsFrame::SettingsFrame(const wxString title, wxFrame *parent, YAML::Node&
//Now set the layout and sizes.
SetBackgroundColour(wxColour(255,255,255));
SetIcon(wxIconLocation("BOSS.exe"));
SetSizerAndFit(bigBox);
}
+2 -2
View File
@@ -30,7 +30,7 @@
class SettingsFrame : public wxFrame {
public:
SettingsFrame(const wxString title, wxFrame *parent, YAML::Node& settings);
SettingsFrame(wxWindow *parent, const wxString& title, YAML::Node& settings);
void OnQuit(wxCommandEvent& event);
void SetDefaultValues();
DECLARE_EVENT_TABLE()
@@ -45,6 +45,6 @@ private:
wxTextCtrl *FO3URL;
wxTextCtrl *FONVURL;
YAML::Node _settings;
YAML::Node& _settings;
};
#endif