Commit 4fac3f44 authored by twanvl's avatar twanvl

dialog for column selection; column settings are stored

parent cdf34aab
...@@ -24,9 +24,10 @@ Field::Field() ...@@ -24,9 +24,10 @@ Field::Field()
, save_value (true) , save_value (true)
, show_statistics (true) , show_statistics (true)
, identifying (false) , identifying (false)
, card_list_column (-1) , card_list_column (100)
, card_list_width (100) , card_list_width (100)
, card_list_allow (true) , card_list_allow (true)
, card_list_visible(false)
, card_list_align (ALIGN_LEFT) , card_list_align (ALIGN_LEFT)
, tab_index (0) , tab_index (0)
{} {}
...@@ -47,6 +48,7 @@ IMPLEMENT_REFLECTION(Field) { ...@@ -47,6 +48,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(identifying); REFLECT(identifying);
REFLECT(card_list_column); REFLECT(card_list_column);
REFLECT(card_list_width); REFLECT(card_list_width);
REFLECT(card_list_visible);
REFLECT(card_list_allow); REFLECT(card_list_allow);
REFLECT(card_list_name); REFLECT(card_list_name);
if (tag.reading() && card_list_name.empty()) card_list_name = name; if (tag.reading() && card_list_name.empty()) card_list_name = name;
......
...@@ -42,9 +42,10 @@ class Field { ...@@ -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 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 show_statistics; ///< Should this field appear as a group by choice in the statistics panel?
bool identifying; ///< Does this field give Card::identification()? 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). 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. String card_list_name; ///< Alternate name to use in card list.
Alignment card_list_align; ///< Alignment of the card list colummn. Alignment card_list_align; ///< Alignment of the card list colummn.
int tab_index; ///< Tab index in editor int tab_index; ///< Tab index in editor
......
...@@ -30,6 +30,9 @@ ColumnSettings::ColumnSettings() ...@@ -30,6 +30,9 @@ ColumnSettings::ColumnSettings()
: width(100), position(COLUMN_NOT_INITIALIZED), visible(false) : width(100), position(COLUMN_NOT_INITIALIZED), visible(false)
{} {}
// dummy for ColumnSettings reflection
ScriptValueP toScript(const ColumnSettings&) { return script_nil; }
IMPLEMENT_REFLECTION(ColumnSettings) { IMPLEMENT_REFLECTION(ColumnSettings) {
REFLECT(width); REFLECT(width);
REFLECT(position); REFLECT(position);
...@@ -39,13 +42,17 @@ IMPLEMENT_REFLECTION(ColumnSettings) { ...@@ -39,13 +42,17 @@ IMPLEMENT_REFLECTION(ColumnSettings) {
IMPLEMENT_REFLECTION(GameSettings) { IMPLEMENT_REFLECTION(GameSettings) {
REFLECT(default_stylesheet); REFLECT(default_stylesheet);
REFLECT(default_export); REFLECT(default_export);
// REFLECT_N("cardlist columns", columns); REFLECT_N("cardlist columns", columns);
REFLECT(sort_cards_by); REFLECT(sort_cards_by);
REFLECT(sort_cards_ascending); REFLECT(sort_cards_ascending);
} }
IMPLEMENT_REFLECTION(StyleSheetSettings) { IMPLEMENT_REFLECTION(StyleSheetSettings) {
// TODO REFLECT(card_zoom);
REFLECT(card_angle);
REFLECT(card_anti_alias);
REFLECT(card_borders);
REFLECT(card_normal_export);
} }
// ----------------------------------------------------------------------------- : Settings // ----------------------------------------------------------------------------- : Settings
...@@ -89,7 +96,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field ...@@ -89,7 +96,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field
ColumnSettings& cs = gs.columns[field.name]; ColumnSettings& cs = gs.columns[field.name];
if (cs.position == COLUMN_NOT_INITIALIZED) { if (cs.position == COLUMN_NOT_INITIALIZED) {
// column info not set, initialize based on the game // 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.position = field.card_list_column;
cs.width = field.card_list_width; cs.width = field.card_list_width;
} }
...@@ -114,7 +121,9 @@ String Settings::settingsFile() { ...@@ -114,7 +121,9 @@ String Settings::settingsFile() {
} }
IMPLEMENT_REFLECTION(Settings) { 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(recent_sets);
REFLECT(set_window_maximized); REFLECT(set_window_maximized);
REFLECT(set_window_width); REFLECT(set_window_width);
...@@ -124,9 +133,9 @@ IMPLEMENT_REFLECTION(Settings) { ...@@ -124,9 +133,9 @@ IMPLEMENT_REFLECTION(Settings) {
REFLECT(apprentice_location); REFLECT(apprentice_location);
REFLECT(updates_url); REFLECT(updates_url);
REFLECT(check_updates); REFLECT(check_updates);
// ioAll(io, game_settings); REFLECT(game_settings);
// ioStyleSettings(io); REFLECT(stylesheet_settings);
// REFLECT(default_style_settings); REFLECT(default_stylesheet_settings);
} }
void Settings::read() { void Settings::read() {
......
...@@ -159,7 +159,7 @@ void SymbolPart::calculateBounds() { ...@@ -159,7 +159,7 @@ void SymbolPart::calculateBounds() {
// ----------------------------------------------------------------------------- : Symbol // ----------------------------------------------------------------------------- : Symbol
IMPLEMENT_REFLECTION(Symbol) { IMPLEMENT_REFLECTION(Symbol) {
//%% version? tag.handleAppVersion();
REFLECT(parts); REFLECT(parts);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <gui/control/card_list.hpp> #include <gui/control/card_list.hpp>
#include <gui/control/card_list_column_select.hpp>
#include <data/game.hpp> #include <data/game.hpp>
#include <data/field.hpp> #include <data/field.hpp>
#include <data/field/choice.hpp> #include <data/field/choice.hpp>
...@@ -282,10 +283,10 @@ void CardListBase::storeColumns() { ...@@ -282,10 +283,10 @@ void CardListBase::storeColumns() {
gs.sort_cards_ascending = sort_ascending; gs.sort_cards_ascending = sort_ascending;
} }
void CardListBase::selectColumns() { void CardListBase::selectColumns() {
// CardListColumnSelect wnd(this, set->game); CardListColumnSelectDialog wnd(this, set->game);
// if (wnd.ShowModal() == wxID_OK) { if (wnd.ShowModal() == wxID_OK) {
// rebuild(); // columns have changed rebuild(); // columns have changed
// } }
} }
// ----------------------------------------------------------------------------- : CardListBase : Item 'events' // ----------------------------------------------------------------------------- : CardListBase : Item 'events'
......
//+----------------------------------------------------------------------------+
//| 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 <gui/control/card_list_column_select.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
#include <util/window_id.hpp>
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 ()
//+----------------------------------------------------------------------------+
//| 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 <util/prec.hpp>
#include <data/settings.hpp>
DECLARE_POINTER_TYPE(Game);
DECLARE_POINTER_TYPE(Field);
// ----------------------------------------------------------------------------- : CardListColumnSelectDialog
/// A dialog for selecting the card list columns to show and their order
/** Layout
* | <X> col a | <^>
* | < > col b | <V>
* | <X> col b |
*
* <ok> <cancel>
*/
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<ColumnSettingsF> 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
...@@ -351,12 +351,12 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) { ...@@ -351,12 +351,12 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
break; break;
} }
// copy & paste & find // 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_COPY : ev.Enable(current_panel->canCopy()); break;
case ID_EDIT_PASTE : ev.Enable(current_panel->canPaste()); 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 : ev.Enable(current_panel->canFind()); break;
case ID_EDIT_FIND_NEXT : 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: default:
// items created by the panel, and cut/copy/paste and find/replace // items created by the panel, and cut/copy/paste and find/replace
current_panel->onUpdateUI(ev); current_panel->onUpdateUI(ev);
......
...@@ -29,7 +29,6 @@ class GetDefaultMember { ...@@ -29,7 +29,6 @@ class GetDefaultMember {
inline bool reading() const { return false; } inline bool reading() const { return false; }
inline bool isComplex() const { return false; } inline bool isComplex() const { return false; }
inline void addAlias(int, const Char*, const Char*) {} inline void addAlias(int, const Char*, const Char*) {}
inline void handleAppVersion() {} // no effect inline void handleAppVersion() {} // no effect
/// The result, or script_nil if the member was not found /// The result, or script_nil if the member was not found
...@@ -70,6 +69,7 @@ class GetMember : private GetDefaultMember { ...@@ -70,6 +69,7 @@ class GetMember : private GetDefaultMember {
inline bool reading() const { return false; } inline bool reading() const { return false; }
inline bool isComplex() const { return false; } inline bool isComplex() const { return false; }
inline void addAlias(int, const Char*, const Char*) {} inline void addAlias(int, const Char*, const Char*) {}
inline void handleAppVersion() {} // no effect
/// The result, or script_nil if the member was not found /// The result, or script_nil if the member was not found
inline ScriptValueP result() { return gdm.result(); } inline ScriptValueP result() { return gdm.result(); }
......
...@@ -395,10 +395,10 @@ void Packaged::open(const String& package) { ...@@ -395,10 +395,10 @@ void Packaged::open(const String& package) {
} }
} }
void Packaged::save() { void Packaged::save() {
//writeFile(thisT().fileName, thisT()); // writeFile(thisT().fileName, thisT());
Package::save(); Package::save();
} }
void Packaged::saveAs(const String& package) { void Packaged::saveAs(const String& package) {
//writeFile(thisT().fileName, thisT()); // writeFile(thisT().fileName, thisT());
Package::saveAs(package); Package::saveAs(package);
} }
...@@ -104,8 +104,8 @@ class Package { ...@@ -104,8 +104,8 @@ class Package {
/// Open a file given an absolute filename /// Open a file given an absolute filename
static InputStreamP openAbsoluteFile(const String& name); static InputStreamP openAbsoluteFile(const String& name);
/*
// --------------------------------------------------- : Managing the inside of the package : IO files /* // --------------------------------------------------- : Managing the inside of the package : IO files
template <typename T> template <typename T>
void readFile<T> (String n, T& obj) { void readFile<T> (String n, T& obj) {
......
...@@ -163,6 +163,10 @@ enum ControlID { ...@@ -163,6 +163,10 @@ enum ControlID {
, ID_SEPARATOR , ID_SEPARATOR
, ID_REMINDER , ID_REMINDER
, ID_RULES , ID_RULES
, ID_MOVE_UP
, ID_MOVE_DOWN
, ID_SHOW
, ID_HIDE
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment