Пример #1
0
 /// <summary>
 /// Constructs a UMFGadgetConfigMenu, optionally for a given ini file section and given config file path. Throws an <see cref="InvalidOperationException"/> with the message <see cref="NO_CONFIGURABLE_DATA"/> if the given config file has no configurable data.
 /// </summary>
 /// <param name="section">The Ini file section to reference. If the specified section is not present, then the section matching the config file's name will be used instead.</param>
 /// <param name="hidesModMenu">Specifies whether the mod menu should be hidden when this config menu is opened.</param>
 /// <param name="configFilePath">Specifies the location of the config file to reference. If left unspecified, the standard config file for your mod will be used.</param>
 /// <param name="autoReload">If not null, auto-reloads the configs for the given <see cref="ModMenuEntry"/>.</param>
 /// <param name="readonlyEntries">All config entries that match names in this list will be displayed as read-only.</param>
 public INIGadgetConfigMenu(string section, bool hidesModMenu = false, string configFilePath = null, ModMenuEntry autoReload = null, params string[] readonlyEntries) : base(hidesModMenu)
 {
     if (configFilePath == null)
     {
         configFilePath = Path.Combine(GadgetPaths.ConfigsPath, Assembly.GetCallingAssembly().GetName().Name) + ".ini";
     }
     this.autoReload = autoReload;
     LoadConfigFile(configFilePath, section, readonlyEntries);
 }
Пример #2
0
        internal static void BuildConfigMenus(RectTransform parent)
        {
            ConfigMenus.Clear();

            if (GadgetCoreAPI.GetUMFAPI() != null)
            {
                if (UMFConfigMenu == null || UMFConfigMenu.Item2 == null)
                {
                    UMFConfigMenu umfConfigMenu = new UMFConfigMenu();
                    RectTransform menuParent    = new GameObject("uModFramework", typeof(RectTransform)).GetComponent <RectTransform>();
                    menuParent.gameObject.SetActive(false);
                    menuParent.SetParent(parent);
                    menuParent.anchorMin = new Vector2(0f, 0f);
                    menuParent.anchorMax = new Vector2(1f, 1f);
                    menuParent.offsetMin = Vector2.zero;
                    menuParent.offsetMax = Vector2.zero;
                    umfConfigMenu.Build(menuParent);
                    UMFConfigMenu = Tuple.Create <IGadgetConfigMenu, RectTransform>(umfConfigMenu, menuParent);
                }
                else
                {
                    UMFConfigMenu.Item1.Reset();
                }
            }

            for (int i = 0; i < ModMenuController.modEntries.Count; i++)
            {
                ModMenuEntry entry = ModMenuController.modEntries[i];
                if (entry.Type == ModMenuEntryType.GADGET || entry.Type == ModMenuEntryType.UMF || entry.Type == ModMenuEntryType.DISABLED_UMF)
                {
                    try
                    {
                        GadgetInfo        gadgetForConfig = entry.Gadgets.FirstOrDefault(x => x.Attribute.Name == entry.Name);
                        IGadgetConfigMenu configMenu      = gadgetForConfig?.Gadget.GetConfigMenu();
                        if (configMenu != null)
                        {
                            RectTransform menuParent = new GameObject(entry.Name, typeof(RectTransform)).GetComponent <RectTransform>();
                            menuParent.gameObject.SetActive(false);
                            menuParent.SetParent(parent);
                            menuParent.anchorMin = new Vector2(0f, 0f);
                            menuParent.anchorMax = new Vector2(1f, 1f);
                            menuParent.offsetMin = Vector2.zero;
                            menuParent.offsetMax = Vector2.zero;
                            configMenu.Build(menuParent);
                            ConfigMenus.Add((i << 16) + 0xFFFF, Tuple.Create(configMenu, menuParent));
                        }
                        else
                        {
                            ConfigMenus.Add((i << 16) + 0xFFFF, null);
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        if (e.Message == INIGadgetConfigMenu.NO_CONFIGURABLE_DATA)
                        {
                            ConfigMenus.Add((i << 16) + 0xFFFF, null);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    for (int g = 0; g < entry.Gadgets.Length; g++)
                    {
                        GadgetInfo gadget = entry.Gadgets[g];
                        try
                        {
                            IGadgetConfigMenu configMenu = gadget?.Gadget.GetConfigMenu();
                            if (configMenu != null)
                            {
                                RectTransform menuParent = new GameObject(gadget.Attribute.Name, typeof(RectTransform)).GetComponent <RectTransform>();
                                menuParent.gameObject.SetActive(false);
                                menuParent.SetParent(parent);
                                menuParent.anchorMin = new Vector2(0f, 0f);
                                menuParent.anchorMax = new Vector2(1f, 1f);
                                menuParent.offsetMin = Vector2.zero;
                                menuParent.offsetMax = Vector2.zero;
                                configMenu.Build(menuParent);
                                ConfigMenus.Add((i << 16) + g, Tuple.Create(configMenu, menuParent));
                            }
                            else
                            {
                                ConfigMenus.Add((i << 16) + g, null);
                            }
                        }
                        catch (InvalidOperationException e)
                        {
                            if (e.Message == INIGadgetConfigMenu.NO_CONFIGURABLE_DATA)
                            {
                                ConfigMenus.Add((i << 16) + g, null);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }
        }