Commit 53783d4c authored by twanvl's avatar twanvl

Implemented CardsPanel with just a CardList for now

parent 76b5e931
......@@ -39,6 +39,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(type);
}
REFLECT(name);
if (tag.reading()) name = cannocial_name_form(name);
REFLECT(description);
REFLECT(editable);
REFLECT(save_value);
......@@ -48,6 +49,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_width);
REFLECT(card_list_allow);
REFLECT(card_list_name);
if (tag.reading() && card_list_name.empty()) card_list_name = name;
REFLECT_N("card_list_alignment", card_list_align);
REFLECT(tab_index);
}
......
......@@ -26,7 +26,7 @@ class Field {
Field();
virtual ~Field();
UInt index; ///< Used by IndexMap
size_t index; ///< Used by IndexMap
String name; ///< Name of the field, for refering to it from scripts and files
String description; ///< Description, used in status bar
bool editable; ///< Can values of this field be edited?
......@@ -56,7 +56,9 @@ class Field {
template <>
shared_ptr<Field> read_new<Field>(Reader& reader);
inline void update_index(FieldP& f, size_t index) {
f->index = index;
}
// ----------------------------------------------------------------------------- : Style
......
......@@ -128,7 +128,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) {
if (isGroup() || (tag.reading() && tag.isComplex())) {
// complex values are groups
REFLECT(name);
REFLECT_N("group choice", default_name);
REFLECT_N("group_choice", default_name);
REFLECT(choices);
} else {
REFLECT_NAMELESS(name);
......
......@@ -45,7 +45,10 @@ SetView::~SetView() {
void SetView::setSet(const SetP& newSet) {
// no longer listening to old set
if (set) set->actions.removeListener(this);
if (set) {
onBeforeChangeSet();
set->actions.removeListener(this);
}
set = newSet;
// start listening to new set
if (set) set->actions.addListener(this);
......
......@@ -9,6 +9,7 @@
#include <gui/control/card_list.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
#include <data/field/choice.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/settings.hpp>
......@@ -16,6 +17,7 @@
DECLARE_TYPEOF_COLLECTION(CardP);
DECLARE_TYPEOF_COLLECTION(FieldP);
DECLARE_POINTER_TYPE(ChoiceValue);
typedef map<int,FieldP> map_int_FieldP;
DECLARE_TYPEOF(map_int_FieldP);
......@@ -26,7 +28,14 @@ DEFINE_EVENT_TYPE(EVENT_CARD_SELECT);
// ----------------------------------------------------------------------------- : CardListBase
CardListBase::CardListBase(Window* parent, int id, int additional_style)
{}
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | wxLC_SINGLE_SEL)
{
// create image list
wxImageList* il = new wxImageList(18,14);
il->Add(Bitmap(_("SORT_ASC")), Color(255,0,255));
il->Add(Bitmap(_("SORT_DESC")), Color(255,0,255));
AssignImageList(il, wxIMAGE_LIST_SMALL);
}
CardListBase::~CardListBase() {
storeColumns();
......@@ -48,6 +57,21 @@ vector<CardP>& CardListBase::getCards() const {
// ----------------------------------------------------------------------------- : CardListBase : Selection
bool CardListBase::canSelectPrevious() const {
return selected_card_pos + 1 >= 0;
}
bool CardListBase::canSelectNext() const {
return selected_card_pos >= 0 && static_cast<size_t>(selected_card_pos + 1) < sorted_card_list.size();
}
void CardListBase::selectPrevious() {
// TODO
}
void CardListBase::selectNext() {
// TODO
}
// ----------------------------------------------------------------------------- : CardListBase : Selection (private)
void CardListBase::selectCard(const CardP& card, bool focus) {
selected_card = card;
CardSelectEvent ev(card);
......@@ -73,6 +97,7 @@ void CardListBase::selectCardPos(size_t pos, bool focus = true, bool force = fal
void CardListBase::findSelectedCardPos() {
// find the position of the selected card
long count = GetItemCount();
selected_card_pos = -1;
for (long pos = 0 ; pos < count ; ++pos) {
if (sorted_card_list[pos] == selected_card) {
selected_card_pos = pos;
......@@ -82,8 +107,14 @@ void CardListBase::findSelectedCardPos() {
}
void CardListBase::selectCurrentCard() {
if (GetItemCount() > 0) {
SetItemState(selected_card_pos, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED,
wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
if (selected_card_pos == -1) {
// deselect currently selected item, if any
long sel = GetFirstSelected();
Select(sel, false);
} else {
Select(selected_card_pos);
Focus(selected_card_pos);
}
}
}
......@@ -230,10 +261,10 @@ int CardListBase::OnGetItemImage(long pos) const {
wxListItemAttr* CardListBase::OnGetItemAttr(long pos) const {
if (!color_style) return nullptr;
// ChoiceValueP val = static_cast<ChoiceValueP>( sorted_car_list[cardPos]->data[color_field]);
// assert(val);
// itemAttr.textColour = colorStyle->choiceColors#(val->value); // if it doesn't exist we get black
return &itemAttr;
ChoiceValueP val = static_pointer_cast<ChoiceValue>( sorted_card_list[pos]->data[color_style->fieldP]);
assert(val);
item_attr.SetTextColour(color_style->choice_colors[val->value()]); // if it doesn't exist we get black
return &item_attr;
}
// ----------------------------------------------------------------------------- : CardListBase : Window events
......@@ -244,7 +275,7 @@ void CardListBase::onColumnClick(wxListEvent& ev) {
if (sort_ascending) {
sort_ascending = false; // 2nd click on same column -> sort descending
} else {
sort_criterium.reset(); // 3rd click on same column -> don't sort
new_sort_criterium.reset(); // 3rd click on same column -> don't sort
}
} else {
sort_ascending = true;
......@@ -253,16 +284,11 @@ void CardListBase::onColumnClick(wxListEvent& ev) {
int i = 0;
FOR_EACH(f, column_fields) {
if (f == new_sort_criterium) {
wxListItem li;
li.m_mask = wxLIST_MASK_IMAGE;
li.m_image = sort_ascending ? 0 : 1; // arrow up/down
SetColumn(i, li);
SetColumnImage(i, sort_ascending ? 0 : 1); // arrow up/down
} else if (f == sort_criterium) {
wxListItem li;
li.m_mask = wxLIST_MASK_IMAGE;
li.m_image = -1; // no sort icon
SetColumn(i, li);
ClearColumnImage(i);
}
++i;
}
sort_criterium = new_sort_criterium;
refreshList();
......@@ -303,7 +329,7 @@ void CardListBase::onDrag(wxMouseEvent& ev) {
// ----------------------------------------------------------------------------- : CardListBase : Event table
BEGIN_EVENT_TABLE(CardListBase, wxListCtrl)
BEGIN_EVENT_TABLE(CardListBase, wxListView)
EVT_LIST_COL_CLICK (wxID_ANY, CardListBase::onColumnClick)
EVT_LIST_COL_RIGHT_CLICK (wxID_ANY, CardListBase::onColumnRightClick)
EVT_LIST_ITEM_FOCUSED (wxID_ANY, CardListBase::onItemFocus)
......
......@@ -42,7 +42,7 @@ struct CardSelectEvent : public wxCommandEvent {
* This class is an abstract base class for card lists, derived classes must overload:
* - getCard(index)
*/
class CardListBase : public wxListCtrl, public SetView {
class CardListBase : public wxListView, public SetView {
public:
CardListBase(Window* parent, int id, int additional_style = 0);
~CardListBase();
......@@ -52,14 +52,14 @@ class CardListBase : public wxListCtrl, public SetView {
inline CardP getCard() const { return selected_card; }
inline void setCard(const CardP& card) { selectCard(card); }
/// Is there a previous card to select?
bool canSelectPrevious() const;
/// Is there a next card to select?
bool canSelectNext() const;
/// Move the selection to the previous card (if possible)
void selectPrevious();
/// Move the selection to the next card (if possible)
void selectNext();
/// Is there a previous card to select?
bool canSelectPrevious();
/// Is there a next card to select?
bool canSelectNext();
// --------------------------------------------------- : Clipboard
......@@ -104,10 +104,10 @@ class CardListBase : public wxListCtrl, public SetView {
FieldP sort_criterium; ///< Field to sort by
bool sort_ascending; ///< Sort order
mutable wxListItemAttr itemAttr; // for OnGetItemAttr
mutable wxListItemAttr item_attr; // for OnGetItemAttr
/// Get a card by position
void getCard(long pos);
// /// Get a card by position
// void getCard(long pos);
/// Select a card, send an event to the parent
/** If focus then the card is also focused and selected in the actual control.
......
......@@ -7,5 +7,205 @@
// ----------------------------------------------------------------------------- : Includes
#include <gui/set/cards_panel.hpp>
#include <gui/control/card_list.hpp>
#include <gui/icon_menu.hpp>
#include <data/set.hpp>
#include <data/action/set.hpp>
#include <data/settings.hpp>
#include <util/window_id.hpp>
#include <wx/splitter.h>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : CardsPanel
CardsPanel::CardsPanel(Window* parent, int id)
: SetWindowPanel(parent, id, false)
{
// init controls
// splitter = new SplitterWindow(&this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
// card_list = new EditCardList(splitter, idCardList);
// card_list = new EditCardList(splitter, ID_CARD_LIST);
card_list = new CardListBase(this, ID_CARD_LIST);
// init splitter
// splitter->minimumPaneSize = 14;
// splitter->sashGravity = 1.0;
// splitter->splitHorizontally(cardList, notesP, -40);
// init sizer
/* Sizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(editor, 0, wxRIGHT, 2);
s->Add(splitter, 1, wxEXPAND);
s->SetSizeHints(this);
SetSizer(s);
*/
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(card_list, 1, wxEXPAND);
SetSizer(s);
}
CardsPanel::~CardsPanel() {
// settings.card_notes_height = splitter->GetSashPosition();
}
void CardsPanel::onChangeSet() {
// editor->setSet(set);
card_list->setSet(set);
/* // resize editor
Sizer* s = sizer;
minSize = s->minSize;
layout();*/
}
// ----------------------------------------------------------------------------- : UI
void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
// Toolbar
tb->AddTool(ID_FORMAT_BOLD, _(""), Bitmap(_("TOOL_BOLD")), wxNullBitmap, wxITEM_CHECK, _("Bold"));
tb->AddTool(ID_FORMAT_ITALIC, _(""), Bitmap(_("TOOL_ITALIC")), wxNullBitmap, wxITEM_CHECK, _("Italic"));
tb->AddTool(ID_FORMAT_SYMBOL, _(""), Bitmap(_("TOOL_SYMBOL")), wxNullBitmap, wxITEM_CHECK, _("Symbols"));
tb->AddSeparator();
tb->AddTool(ID_CARD_ADD, _(""), Bitmap(_("TOOL_CARD_ADD")), wxNullBitmap, wxITEM_NORMAL,_("Add card"));
tb->AddTool(ID_CARD_REMOVE, _(""), Bitmap(_("TOOL_CARD_DEl")), wxNullBitmap, wxITEM_NORMAL,_("Remove selected card"));
tb->AddSeparator();
tb->AddTool(ID_CARD_ROTATE, _(""), Bitmap(_("TOOL_CARD_ROTATE")),wxNullBitmap,wxITEM_NORMAL,_("Rotate card"));
tb->Realize();
// Menus
IconMenu* menuCard = new IconMenu();
menuCard->Append(ID_CARD_PREV, _("Select &Previous Card\tPgUp"), _("Selects the previous card in the list"));
menuCard->Append(ID_CARD_NEXT, _("Select &Next Card\tPgDn"), _("Selects the next card in the list"));
menuCard->AppendSeparator();
menuCard->Append(ID_CARD_ADD, _("TOOL_CARD_ADD"), _("&Add Card\tCtrl++"), _("Add a new, blank, card to this set"));
menuCard->Append(ID_CARD_ADD_MULT, _("TOOL_CARD_ADD_M"), _("Add &Multiple Cards..."), _("Add multiple cards to the set"));
// NOTE: space after "Del" prevents wx from making del an accellerator
// otherwise we delete a card when delete is pressed inside the editor
menuCard->Append(ID_CARD_REMOVE, _("TOOL_CARD_DEL"), _("&Remove Select Card\tDel "), _("Delete the selected card from this set"));
menuCard->AppendSeparator();
IconMenu* menuRotate = new IconMenu();
menuRotate->Append(ID_CARD_ROTATE_0, _("TOOL_CARD_ROTATE_0"), _("&Normal"), _("Display the card with the right side up"), wxITEM_CHECK);
menuRotate->Append(ID_CARD_ROTATE_270, _("TOOL_CARD_ROTATE_270"), _("Rotated 90 &Clockwise"), _("Display the card rotated clockwise"), wxITEM_CHECK);
menuRotate->Append(ID_CARD_ROTATE_90, _("TOOL_CARD_ROTATE_90"), _("Rotated 90 C&ounter Clockwise"), _("Display the card rotated counter-clockwise (anti-clockwise for the British)"), wxITEM_CHECK);
menuRotate->Append(ID_CARD_ROTATE_180, _("TOOL_CARD_ROTATE_180"), _("Rotated 180, &Up Side Down"), _("Display the card up side down"), wxITEM_CHECK);
menuCard->Append(wxID_ANY, _("TOOL_CARD_ROTATE"), _("&Orientation"), _("Orientation of the card display"), wxITEM_NORMAL, menuRotate);
menuCard->AppendSeparator();
// This probably belongs in the window menu, but there we can't remove the separator once it is added
menuCard->Append(ID_SELECT_COLUMNS, _("C&ard List Columns..."), _("Select what columns should be shown and in what order."));
mb->Insert(2, menuCard, _("&Cards"));
IconMenu* menuFormat = new IconMenu();
menuFormat->Append(ID_FORMAT_BOLD, _("TOOL_BOLD"), _("Bold\tCtrl+B"), _("Makes the selected text bold"), wxITEM_CHECK);
menuFormat->Append(ID_FORMAT_ITALIC, _("TOOL_ITALIC"), _("Italic\tCtrl+I"), _("Makes the selected text italic"), wxITEM_CHECK);
menuFormat->Append(ID_FORMAT_SYMBOL, _("TOOL_SYMBOL"), _("Symbols\tCtrl+M"), _("Draws the selected text with symbols"), wxITEM_CHECK);
mb->Insert(3, menuFormat, _("&Format"));
}
void CardsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
// Toolbar
tb->DeleteTool(ID_FORMAT_BOLD);
tb->DeleteTool(ID_FORMAT_ITALIC);
tb->DeleteTool(ID_FORMAT_SYMBOL);
tb->DeleteTool(ID_CARD_ADD);
tb->DeleteTool(ID_CARD_REMOVE);
tb->DeleteTool(ID_CARD_ROTATE);
// HACK: hardcoded size of rest of toolbar
tb->DeleteToolByPos(10); // delete separator
tb->DeleteToolByPos(10); // delete separator
// Menus
delete mb->Remove(3);
delete mb->Remove(2);
}
void CardsPanel::onUpdateUI(wxUpdateUIEvent& e) {
switch (e.GetId()) {
case ID_CARD_PREV: e.Enable(card_list->canSelectPrevious()); break;
case ID_CARD_NEXT: e.Enable(card_list->canSelectNext()); break;
/* case ID_CARD_ROTATE_0: e.Check(editor->rotation.angle == 0); break;
case ID_CARD_ROTATE_90: e.Check(editor->rotation.angle == 90); break;
case ID_CARD_ROTATE_180: e.Check(editor->rotation.angle == 180); break;
case ID_CARD_ROTATE_270: e.Check(editor->rotation.angle == 270); break;
case ID_CARD_REMOVE: e.Enable(set->cards.size() > 0); break;
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: {
if (focusedControl() == idEditor) {
e.Enable(editor->canFormat(e.id));
e.Check (editor->hasFormat(e.id));
} else {
e.Enable(false);
e.Check(false);
}
break;
}*/
}
}
void CardsPanel::onCommand(int id) {
switch (id) {
case ID_CARD_PREV:
card_list->selectPrevious();
break;
case ID_CARD_NEXT:
card_list->selectNext();
break;
case ID_CARD_ADD:
set->actions.add(new AddCardAction(*set));
break;
case ID_CARD_ROTATE:
set->actions.add(new RemoveCardAction(*set, card_list->getCard()));
break;
/* case idCardRotate {
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
ss.cardAngle = (ss.cardAngle + 90) % 360;
onRenderSettingsChange();
}
case idCardRotate0 {
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
ss.cardAngle = 0;
onRenderSettingsChange();
}
case idCardRotate90 {
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
ss.cardAngle = 90;
onRenderSettingsChange();
}
case idCardRotate180 {
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
ss.cardAngle = 180;
onRenderSettingsChange();
}
case idCardRotate270 {
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
ss.cardAngle = 270;
onRenderSettingsChange();
}
case idSelectColumns {
cardList->selectColumns();
}
case idFormatBold, idFormatItalic, idFormatSymbol, idFormatNoAuto {
if (focusedControl() == idEditor) {
editor->doFormat(id);
}
}*/
}
}
// ----------------------------------------------------------------------------- : Actions
bool CardsPanel::wantsToHandle(const Action&) const {
return false;
}
void CardsPanel::onAction(const Action& action) {
// TODO
}
void CardsPanel::onRenderSettingsChange() {
}
// ----------------------------------------------------------------------------- : Clipboard
// ----------------------------------------------------------------------------- : Searching
// ----------------------------------------------------------------------------- : Selection
CardP CardsPanel::selectedCard() const {
return card_list->getCard();
}
void CardsPanel::selectCard(const CardP& card) {
card_list->setCard(card);
// editor->setCard(card);
}
\ No newline at end of file
......@@ -12,6 +12,9 @@
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
class wxSplitterWindow;
class CardListBase;
// ----------------------------------------------------------------------------- : CardsPanel
/// A card list and card editor panel
......@@ -20,13 +23,8 @@ class CardsPanel : public SetWindowPanel {
CardsPanel(Window* parent, int id);
~CardsPanel();
void onSetChange();
// --------------------------------------------------- : Meta information
virtual String shortName();
virtual String longName();
virtual String description();
void onChangeSet();
// --------------------------------------------------- : UI
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
......@@ -36,7 +34,7 @@ class CardsPanel : public SetWindowPanel {
// --------------------------------------------------- : Actions
virtual bool wantsToHandle(const Action&);
virtual bool wantsToHandle(const Action&) const;
virtual void onAction(const Action&);
virtual void onRenderSettingsChange();
private:
......@@ -44,16 +42,16 @@ class CardsPanel : public SetWindowPanel {
public:
// --------------------------------------------------- : Clipboard
virtual bool canCut();
virtual bool canCopy();
virtual bool canPaste();
/* virtual bool canCut() const;
virtual bool canCopy() const;
virtual bool canPaste() const;
virtual void doCut();
virtual void doCopy();
virtual void doPaste();
// --------------------------------------------------- : Searching (find/replace)
virtual bool canFind();
virtual bool canReplace();
virtual bool canFind() const;
virtual bool canReplace() const;
virtual bool doFind(wxFindReplaceData& what);
virtual bool doReplace(wxFindReplaceData& what);
private:
......@@ -88,14 +86,14 @@ class CardsPanel : public SetWindowPanel {
public:
// --------------------------------------------------- : Selection
virtual CardP selectedCard();
virtual CardP selectedCard() const;
virtual void selectCard(const CardP& card);
private:
// --------------------------------------------------- : Controls
// wxSplitterWindow* splitter;
wxSplitterWindow* splitter;
// Editor* editor;
// EditCardList* cardList;
CardListBase* card_list;
// DataTextCtrl* notes;
// --------------------------------------------------- : Menus & tools
......
......@@ -113,16 +113,16 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
// NOTE: place the CardsPanel last in the panels list,
// this way the card list is the last to be told of a set change
// this way everyone else already uses the new set when it sends a CardSelectEvent
// addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 4, _("F5"), _("Cards"), _("Cards"));
addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 2, _("F5"), _("Cards"), _("Cards"), _("Edit the cards in the set"));
// addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6"));
addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Chnage the style of cards"));
addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Change the style of cards"));
// addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8"));
// addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 3, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set"));
//addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10"))
// selectPanel(idWindowMin + 4); // select cards panel
addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 0, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set"));
selectPanel(ID_WINDOW_MIN+1); // test
selectPanel(ID_WINDOW_MIN+2); // test
// loose ends
tabBar->Realize();
......
......@@ -100,6 +100,10 @@ enum ChildMenuID {
, ID_KEYWORD_PREV
, ID_KEYWORD_NEXT
// Format menu
, ID_FORMAT_BOLD = 1201
, ID_FORMAT_ITALIC
, ID_FORMAT_SYMBOL
// SymbolSelectEditor toolbar/menu
, ID_PART = 2001
......
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