Commit efa7a856 authored by twanvl's avatar twanvl

Added dummy keyword panel; fixed directory finding; added more controls to style panel

parent ffa3fab1
...@@ -14,7 +14,7 @@ IMPLEMENT_REFLECTION(KeywordParam) { ...@@ -14,7 +14,7 @@ IMPLEMENT_REFLECTION(KeywordParam) {
REFLECT(name); REFLECT(name);
REFLECT(description); REFLECT(description);
REFLECT(match); REFLECT(match);
REFLECT(in_reminder); REFLECT(script);
} }
IMPLEMENT_REFLECTION(KeywordMode) { IMPLEMENT_REFLECTION(KeywordMode) {
REFLECT(name); REFLECT(name);
...@@ -25,8 +25,32 @@ IMPLEMENT_REFLECTION(KeywordExpansion) { ...@@ -25,8 +25,32 @@ IMPLEMENT_REFLECTION(KeywordExpansion) {
REFLECT(after); REFLECT(after);
REFLECT(reminder); REFLECT(reminder);
} }
// backwards compatability
template <typename T> void read_compat(T&, const Keyword*) {}
void read_compat(Reader& tag, Keyword* k) {
String separator, parameter, reminder;
REFLECT(separator);
REFLECT(parameter);
REFLECT(reminder);
if (!separator.empty() || !parameter.empty() || !reminder.empty()) {
// old style keyword declaration, no separate expansion
KeywordExpansionP e(new KeywordExpansion);
size_t start = separator.find_first_of('[');
size_t end = separator.find_first_of(']');
if (start != String.npos && end != String.npos) {
e->after += separator.substr(start + 1, end - start - 1);
}
if (!parameter.empty()) {
e->after += _("<param>") + parameter + _("</param>");
}
e->reminder.set(reminder);
}
}
IMPLEMENT_REFLECTION(Keyword) { IMPLEMENT_REFLECTION(Keyword) {
REFLECT(keyword); REFLECT(keyword);
read_compat(tag, this);
REFLECT(expansions); REFLECT(expansions);
REFLECT(rules); REFLECT(rules);
REFLECT(mode); REFLECT(mode);
......
...@@ -26,7 +26,7 @@ class KeywordParam { ...@@ -26,7 +26,7 @@ class KeywordParam {
String description; ///< Description of the type String description; ///< Description of the type
String match; ///< Uncompiled regex String match; ///< Uncompiled regex
wxRegEx matchRe; ///< Regular expression to match wxRegEx matchRe; ///< Regular expression to match
OptionalScript in_reminder; ///< Transformation of the value for showing in the reminder text OptionalScript script; ///< Transformation of the value for showing in the reminder text
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
...@@ -50,7 +50,7 @@ class KeywordExpansion { ...@@ -50,7 +50,7 @@ class KeywordExpansion {
String after; ///< Components after the keyword: parameters and separators String after; ///< Components after the keyword: parameters and separators
vector<KeywordParamP> parameters; ///< The types of parameters vector<KeywordParamP> parameters; ///< The types of parameters
wxRegEx splitter; ///< Regular expression to split/match the components, automatically generated wxRegEx splitter; ///< Regular expression to split/match the components, automatically generated
OptionalScript reminder; ///< Reminder text of the keyword StringScript reminder; ///< Reminder text of the keyword
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
#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>
#include <script/value.hpp>
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/wfstream.h> #include <wx/wfstream.h>
#include <script/value.hpp> #include <wx/stdpaths.h>
// ----------------------------------------------------------------------------- : Extra types // ----------------------------------------------------------------------------- : Extra types
...@@ -131,8 +132,11 @@ StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet ...@@ -131,8 +132,11 @@ StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet
return *ss; return *ss;
} }
/// Retrieve the directory to use for settings and other data files
String user_settings_dir() { String user_settings_dir() {
return _(""); // TODO String dir = wxStandardPaths::Get().GetUserDataDir();
if (!wxDirExists(dir)) wxMkDir(dir);
return dir + _("/");
} }
String Settings::settingsFile() { String Settings::settingsFile() {
......
//+----------------------------------------------------------------------------+
//| 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/set/keywords_panel.hpp>
// ----------------------------------------------------------------------------- : KeywordsList
// ----------------------------------------------------------------------------- : KeywordsPanel
KeywordsPanel::KeywordsPanel(Window* parent, int id)
: SetWindowPanel(parent, id)
{
/*wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(list_active, 1, wxEXPAND);
s2->Add(list_inactive, 1, wxEXPAND);
s->SetSizeHints(this);
SetSizer(s);*/
}
//+----------------------------------------------------------------------------+
//| 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_SET_KEYWORDS_PANEL
#define HEADER_GUI_SET_KEYWORDS_PANEL
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
// ----------------------------------------------------------------------------- : KeywordsPanel
/// A panel for listing and editing the keywords in a set
class KeywordsPanel : public SetWindowPanel {
public:
KeywordsPanel(Window* parent, int id);
};
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -18,6 +18,7 @@ class FilteredCardList; ...@@ -18,6 +18,7 @@ class FilteredCardList;
// ----------------------------------------------------------------------------- : StatsPanel // ----------------------------------------------------------------------------- : StatsPanel
/// A panel for showing statistics on cards
class StatsPanel : public SetWindowPanel { class StatsPanel : public SetWindowPanel {
public: public:
StatsPanel(Window* parent, int id); StatsPanel(Window* parent, int id);
......
...@@ -8,17 +8,47 @@ ...@@ -8,17 +8,47 @@
#include <gui/set/style_panel.hpp> #include <gui/set/style_panel.hpp>
#include <gui/control/package_list.hpp> #include <gui/control/package_list.hpp>
#include <gui/control/card_viewer.hpp>
#include <gui/control/native_look_editor.hpp>
#include <util/window_id.hpp>
#include <data/set.hpp>
#include <data/game.hpp> #include <data/game.hpp>
#include <data/stylesheet.hpp>
// ----------------------------------------------------------------------------- : StylePanel // ----------------------------------------------------------------------------- : StylePanel
StylePanel::StylePanel(Window* parent, int id) StylePanel::StylePanel(Window* parent, int id)
: SetWindowPanel(parent, id) : SetWindowPanel(parent, id)
{ {
PackageList* list = new PackageList(this, wxID_ANY); // init controls
list->showData<Game>(); preview = new CardViewer (this, wxID_ANY);
editor = new StylingEditor(this, wxID_ANY, wxNO_BORDER);
list = new PackageList (this, wxID_ANY);
use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _("Use for &all cards"));
// init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL); wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(list, 1, wxEXPAND); s->Add(preview, 0, wxRIGHT, 2);
wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4);
s2->Add(use_for_all, 0, wxRIGHT | wxBOTTOM | wxALIGN_RIGHT, 4);
wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _("Extra styling options"));
s3->Add(editor, 2, wxEXPAND, 0);
s2->Add(s3, 1, wxEXPAND | wxALL, 2);
s->Add(s2, 1, wxEXPAND, 8);
s->SetSizeHints(this);
SetSizer(s); SetSizer(s);
} }
void StylePanel::onChangeSet() {
list->showData<StyleSheet>(set->game->name() + _("-*"));
list->select(set->stylesheet->name());
editor->setSet(set);
preview->setSet(set);
}
// ----------------------------------------------------------------------------- : Selection
void StylePanel::selectCard(const CardP& card) {
preview->setCard(card);
list->select(set->stylesheetFor(card)->name());
}
...@@ -12,11 +12,27 @@ ...@@ -12,11 +12,27 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <gui/set/panel.hpp> #include <gui/set/panel.hpp>
class CardViewer;
class PackageList;
class StylingEditor;
// ----------------------------------------------------------------------------- : StylePanel // ----------------------------------------------------------------------------- : StylePanel
/// A panel showing a list of stylesheets, and an editor for styling
class StylePanel : public SetWindowPanel { class StylePanel : public SetWindowPanel {
public: public:
StylePanel(Window* parent, int id); StylePanel(Window* parent, int id);
virtual void onChangeSet();
// --------------------------------------------------- : Selection
virtual void selectCard(const CardP& card);
private:
CardViewer* preview; ///< Card preview
PackageList* list; ///< List of stylesheets
StylingEditor* editor; ///< Editor for styling information
wxButton* use_for_all;
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <gui/set/cards_panel.hpp> #include <gui/set/cards_panel.hpp>
#include <gui/set/set_info_panel.hpp> #include <gui/set/set_info_panel.hpp>
#include <gui/set/style_panel.hpp> #include <gui/set/style_panel.hpp>
#include <gui/set/keywords_panel.hpp>
#include <gui/set/stats_panel.hpp> #include <gui/set/stats_panel.hpp>
#include <gui/control/card_list.hpp> #include <gui/control/card_list.hpp>
#include <gui/control/gallery_list.hpp> #include <gui/control/gallery_list.hpp>
...@@ -117,13 +118,13 @@ SetWindow::SetWindow(Window* parent, const SetP& set) ...@@ -117,13 +118,13 @@ 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), 3, _("F5"), _("Cards"), _("Cards"), _("Edit the cards in the set")); addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 4, _("F5"), _("Cards"), _("Cards"), _("Edit the cards in the set"));
addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6"), _("Set info"), _("&Set Information"), _("Edit information about the set, its creator, etc.")); addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6"), _("Set info"), _("&Set Information"), _("Edit information about the set, its creator, etc."));
addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Change the style of cards")); addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Change the style of cards"));
// addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8")); addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8"), _("Keywords"), _("Keywords"), _("Define extra keywords for this set"));
addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 2, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set")); 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(ID_WINDOW_MIN + 3); // select cards panel selectPanel(ID_WINDOW_MIN + 0); // select cards panel
// loose ends // loose ends
tabBar->Realize(); tabBar->Realize();
...@@ -256,7 +257,6 @@ void SetWindow::onRenderSettingsChange() { ...@@ -256,7 +257,6 @@ void SetWindow::onRenderSettingsChange() {
} }
void SetWindow::fixMinWindowSize() { void SetWindow::fixMinWindowSize() {
current_panel->Layout();
current_panel->SetMinSize(current_panel->GetSizer()->GetMinSize()); current_panel->SetMinSize(current_panel->GetSizer()->GetMinSize());
Layout(); Layout();
wxSize s = GetSizer()->GetMinSize(); wxSize s = GetSizer()->GetMinSize();
......
...@@ -40,6 +40,7 @@ bool MSE::OnInit() { ...@@ -40,6 +40,7 @@ bool MSE::OnInit() {
SetAppName(_("Magic Set Editor")); SetAppName(_("Magic Set Editor"));
wxInitAllImageHandlers(); wxInitAllImageHandlers();
init_file_formats(); init_file_formats();
packages.init();
settings.read(); settings.read();
//Window* wnd = new SymbolWindow(nullptr); //Window* wnd = new SymbolWindow(nullptr);
//GameP g = Game::byName(_("magic")) //GameP g = Game::byName(_("magic"))
......
...@@ -328,6 +328,12 @@ ...@@ -328,6 +328,12 @@
<File <File
RelativePath=".\gui\set\cards_panel.hpp"> RelativePath=".\gui\set\cards_panel.hpp">
</File> </File>
<File
RelativePath=".\gui\set\keywords_panel.cpp">
</File>
<File
RelativePath=".\gui\set\keywords_panel.hpp">
</File>
<File <File
RelativePath=".\gui\set\panel.cpp"> RelativePath=".\gui\set\panel.cpp">
</File> </File>
......
...@@ -72,3 +72,34 @@ template <> void GetDefaultMember::handle(const OptionalScript& os) { ...@@ -72,3 +72,34 @@ template <> void GetDefaultMember::handle(const OptionalScript& os) {
handle(script_nil); handle(script_nil);
} }
} }
// ----------------------------------------------------------------------------- : StringScript
const String& StringScript::get() const {
return unparsed;
}
void StringScript::set(const String& s) {
unparsed = s;
script = ::parse(unparsed, true);
}
template <> void Reader::handle(StringScript& os) {
handle(os.unparsed);
os.parse(*this, true);
}
// same as OptionalScript
template <> void Writer::handle(const StringScript& os) {
handle(os.unparsed);
}
template <> void GetDefaultMember::handle(const StringScript& os) {
// reflect as the script itself
if (os.script) {
handle(os.script);
} else {
handle(script_nil);
}
}
...@@ -30,7 +30,7 @@ void store(const ScriptValueP& val, Defaultable<String>& var); ...@@ -30,7 +30,7 @@ void store(const ScriptValueP& val, Defaultable<String>& var);
// ----------------------------------------------------------------------------- : OptionalScript // ----------------------------------------------------------------------------- : OptionalScript
/// An optional script, /// An optional script
class OptionalScript { class OptionalScript {
public: public:
inline OptionalScript() {} inline OptionalScript() {}
...@@ -73,7 +73,7 @@ class OptionalScript { ...@@ -73,7 +73,7 @@ class OptionalScript {
/// Initialize things this script depends on by adding dep to their list of dependent scripts /// Initialize things this script depends on by adding dep to their list of dependent scripts
void initDependencies(Context&, const Dependency& dep) const; void initDependencies(Context&, const Dependency& dep) const;
private: protected:
ScriptP script; ///< The script, may be null if there is no script ScriptP script; ///< The script, may be null if there is no script
String unparsed; ///< Unparsed script, for writing back to a file String unparsed; ///< Unparsed script, for writing back to a file
// parse the unparsed string, while reading // parse the unparsed string, while reading
...@@ -85,6 +85,16 @@ class OptionalScript { ...@@ -85,6 +85,16 @@ class OptionalScript {
template <typename T> template <typename T>
inline ScriptValueP toScript(const Defaultable<T>& v) { return toScript(v.get()); } inline ScriptValueP toScript(const Defaultable<T>& v) { return toScript(v.get()); }
// ----------------------------------------------------------------------------- : StringScript
/// An optional script which is parsed in string mode
class StringScript : public OptionalScript {
public:
const String& get() const;
void set(const String&);
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : Scriptable // ----------------------------------------------------------------------------- : Scriptable
/// A script that defines a calculation to find a value /// A script that defines a calculation to find a value
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/action_stack.hpp>
#include <util/for_each.hpp>
#include <algorithm> #include <algorithm>
#include "action_stack.hpp"
#include "for_each.hpp"
// ----------------------------------------------------------------------------- : Action stack // ----------------------------------------------------------------------------- : Action stack
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/string.hpp>
#include <vector> #include <vector>
#include "string.hpp"
// ----------------------------------------------------------------------------- : Action // ----------------------------------------------------------------------------- : Action
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <data/game.hpp> #include <data/game.hpp>
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <data/symbol_font.hpp> #include <data/symbol_font.hpp>
#include <wx/stdpaths.h>
// ----------------------------------------------------------------------------- : IncludePackage // ----------------------------------------------------------------------------- : IncludePackage
...@@ -34,16 +35,12 @@ IMPLEMENT_REFLECTION(IncludePackage) { ...@@ -34,16 +35,12 @@ IMPLEMENT_REFLECTION(IncludePackage) {
// ----------------------------------------------------------------------------- : PackageManager // ----------------------------------------------------------------------------- : PackageManager
String program_dir() {
return wxGetCwd(); //TODO
}
PackageManager packages; PackageManager packages;
PackageManager::PackageManager() { void PackageManager::init() {
// determine data directory // determine data directory
data_directory = program_dir(); data_directory = wxStandardPaths::Get().GetDataDir();
// check if this is the actual data directory, especially during debugging, // check if this is the actual data directory, especially during debugging,
// the data may be higher up: // the data may be higher up:
// exe path = mse/build/debug/mse.exe // exe path = mse/build/debug/mse.exe
......
...@@ -23,7 +23,12 @@ DECLARE_POINTER_TYPE(Packaged); ...@@ -23,7 +23,12 @@ DECLARE_POINTER_TYPE(Packaged);
*/ */
class PackageManager { class PackageManager {
public: public:
PackageManager(); /// Initialize the package manager
void init();
/// Empty the list of packages.
/** This function MUST be called before the program terminates, otherwise
* we could get into fights with pool allocators used by ScriptValues */
void destroy();
/// Open a package with the specified name (including extension) /// Open a package with the specified name (including extension)
template <typename T> template <typename T>
...@@ -55,12 +60,7 @@ class PackageManager { ...@@ -55,12 +60,7 @@ class PackageManager {
// Open a file from a package, with a name encoded as "package/file" // Open a file from a package, with a name encoded as "package/file"
InputStreamP openFileFromPackage(const String& name); InputStreamP openFileFromPackage(const String& name);
/// Empty the list of packages.
/** This function MUST be called before the program terminates, otherwise
* we could get into fights with pool allocators used by ScriptValues */
void destroy();
private: private:
map<String, PackagedP> loaded_packages; map<String, PackagedP> loaded_packages;
String data_directory; String data_directory;
......
...@@ -141,6 +141,9 @@ enum ChildMenuID { ...@@ -141,6 +141,9 @@ enum ChildMenuID {
// Statistics // Statistics
, ID_FIELD_LIST = 3101 , ID_FIELD_LIST = 3101
// Style
, ID_STYLE_USE_FOR_ALL = 3201
}; };
......
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