Commit eb29499a authored by twanvl's avatar twanvl

Working on the keywords panel;

Correct styling data now shown on style panel
parent 66275038
......@@ -160,7 +160,7 @@ void KeywordReminderTextValue::highlight(const String& code) {
size_t end = code.find_first_not_of(_("0123456789"), pos + 5);
if (end == String::npos) end = code.size();
String param = code.substr(pos, end-pos);
new_value += _("<") + param + _(">") + param + _("</") + param + _(">");
new_value += _("<ref-") + param + _(">") + param + _("</ref-") + param + _(">");
pos = end;
} else {
new_value += c;
......
......@@ -115,20 +115,24 @@ FakeTextValue::FakeTextValue(const TextFieldP& field, String* underlying, bool e
{}
void FakeTextValue::store() {
if (editable) {
*underlying = untagged ? untag(value) : value;
} else {
retrieve();
if (underlying) {
if (editable) {
*underlying = untagged ? untag(value) : value;
} else {
retrieve();
}
}
}
void FakeTextValue::retrieve() {
value.assign(untagged ? escape(*underlying) : *underlying);
if (underlying) {
value.assign(untagged ? escape(*underlying) : *underlying);
} else {
value.assign(wxEmptyString);
}
}
void FakeTextValue::onAction(Action& a, bool undone) {
if (underlying) {
store();
}
store();
}
bool FakeTextValue::equals(const Value* that) {
......
......@@ -52,7 +52,7 @@ void read_compat(Reader& tag, Keyword* k) {
k->match += separator.substr(start + 1, end - start - 1);
}
if (!parameter.empty()) {
k->match += _("<param>") + parameter + _("</param>");
k->match += _("<atom-param>") + parameter + _("</atom-param>");
}
}
......@@ -120,7 +120,7 @@ void Keyword::prepare(const vector<KeywordParamP>& param_types, bool force) {
// Parse the 'match' string
for (size_t i = 0 ; i < match.size() ;) {
Char c = match.GetChar(i);
if (is_substr(match, i, _("<param"))) {
if (is_substr(match, i, _("<atom-param"))) {
// parameter, determine type...
size_t start = skip_tag(match, i), end = match_close_tag(match, i);
String type = match.substr(start, end-start);
......@@ -237,7 +237,7 @@ void KeywordDatabase::add(const Keyword& kw) {
KeywordTrie* cur = root->insertAnyStar();
for (size_t i = 0 ; i < kw.match.size() ;) {
Char c = kw.match.GetChar(i);
if (is_substr(kw.match, i, _("<param"))) {
if (is_substr(kw.match, i, _("<atom-param"))) {
// tag, parameter, match anything
cur = cur->insertAnyStar();
i = match_close_tag_end(kw.match, i);
......
......@@ -58,7 +58,7 @@ class Keyword {
String keyword; ///< The keyword, only for human use
String rules; ///< Rules/explanation
String match; ///< String to match, <param> tags are used for parameters
String match; ///< String to match, <atom-param> tags are used for parameters
vector<KeywordParamP> parameters; ///< The types of parameters
StringScript reminder; ///< Reminder text of the keyword
String mode; ///< Mode of use, can be used by scripts (only gives the name)
......
......@@ -99,8 +99,8 @@ void KeywordList::onAction(const Action& action, bool undone) {
String match_string(const Keyword& a) {
return untag(replace_all(replace_all(
a.match,
_("<param>"), _("")),
_("</param>"), _(""))
_("<atom-param>"), _("")),
_("</atom-param>"), _(""))
);
}
......
......@@ -91,6 +91,7 @@ void NativeLookEditor::resizeViewers() {
}
void NativeLookEditor::onInit() {
DataEditor::onInit();
// Give viewers a chance to show/hide controls (scrollbar) when selecting other editors
FOR_EACH_EDITOR {
e->onShow(true);
......@@ -191,7 +192,6 @@ StylingEditor::StylingEditor(Window* parent, int id, long style)
{}
void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) {
this->stylesheet = stylesheet;
setStyles(set->stylesheet, stylesheet->styling_style);
setData(set->stylingDataFor(*stylesheet));
}
......
......@@ -72,8 +72,6 @@ class StylingEditor : public NativeLookEditor {
protected:
virtual void onChangeSet();
private:
StyleSheetP stylesheet; ///< The stylesheet for which we are showing the styling data
};
// ----------------------------------------------------------------------------- : EOF
......
......@@ -12,12 +12,15 @@
#include <gui/icon_menu.hpp>
#include <gui/util.hpp>
#include <data/keyword.hpp>
#include <data/game.hpp>
#include <data/action/value.hpp>
#include <data/action/keyword.hpp>
#include <data/field/text.hpp>
#include <util/window_id.hpp>
#include <wx/listctrl.h>
#include <wx/splitter.h>
#include <wx/statline.h>
#include <wx/artprov.h>
// ----------------------------------------------------------------------------- : KeywordsPanel
......@@ -32,25 +35,42 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
match = 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, _(""));
// warning about fixed keywords
fixedL = new wxStaticText(panel, wxID_ANY, _(""));
wxStaticBitmap* fixedI = new wxStaticBitmap(panel, wxID_ANY, wxArtProvider::GetBitmap(wxART_WARNING));
fixed = new wxBoxSizer(wxVERTICAL);
wxSizer* s0 = new wxBoxSizer(wxHORIZONTAL);
s0->Add(fixedI, 0, wxALIGN_CENTER | wxRIGHT, 10);
s0->Add(fixedL, 0, wxALIGN_CENTER_VERTICAL);
fixed->Add(new wxStaticLine(panel), 0, wxEXPAND | wxBOTTOM, 8);
fixed->Add(s0, 0, wxALL & ~wxTOP | wxALIGN_CENTER, 8);
fixed->Add(new wxStaticLine(panel), 0, wxEXPAND | wxBOTTOM, 8);
// init sizer for panel
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"));
s2->Add(new wxStaticText(panel, wxID_ANY, _("Keyword format:")), 0, wxALL, 6);
s2->Add(match, 0, wxEXPAND | wxALL & ~wxTOP, 6);
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, 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);
sp->Add(fixed, 0, wxEXPAND); sp->Show(fixed,false);
wxSizer* s1 = new wxBoxSizer(wxVERTICAL);
s1->Add(new wxStaticText(panel, wxID_ANY, _("Keyword:")), 0);
s1->Add(keyword, 0, wxEXPAND | wxTOP, 2);
sp->Add(s1, 0, wxEXPAND | wxLEFT, 2);
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(new wxStaticText(panel, wxID_ANY, _("Match:")), 0);
s2->Add(match, 0, wxEXPAND | wxTOP, 2);
s2->Add(new wxStaticText(panel, wxID_ANY, _("Parameters:")), 0, wxTOP, 6);
sp->Add(s2, 0, wxEXPAND | wxLEFT, 2);
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
wxSizer* s3 = new wxBoxSizer(wxVERTICAL);
s3->Add(new wxStaticText(panel, wxID_ANY, _("Reminder:")), 0);
s3->Add(reminder, 1, wxEXPAND | wxTOP, 2);
s3->Add(errors, 0, wxEXPAND | wxTOP, 4);
s3->Add(new wxStaticText(panel, wxID_ANY, _("Example:")), 0, wxTOP, 6);
sp->Add(s3, 1, wxEXPAND | wxLEFT, 2);
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
wxSizer* s4 = new wxBoxSizer(wxVERTICAL);
s4->Add(new wxStaticText(panel, wxID_ANY, _("Rules:")), 0);
s4->Add(rules, 1, wxEXPAND | wxTOP, 2);
sp->Add(s4, 1, wxEXPAND | wxLEFT, 2);
panel->SetSizer(sp);
// init splitter
splitter->SetMinimumPaneSize(100);
......@@ -135,6 +155,8 @@ void KeywordsPanel::onCommand(int id) {
void KeywordsPanel::onChangeSet() {
list->setSet(set);
// warning label (depends on game name)
fixedL->SetLabel(format_string(_LABEL_("standard keyword"), set->game->short_name));
// init text controls
keyword ->setSet(set);
keyword ->getStyle().font.size = 16;
......@@ -169,17 +191,14 @@ void KeywordsPanel::onAction(const Action& action, bool undone) {
void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
if (ev.keyword) {
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();
sp->Show(fixed, kw.fixed);
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);
sp->Layout();
} else {
keyword ->setValue(nullptr);
match ->setValue(nullptr);
......
......@@ -49,8 +49,16 @@ class KeywordsPanel : public SetWindowPanel {
TextCtrl* reminder;
TextCtrl* rules;
IconMenu* menuKeyword;
wxStaticText* fixed;
wxStaticText* fixedL;
wxSizer* fixed;
wxStaticText* errors;
/// Controls to edit a parameter
struct ParamEditor {
wxStaticText* label;
wxChoice* type;
bool shown;
};
vector<ParamEditor> params;
// --------------------------------------------------- : Events
void onKeywordSelect(KeywordSelectEvent& ev);
......
......@@ -53,10 +53,12 @@ void StylePanel::onChangeSet() {
void StylePanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, ChangeSetStyleAction) {
list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetFor(card));
}
TYPE_CASE(action, ChangeCardStyleAction) {
if (action.card == card) {
list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetFor(card));
}
}
use_for_all->Enable(card && card->stylesheet);
......@@ -67,6 +69,7 @@ void StylePanel::onAction(const Action& action, bool undone) {
void StylePanel::selectCard(const CardP& card) {
this->card = card;
preview->setCard(card);
editor->showStylesheet(set->stylesheetFor(card));
list->select(set->stylesheetFor(card)->name(), false);
use_for_all->Enable(card && card->stylesheet);
}
......
......@@ -57,7 +57,7 @@ double TextElements::scaleStep() const {
return m;
}
// Colors for <param> tags
// Colors for <atom-param> tags
Color param_colors[] =
{ Color(0,170,0)
, Color(0,0,200)
......@@ -109,19 +109,19 @@ struct TextElementsFromString {
else if (is_substr(text, tag_start, _("</code"))) code -= 1;
else if (is_substr(text, tag_start, _( "<ref-param"))) {
// determine the param being referenced
// from a tag <param123>
// from a tag <ref-param123>
if (pos != String::npos) {
String ref = text.substr(tag_start + 6, pos - tag_start - 7);
String ref = text.substr(tag_start + 10, pos - tag_start - 11);
long ref_n;
if (ref.ToLong(&ref_n)) {
param_id = ref_n;
param_id = (ref_n - 1)%param_colors_count + param_colors_count;
}
}
param_ref += 1;
}
else if (is_substr(text, tag_start, _("</ref-param"))) param_ref -= 1;
else if (is_substr(text, tag_start, _( "<param"))) param += 1;
else if (is_substr(text, tag_start, _("</param"))) param -= 1;
else if (is_substr(text, tag_start, _( "<atom-param"))) param += 1;
else if (is_substr(text, tag_start, _("</atom-param"))) param -= 1;
else if (is_substr(text, tag_start, _( "<line"))) line += 1;
else if (is_substr(text, tag_start, _("</line"))) line -= 1;
else if (is_substr(text, tag_start, _("<atom"))) {
......
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