Exemple #1
0
 /// <summary>
 /// Setup the Mods-GUI list on the main menu
 /// </summary>
 private void SetupGUI()
 {
     _ModListButtonArea = new GUI.Area(new UnityEngine.Rect(UnityEngine.Screen.width - 150, 0, 150, UnityEngine.Screen.height))
     {
         MaxWidth = 200, MaxHeight = 400
     };
     _ToggleModListBtn          = new GUI.Button("Mods");
     _ToggleModListBtn.Clicked += ToggleModListBtn_Clicked;
     _ModListButtonArea.Items.Add(_ToggleModListBtn);
 }
Exemple #2
0
        public override void OnCreateGUI()
        {
            _loadingBoxStyle = new GUIStyle(UnityEngine.GUI.skin.box)
            {
                alignment = TextAnchor.MiddleCenter,
                fontSize  = 16
            };

            GUI.Group btnGroup = new GUI.Group(GUI.GUIItem.Direction.Horizontal);

            GUI.Button exportBtn = new GUI.Button("Export");
            exportBtn.Clicked += ExportBtn_Clicked;
            btnGroup.Items.Add(exportBtn);

            GUI.Button importBtn = new GUI.Button("Import");
            importBtn.Clicked += ImportBtn_Clicked;
            btnGroup.Items.Add(importBtn);

            ModWindow.Items.Add(btnGroup);
        }
Exemple #3
0
        /// <summary>
        /// <para>Called from within the game's code. Notifying all enabled mods that it can draw custom gui elements</para>
        /// <para>Do not call this manually</para>
        /// </summary>
        public void __OnGui()
        {
            if (_FirstPass)
            {
                _FirstPass   = false;
                _debugWindow = new GUI.Window(ModGUI.GetWindowIndex(), "Mod Debug")
                {
                    Visible = false, IsDraggable = true, IsResizeable = true
                };
                _debugWindow.Rect = new UnityEngine.Rect((UnityEngine.Screen.width - 400) / 2, (UnityEngine.Screen.height - 400) / 2, 400, 400);
                _debugWindow.Items.Add(new GUI.TextArea()
                {
                    IsRichText = true, IsEditable = false
                });
                GUI.Button closeDebugBtn = new GUI.Button("Close");
                closeDebugBtn.Clicked += CloseDebugBtn_Clicked;
                _debugWindow.Items.Add(new GUI.FlexibleSpace());
                _debugWindow.Items.Add(closeDebugBtn);

                if (_errorBeforeLoad.Count > 0)
                {
                    ShowError(_errorBeforeLoad[0].ModName, _errorBeforeLoad[0].ModVersion, _errorBeforeLoad[0].Error, _errorBeforeLoad[0].Where);
                }
            }

            _debugWindow.__Draw();

            if (ManagerMenu.mainMenuActive)
            {
                if (!_ModAreaResized)
                {
                    _ModAreaResized = true;
                }

                _ModListButtonArea.__Draw();
            }
        }
