示例#1
0
        public ScriptContext(IRenderer2D renderer, Vector2D inmappos, bool insnaptogrid, bool insnaptonearest)
        {
            errorText = "";
            context   = this;


            snaptogrid    = insnaptogrid;
            snaptonearest = insnaptonearest;
            mousemappos   = inmappos;
            ui_parameters = new LuaUIParameters(16);
            if (float.IsNaN(mousemappos.x) || float.IsInfinity(mousemappos.x))
            {
                mousemappos.x = 0f;
            }
            if (float.IsNaN(mousemappos.y) || float.IsInfinity(mousemappos.y))
            {
                mousemappos.y = 0f;
            }
            rendererscale = renderer.Scale;
            scriptlog_sb  = new StringBuilder();
            debuglog_sb   = new StringBuilder();

            UserData.RegisterAssembly();
            script = new Script(CoreModules.Preset_SoftSandbox);

            script.Options.DebugPrint = s => { LuaUI.DebugLogLine(s); };

            script.Globals["Line2D"]    = typeof(LuaLine2D);
            script.Globals["Vector2D"]  = typeof(LuaVector2D);
            script.Globals["Vector3D"]  = typeof(LuaVector3D);
            script.Globals["Map"]       = typeof(LuaMap);
            script.Globals["Pen"]       = typeof(Pen);
            script.Globals["UI"]        = typeof(LuaUI);
            script.Globals["Data"]      = typeof(LuaDataManager);
            script.Globals["MapFormat"] = typeof(LuaMapFormat);
            script.Globals["dofile"]    = (Func <string, DynValue>)DoFile;
            script.Globals["dostring"]  = (Func <string, DynValue>)DoString;
            script.Globals["require"]   = (Func <string, DynValue>)Require;

            script.Options.DebugPrint = DebugLogLine;

            bInitializedRequireSandbox = false;

            // hacky workaround for .NET 3.5 bug, see RandomSeed for more info
            {
                object math = script.Globals["math"];
                if (math is Table)
                {
                    Table math_table = (Table)math;
                    math_table["randomseed"] = (Func <DynValue, DynValue>)RandomSeed;
                }
            }
        }
示例#2
0
        public static Dictionary <string, string> ShowParamsDialog(LuaUIParameters ui_parameters)
        {
            // ano - safer to assume data coming from a script is suspect
            if (ui_parameters.keys == null || ui_parameters.labels == null)
            {
                throw new ScriptRuntimeException("Keys/labels were nil for taking script parameters");
            }
            if (ui_parameters.keys.Count != ui_parameters.labels.Count)
            {
                throw new ScriptRuntimeException("# keys must be equal to # labels for parameters dialog");
            }

            // ano - really suspect
            if (ui_parameters.keys.Count > 384)
            {
                throw new ScriptRuntimeException("# keys for script parameters can't be greater than 384");
            }

            if (ui_parameters.defaultvalues == null)
            {
                ui_parameters.defaultvalues = new List <string>();
            }

            while (ui_parameters.defaultvalues.Count < ui_parameters.keys.Count)
            {
                ui_parameters.defaultvalues.Add("");
            }

            ScriptParamForm form = new ScriptParamForm();

            for (int i = 0; i < ui_parameters.labels.Count; i++)
            {
                form.paramsview.Rows.Add(ui_parameters.labels[i], ui_parameters.defaultvalues[i]);
            }
            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                Dictionary <string, string> output = new Dictionary <string, string>(ui_parameters.labels.Count);
                for (int i = 0; i < ui_parameters.labels.Count; i++)
                {
                    output.Add(ui_parameters.keys[i], form.paramsview.Rows[i].Cells[1].Value.ToString());
                }
                return(output);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public ScriptContext(IRenderer2D renderer, Vector2D inmappos, bool insnaptogrid, bool insnaptonearest)
        {
            errorText = "";
            context   = this;


            snaptogrid    = insnaptogrid;
            snaptonearest = insnaptonearest;
            mousemappos   = inmappos;
            ui_parameters = new LuaUIParameters(16);
            if (float.IsNaN(mousemappos.x) || float.IsInfinity(mousemappos.x))
            {
                mousemappos.x = 0f;
            }
            if (float.IsNaN(mousemappos.y) || float.IsInfinity(mousemappos.y))
            {
                mousemappos.y = 0f;
            }
            rendererscale = renderer.Scale;
            scriptlog_sb  = new StringBuilder();
            debuglog_sb   = new StringBuilder();

            UserData.RegisterAssembly();
            script = new Script(CoreModules.Preset_SoftSandbox);

            script.Options.DebugPrint = s => { LuaUI.DebugLogLine(s); };

            script.Globals["Line2D"]    = typeof(LuaLine2D);
            script.Globals["Vector2D"]  = typeof(LuaVector2D);
            script.Globals["Vector3D"]  = typeof(LuaVector3D);
            script.Globals["Map"]       = typeof(LuaMap);
            script.Globals["Pen"]       = typeof(Pen);
            script.Globals["UI"]        = typeof(LuaUI);
            script.Globals["Data"]      = typeof(LuaDataManager);
            script.Globals["MapFormat"] = typeof(LuaMapFormat);
            script.Globals["dofile"]    = (Func <string, DynValue>)DoFile;
        }
示例#4
0
        public static Dictionary <string, string> ShowParamsDialog(LuaUIParameters ui_parameters)
        {
            // ano - safer to assume data coming from a script is suspect
            if (ui_parameters.keys == null || ui_parameters.labels == null)
            {
                ScriptContext.context.Warn("Keys/labels were nil for taking script parameters. Possibly Lua API bug?");
                return(null);
            }
            if (ui_parameters.keys.Count != ui_parameters.labels.Count)
            {
                ScriptContext.context.Warn("# keys must be equal to # labels for parameters dialog. Possibly Lua API bug?");
                return(null);
            }

            // ano - really suspect
            if (ui_parameters.keys.Count > 384)
            {
                ScriptContext.context.Warn("# keys for script parameters can't be greater than 384");
                return(null);
            }

            if (ui_parameters.defaultvalues == null)
            {
                ui_parameters.defaultvalues = new List <string>();
            }

            while (ui_parameters.defaultvalues.Count < ui_parameters.keys.Count)
            {
                ui_parameters.defaultvalues.Add(null);
            }

            ScriptParamForm form = new ScriptParamForm();

            for (int i = 0; i < ui_parameters.labels.Count; i++)
            {
                if (ui_parameters.defaultvalues[i] == null)
                {
                    form.paramsview.Rows.Add(ui_parameters.labels[i], "");
                }
                else
                {
                    form.paramsview.Rows.Add(ui_parameters.labels[i], ui_parameters.defaultvalues[i]);
                }

                if (ui_parameters.tooltips[i] != null && ui_parameters.tooltips[i].Length > 0)
                {
                    form.paramsview.Rows[i].Cells[0].ToolTipText = ui_parameters.tooltips[i];
                    form.paramsview.Rows[i].Cells[1].ToolTipText = ui_parameters.tooltips[i];
                }
            }

            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                Dictionary <string, string> output = new Dictionary <string, string>(ui_parameters.labels.Count);

                for (int i = 0; i < ui_parameters.labels.Count; i++)
                {
                    output.Add(ui_parameters.keys[i], form.paramsview.Rows[i].Cells[1].Value.ToString());
                }

                return(output);
            }
            else
            {
                return(null);
            }
        }