Commit b8a3bf5e authored by twanvl's avatar twanvl

Implemented CardList

parent fdd32b44
...@@ -16,7 +16,7 @@ ...@@ -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 { ...@@ -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 @@ ...@@ -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
......
...@@ -81,7 +81,10 @@ class Value { ...@@ -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) { ...@@ -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 { ...@@ -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 { ...@@ -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);
......
...@@ -32,8 +32,12 @@ class Game : public Packaged { ...@@ -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();
......
...@@ -8,6 +8,7 @@ ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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());
......
...@@ -11,12 +11,14 @@ ...@@ -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 ...@@ -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 { ...@@ -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 { ...@@ -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
......
This diff is collapsed.
//+----------------------------------------------------------------------------+
//| 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
...@@ -26,12 +26,9 @@ class SetWindowPanel : public wxPanel, public SetView { ...@@ -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 { ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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) ...@@ -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() { ...@@ -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 { ...@@ -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);
......
...@@ -368,6 +368,18 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 ...@@ -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 ...@@ -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 @@ ...@@ -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 { ...@@ -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 { ...@@ -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 @@ ...@@ -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() { ...@@ -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();
} }
\ No newline at end of file
...@@ -44,9 +44,14 @@ class PackageManager { ...@@ -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) { ...@@ -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&); ...@@ -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 { ...@@ -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
}; };
......
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