From df9bb78e51904d66f4f25ab51639cc7d1120717e Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 23 Jun 2007 19:44:50 +0000 Subject: [PATCH] 'initial' property for color fields; export options stored in settings; editor for export options. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@429 0fc631ac-6414-0410-93d0-97cfa31319b6 --- data/en.mse-locale/locale | 4 ++++ src/data/export_template.cpp | 5 +++++ src/data/export_template.hpp | 2 +- src/data/field/choice.cpp | 8 ++++++++ src/data/field/choice.hpp | 11 +++++------ src/data/field/color.cpp | 9 +++++++++ src/data/field/color.hpp | 13 +++++++------ src/data/field/multiple_choice.hpp | 2 +- src/data/settings.cpp | 6 ++++++ src/data/settings.hpp | 11 +++++++++++ src/gui/control/card_viewer.cpp | 2 +- src/gui/control/native_look_editor.cpp | 14 ++++++++++++++ src/gui/control/native_look_editor.hpp | 3 --- src/gui/html_export_window.cpp | 12 ++++++++++-- src/gui/html_export_window.hpp | 6 ++++-- src/gui/set/style_panel.cpp | 4 ++-- src/mse.vcproj | 3 --- 17 files changed, 88 insertions(+), 27 deletions(-) diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index 7ad092a3..e3cb9f34 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -348,6 +348,9 @@ label: This is a standard %s keyword, you can not edit it. If you make a copy of the keyword your copy will take precedent. + # Style tab + styling options: Styling options + # Open dialogs all files All files @@ -389,6 +392,7 @@ label: # Html export html template: Template: + html export options:Export options # Image slicer original: Original: diff --git a/src/data/export_template.cpp b/src/data/export_template.cpp index ff771997..53590752 100644 --- a/src/data/export_template.cpp +++ b/src/data/export_template.cpp @@ -19,8 +19,13 @@ String ExportTemplate::typeName() const { return _("export-template"); } IMPLEMENT_REFLECTION(ExportTemplate) { REFLECT_BASE(Packaged); + REFLECT(game); REFLECT(file_type); REFLECT(create_directory); + REFLECT(option_fields); + REFLECT_IF_READING option_style.init(option_fields); + REFLECT(option_style); + REFLECT(script); } // ----------------------------------------------------------------------------- : diff --git a/src/data/export_template.hpp b/src/data/export_template.hpp index 440a8150..3e982989 100644 --- a/src/data/export_template.hpp +++ b/src/data/export_template.hpp @@ -25,11 +25,11 @@ class ExportTemplate : public Packaged { ExportTemplate(); GameP game; ///< Game this template is for - OptionalScript script; ///< Export script String file_type; ///< Type of the created file, in "name|*.ext" format bool create_directory; ///< The export creates an entire directory vector option_fields; ///< Options for exporting IndexMap option_style; ///< Style of the options + OptionalScript script; ///< Export script, for multi file templates and initialization static String typeNameStatic(); virtual String typeName() const; diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 8a284404..7e8d287e 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -291,6 +291,14 @@ IMPLEMENT_REFLECTION(ChoiceStyle) { // ----------------------------------------------------------------------------- : ChoiceValue +ChoiceValue::ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice) + : Value(field) + , value( !field->initial.empty() ? field->initial + : initial_first_choice ? field->choices->choiceName(0) + : _("") + , true) +{} + String ChoiceValue::toString() const { return value(); } diff --git a/src/data/field/choice.hpp b/src/data/field/choice.hpp index abf4f62d..07d580b4 100644 --- a/src/data/field/choice.hpp +++ b/src/data/field/choice.hpp @@ -167,12 +167,11 @@ class ChoiceStyle : public Style { /// The Value in a ChoiceField class ChoiceValue : public Value { public: - inline ChoiceValue(const ChoiceFieldP& field, bool initial_empty = false) - : Value(field) - , value(field->initial.empty() && !initial_empty - ? field->choices->choiceName(0) // first choice - : field->initial, true) - {} + /// Create a value for the given field + /** If initial_first_choice then the first choice should be used in the absence of + an explicit initial value + */ + ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice = true); DECLARE_HAS_FIELD(Choice) typedef Defaultable ValueType; diff --git a/src/data/field/color.cpp b/src/data/field/color.cpp index 25eb6cc6..21953f75 100644 --- a/src/data/field/color.cpp +++ b/src/data/field/color.cpp @@ -35,6 +35,7 @@ IMPLEMENT_REFLECTION(ColorField) { REFLECT_BASE(Field); REFLECT(script); REFLECT_N("default", default_script); + REFLECT(initial); REFLECT(default_name); REFLECT(allow_custom); REFLECT(choices); @@ -73,6 +74,14 @@ bool ColorStyle::update(Context& ctx) { // ----------------------------------------------------------------------------- : ColorValue +ColorValue::ColorValue(const ColorFieldP& field) + : Value(field) + , value( !field->initial.isDefault() ? field->initial() + : !field->choices.empty() ? field->choices[0]->color + : *wxBLACK + , true) +{} + String ColorValue::toString() const { if (value.isDefault()) return field().default_name; // is this a named color? diff --git a/src/data/field/color.hpp b/src/data/field/color.hpp index 145e5424..407761c3 100644 --- a/src/data/field/color.hpp +++ b/src/data/field/color.hpp @@ -29,11 +29,12 @@ class ColorField : public Field { class Choice; typedef intrusive_ptr ChoiceP; - OptionalScript script; ///< Script to apply to all values - OptionalScript default_script; ///< Script that generates the default value - vector choices; ///< Color choices available - bool allow_custom; ///< Are colors not in the list of choices allowed? - String default_name; ///< Name of "default" value + OptionalScript script; ///< Script to apply to all values + OptionalScript default_script; ///< Script that generates the default value + vector choices; ///< Color choices available + bool allow_custom; ///< Are colors not in the list of choices allowed? + Defaultable initial; ///< Initial choice of a new value, if not set the first choice is used + String default_name; ///< Name of "default" value virtual void initDependencies(Context&, const Dependency&) const; @@ -76,7 +77,7 @@ class ColorStyle : public Style { /// The Value in a ColorField class ColorValue : public Value { public: - inline ColorValue(const ColorFieldP& field) : Value(field) {} + ColorValue(const ColorFieldP& field); DECLARE_HAS_FIELD(Color) typedef Defaultable ValueType; diff --git a/src/data/field/multiple_choice.hpp b/src/data/field/multiple_choice.hpp index e7c3efc7..fc8952f9 100644 --- a/src/data/field/multiple_choice.hpp +++ b/src/data/field/multiple_choice.hpp @@ -54,7 +54,7 @@ class MultipleChoiceStyle : public ChoiceStyle { */ class MultipleChoiceValue : public ChoiceValue { public: - inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, true) {} + inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, false) {} DECLARE_HAS_FIELD(MultipleChoice); String last_change; ///< Which of the choices was selected/deselected last? diff --git a/src/data/settings.cpp b/src/data/settings.cpp index e764978e..91e7c583 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -148,6 +149,10 @@ StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet return *ss; } +IndexMap& Settings::exportOptionsFor(const ExportTemplate& export) { + return export_options.get(export.name(), export.option_fields); +} + /// Retrieve the directory to use for settings and other data files String user_settings_dir() { String dir = wxStandardPaths::Get().GetUserDataDir(); @@ -180,6 +185,7 @@ IMPLEMENT_REFLECTION(Settings) { REFLECT(game_settings); REFLECT(stylesheet_settings); REFLECT(default_stylesheet_settings); + REFLECT(export_options); } void Settings::read() { diff --git a/src/data/settings.hpp b/src/data/settings.hpp index e1459dd3..c8e52d26 100644 --- a/src/data/settings.hpp +++ b/src/data/settings.hpp @@ -15,10 +15,13 @@ class Game; class StyleSheet; +class ExportTemplate; class Field; DECLARE_POINTER_TYPE(GameSettings); DECLARE_POINTER_TYPE(StyleSheetSettings); +DECLARE_POINTER_TYPE(Field); +DECLARE_POINTER_TYPE(Value); // ----------------------------------------------------------------------------- : Extra data structures @@ -133,6 +136,14 @@ class Settings { public: StyleSheetSettings default_stylesheet_settings; ///< The default settings for stylesheets + // --------------------------------------------------- : Exports + private: + DelayedIndexMaps export_options; + public: + + /// Get the options for an export template + IndexMap& exportOptionsFor(const ExportTemplate& export); + // --------------------------------------------------- : Special game stuff String apprentice_location; String mws_location; diff --git a/src/gui/control/card_viewer.cpp b/src/gui/control/card_viewer.cpp index 00a61209..35741324 100644 --- a/src/gui/control/card_viewer.cpp +++ b/src/gui/control/card_viewer.cpp @@ -19,7 +19,7 @@ DEFINE_EVENT_TYPE(EVENT_SIZE_CHANGE); // ----------------------------------------------------------------------------- : CardViewer CardViewer::CardViewer(Window* parent, int id, long style) - : wxControl(parent, id, wxDefaultPosition, wxDefaultSize, style) + : wxControl(parent, id, wxDefaultPosition, wxDefaultSize, style | wxNO_FULL_REPAINT_ON_RESIZE) , up_to_date(false) {} diff --git a/src/gui/control/native_look_editor.cpp b/src/gui/control/native_look_editor.cpp index 550966d5..a2f208f0 100644 --- a/src/gui/control/native_look_editor.cpp +++ b/src/gui/control/native_look_editor.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include DECLARE_TYPEOF_COLLECTION(ValueViewerP); DECLARE_TYPEOF_NO_REV(IndexMap); @@ -199,3 +201,15 @@ void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) { void StylingEditor::onChangeSet() { showStylesheet(set->stylesheet); } + +// ----------------------------------------------------------------------------- : ExportOptionsEditor + +ExportOptionsEditor::ExportOptionsEditor(Window* parent, int id, long style) + : NativeLookEditor(parent, id, style) +{} + +void ExportOptionsEditor::showExport(const ExportTemplateP& export) { + setStyles(set->stylesheet, export->option_style); + setData(settings.exportOptionsFor(*export)); +} + diff --git a/src/gui/control/native_look_editor.hpp b/src/gui/control/native_look_editor.hpp index 0f03b998..037938b8 100644 --- a/src/gui/control/native_look_editor.hpp +++ b/src/gui/control/native_look_editor.hpp @@ -84,9 +84,6 @@ class ExportOptionsEditor : public NativeLookEditor { /// Show the options for given export template void showExport(const ExportTemplateP& export); - - protected: - virtual void onChangeSet(); }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/gui/html_export_window.cpp b/src/gui/html_export_window.cpp index 746af387..2a11e542 100644 --- a/src/gui/html_export_window.cpp +++ b/src/gui/html_export_window.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -20,18 +21,24 @@ DECLARE_POINTER_TYPE(ExportTemplate); // ----------------------------------------------------------------------------- : HtmlExportWindow HtmlExportWindow::HtmlExportWindow(Window* parent, const SetP& set) - : wxDialog(parent,wxID_ANY,_TITLE_("export html"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE) + : wxDialog(parent,wxID_ANY,_TITLE_("export html"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxCLIP_CHILDREN) , set(set) { // init controls - list = new PackageList(this, ID_EXPORT_LIST); + list = new PackageList(this, ID_EXPORT_LIST); + options = new ExportOptionsEditor(this, wxID_ANY, wxNO_BORDER); + options->setSet(set); // init sizers wxSizer* s = new wxBoxSizer(wxVERTICAL); s->Add(new wxStaticText(this, wxID_ANY, _LABEL_("html template")), 0, wxALL, 4); s->Add(list, 0, wxEXPAND | wxALL & ~wxTOP, 4); + wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("html export options")); + s2->Add(options, 2, wxEXPAND, 0); + s->Add(s2, 1, wxEXPAND | wxALL, 4); s->Add(CreateButtonSizer(wxOK | wxCANCEL) , 0, wxEXPAND | wxALL, 8); s->SetSizeHints(this); SetSizer(s); + SetSize(700,500); // list list->showData(set->game->name() + _("-*")); list->select(settings.gameSettingsFor(*set->game).default_export); @@ -57,6 +64,7 @@ void HtmlExportWindow::onTemplateSelect(wxCommandEvent&) { wxBusyCursor wait; ExportTemplateP export = list->getSelection(); handle_pending_errors(); + options->showExport(export); settings.gameSettingsFor(*set->game).default_export = export->name(); UpdateWindowUI(wxUPDATE_UI_RECURSE); } diff --git a/src/gui/html_export_window.hpp b/src/gui/html_export_window.hpp index feadbcd9..8b58a61a 100644 --- a/src/gui/html_export_window.hpp +++ b/src/gui/html_export_window.hpp @@ -12,6 +12,7 @@ #include class PackageList; +class ExportOptionsEditor; DECLARE_POINTER_TYPE(Set); // ----------------------------------------------------------------------------- : HtmlExportWindow @@ -21,8 +22,9 @@ class HtmlExportWindow : public wxDialog { HtmlExportWindow(Window* parent, const SetP& set); private: - PackageList* list; ///< List of templates - SetP set; ///< Set to export + PackageList* list; ///< List of templates + ExportOptionsEditor* options; ///< Editor for template options + SetP set; ///< Set to export DECLARE_EVENT_TABLE(); diff --git a/src/gui/set/style_panel.cpp b/src/gui/set/style_panel.cpp index 08642bbd..65def130 100644 --- a/src/gui/set/style_panel.cpp +++ b/src/gui/set/style_panel.cpp @@ -26,14 +26,14 @@ StylePanel::StylePanel(Window* parent, int id) 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")); + use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _BUTTON_("use for all cards")); // init sizer wxSizer* s = new wxBoxSizer(wxHORIZONTAL); 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")); + wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("styling options")); s3->Add(editor, 2, wxEXPAND, 0); s2->Add(s3, 1, wxEXPAND | wxALL, 2); s->Add(s2, 1, wxEXPAND, 8); diff --git a/src/mse.vcproj b/src/mse.vcproj index 63f23988..f43e5df5 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -3217,9 +3217,6 @@ - -