예제 #1
0
        /// <summary>
        /// MonoBehavior Update
        /// </summary>
        public void Update()
        {
            if (!init)
            {
                rw = UnityEngine.Object.FindObjectOfType <RainWorld>();
                if (rw == null)
                {
                    return;
                }
                pm = rw.processManager;
                if (pm.upcomingProcess == ProcessManager.ProcessID.MainMenu)
                {
                    try
                    {
                        Initialize();
                    }
                    catch (Exception ex) { Debug.LogError(ex); }
                    init = true;
                }
                ConfigMenu.currentTab = null;
                return;
            }
            if (pm == null)
            {
                rw = UnityEngine.Object.FindObjectOfType <RainWorld>();
                if (rw == null)
                {
                    return;
                }
                pm = rw.processManager;
                return;
            }

            if (pm.currentMainLoop?.ID != ProcessManager.ProcessID.OptionsMenu)
            {
                goto BackgroundUpdate;
            }
            else if (!OptionsMenuPatch.mod)
            {
                return;
            }

            //Option is running
            ConfigMenu.script = this;

            if (ConfigMenu.currentTab != null)
            {
                ConfigMenu.description = "";
                ConfigMenu.menuTab.Update(Time.deltaTime);
                if (soundFill > 0)
                {
                    soundFill--;
                }
                try
                {
                    if (!ConfigMenu.freezeMenu)
                    {
                        ConfigMenu.currentTab.Update(Time.deltaTime);
                    }
                    else
                    {
                        bool h = false;
                        foreach (UIelement element in ConfigMenu.currentTab.items)
                        {
                            if (element.GetType().IsSubclassOf(typeof(UIconfig)))
                            {
                                if ((element as UIconfig).held)
                                {
                                    h = true; element.Update(Time.deltaTime); continue;
                                }
                            }
                        }
                        if (!h)
                        {
                            foreach (UIelement element in ConfigMenu.currentTab.items)
                            {
                                element.Update(Time.deltaTime);
                            }
                        }
                    }
                    ConfigMenu.currentInterface.Update(Time.deltaTime);
                }
                catch (Exception ex)
                { //Update Error Handle!
                    PartialityMod    mod    = ConfigMenu.currentInterface.mod;
                    List <Exception> unload = new List <Exception>();
                    ConfigMenu       menu   = (pm.currentMainLoop as ConfigMenu);
                    foreach (OpTab tab in ConfigMenu.currentInterface.Tabs)
                    {
                        try
                        {
                            tab.Hide();
                            tab.Unload();
                        }
                        catch (Exception ex0) { unload.Add(ex0); }
                    }
                    string fullLog = string.Concat(
                        mod.ModID, " had error in Update(Time.deltaTime)!", Environment.NewLine,
                        ex.ToString());
                    foreach (Exception ex0 in unload)
                    {
                        fullLog += Environment.NewLine + "TabUnloadError: " + ex0.ToString();
                    }

                    UnconfiguableOI newItf = new UnconfiguableOI(mod, new GenericUpdateException(fullLog));
                    loadedInterfaceDict.Remove(mod.ModID);
                    loadedInterfaceDict.Add(mod.ModID, newItf);

                    int index = 0;
                    foreach (KeyValuePair <int, string> item in menu.modList)
                    {
                        if (item.Value == mod.ModID)
                        {
                            index = item.Key; break;
                        }
                    }
                    int i = 0;
                    do
                    {
                        string key = string.Concat(index.ToString("D3") + "_" + i.ToString("D2"));
                        if (tabs.ContainsKey(key))
                        {
                            tabs.Remove(key);
                        }
                        else
                        {
                            break;
                        }
                        i++;
                    } while (i < 100);


                    newItf.Initialize();
                    ConfigMenu.selectedTabIndex = 0;
                    tabs.Add(string.Concat(index.ToString("D3") + "_00"), newItf.Tabs[0]);

                    foreach (UIelement element in newItf.Tabs[0].items)
                    {
                        foreach (MenuObject obj in element.subObjects)
                        {
                            menu.pages[0].subObjects.Add(obj);
                        }
                        menu.pages[0].Container.AddChild(element.myContainer);
                    }
                    newItf.Tabs[0].Show();

                    ConfigMenu.currentInterface = newItf;
                    ConfigMenu.currentTab       = newItf.Tabs[0];

                    (pm.currentMainLoop as ConfigMenu).PlaySound(SoundID.MENU_Error_Ping);
                    (pm.currentMainLoop as ConfigMenu).opened = false;
                    (pm.currentMainLoop as ConfigMenu).OpenMenu();
                }
            }

            return;

BackgroundUpdate:
            //Background running
            if (pm.currentMainLoop?.ID == ProcessManager.ProcessID.IntroRoll)
            {
                return;
            }

            /*
             * foreach (OptionInterface oi in loadedInterfaces)
             * {
             *
             * }
             */
        }
