Beispiel #1
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
                });
            }
        }
Beispiel #2
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));
                }
            }
        }