mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
choice fields show only the highest level of choices in statistics panel
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@361 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -12,10 +12,12 @@
|
||||
#include <data/set.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/field/text.hpp>
|
||||
#include <data/field/choice.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(FieldP);
|
||||
DECLARE_TYPEOF_COLLECTION(TextValue*);
|
||||
DECLARE_TYPEOF_COLLECTION(String);
|
||||
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Combined editor
|
||||
|
||||
@@ -131,9 +133,31 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) {
|
||||
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
|
||||
|
||||
void init_script_editor_functions(Context& ctx) {
|
||||
ctx.setVariable(_("forward editor"), script_combined_editor); // combatability
|
||||
ctx.setVariable(_("combined editor"), script_combined_editor);
|
||||
ctx.setVariable(_("primary choice"), script_primary_choice);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <util/io/package_manager.hpp> // for "include file" semi hack
|
||||
#include <stack>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(int);
|
||||
DECLARE_TYPEOF_COLLECTION(Variable);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#define TokenType TokenType_ // some stupid windows header uses our name
|
||||
@@ -546,7 +546,7 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
|
||||
expectToken(input, _("]"));
|
||||
} else if (minPrec <= PREC_FUN && token==_("(")) {
|
||||
// function call, read arguments
|
||||
vector<int> arguments;
|
||||
vector<Variable> arguments;
|
||||
Token t = input.peek();
|
||||
while (t != _(")") && t != TOK_EOF) {
|
||||
if (input.peek(2) == _(":")) {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Variables
|
||||
|
||||
typedef map<String, unsigned int> Variables;
|
||||
typedef map<String, Variable> Variables;
|
||||
Variables variables;
|
||||
DECLARE_TYPEOF(Variables);
|
||||
#ifdef _DEBUG
|
||||
@@ -21,13 +21,13 @@ DECLARE_TYPEOF(Variables);
|
||||
#endif
|
||||
|
||||
/// 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);
|
||||
if (it == variables.end()) {
|
||||
#ifdef _DEBUG
|
||||
variable_names.push_back(s);
|
||||
#endif
|
||||
unsigned int v = (unsigned int)variables.size();
|
||||
Variable v = (Variable)variables.size();
|
||||
variables.insert(make_pair(s,v));
|
||||
return v;
|
||||
} else {
|
||||
@@ -38,7 +38,7 @@ unsigned int string_to_variable(const String& s) {
|
||||
/// Get the name of a vaiable
|
||||
/** 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) {
|
||||
if (vi.second == v) return vi.first;
|
||||
}
|
||||
|
||||
@@ -92,13 +92,15 @@ struct Instruction {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Variables
|
||||
|
||||
typedef unsigned int Variable;
|
||||
|
||||
/// 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
|
||||
/** 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user