mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implemented CardList
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@23 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+5
-6
@@ -16,7 +16,7 @@
|
|||||||
class Game;
|
class Game;
|
||||||
DECLARE_POINTER_TYPE(Field);
|
DECLARE_POINTER_TYPE(Field);
|
||||||
DECLARE_POINTER_TYPE(Value);
|
DECLARE_POINTER_TYPE(Value);
|
||||||
DECLARE_POINTER_TYPE(CardStyle);
|
DECLARE_POINTER_TYPE(StyleSheet);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Card
|
// ----------------------------------------------------------------------------- : Card
|
||||||
|
|
||||||
@@ -34,17 +34,16 @@ class Card {
|
|||||||
/// Get an identification of the card, an identification is something like a name, title, etc.
|
/// Get an identification of the card, an identification is something like a name, title, etc.
|
||||||
String identification() const;
|
String identification() const;
|
||||||
|
|
||||||
private:
|
/// The values on the fields of the card.
|
||||||
/// The values on the fields of the card
|
/** The indices should correspond to the cardFields in the Game */
|
||||||
/// The indices should correspond to the cardFields in the Game
|
|
||||||
IndexMap<FieldP, ValueP> data;
|
IndexMap<FieldP, ValueP> data;
|
||||||
|
|
||||||
/// Notes for this card
|
/// Notes for this card
|
||||||
String notes;
|
String notes;
|
||||||
|
|
||||||
/// Alternative style to use for this card
|
/// Alternative style to use for this card
|
||||||
/// Optional, if not set use the card style from the set
|
/** Optional; if not set use the card style from the set */
|
||||||
CardStyleP style;
|
StyleSheetP stylesheet;
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
|
|
||||||
#include <data/field.hpp>
|
#include <data/field.hpp>
|
||||||
#include <data/field/text.hpp>
|
#include <data/field/text.hpp>
|
||||||
|
#include <data/field/choice.hpp>
|
||||||
|
#include <data/field/boolean.hpp>
|
||||||
|
#include <data/field/image.hpp>
|
||||||
|
#include <data/field/symbol.hpp>
|
||||||
|
#include <data/field/color.hpp>
|
||||||
#include <util/error.hpp>
|
#include <util/error.hpp>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Field
|
// ----------------------------------------------------------------------------- : Field
|
||||||
|
|||||||
+4
-1
@@ -81,7 +81,10 @@ class Value {
|
|||||||
|
|
||||||
/// Create a copy of this value
|
/// Create a copy of this value
|
||||||
virtual ValueP clone() const = 0;
|
virtual ValueP clone() const = 0;
|
||||||
|
|
||||||
|
/// Convert this value to a string for use in tables
|
||||||
|
virtual String toString() const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_REFLECTION_VIRTUAL();
|
DECLARE_REFLECTION_VIRTUAL();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ IMPLEMENT_REFLECTION(TextStyle) {
|
|||||||
ValueP TextValue::clone() const {
|
ValueP TextValue::clone() const {
|
||||||
return new_shared1<TextValue>(*this);
|
return new_shared1<TextValue>(*this);
|
||||||
}
|
}
|
||||||
|
String TextValue::toString() const {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(TextValue) {
|
IMPLEMENT_REFLECTION(TextValue) {
|
||||||
REFLECT_BASE(Value);
|
REFLECT_BASE(Value);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class TextValue : public Value {
|
|||||||
Defaultable<String> value; ///< The text of this value
|
Defaultable<String> value; ///< The text of this value
|
||||||
|
|
||||||
virtual ValueP clone() const;
|
virtual ValueP clone() const;
|
||||||
|
virtual String toString() const;
|
||||||
private:
|
private:
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,8 +22,18 @@ bool Game::isMagic() const {
|
|||||||
return name() == _("magic");
|
return name() == _("magic");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Game::typeNameStatic() { return _("game"); }
|
||||||
String Game::typeName() const { return _("game"); }
|
String Game::typeName() const { return _("game"); }
|
||||||
|
|
||||||
|
String Game::fullName() const { return full_name; }
|
||||||
|
InputStreamP Game::openIconFile() {
|
||||||
|
if (!icon_filename.empty()) {
|
||||||
|
return openIn(icon_filename);
|
||||||
|
} else {
|
||||||
|
return InputStreamP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(Game) {
|
IMPLEMENT_REFLECTION(Game) {
|
||||||
// ioMseVersion(io, fileName, fileVersion);
|
// ioMseVersion(io, fileName, fileVersion);
|
||||||
REFLECT(full_name);
|
REFLECT(full_name);
|
||||||
|
|||||||
+5
-1
@@ -32,8 +32,12 @@ class Game : public Packaged {
|
|||||||
/// Is this Magic the Gathering?
|
/// Is this Magic the Gathering?
|
||||||
bool isMagic() const;
|
bool isMagic() const;
|
||||||
|
|
||||||
|
static String typeNameStatic();
|
||||||
|
virtual String typeName() const;
|
||||||
|
virtual String fullName() const;
|
||||||
|
virtual InputStreamP openIconFile();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String typeName() const;
|
|
||||||
void validate();
|
void validate();
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
|
|||||||
+21
-1
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <data/settings.hpp>
|
#include <data/settings.hpp>
|
||||||
#include <data/game.hpp>
|
#include <data/game.hpp>
|
||||||
|
#include <data/field.hpp>
|
||||||
#include <util/reflect.hpp>
|
#include <util/reflect.hpp>
|
||||||
#include <util/io/reader.hpp>
|
#include <util/io/reader.hpp>
|
||||||
#include <util/io/writer.hpp>
|
#include <util/io/writer.hpp>
|
||||||
@@ -23,6 +24,12 @@ IMPLEMENT_REFLECTION_ENUM(CheckUpdates) {
|
|||||||
VALUE_N("never", CHECK_NEVER);
|
VALUE_N("never", CHECK_NEVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int COLUMN_NOT_INITIALIZED = -100000;
|
||||||
|
|
||||||
|
ColumnSettings::ColumnSettings()
|
||||||
|
: width(100), position(COLUMN_NOT_INITIALIZED), visible(false)
|
||||||
|
{}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(ColumnSettings) {
|
IMPLEMENT_REFLECTION(ColumnSettings) {
|
||||||
REFLECT(width);
|
REFLECT(width);
|
||||||
REFLECT(position);
|
REFLECT(position);
|
||||||
@@ -37,7 +44,7 @@ IMPLEMENT_REFLECTION(GameSettings) {
|
|||||||
REFLECT(sort_cards_ascending);
|
REFLECT(sort_cards_ascending);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(StyleSettings) {
|
IMPLEMENT_REFLECTION(StyleSheetSettings) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +82,19 @@ GameSettings& Settings::gameSettingsFor(const Game& game) {
|
|||||||
if (!gs) gs.reset(new GameSettings);
|
if (!gs) gs.reset(new GameSettings);
|
||||||
return *gs;
|
return *gs;
|
||||||
}
|
}
|
||||||
|
ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field) {
|
||||||
|
// Get game info
|
||||||
|
GameSettings& gs = gameSettingsFor(game);
|
||||||
|
// Get column info
|
||||||
|
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.position = field.card_list_column;
|
||||||
|
cs.width = field.card_list_width;
|
||||||
|
}
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
StyleSettings& Settings::styleSettingsFor(const CardStyle& style) {
|
StyleSettings& Settings::styleSettingsFor(const CardStyle& style) {
|
||||||
StyleSettingsP& ss = settings.styleSettings#(style.name());
|
StyleSettingsP& ss = settings.styleSettings#(style.name());
|
||||||
|
|||||||
+23
-18
@@ -11,12 +11,14 @@
|
|||||||
|
|
||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
#include <util/reflect.hpp>
|
#include <util/reflect.hpp>
|
||||||
|
#include <util/defaultable.hpp>
|
||||||
|
|
||||||
class Game;
|
class Game;
|
||||||
class CardStyle;
|
class StyleSheet;
|
||||||
|
class Field;
|
||||||
|
|
||||||
DECLARE_POINTER_TYPE(GameSettings);
|
DECLARE_POINTER_TYPE(GameSettings);
|
||||||
DECLARE_POINTER_TYPE(StyleSettings);
|
DECLARE_POINTER_TYPE(StyleSheetSettings);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Extra data structures
|
// ----------------------------------------------------------------------------- : Extra data structures
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@ enum CheckUpdates
|
|||||||
/// Settings of a single column in the card list
|
/// Settings of a single column in the card list
|
||||||
class ColumnSettings {
|
class ColumnSettings {
|
||||||
public:
|
public:
|
||||||
|
ColumnSettings();
|
||||||
UInt width;
|
UInt width;
|
||||||
int position;
|
int position;
|
||||||
bool visible;
|
bool visible;
|
||||||
@@ -49,20 +52,20 @@ class GameSettings {
|
|||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Settings for a Style
|
/// Settings for a StyleSheet
|
||||||
class StyleSettings {
|
class StyleSheetSettings {
|
||||||
public:
|
public:
|
||||||
// Rendering/display settings
|
// Rendering/display settings
|
||||||
/* SimpleDefaultable<double> card_zoom = 1.0;
|
Defaultable<double> card_zoom;
|
||||||
SimpleDefaultable<int> card_angle = 0;
|
Defaultable<int> card_angle;
|
||||||
SimpleDefaultable<bool> card_anti_alias = true;
|
Defaultable<bool> card_anti_alias;
|
||||||
SimpleDefaultable<bool> card_borders = true;
|
Defaultable<bool> card_borders;
|
||||||
SimpleDefaultable<bool> card_normal_export = true;
|
Defaultable<bool> card_normal_export;
|
||||||
*/
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
|
|
||||||
// /// Where the settings are the default, use the value from ss
|
// /// Where the settings are the default, use the value from ss
|
||||||
// void useDefault(const StyleSettings& ss);
|
// void useDefault(const StyleSheetSettings& ss);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Settings
|
// ----------------------------------------------------------------------------- : Settings
|
||||||
@@ -92,17 +95,19 @@ class Settings {
|
|||||||
// --------------------------------------------------- : Default pacakge selections
|
// --------------------------------------------------- : Default pacakge selections
|
||||||
String default_game;
|
String default_game;
|
||||||
|
|
||||||
// --------------------------------------------------- : Game/style specific
|
// --------------------------------------------------- : Game/stylesheet specific
|
||||||
|
|
||||||
/// Get the settings object for a specific game
|
/// Get the settings object for a specific game
|
||||||
GameSettings& gameSettingsFor(const Game& game);
|
GameSettings& gameSettingsFor (const Game& game);
|
||||||
/// Get the settings object for a specific style
|
/// Get the settings for a column for a specific field in a game
|
||||||
StyleSettings& styleSettingsFor(const CardStyle& style);
|
ColumnSettings& columnSettingsFor (const Game& game, const Field& field);
|
||||||
|
/// Get the settings object for a specific stylesheet
|
||||||
|
StyleSheetSettings& styleSheetSettingsFor(const StyleSheet& stylesheet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
map<String,GameSettingsP> game_settings;
|
map<String,GameSettingsP> game_settings;
|
||||||
map<String,StyleSettingsP> style_settings;
|
map<String,StyleSheetSettingsP> stylesheet_settings;
|
||||||
StyleSettings default_style_settings;
|
StyleSheetSettings default_stylesheet_settings;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// --------------------------------------------------- : Special game stuff
|
// --------------------------------------------------- : Special game stuff
|
||||||
|
|||||||
@@ -0,0 +1,313 @@
|
|||||||
|
//+----------------------------------------------------------------------------+
|
||||||
|
//| 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.hpp>
|
||||||
|
#include <data/game.hpp>
|
||||||
|
#include <data/field.hpp>
|
||||||
|
#include <data/set.hpp>
|
||||||
|
#include <data/card.hpp>
|
||||||
|
#include <data/settings.hpp>
|
||||||
|
#include <util/window_id.hpp>
|
||||||
|
|
||||||
|
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||||
|
DECLARE_TYPEOF_COLLECTION(FieldP);
|
||||||
|
typedef map<int,FieldP> map_int_FieldP;
|
||||||
|
DECLARE_TYPEOF(map_int_FieldP);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Events
|
||||||
|
|
||||||
|
DEFINE_EVENT_TYPE(EVENT_CARD_SELECT);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase
|
||||||
|
|
||||||
|
CardListBase::CardListBase(Window* parent, int id, int additional_style)
|
||||||
|
{}
|
||||||
|
|
||||||
|
CardListBase::~CardListBase() {
|
||||||
|
storeColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::onBeforeChangeSet() {
|
||||||
|
storeColumns();
|
||||||
|
}
|
||||||
|
void CardListBase::onChangeSet() {
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
void CardListBase::onAction(const Action& action) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<CardP>& CardListBase::getCards() const {
|
||||||
|
return set->cards;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase : Selection
|
||||||
|
|
||||||
|
void CardListBase::selectCard(const CardP& card, bool focus) {
|
||||||
|
selected_card = card;
|
||||||
|
CardSelectEvent ev(card);
|
||||||
|
ProcessEvent(ev);
|
||||||
|
if (focus) {
|
||||||
|
findSelectedCardPos();
|
||||||
|
selectCurrentCard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
void CardListBase::selectCardPos(size_t pos, bool focus = true, bool force = false) {
|
||||||
|
if (selectedCardPos == pos && !force) return; // this card is already selected
|
||||||
|
if (pos < sortedCardList.size()) {
|
||||||
|
// only if there is something to select
|
||||||
|
selectCard(getCard(pos), false);
|
||||||
|
} else {
|
||||||
|
selectCard(CardP(), false);
|
||||||
|
}
|
||||||
|
selectedCardPos = Long(pos);
|
||||||
|
if (focus) selectCurrentCard();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
void CardListBase::findSelectedCardPos() {
|
||||||
|
// find the position of the selected card
|
||||||
|
long count = GetItemCount();
|
||||||
|
for (long pos = 0 ; pos < count ; ++pos) {
|
||||||
|
if (sorted_card_list[pos] == selected_card) {
|
||||||
|
selected_card_pos = pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void CardListBase::selectCurrentCard() {
|
||||||
|
if (GetItemCount() > 0) {
|
||||||
|
SetItemState(selected_card_pos, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED,
|
||||||
|
wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
||||||
|
|
||||||
|
// Comparison object for comparing cards
|
||||||
|
struct CardListBase::CardComparer {
|
||||||
|
CardComparer(CardListBase& cl) : cl(cl) {}
|
||||||
|
CardListBase& cl; // 'this' pointer
|
||||||
|
// Compare two cards using the current criterium and order
|
||||||
|
bool operator () (const CardP& a, const CardP& b) {
|
||||||
|
ValueP va = a->data[cl.sort_criterium];
|
||||||
|
ValueP vb = b->data[cl.sort_criterium];
|
||||||
|
if (cl.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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void CardListBase::sortList() {
|
||||||
|
sorted_card_list.clear();
|
||||||
|
FOR_EACH(card, getCards()) {
|
||||||
|
sorted_card_list.push_back(card);
|
||||||
|
}
|
||||||
|
if (sort_criterium) {
|
||||||
|
sort(sorted_card_list.begin(), sorted_card_list.end(), CardComparer(*this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::rebuild() {
|
||||||
|
ClearAll();
|
||||||
|
column_fields.clear();
|
||||||
|
selected_card_pos = -1;
|
||||||
|
// determine column order
|
||||||
|
map<int,FieldP> new_column_fields;
|
||||||
|
FOR_EACH(f, set->game->card_fields) {
|
||||||
|
ColumnSettings& cs = settings.columnSettingsFor(*set->game, *f);
|
||||||
|
if (cs.visible && f->card_list_allow) {
|
||||||
|
new_column_fields[cs.position] = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add columns
|
||||||
|
FOR_EACH(f, new_column_fields) {
|
||||||
|
ColumnSettings& cs = settings.columnSettingsFor(*set->game, *f.second);
|
||||||
|
int align;
|
||||||
|
if (f.second->card_list_align == ALIGN_RIGHT) align = wxLIST_FORMAT_RIGHT;
|
||||||
|
else if (f.second->card_list_align == ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE;
|
||||||
|
else align = wxLIST_FORMAT_LEFT;
|
||||||
|
InsertColumn((long)column_fields.size(), capitalize(f.second->card_list_name), align, cs.width);
|
||||||
|
column_fields.push_back(f.second);
|
||||||
|
}
|
||||||
|
// find field that determines color
|
||||||
|
color_style = findColorStyle();
|
||||||
|
// determine sort settings
|
||||||
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
|
sort_ascending = gs.sort_cards_ascending;
|
||||||
|
sort_criterium = FieldP();
|
||||||
|
int i = 0;
|
||||||
|
FOR_EACH(f, column_fields) {
|
||||||
|
if (f->name == gs.sort_cards_by) {
|
||||||
|
// we are sorting by this column, store the field
|
||||||
|
sort_criterium = f;
|
||||||
|
// and display an arrow in the header
|
||||||
|
wxListItem li;
|
||||||
|
li.m_mask = wxLIST_MASK_IMAGE;
|
||||||
|
li.m_image = sort_ascending ? 0 : 1; // arrow up/down
|
||||||
|
SetColumn(i, li);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refreshList();
|
||||||
|
// select a card if possible
|
||||||
|
// if (!getCards().empty()) {
|
||||||
|
// selectCardPos(0, true);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::refreshList() {
|
||||||
|
// ensure correct list size
|
||||||
|
long items = (long) getCards().size();
|
||||||
|
SetItemCount(items);
|
||||||
|
// (re)sort the list
|
||||||
|
sortList();
|
||||||
|
// refresh
|
||||||
|
RefreshItems(0, items - 1);
|
||||||
|
if (items == 0) Refresh();
|
||||||
|
// select
|
||||||
|
findSelectedCardPos();
|
||||||
|
selectCurrentCard();
|
||||||
|
}
|
||||||
|
|
||||||
|
ChoiceStyleP CardListBase::findColorStyle() {
|
||||||
|
/* FOR_EACH(s, set->default_stylesheet->card_style) {
|
||||||
|
ChoiceStyleP cs = dynamic_cast<ChoiceStyleP>(s);
|
||||||
|
if (cs && cs->colors_card_list) {
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return ChoiceStyleP();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase : Columns
|
||||||
|
|
||||||
|
void CardListBase::storeColumns() {
|
||||||
|
if (!set) return;
|
||||||
|
// store column widths
|
||||||
|
int i = 0;
|
||||||
|
FOR_EACH(f, column_fields) {
|
||||||
|
ColumnSettings& cs = settings.columnSettingsFor(*set->game, *f);
|
||||||
|
cs.width = GetColumnWidth(i++);
|
||||||
|
}
|
||||||
|
// store sorting
|
||||||
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
|
if (sort_criterium) gs.sort_cards_by = sort_criterium->name;
|
||||||
|
else gs.sort_cards_by = wxEmptyString;
|
||||||
|
gs.sort_cards_ascending = sort_ascending;
|
||||||
|
}
|
||||||
|
void CardListBase::selectColumns() {
|
||||||
|
// CardListColumnSelect wnd(this, set->game);
|
||||||
|
// if (wnd.ShowModal() == wxID_OK) {
|
||||||
|
// rebuild(); // columns have changed
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase : Item 'events'
|
||||||
|
|
||||||
|
String CardListBase::OnGetItemText(long pos, long col) const {
|
||||||
|
if (col < 0 || (size_t)col >= column_fields.size()) {
|
||||||
|
// wx may give us non existing columns!
|
||||||
|
return wxEmptyString;
|
||||||
|
}
|
||||||
|
ValueP val = sorted_card_list[pos]->data[column_fields[col]];
|
||||||
|
if (val) return val->toString();
|
||||||
|
else return wxEmptyString;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CardListBase::OnGetItemImage(long pos) const {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase : Window events
|
||||||
|
|
||||||
|
void CardListBase::onColumnClick(wxListEvent& ev) {
|
||||||
|
FieldP new_sort_criterium = column_fields[ev.GetColumn()];
|
||||||
|
if (sort_criterium == new_sort_criterium) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sort_ascending = true;
|
||||||
|
}
|
||||||
|
// Change image in column header
|
||||||
|
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);
|
||||||
|
} else if (f == sort_criterium) {
|
||||||
|
wxListItem li;
|
||||||
|
li.m_mask = wxLIST_MASK_IMAGE;
|
||||||
|
li.m_image = -1; // no sort icon
|
||||||
|
SetColumn(i, li);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort_criterium = new_sort_criterium;
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::onColumnRightClick(wxListEvent&) {
|
||||||
|
// show menu
|
||||||
|
wxMenu* m = new wxMenu;
|
||||||
|
m->Append(ID_SELECT_COLUMNS, _("&Select Columns..."), _("Select what columns should be shown and in what order."));
|
||||||
|
PopupMenu(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::onSelectColumns(wxCommandEvent&) {
|
||||||
|
selectColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::onItemFocus(wxListEvent& ev) {
|
||||||
|
// selectCardPos(ev.GetIndex(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::onChar(wxKeyEvent& ev) {
|
||||||
|
if (ev.GetKeyCode() == WXK_DELETE) {
|
||||||
|
// set->actions.add(new_shared2<RemoveCardAction>(set.get(), card));
|
||||||
|
} else if (ev.GetKeyCode() == WXK_TAB) {
|
||||||
|
// send a navigation event to our parent, to select another control
|
||||||
|
// we need this because tabs are not handled on the cards panel
|
||||||
|
wxNavigationKeyEvent nev;
|
||||||
|
nev.SetDirection(!ev.ShiftDown());
|
||||||
|
GetParent()->ProcessEvent(nev);
|
||||||
|
} else {
|
||||||
|
ev.Skip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardListBase::onDrag(wxMouseEvent& ev) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase : Event table
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(CardListBase, wxListCtrl)
|
||||||
|
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)
|
||||||
|
EVT_CHAR ( CardListBase::onChar)
|
||||||
|
EVT_MOTION ( CardListBase::onDrag)
|
||||||
|
EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns)
|
||||||
|
END_EVENT_TABLE ()
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
//+----------------------------------------------------------------------------+
|
||||||
|
//| 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
|
||||||
|
#define HEADER_GUI_CONTROL_CARD_LIST
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
|
#include <util/prec.hpp>
|
||||||
|
#include <data/set.hpp>
|
||||||
|
#include <wx/listctrl.h>
|
||||||
|
|
||||||
|
DECLARE_POINTER_TYPE(ChoiceStyle);
|
||||||
|
DECLARE_POINTER_TYPE(Field);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Events
|
||||||
|
|
||||||
|
DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>);
|
||||||
|
/// Handle CardSelectEvents
|
||||||
|
#define EVT_CARD_SELECT(id, handler) EVT_COMMAND(id, EVENT_CARD_SELECT, handler);
|
||||||
|
|
||||||
|
/// The event of selecting a card
|
||||||
|
struct CardSelectEvent : public wxCommandEvent {
|
||||||
|
CardP card; ///< The selected card
|
||||||
|
inline CardSelectEvent(const CardP& card)
|
||||||
|
: wxCommandEvent(EVENT_CARD_SELECT), card(card)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : CardListBase
|
||||||
|
|
||||||
|
/// A list view of the cards in a set.
|
||||||
|
/* This class allows the cards to be sorted, and has a _('currentCard'), the selected card
|
||||||
|
* when a card is selected, it raises a CardSelectEvent, that will propage to the parent window.
|
||||||
|
*
|
||||||
|
* Note: (long) pos refers to position in the sorted_card_list,
|
||||||
|
* (size_t) index refers to the index in the actual card list (as returned by getCards).
|
||||||
|
*
|
||||||
|
* This class is an abstract base class for card lists, derived classes must overload:
|
||||||
|
* - getCard(index)
|
||||||
|
*/
|
||||||
|
class CardListBase : public wxListCtrl, public SetView {
|
||||||
|
public:
|
||||||
|
CardListBase(Window* parent, int id, int additional_style = 0);
|
||||||
|
~CardListBase();
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Selection
|
||||||
|
|
||||||
|
inline CardP getCard() const { return selected_card; }
|
||||||
|
inline void setCard(const CardP& card) { selectCard(card); }
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
|
||||||
|
bool canCut() const;
|
||||||
|
bool canCopy() const;
|
||||||
|
bool canPaste() const;
|
||||||
|
void doCut();
|
||||||
|
void doCopy();
|
||||||
|
void doPaste();
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Set actions
|
||||||
|
|
||||||
|
virtual void onBeforeChangeSet();
|
||||||
|
virtual void onChangeSet();
|
||||||
|
virtual void onAction(const Action&);
|
||||||
|
|
||||||
|
// --------------------------------------------------- : The cards
|
||||||
|
protected:
|
||||||
|
/// What cards should be shown?
|
||||||
|
virtual vector<CardP>& getCards() const;
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Item 'events'
|
||||||
|
|
||||||
|
/// Get the text of an item in a specific column
|
||||||
|
/** Overrides a function from wxListCtrl */
|
||||||
|
String OnGetItemText (long pos, long col) const;
|
||||||
|
/// Get the image of an item, by default no image is used
|
||||||
|
/** Overrides a function from wxListCtrl */
|
||||||
|
int OnGetItemImage(long pos) const;
|
||||||
|
/// Get the color for an item
|
||||||
|
wxListItemAttr* OnGetItemAttr(long pos) const;
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Data
|
||||||
|
private:
|
||||||
|
CardP selected_card; ///< The currently selected card, or -1 if no card is selected
|
||||||
|
long selected_card_pos;///< Position of the selected card in the sorted_card_list
|
||||||
|
// display stuff
|
||||||
|
ChoiceStyleP color_style; ///< Style (and field) to use for text color (optional)
|
||||||
|
vector<FieldP> column_fields; ///< The field to use for each column (by column index)
|
||||||
|
// sorted list stuff
|
||||||
|
vector<CardP> sorted_card_list; ///< Sorted list of cards, can be considered a map: pos->card
|
||||||
|
FieldP sort_criterium; ///< Field to sort by
|
||||||
|
bool sort_ascending; ///< Sort order
|
||||||
|
|
||||||
|
mutable wxListItemAttr itemAttr; // for OnGetItemAttr
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
* This should abviously not be done when the card is selected because it was selected (leading to a loop).
|
||||||
|
*/
|
||||||
|
void selectCard(const CardP& card, bool focus = false);
|
||||||
|
/// Select a card at the specified position
|
||||||
|
void selectCardPos(long pos);
|
||||||
|
/// Find the position for the selected_card
|
||||||
|
void findSelectedCardPos();
|
||||||
|
/// Actually select the card at selected_card_pos in the control
|
||||||
|
void selectCurrentCard();
|
||||||
|
|
||||||
|
/// Sorts the list by the current sorting criterium
|
||||||
|
void sortList();
|
||||||
|
struct CardComparer; // for comparing cards
|
||||||
|
/// Rebuild the card list (clear all vectors and fill them again)
|
||||||
|
void rebuild();
|
||||||
|
/// Refresh the card list (resort, refresh and reselect current item)
|
||||||
|
void refreshList();
|
||||||
|
/// Find the field that determines the color, if any.
|
||||||
|
/** Note: Uses only fields from the set's default style */
|
||||||
|
ChoiceStyleP findColorStyle();
|
||||||
|
|
||||||
|
/// Store the column sizes in the settings
|
||||||
|
void storeColumns();
|
||||||
|
/// Open a dialog for selecting columns to be shown
|
||||||
|
void selectColumns();
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Window events
|
||||||
|
DECLARE_EVENT_TABLE();
|
||||||
|
|
||||||
|
void onColumnClick (wxListEvent& ev);
|
||||||
|
void onColumnRightClick(wxListEvent& ev);
|
||||||
|
void onSelectColumns (wxCommandEvent& ev);
|
||||||
|
void onItemFocus (wxListEvent& ev);
|
||||||
|
void onChar (wxKeyEvent& ev);
|
||||||
|
void onDrag (wxMouseEvent& ev);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
|
#endif
|
||||||
+11
-14
@@ -26,12 +26,9 @@ class SetWindowPanel : public wxPanel, public SetView {
|
|||||||
/// We will probably want to respond to set changes
|
/// We will probably want to respond to set changes
|
||||||
virtual void onSetChange() {}
|
virtual void onSetChange() {}
|
||||||
|
|
||||||
// --------------------------------------------------- : Meta information
|
// // --------------------------------------------------- : Meta information
|
||||||
|
//
|
||||||
virtual String shortName() { return _("<undefined>"); } ///< for tab bar
|
// virtual String helpFile() { return _(""); } ///< help file to use when this panel is active
|
||||||
virtual String longName() { return shortName(); } ///< for menu
|
|
||||||
virtual String description() { return _("<undefined>"); } ///< for status bar
|
|
||||||
virtual String helpFile() { return _(""); } ///< help file to use when this panel is active
|
|
||||||
|
|
||||||
// --------------------------------------------------- : UI
|
// --------------------------------------------------- : UI
|
||||||
|
|
||||||
@@ -49,29 +46,29 @@ class SetWindowPanel : public wxPanel, public SetView {
|
|||||||
// --------------------------------------------------- : Actions/Events
|
// --------------------------------------------------- : Actions/Events
|
||||||
|
|
||||||
/// Should return true if this panel wants to get focus to show an action
|
/// Should return true if this panel wants to get focus to show an action
|
||||||
virtual bool wantsToHandle(const Action&) { return false; }
|
virtual bool wantsToHandle(const Action&) const { return false; }
|
||||||
/// Handle an action that changes the current set
|
/// Handle an action that changes the current set
|
||||||
virtual void onAction(const Action&) {}
|
virtual void onAction(const Action&) {}
|
||||||
/// The settings for rendering cards have changed, refresh card viewers/editors
|
/// The settings for rendering cards have changed, refresh card viewers/editors
|
||||||
virtual void onRenderSettingsChange() {}
|
virtual void onRenderSettingsChange() {}
|
||||||
|
|
||||||
// --------------------------------------------------- : Clipboard
|
// --------------------------------------------------- : Clipboard
|
||||||
virtual bool canPaste() { return false; } ///< Is pasting possible?
|
virtual bool canPaste() const { return false; } ///< Is pasting possible?
|
||||||
virtual bool canCopy() { return false; } ///< Is copying possible?
|
virtual bool canCopy() const { return false; } ///< Is copying possible?
|
||||||
virtual bool canCut() { return canCopy(); } ///< Is cutting possible?
|
virtual bool canCut() const { return canCopy(); } ///< Is cutting possible?
|
||||||
virtual void doPaste() {} ///< Paste the contents of the clipboard
|
virtual void doPaste() {} ///< Paste the contents of the clipboard
|
||||||
virtual void doCopy() {} ///< Copy the selection to the clipboard
|
virtual void doCopy() {} ///< Copy the selection to the clipboard
|
||||||
virtual void doCut() {} ///< Cut the selection to the clipboard
|
virtual void doCut() {} ///< Cut the selection to the clipboard
|
||||||
|
|
||||||
// --------------------------------------------------- : Searching (find/replace)
|
// --------------------------------------------------- : Searching (find/replace)
|
||||||
virtual bool canFind() { return false; } ///< Is finding possible?
|
virtual bool canFind() const { return false; } ///< Is finding possible?
|
||||||
virtual bool canReplace() { return false; } ///< Is replacing possible?
|
virtual bool canReplace() const { return false; } ///< Is replacing possible?
|
||||||
virtual bool doFind(wxFindReplaceData&) { return false; } ///< Find the next math
|
virtual bool doFind(wxFindReplaceData&) { return false; } ///< Find the next math
|
||||||
virtual bool doReplace(wxFindReplaceData&) { return false; } ///< Replace the next match
|
virtual bool doReplace(wxFindReplaceData&) { return false; } ///< Replace the next match
|
||||||
|
|
||||||
// --------------------------------------------------- : Selection
|
// --------------------------------------------------- : Selection
|
||||||
virtual CardP selectedCard() { return CardP(); } ///< Return the currently selected card, or CardP()
|
virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP()
|
||||||
virtual void selectCard(CardP card) {} ///< Switch the view to another card
|
virtual void selectCard(CardP card) {} ///< Switch the view to another card
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// --------------------------------------------------- : Helper functions for UI
|
// --------------------------------------------------- : Helper functions for UI
|
||||||
|
|||||||
@@ -10,9 +10,14 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
|
#include <gui/set/panel.hpp>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- :
|
// ----------------------------------------------------------------------------- : SetInfoPanel
|
||||||
|
|
||||||
|
class SetInfoPanel : public SetWindowPanel {
|
||||||
|
public:
|
||||||
|
SetInfoPanel(Window* parent, int id);
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EOF
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,5 +7,18 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <gui/set/style_panel.hpp>
|
#include <gui/set/style_panel.hpp>
|
||||||
|
#include <gui/control/package_list.hpp>
|
||||||
|
#include <data/game.hpp>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- :
|
// ----------------------------------------------------------------------------- : StylePanel
|
||||||
|
|
||||||
|
StylePanel::StylePanel(Window* parent, int id)
|
||||||
|
: SetWindowPanel(parent, id)
|
||||||
|
{
|
||||||
|
PackageList* list = new PackageList(this, wxID_ANY);
|
||||||
|
list->showData<Game>();
|
||||||
|
|
||||||
|
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
s->Add(list, 1, wxEXPAND);
|
||||||
|
SetSizer(s);
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,9 +10,14 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
|
#include <gui/set/panel.hpp>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- :
|
// ----------------------------------------------------------------------------- : StylePanel
|
||||||
|
|
||||||
|
class StylePanel : public SetWindowPanel {
|
||||||
|
public:
|
||||||
|
StylePanel(Window* parent, int id);
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EOF
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -113,16 +113,16 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
|||||||
// NOTE: place the CardsPanel last in the panels list,
|
// 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 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
|
// this way everyone else already uses the new set when it sends a CardSelectEvent
|
||||||
// addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 4, _("F5"));
|
// addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 4, _("F5"), _("Cards"), _("Cards"));
|
||||||
// addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6"));
|
// addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6"));
|
||||||
// addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"));
|
addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Chnage the style of cards"));
|
||||||
// addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8"));
|
// addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8"));
|
||||||
// addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 3, _("F9"));
|
// 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"))
|
//addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10"))
|
||||||
// selectPanel(idWindowMin + 4); // select cards panel
|
// selectPanel(idWindowMin + 4); // select cards panel
|
||||||
|
|
||||||
addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 0, _("F9"));
|
addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 0, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set"));
|
||||||
selectPanel(ID_WINDOW_MIN); // test
|
selectPanel(ID_WINDOW_MIN+1); // test
|
||||||
|
|
||||||
// loose ends
|
// loose ends
|
||||||
tabBar->Realize();
|
tabBar->Realize();
|
||||||
@@ -162,15 +162,16 @@ SetWindow::~SetWindow() {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Panel managment
|
// ----------------------------------------------------------------------------- : Panel managment
|
||||||
|
|
||||||
void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, const String& shortcut) {
|
void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos,
|
||||||
|
const String& shortcut, const String& shortName, const String& longName, const String& description) {
|
||||||
// insert in list
|
// insert in list
|
||||||
if (panels.size() <= pos) panels.resize(pos + 1);
|
if (panels.size() <= pos) panels.resize(pos + 1);
|
||||||
panels[pos] = panel;
|
panels[pos] = panel;
|
||||||
// add to tab bar
|
// add to tab bar
|
||||||
int id = ID_WINDOW_MIN + pos;
|
int id = ID_WINDOW_MIN + pos;
|
||||||
tabBar->AddTool(id,panel->shortName(), wxNullBitmap, wxNullBitmap, wxITEM_CHECK, panel->longName(), panel->description());
|
tabBar->AddTool(id, shortName, wxNullBitmap, wxNullBitmap, wxITEM_CHECK, longName, description);
|
||||||
// add to menu bar
|
// add to menu bar
|
||||||
windowMenu->AppendCheckItem(id, panel->longName() + _("\t") + shortcut, panel->description());
|
windowMenu->AppendCheckItem(id, longName + _("\t") + shortcut, description);
|
||||||
// add to sizer
|
// add to sizer
|
||||||
GetSizer()->Add(panel, 1, wxEXPAND);
|
GetSizer()->Add(panel, 1, wxEXPAND);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ class SetWindow : public wxFrame, public SetView {
|
|||||||
/// Add a panel to the window, as well as to the menu and tab bar
|
/// Add a panel to the window, as well as to the menu and tab bar
|
||||||
/** The position only determines the order in which events will be send.
|
/** The position only determines the order in which events will be send.
|
||||||
*/
|
*/
|
||||||
void addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, const String& shortcut);
|
void addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos,
|
||||||
|
const String& shortcut, const String& shortName, const String& longName, const String& description);
|
||||||
|
|
||||||
/// Select a panel, based on a tab id
|
/// Select a panel, based on a tab id
|
||||||
void selectPanel(int id);
|
void selectPanel(int id);
|
||||||
|
|||||||
+42
-4
@@ -368,6 +368,18 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\gui\control\card_list.hpp">
|
RelativePath=".\gui\control\card_list.hpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\gallery_list.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\gallery_list.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\package_list.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\package_list.hpp">
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="editor"
|
Name="editor"
|
||||||
@@ -542,10 +554,6 @@
|
|||||||
RelativePath=".\resource\mse.rc">
|
RelativePath=".\resource\mse.rc">
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
|
||||||
Name="symbol"
|
|
||||||
Filter="">
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="data"
|
Name="data"
|
||||||
Filter="">
|
Filter="">
|
||||||
@@ -671,12 +679,42 @@
|
|||||||
<Filter
|
<Filter
|
||||||
Name="field"
|
Name="field"
|
||||||
Filter="">
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\boolean.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\boolean.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\choice.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\choice.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\color.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\color.hpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\data\field.cpp">
|
RelativePath=".\data\field.cpp">
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\data\field.hpp">
|
RelativePath=".\data\field.hpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\image.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\image.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\symbol.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\field\symbol.hpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\data\field\text.cpp">
|
RelativePath=".\data\field\text.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
#include <util/reflect.hpp>
|
#include <util/reflect.hpp>
|
||||||
#include <util/defaultable.hpp>
|
#include <util/defaultable.hpp>
|
||||||
|
#include <script/script.hpp>
|
||||||
|
|
||||||
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
|
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
|
||||||
class Context;
|
class Context;
|
||||||
|
|||||||
@@ -11,6 +11,28 @@
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Alignment
|
// ----------------------------------------------------------------------------- : Alignment
|
||||||
|
|
||||||
|
double align_delta_x(Alignment align, double box_width, double obj_width) {
|
||||||
|
if (align & ALIGN_CENTER) return (box_width - obj_width) / 2;
|
||||||
|
else if (align & ALIGN_RIGHT) return box_width - obj_width;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double align_delta_y(Alignment align, double box_height, double obj_height) {
|
||||||
|
if (align & ALIGN_MIDDLE) return (box_height - obj_height) / 2;
|
||||||
|
else if (align & ALIGN_BOTTOM) return box_height - obj_height;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRect& outer) {
|
||||||
|
return RealPoint(
|
||||||
|
outer.position.x + align_delta_x(align, outer.size.width, to_align.width),
|
||||||
|
outer.position.y + align_delta_y(align, outer.size.height, to_align.height)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Reflection stuff
|
||||||
|
|
||||||
/// Convert a String to an Alignment
|
/// Convert a String to an Alignment
|
||||||
Alignment fromString(const String& str) {
|
Alignment fromString(const String& str) {
|
||||||
int al = 0;
|
int al = 0;
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ enum Alignment
|
|||||||
, ALIGN_JUSTIFY_OVERFLOW = 0x1000
|
, ALIGN_JUSTIFY_OVERFLOW = 0x1000
|
||||||
, ALIGN_STRETCH = 0x2000
|
, ALIGN_STRETCH = 0x2000
|
||||||
// common combinations
|
// common combinations
|
||||||
, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT
|
, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT
|
||||||
|
, ALIGN_MIDDLE_CENTER = ALIGN_MIDDLE | ALIGN_CENTER
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ enum Alignment
|
|||||||
double align_delta_x(Alignment align, double box_width, double obj_width);
|
double align_delta_x(Alignment align, double box_width, double obj_width);
|
||||||
|
|
||||||
/// How much should an object with obj_height be moved to be aligned in a box with box_height?
|
/// How much should an object with obj_height be moved to be aligned in a box with box_height?
|
||||||
double align_delta_t(Alignment align, double box_height, double obj_height);
|
double align_delta_y(Alignment align, double box_height, double obj_height);
|
||||||
|
|
||||||
/// Align a rectangle inside another rectangle
|
/// Align a rectangle inside another rectangle
|
||||||
/** returns the topleft coordinates of the inner rectangle after alignment
|
/** returns the topleft coordinates of the inner rectangle after alignment
|
||||||
|
|||||||
@@ -185,6 +185,13 @@
|
|||||||
FOR_EACH_2_T(TYPEOF_IT(Collection1), TYPEOF_REF(Collection1), Elem1, Collection1, \
|
FOR_EACH_2_T(TYPEOF_IT(Collection1), TYPEOF_REF(Collection1), Elem1, Collection1, \
|
||||||
TYPEOF_IT(Collection2), TYPEOF_REF(Collection2), Elem2, Collection2)
|
TYPEOF_IT(Collection2), TYPEOF_REF(Collection2), Elem2, Collection2)
|
||||||
|
|
||||||
|
/// Iterate over two constants collections in parallel, their type must be declared with DECLARE_TYPEOF.
|
||||||
|
/** Usage: FOR_EACH_2_CONST(e1,collect1, e2,collect2) { body-of-loop }
|
||||||
|
*/
|
||||||
|
#define FOR_EACH_2_CONST(Elem1,Collection1, Elem2,Collection2) \
|
||||||
|
FOR_EACH_2_T(TYPEOF_CIT(Collection1), TYPEOF_CREF(Collection1), Elem1, Collection1, \
|
||||||
|
TYPEOF_CIT(Collection2), TYPEOF_CREF(Collection2), Elem2, Collection2)
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EOF
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -50,9 +50,15 @@ String Package::name() const {
|
|||||||
else if ( ext == String::npos) return filename.substr(slash+1);
|
else if ( ext == String::npos) return filename.substr(slash+1);
|
||||||
else return filename.substr(slash+1, ext-slash-1);
|
else return filename.substr(slash+1, ext-slash-1);
|
||||||
}
|
}
|
||||||
|
String Package::fullName() const {
|
||||||
|
return name();
|
||||||
|
}
|
||||||
const String& Package::absoluteFilename() const {
|
const String& Package::absoluteFilename() const {
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
InputStreamP Package::openIconFile() {
|
||||||
|
return InputStreamP();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Package::open(const String& n) {
|
void Package::open(const String& n) {
|
||||||
|
|||||||
@@ -51,9 +51,14 @@ class Package {
|
|||||||
bool needSaveAs() const;
|
bool needSaveAs() const;
|
||||||
/// Determines the short name of this package: the filename without path or extension
|
/// Determines the short name of this package: the filename without path or extension
|
||||||
String name() const;
|
String name() const;
|
||||||
|
/// Return the full name of this package, by default equal to name()
|
||||||
|
virtual String fullName() const;
|
||||||
/// Return the absolute filename of this file
|
/// Return the absolute filename of this file
|
||||||
const String& absoluteFilename() const;
|
const String& absoluteFilename() const;
|
||||||
|
|
||||||
|
/// Get an input stream for the package icon, if there is any
|
||||||
|
virtual InputStreamP openIconFile();
|
||||||
|
|
||||||
/// Open a package, should only be called when the package is constructed using the default constructor!
|
/// Open a package, should only be called when the package is constructed using the default constructor!
|
||||||
/// @pre open not called before [TODO]
|
/// @pre open not called before [TODO]
|
||||||
void open(const String& package);
|
void open(const String& package);
|
||||||
|
|||||||
@@ -8,11 +8,12 @@
|
|||||||
|
|
||||||
#include <util/io/package_manager.hpp>
|
#include <util/io/package_manager.hpp>
|
||||||
#include <util/error.hpp>
|
#include <util/error.hpp>
|
||||||
|
#include <data/game.hpp>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : PackageManager
|
// ----------------------------------------------------------------------------- : PackageManager
|
||||||
|
|
||||||
String program_dir() {
|
String program_dir() {
|
||||||
return _("."); //TODO
|
return wxGetCwd(); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageManager packages;
|
PackageManager packages;
|
||||||
@@ -36,6 +37,33 @@ PackageManager::PackageManager() {
|
|||||||
data_directory += _("/data");
|
data_directory += _("/data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackagedP PackageManager::openAny(const String& name) {
|
||||||
|
wxFileName fn(data_directory + _("/") + name);
|
||||||
|
fn.Normalize();
|
||||||
|
String filename = fn.GetFullPath();
|
||||||
|
// Is this package already loaded?
|
||||||
|
PackagedP& p = loaded_packages[filename];
|
||||||
|
if (p) {
|
||||||
|
return p;
|
||||||
|
} else {
|
||||||
|
// load with the right type, based on extension
|
||||||
|
if (fn.GetExt() == _("mse-game")) p = new_shared<Game>();
|
||||||
|
// else if (fn.GetExt() == _("mse-style")) p = new_shared<CardStyle>();
|
||||||
|
// else if (fn.GetExt() == _("mse-locale")) p = new_shared<Locale>();
|
||||||
|
// else if (fn.GetExt() == _("mse-include")) p = new_shared<IncludePackage>();
|
||||||
|
// else if (fn.GetExt() == _("mse-symbol-font")) p = new_shared<SymbolFont>();
|
||||||
|
else {
|
||||||
|
throw PackageError(_("Unrecognized package type: ") + fn.GetExt());
|
||||||
|
}
|
||||||
|
p->open(filename);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String PackageManager::findFirst(const String& pattern) {
|
||||||
|
return wxFindFirstFile(data_directory + _("/") + pattern, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void PackageManager::destroy() {
|
void PackageManager::destroy() {
|
||||||
loaded_packages.clear();
|
loaded_packages.clear();
|
||||||
}
|
}
|
||||||
@@ -44,9 +44,14 @@ class PackageManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open a package with the specified name
|
/// Open a package with the specified name, the type of package is determined by its extension!
|
||||||
/// the type of package is determined by its extension!
|
PackagedP openAny(const String& name);
|
||||||
PackagedP openAnyPackage(const String& filename);
|
|
||||||
|
/// Find a package whos name matches a pattern
|
||||||
|
/** Find more using wxFindNextFile().
|
||||||
|
* If no package is found returns an empty string.
|
||||||
|
*/
|
||||||
|
String findFirst(const String& pattern);
|
||||||
|
|
||||||
/// Empty the list of packages.
|
/// Empty the list of packages.
|
||||||
/** This function MUST be called before the program terminates, otherwise
|
/** This function MUST be called before the program terminates, otherwise
|
||||||
|
|||||||
@@ -61,6 +61,45 @@ String trim_left(const String& s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool smart_less(const String& as, const String& bs) {
|
||||||
|
bool in_num = false; // are we inside a number?
|
||||||
|
bool lt = false; // is as less than bs?
|
||||||
|
bool eq = true; // so far is everything equal?
|
||||||
|
FOR_EACH_2_CONST(a, as, b, bs) {
|
||||||
|
bool na = isDigit(a), nb = isDigit(b);
|
||||||
|
Char la = toLower(a), lb = toLower(b);
|
||||||
|
if (na && nb) {
|
||||||
|
// compare numbers
|
||||||
|
in_num = true;
|
||||||
|
if (eq && a != b) {
|
||||||
|
eq = false;
|
||||||
|
lt = a < b;
|
||||||
|
}
|
||||||
|
} else if (in_num && na) {
|
||||||
|
// comparing numbers, one is longer, therefore it is greater
|
||||||
|
return false;
|
||||||
|
} else if (in_num && nb) {
|
||||||
|
return true;
|
||||||
|
} else if (in_num && !eq) {
|
||||||
|
// two numbers of the same length, but not equal
|
||||||
|
return lt;
|
||||||
|
} else {
|
||||||
|
// compare characters
|
||||||
|
if (la < lb) return true;
|
||||||
|
if (la > lb) return false;
|
||||||
|
}
|
||||||
|
in_num = na && nb;
|
||||||
|
}
|
||||||
|
// When we are at the end; shorter strings come first
|
||||||
|
// This is true for normal string collation
|
||||||
|
// and also when both end in a number and another digit follows
|
||||||
|
if (as.size() != bs.size()) {
|
||||||
|
return as.size() < bs.size();
|
||||||
|
} else {
|
||||||
|
return lt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Words
|
// ----------------------------------------------------------------------------- : Words
|
||||||
|
|
||||||
String last_word(const String& s) {
|
String last_word(const String& s) {
|
||||||
|
|||||||
@@ -81,6 +81,13 @@ String trim(const String&);
|
|||||||
/// Remove whitespace from the start of a string
|
/// Remove whitespace from the start of a string
|
||||||
String trim_left(const String&);
|
String trim_left(const String&);
|
||||||
|
|
||||||
|
/// Compare two strings, is the first less than the first?
|
||||||
|
/** Uses a smart comparison algorithm that understands numbers.
|
||||||
|
* The comparison is case insensitive.
|
||||||
|
* Doesn't handle leading zeros.
|
||||||
|
*/
|
||||||
|
bool smart_less(const String&, const String&);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Words
|
// ----------------------------------------------------------------------------- : Words
|
||||||
|
|
||||||
/// Returns the last word in a string
|
/// Returns the last word in a string
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ enum ChildMenuID {
|
|||||||
, ID_SHAPE_STAR
|
, ID_SHAPE_STAR
|
||||||
, ID_SHAPE_MAX
|
, ID_SHAPE_MAX
|
||||||
, ID_SIDES
|
, ID_SIDES
|
||||||
|
|
||||||
|
// CardList
|
||||||
|
, ID_SELECT_COLUMNS = 3001
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user