GUI code refactoring.

Helper dialogs and controls are now in misc.h/.cpp, and the MiniEditor
class got moved into editor.h/.cpp.

Also , the Editor class now takes plugin lists, not vectors, to match
the rest of the code. The alpha sort function had to be updated to
invert the order, to give the same result.
This commit is contained in:
WrinklyNinja
2014-02-09 13:27:25 +00:00
parent 425a49cee7
commit 99cd357552
8 changed files with 933 additions and 780 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ set (BOSS_GUI_SRC ${BOSS_SRC}
"${CMAKE_SOURCE_DIR}/src/gui/settings.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/editor.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/viewer.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/sorting.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/misc.cpp"
"${CMAKE_SOURCE_DIR}/src/resource.rc")
set (BOSS_API_SRC ${BOSS_SRC}
+1 -1
View File
@@ -741,7 +741,7 @@ namespace boss {
}
bool alpha_sort(const Plugin& lhs, const Plugin& rhs) {
return boost::ilexicographical_compare(lhs.Name(), rhs.Name());
return boost::ilexicographical_compare(rhs.Name(), lhs.Name());
}
bool master_sort(const Plugin& lhs, const Plugin& rhs) {
+234 -458
View File
File diff suppressed because it is too large Load Diff
+39 -87
View File
@@ -24,6 +24,7 @@
#define __BOSS_GUI_EDITOR__
#include "ids.h"
#include "misc.h"
#include "../backend/metadata.h"
#include <string>
@@ -32,29 +33,50 @@
#include <wx/notebook.h>
#include <wx/listctrl.h>
class MessageList : public wxListView {
/* Have two versions of the editor: one mini editor that only contains
controls for editing the load order related metadata, and a full editor
that contains controls for editing all the metadata.
Both editors need to convert between metadata and control data, and to
keep track of what edits have been made.
Have a immutable plugin list to keep track of non-user-edit metadata,
and a mutable plugin list to keep track of user-edit metadata. When
recording edits, diff the metadata obtained from the control values with
the metadata in the immutable plugin entry to get the new user-edit metadata.
If a metadata type's corresponding control is not present (ie. in the mini
editor), then use the immutable plugin entry's metadata for that type.
*/
class MiniEditor : public wxDialog {
public:
MessageList(wxWindow * parent, wxWindowID id, const unsigned int language);
MiniEditor(wxWindow *parent, const wxString& title, const std::list<boss::Plugin>& plugins, const boss::Game& game);
void SetItems(const std::vector<boss::Message>& messages);
std::vector<boss::Message> GetItems() const;
boss::Message GetItem(long item) const;
void SetItem(long item, const boss::Message& message);
void AppendItem(const boss::Message& message);
void OnDeleteItem(wxListEvent& event);
protected:
wxString OnGetItemText(long item, long column) const;
void OnPluginSelect(wxListEvent& event);
void OnRowSelect(wxListEvent& event);
void OnRemoveRow(wxCommandEvent& event);
void OnFilterToggle(wxCommandEvent& event);
const std::list<boss::Plugin>& GetEditedPlugins() const;
private:
std::vector<boss::Message> _messages;
const unsigned int _language;
wxButton * removeBtn;
wxListView * pluginList;
wxListView * loadAfterList;
wxCheckBox * filterCheckbox;
wxSpinCtrl * prioritySpin;
wxStaticText * pluginText;
void MiniEditor::ApplyEdits(const wxString& plugin);
const std::list<boss::Plugin> _basePlugins;
std::list<boss::Plugin> _editedPlugins;
const boss::Game& _game;
};
class Editor : public wxFrame {
public:
Editor(wxWindow *parent, const wxString& title, const std::string userlistPath, const std::vector<boss::Plugin>& basePlugins, std::vector<boss::Plugin>& editedPlugins, const unsigned int language, const boss::Game& game);
Editor(wxWindow *parent, const wxString& title, const std::string userlistPath, const std::list<boss::Plugin>& basePlugins, std::list<boss::Plugin>& editedPlugins, const unsigned int language, const boss::Game& game);
void OnPluginSelect(wxListEvent& event);
void OnPluginListRightClick(wxListEvent& event);
@@ -88,10 +110,9 @@ private:
wxStaticText * pluginText;
const std::string _userlistPath;
const std::vector<boss::Plugin> _basePlugins;
const std::list<boss::Plugin> _basePlugins;
std::list<boss::Plugin> _editedPlugins;
const boss::Game& _game;
std::vector<boss::Plugin> _editedPlugins;
std::vector<boss::Message> currentMessages;
void ApplyEdits(const wxString& plugin);
@@ -103,73 +124,4 @@ private:
boss::Tag RowToTag(wxListView * list, long row) const;
boss::PluginDirtyInfo RowToPluginDirtyInfo(wxListView * list, long row) const;
};
class FileEditDialog : public wxDialog {
public:
FileEditDialog(wxWindow *parent, const wxString& title);
void SetValues(const wxString& name, const wxString& display, const wxString& condition);
wxString GetName() const;
wxString GetDisplayName() const;
wxString GetCondition() const;
private:
wxTextCtrl * _name;
wxTextCtrl * _display;
wxTextCtrl * _condition;
};
class MessageEditDialog : public wxDialog {
public:
MessageEditDialog(wxWindow *parent, const wxString& title);
void SetMessage(const boss::Message& message);
boss::Message GetMessage() const;
void OnSelect(wxListEvent& event);
void OnAdd(wxCommandEvent& event);
void OnEdit(wxCommandEvent& event);
void OnRemove(wxCommandEvent& event);
private:
wxButton * addBtn;
wxButton * editBtn;
wxButton * removeBtn;
wxChoice * _type;
wxChoice * _language;
wxListView * _content;
wxTextCtrl * _condition;
wxTextCtrl * _str;
};
class TagEditDialog : public wxDialog {
public:
TagEditDialog(wxWindow *parent, const wxString& title);
void SetValues(int state, const wxString& name, const wxString& condition);
wxString GetState() const;
wxString GetName() const;
wxString GetCondition() const;
private:
wxChoice * _state;
wxTextCtrl * _name;
wxTextCtrl * _condition;
};
class DirtInfoEditDialog : public wxDialog {
public:
DirtInfoEditDialog(wxWindow * parent, const wxString& title);
void SetValues(const wxString& crc, unsigned int itm, unsigned int udr, unsigned int nav, const wxString& utility);
wxString GetCRC() const;
wxString GetUtility() const;
unsigned int GetITMs() const;
unsigned int GetUDRs() const;
unsigned int GetDeletedNavmeshes() const;
private:
wxTextCtrl * _crc;
wxSpinCtrl * _itm;
wxSpinCtrl * _udr;
wxSpinCtrl * _nav;
wxTextCtrl * _utility;
};
#endif
+519
View File
File diff suppressed because it is too large Load Diff
+139
View File
@@ -0,0 +1,139 @@
/* BOSS
A plugin load order optimiser for games that use the esp/esm plugin system.
Copyright (C) 2013-2014 WrinklyNinja
This file is part of BOSS.
BOSS is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
BOSS is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BOSS. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef __BOSS_GUI_MISC__
#define __BOSS_GUI_MISC__
#include "ids.h"
#include "../backend/metadata.h"
#include <string>
#include <vector>
#include <wx/listctrl.h>
#include <wx/spinctrl.h>
const wxString Type[3] = {
translate("Note"),
translate("Warning"),
translate("Error")
};
const wxString State[2] = {
translate("Add"),
translate("Remove")
};
class MessageList : public wxListView {
public:
MessageList(wxWindow * parent, wxWindowID id, const unsigned int language);
void SetItems(const std::vector<boss::Message>& messages);
std::vector<boss::Message> GetItems() const;
boss::Message GetItem(long item) const;
void SetItem(long item, const boss::Message& message);
void AppendItem(const boss::Message& message);
void OnDeleteItem(wxListEvent& event);
protected:
wxString OnGetItemText(long item, long column) const;
private:
std::vector<boss::Message> _messages;
const unsigned int _language;
};
class FileEditDialog : public wxDialog {
public:
FileEditDialog(wxWindow *parent, const wxString& title);
void SetValues(const wxString& name, const wxString& display, const wxString& condition);
wxString GetName() const;
wxString GetDisplayName() const;
wxString GetCondition() const;
private:
wxTextCtrl * _name;
wxTextCtrl * _display;
wxTextCtrl * _condition;
};
class MessageEditDialog : public wxDialog {
public:
MessageEditDialog(wxWindow *parent, const wxString& title);
void SetMessage(const boss::Message& message);
boss::Message GetMessage() const;
void OnSelect(wxListEvent& event);
void OnAdd(wxCommandEvent& event);
void OnEdit(wxCommandEvent& event);
void OnRemove(wxCommandEvent& event);
private:
wxButton * addBtn;
wxButton * editBtn;
wxButton * removeBtn;
wxChoice * _type;
wxChoice * _language;
wxListView * _content;
wxTextCtrl * _condition;
wxTextCtrl * _str;
};
class TagEditDialog : public wxDialog {
public:
TagEditDialog(wxWindow *parent, const wxString& title);
void SetValues(int state, const wxString& name, const wxString& condition);
wxString GetState() const;
wxString GetName() const;
wxString GetCondition() const;
private:
wxChoice * _state;
wxTextCtrl * _name;
wxTextCtrl * _condition;
};
class DirtInfoEditDialog : public wxDialog {
public:
DirtInfoEditDialog(wxWindow * parent, const wxString& title);
void SetValues(const wxString& crc, unsigned int itm, unsigned int udr, unsigned int nav, const wxString& utility);
wxString GetCRC() const;
wxString GetUtility() const;
unsigned int GetITMs() const;
unsigned int GetUDRs() const;
unsigned int GetDeletedNavmeshes() const;
private:
wxTextCtrl * _crc;
wxSpinCtrl * _itm;
wxSpinCtrl * _udr;
wxSpinCtrl * _nav;
wxTextCtrl * _utility;
};
class LoadOrderPreview : public wxDialog {
public:
LoadOrderPreview(wxWindow *parent, const wxString title, const std::list<boss::Plugin>& plugins, const boss::Game& game);
private:
wxListView * _loadOrder;
};
#endif
-169
View File
@@ -1,169 +0,0 @@
/* BOSS
A plugin load order optimiser for games that use the esp/esm plugin system.
Copyright (C) 2013-2014 WrinklyNinja
This file is part of BOSS.
BOSS is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
BOSS is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BOSS. If not, see
<http://www.gnu.org/licenses/>.
*/
#include "sorting.h"
#include "../backend/helpers.h"
using namespace std;
MiniEditor::MiniEditor(wxWindow *parent, const wxString& title, const std::list<boss::Plugin>& plugins, const boss::Game& game) : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), _basePlugins(plugins) {
//Initialise controls.
pluginText = new wxStaticText(this, wxID_ANY, "");
prioritySpin = new wxSpinCtrl(this, wxID_ANY, "0");
prioritySpin->SetRange(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
filterCheckbox = new wxCheckBox(this, wxID_ANY, translate("Show only conflicting plugins."));
pluginList = new wxListView(this, LIST_Plugins, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
loadAfterList = new wxListView(this, LIST_LoadAfter, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
removeBtn = new wxButton(this, BUTTON_RemoveRow, translate("Remove"));
wxMenu * pluginMenu = new wxMenu();
//Set up list columns.
pluginList->AppendColumn(translate("Plugin"));
pluginList->AppendColumn(translate("Priority"));
loadAfterList->AppendColumn(translate("Filename"));
//Set up plugin right-click menu.
pluginMenu->Append(MENU_CopyName, translate("Copy Into Load After List"));
//Initialise control states.
removeBtn->Enable(false);
prioritySpin->Enable(false);
filterCheckbox->Enable(false);
//Make plugin name bold text.
pluginText->SetFont(pluginText->GetFont().Bold());
//Set up layout.
wxBoxSizer * bigBox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer * hBox = new wxBoxSizer(wxHORIZONTAL);
hBox->Add(pluginList, 1, wxEXPAND | wxALL, 10);
wxBoxSizer * mainBox = new wxBoxSizer(wxVERTICAL);
mainBox->Add(pluginText, 0, wxTOP | wxBOTTOM, 10);
mainBox->Add(filterCheckbox, 0, wxTOP | wxBOTTOM, 10);
wxBoxSizer * hbox2 = new wxBoxSizer(wxHORIZONTAL);
hbox2->Add(new wxStaticText(this, wxID_ANY, translate("Priority: ")), 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT, 5);
hbox2->Add(prioritySpin, 0, wxALIGN_RIGHT);
mainBox->Add(hbox2, 0, wxEXPAND | wxALIGN_RIGHT | wxTOP | wxBOTTOM, 5);
mainBox->Add(loadAfterList, 1, wxEXPAND);
mainBox->Add(removeBtn, 0, wxTOP | wxBOTTOM | wxALIGN_RIGHT, 10);
hBox->Add(mainBox, 1, wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT, 10);
bigBox->Add(hBox, 1, wxEXPAND);
//Need to add 'Yes' and 'No' buttons.
wxSizer * sizer = CreateSeparatedButtonSizer(wxAPPLY | wxCANCEL);
//Now add buttons to window sizer.
if (sizer != NULL)
bigBox->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 15);
//Fill pluginList with the contents of basePlugins.
int i = 0;
for (list<boss::Plugin>::const_iterator it = _basePlugins.begin(); it != _basePlugins.end(); ++it) {
pluginList->InsertItem(i, FromUTF8(it->Name()));
pluginList->SetItem(i, 1, FromUTF8(boss::IntToString(it->Priority())));
if (it->FormIDs().empty()) {
pluginList->SetItemTextColour(i, wxColour(122, 122, 122));
}
else if (it->LoadsBSA(game)) {
pluginList->SetItemTextColour(i, wxColour(0, 142, 219));
}
++i;
}
pluginList->SetColumnWidth(0, wxLIST_AUTOSIZE);
SetBackgroundColour(wxColour(255, 255, 255));
SetIcon(wxIconLocation("BOSS.exe"));
SetSizerAndFit(bigBox);
Layout();
}
void MiniEditor::OnPluginSelect(wxListEvent& event) {
}
void MiniEditor::OnPluginListRightClick(wxListEvent& event) {
}
void MiniEditor::OnPluginCopy(wxCommandEvent& event) {
}
void MiniEditor::OnFilterToggle(wxCommandEvent& event) {
}
void MiniEditor::OnQuit(wxCommandEvent& event) {
}
LoadOrderPreview::LoadOrderPreview(wxWindow *parent, const wxString title, const std::list<boss::Plugin>& plugins, const boss::Game& game) : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
//Init controls.
_loadOrder = new wxListView(this, LIST_LoadOrder, wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
//Populate list.
_loadOrder->AppendColumn(translate("Load Order"));
size_t i = 0;
for (list<boss::Plugin>::const_iterator it = plugins.begin(), endit = plugins.end(); it != endit; ++it, ++i) {
_loadOrder->InsertItem(i, FromUTF8(it->Name()));
if (it->FormIDs().empty()) {
_loadOrder->SetItemTextColour(i, wxColour(122, 122, 122));
}
else if (it->LoadsBSA(game)) {
_loadOrder->SetItemTextColour(i, wxColour(0, 142, 219));
}
}
_loadOrder->SetColumnWidth(0, wxLIST_AUTOSIZE);
//Set up layout.
wxBoxSizer * bigBox = new wxBoxSizer(wxVERTICAL);
bigBox->Add(_loadOrder, 1, wxEXPAND | wxALL, 15);
bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Do you wish to make any changes to the load order above?")), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 15);
//Need to add 'Yes' and 'No' buttons.
wxSizer * sizer = CreateSeparatedButtonSizer(wxYES | wxNO | wxCANCEL);
//Now add buttons to window sizer.
if (sizer != NULL)
bigBox->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 15);
//Now set the layout and sizes.
SetBackgroundColour(wxColour(255, 255, 255));
SetIcon(wxIconLocation("BOSS.exe"));
SetSizerAndFit(bigBox);
}
-64
View File
@@ -1,64 +0,0 @@
/* BOSS
A plugin load order optimiser for games that use the esp/esm plugin system.
Copyright (C) 2013-2014 WrinklyNinja
This file is part of BOSS.
BOSS is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
BOSS is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BOSS. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef __BOSS_GUI_SORTING__
#define __BOSS_GUI_SORTING__
#include "ids.h"
#include "../backend/metadata.h"
#include <string>
#include <vector>
#include <list>
#include <wx/spinctrl.h>
#include <wx/listctrl.h>
class MiniEditor : public wxDialog {
public:
MiniEditor(wxWindow *parent, const wxString& title, const std::list<boss::Plugin>& plugins, const boss::Game& game);
void OnPluginSelect(wxListEvent& event);
void OnPluginListRightClick(wxListEvent& event);
void OnPluginCopy(wxCommandEvent& event);
void OnFilterToggle(wxCommandEvent& event);
void OnQuit(wxCommandEvent& event);
private:
wxButton * removeBtn;
wxListView * pluginList;
wxListView * loadAfterList;
wxCheckBox * filterCheckbox;
wxSpinCtrl * prioritySpin;
wxStaticText * pluginText;
const std::list<boss::Plugin>& _basePlugins;
std::list<boss::Plugin> _editedPlugins;
};
class LoadOrderPreview : public wxDialog {
public:
LoadOrderPreview(wxWindow *parent, const wxString title, const std::list<boss::Plugin>& plugins, const boss::Game& game);
private:
wxListView * _loadOrder;
};
#endif