mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
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
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/control/card_list.hpp>
|
||||
#include <gui/control/card_list_column_select.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <data/field/choice.hpp>
|
||||
@@ -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'
|
||||
|
||||
@@ -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 <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 ()
|
||||
@@ -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 <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) {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user