From 040e87e938cfdf0b5cb9947c156e01f5a45352ab Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 19 Nov 2006 22:30:19 +0000 Subject: [PATCH] dialog for column selection; column settings are stored git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@77 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/field.cpp | 4 +- src/data/field.hpp | 5 +- src/data/settings.cpp | 23 ++- src/data/symbol.cpp | 2 +- src/gui/control/card_list.cpp | 9 +- src/gui/control/card_list_column_select.cpp | 156 ++++++++++++++++++++ src/gui/control/card_list_column_select.hpp | 66 +++++++++ src/gui/set/window.cpp | 4 +- src/util/io/get_member.hpp | 2 +- src/util/io/package.cpp | 4 +- src/util/io/package.hpp | 4 +- src/util/window_id.hpp | 4 + 12 files changed, 261 insertions(+), 22 deletions(-) create mode 100644 src/gui/control/card_list_column_select.cpp create mode 100644 src/gui/control/card_list_column_select.hpp diff --git a/src/data/field.cpp b/src/data/field.cpp index 0e843496..6ba08a26 100644 --- a/src/data/field.cpp +++ b/src/data/field.cpp @@ -24,9 +24,10 @@ Field::Field() , save_value (true) , show_statistics (true) , identifying (false) - , card_list_column (-1) + , card_list_column (100) , card_list_width (100) , card_list_allow (true) + , card_list_visible(false) , card_list_align (ALIGN_LEFT) , tab_index (0) {} @@ -47,6 +48,7 @@ IMPLEMENT_REFLECTION(Field) { REFLECT(identifying); REFLECT(card_list_column); REFLECT(card_list_width); + REFLECT(card_list_visible); REFLECT(card_list_allow); REFLECT(card_list_name); if (tag.reading() && card_list_name.empty()) card_list_name = name; diff --git a/src/data/field.hpp b/src/data/field.hpp index 5aebec81..46963c74 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -42,9 +42,10 @@ class Field { bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields. bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel? bool identifying; ///< Does this field give Card::identification()? - int card_list_column; ///< What column to use in the card list? -1 = don't list + int card_list_column; ///< What column to use in the card list? UInt card_list_width; ///< Width of the card list column (pixels). - bool card_list_allow; ///< Is this field allowed to appear in the card list. + bool card_list_visible;///< Is this field shown in the card list? + bool card_list_allow; ///< Is this field allowed to appear in the card list? String card_list_name; ///< Alternate name to use in card list. Alignment card_list_align; ///< Alignment of the card list colummn. int tab_index; ///< Tab index in editor diff --git a/src/data/settings.cpp b/src/data/settings.cpp index 847e770c..9fa2f3a9 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -30,6 +30,9 @@ ColumnSettings::ColumnSettings() : width(100), position(COLUMN_NOT_INITIALIZED), visible(false) {} +// dummy for ColumnSettings reflection +ScriptValueP toScript(const ColumnSettings&) { return script_nil; } + IMPLEMENT_REFLECTION(ColumnSettings) { REFLECT(width); REFLECT(position); @@ -39,13 +42,17 @@ IMPLEMENT_REFLECTION(ColumnSettings) { IMPLEMENT_REFLECTION(GameSettings) { REFLECT(default_stylesheet); REFLECT(default_export); -// REFLECT_N("cardlist columns", columns); + REFLECT_N("cardlist columns", columns); REFLECT(sort_cards_by); REFLECT(sort_cards_ascending); } IMPLEMENT_REFLECTION(StyleSheetSettings) { - // TODO + REFLECT(card_zoom); + REFLECT(card_angle); + REFLECT(card_anti_alias); + REFLECT(card_borders); + REFLECT(card_normal_export); } // ----------------------------------------------------------------------------- : Settings @@ -89,7 +96,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field ColumnSettings& cs = gs.columns[field.name]; if (cs.position == COLUMN_NOT_INITIALIZED) { // column info not set, initialize based on the game - cs.visible = field.card_list_column >= 0; + cs.visible = field.card_list_visible; cs.position = field.card_list_column; cs.width = field.card_list_width; } @@ -114,7 +121,9 @@ String Settings::settingsFile() { } IMPLEMENT_REFLECTION(Settings) { -// ioMseVersion(io, "settings", file_version); + tag.handleAppVersion(); + tag.addAlias(300, _("style settings"), _("stylesheet settings")); + tag.addAlias(300, _("default style settings"), _("default stylesheet settings")); REFLECT(recent_sets); REFLECT(set_window_maximized); REFLECT(set_window_width); @@ -124,9 +133,9 @@ IMPLEMENT_REFLECTION(Settings) { REFLECT(apprentice_location); REFLECT(updates_url); REFLECT(check_updates); -// ioAll(io, game_settings); -// ioStyleSettings(io); -// REFLECT(default_style_settings); + REFLECT(game_settings); + REFLECT(stylesheet_settings); + REFLECT(default_stylesheet_settings); } void Settings::read() { diff --git a/src/data/symbol.cpp b/src/data/symbol.cpp index a1c6344d..b6bd35d7 100644 --- a/src/data/symbol.cpp +++ b/src/data/symbol.cpp @@ -159,7 +159,7 @@ void SymbolPart::calculateBounds() { // ----------------------------------------------------------------------------- : Symbol IMPLEMENT_REFLECTION(Symbol) { -//%% version? + tag.handleAppVersion(); REFLECT(parts); } diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 088f656e..22f08783 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -7,6 +7,7 @@ // ----------------------------------------------------------------------------- : Includes #include +#include #include #include #include @@ -282,10 +283,10 @@ void CardListBase::storeColumns() { gs.sort_cards_ascending = sort_ascending; } void CardListBase::selectColumns() { -// CardListColumnSelect wnd(this, set->game); -// if (wnd.ShowModal() == wxID_OK) { -// rebuild(); // columns have changed -// } + CardListColumnSelectDialog wnd(this, set->game); + if (wnd.ShowModal() == wxID_OK) { + rebuild(); // columns have changed + } } // ----------------------------------------------------------------------------- : CardListBase : Item 'events' diff --git a/src/gui/control/card_list_column_select.cpp b/src/gui/control/card_list_column_select.cpp new file mode 100644 index 00000000..3e849b0a --- /dev/null +++ b/src/gui/control/card_list_column_select.cpp @@ -0,0 +1,156 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include +#include + +DECLARE_TYPEOF_COLLECTION(FieldP); +DECLARE_TYPEOF_COLLECTION(CardListColumnSelectDialog::ColumnSettingsF); + +// ----------------------------------------------------------------------------- : CardListColumnSelectDialog + +CardListColumnSelectDialog::CardListColumnSelectDialog(Window* parent, const GameP& game) + : wxDialog(parent, wxID_ANY,_("Select Columns"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) + , game(game) +{ + // Create controls + list = new wxCheckListBox(this, wxID_ANY); + // Create sizer + wxSizer* s = new wxBoxSizer(wxVERTICAL); + s->Add(new wxStaticText(this, wxID_ANY, _("Select the columns you want to display")), 0, wxALL, 8); + s->Add(new wxStaticText(this, wxID_ANY, _("Columns:") ), 0, wxALL & ~wxBOTTOM, 8); + wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL); + s2->Add(list, 1, wxEXPAND | wxLEFT | wxRIGHT, 4); + wxSizer* s3 = new wxBoxSizer(wxVERTICAL); + s3->Add(new wxButton(this, ID_MOVE_UP, _("Move &Up")), 0, wxEXPAND, 2); + s3->Add(new wxButton(this, ID_MOVE_DOWN, _("Move &Down")), 0, wxEXPAND | wxTOP, 2); + s3->Add(new wxButton(this, ID_SHOW, _("&Show")), 0, wxEXPAND | wxTOP, 2); + s3->Add(new wxButton(this, ID_HIDE, _("&Hide")), 0, wxEXPAND | wxTOP, 2); + s2->Add(s3, 0, wxEXPAND | wxALL & ~wxTOP, 4); + s->Add(s2 , 1, wxEXPAND | wxALL, 4); + s->Add(CreateButtonSizer(wxOK | wxCANCEL) , 0, wxEXPAND | wxALL, 8); + s->SetSizeHints(this); + SetSizer(s); + // Set default size + SetSize(350, 450); + // Initialize order list + initColumns(); + initList(); + UpdateWindowUI(wxUPDATE_UI_RECURSE); +} + +struct SortByPosition { + SortByPosition(const Game& game) : game(game) {} + const Game& game; + bool operator() (const CardListColumnSelectDialog::ColumnSettingsF& a, const CardListColumnSelectDialog::ColumnSettingsF& b){ + return a.settings.position < b.settings.position; + } +}; + +void CardListColumnSelectDialog::initColumns() { + // order is a list of all columns that may be shown + FOR_EACH(f, game->card_fields) { + if (f->card_list_allow) { + columns.push_back(ColumnSettingsF(f, settings.columnSettingsFor(*game, *f))); + } + } + // sorted by position + sort(columns.begin(), columns.end(), SortByPosition(*game)); + // force unique position + int min = 0; + FOR_EACH(c, columns) { + if (c.settings.position < min) c.settings.position = min; + min = c.settings.position + 1; + } +} + +void CardListColumnSelectDialog::initList() { + // Init items + Color window_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + FOR_EACH(c, columns) { + list->Append(capitalize(c.field->card_list_name)); + // check + int i = list->GetCount() - 1; + list->Check(i, c.settings.visible); + // fix the background color + list->GetItem(i)->SetBackgroundColour(window_color); + } +} + +void CardListColumnSelectDialog::refreshItem(int i) { + list->Check (i, columns[i].settings.visible); + list->SetString(i, capitalize(columns[i].field->card_list_name)); +} + +// ----------------------------------------------------------------------------- : Events + +void CardListColumnSelectDialog::onSelect(wxCommandEvent& ev) { + UpdateWindowUI(wxUPDATE_UI_RECURSE); +} + +void CardListColumnSelectDialog::onCheck(wxCommandEvent& ev) { + int i = ev.GetSelection(); + columns[i].settings.visible = list->IsChecked(i); + UpdateWindowUI(wxUPDATE_UI_RECURSE); +} + +void CardListColumnSelectDialog::onMove(wxCommandEvent& ev) { + int i = list->GetSelection(); + int delta = ev.GetId() == ID_MOVE_UP ? -1 : 1; + if (i == wxNOT_FOUND || i + delta < 0 || i + delta >= (int)columns.size()) return; + list->SetSelection(i + delta); + // swap the columns and positions + swap(columns[i], columns[i + delta]); + swap(columns[i].settings.position, columns[i + delta].settings.position); + refreshItem(i); + refreshItem(i + delta); + UpdateWindowUI(wxUPDATE_UI_RECURSE); +} + +void CardListColumnSelectDialog::onShowHide(wxCommandEvent& ev) { + int i = list->GetSelection(); + if (i == wxNOT_FOUND) return; + columns[i].settings.visible = ev.GetId() == ID_SHOW; + refreshItem(i); + UpdateWindowUI(wxUPDATE_UI_RECURSE); +} + +void CardListColumnSelectDialog::onOk(wxCommandEvent&) { + // store column settings + FOR_EACH(c, columns) { + settings.columnSettingsFor(*game, *c.field) = c.settings; + } + // close dialog + EndModal(wxID_OK); + +} + +void CardListColumnSelectDialog::onUpdateUI(wxUpdateUIEvent& ev) { + int i = list->GetSelection(); + switch (ev.GetId()) { + case ID_MOVE_UP: ev.Enable(i != wxNOT_FOUND && i - 1 >= 0); break; + case ID_MOVE_DOWN: ev.Enable(i != wxNOT_FOUND && i + 1 < (int)columns.size()); break; + case ID_SHOW: ev.Enable(i != wxNOT_FOUND && !columns[i].settings.visible); break; + case ID_HIDE: ev.Enable(i != wxNOT_FOUND && columns[i].settings.visible); break; + } +} + +// ----------------------------------------------------------------------------- : Event table + +BEGIN_EVENT_TABLE(CardListColumnSelectDialog, wxDialog) + EVT_LISTBOX (wxID_ANY, CardListColumnSelectDialog::onSelect) + EVT_CHECKLISTBOX (wxID_ANY, CardListColumnSelectDialog::onCheck) + EVT_BUTTON (ID_MOVE_UP, CardListColumnSelectDialog::onMove) + EVT_BUTTON (ID_MOVE_DOWN, CardListColumnSelectDialog::onMove) + EVT_BUTTON (ID_SHOW, CardListColumnSelectDialog::onShowHide) + EVT_BUTTON (ID_HIDE, CardListColumnSelectDialog::onShowHide) + EVT_BUTTON (wxID_OK, CardListColumnSelectDialog::onOk) + EVT_UPDATE_UI (wxID_ANY, CardListColumnSelectDialog::onUpdateUI) +END_EVENT_TABLE () diff --git a/src/gui/control/card_list_column_select.hpp b/src/gui/control/card_list_column_select.hpp new file mode 100644 index 00000000..468d5062 --- /dev/null +++ b/src/gui/control/card_list_column_select.hpp @@ -0,0 +1,66 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_GUI_CONTROL_CARD_LIST_COLUMN_SELECT +#define HEADER_GUI_CONTROL_CARD_LIST_COLUMN_SELECT + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +DECLARE_POINTER_TYPE(Game); +DECLARE_POINTER_TYPE(Field); + +// ----------------------------------------------------------------------------- : CardListColumnSelectDialog + +/// A dialog for selecting the card list columns to show and their order +/** Layout + * | col a | <^> + * | < > col b | + * | col b | + * + * + */ +class CardListColumnSelectDialog : public wxDialog { + public: + CardListColumnSelectDialog(Window* parent, const GameP& game); + + private: + DECLARE_EVENT_TABLE(); + + // gui items + wxCheckListBox* list; + // other info + GameP game; ///< The game we are changing + public: struct ColumnSettingsF { + ColumnSettingsF(const FieldP& field, const ColumnSettings& settings) + : field(field) + , settings(settings) + {} + FieldP field; + ColumnSettings settings; + }; + private: vector columns; ///< Settings of the fields, in order + + // initialize columns + void initColumns(); + // intialize the list box + void initList(); + // refresh list item i + void refreshItem(int i); + + void onSelect (wxCommandEvent&); + void onCheck (wxCommandEvent&); + void onMove (wxCommandEvent&); + void onShowHide(wxCommandEvent&); + void onOk (wxCommandEvent&); + void onUpdateUI(wxUpdateUIEvent&); + +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 773a58b7..20a10d77 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -351,12 +351,12 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) { break; } // copy & paste & find - case ID_EDIT_CUT : ev.Enable(current_panel->canCut()); break; + case ID_EDIT_CUT : ev.Enable(current_panel->canCut()); break; case ID_EDIT_COPY : ev.Enable(current_panel->canCopy()); break; case ID_EDIT_PASTE : ev.Enable(current_panel->canPaste()); break; case ID_EDIT_FIND : ev.Enable(current_panel->canFind()); break; case ID_EDIT_FIND_NEXT : ev.Enable(current_panel->canFind()); break; - case ID_EDIT_REPLACE : ev.Enable(current_panel->canReplace()); break; + case ID_EDIT_REPLACE : ev.Enable(current_panel->canReplace());break; default: // items created by the panel, and cut/copy/paste and find/replace current_panel->onUpdateUI(ev); diff --git a/src/util/io/get_member.hpp b/src/util/io/get_member.hpp index 4aa4c40c..8b16fa36 100644 --- a/src/util/io/get_member.hpp +++ b/src/util/io/get_member.hpp @@ -29,7 +29,6 @@ class GetDefaultMember { inline bool reading() const { return false; } inline bool isComplex() const { return false; } inline void addAlias(int, const Char*, const Char*) {} - inline void handleAppVersion() {} // no effect /// The result, or script_nil if the member was not found @@ -70,6 +69,7 @@ class GetMember : private GetDefaultMember { inline bool reading() const { return false; } inline bool isComplex() const { return false; } inline void addAlias(int, const Char*, const Char*) {} + inline void handleAppVersion() {} // no effect /// The result, or script_nil if the member was not found inline ScriptValueP result() { return gdm.result(); } diff --git a/src/util/io/package.cpp b/src/util/io/package.cpp index 5504f190..ca27d096 100644 --- a/src/util/io/package.cpp +++ b/src/util/io/package.cpp @@ -395,10 +395,10 @@ void Packaged::open(const String& package) { } } void Packaged::save() { - //writeFile(thisT().fileName, thisT()); +// writeFile(thisT().fileName, thisT()); Package::save(); } void Packaged::saveAs(const String& package) { - //writeFile(thisT().fileName, thisT()); +// writeFile(thisT().fileName, thisT()); Package::saveAs(package); } diff --git a/src/util/io/package.hpp b/src/util/io/package.hpp index 99121dc9..a83e5df7 100644 --- a/src/util/io/package.hpp +++ b/src/util/io/package.hpp @@ -104,8 +104,8 @@ class Package { /// Open a file given an absolute filename static InputStreamP openAbsoluteFile(const String& name); - /* - // --------------------------------------------------- : Managing the inside of the package : IO files + +/* // --------------------------------------------------- : Managing the inside of the package : IO files template void readFile (String n, T& obj) { diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index e04fce79..8d01ef7d 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -163,6 +163,10 @@ enum ControlID { , ID_SEPARATOR , ID_REMINDER , ID_RULES +, ID_MOVE_UP +, ID_MOVE_DOWN +, ID_SHOW +, ID_HIDE }; // ----------------------------------------------------------------------------- : EOF