Browse Source

Add mod only filter toggle and new config option

- bg2 now has a toggle to filter out non mod items.
- MM ini now includes the boolean value "mods_only" which defaults to
false under the "config" section. This will make it so only menu/mod
files in the "Mod" folder will be read
habeebweeb 4 years ago
parent
commit
956963a956

+ 13 - 0
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Config.cs

@@ -87,6 +87,19 @@ namespace CM3D2.MultipleMaids.Plugin
                 }
             }
 
+            IniKey modsOnlyKey = Preferences["config"]["mods_only"];
+            if (modsOnlyKey.Value == "true")
+            {
+                modItemsOnly = true;
+                modItemsToggle = true;
+            }
+            else if (modsOnlyKey.Value != "false")
+            {
+                Preferences["config"]["mods_only"].Value = "false";
+                SaveConfig();
+                modItemsOnly = false;
+            }
+
             if (!int.TryParse(Preferences["config"]["scene_max"].Value, out maxPage))
             {
                 maxPage = 100;

+ 44 - 8
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Gui.cs

@@ -660,9 +660,24 @@ namespace CM3D2.MultipleMaids.Plugin
                 GUI.enabled = false;
             }
 
+            bool previousGUIState = GUI.enabled;
+            GUI.enabled = !modItemsOnly;
+
+            modItemsToggle = GUI.Toggle(new Rect(GetPix(156),
+                GetPix(115),
+                GetPix(50),
+                GetPix(20)),
+                modItemsToggle,
+                "Mods",
+                style3
+            );
+
+            GUI.enabled = previousGUIState;
+
             int iconSize = GetPix(45);
             Rect position1;
             Rect viewRect;
+            int bg2ItemCount = (!modItemsOnly && modItemsToggle) ? numberOfModItems : sortList.Count;
             if (sceneLevel != 5)
             {
                 position1 = new Rect(GetPix(7),
@@ -672,7 +687,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 viewRect = new Rect(0.0f,
                                     0.0f,
                                     position1.width * 0.845f,
-                                    Mathf.Ceil(sortList.Count / 4f) * iconSize + GetPix(10));
+                                    Mathf.Ceil(bg2ItemCount / 4f) * iconSize + GetPix(10));
             }
             else
             {
@@ -683,16 +698,20 @@ namespace CM3D2.MultipleMaids.Plugin
                 viewRect = new Rect(0.0f,
                                     0.0f,
                                     position1.width * 0.845f,
-                                    Mathf.Ceil(sortList.Count / 4f) * iconSize + GetPix(10));
+                                    Mathf.Ceil(bg2ItemCount / 4f) * iconSize + GetPix(10));
             }
 
             bg2ScrollPos = GUI.BeginScrollView(position1, bg2ScrollPos, viewRect);
-            for (int index = 0; index < sortList.Count; ++index)
+            int bg2Index = 0;
+            foreach (SortItem sortItem in sortList)
             {
-                SortItem sortItem = sortList[index];
+                if (modItemsToggle && !sortItem.isMod)
+                {
+                    continue;
+                }
                 Rect position2 = new Rect(
-                    index % 4 * iconSize,
-                    index / 4 * iconSize,
+                    bg2Index % 4 * iconSize,
+                    bg2Index / 4 * iconSize,
                     iconSize,
                     iconSize
                 );
@@ -761,6 +780,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 }
 
                 GUI.DrawTexture(position2, sortItem.tex);
+                bg2Index++;
             }
 
             GUI.EndScrollView();
@@ -1093,6 +1113,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 return;
             }
 
+            numberOfModItems = 0;
             slotIndex = num1;
             sortList.Clear();
             bg2ScrollPos = new Vector2(0.0f, 0.0f);
@@ -1100,7 +1121,15 @@ namespace CM3D2.MultipleMaids.Plugin
             if (itemDataList.Count == 0)
             {
                 #region menu files
-                foreach (string menuFile in GameUty.MenuFiles)
+                HashSet<string> modMenus = null;
+                if (!modItemsOnly)
+                {
+                    modMenus = new HashSet<string>(GameUty.ModOnlysMenuFiles
+                        .Select(file => Path.GetFileName(file).ToLowerInvariant()));
+                }
+
+                string[] menuFiles = modItemsOnly ? GameUty.ModOnlysMenuFiles : GameUty.MenuFiles;
+                foreach (string menuFile in menuFiles)
                 {
                     string fileName = Path.GetFileName(menuFile);
                     byte[] buf;
@@ -1113,7 +1142,11 @@ namespace CM3D2.MultipleMaids.Plugin
                         buf = aFileBase.ReadAll();
                     }
 
-                    ItemData item = new ItemData() { menu = fileName };
+                    ItemData item = new ItemData()
+                    {
+                        menu = fileName,
+                        isMod = modItemsOnly ? true : modMenus.Contains(fileName)
+                    };
                     BinaryReader binaryReader = new BinaryReader(new MemoryStream(buf), Encoding.UTF8);
                     if (binaryReader.ReadString() != "CM3D2_MENU")
                     {
@@ -1190,6 +1223,7 @@ namespace CM3D2.MultipleMaids.Plugin
 
                     ItemData item = new ItemData()
                     {
+                        isMod = true,
                         isOfficialMod = true,
                         menu = modFile,
                         priority = 1000
@@ -1267,6 +1301,7 @@ namespace CM3D2.MultipleMaids.Plugin
                         icon = itemData.icon,
                         menu = itemData.menu,
                         tex = itemData.tex,
+                        isMod = itemData.isMod,
                         isOfficialMod = itemData.isOfficialMod,
                         baseItem = itemData.baseItem
                     });
@@ -1286,6 +1321,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 {
                     if (item.menu != previousMenu)
                     {
+                        if (!modItemsOnly && item.isMod) numberOfModItems++;
                         if (item.tex == null)
                         {
                             byte[] data = ImportCM.LoadTexture(GameUty.FileSystem, item.icon, false).data;

+ 5 - 0
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.cs

@@ -4423,6 +4423,9 @@ namespace CM3D2.MultipleMaids.Plugin
         private readonly MouseDrag5[] mMaid2 = new MouseDrag5[maxMaidCnt];
         private readonly MouseDrag2[] mMaidC = new MouseDrag2[maxMaidCnt];
         private readonly MouseDrag3[] mNeck = new MouseDrag3[maxMaidCnt];
+        private bool modItemsOnly = false;
+        private bool modItemsToggle = false;
+        private int numberOfModItems = 0;
         private float moutha;
         private float mouthc;
         private float mouthdw;
@@ -5644,6 +5647,7 @@ namespace CM3D2.MultipleMaids.Plugin
             public string name = string.Empty;
             public string icon = string.Empty;
             public bool isOfficialMod = false;
+            public bool isMod = false;
             public string baseItem = string.Empty;
             public int priority;
             public Texture2D tex;
@@ -5657,6 +5661,7 @@ namespace CM3D2.MultipleMaids.Plugin
             public string icon = string.Empty;
             public string baseItem = string.Empty;
             public bool isOfficialMod = false;
+            public bool isMod = false;
             public int priority = -1;
             public Texture2D tex = null;