1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
|
diff -Naur MagicSetEditor2-2.1.2/CHANGES.md MagicSetEditor2-master/CHANGES.md
--- MagicSetEditor2-2.1.2/CHANGES.md 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/CHANGES.md 2021-07-06 11:54:44.000000000 -0400
@@ -4,6 +4,12 @@
HEAD: new items added as changes are made
------------------------------------------------------------------------------
+Features:
+ * You can now check/uncheck all selected cards in the export window (#93)
+
+Template features:
+ * Localization of game/stylesheet/symbol_font names is now done in those templates, instead of via the program-wide locale file. (#100)
+
------------------------------------------------------------------------------
version 2.1.2, 2020-09-28
------------------------------------------------------------------------------
diff -Naur MagicSetEditor2-2.1.2/doc/type/field.txt MagicSetEditor2-master/doc/type/field.txt
--- MagicSetEditor2-2.1.2/doc/type/field.txt 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/doc/type/field.txt 2021-07-06 11:54:44.000000000 -0400
@@ -27,7 +27,7 @@
* @color@
* @info@
| @name@ [[type:string]] ''required'' Name of the field.
-| @description@ [[type:string]] @""@ Description of the field, shown in the status bar when the mouse is over the field.
+| @description@ [[type:localized string]] @""@ Description of the field, shown in the status bar when the mouse is over the field.
| @icon@ [[type:filename]] Filename of an icon for this field, used for automatically generated [[type:statistics category]]s.
| @editable@ [[type:boolean]] @true@ Can values of this field be edited?
| @save value@ [[type:boolean]] @true@ Should values of this field be saved to files? Should be disabled for values that are generated by scripts.
@@ -38,7 +38,7 @@
| @card list width@ [[type:int]] @100@ Width of the card list column in pixels.
| @card list visible@ [[type:boolean]] @false@ Should this field be shown in the card list by default?
| @card list allow@ [[type:boolean]] @true@ Should this field be allowed in the card list at all?
-| @card list name@ [[type:string]] field name Alternate name to use for the card list, for example an abbreviation.
+| @card list name@ [[type:localized string]] field name Alternate name to use for the card list, for example an abbreviation.
| @card list alignment@ [[type:alignment]] @left@ Alignment of the card list column.
| @sort script@ [[type:script]] Alternate way to sort the card list when using this column to sort the list.
diff -Naur MagicSetEditor2-2.1.2/doc/type/insert_symbol_menu.txt MagicSetEditor2-master/doc/type/insert_symbol_menu.txt
--- MagicSetEditor2-2.1.2/doc/type/insert_symbol_menu.txt 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/doc/type/insert_symbol_menu.txt 2021-07-06 11:54:44.000000000 -0400
@@ -14,18 +14,19 @@
* @line@, a separating line.
* @submenu@, a submenu.
| @name@ [[type:string]] ''required'' Name of this menu item, corresponding to the code to insert.
+| @label@ [[type:localized string]] name Label to show in the menu.
+| @prompt@ [[type:localized string]] Prompt to use for the pop up box with @custom@ type
| @items@ [[type:list]] of [[type:insert symbol menu|submenu items]] Items in the submenu, when items are present the @type@ is set to @"submenu"@.
-In the user interface the items are shown as @"menu item {name}"@, the [[type:locale]] should be used to give a beter label.
-
-For custom items the dialog will be titled @"title {name}"@ and have message text @"message {name}"@, again this should be changed in the locale.
+For custom items the dialog will be titled with the @label@ and have message text @prompt@.
--Examples--
A menu for magic mana symbols (simplified). Containing all types of items.
>insert symbol menu:
> item:
> type: custom
-> name: colorless
+> name: Generic
+> prompt: How much generic mana?
> item:
> type: line
> item: W
@@ -34,6 +35,9 @@
> item: R
> item: G
> item:
+> label: Complex
+> name: cplx
+> item:
> type: line
> item:
> name: hybrid
diff -Naur MagicSetEditor2-2.1.2/doc/type/locale.txt MagicSetEditor2-master/doc/type/locale.txt
--- MagicSetEditor2-2.1.2/doc/type/locale.txt 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/doc/type/locale.txt 2021-07-06 11:54:44.000000000 -0400
@@ -35,12 +35,15 @@
| @error@ [[type:map]] of [[type:string]]s Error messages.
| @type@ [[type:map]] of [[type:string]]s Types of objects for error messages.
| @game@ [[type:map]] of [[type:map]] of [[type:string]]s
+ Deprecated since MSE 2.1.3, use @localized_...@ instead.<br/>
Translations for specific [[type:game]]s.<br/>
Field names and field descriptions are looked up in the locale, if they are found the translation is used, otherwise the value from the game file.<br/>
Extra keys not present in the English locale can be added here.
| @stylesheet@ [[type:map]] of [[type:map]] of [[type:string]]s
+ Deprecated since MSE 2.1.3, use @localized_...@ instead.<br/>
Translations for specific [[type:stylesheet]]s.
| @symbol font@ [[type:map]] of [[type:map]] of [[type:string]]s
+ Deprecated since MSE 2.1.3, use @localized_...@ instead.<br/>
Translations for specific [[type:symbol font]]s, in particular the "insert symbol" menu.
Some of the items can contain placeholders for other values, for example:
diff -Naur MagicSetEditor2-2.1.2/doc/type/localized_string.txt MagicSetEditor2-master/doc/type/localized_string.txt
--- MagicSetEditor2-2.1.2/doc/type/localized_string.txt 1969-12-31 19:00:00.000000000 -0500
+++ MagicSetEditor2-master/doc/type/localized_string.txt 2021-07-06 11:54:44.000000000 -0400
@@ -0,0 +1,14 @@
+Localized strings
+
+A 'localized string' is a [[type:map]] of [[type::string]]s, indexed by locale name.
+It is used to translate games and stylesheets to other user interface languages.
+
+Localized strings can be given with a @localized@ prefix on the property name.
+For example, a field has a @description@ which is a [[type::string]], and a @localized_description@ for localized variants. So
+
+>field:
+> name: cost
+> description: How much this card costs
+> localized description:
+> en_US: How much this card costs
+> nl_NL: Hoeveel deze kaart kost
diff -Naur MagicSetEditor2-2.1.2/doc/type/statistics_category.txt MagicSetEditor2-master/doc/type/statistics_category.txt
--- MagicSetEditor2-2.1.2/doc/type/statistics_category.txt 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/doc/type/statistics_category.txt 2021-07-06 11:54:44.000000000 -0400
@@ -12,7 +12,7 @@
--Properties--
! Property Type Default Description
| @name@ [[type:string]] ''required'' Name of this category.
-| @description@ [[type:string]] @""@ A description of the category, currently not used.
+| @description@ [[type:localized string]] @""@ A description of the category, currently not used.
| @position hint@ [[type:string]] @0@ Hint for ordering category, lower numbers are at the top of the list.
| @icon@ [[type:filename]] Filename of an icon for this category, the image should be 21x21 pixels.
| @type@ [[type:graph type]] @"bar"@ Type of graph to use.
diff -Naur MagicSetEditor2-2.1.2/doc/type/statistics_dimension.txt MagicSetEditor2-master/doc/type/statistics_dimension.txt
--- MagicSetEditor2-2.1.2/doc/type/statistics_dimension.txt 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/doc/type/statistics_dimension.txt 2021-07-06 11:54:44.000000000 -0400
@@ -13,7 +13,7 @@
--Properties--
! Property Type Default Description
| @name@ [[type:string]] ''required'' Name of this dimension, used as an axis label and a label for automatically generated categories.
-| @description@ [[type:string]] @""@ A description of the dimension, currently not used.
+| @description@ [[type:localized string]] @""@ A description of the dimension, currently not used.
| @position hint@ [[type:string]] @0@ Hint for ordering dimensions.
| @icon@ [[type:filename]] Filename of an icon for this dimension.
| @script@ [[type:script]] ''required'' Script that generates a value for each card in the set.
diff -Naur MagicSetEditor2-2.1.2/src/data/field/information.cpp MagicSetEditor2-master/src/data/field/information.cpp
--- MagicSetEditor2-2.1.2/src/data/field/information.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/field/information.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -64,7 +64,7 @@
return value;
}
bool InfoValue::update(Context& ctx) {
- if (value.empty()) value = field().caption;
+ if (value.empty()) value = field().caption.get();
bool change = field().script.invokeOn(ctx, value);
Value::update(ctx);
return change;
diff -Naur MagicSetEditor2-2.1.2/src/data/field.cpp MagicSetEditor2-master/src/data/field.cpp
--- MagicSetEditor2-2.1.2/src/data/field.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/field.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -47,8 +47,8 @@
REFLECT(type);
}
REFLECT(name);
- REFLECT(caption);
- REFLECT(description);
+ REFLECT_LOCALIZED(caption);
+ REFLECT_LOCALIZED(description);
REFLECT_N("icon", icon_filename);
REFLECT(editable);
REFLECT(save_value);
@@ -59,15 +59,15 @@
REFLECT(card_list_width);
REFLECT(card_list_visible);
REFLECT(card_list_allow);
- REFLECT(card_list_name);
+ REFLECT_LOCALIZED(card_list_name);
REFLECT(sort_script);
REFLECT_N("card_list_alignment", card_list_align);
}
void Field::after_reading(Version ver) {
name = canonical_name_form(name);
- if(caption.empty()) caption = name_to_caption(name);
- if(card_list_name.empty()) card_list_name = capitalize(caption);
+ if(caption.default_.empty()) caption.default_ = name_to_caption(name);
+ if(card_list_name.default_.empty()) card_list_name.default_ = capitalize(caption.default_);
}
template <>
diff -Naur MagicSetEditor2-2.1.2/src/data/field.hpp MagicSetEditor2-master/src/data/field.hpp
--- MagicSetEditor2-2.1.2/src/data/field.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/field.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -13,6 +13,7 @@
#include <util/alignment.hpp>
#include <util/age.hpp>
#include <util/rotation.hpp>
+#include <data/localized_string.hpp>
#include <script/scriptable.hpp>
#include <script/dependency.hpp>
#include <script/image.hpp>
@@ -43,8 +44,8 @@
size_t index; ///< Used by IndexMap
String name; ///< Name of the field, for refering to it from scripts and files
- String caption; ///< Caption for NativeLookEditor
- String description; ///< Description, used in status bar
+ LocalizedString caption; ///< Caption for NativeLookEditor
+ LocalizedString description;///< Description, used in status bar
String icon_filename; ///< Filename for an icon (for list of fields)
bool editable; ///< Can values of this field be edited?
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
@@ -55,7 +56,7 @@
UInt card_list_width; ///< Width of the card list column (pixels).
bool card_list_visible;///< Is this field shown in the card list?
bool card_list_allow; ///< Is this field allowed to appear in the card list?
- String card_list_name; ///< Alternate name to use in card list.
+ LocalizedString card_list_name; ///< Name to use in card list.
Alignment card_list_align; ///< Alignment of the card list colummn.
OptionalScript sort_script; ///< The script to use when sorting this, if not the value.
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
diff -Naur MagicSetEditor2-2.1.2/src/data/locale.cpp MagicSetEditor2-master/src/data/locale.cpp
--- MagicSetEditor2-2.1.2/src/data/locale.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/locale.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -8,6 +8,7 @@
#include <util/prec.hpp>
#include <data/locale.hpp>
+#include <data/localized_string.hpp>
#include <data/game.hpp>
#include <data/stylesheet.hpp>
#include <data/symbol_font.hpp>
@@ -118,3 +119,23 @@
}
return loc->tr(subcat, key, def);
}
+
+// ----------------------------------------------------------------------------- : LocalizedString
+
+String const& LocalizedString::get(String const& locale) const {
+ auto it = translations.find(locale);
+ if (it != translations.end()) {
+ return it->second;
+ } else {
+ return default_;
+ }
+}
+
+String const& LocalizedString::get(Locale const& locale) const {
+ return get(locale.name());
+}
+
+String const& LocalizedString::get() const {
+ if (translations.empty()) return default_;
+ return get(the_locale->name());
+}
diff -Naur MagicSetEditor2-2.1.2/src/data/localized_string.hpp MagicSetEditor2-master/src/data/localized_string.hpp
--- MagicSetEditor2-2.1.2/src/data/localized_string.hpp 1969-12-31 19:00:00.000000000 -0500
+++ MagicSetEditor2-master/src/data/localized_string.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -0,0 +1,37 @@
+//+----------------------------------------------------------------------------+
+//| Description: Magic Set Editor - Program to make Magic (tm) cards |
+//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
+//| License: GNU General Public License 2 or later (see file COPYING) |
+//+----------------------------------------------------------------------------+
+
+#pragma once
+
+// ----------------------------------------------------------------------------- : Includes
+
+#include <util/prec.hpp>
+
+class Locale;
+
+// ----------------------------------------------------------------------------- : LocalizedString
+
+/// Translations of a text in a template
+class LocalizedString {
+public:
+ String default_; //< Value in all other locales
+ unordered_map<String, String> translations;
+
+ /// Translate
+ String const& get(Locale const& locale) const;
+ String const& get(String const& locale) const;
+ String const& get() const;
+
+ bool empty() const { return default_.empty(); }
+};
+
+#define REFLECT_LOCALIZED_N(name, var) \
+ do { \
+ handler.handle(name, var.default_); \
+ handler.handle(_("localized_") name, var.translations); \
+ } while (0)
+
+#define REFLECT_LOCALIZED(var) REFLECT_LOCALIZED_N(_(#var), var)
diff -Naur MagicSetEditor2-2.1.2/src/data/statistics.cpp MagicSetEditor2-master/src/data/statistics.cpp
--- MagicSetEditor2-2.1.2/src/data/statistics.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/statistics.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -64,7 +64,7 @@
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
if (!automatic) {
REFLECT(name);
- REFLECT(description);
+ REFLECT_LOCALIZED(description);
REFLECT(position_hint);
REFLECT_N("icon", icon_filename);
REFLECT(script);
@@ -98,7 +98,7 @@
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
if (!automatic) {
REFLECT(name);
- REFLECT(description);
+ REFLECT_LOCALIZED(description);
REFLECT(position_hint);
REFLECT_N("icon", icon_filename);
REFLECT(type);
diff -Naur MagicSetEditor2-2.1.2/src/data/statistics.hpp MagicSetEditor2-master/src/data/statistics.hpp
--- MagicSetEditor2-2.1.2/src/data/statistics.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/statistics.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <util/reflect.hpp>
#include <data/graph_type.hpp>
+#include <data/localized_string.hpp>
#include <script/scriptable.hpp>
class Field;
@@ -28,7 +29,7 @@
const bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension
- String description; ///< Description, used in status bar
+ LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course)
@@ -52,15 +53,15 @@
StatsCategory();
StatsCategory(const StatsDimensionP&);
- const bool automatic; ///< Automatically generated?
- String name; ///< Name/label
- String description; ///< Description, used in status bar
- int position_hint; ///< Hint for the ordering
- String icon_filename; ///< Icon for lists
- Bitmap icon; ///< The loaded icon (optional of course)
- vector<String> dimension_names;///< Names of the dimensions to use
- vector<StatsDimensionP> dimensions; ///< Actual dimensions
- GraphType type; ///< Type of graph to use
+ const bool automatic; ///< Automatically generated?
+ String name; ///< Name/label
+ LocalizedString description; ///< Description, used in status bar
+ int position_hint; ///< Hint for the ordering
+ String icon_filename; ///< Icon for lists
+ Bitmap icon; ///< The loaded icon (optional of course)
+ vector<String> dimension_names; ///< Names of the dimensions to use
+ vector<StatsDimensionP> dimensions; ///< Actual dimensions
+ GraphType type; ///< Type of graph to use
/// Initialize dimensions from dimension_names
void find_dimensions(const vector<StatsDimensionP>& available);
diff -Naur MagicSetEditor2-2.1.2/src/data/symbol_font.cpp MagicSetEditor2-master/src/data/symbol_font.cpp
--- MagicSetEditor2-2.1.2/src/data/symbol_font.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/symbol_font.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -52,8 +52,8 @@
REFLECT_N("vertical_space", spacing.height);
WITH_DYNAMIC_ARG(symbol_font_for_reading, this);
REFLECT(symbols);
- REFLECT(scale_text);
- REFLECT(insert_symbol_menu);
+ REFLECT(scale_text);
+ REFLECT(insert_symbol_menu);
}
// ----------------------------------------------------------------------------- : SymbolInFont
@@ -460,11 +460,11 @@
} else if (id == 0 && type == Type::CODE) {
return name;
} else if (id == 0 && type == Type::CUSTOM) {
- String caption = tr(font, _("title"), name, capitalize_sentence);
- String message = tr(font, _("message"), name, capitalize_sentence);
- return wxGetTextFromUser(message, caption);
+ String title = this->label.get();
+ title.Replace(_("&"), _("")); // remove underlines
+ return wxGetTextFromUser(prompt.get(), title);
}
- return wxEmptyString;
+ return String();
}
wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
@@ -478,17 +478,18 @@
}
return nullptr;
}
+
wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolFont& font) const {
- wxString menu_name = tr(font, _("menu_item"), name, capitalize);
+ String label = this->label.get();
// ensure that there is not actually an accelerator string,
- menu_name.Replace(_("\t "),_("\t"));
+ label.Replace(_("\t "), _("\t"));
#ifdef __WXMSW__
- menu_name.Replace(_("\t"),_("\t ")); // by prepending " "
+ label.Replace(_("\t"), _("\t ")); // by prepending " "
#else
- menu_name.Replace(_("\t"),_(" ")); // by simply dropping the \t
+ label.Replace(_("\t"), _(" ")); // by simply dropping the \t
#endif
if (type == Type::SUBMENU) {
- wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, menu_name,
+ wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, label,
wxEmptyString, wxITEM_NORMAL,
makeMenu(first_id, font));
item->SetBitmap(wxNullBitmap);
@@ -497,7 +498,7 @@
wxMenuItem* item = new wxMenuItem(parent, wxID_SEPARATOR);
return item;
} else {
- wxMenuItem* item = new wxMenuItem(parent, first_id, menu_name);
+ wxMenuItem* item = new wxMenuItem(parent, first_id, label);
// Generate bitmap for use on this item
SymbolInFont* symbol = nullptr;
if (type == Type::CUSTOM) {
@@ -527,24 +528,24 @@
VALUE_N("submenu", InsertSymbolMenu::Type::SUBMENU);
}
-IMPLEMENT_REFLECTION_NO_GET_MEMBER(InsertSymbolMenu) {
+IMPLEMENT_REFLECTION(InsertSymbolMenu) {
REFLECT_IF_READING_SINGLE_VALUE_AND(items.empty()) {
REFLECT_NAMELESS(name);
} else {
// complex values are groups
REFLECT(type);
REFLECT(name);
+ REFLECT_LOCALIZED(label);
+ REFLECT_LOCALIZED(prompt);
REFLECT(items);
if (Handler::isReading && !items.empty()) type = Type::SUBMENU;
}
}
-template <> void GetDefaultMember::handle(const InsertSymbolMenu& m) {
- handle(m.name);
-}
-template <> void GetMember::handle(const InsertSymbolMenu& m) {
- handle(_("type"), m.type);
- handle(_("name"), m.name);
- handle(_("items"), m.items);
+
+void after_reading(InsertSymbolMenu& m, Version ver) {
+ assert(symbol_font_for_reading());
+ if (m.label.empty()) m.label.default_ = tr(*symbol_font_for_reading(), _("menu_item"), m.name, capitalize);
+ if (m.prompt.empty()) m.prompt.default_ = tr(*symbol_font_for_reading(), _("message"), m.name, capitalize_sentence);
}
// ----------------------------------------------------------------------------- : SymbolFontRef
diff -Naur MagicSetEditor2-2.1.2/src/data/symbol_font.hpp MagicSetEditor2-master/src/data/symbol_font.hpp
--- MagicSetEditor2-2.1.2/src/data/symbol_font.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/data/symbol_font.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <util/alignment.hpp>
#include <util/io/package.hpp>
+#include <data/localized_string.hpp>
#include <data/font.hpp>
#include <wx/regex.h>
@@ -124,6 +125,8 @@
};
Type type;
String name;
+ LocalizedString label; // text of menu item
+ LocalizedString prompt; // prompt for dialog box if type == CUSTOM
vector<InsertSymbolMenuP> items;
/// Number of ids used (recursive)
@@ -139,6 +142,8 @@
DECLARE_REFLECTION();
};
+void after_reading(InsertSymbolMenu&, Version ver);
+
// ----------------------------------------------------------------------------- : SymbolFontRef
/// A reference to an actual symbol font
diff -Naur MagicSetEditor2-2.1.2/src/gui/control/card_editor.cpp MagicSetEditor2-master/src/gui/control/card_editor.cpp
--- MagicSetEditor2-2.1.2/src/gui/control/card_editor.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/gui/control/card_editor.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -355,7 +355,7 @@
// set status text
wxFrame* frame = dynamic_cast<wxFrame*>( wxGetTopLevelParent(this) );
if (frame) {
- frame->SetStatusText(hovered_viewer ? hovered_viewer->getField()->description : String());
+ frame->SetStatusText(hovered_viewer ? hovered_viewer->getField()->description.get() : String());
}
}
}
diff -Naur MagicSetEditor2-2.1.2/src/gui/control/card_list_column_select.cpp MagicSetEditor2-master/src/gui/control/card_list_column_select.cpp
--- MagicSetEditor2-2.1.2/src/gui/control/card_list_column_select.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/gui/control/card_list_column_select.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -67,7 +67,7 @@
// Init items
Color window_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
FOR_EACH(c, columns) {
- list->Append(tr(*game, c.field->card_list_name, identity));
+ list->Append(c.field->card_list_name.get());
// check
int i = list->GetCount() - 1;
list->Check(i, c.settings.visible);
@@ -80,7 +80,7 @@
void CardListColumnSelectDialog::refreshItem(int i) {
list->Check (i, columns[i].settings.visible);
- list->SetString(i, tr(*game, columns[i].field->card_list_name, identity) );
+ list->SetString(i, columns[i].field->card_list_name.get());
}
// ----------------------------------------------------------------------------- : Events
diff -Naur MagicSetEditor2-2.1.2/src/gui/control/card_list.cpp MagicSetEditor2-master/src/gui/control/card_list.cpp
--- MagicSetEditor2-2.1.2/src/gui/control/card_list.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/gui/control/card_list.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -225,9 +225,7 @@
if (f.second->card_list_align & ALIGN_RIGHT) align = wxLIST_FORMAT_RIGHT;
else if (f.second->card_list_align & ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE;
else align = wxLIST_FORMAT_LEFT;
- InsertColumn((long)column_fields.size(),
- tr(*set->game, f.second->card_list_name, identity),
- align, cs.width);
+ InsertColumn((long)column_fields.size(), f.second->card_list_name.get(), align, cs.width);
column_fields.push_back(f.second);
}
// determine sort settings
diff -Naur MagicSetEditor2-2.1.2/src/gui/control/native_look_editor.cpp MagicSetEditor2-master/src/gui/control/native_look_editor.cpp
--- MagicSetEditor2-2.1.2/src/gui/control/native_look_editor.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/gui/control/native_look_editor.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -39,9 +39,7 @@
// draw label
dc.SetFont(*wxNORMAL_FONT);
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
- // TODO : tr using stylesheet or using game?
- dc.DrawText(tr(getStylePackage(), v.getField()->caption, identity),
- RealPoint(margin_left - v.bounding_box.x, 1));
+ dc.DrawText(v.getField()->caption.get(), RealPoint(margin_left - v.bounding_box.x, 1));
}
// draw viewer
v.draw(dc);
@@ -64,8 +62,7 @@
// width of the label string
int w;
Style& s = *v->getStyle();
- String text = tr(getStylePackage(), s.fieldP->caption, identity);
- dc.GetTextExtent(text,&w,nullptr);
+ dc.GetTextExtent(s.fieldP->caption.get(), &w, nullptr);
label_width = max(label_width, w + label_margin);
}
}
diff -Naur MagicSetEditor2-2.1.2/src/gui/control/select_card_list.cpp MagicSetEditor2-master/src/gui/control/select_card_list.cpp
--- MagicSetEditor2-2.1.2/src/gui/control/select_card_list.cpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/gui/control/select_card_list.cpp 2021-07-06 11:54:44.000000000 -0400
@@ -74,6 +74,17 @@
}
}
+void SelectCardList::toggleSelected(bool select) {
+ for (long i = GetFirstSelected(); i != -1; i = GetNextSelected(i)) {
+ if (select) {
+ selected.insert(getCard(i));
+ } else {
+ selected.erase(getCard(i));
+ }
+ RefreshItem(i);
+ }
+}
+
void SelectCardList::onKeyDown(wxKeyEvent& ev) {
if (selected_item_pos == -1 || !selected_item) {
// no selection
@@ -82,18 +93,15 @@
}
switch (ev.GetKeyCode()) {
case WXK_SPACE: {
- toggle(getCard());
- RefreshItem(selected_item_pos);
+ toggleSelected(!isSelected(getCard()));
break;
}
case WXK_NUMPAD_ADD: case '+': {
- selected.insert(getCard());
- RefreshItem(selected_item_pos);
+ toggleSelected(true);
break;
}
case WXK_NUMPAD_SUBTRACT: case '-': {
- selected.erase(getCard());
- RefreshItem(selected_item_pos);
+ toggleSelected(false);
break;
}
default:
@@ -106,8 +114,14 @@
long item = HitTest(wxPoint(ev.GetX(), ev.GetY()), flags);
if (flags == wxLIST_HITTEST_ONITEMICON) {
// only clicking the icon toggles
- toggle(getCard(item));
- RefreshItem(item);
+ if (IsSelected(item)) {
+ // if multiple items are selected in the view (regardless of checkbox status), check/uncheck them all
+ toggleSelected(!isSelected(getCard(item)));
+ return; // don't change selection
+ } else {
+ toggle(getCard(item));
+ RefreshItem(item);
+ }
}
ev.Skip();
}
diff -Naur MagicSetEditor2-2.1.2/src/gui/control/select_card_list.hpp MagicSetEditor2-master/src/gui/control/select_card_list.hpp
--- MagicSetEditor2-2.1.2/src/gui/control/select_card_list.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/gui/control/select_card_list.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -37,8 +37,9 @@
DECLARE_EVENT_TABLE();
std::set<CardP> selected; ///< which cards are selected?
-
+
void toggle(const CardP& card);
+ void toggleSelected(bool select);
void onKeyDown(wxKeyEvent&);
void onLeftDown(wxMouseEvent&);
diff -Naur MagicSetEditor2-2.1.2/src/script/to_value.hpp MagicSetEditor2-master/src/script/to_value.hpp
--- MagicSetEditor2-2.1.2/src/script/to_value.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/script/to_value.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -145,9 +145,9 @@
// ----------------------------------------------------------------------------- : Collections : maps
-template <typename V>
-ScriptValueP get_member(const map<String,V>& m, const String& name) {
- typename map<String,V>::const_iterator it = m.find(name);
+template <typename Container>
+ScriptValueP get_member(const Container& m, const String& name) {
+ auto it = m.find(name);
if (it != m.end()) {
return to_script(it->second);
} else {
@@ -403,6 +403,10 @@
return make_intrusive<ScriptMap<map<K,V>>>(v);
}
template <typename K, typename V>
+inline ScriptValueP to_script(const unordered_map<K,V>* v) {
+ return make_intrusive<ScriptMap<unordered_map<K,V>>>(v);
+}
+template <typename K, typename V>
inline ScriptValueP to_script(const IndexMap<K,V>* v) {
return make_intrusive<ScriptMap<IndexMap<K,V>>>(v);
}
diff -Naur MagicSetEditor2-2.1.2/src/util/io/get_member.hpp MagicSetEditor2-master/src/util/io/get_member.hpp
--- MagicSetEditor2-2.1.2/src/util/io/get_member.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/util/io/get_member.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -56,6 +56,7 @@
template <typename T> void handle(const Scriptable<T>& );
template <typename T> void handle(const vector<T>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const map<K,V>& c) { value = to_script(&c); }
+ template <typename K, typename V> void handle(const unordered_map<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const IndexMap<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const DelayedIndexMaps<K,V>&) {}
template <typename K, typename V> void handle(const DelayedIndexMapsData<K,V>& c);
diff -Naur MagicSetEditor2-2.1.2/src/util/locale.hpp MagicSetEditor2-master/src/util/locale.hpp
--- MagicSetEditor2-2.1.2/src/util/locale.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/util/locale.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -49,9 +49,11 @@
String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity);
/// Translate 'key' in the for a Package using the current locale
+[[deprecated]]
String tr(const Package&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Package using the current locale
+[[deprecated]]
String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def);
/// A localized string for menus
diff -Naur MagicSetEditor2-2.1.2/src/util/prec.hpp MagicSetEditor2-master/src/util/prec.hpp
--- MagicSetEditor2-2.1.2/src/util/prec.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/util/prec.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -40,6 +40,7 @@
#include <vector>
#include <map>
#include <set>
+#include <unordered_map>
using namespace std;
#undef RGB
diff -Naur MagicSetEditor2-2.1.2/src/util/regex.hpp MagicSetEditor2-master/src/util/regex.hpp
--- MagicSetEditor2-2.1.2/src/util/regex.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/util/regex.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -31,23 +31,18 @@
// ----------------------------------------------------------------------------- : Boost implementation
#if USE_BOOST_REGEX
- // needed for boost::regex
- inline std::size_t hash_value(wxUniChar const& x) {
- boost::hash<int> hasher;
- return hasher(static_cast<int>(x));
- }
- /*
- // fix: boost regex doesn't like that wxUniChar can't be constructed from an int
- namespace boost {
- namespace BOOST_REGEX_DETAIL_NS {
- inline bool can_start(wxUniChar c, const unsigned char* map, unsigned char mask) {
- return can_start(c.GetValue(), map, mask);
- }
- inline bool can_start(wxUniCharRef c, const unsigned char* map, unsigned char mask) {
- return can_start(c.GetValue(), map, mask);
- }
+ // needed for boost::regex to compute hash values of unicode chars
+ #if BOOST_VERSION < 107600
+ inline std::size_t hash_value(wxUniChar const& x) {
+ boost::hash<int> hasher;
+ return hasher(static_cast<int>(x));
}
- }*/
+ #else
+ // boost > 1.76 uses its own hash function that needs operator +
+ inline int operator + (wxUniChar x, unsigned int y) {
+ return static_cast<int>(x) + y;
+ }
+ #endif
/// Our own regular expression wrapper
/** Suppors both boost::regex and wxRegEx.
diff -Naur MagicSetEditor2-2.1.2/src/util/string.hpp MagicSetEditor2-master/src/util/string.hpp
--- MagicSetEditor2-2.1.2/src/util/string.hpp 2020-09-27 20:12:17.000000000 -0400
+++ MagicSetEditor2-master/src/util/string.hpp 2021-07-06 11:54:44.000000000 -0400
@@ -33,6 +33,17 @@
#endif
}
+#if wxVERSION_NUMBER < 3100
+// wxWidgets 3.1.0 added this specialization
+namespace std {
+ template<> struct hash<String> {
+ size_t operator()(String const& s) const {
+ return std::hash<std::wstring>()(s.ToStdWstring());
+ }
+ };
+}
+#endif
+
// ----------------------------------------------------------------------------- : Unicode
/// u if UNICODE is defined, a otherwise
|