Commit fa4d91f2 authored by twanvl's avatar twanvl

'initial' property for color fields;

export options stored in settings;
editor for export options.
parent 974399c7
......@@ -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:
......
......@@ -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);
}
// ----------------------------------------------------------------------------- :
......@@ -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<FieldP> option_fields; ///< Options for exporting
IndexMap<FieldP,StyleP> option_style; ///< Style of the options
OptionalScript script; ///< Export script, for multi file templates and initialization
static String typeNameStatic();
virtual String typeName() const;
......
......@@ -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();
}
......
......@@ -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<String> ValueType;
......
......@@ -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?
......
......@@ -29,11 +29,12 @@ class ColorField : public Field {
class Choice;
typedef intrusive_ptr<Choice> ChoiceP;
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
vector<ChoiceP> 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<ChoiceP> choices; ///< Color choices available
bool allow_custom; ///< Are colors not in the list of choices allowed?
Defaultable<Color> 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<Color> ValueType;
......
......@@ -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?
......
......@@ -10,6 +10,7 @@
#include <data/game.hpp>
#include <data/stylesheet.hpp>
#include <data/field.hpp>
#include <data/export_template.hpp>
#include <util/reflect.hpp>
#include <util/platform.hpp>
#include <util/io/reader.hpp>
......@@ -148,6 +149,10 @@ StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet
return *ss;
}
IndexMap<FieldP,ValueP>& 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() {
......
......@@ -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<FieldP,ValueP> export_options;
public:
/// Get the options for an export template
IndexMap<FieldP,ValueP>& exportOptionsFor(const ExportTemplate& export);
// --------------------------------------------------- : Special game stuff
String apprentice_location;
String mws_location;
......
......@@ -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)
{}
......
......@@ -10,6 +10,8 @@
#include <gui/value/editor.hpp>
#include <gui/util.hpp>
#include <data/stylesheet.hpp>
#include <data/export_template.hpp>
#include <data/settings.hpp>
DECLARE_TYPEOF_COLLECTION(ValueViewerP);
DECLARE_TYPEOF_NO_REV(IndexMap<FieldP COMMA StyleP>);
......@@ -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));
}
......@@ -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
......
......@@ -8,6 +8,7 @@
#include <gui/html_export_window.hpp>
#include <gui/control/package_list.hpp>
#include <gui/control/native_look_editor.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
#include <data/settings.hpp>
......@@ -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<ExportTemplate>(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<ExportTemplate>();
handle_pending_errors();
options->showExport(export);
settings.gameSettingsFor(*set->game).default_export = export->name();
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
......
......@@ -12,6 +12,7 @@
#include <util/prec.hpp>
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();
......
......@@ -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);
......
......@@ -3217,9 +3217,6 @@
<File
RelativePath="..\data\en.mse-locale\locale">
</File>
<File
RelativePath="..\data\nl.mse-locale\locale">
</File>
<File
RelativePath=".\main.cpp">
</File>
......
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