Commit edbd7e3b authored by twanvl's avatar twanvl

choice fields show only the highest level of choices in statistics panel

parent 839b0d37
...@@ -60,7 +60,7 @@ class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> { ...@@ -60,7 +60,7 @@ class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> {
* The top level group has first_id 0. * The top level group has first_id 0.
*/ */
int first_id; int first_id;
/// Is this a group? /// Is this a group?
bool isGroup() const; bool isGroup() const;
/// Can this Choice itself be chosen? /// Can this Choice itself be chosen?
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
DECLARE_TYPEOF_COLLECTION(String); DECLARE_TYPEOF_COLLECTION(String);
DECLARE_TYPEOF_COLLECTION(StatsDimensionP); DECLARE_TYPEOF_COLLECTION(StatsDimensionP);
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
// ----------------------------------------------------------------------------- : Statistics dimension // ----------------------------------------------------------------------------- : Statistics dimension
...@@ -33,16 +34,29 @@ StatsDimension::StatsDimension(const Field& field) ...@@ -33,16 +34,29 @@ StatsDimension::StatsDimension(const Field& field)
const ChoiceField* choice_field = dynamic_cast<const ChoiceField*>(&field); const ChoiceField* choice_field = dynamic_cast<const ChoiceField*>(&field);
if (choice_field) { if (choice_field) {
colors = choice_field->choice_colors; colors = choice_field->choice_colors;
int count = choice_field->choices->lastId(); /*int count = choice_field->choices->lastId();
for (int i = 0 ; i < count ; ++i) { for (int i = 0 ; i < count ; ++i) {
groups.push_back(choice_field->choices->choiceName(i)); groups.push_back(choice_field->choices->choiceName(i));
}*/
// only top level choices
FOR_EACH_CONST(g, choice_field->choices->choices) {
groups.push_back(g->name);
} }
// initialize script, primary_choice(card.{field_name})
Script& s = script.getScript();
s.addInstruction(I_GET_VAR, string_to_variable(_("primary choice")));
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
s.addInstruction(I_MEMBER_C, field.name);
s.addInstruction(I_CALL, 1);
s.addInstruction(I_NOP, string_to_variable(_("input")));
s.addInstruction(I_RET);
} else {
// initialize script, card.{field_name}
Script& s = script.getScript();
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
s.addInstruction(I_MEMBER_C, field.name);
s.addInstruction(I_RET);
} }
// initialize script, card.{field_name}
Script& s = script.getScript();
s.addInstruction(I_GET_VAR, string_to_variable(_("card")));
s.addInstruction(I_MEMBER_C, field.name);
s.addInstruction(I_RET);
} }
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) { IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
......
...@@ -427,7 +427,7 @@ void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const { ...@@ -427,7 +427,7 @@ void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const {
Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
if (draw_lines) { if (draw_lines) {
dc.SetPen(lerp(bg, fg, 0.5)); dc.SetPen(lerp(bg, fg, 0.5));
for (int i = 0 ; i < count ; ++i) { for (int i = 1 ; i <= count ; ++i) {
dc.DrawLine(RealPoint(rect.x + i*width, rect.top()), RealPoint(rect.x + i*width, rect.bottom())); dc.DrawLine(RealPoint(rect.x + i*width, rect.top()), RealPoint(rect.x + i*width, rect.bottom()));
} }
} }
...@@ -436,6 +436,29 @@ void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const { ...@@ -436,6 +436,29 @@ void GraphLabelAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const {
dc.DrawLine(rect.topLeft(), rect.bottomLeft()); dc.DrawLine(rect.topLeft(), rect.bottomLeft());
} else { } else {
// TODO // TODO
double height = rect.height / count; // width of an item
// Draw labels
double y = rect.bottom();
FOR_EACH_CONST(g, axis.groups) {
// draw label, aligned bottom center
RealSize text_size = dc.GetTextExtent(g.name);
//dc.SetClippingRegion(RealRect(x + 2, rect.bottom() + 3, width - 4, text_size.height));
dc.DrawText(g.name, align_in_rect(ALIGN_MIDDLE_RIGHT, text_size, RealRect(-3, y, 0, -height)));
//dc.DestroyClippingRegion();
y -= height;
}
// Draw lines
Color bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
if (draw_lines) {
dc.SetPen(lerp(bg, fg, 0.5));
for (int i = 1 ; i <= count ; ++i) {
dc.DrawLine(RealPoint(rect.left(), rect.bottom() - i*height), RealPoint(rect.right(), rect.bottom() - i*height));
}
}
// always draw axis line
dc.SetPen(fg);
dc.DrawLine(rect.bottomLeft(), rect.bottomRight());
} }
} }
} }
...@@ -560,6 +583,12 @@ void GraphControl::setLayout(GraphType type) { ...@@ -560,6 +583,12 @@ void GraphControl::setLayout(GraphType type) {
break; break;
} case GRAPH_TYPE_SCATTER: { } case GRAPH_TYPE_SCATTER: {
// TODO // TODO
intrusive_ptr<GraphContainer> combined(new GraphContainer());
combined->add(new_intrusive4<GraphLabelAxis>(0, HORIZONTAL, false, true));
combined->add(new_intrusive4<GraphLabelAxis>(1, VERTICAL, false, true));
//combined->add(new_intrusive2<BarGraph2D>(0,1));
graph = new_intrusive5<GraphWithMargins>(combined, 23,8,7,20);
break;
} default: } default:
graph = GraphP(); graph = GraphP();
} }
...@@ -574,8 +603,8 @@ void GraphControl::setData(const GraphDataP& data) { ...@@ -574,8 +603,8 @@ void GraphControl::setData(const GraphDataP& data) {
if (graph) { if (graph) {
graph->setData(data); graph->setData(data);
current_item.clear(); // TODO : preserve selection current_item.clear(); // TODO : preserve selection
Refresh(false);
} }
Refresh(false);
} }
void GraphControl::onPaint(wxPaintEvent&) { void GraphControl::onPaint(wxPaintEvent&) {
......
...@@ -12,10 +12,12 @@ ...@@ -12,10 +12,12 @@
#include <data/set.hpp> #include <data/set.hpp>
#include <data/game.hpp> #include <data/game.hpp>
#include <data/field/text.hpp> #include <data/field/text.hpp>
#include <data/field/choice.hpp>
DECLARE_TYPEOF_COLLECTION(FieldP); DECLARE_TYPEOF_COLLECTION(FieldP);
DECLARE_TYPEOF_COLLECTION(TextValue*); DECLARE_TYPEOF_COLLECTION(TextValue*);
DECLARE_TYPEOF_COLLECTION(String); DECLARE_TYPEOF_COLLECTION(String);
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
// ----------------------------------------------------------------------------- : Combined editor // ----------------------------------------------------------------------------- : Combined editor
...@@ -131,9 +133,31 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) { ...@@ -131,9 +133,31 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) {
return dependency_dummy; return dependency_dummy;
} }
// ----------------------------------------------------------------------------- : Choice values
// convert a full choice name into the name of the top level group it is in
SCRIPT_FUNCTION(primary_choice) {
SCRIPT_PARAM(ValueP,input);
ChoiceValueP value = dynamic_pointer_cast<ChoiceValue>(input);
if (!value) {
throw ScriptError(_("Argument to 'primary_choice' should be a choice field"));
}
// determine choice
int id = value->field().choices->choiceId(value->value);
// find the last group that still contains id
const vector<ChoiceField::ChoiceP>& choices = value->field().choices->choices;
FOR_EACH_CONST_REVERSE(c, choices) {
if (id >= c->first_id) {
SCRIPT_RETURN(c->name);
}
}
SCRIPT_RETURN(_(""));
}
// ----------------------------------------------------------------------------- : Init // ----------------------------------------------------------------------------- : Init
void init_script_editor_functions(Context& ctx) { void init_script_editor_functions(Context& ctx) {
ctx.setVariable(_("forward editor"), script_combined_editor); // combatability ctx.setVariable(_("forward editor"), script_combined_editor); // combatability
ctx.setVariable(_("combined editor"), script_combined_editor); ctx.setVariable(_("combined editor"), script_combined_editor);
ctx.setVariable(_("primary choice"), script_primary_choice);
} }
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <util/io/package_manager.hpp> // for "include file" semi hack #include <util/io/package_manager.hpp> // for "include file" semi hack
#include <stack> #include <stack>
DECLARE_TYPEOF_COLLECTION(int); DECLARE_TYPEOF_COLLECTION(Variable);
#ifdef __WXMSW__ #ifdef __WXMSW__
#define TokenType TokenType_ // some stupid windows header uses our name #define TokenType TokenType_ // some stupid windows header uses our name
...@@ -546,7 +546,7 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc ...@@ -546,7 +546,7 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
expectToken(input, _("]")); expectToken(input, _("]"));
} else if (minPrec <= PREC_FUN && token==_("(")) { } else if (minPrec <= PREC_FUN && token==_("(")) {
// function call, read arguments // function call, read arguments
vector<int> arguments; vector<Variable> arguments;
Token t = input.peek(); Token t = input.peek();
while (t != _(")") && t != TOK_EOF) { while (t != _(")") && t != TOK_EOF) {
if (input.peek(2) == _(":")) { if (input.peek(2) == _(":")) {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// ----------------------------------------------------------------------------- : Variables // ----------------------------------------------------------------------------- : Variables
typedef map<String, unsigned int> Variables; typedef map<String, Variable> Variables;
Variables variables; Variables variables;
DECLARE_TYPEOF(Variables); DECLARE_TYPEOF(Variables);
#ifdef _DEBUG #ifdef _DEBUG
...@@ -21,13 +21,13 @@ DECLARE_TYPEOF(Variables); ...@@ -21,13 +21,13 @@ DECLARE_TYPEOF(Variables);
#endif #endif
/// Return a unique name for a variable to allow for faster loopups /// Return a unique name for a variable to allow for faster loopups
unsigned int string_to_variable(const String& s) { Variable string_to_variable(const String& s) {
map<String, unsigned int>::iterator it = variables.find(s); map<String, unsigned int>::iterator it = variables.find(s);
if (it == variables.end()) { if (it == variables.end()) {
#ifdef _DEBUG #ifdef _DEBUG
variable_names.push_back(s); variable_names.push_back(s);
#endif #endif
unsigned int v = (unsigned int)variables.size(); Variable v = (Variable)variables.size();
variables.insert(make_pair(s,v)); variables.insert(make_pair(s,v));
return v; return v;
} else { } else {
...@@ -38,7 +38,7 @@ unsigned int string_to_variable(const String& s) { ...@@ -38,7 +38,7 @@ unsigned int string_to_variable(const String& s) {
/// Get the name of a vaiable /// Get the name of a vaiable
/** Warning: this function is slow, it should only be used for error messages and such. /** Warning: this function is slow, it should only be used for error messages and such.
*/ */
String variable_to_string(unsigned int v) { String variable_to_string(Variable v) {
FOR_EACH(vi, variables) { FOR_EACH(vi, variables) {
if (vi.second == v) return vi.first; if (vi.second == v) return vi.first;
} }
......
...@@ -92,13 +92,15 @@ struct Instruction { ...@@ -92,13 +92,15 @@ struct Instruction {
// ----------------------------------------------------------------------------- : Variables // ----------------------------------------------------------------------------- : Variables
typedef unsigned int Variable;
/// Return a unique name for a variable to allow for faster loopups /// Return a unique name for a variable to allow for faster loopups
unsigned int string_to_variable(const String& s); Variable string_to_variable(const String& s);
/// Get the name of a vaiable /// Get the name of a vaiable
/** Warning: this function is slow, it should only be used for error messages and such. /** Warning: this function is slow, it should only be used for error messages and such.
*/ */
String variable_to_string(unsigned int v); String variable_to_string(Variable v);
// ----------------------------------------------------------------------------- : Script // ----------------------------------------------------------------------------- : Script
......
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