Exemplo n.º 1
0
 private void LoadFile_Click(object sender, EventArgs e)
 {
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             var sr = new StreamReader(openFileDialog.FileName);
             OpenFile = sr.ReadToEnd();
             obj      = JsonConvert.DeserializeObject <ModelJson>(OpenFile);
             UpdateControls();
             sr.Close();
         }
         catch (SecurityException ex)
         {
             MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
                             $"Details:\n\n{ex.StackTrace}");
         }
     }
 }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            obj = new ModelJson
            {
                slots    = new Dictionary <int, Modelslots>(),
                handlers = new List <Modelhandlers>(),
                methods  = new List <string>(),
                events   = new List <string>()
            };
            obj.slots.Add(0, new Modelslots {
                name = "slot1", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(1, new Modelslots {
                name = "slot2", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(2, new Modelslots {
                name = "slot3", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(3, new Modelslots {
                name = "slot4", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(4, new Modelslots {
                name = "slot5", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(5, new Modelslots {
                name = "slot6", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(6, new Modelslots {
                name = "slot7", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(7, new Modelslots {
                name = "slot8", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(8, new Modelslots {
                name = "slot9", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(9, new Modelslots {
                name = "slot10", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(-1, new Modelslots {
                name = "unit", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(-2, new Modelslots {
                name = "system", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });
            obj.slots.Add(-3, new Modelslots {
                name = "library", type = new Modeltype {
                    events = new List <string>(), methods = new List <string>()
                }
            });


            //--Code to edit/insert items
            //Modelslots thisSlot;
            //obj.slots.TryGetValue(0, out thisSlot);
            //thisSlot.name = "EditedName";

            // This does work and added a filter at startup but is not needed
            //obj.handlers.Add(new Modelhandlers { code = @"screen.setRawHTML(""HI"")", filter = new Modelfilter { args = new List<Modelargs>(), signature = "start()", slotKey = -2 }, key = "1" });

            //obj.handlers.Add(new Modelhandlers { code = "Code here (system.update)", filter = new Modelfilter { args = new List<Modelargs>(), signature = "update()", slotKey = -2 }, key = "2" });
            //--



            PrivateFontCollection pfc = new PrivateFontCollection();

            pfc.AddFontFile(Application.StartupPath + "\\BankGothic-Regular.ttf");
            SlotsLable.Font = new Font(pfc.Families[0], 16, FontStyle.Regular);

            // LuaTable lt = (LuaTable)lua.DoString("return {1 = 'example1', 2 = 234, 'foo' = 'Foo Example'}")[0];
            // LuaTable lt4 =  lua.NewTable("");
            //lt["1"] = "example1";
            // lt["2"] = 234;
            //lt["foo"] = "Foo Example";

            var test = new Dictionary <string, int> {
                { "A", 1 },
                { "B", 2 }
            };

            //table["C"] = lua.CreateTable(); ((LuaTable)table["C"])["A"] = 3;

            //foreach (var entry in test)
            //{
            //  (LuaTable)lua]["test"])[entry.Key] = entry.Value;
            //}
            //lua.DoString("yourTable = YourExportedFunction('arg1')", "internal");

            lua.DoString("screen = { setHTML = nil }");
            lua.RegisterFunction("screen.setHTML", this, this.GetType().GetMethod("setScreenHTML"));

            // lua.RegisterFunction("system", this, this.GetType().GetMethod("setRawHTML"));
            //lua.RegisterFunction("setHTML", this, this.GetType().GetMethod("setRawHTML"));
            //---------------------------------------

            lua.RegisterFunction("DanSays", this, this.GetType().GetMethod("DanSays"));
            lua.RegisterFunction("ThorSays", this, this.GetType().GetMethod("ThorSays"));
            UpdateControls();
        }