Ejemplo n.º 1
0
        public void Start()
        {
            DontDestroyOnLoad(this);

            button = new SettingsButton()
            {
                Text     = "Keys",
                Value    = false,
                OnToggle = OnInterfaceToggle
            };
            button.Create();

            windowRect.x      = Configuration.GetFloat("main-x", 1100f);
            windowRect.y      = Configuration.GetFloat("main-y", 309);
            windowRect.width  = 400;
            windowRect.height = 500;
            editInterface.LoadWindowPosition();

            toggleKey = Keybindings.AddKeybinding("Key Manager",
                                                  new Key(KeyCode.RightControl, KeyCode.M));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Instantiates the mod and it's components.
        ///     Looks for and loads assemblies.
        /// </summary>
        public override void OnLoad()
        {
            Game.OnSimulationToggle += Block.OnSimulationToggle;
            Game.OnSimulationToggle += Script.OnSimulationToggle;
            Game.OnBlockPlaced      += block => Block.FlagForIDRebuild();
            Game.OnBlockRemoved     += Block.FlagForIDRebuild;
            Block.OnInitialisation  += Script.Start;

            XmlSaver.OnSave  += MachineData.Save;
            XmlLoader.OnLoad += MachineData.Load;

            Commands.RegisterCommand("lsm", ConfigurationCommand,
                                     "Scripter Mod configuration command.");
            Commands.RegisterCommand("py", PythonCommand,
                                     "Executes Python expression.");
            Commands.RegisterCommand("python", PythonCommand,
                                     "Executes Python expression.");

            Controller = new GameObject("LenchScripterMod")
            {
                hideFlags = HideFlags.DontSave
            };
            Controller.AddComponent <ModController>();

            IdentifierDisplayWindow = new IdentifierDisplayWindow();
            ScriptOptionsWindow     = new ScriptOptionsWindow();
            WatchlistWindow         = new WatchlistWindow();
            Toolbar = new Toolbar
            {
                Texture = Images.IconPython,
                Visible = Script.Enabled,
                Buttons =
                {
                    new Toolbar.Button
                    {
                        Style = new GUIStyle
                        {
                            normal      = { background = Images.ButtonKeyNormal      },
                            focused     = { background = Images.ButtonKeyFocus       },
                            hover       = { background = Images.ButtonKeyHover       },
                            active      = { background = Images.ButtonKeyActive      },
                            fixedWidth  = 32,
                            fixedHeight = 32
                        },
                        Text    = "",
                        OnClick = OpenIdentifier
                    },
                    new Toolbar.Button
                    {
                        Style = new GUIStyle
                        {
                            normal      = { background = Images.ButtonListNormal     },
                            focused     = { background = Images.ButtonListFocus      },
                            hover       = { background = Images.ButtonListHover      },
                            active      = { background = Images.ButtonListActive     },
                            fixedWidth  = 32,
                            fixedHeight = 32
                        },
                        Text    = "",
                        OnClick = OpenWatchlist
                    },
                    new Toolbar.Button
                    {
                        Style = new GUIStyle
                        {
                            normal      = { background = Images.ButtonScriptNormal   },
                            focused     = { background = Images.ButtonScriptFocus    },
                            hover       = { background = Images.ButtonScriptHover    },
                            active      = { background = Images.ButtonScriptActive   },
                            fixedWidth  = 32,
                            fixedHeight = 32
                        },
                        Text    = "",
                        OnClick = OpenScript
                    },
                    new Toolbar.Button
                    {
                        Style = new GUIStyle()
                        {
                            normal      = { background = Images.ButtonSettingsNormal },
                            focused     = { background = Images.ButtonSettingsFocus  },
                            hover       = { background = Images.ButtonSettingsHover  },
                            active      = { background = Images.ButtonSettingsActive },
                            fixedWidth  = 32,
                            fixedHeight = 32
                        },
                        Text    = "",
                        OnClick = OpenSettings
                    }
                }
            };

            Object.DontDestroyOnLoad(DependencyInstaller.Instance);

            LoadedAPI = true;

            Configuration.Load();

            EnableScriptButton = new SettingsButton
            {
                Text     = "SCRIPT",
                Value    = Script.Enabled,
                OnToggle = enabled =>
                {
                    Script.Enabled  = enabled;
                    Toolbar.Visible = enabled;
                }
            };
            EnableScriptButton.Create();

            PythonVersion2Button = new OptionsButton
            {
                Text     = "Python 2.7",
                Value    = PythonEnvironment.Version == "ironpython2.7",
                OnToggle = enabled =>
                {
                    if (enabled)
                    {
                        if (PythonEnvironment.Version != "ironpython3.0")
                        {
                            return;
                        }
                        PythonVersion3Button.Value = false;
                        Script.SetVersionAndReload("ironpython2.7");
                    }
                    else
                    {
                        PythonVersion2Button.Value = true;
                    }
                }
            };
            PythonVersion2Button.Create();

            PythonVersion3Button = new OptionsButton
            {
                Text     = "Python 3.0",
                Value    = PythonEnvironment.Version == "ironpython3.0",
                OnToggle = enabled =>
                {
                    if (enabled)
                    {
                        if (PythonEnvironment.Version != "ironpython2.7")
                        {
                            return;
                        }
                        PythonVersion2Button.Value = false;
                        Script.SetVersionAndReload("ironpython3.0");
                    }
                    else
                    {
                        PythonVersion3Button.Value = true;
                    }
                }
            };
            PythonVersion3Button.Create();

            if (UpdateCheckerEnabled)
            {
                CheckForModUpdate();
            }
        }