Exemple #1
0
        /// <summary>
        /// Adds Basic Profile on top of OpTab
        /// </summary>
        /// <param name="tab"><see cref="OpTab"/> which will contain the profile</param>
        /// <param name="mod"><see cref="RainWorldMod"/> that has basic information of the mod</param>
        public static void AddBasicProfile(OpTab tab, RainWorldMod mod)
        {
            tab.AddItems(new OpLabel(new Vector2(100f, 550f), new Vector2(400f, 50f), mod.ModID, FLabelAlignment.Center, true));
            tab.AddItems(new OpLabel(new Vector2(50f, 500f), new Vector2(100f, 20f), InternalTranslator.Translate("Version: <ModVersion>").Replace("<ModVersion>", mod.Version), FLabelAlignment.Left));

            if (mod.author != RainWorldMod.authorNull)
            {
                tab.AddItems(new OpLabel(new Vector2(350f, 500f), new Vector2(200f, 20f), InternalTranslator.Translate("Author: <ModAuthor>").Replace("<ModAuthor>", mod.author), FLabelAlignment.Right)
                {
                    autoWrap = true
                });
            }

            /*
             * if (mod.coauthor != RainWorldMod.authorNull)
             * {
             *  labelCoauthor = new OpLabel(new Vector2(100f, 420f), new Vector2(300f, 20f), string.Concat("Coautor: ", mod.coauthor));
             *  Tabs[0].AddItem(labelCoauthor);
             *  labelCoauthor.autoWrap = true;
             * }
             * if(mod.description != RainWorldMod.authorNull)
             * {
             *  labelDesc = new OpLabel(new Vector2(80f, 350f), new Vector2(340f, 20f), mod.description, FLabelAlignment.Left);
             *  Tabs[0].AddItem(labelDesc);
             *  labelDesc.autoWrap = true;
             * } */
        }
 public MenuTab() : base("")
 {
     isHidden     = false;
     _initLog     = false; logMode = false;
     _lblInfoDesc = InternalTranslator.Translate("Click to Display Config Machine ChangeLog");
     _sbDesc      = InternalTranslator.Translate("Display <ModID>");
 }
        public static string GetCMVersion()
        {
            string v = OptionMod.ver; // OptionMod.instance.Version.Substring(0, 1);

            // for (int i = 1; i < OptionMod.instance.Version.Length; i++) { v += string.Concat(".", OptionMod.instance.Version.Substring(i, 1)); }
            return(InternalTranslator.Translate("Version: <ModVersion>").Replace("<ModVersion>", v));
        }
        // #pragma warning disable IDE0060

        internal static string UpdateInfoTextPatch(On.Menu.OptionsMenu.orig_UpdateInfoText orig, OptionsMenu menu)
        {
            //Code
            if (menu.selectedObject == enterConfig)
            {
                return(InternalTranslator.Translate("Configure Settings for Rain World Mods"));
            }
            return(orig.Invoke(menu));
        }
        private static string GetTranslator()
        {
            string name = InternalTranslator.Translate("Translator Name");

            if (name == "Translator Name")
            {
                return(string.Empty);
            }
            return(InternalTranslator.Translate("Translated to English by <TranslatorName>").Replace("<TranslatorName>", name));
        }
Exemple #6
0
        private void TutoInit()
        {
            labelID = new OpLabel(new Vector2(100f, 500f), new Vector2(400f, 50f), InternalTranslator.Translate("No Mod can be configured"), FLabelAlignment.Center, true);

            labelVersion = new OpLabel(new Vector2(100f, 440f), new Vector2(200f, 20f), "Config Machine (a.k.a. CompletelyOptional) by topicular", FLabelAlignment.Left);
            labelAuthor  = new OpLabel(new Vector2(300f, 410f), new Vector2(200f, 20f), InternalTranslator.Translate("also shoutout to RW Discord for helping me out"), FLabelAlignment.Right);

            labelSluggo0 = new OpLabel(new Vector2(100f, 300f), new Vector2(400f, 20f), InternalTranslator.Translate("check out pinned tutorial in modding-support"));
            labelSluggo1 = new OpLabel(new Vector2(100f, 260f), new Vector2(400f, 20f), InternalTranslator.Translate("and create your own config screen!"));
            Tabs[0].AddItems(labelID, labelVersion, labelAuthor, labelSluggo0, labelSluggo1);
        }
        internal static void UpdatePatch(On.Menu.OptionsMenu.orig_Update orig, OptionsMenu menu)
        {
            if (mod)
            {
                //modmenu.Update();
                menu.manager.currentMainLoop = null;
                //menu.manager.soundLoader.ReleaseAllUnityAudio();
                menu.processActive = false;

                menu.manager.currentMainLoop = new ConfigMenu(menu.manager);
                modmenu             = menu.manager.currentMainLoop as ConfigMenu;
                modmenu.vanillaMenu = menu;

                return;
            }
            else if (modmenu != null)
            {
                modmenu.ShutDownProcess();
                modmenu = null;
            }

            if (menu.manager.currentMainLoop != menu)
            {
                menu.ShutDownProcess();
                return;
            }
            if (!mod && enterConfig == null)
            { //ctor
                string t = InternalTranslator.Translate("MOD CONFIG");
                enterConfig = new SimpleButton(menu, menu.pages[0], t, "MOD CONFIG", new Vector2(340f, 50f), new Vector2(Mathf.Max(110f, t.Length * 9f + 15f), 30f));
                menu.pages[0].subObjects.Add(enterConfig);
                //menu.manager.musicPlayer.MenuRequestsSong(CompletelyOptional.ConfigManager.randomSong, 2f, 2f);
                menu.backButton.nextSelectable[2]    = enterConfig;
                enterConfig.nextSelectable[1]        = menu.soundSlider;
                enterConfig.nextSelectable[0]        = menu.backButton;
                enterConfig.nextSelectable[2]        = menu.creditsButton;
                menu.creditsButton.nextSelectable[0] = enterConfig;
            }

            orig.Invoke(menu);

            /*
             * if (resolutionDirty)
             * {
             *  resolutionDirty = false;
             *  Screen.SetResolution((int)menu.manager.rainWorld.options.ScreenSize.x, (int)menu.manager.rainWorld.options.ScreenSize.y, false);
             *  Screen.fullScreen = false;
             *  Screen.showCursor = true;
             *  menu.manager.RequestMainProcessSwitch(ProcessManager.ProcessID.OptionsMenu);
             * }
             */
        }
Exemple #8
0
            public override void Update(float dt)
            {
                foreach (MenuObject obj in this.subObjects)
                {
                    obj.Update();
                    if (!this.ctrl.hidden)
                    {
                        obj.GrafUpdate(dt);
                    }
                }
                this.GrafUpdate(dt);

                if (greyedOut || this.ctrl.hidden)
                {
                    return;
                }
                if (MouseOver)
                {
                    if (!mouseTop)
                    {
                        mouseTop = true;
                        ctrl.cfgMenu.PlaySound(SoundID.MENU_Button_Select_Mouse);
                    }
                    if (string.IsNullOrEmpty(this.name))
                    {
                        ConfigMenu.description = InternalTranslator.Translate("Switch to Tab No <TabIndex>").Replace("<TabIndex>", index.ToString());
                    }
                    else
                    {
                        ConfigMenu.description = InternalTranslator.Translate("Switch to Tab <TabName>").Replace("<TabName>", this.name);
                    }

                    if (Input.GetMouseButton(0))
                    {
                        this.click = true; this.bumpBehav.held = true;
                    }
                    else if (this.click)
                    {
                        this.click = false; this.bumpBehav.held = false;
                        ctrl.index = this.index;
                    }
                }
                else
                {
                    mouseTop = false;
                    if (!Input.GetMouseButton(0))
                    {
                        this.bumpBehav.held = false; this.click = false;
                    }
                }
            }
