mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Editing of keywords
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@255 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#include <data/set.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <data/action/keyword.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
|
||||
@@ -47,8 +49,49 @@ void KeywordList::onChangeSet() {
|
||||
}
|
||||
|
||||
void KeywordList::onAction(const Action& action, bool undone) {
|
||||
//TYPE_CASE(action, AddKeywordAction) {
|
||||
//}
|
||||
TYPE_CASE(action, AddKeywordAction) {
|
||||
if (undone) {
|
||||
long pos = selected_item_pos;
|
||||
refreshList();
|
||||
if (action.keyword == selected_item) {
|
||||
// select the next keyword, if not possible, select the last
|
||||
if (pos + 1 < GetItemCount()) {
|
||||
selectItemPos(pos, true);
|
||||
} else {
|
||||
selectItemPos(GetItemCount() - 1, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// select the new keyword
|
||||
selectItem(action.keyword, false /*list will be refreshed anyway*/, true);
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
TYPE_CASE(action, RemoveKeywordAction) {
|
||||
if (undone) {
|
||||
// select the re-added keyword
|
||||
selectItem(action.keyword, false /*list will be refreshed anyway*/, true);
|
||||
refreshList();
|
||||
} else {
|
||||
long pos = selected_item_pos;
|
||||
refreshList();
|
||||
if (action.keyword == selected_item) {
|
||||
// select the next keyword, if not possible, select the last
|
||||
if (pos + 1 < GetItemCount()) {
|
||||
selectItemPos(pos, true);
|
||||
} else {
|
||||
selectItemPos(GetItemCount() - 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
|
||||
if (value) {
|
||||
// this is indeed an action on a keyword, refresh
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordListBase : for ItemList
|
||||
@@ -83,8 +126,8 @@ bool KeywordList::compareItems(void* a, void* b) const {
|
||||
case 1: return ka.match < kb.match;
|
||||
case 2: return ka.mode < kb.mode;
|
||||
//case 3:
|
||||
//case 4:
|
||||
default: // TODO: 3 and 4
|
||||
case 4: return ka.reminder.getUnparsed() < kb.reminder.getUnparsed();
|
||||
default: // TODO: 3
|
||||
return ka.keyword < kb.keyword;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +141,7 @@ String KeywordList::OnGetItemText (long pos, long col) const {
|
||||
case 1: return match_string(kw);
|
||||
case 2: return kw.mode;
|
||||
case 3: return _("TODO");
|
||||
case 4: return _("TODO");
|
||||
case 4: return kw.reminder.getUnparsed();
|
||||
default: return wxEmptyString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ TextField& TextCtrl::getField() {
|
||||
assert(!viewers.empty());
|
||||
return static_cast<TextField&>(*viewers.front()->getField());
|
||||
}
|
||||
TextFieldP TextCtrl::getFieldP() {
|
||||
assert(!viewers.empty());
|
||||
return static_pointer_cast<TextField>(viewers.front()->getField());
|
||||
}
|
||||
void TextCtrl::updateSize() {
|
||||
wxSize cs = GetClientSize();
|
||||
Style& style = getStyle();
|
||||
@@ -49,36 +53,15 @@ void TextCtrl::updateSize() {
|
||||
}
|
||||
|
||||
void TextCtrl::setValue(String* value, bool untagged) {
|
||||
if (value != this->value) {
|
||||
this->value = value;
|
||||
// create a new value, for a different underlying actual value
|
||||
ValueViewer& viewer = *viewers.front();
|
||||
TextValueP new_value(new FakeTextValue(static_pointer_cast<TextField>(viewer.getField()), this->value, untagged));
|
||||
viewer.setValue(new_value);
|
||||
updateSize();
|
||||
valueChanged();
|
||||
}
|
||||
setValue(new_shared4<FakeTextValue>(getFieldP(), value, true, untagged));
|
||||
}
|
||||
void TextCtrl::valueChanged() {
|
||||
if (!viewers.empty()) {
|
||||
TextValue& tv = static_cast<TextValue&>(*viewers.front()->getValue());
|
||||
tv.value.assign(value ? String(*value) : String(wxEmptyString));
|
||||
viewers.front()->onValueChange();
|
||||
}
|
||||
void TextCtrl::setValue(const FakeTextValueP& value) {
|
||||
value->retrieve();
|
||||
viewers.front()->setValue(value);
|
||||
updateSize();
|
||||
onChange();
|
||||
}
|
||||
void TextCtrl::onAction(const Action& action, bool undone) {
|
||||
DataEditor::onAction(action, undone);
|
||||
/*
|
||||
TYPE_CASE(action, TextValueAction) {
|
||||
FakeTextValue& tv = static_cast<FakeTextValue&>(*viewers.front()->getValue());
|
||||
if (tv.equals(action.valueP.get())) {
|
||||
// the value has changed
|
||||
if (value) *value = tv.value();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void TextCtrl::onChangeSet() {
|
||||
DataEditor::onChangeSet();
|
||||
// initialize
|
||||
@@ -86,7 +69,7 @@ void TextCtrl::onChangeSet() {
|
||||
// create a field, style and value
|
||||
TextFieldP field(new TextField);
|
||||
TextStyleP style(new TextStyle(field));
|
||||
TextValueP value(new FakeTextValue(field, nullptr, false));
|
||||
TextValueP value(new FakeTextValue(field, nullptr, false, false));
|
||||
// set stuff
|
||||
field->index = 0;
|
||||
field->multi_line = multi_line;
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/card_editor.hpp>
|
||||
|
||||
class TextField;
|
||||
class TextStyle;
|
||||
DECLARE_POINTER_TYPE(TextField);
|
||||
DECLARE_POINTER_TYPE(FakeTextValue);
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextCtrl
|
||||
|
||||
@@ -31,16 +32,20 @@ class TextCtrl : public DataEditor {
|
||||
TextCtrl(Window* parent, int id, bool multi_line, long style = 0);
|
||||
|
||||
/// Set the value that is being edited
|
||||
/** value can be a nullptr*/
|
||||
void setValue(String* value, bool untagged = false);
|
||||
/// Notification that the value has changed outside this control
|
||||
void valueChanged();
|
||||
/// Set the value that is being edited
|
||||
void setValue(const FakeTextValueP& value);
|
||||
|
||||
/// Update the size, for example after changing the style
|
||||
void updateSize();
|
||||
|
||||
/// Get access to the field used by the control
|
||||
TextField& getField();
|
||||
/// Get access to the field used by the control
|
||||
TextFieldP getFieldP();
|
||||
/// Get access to the style used by the control
|
||||
TextStyle& getStyle();
|
||||
/// Update the size, for example after changing the style
|
||||
void updateSize();
|
||||
|
||||
/// Uses a native look
|
||||
virtual bool nativeLook() const { return true; }
|
||||
@@ -49,8 +54,6 @@ class TextCtrl : public DataEditor {
|
||||
|
||||
virtual void draw(DC& dc);
|
||||
|
||||
/// When an action is received, change the underlying value
|
||||
virtual void onAction(const Action&, bool undone);
|
||||
virtual void onChangeSet();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -272,6 +272,7 @@ CardP CardsPanel::selectedCard() const {
|
||||
return card_list->getCard();
|
||||
}
|
||||
void CardsPanel::selectCard(const CardP& card) {
|
||||
if (!set) return; // we want onChangeSet first
|
||||
card_list->setCard(card);
|
||||
editor->setCard(card);
|
||||
notes->setValue(card ? &card->notes : nullptr);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <gui/icon_menu.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <data/action/keyword.hpp>
|
||||
#include <data/field/text.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
@@ -29,12 +30,14 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
panel = new Panel(splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* no tab traversal*/);
|
||||
keyword = new TextCtrl(panel, wxID_ANY, false);
|
||||
match = new TextCtrl(panel, wxID_ANY, false);
|
||||
reminder = new TextCtrl(panel, wxID_ANY, false);
|
||||
reminder = new TextCtrl(panel, wxID_ANY, true); // allow multiline for wordwrap
|
||||
rules = new TextCtrl(panel, wxID_ANY, true);
|
||||
fixed = new wxStaticText(panel, wxID_ANY, _("This is a standard $game keyword, you can not edit it. ")
|
||||
_("If you make a copy of the keyword your copy will take precedent."));
|
||||
errors = new wxStaticText(panel, wxID_ANY, _(""));
|
||||
// init sizer for panel
|
||||
wxSizer* sp = new wxBoxSizer(wxVERTICAL);
|
||||
sp->Add(new wxStaticText(panel, wxID_ANY, _("This is a standard $game keyword, you can not edit it. ")
|
||||
_("If you make a copy of the keyword your copy will take precedent.")), 0, wxALL, 6);
|
||||
sp = new wxBoxSizer(wxVERTICAL);
|
||||
sp->Add(fixed, 0, wxALL, 6);
|
||||
sp->Add(new wxStaticText(panel, wxID_ANY, _("Keyword:")), 0, wxALL, 6);
|
||||
sp->Add(keyword, 0, wxEXPAND | wxALL & ~wxTOP, 6);
|
||||
wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, panel, _("Match"));
|
||||
@@ -43,7 +46,8 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
s2->Add(new wxStaticText(panel, wxID_ANY, _("Parameters:")), 0, wxALL, 6);
|
||||
sp->Add(s2, 0, wxEXPAND | wxALL, 6);
|
||||
sp->Add(new wxStaticText(panel, wxID_ANY, _("Reminder:")), 0, wxALL, 6);
|
||||
sp->Add(reminder, 0, wxEXPAND | wxALL & ~wxTOP, 6);
|
||||
sp->Add(reminder, 1, wxEXPAND | wxALL & ~wxTOP, 6);
|
||||
sp->Add(errors, 0, wxALL & ~wxTOP, 6);
|
||||
sp->Add(new wxStaticText(panel, wxID_ANY, _("Example:")), 0, wxALL, 6);
|
||||
sp->Add(new wxStaticText(panel, wxID_ANY, _("Rules:")), 0, wxALL, 6);
|
||||
sp->Add(rules, 1, wxEXPAND | wxALL & ~wxTOP, 6);
|
||||
@@ -144,20 +148,43 @@ void KeywordsPanel::onChangeSet() {
|
||||
match ->updateSize();
|
||||
reminder->setSet(set);
|
||||
reminder->getStyle().padding_bottom = 2;
|
||||
match ->getStyle().font.size = 10;
|
||||
match ->getStyle().font.font.SetPointSize(10);
|
||||
reminder->updateSize();
|
||||
rules ->setSet(set);
|
||||
// re-layout
|
||||
panel->Layout();
|
||||
}
|
||||
|
||||
void KeywordsPanel::onAction(const Action& action, bool undone) {
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
KeywordReminderTextValue* value = dynamic_cast<KeywordReminderTextValue*>(action.valueP.get());
|
||||
if (value && &value->keyword == list->getKeyword().get()) {
|
||||
// the current keyword's reminder text changed
|
||||
errors->SetLabel(value->errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
|
||||
if (ev.keyword) {
|
||||
panel->Enable(!ev.keyword->fixed);
|
||||
keyword->setValue(&ev.keyword->keyword, true);
|
||||
match ->setValue(&ev.keyword->match);
|
||||
rules ->setValue(&ev.keyword->rules);
|
||||
Keyword& kw = *ev.keyword;
|
||||
//sp->Show(fixed, kw.fixed);
|
||||
fixed->SetLabel(kw.fixed ? _("This is a standard $game keyword, you can not edit it. ")
|
||||
_("If you make a copy of the keyword your copy will take precedent.")
|
||||
: _(""));
|
||||
Layout();
|
||||
keyword ->setValue(new_shared5<KeywordTextValue> (keyword->getFieldP(), &kw, &kw.keyword, !kw.fixed, true));
|
||||
match ->setValue(new_shared4<KeywordTextValue> (match->getFieldP(), &kw, &kw.match, !kw.fixed));
|
||||
rules ->setValue(new_shared4<KeywordTextValue> (rules->getFieldP(), &kw, &kw.rules, !kw.fixed));
|
||||
shared_ptr<KeywordReminderTextValue> reminder_value(new KeywordReminderTextValue(reminder->getFieldP(), &kw, !kw.fixed));
|
||||
reminder->setValue(reminder_value);
|
||||
errors->SetLabel(reminder_value->errors);
|
||||
} else {
|
||||
panel->Enable(false);
|
||||
keyword ->setValue(nullptr);
|
||||
match ->setValue(nullptr);
|
||||
rules ->setValue(nullptr);
|
||||
reminder->setValue(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class KeywordsPanel : public SetWindowPanel {
|
||||
~KeywordsPanel();
|
||||
|
||||
virtual void onChangeSet();
|
||||
virtual void onAction(const Action&, bool);
|
||||
|
||||
// --------------------------------------------------- : UI
|
||||
|
||||
@@ -41,12 +42,15 @@ class KeywordsPanel : public SetWindowPanel {
|
||||
// --------------------------------------------------- : Controls
|
||||
wxSplitterWindow* splitter;
|
||||
wxPanel* panel;
|
||||
wxSizer* sp;
|
||||
KeywordList* list;
|
||||
TextCtrl* keyword;
|
||||
TextCtrl* match;
|
||||
TextCtrl* reminder;
|
||||
TextCtrl* rules;
|
||||
IconMenu* menuKeyword;
|
||||
wxStaticText* fixed;
|
||||
wxStaticText* errors;
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
void onKeywordSelect(KeywordSelectEvent& ev);
|
||||
|
||||
Reference in New Issue
Block a user