mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
Implemented auto replace, including GUI
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@631 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+2
-1
@@ -57,7 +57,8 @@ IMPLEMENT_REFLECTION(Game) {
|
||||
REFLECT(keyword_modes);
|
||||
REFLECT(keyword_parameter_types);
|
||||
REFLECT_NO_SCRIPT(keywords);
|
||||
REFLECT(word_lists);
|
||||
REFLECT_NO_SCRIPT(word_lists);
|
||||
REFLECT_NO_SCRIPT(auto_replaces);
|
||||
}
|
||||
|
||||
void Game::validate(Version v) {
|
||||
|
||||
+4
-2
@@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(KeywordParam);
|
||||
DECLARE_POINTER_TYPE(KeywordMode);
|
||||
DECLARE_POINTER_TYPE(Keyword);
|
||||
DECLARE_POINTER_TYPE(WordList);
|
||||
DECLARE_POINTER_TYPE(AutoReplace);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Game
|
||||
|
||||
@@ -45,13 +46,14 @@ class Game : public Packaged {
|
||||
vector<StatsCategoryP> statistics_categories; ///< (Additional) statistics categories
|
||||
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
||||
vector<WordListP> word_lists; ///< Word lists for editing with a drop down list
|
||||
|
||||
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
||||
|
||||
bool has_keywords; ///< Does this game use keywords?
|
||||
OptionalScript keyword_match_script; ///< For the keyword editor
|
||||
vector<KeywordParamP> keyword_parameter_types;///< Types of keyword parameters
|
||||
vector<KeywordModeP> keyword_modes; ///< Modes of keywords
|
||||
vector<KeywordP> keywords; ///< Keywords for use in text
|
||||
|
||||
|
||||
Dependencies dependent_scripts_cards; ///< scripts that depend on the card list
|
||||
Dependencies dependent_scripts_keywords; ///< scripts that depend on the keywords
|
||||
bool dependencies_initialized; ///< are the script dependencies comming from this game all initialized?
|
||||
|
||||
+34
-4
@@ -11,6 +11,7 @@
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <data/export_template.hpp>
|
||||
#include <data/word_list.hpp>
|
||||
#include <util/reflect.hpp>
|
||||
#include <util/platform.hpp>
|
||||
#include <util/io/reader.hpp>
|
||||
@@ -19,6 +20,8 @@
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/stdpaths.h>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(AutoReplaceP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Extra types
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(CheckUpdates) {
|
||||
@@ -43,7 +46,7 @@ ColumnSettings::ColumnSettings()
|
||||
// dummy for ColumnSettings reflection
|
||||
ScriptValueP to_script(const ColumnSettings&) { return script_nil; }
|
||||
|
||||
IMPLEMENT_REFLECTION(ColumnSettings) {
|
||||
IMPLEMENT_REFLECTION_NO_SCRIPT(ColumnSettings) {
|
||||
REFLECT(width);
|
||||
REFLECT(position);
|
||||
REFLECT(visible);
|
||||
@@ -53,9 +56,33 @@ GameSettings::GameSettings()
|
||||
: sort_cards_ascending(true)
|
||||
, images_export_filename(_("{card.name}.jpg"))
|
||||
, images_export_conflicts(CONFLICT_NUMBER_OVERWRITE)
|
||||
, use_auto_replace(true)
|
||||
, initialized(false)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION(GameSettings) {
|
||||
void GameSettings::initDefaults(const Game& game) {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
// init auto_replaces, copy from game file
|
||||
FOR_EACH_CONST(ar, game.auto_replaces) {
|
||||
// do we have this one?
|
||||
bool already_have = false;
|
||||
FOR_EACH(ar2, auto_replaces) {
|
||||
if (ar->match == ar2->match) {
|
||||
ar2->custom = false;
|
||||
already_have = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!already_have) {
|
||||
// TODO: when we start saving games, clone here
|
||||
ar->custom = false;
|
||||
auto_replaces.push_back(ar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_NO_SCRIPT(GameSettings) {
|
||||
REFLECT(default_stylesheet);
|
||||
REFLECT(default_export);
|
||||
REFLECT_N("cardlist columns", columns);
|
||||
@@ -63,6 +90,8 @@ IMPLEMENT_REFLECTION(GameSettings) {
|
||||
REFLECT(sort_cards_ascending);
|
||||
REFLECT(images_export_filename);
|
||||
REFLECT(images_export_conflicts);
|
||||
REFLECT(use_auto_replace);
|
||||
REFLECT(auto_replaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +111,7 @@ void StyleSheetSettings::useDefault(const StyleSheetSettings& ss) {
|
||||
if (card_normal_export.isDefault()) card_normal_export.assignDefault(ss.card_normal_export);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(StyleSheetSettings) {
|
||||
IMPLEMENT_REFLECTION_NO_SCRIPT(StyleSheetSettings) {
|
||||
REFLECT(card_zoom);
|
||||
REFLECT(card_angle);
|
||||
REFLECT(card_anti_alias);
|
||||
@@ -127,6 +156,7 @@ void Settings::addRecentFile(const String& filename) {
|
||||
GameSettings& Settings::gameSettingsFor(const Game& game) {
|
||||
GameSettingsP& gs = game_settings[game.name()];
|
||||
if (!gs) gs = new_intrusive<GameSettings>();
|
||||
gs->initDefaults(game);
|
||||
return *gs;
|
||||
}
|
||||
ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field) {
|
||||
@@ -165,7 +195,7 @@ String Settings::settingsFile() {
|
||||
return user_settings_dir() + _("mse8.config"); // use different file during development of C++ port
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(Settings) {
|
||||
IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
|
||||
REFLECT_ALIAS(300, "style settings", "stylesheet settings");
|
||||
REFLECT_ALIAS(300, "default style settings", "default stylesheet settings");
|
||||
REFLECT(locale);
|
||||
|
||||
@@ -22,6 +22,7 @@ DECLARE_POINTER_TYPE(GameSettings);
|
||||
DECLARE_POINTER_TYPE(StyleSheetSettings);
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
DECLARE_POINTER_TYPE(Value);
|
||||
DECLARE_POINTER_TYPE(AutoReplace);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Extra data structures
|
||||
|
||||
@@ -56,6 +57,9 @@ class GameSettings : public IntrusivePtrBase<GameSettings> {
|
||||
public:
|
||||
GameSettings();
|
||||
|
||||
/// Where the settings have defaults, initialize with the values from the game
|
||||
void initDefaults(const Game& g);
|
||||
|
||||
String default_stylesheet;
|
||||
String default_export;
|
||||
map<String, ColumnSettings> columns;
|
||||
@@ -63,8 +67,12 @@ class GameSettings : public IntrusivePtrBase<GameSettings> {
|
||||
bool sort_cards_ascending;
|
||||
String images_export_filename;
|
||||
FilenameConflicts images_export_conflicts;
|
||||
bool use_auto_replace;
|
||||
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
private:
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
/// Settings for a StyleSheet
|
||||
|
||||
@@ -281,9 +281,16 @@ IMPLEMENT_REFLECTION(Symbol) {
|
||||
}
|
||||
|
||||
double Symbol::aspectRatio() const {
|
||||
// Margin between the edges and the symbol.
|
||||
// In each direction take the lowest one
|
||||
// This is at most 0.5 (if the symbol is just a line in the middle)
|
||||
// Multiply by 2 (below) to give something in the range [0...1] i.e. [touches the edge...only in the middle]
|
||||
double margin_x = min(0.4999, max(0., min(min_pos.x, 1-max_pos.x)));
|
||||
double margin_y = min(0.4999, max(0., min(min_pos.y, 1-max_pos.y)));
|
||||
// The difference between these two,
|
||||
// e.g. if the vertical margin is more then the horizontal one, the symbol is 'flat'
|
||||
double delta = 2 * (margin_y - margin_x);
|
||||
// The aspect ratio, i.e. width/height
|
||||
if (delta > 0) {
|
||||
return 1 / (1 - delta);
|
||||
} else {
|
||||
|
||||
@@ -32,3 +32,18 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(WordList) {
|
||||
REFLECT(words);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Auto replace words
|
||||
|
||||
AutoReplace::AutoReplace()
|
||||
: enabled(true)
|
||||
, whole_word(true)
|
||||
, custom(true)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION_NO_SCRIPT(AutoReplace) {
|
||||
REFLECT(enabled);
|
||||
REFLECT(whole_word);
|
||||
REFLECT(match);
|
||||
REFLECT(replace);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
DECLARE_POINTER_TYPE(WordListWord);
|
||||
DECLARE_POINTER_TYPE(WordList);
|
||||
DECLARE_POINTER_TYPE(AutoReplace);
|
||||
|
||||
// ----------------------------------------------------------------------------- : WordList
|
||||
|
||||
@@ -38,6 +39,23 @@ class WordList : public WordListWord {
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Auto replace words
|
||||
|
||||
/// Autoreplace specific shortcut words
|
||||
class AutoReplace : public IntrusivePtrVirtualBase {
|
||||
public:
|
||||
AutoReplace();
|
||||
|
||||
bool enabled;
|
||||
bool whole_word;
|
||||
bool custom; ///< Is this a custom auto replace?
|
||||
String match;
|
||||
String replace;
|
||||
|
||||
inline AutoReplaceP clone() const { return new_intrusive1<AutoReplace>(*this); }
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user