Exemple #9
0
        /// <summary>
        /// Call this manually if you really need to. This is what Save Button does.
        /// </summary>
        /// <param name="silent">Whether to hide indication or not</param>
        public static void SaveCurrentConfig(bool silent = false)
        {
            if (!currentInterface.Configuable())
            {
                return;
            }
            Dictionary <string, string> newConfig = currentInterface.GrabConfig();

            if (!currentInterface.SaveConfig(newConfig))
            {
                alert = InternalTranslator.Translate("<ModID> had an issue with saving its configuration").Replace("<ModID>", currentInterface.rwMod.ModID);
            }
            else if (!silent)
            {
                alert = InternalTranslator.Translate("<ModID> has saved its configuration").Replace("<ModID>", currentInterface.rwMod.ModID);
            }
        }
        internal static void ShutDownProcessPatch(On.Menu.OptionsMenu.orig_ShutDownProcess orig, OptionsMenu menu)
        {
            orig.Invoke(menu);

            if (OptionScript.ComModExists)
            {
                if (menu.CurrLang != InGameTranslator.LanguageID.Portuguese)
                {
                    OptionScript.curLang = (string)OptionScript.ComMod.GetType().GetField("customLang", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(OptionScript.ComMod);
                }
                else
                {
                    OptionScript.curLang = "eng";
                }
            }
            else
            {
                OptionScript.curLang = OptionScript.ID2Code[(int)menu.CurrLang];
            }
            InternalTranslator.LoadTranslation();

            string songid = "";

            if (menu.manager.musicPlayer != null)
            {
                songid = menu.manager.musicPlayer.song?.name.Substring(0, 5);
            }

            if (!mod)
            { //going back to main menu
                if (menu.manager.musicPlayer != null && songid != "RW_8 " && songid != "Title")
                {
                    Debug.Log(string.Concat("Shutdown Option Music :" + menu.manager.musicPlayer.song?.name));
                    menu.manager.musicPlayer.nextSong = new MenuOrSlideShowSong(menu.manager.musicPlayer, "RW_8 - Sundown", 0.8f, 2f)
                    {
                        playWhenReady = false
                    };
                }
            }
            if (enterConfig != null)
            {
                enterConfig.RemoveSprites();
                enterConfig = null;
            }
        }
Exemple #11
0
        public override void Singal(MenuObject sender, string message)
        {
            if (message != null)
            {
                if (buttonList == null)
                {
                    Dictionary <string, int> dictionary = new Dictionary <string, int>(4)
                    {
                        { "CANCEL", 0 },
                        { "APPLY", 1 },
                        { "RESET CONFIG", 2 },
                        { "SOUNDTEST", 3 }
                    };
                    buttonList = dictionary;
                }

                if (buttonList.TryGetValue(message, out int num))
                {
                    switch (num)
                    {
                    case 0:
                        OptionsMenuPatch.mod = false;
                        opened = false;
                        base.PlaySound(SoundID.MENU_Switch_Page_Out);
                        this.manager.RequestMainProcessSwitch(ProcessManager.ProcessID.OptionsMenu);
                        break;

                    case 1:
                        if (OptionScript.configChanged)
                        {
                            base.PlaySound(SoundID.MENU_Switch_Page_In);
                            SaveCurrentConfig(true);
                            OptionScript.configChanged     = false;
                            this.saveButton.menuLabel.text = InternalTranslator.Translate("SAVE ALL");
                        }
                        else
                        {
                            if (this.saveButton.menuLabel.text == InternalTranslator.Translate("SAVE ALL"))
                            {
                                base.PlaySound(SoundID.MENU_Next_Slugcat);
                                SaveAllConfig();
                                //EXIT
                                OptionsMenuPatch.mod = false;
                                opened = false;
                                this.manager.RequestMainProcessSwitch(ProcessManager.ProcessID.OptionsMenu);
                            }
                            else
                            {
                                base.PlaySound(SoundID.MENU_Button_Standard_Button_Pressed);
                            }
                        }
                        break;

                    case 2:
                        ResetCurrentConfig();
                        base.PlaySound(SoundID.MENU_Switch_Page_In);
                        break;

                    case 3:
                        if (!redUnlocked)
                        {
                            base.PlaySound(SoundID.MENU_Button_Standard_Button_Pressed);
                        }
                        else
                        {
                            base.PlaySound(SoundID.MENU_Switch_Page_In);

                            Debug.Log("Enter SoundTest");

                            this.InitializeSitting();
                            this.manager.rainWorld.progression.ClearOutSaveStateFromMemory();
                            if (this.manager.arenaSitting.ReadyToStart)
                            {
                                this.manager.RequestMainProcessSwitch(ProcessManager.ProcessID.Game);    //, 1.2f);
                            }
                            else
                            {
                                this.manager.arenaSitting = null;
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemple #12
0
        private void InitChangeLog()
        {
            List <UIelement> newElems = new List <UIelement>();

            this.lblTitle = new OpLabel(new Vector2(200f, 560f), new Vector2(200f, 30f), InternalTranslator.Translate("Config Machine ChangeLog"), bigText: true);
            this.lblVer   = new OpLabel(new Vector2(50f, 540f), new Vector2(200f, 20f), GetCMVersion(), FLabelAlignment.Left);
            this.lblTrans = new OpLabel(new Vector2(350f, 540f), new Vector2(200f, 20f), GetTranslator(), FLabelAlignment.Right);
            this.AddItems(this.lblTitle, this.lblVer, this.lblTrans);
            newElems.Add(this.lblTitle); newElems.Add(this.lblVer); newElems.Add(this.lblTrans);

            if (rawLog == null)
            {
                ReadTXT();
            }
            int len = Math.Min(rawLog.Length - 1, 16);

            this.box = new OpScrollBox(new Vector2(20f, 10f), new Vector2(560f, 520f), len * 560f, true, true, false)
            {
                redrawFlags = OpScrollBox.RedrawEvents.OnHover, doesBackBump = false
            };
            this.AddItems(this.box); this.box.Lock(true);
            newElems.Add(this.box);
            this.vers = new string[len];
            for (int i = 0; i < len; i++)
            {
                string[] split = Regex.Split(rawLog[i + 1], "#!#");
                this.vers[i] = split[0];
                OpLabel     ver = new OpLabel(new Vector2(130f + i * 560f, 470f), new Vector2(300f, 30f), split[0], bigText: true);
                OpLabelLong log = new OpLabelLong(new Vector2(20f + i * 560f, 20f), new Vector2(520f, 420f), "placeholder")
                {
                    allowOverflow = false
                };
                log.text = split[2].Trim();
                if (!string.IsNullOrEmpty(split[1]))
                {
                    ver.description = ConvertDate(split[1].Trim()); ver.bumpBehav = new BumpBehaviour(ver);
                }
                this.box.AddItems(ver, log);
                newElems.Add(ver); newElems.Add(log);
            }

            sbRight = new ScrollButton(new Vector2(460f, 470f), true);
            sbLeft  = new ScrollButton(new Vector2(90f, 470f), false);
            this.AddItems(sbRight, sbLeft); sbLeft.Hide(); curVer = 0;
            newElems.Add(sbRight); newElems.Add(sbLeft);

            foreach (UIelement element in newElems)
            {
                foreach (MenuObject obj in element.subObjects)
                {
                    OptionScript.configMenu.pages[0].subObjects.Add(obj);
                }
                OptionScript.configMenu.pages[0].Container.AddChild(element.myContainer);
            }

            _initLog = true;
        }
Exemple #13
0
        /// <summary>
        /// Adds Basic Profile on top of <see cref="OpScrollBox"/>
        /// </summary>
        /// <param name="box"><see cref="OpScrollBox"/> which will contain the profile</param>
        /// <param name="mod"><see cref="RainWorldMod"/> that has basic information of the mod</param>
        public static void AddBasicProfile(OpScrollBox box, RainWorldMod mod)
        {
            box.AddItems(new OpLabel(new Vector2(100f, box.GetContentSize() - 600f + 550f), new Vector2(400f, 50f), mod.ModID, FLabelAlignment.Center, true));
            box.AddItems(new OpLabel(new Vector2(50f, box.GetContentSize() - 600f + 500f), new Vector2(100f, 20f), InternalTranslator.Translate("Version: <ModVersion>").Replace("<ModVersion>", mod.Version), FLabelAlignment.Left));

            if (mod.author != RainWorldMod.authorNull)
            {
                box.AddItems(new OpLabel(new Vector2(350f, box.GetContentSize() - 600f + 500f), new Vector2(200f, 20f), InternalTranslator.Translate("Author: <ModAuthor>").Replace("<ModAuthor>", mod.author), FLabelAlignment.Right)
                {
                    autoWrap = true
                });
            }
        }
Exemple #14
0
        /// <summary>
        /// MonoBehavior Update
        /// </summary>
        public void Update()
        {
            if (!init)
            {
                return;
            }

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

            //Option is running
            ConfigMenu.script = this;
            isOptionMenu      = true;

            #region curFramerate
            dtHistory[dtHistoryMark] = Time.deltaTime;
            dtHistoryMark--; if (dtHistoryMark < 0)
            {
                dtHistoryMark = dtHistory.Length - 1;
            }
            float sum = 0;
            for (int h = 0; h < dtHistory.Length; h++)
            {
                sum += dtHistory[h];
            }
            curFramerate = dtHistory.Length / sum;
            #endregion curFramerate

            if (soundFill > 0)
            {
                soundFill--;
            }
            ConfigMenu.description = "";
            if (ConfigMenu.currentTab != null)
            {
                bool fade = ConfigMenu.instance.fadeSprite != null;
                ConfigMenu.menuTab.Update(Time.deltaTime);
                if (MenuTab.logMode)
                {
                    ConfigMenu.instance.saveButton.buttonBehav.greyedOut  = true;
                    ConfigMenu.instance.resetButton.buttonBehav.greyedOut = true;
                    return;
                }
                ConfigMenu.instance.backButton.buttonBehav.greyedOut = fade;
                try
                {
                    if (!ConfigMenu.freezeMenu)
                    {
                        ConfigMenu.currentTab.Update(Time.deltaTime);
                        ConfigMenu.instance.saveButton.buttonBehav.greyedOut = fade || false;
                        for (int m = 0; m < ConfigMenu.instance.modButtons.Length; m++)
                        {
                            ConfigMenu.instance.modButtons[m].buttonBehav.greyedOut = fade || false;
                        }
                        ConfigMenu.tabCtrler.greyedOut = fade || false;
                    }
                    else
                    {
                        bool h = false;
                        foreach (UIelement element in ConfigMenu.currentTab.items)
                        {
                            if (element.GetType().IsSubclassOf(typeof(UIconfig)))
                            {
                                if ((element as UIconfig).held)
                                {
                                    h = true;
                                    if (Input.GetKey(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl))
                                    {
                                        if (Input.GetKey(KeyCode.V) && !string.IsNullOrEmpty(UniClipboard.GetText()))
                                        {
                                            string grab = UniClipboard.GetText();
                                            if ((element as UIconfig).CopyFromClipboard(grab))
                                            {
                                                (element as UIconfig).bumpBehav.flash = 1f;
                                                if ((element as UIconfig).cosmetic)
                                                {
                                                    ConfigMenu.alert = InternalTranslator.Translate("Pasted <Text> from Clipboard").Replace("<Text>", grab);
                                                }
                                                else
                                                {
                                                    ConfigMenu.alert = InternalTranslator.Translate("Pasted <Text> from Clipboard to <ObjectName>").Replace("<Text>", grab).Replace("<ObjectName>", (element as UIconfig).key);
                                                }
                                            }
                                        }
                                        else if (Input.GetKey(KeyCode.C))
                                        {
                                            string grab = (element as UIconfig).CopyToClipboard();
                                            if (!string.IsNullOrEmpty(grab))
                                            {
                                                (element as UIconfig).bumpBehav.flash = 1f;
                                                UniClipboard.SetText(grab);
                                                if ((element as UIconfig).cosmetic)
                                                {
                                                    ConfigMenu.alert = InternalTranslator.Translate("Copied <Text> to Clipboard").Replace("<Text>", grab);
                                                }
                                                else
                                                {
                                                    ConfigMenu.alert = InternalTranslator.Translate("Copied <Text> to Clipboard from <ObjectName>").Replace("<Text>", grab).Replace("<ObjectName>", (element as UIconfig).key);
                                                }
                                            }
                                        }
                                    }
                                    element.Update(Time.deltaTime);
                                    continue;
                                }
                            }
                            if (element.GetType().IsSubclassOf(typeof(UItrigger)))
                            {
                                if ((element as UItrigger).held)
                                {
                                    h = true; element.Update(Time.deltaTime); continue;
                                }
                            }
                        }
                        if (!h)
                        {
                            foreach (UIelement element in ConfigMenu.currentTab.items)
                            {
                                element.Update(Time.deltaTime);
                            }
                        }
                        ConfigMenu.instance.saveButton.buttonBehav.greyedOut = fade || h;
                        for (int m = 0; m < ConfigMenu.instance.modButtons.Length; m++)
                        {
                            ConfigMenu.instance.modButtons[m].buttonBehav.greyedOut = fade || h;
                        }
                        ConfigMenu.tabCtrler.greyedOut = h;
                    }
                    ConfigMenu.currentInterface.Update(Time.deltaTime);
                }
                catch (Exception ex)
                { //Update Error Handle!
                    RainWorldMod     mod    = ConfigMenu.currentInterface.rwMod;
                    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];
                    ConfigMenu.tabCtrler.Reset();

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

            return;

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

            /*
             * foreach (OptionInterface oi in loadedInterfaces)
             * {
             * }
             */
        }
Exemple #15
0
        /// <summary>
        /// Runs right before MainMenu opens
        /// </summary>
        private static void Initialize()
        {
            //Application.RegisterLogCallback(new Application.LogCallback(TroubleShoot));

            ID2Code = new Dictionary <int, string>()
            {
                { 0, "eng" },
                { 1, "fre" },
                { 2, "ita" },
                { 3, "ger" },
                { 4, "spa" },
                { 5, "por" },
                { 6, "jap" },
                { 7, "kor" }
            };
            if (ID2Code.TryGetValue(rw.options.language, out string code))
            {
                curLang = code;
            }
            else
            {
                curLang = "eng";
            }
            string curCurLang = curLang;

            InternalTranslator.LoadTranslation();

            #region PartialityMods
            loadedMods           = Partiality.PartialityManager.Instance.modManager.loadedMods;
            loadedModsDictionary = new Dictionary <string, PartialityMod>();
            ComModExists         = false;
            foreach (PartialityMod mod in loadedMods)
            {
                if (string.IsNullOrEmpty(mod.ModID))
                {
                    goto invaildID;
                }
                if (blackList.Contains <string>(mod.ModID)) //No Config for this :P
                {
                    if (mod.ModID == "CommunicationModule")
                    {
                        ComMod = mod; ComModExists = true;
                        if (rw.options.language != 5)
                        {
                            curLang = (string)mod.GetType().GetField("customLang", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(mod);
                        }
                        else
                        {
                            curLang = "eng";
                        }
                    }
                    continue;
                }
                if (mod.ModID.Substring(0, 1) == "_")
                {
                    continue;
                }                                                   //Skip this mod from configuration
                if (mod.ModID == "SlugBase")
                {
                    SlugBaseMod = mod; SlugBaseExists = true;
                }

                if (loadedModsDictionary.ContainsKey(mod.ModID))
                {
                    Debug.LogError($"Duplicate ModID detected! (dupe ID: {mod.ModID})");
                }
                else if (Regex.IsMatch(mod.ModID, "^[^\\/?%*:|\"<>/.]+$"))
                {
                    loadedModsDictionary.Add(mod.ModID, mod); continue;
                }

invaildID:
                string InvalidID = string.IsNullOrEmpty(mod.ModID) ? "No ModID" : mod.ModID;
                Debug.Log($"{InvalidID} does not support CompletelyOptional: Invalid Mod ID! Using Mod Type name instead.");
                mod.ModID = mod.GetType().Name;
                //Assembly.GetAssembly(this.mod.GetType());
                if (!ValidModIDCheck(mod.ModID))
                {
                    Debug.Log($"{mod.ModID} does not support CompletelyOptional either! Using Assembly Name instead.");
                    mod.ModID = Assembly.GetAssembly(mod.GetType()).GetName().Name;
                    if (!ValidModIDCheck(mod.ModID))
                    {
                        Debug.Log($"{mod.ModID} does not support CompletelyOptional either! Abandoning {InvalidID}!"); continue;
                    }
                }
                loadedModsDictionary.Add(mod.ModID, mod);
            }

            //Debug.Log(string.Concat("curLang: ", curLang));
            if (curCurLang != curLang)
            {
                InternalTranslator.LoadTranslation();
            }

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

            //No Mods Installed!
            if (loadedModsDictionary.Count == 0 && !OptionMod.ReferencesBepInEx)
            {
                loadedModsDictionary = new Dictionary <string, PartialityMod>(1);
                PartialityMod blankMod = new PartialityMod
                {
                    ModID   = "No Mods Installed",
                    Version = "XXXX",
                    author  = RainWorldMod.authorNull
                };
                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;

                try
                {
                    var method = mod.GetType().GetMethod("LoadOI");
                    if (method == null || method.GetParameters().Length > 0 || method.ContainsGenericParameters)
                    {
                        // Mod didn't attempt to interface with CompletelyOptional, don't bother logging it.
                        itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                    }
                    else if (method.Invoke(mod, null) is OptionInterface oi)
                    {
                        itf = oi;
                        //Your code
                        Debug.Log($"Loaded OptionInterface from {mod.ModID} (type: {itf.GetType()})");
                    }
                    else
                    {
                        itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                        Debug.Log($"{mod.ModID} did not return an OptionInterface in LoadOI.");
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"{mod.ModID} threw an exception in LoadOI: {ex.Message}");
                    itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                }

                if (itf.rwMod.mod == null)
                {
                    NullModException e = new NullModException(mod.ModID);
                    Debug.Log(e); Debug.LogException(e);
                    itf.rwMod = new RainWorldMod(mod);
                    // itf = new UnconfiguableOI(mod, e);
                }

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

                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.rwMod, new NoTabException(mod.ModID));
                    itf.Initialize();
                    //OptionScript.loadedInterfaceDict.Remove(mod.ModID);
                    //OptionScript.loadedInterfaceDict.Add(mod.ModID, itf);
                }
                else if (itf.Configuable())
                {
                    if (itf.LoadConfig())
                    {
                        Debug.Log($"CompletelyOptional) {itf.rwMod.ModID} config has been loaded.");
                    }
                    else
                    {
                        Debug.Log($"CompletelyOptional) {itf.rwMod.ModID} does not have config.json.");
                        //itf.Initialize();
                        try
                        {
                            itf.SaveConfig(itf.GrabConfig());
                            Debug.Log($"CompletelyOptional) {itf.rwMod.ModID} uses default config.");
                        }
                        catch (Exception e)
                        {
                            Debug.Log("Saving Default Config Failed.");
                            Debug.Log(e);
                        }
                    }
                }

                loadedInterfaces.Add(itf);
                loadedInterfaceDict.Add(itf.rwMod.ModID, itf);
                //loadedModsDictionary[item.Key].GetType().GetMember("OI")
            }
            // Progression of loaded OIs
            ProgressData.SubPatch();
            if (OptionScript.rw.setup.loadProg)
            {
                ProgressData.LoadOIsProgression();
            }

            #endregion PartialityMods

            #region InternalTest
            if (OptionMod.testing)
            {
#pragma warning disable CS0162
                PartialityMod temp = new PartialityMod()
                {
                    author  = "topicular",
                    ModID   = "InternalTest",
                    Version = OptionMod.instance.Version
                };
                loadedModsDictionary.Add(temp.ModID, temp);
                OptionInterface itf = new InternalTestOI(temp);
                try { itf.Initialize(); }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(temp, new GeneralInitializeException(ex));
                    itf.Initialize();
                }
                loadedInterfaces.Add(itf);
                loadedInterfaceDict.Add(temp.ModID, itf);
#pragma warning restore CS0162
            }
            #endregion InternalTest

            // dual's code
            if (OptionMod.ReferencesBepInEx)
            {
                LoadBaseUnityPlugins();
            }

            Debug.Log($"CompletelyOptional finished initializing {loadedInterfaceDict.Count} OIs.");
        }
Exemple #16
0
        private void ListMods()
        {
            const int modInPage = 20;
            int       cListNum  = Mathf.CeilToInt(configuableMods.Length / (float)modInPage);
            int       iListNum  = Mathf.CeilToInt(ignoredMods.Length / (float)modInPage);

            string modNumDecimal = "D" + (configuableMods.Length + ignoredMods.Length).ToString().Length.ToString();

            Tabs = new OpTab[cListNum + iListNum];
            for (int t = 0; t < cListNum; t++)
            {
                string name = InternalTranslator.Translate("Mods") + " " + ((t * modInPage) + 1).ToString(modNumDecimal) + " ~ "
                              + (Math.Min((t + 1) * modInPage, configuableMods.Length)).ToString(modNumDecimal);
                Tabs[t] = new OpTab(name);
                Tabs[t].AddItems(new OpLabel(new Vector2(100f, 500f), new Vector2(400f, 50f), InternalTranslator.Translate("Configurable Mod List"), FLabelAlignment.Center, true));
            }
            for (int t = cListNum; t < cListNum + iListNum; t++)
            {
                string name = InternalTranslator.Translate("Mods") + " " + (1 + configuableMods.Length + ((t - cListNum) * modInPage)).ToString(modNumDecimal) + " ~ "
                              + (configuableMods.Length + Math.Min((t - cListNum + 1) * modInPage, ignoredMods.Length)).ToString(modNumDecimal);
                Tabs[t] = new OpTab(name);
                Tabs[t].AddItems(new OpLabel(new Vector2(100f, 500f), new Vector2(400f, 50f), InternalTranslator.Translate("Other Mod List"), FLabelAlignment.Center, true));
            }

            for (int i = 0; i < configuableMods.Length; i++)
            {
                string name = configuableMods[i].ModID + " (" + configuableMods[i].Version + ")";
                string ath  = "";
                if (!string.IsNullOrEmpty(configuableMods[i].author) && configuableMods[i].author != RainWorldMod.authorNull)
                {
                    ath = configuableMods[i].author;
                }
                Vector2 pos = default;
                pos.x = i % 2 == 0 ? 40f : 320f;
                pos.y = 405f - Mathf.FloorToInt((i % modInPage) / 2f) * 40f;
                string desc = string.IsNullOrEmpty(ath) ? InternalTranslator.Translate("Configure <ModID>")
                    : InternalTranslator.Translate("Configure <ModID> by <ModAuthor>").Replace("<ModAuthor>", ath);
                Tabs[Mathf.FloorToInt(i / (float)modInPage)].AddItems(new OpSimpleButton(pos, new Vector2(240f, 30f), configuableMods[i].ModID, name)
                {
                    description = desc.Replace("<ModID>", configuableMods[i].ModID)
                });
            }

            for (int i = 0; i < ignoredMods.Length; i++)
            {
                string name = ignoredMods[i].ModID + " (" + ignoredMods[i].Version + ")";
                string desc = " ";
                if (!string.IsNullOrEmpty(ignoredMods[i].author) && ignoredMods[i].author != RainWorldMod.authorNull)
                {
                    desc = InternalTranslator.Translate("<ModID> by <ModAuthor>").Replace("<ModAuthor>", ignoredMods[i].author).Replace("<ModID>", ignoredMods[i].ModID);
                }
                Vector2 pos = default;
                pos.x = i % 2 == 0 ? 50f : 330f;
                pos.y = 410f - Mathf.FloorToInt((i % modInPage) / 2f) * 40f;
                Tabs[cListNum + Mathf.FloorToInt(i / (float)modInPage)].AddItems(new OpRect(new Vector2(pos.x - 10f, pos.y - 5f), new Vector2(240f, 30f))
                {
                    description = desc, doesBump = true
                },
                                                                                 new OpLabel(pos, new Vector2(220f, 20f), name));
            }
        }
Exemple #17
0
        public override void Initialize()
        {
            base.Initialize();

            if (mode == GenMode.BepInExConfig)
            {
                ICollection <ConfigDefinition> keys = bepConfig.Keys;
                List <string> sections = new List <string>();
                foreach (ConfigDefinition k in keys)
                {
                    // Debug.Log($"{rwMod.ModID}) {k.Section}: {k.Key}");
                    if (!sections.Contains(k.Section))
                    {
                        sections.Add(k.Section);
                    }
                }
                sections.Sort();

                bool        hasUnsupported = false, hasFirstScroll = false;
                OpScrollBox firstScroll = null;
                Tabs = new OpTab[Mathf.Min(20, sections.Count)];
                for (int t = 0; t < Tabs.Length; t++)
                {
                    Tabs[t] = new OpTab(sections[t]);
                    float h = t != 0 ? 50f : 150f;
                    List <ConfigDefinition> cds = new List <ConfigDefinition>();
                    foreach (ConfigDefinition k in keys)
                    {
                        if (k.Section == sections[t])
                        {
                            cds.Add(k);
                        }
                    }
                    cds.Sort(CompareCDkey);
                    List <UIelement> elms = new List <UIelement>();
                    for (int e = 0; e < cds.Count; e++)
                    {
                        if (TryGetBase(bepConfig, cds[e], out ConfigEntryBase entryBase))
                        {
                            string desc = entryBase.Description.Description; // LoremIpsum.Generate(3, 4);
                            switch (entryBase.SettingType.Name.ToLower())
                            {
                            case "bool":     // OpCheckBox
                            case "boolean":
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <bool> eBool))
                                {
                                    elms.Add(new OpCheckBox(new Vector2(30f, 600f - h - 40f), GenerateKey(cds[e]), (bool)eBool.DefaultValue)
                                    {
                                        description = GetFirstSentence(desc)
                                    });
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(70f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(80f, 600f - h - 80f), new Vector2(500f, 45f), desc));
                                    }
                                    h += 60f;
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case "byte":     //OpSliderSubtle
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <byte> eByte))
                                {
                                    elms.Add(new OpSliderSubtle(new Vector2(30f, 600f - h - 45f), GenerateKey(cds[e]), new IntVector2(0, 20), 240, false, Mathf.Clamp((byte)eByte.DefaultValue, 0, 20))
                                    {
                                        description = GetFirstSentence(desc)
                                    });
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(80f, 600f - h - 90f), new Vector2(500f, 45f), desc));
                                    }
                                    h += 90f;
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case "uint":     //OpSlider
                            case "uint32":
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <uint> eUint))
                                {
                                    elms.Add(new OpSlider(new Vector2(30f, 600f - h - 45f), GenerateKey(cds[e]), new IntVector2(0, 100), 400, false, Mathf.Clamp(Convert.ToInt32((uint)eUint.DefaultValue), 0, 100))
                                    {
                                        description = GetFirstSentence(desc)
                                    });
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(80f, 600f - h - 90f), new Vector2(500f, 45f), desc));
                                    }
                                    h += 90f;
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case "int":     //OpUpdown
                            case "int32":
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <int> eInt))
                                {
                                    elms.Add(new OpUpdown(new Vector2(30f, 600f - h - 45f), 110f, GenerateKey(cds[e]), (int)eInt.DefaultValue)
                                    {
                                        description = GetFirstSentence(desc), allowSpace = true
                                    });
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(160f, 600f - h - 60f), new Vector2(420f, 45f), desc));
                                    }
                                    h += 60f;
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case "float":     //OpUpdown
                            case "single":
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <float> eFloat))
                                {
                                    elms.Add(new OpUpdown(new Vector2(30f, 600f - h - 45f), 110f, GenerateKey(cds[e]), (float)eFloat.DefaultValue, 2)
                                    {
                                        description = GetFirstSentence(desc), allowSpace = true
                                    });
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(160f, 600f - h - 60f), new Vector2(420f, 45f), desc));
                                    }
                                    h += 60f;
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case "string":     //OpTextBox or OpColorPicker
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <string> eString))
                                {
                                    string defaultString = (string)eString.DefaultValue;
                                    if (OpColorPicker.IsStringHexColor(defaultString))
                                    {     //OpColorPicker
                                        elms.Add(new OpColorPicker(new Vector2(30f, 600f - h - 170f), GenerateKey(cds[e]), defaultString));
                                        elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                        {
                                            alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                        });
                                        if (!string.IsNullOrEmpty(desc))
                                        {
                                            elms.Add(new OpLabelLong(new Vector2(200f, 600f - h - 170f), new Vector2(380f, 135f), desc));
                                        }
                                        h += 170f;
                                    }
                                    else
                                    {
                                        elms.Add(new OpTextBox(new Vector2(30f, 600f - h - 45f), 110f, GenerateKey(cds[e]), defaultString, OpTextBox.Accept.StringASCII)
                                        {
                                            description = GetFirstSentence(desc)
                                        });
                                        elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                        {
                                            alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                        });
                                        if (!string.IsNullOrEmpty(desc))
                                        {
                                            elms.Add(new OpLabelLong(new Vector2(160f, 600f - h - 60f), new Vector2(420f, 45f), desc));
                                        }
                                        h += 60f;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case "keycode":     //OpKeyBinder
                                if (bepConfig.TryGetEntry(cds[e], out ConfigEntry <KeyCode> eKeyCode))
                                {
                                    elms.Add(new OpKeyBinder(new Vector2(30f, 600f - h - 50f), new Vector2(150f, 30f), rwMod.ModID, GenerateKey(cds[e]), ((KeyCode)eKeyCode.DefaultValue).ToString(), false));
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(200f, 600f - h - 90f), new Vector2(380f, 75f), desc));
                                    }
                                    h += 100f;
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            default:
                                // if type is enum => OpComboBox
                                if (entryBase.SettingType.IsEnum)
                                {
                                    elms.Add(new OpResourceSelector(new Vector2(30f, 600f - h - 45f), 120f, GenerateKey(cds[e]), entryBase.SettingType, entryBase.DefaultValue.ToString()));
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(160f, 600f - h - 60f), new Vector2(420f, 45f), desc));
                                    }
                                    h += 60f;
                                    break;
                                }

                                if (TryAcceptableValueList(entryBase.Description.AcceptableValues,
                                                           out var valueType, out var values))
                                {
                                    var items = new List <ListItem>();
                                    for (var i = 0; i < values.Length; i++)
                                    {
                                        var value = values[i];
                                        var name  = TomlTypeConverter.ConvertToString(value, valueType);
                                        var item  = new ListItem(name, i)
                                        {
                                            displayName = value.ToString()
                                        };
                                        items.Add(item);
                                    }

                                    elms.Add(new OpComboBox(new Vector2(30f, 600f - h - 45f), 120f, GenerateKey(cds[e]), items, TomlTypeConverter.ConvertToString(entryBase.DefaultValue, valueType)));
                                    elms.Add(new OpLabel(new Vector2(20f, 600f - h - 15f), new Vector2(120f, 15f), cds[e].Key)
                                    {
                                        alignment = FLabelAlignment.Left, description = GetFirstSentence(desc), bumpBehav = (elms[elms.Count - 1] as UIconfig).bumpBehav
                                    });
                                    if (!string.IsNullOrEmpty(desc))
                                    {
                                        elms.Add(new OpLabelLong(new Vector2(160f, 600f - h - 60f), new Vector2(420f, 45f), desc));
                                    }
                                    h += 60f;
                                    break;
                                }

                                Debug.Log($"{rwMod.ModID} has unsupported ConfigEntry: {cds[e].Key}({entryBase.SettingType.Name})");
                                hasUnsupported = true; continue; // Not supported
                            }
                            h += 20f;                            // between gap
                        }
                    }
                    if (h <= 600f)
                    {
                        if (t == 0)
                        {
                            AddBasicProfile(Tabs[0], rwMod); hasFirstScroll = false;
                        }
                        Tabs[t].AddItems(elms.ToArray());
                    }
                    else
                    {
                        OpScrollBox box = new OpScrollBox(Tabs[t], h);
                        if (t == 0)
                        {
                            AddBasicProfile(box, rwMod); hasFirstScroll = true; firstScroll = box;
                        }
                        foreach (UIelement elm in elms)
                        {
                            elm.pos = new Vector2(elm.GetPos().x, elm.GetPos().y - 600f + h);
                        }
                        box.AddItems(elms.ToArray());
                    }
                }
                if (hasUnsupported)
                {
                    string warn = InternalTranslator.Translate("This Plugin contains types of settings that are not supported by Config Machine:") + Environment.NewLine
                                  + InternalTranslator.Translate("Go to [BepInEx]-[config] folder and use Notepad to edit those settings.");
                    if (hasFirstScroll)
                    {
                        firstScroll.AddItems(new OpLabel(new Vector2(50f, firstScroll.GetContentSize() - 600f + 525f), new Vector2(500f, 30f), warn));
                    }
                    else
                    {
                        Tabs[0].AddItems(new OpLabel(new Vector2(50f, 525f), new Vector2(500f, 20f), warn));
                    }
                }
            }
            else
            {
                Tabs    = new OpTab[1];
                Tabs[0] = new OpTab();
                AddBasicProfile(Tabs[0], rwMod);
                if (!string.IsNullOrEmpty(modDescription))
                {
                    Tabs[0].AddItems(new OpLabelLong(new Vector2(50f, 200f), new Vector2(500f, 250f), modDescription, alignment: FLabelAlignment.Center));
                }
            }
        }