예제 #2
0
        public void Initialize() //UI
        {
            if (vanillaMenu != null)
            {
                vanillaMenu.ShutDownProcess();
                vanillaMenu = null;
            }



            if (!redUnlocked)
            {
                this.scene = new InteractiveMenuScene(this, this.pages[0], (MenuScene.SceneID)(bgList[Mathf.FloorToInt(UnityEngine.Random.value * (bgList.Length))]));
            }
            else
            {
                this.scene = new InteractiveMenuScene(this, this.pages[0], (MenuScene.SceneID)(bgListRed[Mathf.FloorToInt(UnityEngine.Random.value * (bgListRed.Length))]));
            }
            Debug.Log(string.Concat("Chosen Background : " + this.scene.sceneID.ToString()));
            this.pages[0].subObjects.Add(this.scene);

            this.fadeSprite.RemoveFromContainer();
            this.pages[0].Container.AddChild(this.fadeSprite); //reset fadeSprite



            this.darkSprite = new FSprite("pixel", true)
            {
                color   = new Color(0f, 0f, 0f),
                anchorX = 0f,
                anchorY = 0f,
                scaleX  = 1368f,
                scaleY  = 770f,
                x       = -1f,
                y       = -1f,
                alpha   = 0.6f
            };
            this.pages[0].Container.AddChild(this.darkSprite);


            modListBound = new OpRect(new Vector2(205f, 225f) - UIelement._offset, new Vector2(280f, 510f), 0.3f);
            //modCanvasBound = new OpRect(new Vector2(553f, 105f), new Vector2(630f, 630f), 0.4f);
            modCanvasBound = new OpRect(new Vector2(533f, 105f) - UIelement._offset, new Vector2(630f, 630f), 0.4f);
            //Base: new Vector2(468f, 120f);
            menuTab.AddItems(modListBound, modCanvasBound);
            this.pages[0].subObjects.Add(modListBound.rect);
            this.pages[0].subObjects.Add(modCanvasBound.rect);



            this.backButton = new SimpleButton(this, this.pages[0], "BACK", "CANCEL", new Vector2(450f, 50f), new Vector2(110f, 30f));
            this.pages[0].subObjects.Add(this.backButton);
            this.saveButton = new SimpleButton(this, this.pages[0], "APPLY", "APPLY", new Vector2(600f, 50f), new Vector2(110f, 30f));
            this.pages[0].subObjects.Add(this.saveButton);
            base.MutualHorizontalButtonBind(saveButton, backButton);
            this.resetButton = new HoldButton(this, this.pages[0], "RESET CONFIG", "RESET CONFIG", new Vector2(300f, 90f), 30f);
            this.pages[0].subObjects.Add(this.resetButton);

            //Dark Box for ModList & Canvas
            //modlist x200 y400 w240 h600
            //canvas  x568 y120 w600 h600

            this.resetButton.nextSelectable[2] = this.backButton;
            this.backButton.nextSelectable[0]  = this.resetButton;
            this.backButton.nextSelectable[2]  = this.saveButton;
            this.saveButton.nextSelectable[0]  = this.backButton;



            modButtons = new SelectOneButton[OptionScript.loadedModsDictionary.Count]; //<==MenuLabel
            int i = 0; selectedModIndex = 0;
            Dictionary <int, string> dictionary  = new Dictionary <int, string>(modButtons.Length);
            Dictionary <int, bool>   dictionary0 = new Dictionary <int, bool>(modButtons.Length);

            foreach (string id in OptionScript.loadedModsDictionary.Keys)
            {
                modButtons[i] = new SelectOneButton(this, this.pages[0], id, "ModSelect", new Vector2(220f, 700f - 30f * i), new Vector2(250f, 24f), modButtons, i);

                this.pages[0].subObjects.Add(modButtons[i]);

                dictionary.Add(i, id);
                Debug.Log(string.Concat("Mod(" + i + ") : " + id));
                OptionInterface itf = OptionScript.loadedInterfaceDict[id];
                try
                {
                    itf.Initialize();
                }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(itf.mod, new Exception(string.Concat("OIinitializeError: ", id, " had a problem in Initialize().",
                                                                                   Environment.NewLine, ex
                                                                                   )));
                    OptionScript.loadedInterfaceDict.Remove(id);
                    OptionScript.loadedInterfaceDict.Add(id, itf);
                    itf.Initialize();
                }


                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.mod, new Exception(string.Concat("TabIsNull: ", id, " OI has No OpTabs! ",
                                                                                   Environment.NewLine, "Did you put base.Initialize() after your code?",
                                                                                   Environment.NewLine, "Leaving OI.Initialize() completely blank will prevent the mod from using LoadData/SaveData."
                                                                                   )));
                    OptionScript.loadedInterfaceDict.Remove(id);
                    OptionScript.loadedInterfaceDict.Add(id, itf);
                    itf.Initialize();
                }
                else if (itf.Tabs.Length > 20)
                {
                    itf = new UnconfiguableOI(itf.mod, new Exception("Too Many Tabs! D: Maximum tab number is 20.\nAlso what are you going to do with all those settings?"));
                    OptionScript.loadedInterfaceDict.Remove(id);
                    OptionScript.loadedInterfaceDict.Add(id, itf);
                    itf.Initialize();
                }

                try
                {
                    itf.LoadConfig();
                    itf.ShowConfig();
                }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(itf.mod, new Exception(string.Concat("OILoad/ShowConfigError: ", id, " had a problem in Load/ShowConfig()\nAre you editing LoadConfig()/ShowConfig()? That could cause serious error.",
                                                                                   Environment.NewLine, ex
                                                                                   )));
                    OptionScript.loadedInterfaceDict.Remove(id);
                    OptionScript.loadedInterfaceDict.Add(id, itf);
                    itf.Initialize();

                    itf.LoadConfig();
                    itf.ShowConfig();
                }

                dictionary0.Add(i, itf.Configuable());


                for (int t = 0; t < itf.Tabs.Length; t++)
                {
                    OptionScript.tabs.Add(string.Concat(i.ToString("D3") + "_" + t.ToString("D2")), itf.Tabs[t]);
                    foreach (UIelement element in itf.Tabs[t].items)
                    {
                        foreach (MenuObject obj in element.subObjects)
                        {
                            this.pages[0].subObjects.Add(obj);
                        }
                        this.pages[0].Container.AddChild(element.myContainer);
                    }
                    itf.Tabs[t].Hide();
                }

                i++;
            }
            modList           = dictionary;
            modConfiguability = dictionary0;


            this.resetButton.nextSelectable[1] = this.modButtons[this.modButtons.Length - 1];
            this.backButton.nextSelectable[1]  = this.modButtons[this.modButtons.Length - 1];
            this.saveButton.nextSelectable[1]  = this.modButtons[this.modButtons.Length - 1];
            this.modButtons[this.modButtons.Length - 1].nextSelectable[3] = this.saveButton;
            if (this.modButtons.Length > 1)
            {
                for (int m = 0; m < this.modButtons.Length - 1; m++)
                {
                    this.modButtons[m].nextSelectable[3]     = this.modButtons[m + 1];
                    this.modButtons[m + 1].nextSelectable[1] = this.modButtons[m];
                }
            }



            //Load Tab
            selectedTabIndex = 0;
            currentInterface = OptionScript.loadedInterfaceDict[modList[0]];
            currentTab       = OptionScript.tabs[string.Concat(selectedModIndex.ToString("D3") + "_" + selectedTabIndex.ToString("D2"))];

            currentTab.Show();
            if (currentInterface.Configuable())
            {
                saveButton.buttonBehav.greyedOut  = false;
                resetButton.buttonBehav.greyedOut = false;
            }
            else
            {
                saveButton.buttonBehav.greyedOut  = true;
                resetButton.buttonBehav.greyedOut = true;
            }


            tabCtrler = new ConfigTabController(new Vector2(493f, 120f) - UIelement._offset, new Vector2(40f, 600f), menuTab, this);
            menuTab.AddItems(tabCtrler);
            foreach (MenuObject obj in tabCtrler.subObjects)
            {
                this.pages[0].subObjects.Add(obj);
            }

            this.selectedObject = this.backButton;


            OptionScript.configChanged = false;
        }