Exemple #4
0
        /// <summary>
        /// Register every Mod in the Mods directory
        /// </summary>
        /// <param name="ModsFolder"></param>
        private void RegisterMods(String ModsFolder)
        {
            Type AbstractModType = typeof(Mod);

            System.IO.DirectoryInfo ModsFolderInfo = new System.IO.DirectoryInfo(ModsFolder);

            List <Mod> PreliminaryMods = new List <Mod>();

            foreach (System.IO.DirectoryInfo modDir in ModsFolderInfo.GetDirectories("*", System.IO.SearchOption.TopDirectoryOnly))
            {
                if (System.IO.File.Exists(System.IO.Path.Combine(modDir.FullName, "Mod.json")))
                {
                    try
                    {
                        String  modInfoJson = System.IO.File.ReadAllText(System.IO.Path.Combine(modDir.FullName, "Mod.json"));
                        ModInfo modInfo     = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize <ModInfo>(modInfoJson);
                        if (modInfo == null)
                        {
                            throw new Exception("Invalid Mod.json file");
                        }

                        try
                        {
                            String dllFile = System.IO.Path.Combine(modDir.FullName, modInfo.EntryDLL);
                            if (String.IsNullOrEmpty(modInfo.EntryDLL) || !System.IO.File.Exists(dllFile))
                            {
                                throw new System.IO.FileNotFoundException("Missing EntryDLL file");
                            }

                            System.Reflection.Assembly ModAssembly = System.Reflection.Assembly.LoadFile(dllFile);
                            bool ModTypeFound = false;
                            foreach (Type T in ModAssembly.GetTypes().Where(t => t.IsSubclassOf(AbstractModType) && t.IsPublic && !t.IsInterface && !t.IsAbstract))
                            {
                                Mod M = (Mod)Activator.CreateInstance(T);
                                if (M != null)
                                {
                                    M.Info      = modInfo;
                                    M.ModFolder = modDir.FullName;
                                    M._Logger   = new UnityEngine.Logger(new ModLoggerHandler(M));
                                    PreliminaryMods.Add(M);
                                    ModTypeFound = true;
                                }
                            }

                            if (!ModTypeFound)
                            {
                                UnityEngine.Debug.LogWarning("No mod found in file " + dllFile + " but it's designated as a mod");
                            }
                        }
                        catch (Exception innerEx)
                        {
                            ShowError(modInfo.Name, modInfo.Version.ToString(), innerEx, "Load");
                            UnityEngine.Debug.LogError("Failed to initialize mod from folder " + modInfo.Name + ": " + innerEx.Message);
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowError(modDir.Name, "", ex, "Load");
                        UnityEngine.Debug.LogError("Failed to initialize mod from folder " + modDir.Name + ": " + ex.Message);
                    }
                }
            }

            foreach (Mod M in PreliminaryMods)
            {
                foreach (ModDependency dep in M.Info.Dependencies)
                {
                    bool has = false;
                    foreach (Mod N in PreliminaryMods)
                    {
                        if (!N.Enabled)
                        {
                            continue;
                        }

                        if (dep.Name == N.Info.Name)
                        {
                            has = true;
                            if (dep.MinimumVersion != null && dep.MinimumVersion > N.Info.Version)
                            {
                                has = false;
                            }
                            else if (dep.MaximumVersion != null && dep.MaximumVersion < N.Info.Version)
                            {
                                has = false;
                            }
                        }
                    }

                    if (!has)
                    {
                        UnityEngine.Debug.LogWarning("Mod " + M.Info.Name + " is missing dependency " + dep.Name);
                        M.Enabled = false;
                        break;
                    }
                }

                if (M.Enabled)
                {
                    _Mods.Add(M);
                }
            }

            foreach (Mod M in _Mods)
            {
                M.ModWindow = new GUI.Window(ModGUI.GetWindowIndex(), M.Info.DisplayName)
                {
                    Visible      = false,
                    IsDraggable  = true,
                    IsResizeable = true,
                    _drawingMod  = M,
                    MinWidth     = 200,
                    MaxWidth     = UnityEngine.Screen.width,
                    MinHeight    = 20,
                    MaxHeight    = UnityEngine.Screen.height
                };

                GUI.Button modBtn = new GUI.Button(M.Info.DisplayName)
                {
                    Tag = M, Visible = false
                };
                modBtn.Clicked += ModBtn_Clicked;
                _ModListButtonArea.Items.Add(modBtn);

                M.OnInitialize();
            }
        }
        private void SetupGUI(GameObject mainMenuRight)
        {
            _SelectedScenario = null;

            _ScenarioWindow = new GUI.Window(ModGUI.GetWindowIndex(), "Scenarios")
            {
                IsDraggable  = true,
                IsResizeable = true,
                IsCloseable  = true,
                Rect         = new Rect((Screen.width / 2) - 200, (Screen.height / 2) - 200, 400, 400),
                Visible      = false,
                MinWidth     = 200,
                MinHeight    = 200
            };

            _ScenarioWindow.WindowClosed += _ScenarioWindow_WindowClosed;

            GUI.Group group = new GUI.Group(GUI.GUIItem.Direction.Vertical);
            _ScenarioWindow.Items.Add(group);

            GUI.Group group1 = new GUI.Group(GUI.GUIItem.Direction.Horizontal);
            group.Items.Add(group1);

            lstScenarios = new GUI.Group(GUI.GUIItem.Direction.Vertical);
            group1.Items.Add(lstScenarios);

            foreach (Scenario scenario in Scenarios)
            {
                GUI.Button btn = new GUI.Button(scenario.Name)
                {
                    Tag = scenario
                };
                btn.Clicked += ScenarioBtn_Clicked;
                lstScenarios.Items.Add(btn);
            }

            _ScenarioInfo = new GUI.Group(GUI.GUIItem.Direction.Vertical)
            {
                Visible = false
            };
            group1.Items.Add(_ScenarioInfo);

            _Name = new GUI.Label("");
            _ScenarioInfo.Items.Add(_Name);

            _Desc = new GUI.TextArea("")
            {
                IsEditable = false,
                IsRichText = true
            };
            _ScenarioInfo.Items.Add(_Desc);

            _ThumbNail = new GUI.Box("")
            {
                Visible   = false,
                MaxWidth  = 200,
                MaxHeight = 200
            };
            _ScenarioInfo.Items.Add(_ThumbNail);

            GUI.Group btnGroup = new GUI.Group(GUI.GUIItem.Direction.Horizontal);
            group.Items.Add(btnGroup);

            _CancelBtn          = new GUI.Button("Cancel");
            _CancelBtn.Clicked += CancelBtn_Clicked;
            btnGroup.Items.Add(_CancelBtn);

            btnGroup.Items.Add(new GUI.FlexibleSpace());

            _LoadBtn = new GUI.Button("Load")
            {
                IsEnabled = false
            };
            _LoadBtn.Clicked += LoadBtn_Clicked;
            btnGroup.Items.Add(_LoadBtn);
        }