Exemple #18
0
#pragma warning restore IDE0060
#pragma warning restore CA1822

        public override void Initialize()
        {
            if (this.reason == Reason.TooManyMod)
            {
                ListMods();
                return;
            }

            Tabs    = new OpTab[1];
            Tabs[0] = new OpTab();

            if (this.reason == Reason.NoMod)
            {
                TutoInit();
                return;
            }

            GeneratedOI.AddBasicProfile(Tabs[0], rwMod);

            switch (this.reason)
            {
            case Reason.NoInterface:
                if (rwMod.description != RainWorldMod.authorNull)
                {
                    Tabs[0].AddItems(new OpLabelLong(new Vector2(50f, 200f), new Vector2(500f, 250f), rwMod.description, alignment: FLabelAlignment.Center));
                    labelSluggo0 = new OpLabel(new Vector2(100f, 150f), new Vector2(400f, 20f),
                                               InternalTranslator.Translate(rwMod.type == RainWorldMod.Type.PartialityMod ? "This Partiality Mod has no Option Interface." : "This BepInEx Plugin has no Option Interface."));
                }
                else
                {
                    labelSluggo0 = new OpLabel(new Vector2(100f, 350f), new Vector2(400f, 20f),
                                               InternalTranslator.Translate(rwMod.type == RainWorldMod.Type.PartialityMod ? "This Partiality Mod has no Option Interface." : "This BepInEx Plugin has no Option Interface."));
                }

                Tabs[0].AddItems(labelSluggo0);

                break;

            case Reason.InitError:
                blue = new OpRect(new Vector2(30f, 20f), new Vector2(540f, 420f))
                {
                    alpha = 0.7f, colorFill = new Color(0.121568627f, 0.40392156862f, 0.69411764705f, 1f)
                };

                Color white = Menu.Menu.MenuRGB(Menu.Menu.MenuColors.White);
                oof = new OpLabel(new Vector2(100f, 380f), new Vector2(30f, 40f), ":(", FLabelAlignment.Left, true)
                {
                    color = white
                };
                labelSluggo0 = new OpLabel(new Vector2(150f, 390f), new Vector2(300f, 20f), InternalTranslator.Translate("There was an issue initializing OptionInterface."))
                {
                    color = white
                };
                labelSluggo1 = new OpLabelLong(new Vector2(50f, 40f), new Vector2(500f, 320f), exception)
                {
                    color = white, allowOverflow = false
                };
                labelVersion = new OpLabel(new Vector2(50f, 480f), new Vector2(100f, 20f), string.Concat(Environment.NewLine, "Config Machine ", MenuTab.GetCMVersion()), FLabelAlignment.Left);

                Tabs[0].AddItems(blue, oof, labelSluggo0, labelSluggo1, labelVersion);

                break;
            }
        }
