mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Added ChangeKeywordModeAction;
Hopefully fixed the 'Invalid multibyte character' build error on linux (I was using left/right-angle-brackets in string constants); Fixed 'cost' keywords; git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@263 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -190,3 +190,17 @@ void KeywordReminderTextValue::highlight(const String& code, const vector<Script
|
||||
// set
|
||||
value = new_value;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Changing keywords : mode
|
||||
|
||||
ChangeKeywordModeAction::ChangeKeywordModeAction(Keyword& keyword, const String& new_mode)
|
||||
: keyword(keyword), mode(new_mode)
|
||||
{}
|
||||
|
||||
String ChangeKeywordModeAction::getName(bool to_undo) const {
|
||||
return _("Keyword mode");
|
||||
}
|
||||
|
||||
void ChangeKeywordModeAction::perform(bool to_undo) {
|
||||
swap(keyword.mode, mode);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,15 @@ class KeywordReminderTextValue : public KeywordTextValue {
|
||||
|
||||
/// Changing the mode of a keyword
|
||||
class ChangeKeywordModeAction : public Action {
|
||||
public:
|
||||
ChangeKeywordModeAction(Keyword& keyword, const String& new_mode);
|
||||
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
//private:
|
||||
Keyword& keyword;
|
||||
String mode;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -13,6 +13,7 @@ class KeywordTrie;
|
||||
DECLARE_TYPEOF(map<Char COMMA KeywordTrie*>);
|
||||
DECLARE_TYPEOF_COLLECTION(KeywordTrie*);
|
||||
DECLARE_TYPEOF_COLLECTION(KeywordP);
|
||||
DECLARE_TYPEOF_COLLECTION(KeywordModeP);
|
||||
DECLARE_TYPEOF_COLLECTION(KeywordParamP);
|
||||
DECLARE_TYPEOF_COLLECTION(const Keyword*);
|
||||
|
||||
@@ -66,6 +67,23 @@ IMPLEMENT_REFLECTION(Keyword) {
|
||||
}
|
||||
|
||||
|
||||
size_t Keyword::findMode(const vector<KeywordModeP>& modes) const {
|
||||
// find
|
||||
size_t id = 0;
|
||||
FOR_EACH_CONST(m, modes) {
|
||||
if (mode == m->name) return id;
|
||||
++id;
|
||||
}
|
||||
// default
|
||||
id = 0;
|
||||
FOR_EACH_CONST(m, modes) {
|
||||
if (m->is_default) return id;
|
||||
++id;
|
||||
}
|
||||
// not found
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Regex stuff
|
||||
|
||||
/// Make sure the given regex does no capturing
|
||||
@@ -291,6 +309,7 @@ String KeywordDatabase::expand(const String& text,
|
||||
s = remove_tag_contents(s, _("<atom-keyword>")); // OLD, TODO: REMOVEME
|
||||
s = remove_tag_contents(s, _("<atom-kwpph>"));
|
||||
s = remove_tag(s, _("<keyword-param"));
|
||||
s = remove_tag(s, _("<param-"));
|
||||
String untagged = untag_no_escape(s);
|
||||
|
||||
if (!root) return s;
|
||||
@@ -386,6 +405,8 @@ String KeywordDatabase::expand(const String& text,
|
||||
ctx.setVariable(_("input"), to_script(part));
|
||||
param = kwp.script.invoke(ctx)->toString();
|
||||
}
|
||||
part = _("<param-") + kwp.name + _(">") + part + _("</param-") + kwp.name + _(">");
|
||||
param = _("<param-") + kwp.name + _(">") + param + _("</param-") + kwp.name + _(">");
|
||||
ctx.setVariable(String(_("param")) << (int)(j/2), to_script(param));
|
||||
}
|
||||
total += part;
|
||||
|
||||
@@ -70,6 +70,10 @@ class Keyword {
|
||||
wxRegEx matchRe;
|
||||
bool fixed; ///< Is this keyword uneditable? (true for game keywods, false for set keywords)
|
||||
|
||||
/// Find the index of the mode in a list of possibilities.
|
||||
/** Returns the default if not found and 0 if there is no default */
|
||||
size_t findMode(const vector<KeywordModeP>& modes) const;
|
||||
|
||||
/// Prepare the expansion: (re)generate matchRe and the list of parameters.
|
||||
/** Throws when there is an error in the input
|
||||
* @param param_types A list of all parameter types.
|
||||
|
||||
@@ -92,6 +92,9 @@ void KeywordList::onAction(const Action& action, bool undone) {
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
TYPE_CASE_(action, ChangeKeywordModeAction) {
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordListBase : for ItemList
|
||||
@@ -99,8 +102,8 @@ void KeywordList::onAction(const Action& action, bool undone) {
|
||||
String match_string(const Keyword& a) {
|
||||
return untag(replace_all(replace_all(
|
||||
a.match,
|
||||
_("<atom-param>"), _("‹")),
|
||||
_("</atom-param>"), _("›"))
|
||||
_("<atom-param>"), LEFT_ANGLE_BRACKET),
|
||||
_("</atom-param>"), RIGHT_ANGLE_BRACKET)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,11 @@ Rotation TextCtrl::getRotation() const {
|
||||
|
||||
void TextCtrl::draw(DC& dc) {
|
||||
RotatedDC rdc(dc, getRotation(), QUALITY_LOW);
|
||||
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
if (viewers.empty() || !static_cast<FakeTextValue&>(*viewers.front()->getValue()).editable) {
|
||||
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
|
||||
} else {
|
||||
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
reminder = new TextCtrl(panel, wxID_ANY, true); // allow multiline for wordwrap
|
||||
rules = new TextCtrl(panel, wxID_ANY, true);
|
||||
errors = new wxStaticText(panel, wxID_ANY, _(""));
|
||||
mode = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr);
|
||||
mode = new wxChoice(panel, ID_KEYWORD_MODE, wxDefaultPosition, wxDefaultSize, 0, nullptr);
|
||||
add_param = new wxButton(panel, ID_KEYWORD_ADD_PARAM, _("Insert Parameter"));
|
||||
// warning about fixed keywords
|
||||
fixedL = new wxStaticText(panel, wxID_ANY, _(""));
|
||||
@@ -159,12 +159,19 @@ void KeywordsPanel::onCommand(int id) {
|
||||
break;
|
||||
case ID_KEYWORD_ADD_PARAM: {
|
||||
wxMenu param_menu;
|
||||
int id = ID_PARAM_TYPE_MIN;
|
||||
FOR_EACH(p, set->game->keyword_parameter_types) {
|
||||
param_menu.Append(wxID_ANY, p->name);
|
||||
param_menu.Append(id++, p->name);
|
||||
}
|
||||
add_param->PopupMenu(¶m_menu, 0, add_param->GetSize().y);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (id >= ID_PARAM_TYPE_MIN && id < ID_PARAM_TYPE_MAX) {
|
||||
// add parameter
|
||||
KeywordParamP param = set->game->keyword_parameter_types.at(id - ID_PARAM_TYPE_MIN);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +205,7 @@ void KeywordsPanel::onChangeSet() {
|
||||
FOR_EACH(m, set->game->keyword_modes) {
|
||||
mode->Append(m->name);
|
||||
}
|
||||
mode ->Enable(false);
|
||||
// re-layout
|
||||
panel->Layout();
|
||||
}
|
||||
@@ -210,6 +218,12 @@ void KeywordsPanel::onAction(const Action& action, bool undone) {
|
||||
errors->SetLabel(value->errors);
|
||||
}
|
||||
}
|
||||
TYPE_CASE(action, ChangeKeywordModeAction) {
|
||||
if (&action.keyword == list->getKeyword().get()) {
|
||||
// the current keyword's mode changed
|
||||
mode->SetSelection((int)list->getKeyword()->findMode(set->game->keyword_modes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
|
||||
@@ -223,7 +237,8 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
|
||||
reminder->setValue(reminder_value);
|
||||
errors->SetLabel(reminder_value->errors);
|
||||
add_param->Enable(!kw.fixed && !set->game->keyword_parameter_types.empty());
|
||||
mode->SetStringSelection(kw.mode);
|
||||
mode ->Enable(!kw.fixed && !set->game->keyword_modes.empty());
|
||||
mode->SetSelection((int)kw.findMode(set->game->keyword_modes));
|
||||
sp->Layout();
|
||||
} else {
|
||||
keyword ->setValue(nullptr);
|
||||
@@ -235,6 +250,16 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
|
||||
}
|
||||
}
|
||||
|
||||
void KeywordsPanel::onModeChange(wxCommandEvent& ev) {
|
||||
if (!list->getKeyword()) return;
|
||||
int sel = mode->GetSelection();
|
||||
if (sel >= 0 && (size_t)sel < set->game->keyword_modes.size()) {
|
||||
set->actions.add(new ChangeKeywordModeAction(*list->getKeyword(), set->game->keyword_modes[sel]->name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BEGIN_EVENT_TABLE(KeywordsPanel, wxPanel)
|
||||
EVT_KEYWORD_SELECT(wxID_ANY, KeywordsPanel::onKeywordSelect)
|
||||
EVT_KEYWORD_SELECT(wxID_ANY, KeywordsPanel::onKeywordSelect)
|
||||
EVT_CHOICE (ID_KEYWORD_MODE, KeywordsPanel::onModeChange)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
@@ -64,6 +64,7 @@ class KeywordsPanel : public SetWindowPanel {
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
void onKeywordSelect(KeywordSelectEvent& ev);
|
||||
void onModeChange(wxCommandEvent& ev);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -174,7 +174,7 @@ struct TextElementsFromString {
|
||||
line > 0 ? BREAK_LINE : BREAK_HARD);
|
||||
}
|
||||
if (bracket) {
|
||||
e->content = String(_("‹")) + c + _("›");
|
||||
e->content = String(LEFT_ANGLE_BRACKET) + c + RIGHT_ANGLE_BRACKET;
|
||||
} else {
|
||||
e->content = c;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,15 @@ const Char BYTE_ORDER_MARK[] = IF_UNICODE(L"\xFEFF", "\xEF\xBB\xBF");
|
||||
/// Writes a string to an output stream, encoded as UTF8
|
||||
void writeUTF8(wxTextOutputStream& stream, const String& str);
|
||||
|
||||
/// Some constants we like to use
|
||||
#ifdef UNICODE
|
||||
#define LEFT_ANGLE_BRACKET _("\x2039")
|
||||
#define RIGHT_ANGLE_BRACKET _("\x203A")
|
||||
#else
|
||||
#define LEFT_ANGLE_BRACKET _("<")
|
||||
#define RIGHT_ANGLE_BRACKET _(">")
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------- : Char functions
|
||||
|
||||
// Character set tests
|
||||
|
||||
+16
-12
@@ -99,17 +99,14 @@ enum ChildMenuID {
|
||||
, ID_CARD_ROTATE_90
|
||||
, ID_CARD_ROTATE_180
|
||||
, ID_CARD_ROTATE_270
|
||||
|
||||
// On cards panel
|
||||
, ID_COLLAPSE_NOTES
|
||||
// CardList
|
||||
, ID_SELECT_COLUMNS
|
||||
|
||||
// Keyword menu
|
||||
, ID_KEYWORD_ADD = 1101
|
||||
, ID_KEYWORD_REMOVE
|
||||
, ID_KEYWORD_PREV
|
||||
, ID_KEYWORD_NEXT
|
||||
, ID_KEYWORD_ADD_PARAM
|
||||
, ID_KEYWORD_REF_PARAM
|
||||
|
||||
// Format menu
|
||||
, ID_FORMAT_BOLD = 1201
|
||||
@@ -150,15 +147,22 @@ enum ChildMenuID {
|
||||
, ID_SHAPE_STAR
|
||||
, ID_SHAPE_MAX
|
||||
, ID_SIDES
|
||||
|
||||
// On cards panel
|
||||
, ID_COLLAPSE_NOTES = 3001
|
||||
|
||||
// Style panel
|
||||
, ID_STYLE_USE_FOR_ALL = 3011
|
||||
|
||||
// CardList
|
||||
, ID_SELECT_COLUMNS = 3001
|
||||
// Keywords panel
|
||||
, ID_KEYWORD_ADD_PARAM = 3021
|
||||
, ID_KEYWORD_REF_PARAM
|
||||
, ID_KEYWORD_MODE
|
||||
, ID_PARAM_TYPE_MIN = 3101
|
||||
, ID_PARAM_TYPE_MAX = 3199
|
||||
|
||||
// Statistics
|
||||
, ID_FIELD_LIST = 3101
|
||||
|
||||
// Style
|
||||
, ID_STYLE_USE_FOR_ALL = 3201
|
||||
// Statistics panel
|
||||
, ID_FIELD_LIST = 3031
|
||||
|
||||
// SymbolFont (Format menu)
|
||||
, ID_INSERT_SYMBOL_MENU_MIN = 3301
|
||||
|
||||
Reference in New Issue
Block a user