コード例 #1
0
ファイル: MafiaPanel.cs プロジェクト: Avatarchik/MafiaUnity
        private void OnGUI()
        {
            if (!GameManager.instance.GetInitialized())
            {
                isInitialized = false;
                GUILayout.Label("Game manager is not initialized yet.");
                return;
            }

            if (!isInitialized)
            {
                modManager    = GameManager.instance.modManager;
                isInitialized = true;

                var modNames = new List <string>(modManager.GetAllModNames());
                var mods     = new List <ModEntry>();
                modEntries = new List <ModEntry>();

                foreach (var modName in modNames)
                {
                    var modEntry = new ModEntry();
                    modEntry.modMeta  = modManager.ReadModInfo(modName);
                    modEntry.modName  = modName;
                    modEntry.isActive = 0;
                    mods.Add(modEntry);
                }

                var newMods = new List <ModEntry>(mods);

                var loadOrder = modManager.GetLoadOrder();

                foreach (var load in loadOrder)
                {
                    foreach (var mod in mods)
                    {
                        if (mod.modName == load.Key)
                        {
                            if (load.Value == "1")
                            {
                                mod.isActive = 1;
                            }

                            modEntries.Add(mod);
                            newMods.Remove(mod);
                        }
                    }
                }

                foreach (var newMod in newMods)
                {
                    modEntries.Add(newMod);
                }

                ApplyChanges();
            }

            if (modEntries == null)
            {
                return;
            }

            for (var i = 0; i < modEntries.Count; i++)
            {
                var modEntry = modEntries[i];

                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Select", GUILayout.Width(60)))
                    {
                        selectedModIndex = i;
                    }

                    if (GUILayout.Button("+", GUILayout.Width(20)))
                    {
                        if (i + 1 < modEntries.Count)
                        {
                            var oldMod = modEntries[i + 1];
                            modEntries[i]     = oldMod;
                            modEntries[i + 1] = modEntry;
                        }
                    }

                    if (GUILayout.Button("-", GUILayout.Width(20)))
                    {
                        if (i > 0)
                        {
                            var oldMod = modEntries[i - 1];
                            modEntries[i]     = oldMod;
                            modEntries[i - 1] = modEntry;
                        }
                    }

                    modEntry.isActive = GUILayout.Toggle(modEntry.isActive != 0, "Active") ? 1 : 0;

                    EditorGUILayout.LabelField(modEntry.modName);
                }
                GUILayout.EndHorizontal();
            }

            if (modEntries.Count > 0 && selectedModIndex >= 0 && selectedModIndex < modEntries.Count)
            {
                var mod = modEntries[selectedModIndex].modMeta;

                if (mod == null)
                {
                    GUILayout.Label("Error loading mod metadata!");
                }
                else
                {
                    GUILayout.Label("Name: " + mod.name);
                    GUILayout.Label("Author: " + mod.author);
                    GUILayout.Label("Version: " + mod.version);
                    GUILayout.Label("Game Version: " + mod.gameVersion);
                    GUILayout.Label("Depends on:");

                    foreach (var dep in mod.dependencies)
                    {
                        GUILayout.Label("  - " + dep);
                    }
                }
            }


            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Apply Changes"))
                {
                    ApplyChanges();
                }

                if (GUILayout.Button("Initialize Mods"))
                {
                    ApplyChanges();

                    foreach (var mod in modEntries)
                    {
                        if (mod.isActive != 0)
                        {
                            modManager.LoadMod(mod.modName);
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
        }