Exemple #19
0
        public override string UpdateInfoText()
        {
            if (this.selectedObject is SelectOneButton)
            {
                if ((this.selectedObject as SelectOneButton).signalText == "ModSelect")
                {
                    string id = (this.selectedObject as SelectOneButton).menuLabel.text;
                    string output;
                    bool   fc = false;
                    if (OptionScript.loadedInterfaceDict.TryGetValue(id, out OptionInterface oi))
                    {
                        fc = oi.Configuable();
                        if (fc)
                        {
                            if (!string.IsNullOrEmpty(oi.rwMod.author) && oi.rwMod.author != RainWorldMod.authorNull)
                            {
                                output = InternalTranslator.Translate("Configure <ModID> by <ModAuthor>").Replace("<ModAuthor>", oi.rwMod.author);
                            }
                            else
                            {
                                output = InternalTranslator.Translate("Configure <ModID>");
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(oi.rwMod.author) && oi.rwMod.author != RainWorldMod.authorNull)
                            {
                                output = InternalTranslator.Translate("Display <ModID> by <ModAuthor>").Replace("<ModAuthor>", oi.rwMod.author);
                            }
                            else
                            {
                                output = InternalTranslator.Translate("Display <ModID>");
                            }
                        }
                    }
                    else
                    {
                        if (fc)
                        {
                            output = InternalTranslator.Translate("Configure <ModID>");
                        }
                        else
                        {
                            output = InternalTranslator.Translate("Display <ModID>");
                        }
                    }
                    output = output.Replace("<ModID>", id);

                    return(output);
                }
                else if ((this.selectedObject as SelectOneButton).signalText == "ScrollUp")
                {
                    return(InternalTranslator.Translate("Scroll Up"));
                }
                else if ((this.selectedObject as SelectOneButton).signalText == "ScrollDown")
                {
                    return(InternalTranslator.Translate("Scroll Down"));
                }
            }
            if (this.selectedObject is HoldButton)
            {
                if (modList.TryGetValue(selectedModIndex, out string id))
                {
                    return(InternalTranslator.Translate("Hold down to restore original config of <ModID>").Replace("<ModID>", id));
                }
                return(InternalTranslator.Translate("Hold down to restore original config for this mod"));
            }
            if (this.selectedObject == this.backButton)
            {
                if (OptionScript.configChanged)
                {
                    return(InternalTranslator.Translate("Return to vanilla option menu (WITHOUT saving!)"));
                }
                else
                {
                    return(InternalTranslator.Translate("Return to vanilla option menu"));
                }
            }
            if (this.selectedObject == this.saveButton)
            {
                if (this.saveButton.menuLabel.text == InternalTranslator.Translate("SAVE ALL"))
                {
                    return(InternalTranslator.Translate("Save all changes and exit"));
                }
                else
                {
                    if (modList.TryGetValue(selectedModIndex, out string id))
                    {
                        return(InternalTranslator.Translate("Save changed config of <ModID>").Replace("<ModID>", id));
                    }
                    return(InternalTranslator.Translate("Save changed config of this mod"));
                }
            }

            return(base.UpdateInfoText());
        }
