mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
(partially working) keyword list
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@230 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -167,13 +167,8 @@ bool CardListBase::compareItems(void* a, void* b) const {
|
||||
FieldP sort_field = column_fields[sort_by_column];
|
||||
ValueP va = reinterpret_cast<Card*>(a)->data[sort_field];
|
||||
ValueP vb = reinterpret_cast<Card*>(b)->data[sort_field];
|
||||
if (sort_ascending) {
|
||||
if (!va || !vb) return va < vb; // got to do something, compare pointers
|
||||
return smart_less( va->toString() , vb->toString() );
|
||||
} else {
|
||||
if (!va || !vb) return vb < va;
|
||||
return smart_less( vb->toString() , va->toString() );
|
||||
}
|
||||
if (!va || !vb) return va < vb; // got to do something, compare pointers
|
||||
return smart_less( va->toString() , vb->toString() );
|
||||
}
|
||||
|
||||
void CardListBase::rebuild() {
|
||||
|
||||
@@ -93,7 +93,11 @@ struct ItemList::ItemComparer {
|
||||
ItemList& list; // 'this' pointer
|
||||
// Compare two items using the current criterium and order
|
||||
bool operator () (const VoidP& a, const VoidP& b) {
|
||||
return list.compareItems(a.get(), b.get());
|
||||
if (list.sort_ascending) {
|
||||
return list.compareItems(a.get(), b.get());
|
||||
} else {
|
||||
return list.compareItems(b.get(), a.get());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,7 +128,6 @@ void ItemList::sortBy(long column, bool ascending) {
|
||||
} else if (i == sort_by_column) {
|
||||
ClearColumnImage(i);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
// sort list
|
||||
sort_by_column = column;
|
||||
|
||||
@@ -45,7 +45,7 @@ class ItemList : public wxListView {
|
||||
|
||||
/// Is sorting required?
|
||||
virtual bool mustSort() const { return false; }
|
||||
/// Compare two items for <
|
||||
/// Compare two items for < based on sort_by_column (not on sort_ascending)
|
||||
virtual bool compareItems(void* a, void* b) const = 0;
|
||||
|
||||
// --------------------------------------------------- : Protected interface
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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/keyword_list.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(KeywordP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
DEFINE_EVENT_TYPE(EVENT_KEYWORD_SELECT);
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordList
|
||||
|
||||
KeywordList::KeywordList(Window* parent, int id, long additional_style)
|
||||
: ItemList(parent, id, additional_style)
|
||||
{
|
||||
// Add columns
|
||||
InsertColumn(0, _LABEL_("keyword"), wxLIST_FORMAT_LEFT, 100);
|
||||
InsertColumn(1, _LABEL_("match"), wxLIST_FORMAT_LEFT, 200);
|
||||
InsertColumn(2, _LABEL_("mode"), wxLIST_FORMAT_LEFT, 100);
|
||||
InsertColumn(3, _LABEL_("uses"), wxLIST_FORMAT_RIGHT, 80);
|
||||
InsertColumn(4, _LABEL_("reminder"), wxLIST_FORMAT_LEFT, 300);
|
||||
}
|
||||
|
||||
KeywordList::~KeywordList() {
|
||||
storeColumns();
|
||||
}
|
||||
void KeywordList::storeColumns() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void KeywordList::onBeforeChangeSet() {
|
||||
storeColumns();
|
||||
}
|
||||
void KeywordList::onChangeSet() {
|
||||
refreshList();
|
||||
}
|
||||
|
||||
void KeywordList::onAction(const Action& action, bool undone) {
|
||||
//TYPE_CASE(action, AddKeywordAction) {
|
||||
//}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordListBase : for ItemList
|
||||
|
||||
void KeywordList::getItems(vector<VoidP>& out) const {
|
||||
FOR_EACH(k, set->keywords) {
|
||||
out.push_back(k);
|
||||
}
|
||||
FOR_EACH(k, set->game->keywords) {
|
||||
out.push_back(k);
|
||||
}
|
||||
}
|
||||
void KeywordList::sendEvent() {
|
||||
KeywordSelectEvent ev(getKeyword());
|
||||
ProcessEvent(ev);
|
||||
}
|
||||
bool KeywordList::compareItems(void* a, void* b) const {
|
||||
const Keyword& ka = *(Keyword*)a;
|
||||
const Keyword& kb = *(Keyword*)b;
|
||||
switch(sort_by_column) {
|
||||
case 0: return ka.keyword < kb.keyword;
|
||||
case 1: return ka.match < kb.match;
|
||||
case 2: return ka.mode < kb.mode;
|
||||
//case 3:
|
||||
//case 4:
|
||||
default: // TODO: 3 and 4
|
||||
return ka.keyword < kb.keyword;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordListBase : Item text
|
||||
|
||||
String KeywordList::OnGetItemText (long pos, long col) const {
|
||||
const Keyword& kw = *getKeyword(pos);
|
||||
switch(col) {
|
||||
case 0: return kw.keyword;
|
||||
case 1: return kw.match;
|
||||
case 2: return kw.mode;
|
||||
case 3: return _("TODO");
|
||||
case 4: return _("TODO");
|
||||
default: return wxEmptyString;
|
||||
}
|
||||
}
|
||||
int KeywordList::OnGetItemImage(long pos) const {
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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_KEYWORD_LIST
|
||||
#define HEADER_GUI_CONTROL_KEYWORD_LIST
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/item_list.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
#include <data/set.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
DECLARE_EVENT_TYPE(EVENT_KEYWORD_SELECT, <not used>)
|
||||
/// Handle KeywordSelectEvents
|
||||
#define EVT_KEYWORD_SELECT(id, handler) \
|
||||
DECLARE_EVENT_TABLE_ENTRY(EVENT_KEYWORD_SELECT, id, -1, \
|
||||
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
|
||||
(void (wxEvtHandler::*)(KeywordSelectEvent&)) (&handler), (wxObject*) NULL),
|
||||
|
||||
/// The event of selecting a keyword
|
||||
struct KeywordSelectEvent : public wxCommandEvent {
|
||||
KeywordP keyword; ///< The selected keyword
|
||||
inline KeywordSelectEvent(const KeywordP& keyword)
|
||||
: wxCommandEvent(EVENT_KEYWORD_SELECT), keyword(keyword)
|
||||
{}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordList
|
||||
|
||||
/// A control that lists the keywords in a set and its game
|
||||
class KeywordList : public ItemList, public SetView {
|
||||
public:
|
||||
KeywordList(Window* parent, int id, long additional_style = 0);
|
||||
~KeywordList();
|
||||
|
||||
// --------------------------------------------------- : Set stuff
|
||||
|
||||
virtual void onBeforeChangeSet();
|
||||
virtual void onChangeSet();
|
||||
virtual void onAction(const Action&, bool);
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
inline KeywordP getKeyword() const { return static_pointer_cast<Keyword>(selected_item); }
|
||||
inline void setKeyword(const KeywordP& kw) { selectItem(kw, true, false); }
|
||||
|
||||
// --------------------------------------------------- : The keywords
|
||||
protected:
|
||||
/// Get a list of all keywords
|
||||
virtual void getItems(vector<VoidP>& out) const;
|
||||
/// Return the keyword at the given position in the sorted keyword list
|
||||
inline KeywordP getKeyword(long pos) const { return static_pointer_cast<Keyword>(getItem(pos)); }
|
||||
|
||||
/// Send an 'item selected' event for the currently selected item (selected_item)
|
||||
virtual void sendEvent();
|
||||
/// Compare cards
|
||||
virtual bool compareItems(void* a, void* b) const;
|
||||
|
||||
/// Get the text of an item in a specific column
|
||||
/** Overrides a function from wxListCtrl */
|
||||
virtual String OnGetItemText (long pos, long col) const;
|
||||
/// Get the image of an item, by default no image is used
|
||||
/** Overrides a function from wxListCtrl */
|
||||
virtual int OnGetItemImage(long pos) const;
|
||||
|
||||
private:
|
||||
void storeColumns();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -7,48 +7,28 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/set/keywords_panel.hpp>
|
||||
#include <gui/control/keyword_list.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
#include <wx/listctrl.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordsList
|
||||
|
||||
/// A control that lists the keywords in a set or game
|
||||
class KeywordList : public wxListView {
|
||||
public:
|
||||
KeywordList(Window* parent, int id);
|
||||
|
||||
/// Set the list of keywords to show
|
||||
void setData(vector<KeywordP>& dat);
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
inline KeywordP getKeyword() const { return selected_keyword; }
|
||||
inline void setKeyword(const KeywordP& kw) { /* TODO */ }
|
||||
|
||||
bool canSelectPrevious() const;
|
||||
bool canSelectNext() const;
|
||||
void selectPrevious();
|
||||
void selectNext();
|
||||
|
||||
protected:
|
||||
/// Get the text of an item in a specific column
|
||||
/** Overrides a function from wxListCtrl */
|
||||
virtual String OnGetItemText (long pos, long col) const;
|
||||
private:
|
||||
KeywordP selected_keyword;
|
||||
long selected_keyword_pos;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordsPanel
|
||||
|
||||
KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
: SetWindowPanel(parent, id)
|
||||
{
|
||||
// init controls
|
||||
list = new KeywordList(this, wxID_ANY);
|
||||
// init sizer
|
||||
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
|
||||
s->Add(new wxStaticText(this, wxID_ANY, _("Sorry, no keywords for now"),wxDefaultPosition,wxDefaultSize,wxALIGN_CENTER), 1, wxALIGN_CENTER); // TODO: Remove
|
||||
s->Add(list, 1, wxEXPAND);
|
||||
//s->Add(new wxStaticText(this, wxID_ANY, _("Sorry, no keywords for now"),wxDefaultPosition,wxDefaultSize,wxALIGN_CENTER), 1, wxALIGN_CENTER); // TODO: Remove
|
||||
/* wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
|
||||
s2->Add(list_active, 1, wxEXPAND);
|
||||
s2->Add(list_inactive, 1, wxEXPAND);*/
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
}
|
||||
|
||||
void KeywordsPanel::onChangeSet() {
|
||||
list->setSet(set);
|
||||
}
|
||||
@@ -20,6 +20,9 @@ class KeywordList;
|
||||
class KeywordsPanel : public SetWindowPanel {
|
||||
public:
|
||||
KeywordsPanel(Window* parent, int id);
|
||||
|
||||
virtual void onChangeSet();
|
||||
|
||||
private:
|
||||
KeywordList* list;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user