Esempio n. 1
0
        // This invokes an action from control event
        private void InvokeTaggedAction(object sender, EventArgs e)
        {
            if (General.Editing.Mode is ScriptMode && sender is ToolStripItem)
            {
                string tag = (sender as ToolStripItem).Tag.ToString();
                if (tag.StartsWith("dbxlua_luaquickaccess;"))
                {
                    string path = tag.Substring("dbxlua_luaquickaccess;".Length);

                    ScriptMode mode = (ScriptMode)General.Editing.Mode;

                    mode.SetCurrentScript(path);
                }
            }
            General.Interface.InvokeTaggedAction(sender, e);
        }
Esempio n. 2
0
        public static Dictionary <string, string> AskForParametersNoClear()
        {
            // TODO add repeating with previous parameters
            // FIXME  check for duplicate keys

            if (ScriptContext.context.ui_parameters.keys == null
                ||
                ScriptContext.context.ui_parameters.keys.Count <= 0)
            {
                ScriptContext.context.Warn("AskForParameters called with no parameters set up.");
                return(null);
            }

            Dictionary <string, string> output = ScriptMode.RequestAndWaitForParams();

            if (output == null)
            {
                throw new ScriptRuntimeException("User cancelled script execution.");
            }
            return(output);
        }
Esempio n. 3
0
        public static Table AskForParametersNoClear()
        {
            // TODO add repeating with previous parameters
            // FIXME  check for duplicate keys

            if (ScriptContext.context.ui_parameters.keys == null
                ||
                ScriptContext.context.ui_parameters.keys.Count <= 0)
            {
                ScriptContext.context.Warn("AskForParameters called with no parameters set up.");
                return(null);
            }

            Dictionary <string, string> dict = ScriptMode.RequestAndWaitForParams();

            if (dict == null)
            {
                // FIXME do this without an error message probably?
                throw new ScriptRuntimeException("User cancelled script execution.");
            }

            Table output = new Table(ScriptContext.context.script);

            foreach (KeyValuePair <string, string> pair in dict)
            {
                output.Set(
                    pair.Key,
                    DynValue.FromObject(ScriptContext.context.script, pair.Value)
                    );
            }

            int count = ScriptContext.context.ui_parameters.datatypes.Count;

            if (ScriptContext.context.ui_parameters.keys.Count != count)
            {
                Logger.WriteLogLine("Inconsistent parameter counts in Lua script!");
                Logger.WriteLogLine("datatypes: ");
                foreach (DataType o in ScriptContext.context.ui_parameters.datatypes)
                {
                    Logger.WriteLogLine(o.ToString());
                }

                Logger.WriteLogLine("keys: ");
                foreach (string o in ScriptContext.context.ui_parameters.keys)
                {
                    if (o == null)
                    {
                        Logger.WriteLogLine("null");
                    }
                    else
                    {
                        Logger.WriteLogLine(o);
                    }
                }

                Logger.WriteLogLine("labels: ");
                foreach (string o in ScriptContext.context.ui_parameters.labels)
                {
                    if (o == null)
                    {
                        Logger.WriteLogLine("null");
                    }
                    else
                    {
                        Logger.WriteLogLine(o);
                    }
                }

                Logger.WriteLogLine("labels: ");
                foreach (string o in ScriptContext.context.ui_parameters.defaultvalues)
                {
                    if (o == null)
                    {
                        Logger.WriteLogLine("null");
                    }
                    else
                    {
                        Logger.WriteLogLine(o);
                    }
                }
                throw new ScriptRuntimeException("Inconsistent parameter counts in Lua script, might be a DBXLua bug. :(");
            }

            for (int i = 0; i < count; i++)
            {
                DataType cur_type  = ScriptContext.context.ui_parameters.datatypes[i];
                DynValue cur_value = output.Get(ScriptContext.context.ui_parameters.keys[i]);
                switch (cur_type)
                {
                case DataType.Boolean:
                    cur_value.Assign(DynValue.NewBoolean(cur_value.CastToBool()));
                    //output.Set(ScriptContext.context.ui_parameters.keys[i], cur_value.CastToBool());
                    break;

                case DataType.Number:
                    double d = cur_value.CastToNumber() ?? 0;
                    cur_value.Assign(DynValue.NewNumber(d));
                    break;

                default:
                    break;     // nope
                }
            }

            return(output);
        }