Exemple #20
0
 private static string ConvertDate(string yyyymmdd) => DateTime.ParseExact(yyyymmdd, "yyyyMMdd", null).ToString("D", InternalTranslator.GetCultureInfo());
Exemple #21
0
        public override void Update()
        {
            if (!string.IsNullOrEmpty(description) && string.IsNullOrEmpty(this.UpdateInfoText()))
            {
                this.infoLabelFade  = 1f;
                this.infoLabel.text = description;
                if (lastDescription != description)
                {
                    this.infolabelDirty = false;
                    this.infoLabelSin   = 0f;
                }
            }
            lastDescription = description;
            if (!string.IsNullOrEmpty(alert))
            {
                this.alertLabelFade  = 2f; this.lastAlertLabelFade = 2f;
                this.alertLabelSin   = 0f;
                this.alertLabel.text = alert;
                alert = null;
            }
            this.lastAlertLabelFade = this.alertLabelFade;
            this.alertLabelFade     = Mathf.Max(0f, this.alertLabelFade - 1f / Mathf.Lerp(1f, 100f, Mathf.Clamp01(this.alertLabelFade)));
            this.alertLabelSin     += this.alertLabelFade;

            base.Update(); //keep buttons to be sane

            if (fadein && this.scene != null && (int)this.scene.sceneID < 12 && (int)this.scene.sceneID > 6)
            { //clamp offset
                this.scene.camPos = new Vector2(this.scene.camPos.x * 0.7f, this.scene.camPos.y * 0.7f);
            }

            if (this.fadeSprite != null)
            {
                if (!fadein)
                {
                    this.fadeoutFrame++;
                    if (this.fadeoutFrame > 40)
                    {
                        //if not loaded yet ==> this.fadeoutFrame = 30; return;
                        this.fadeoutFrame = 20;
                        this.fadein       = true;
                        if (currentInterface == null)
                        {
                            this.Initialize();
                        }
                        if (reset)
                        {
                            ResetCurrentConfigForReal();
                        }
                    }
                }
                else
                {
                    this.fadeoutFrame--;
                    if (this.fadeoutFrame < 1)
                    {
                        this.fadeoutFrame = 0;
                        this.fadeSprite.RemoveFromContainer();
                        this.fadeSprite = null;
                        return;
                    }
                }
                this.OpenMenu();
                return;
            }
            else
            {
                if (OptionScript.configChanged && this.backButton != null)
                {
                    this.backButton.menuLabel.text = InternalTranslator.Translate("CANCEL");
                }
                else
                {
                    this.backButton.menuLabel.text = InternalTranslator.Translate("BACK");
                }
            }

            if (this.manager.musicPlayer != null)
            {
                if (this.manager.musicPlayer.song == null && this.manager.musicPlayer.nextSong == null)
                {
                    this.manager.musicPlayer.MenuRequestsSong(GetRandomSong(), 1f, 2f);
                }
            }
        }