예제 #3
0
        /// <summary>
        /// Runs right before MainMenu opens
        /// </summary>
        public static void Initialize()
        {
            loadedMods           = Partiality.PartialityManager.Instance.modManager.loadedMods;
            loadedModsDictionary = new Dictionary <string, PartialityMod>();
            foreach (PartialityMod mod in loadedMods)
            {
                if (blackList.Contains <string>(mod.ModID))
                {
                    continue;
                }                                                        //No Config for this :P
                else if (mod.ModID.Substring(0, 1) == "_")
                {
                    continue;
                }                                                        //Skip this mod from configuration
                if (!loadedModsDictionary.ContainsKey(mod.ModID))
                {
                    loadedModsDictionary.Add(mod.ModID, mod);
                }
                else
                {
                    Debug.LogError(string.Concat("Duplicate ModID detected! Only one of them is loaded. (duplicated ID: ", mod.ModID, ")"));
                }
            }

            loadedInterfaceDict = new Dictionary <string, OptionInterface>();
            loadedInterfaces    = new List <OptionInterface>();

            //No Mods Installed!
            if (loadedModsDictionary.Count == 0)
            {
                loadedModsDictionary = new Dictionary <string, PartialityMod>(1);
                PartialityMod blankMod = new PartialityMod
                {
                    ModID   = "No Mods Installed",
                    Version = "XXXX",
                    author  = "NULL"
                };
                loadedModsDictionary.Add(blankMod.ModID, blankMod);

                UnconfiguableOI itf = new UnconfiguableOI(blankMod, UnconfiguableOI.Reason.NoMod);
                loadedInterfaceDict.Add(blankMod.ModID, itf);
                loadedInterfaces.Add(itf);

                return;
            }

            //Load Mod Interfaces!
            foreach (KeyValuePair <string, PartialityMod> item in loadedModsDictionary)
            {
                PartialityMod   mod = loadedModsDictionary[item.Key];
                OptionInterface itf;

                if (!Regex.IsMatch(mod.ModID, "^[^\\/?%*:|\"<>/.]+$"))
                {
                    Debug.Log(string.Concat(new object[] {
                        mod.ModID,
                        " does not support CompletelyOptional: Invaild Mod ID!"
                    }));
                    itf = new UnconfiguableOI(mod, new Exception(string.Concat(mod.ModID, " is invaild ModID! Use something that can be used as folder name!")));
                    loadedInterfaces.Add(itf);
                    loadedInterfaceDict.Add(mod.ModID, itf);
                    continue;
                }


                try
                {
                    object obj = mod.GetType().GetMethod("LoadOI").Invoke(mod, new object[] { });
                    //Debug.Log(obj);
                    //itf = (OptionInterface)obj;
                    //itf = obj as OptionInterface;

                    if (obj.GetType().IsSubclassOf(typeof(OptionInterface)))
                    {
                        itf = obj as OptionInterface;
                        //Your code
                        Debug.Log(string.Concat(new object[] {
                            "Loaded OptionInterface from ",
                            mod.ModID,
                            " (type: ",
                            itf.GetType(),
                            ")"
                        }));
                    }
                    else
                    {
                        Debug.Log(string.Concat(new object[] {
                            mod.ModID,
                            " does not support CompletelyOptional: LoadOI returns what is not OptionInterface."
                        }));
                        itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log(string.Concat(new object[] {
                        mod.ModID,
                        " does not support CompletelyOptional: ",
                        ex
                    }));
                    itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                }

                try
                {
                    itf.Initialize();
                }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(itf.mod, new InvalidMenuObjAccessException(ex));
                    itf.Initialize();
                }

                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.mod, new NoTabException(mod.ModID));
                    //OptionScript.loadedInterfaceDict.Remove(mod.ModID);
                    //OptionScript.loadedInterfaceDict.Add(mod.ModID, itf);
                }

                bool loaded = itf.LoadConfig();
                if (loaded)
                {
                    Debug.Log(string.Concat("CompletelyOptional: ", mod.ModID, " config has been loaded."));
                }
                else
                {
                    Debug.Log(string.Concat("CompletelyOptional: ", mod.ModID, " does not have config.txt; Use default config."));
                }


                loadedInterfaces.Add(itf);
                loadedInterfaceDict.Add(mod.ModID, itf);
                //loadedModsDictionary[item.Key].GetType().GetMember("OI")
            }
        }