Esempio n. 1
0
        public static void AddCategory(this OptionsMainPanel optionsMainPanel, PluginInfo p)
        {
            try {
                LogCalled();
                if (!p.isEnabled)
                {
                    return;
                }
                if (p?.GetUserModInstance() is not IUserMod userMod)
                {
                    return;
                }

                string     name          = p.name;
                MethodInfo mOnSettingsUI = userMod.GetType().GetMethod("OnSettingsUI", BindingFlags.Instance | BindingFlags.Public);
                if (mOnSettingsUI != null)
                {
                    Log.Info("Adding category :" + name);
                    UIComponent category = optionsMainPanel.m_CategoriesContainer().AttachUIComponent(UITemplateManager.GetAsGameObject("OptionsScrollPanelTemplate"));
                    category.name = userMod.Name;
                    optionsMainPanel.m_Dummies().Add(category);

                    mOnSettingsUI.Invoke(userMod, new object[] { new UIHelper(category.Find("ScrollContent")) });
                    var categories = optionsMainPanel.m_Categories();
                    categories.items = categories.items.AddToArray(name);
                    category.zOrder  = categories.items.Length - 1;
                }
            } catch (Exception ex) {
                Log.Exception(ex);
            }
        }
Esempio n. 2
0
        //static TDelegate CreateDelegate<TDelegate>(object instance, string name) where TDelegate : Delegate {
        //    var method = GetMethod(instance.GetType(), name);
        //    return (TDelegate)Delegate.CreateDelegate(typeof(TDelegate), instance, method);
        //}

        //public static PluginsChangedHandler RefreshPlugins =>
        //    CreateDelegate<PluginsChangedHandler>(optionsMainPanel, "RefreshPlugins");

        //public static PropertyChangedEventHandler<int> OnCategoryChanged =>
        //    CreateDelegate<PropertyChangedEventHandler<int>>(optionsMainPanel, "OnCategoryChanged");


        public static void DropCategory(this OptionsMainPanel optionsMainPanel, string name)
        {
            try {
                LogCalled();
                if (name == null)
                {
                    throw new ArgumentNullException("name");
                }
                var categories = optionsMainPanel.m_Categories();
                int index      = (categories.items as IList <string>).IndexOf(name);
                if (index < 0)
                {
                    return;
                }
                int selectedIndex = categories.selectedIndex;

                Log.Info("Dropping category :" + name);
                var dummies  = optionsMainPanel.m_Dummies();
                var category = dummies.Find(c => c.name == name);
                dummies.Remove(category);
                GameObject.DestroyImmediate(category);
                categories.items = categories.items.RemoveAt(index);

                categories.selectedIndex = selectedIndex;
            } catch (Exception ex) {
                Log.Exception(ex);
            }
        }
Esempio n. 3
0
 static bool Prefix(OptionsMainPanel __instance)
 {
     try {
         if (RemovePluginAtPathPatch.name != null)
         {
             __instance.DropCategory(RemovePluginAtPathPatch.name);
             MonoStatus.Instance?.ModUnloaded();
             return(false);
         }
         else if (LoadPluginAtPathPatch.name != null)
         {
             var p = PluginManager.instance.GetPluginsInfo().FirstOrDefault(
                 item => item.isEnabled && item.name == LoadPluginAtPathPatch.name);
             if (p != null)
             {
                 __instance.AddCategory(p);
             }
             MonoStatus.Instance?.ModLoaded();
             return(false);
         }
         else
         {
             return(true); //proceed as normal.
         }
     } catch (Exception ex) {
         Log.Exception(ex);
         return(true);
     }
 }
        private static void showOptionsPanel(string budgetName)
        {
            UIView.library.ShowModal("OptionsPanel");
            OptionsMainPanel optionsMainPanel = UIView.library.Get <OptionsMainPanel>("OptionsPanel");

            optionsMainPanel.SelectMod(Mod.ModNameEng);
            //Mod.ScrollTo(budgetName);
        }
Esempio n. 5
0
 public static UITabContainer m_CategoriesContainer(this OptionsMainPanel optionsMainPanel) =>
 GetFieldValue(optionsMainPanel, "m_CategoriesContainer") as UITabContainer;
Esempio n. 6
0
 public static UIListBox m_Categories(this OptionsMainPanel optionsMainPanel) =>
 GetFieldValue(optionsMainPanel, "m_Categories") as UIListBox;
Esempio n. 7
0
 public static List <UIComponent> m_Dummies(this OptionsMainPanel optionsMainPanel) =>
 GetFieldValue(optionsMainPanel, "m_Dummies") as List <UIComponent>;