Exemple #22
0
        public void Initialize() //UI
        {
            if (vanillaMenu != null)
            {
                vanillaMenu.ShutDownProcess();
                vanillaMenu = null;
            }

            instance = this;
            mute     = true;

#pragma warning disable CS0162 // 접근할 수 없는 코드가 있습니다.
            if (!OptionMod.testing)
            {
                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);
            }
            else
            {
                this.scene = new SlideShowMenuScene(this, this.pages[0], MenuScene.SceneID.Intro_4_Walking);
                this.pages[0].subObjects.Add(this.scene);
            }
#pragma warning restore CS0162

            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(193f, 240f) - UIelement._offset, new Vector2(280f, 495f), 0.3f);
            //modCanvasBound = new OpRect(new Vector2(553f, 105f), new Vector2(630f, 630f), 0.4f);
            modCanvasBound = new OpRect(new Vector2(543f, 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], InternalTranslator.Translate("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], InternalTranslator.Translate("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], InternalTranslator.Translate("RESET CONFIG"), "RESET CONFIG", new Vector2(300f, 110f), 30f);
            this.pages[0].subObjects.Add(this.resetButton);
            this.alertLabel = new MenuLabel(this, this.pages[0], "", new Vector2(383f, 735f), new Vector2(600f, 30f), false);
            this.pages[0].subObjects.Add(this.alertLabel);
            this.alertLabelFade = 0f; this.lastAlertLabelFade = 0f; this.alertLabelSin = 0f;

            //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;

            menuTab.lblInfoButton           = new OpLabel(new Vector2(233f, 215f) - UIelement._offset, new Vector2(200f, 20f), "Config Machine " + MenuTab.GetCMVersion());
            menuTab.lblInfoButton.bumpBehav = new BumpBehaviour(menuTab.lblInfoButton);
            menuTab.AddItems(menuTab.lblInfoButton);
            this.pages[0].subObjects.Add(menuTab.lblInfoButton.label);

            List <OptionInterface> itfs = new List <OptionInterface>();

            // Initialize
            OptionScript.loadedInterfaceDict.Remove(InternalTranslator.Translate("Mod List")); // Remove old Mod List
            List <UnconfiguableOI> replacedOIs = new List <UnconfiguableOI>();
            foreach (string id in OptionScript.loadedInterfaceDict.Keys)
            {
                OptionInterface itf = OptionScript.loadedInterfaceDict[id];
                Debug.Log(string.Concat("OptionInterface Initializing: " + id));

#pragma warning disable CS0612
                try { itf.Initialize(); }
                catch (Exception ex)
                { itf = new UnconfiguableOI(itf.mod, new GeneralInitializeException(ex)); goto replaced; }

                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.mod, new NoTabException(id)); goto replaced;
                }
                else if (itf.Tabs.Length > 20)
                {
                    itf = new UnconfiguableOI(itf.mod, new TooManyTabsException()); goto replaced;
                }

                try { itf.LoadConfig(); itf.ShowConfig(); }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(itf.mod, new LoadDataException(string.Concat("OILoad/ShowConfigError: ", id, " had a problem in Load/ShowConfig()\nAre you editing LoadConfig()/ShowConfig()? That could cause serious error.",
                                                                                           Environment.NewLine, ex
                                                                                           )));
                    goto replaced;
                }
#pragma warning restore CS0612

                itfs.Add(itf);
                continue;

replaced:
                itf.Initialize();
                itfs.Add(itf);
                replacedOIs.Add(itf as UnconfiguableOI);
            }
            foreach (UnconfiguableOI itf in replacedOIs)
            {
                OptionScript.loadedInterfaceDict.Remove(itf.rwMod.ModID);
                OptionScript.loadedInterfaceDict.Add(itf.rwMod.ModID, itf);
            }

            // Remove Excess
            int                 priority    = (int)OptionInterface.Priority.NoInterface;
            UnconfiguableOI     listItf     = null;
            List <RainWorldMod> listIgnored = new List <RainWorldMod>();
            while (itfs.Count > 16 && priority < (int)OptionInterface.Priority.Inconfiguable) // 1
            {
                Debug.Log(string.Concat("Mod Count: ", itfs.Count, "! Discarding priority ", priority));

                /* if (priority == -2)
                 * {
                 *  List<OptionInterface> temp2 = new List<OptionInterface>();
                 *  foreach (OptionInterface oi in itfs) { if (oi.GetPriority() > -2) { temp2.Add(oi); } }
                 *  itfs = temp2; priority++; continue;
                 * } */
                if (priority == (int)OptionInterface.Priority.NoInterface)
                {
                    PartialityMod blankMod = new PartialityMod
                    {
                        ModID   = InternalTranslator.Translate("Mod List"),
                        Version = "XXXX",
                        author  = RainWorldMod.authorNull
                    };
                    listItf = new UnconfiguableOI(blankMod, UnconfiguableOI.Reason.TooManyMod);
                }
                List <OptionInterface> temp = new List <OptionInterface>();
                foreach (OptionInterface oi in itfs)
                {
                    if (oi.GetPriority() > priority)
                    {
                        temp.Add(oi);
                    }
                    else
                    {
                        listIgnored.Add(oi.rwMod);
                    }
                }
                itfs = temp;
                priority++;
            }

            // Sorting
            {
                List <OptionInterface>[] sortTemp = new List <OptionInterface> [(int)OptionInterface.Priority.Error + 2];
                for (int p = 0; p < sortTemp.Length; p++)
                {
                    sortTemp[p] = new List <OptionInterface>();
                }
                foreach (OptionInterface oi in itfs)
                {
                    sortTemp[oi.GetPriority() + 1].Add(oi);
                }
                int cmCount = 0;
                for (int p = 0; p < sortTemp.Length; p++)
                {
                    cmCount += sortTemp[p].Count; sortTemp[p].Sort(CompareOIModID);
                }

                itfs = new List <OptionInterface>();
                if (priority > (int)OptionInterface.Priority.NoInterface)
                {
                    OptionScript.loadedInterfaceDict.Add(InternalTranslator.Translate("Mod List"), listItf);
                    listItf.SetIgnoredModList(listIgnored);
                    if (cmCount > 15)
                    {
                        listItf.SetConfiguableModList(sortTemp);
                    }
                    else
                    {
                        listItf.SetConfiguableModList(null);
                    }
                    listItf.Initialize();
                    itfs.Add(listItf);
                }
                for (int p = sortTemp.Length - 1; p >= 0; p--)
                {
                    for (int i = 0; i < sortTemp[p].Count; i++)
                    {
                        itfs.Add(sortTemp[p][i]);
                    }
                }
            }

            // Add Buttons
            modButtons = new SelectOneButton[Math.Min(16, itfs.Count)];
            Dictionary <int, string> dictionary = new Dictionary <int, string>(itfs.Count);
            selectedModIndex = 0;
            for (int i = 0; i < itfs.Count; i++)
            {
                OptionInterface itf = itfs[i];
#pragma warning disable CS0162
                if (OptionMod.testing)
                {
                    Debug.Log(string.Concat("Mod(" + i + ") : " + itf.rwMod.ModID));
                }
#pragma warning restore CS0162
                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();
                }
                dictionary.Add(i, itf.rwMod.ModID);

                if (i > 15)
                {
                    continue;
                }
                modButtons[i] = new SelectOneButton(this, this.pages[0], itf.rwMod.ModID, "ModSelect", new Vector2(208f, 700f - 30f * i), new Vector2(250f, 24f), modButtons, i);
                this.pages[0].subObjects.Add(modButtons[i]);
            }
            modList    = dictionary;
            scrollMode = false;
            if (itfs.Count > 16)
            {
                scrollMode = true;
                scrollTop  = 1;
                modButtons[1].menuLabel.text  = InternalTranslator.Translate("Scroll Up");
                modButtons[1].signalText      = "ScrollUp";
                modButtons[15].menuLabel.text = InternalTranslator.Translate("Scroll Down");
                modButtons[15].signalText     = "ScrollDown";
                ScrollButtons();
            }

            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];
                }
                if (listItf != null)
                {
                    this.modButtons[0].menuLabel.text = listItf.rwMod.ModID;
                }
            }
            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;

            //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(503f, 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;

            mute = false;
        }