Advertisement
cm3d2-01

CM3D2.AddModsSlider.Plugin.0.1.0.7

Aug 19th, 2015
8,751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 27.46 KB | None | 0 0
  1. // CM3D2.AddModsSlider.Plugin.0.1.0.7 : 各modパラメータをスライダーで操作する UnityInjector 用プラグイン
  2.  
  3. // 必須条件: CM3D2.MaidVoicePitch.Plugin (0.2.2) ( http://pastebin.com/WLrP48bG ) が導入済みである事 
  4. //          CM3D2.ExternalSaveData.Patcher (0.1.0) ( http://pastebin.com/XiZZm2SC ) が導入済みである事 
  5. // 必須ファイル: \CM3D2\UnityInjector\Config\ModsParam.xml
  6. // (サンプル: http://pastebin.com/wiCL6ETM ) modパラメータ定義xml
  7. //
  8. // メイドエディット画面中にF5でUI表示トグル。 ( http://i.imgur.com/sWI5rCG.png )
  9. // 各種modをスライドバー・トグルボタンで調整する事が可能。
  10. //
  11.  
  12. // 更新履歴
  13. // 0.1.0.7 エディット画面で入りなおすと一部mod数値が初期化されるバグ修正2。
  14. // 0.1.0.6 各mod仕様をCM3D2.MaidVoicePitch.Plugin (0.2.2) に準拠。
  15. //     WIDESLIDER必須のmodはWIDESLIDER無効時に自動で無効化する様に。
  16. //     on/off不可のmodにはトグルボタンを表示しないように。
  17. //     拡張セーブ時にアクティブメイド以外が保存できないバグ修正。
  18. //     エディット画面で入りなおすとmod数値が初期化されるバグ修正。
  19. // 0.1.0.5 CM3D2.ExternalSaveData.Patcherの拡張セーブデータに対応。
  20. //     上記に伴い ModsParam.xml の書式変更。
  21. //     ON/OFF系のmodをUIよりトグルボタンで操作可能に。
  22. //     UIをドラッグで動かせる様に。
  23. //         夜伽スライダーを別Pluginに分離。
  24. // 0.0.3.4 夜伽時に興奮・精神・理性を変更できるスライドバーを追加。
  25. //     夜伽時にFaceBlend(頬・涙・よだれの組合せ)とFaceAnime(エロ○○系表情)を選べるボタンを追加。
  26. // 0.0.2.3 フォントサイズがウィンドウ幅と比例する様に。
  27. //     スクロールバーが滑らかに。
  28. //         ModsParam.xmlの<mod>属性 forced="..." が正常に機能していなかったのを修正。
  29. //         リフレクションがフレーム毎に実行されてたのを修正。(軽量化)
  30. // 0.0.2.2 ModsParam.xmlの書式を変更。
  31. //     ModsParam.xmlで<mod>の属性に forced="true" 指定で、フリーコメント欄にかかわらずそのmodのスライダーが表示される様に。
  32. //         <value>の属性でtype="scale"指定の時、最小値をスライダーに反映してなかったのを修正。
  33. // 0.0.1.1 各mod定義をxmlファイルにして読み込む様に。
  34. //         スライダーバーとフリーコメント欄が連動する様に。(改造スレその2>>192)
  35. //         EYEBALL,TEST_EYE_ANGの縦横が逆だったのを修正。
  36. // 0.0.0.0 初版
  37.  
  38. using System;
  39. using System.Collections.Generic;
  40. using System.IO;
  41. using System.Reflection;
  42. using System.Text;
  43. using System.Text.RegularExpressions;
  44. using System.Xml;
  45. using UnityEngine;
  46. using UnityInjector.Attributes;
  47. using CM3D2.ExternalSaveData.Managed;
  48.  
  49. namespace CM3D2.AddModsSlider.Plugin
  50. {
  51.     [PluginFilter("CM3D2x64"),
  52.     PluginFilter("CM3D2x86"),
  53.     PluginFilter("CM3D2VRx64"),
  54.     PluginName("CM3D2 AddModsSlider"),
  55.     PluginVersion("0.1.0.7")]
  56.     public class AddModsSlider : UnityInjector.PluginBase
  57.     {
  58.         public const string Version = "0.1.0.7";
  59.  
  60.         private int sceneLevel;
  61.         private bool visible = false;
  62.         private bool xmlLoad = false;
  63.         private bool oneLoad = false;
  64.         private ModsParam mp;
  65.         private PixelValues pv;
  66.  
  67.         private Maid maid;
  68.         private string freeComment;
  69.         private Rect winRect;
  70.         private Vector2 lastScreenSize;
  71.  
  72.         private float modsSliderWidth = 0.25f;
  73.          private Vector2 scrollViewVector = Vector2.zero;
  74.  
  75.         private class ModsParam
  76.         {
  77.             public readonly string DefMatchPattern = @"([-+]?[0-9]*\.?[0-9]+)";
  78.             public readonly string XmlFileName = Directory.GetCurrentDirectory() + @"\UnityInjector\Config\ModsParam.xml";
  79.            
  80.             // WideSlider有効化が前提のmod
  81.             public List<string> NeedsWideSlider = new List<string> { "FARMFIX", "EYE_RATIO", "EYE_ANG", "PELSCL", "SKTSCL", "THISCL", "THIPOS"
  82.                                                                     ,"SPISCL", "S0ASCL", "S1_SCL", "S1ASCL" };
  83.             // MaidVoicePitch.0.2.2 準拠
  84.             // MaidVoicePitchでBool値でのON/OFFフラグが無いmod
  85.             public List<string> CantDisable     = new List<string> { "EYETOCAM", "HEADTOCAM", "PITCH", "MABATAKI", "FACE_ANIME_SPEED"
  86.                                                                     ,"EYEBALL", "EYE_RATIO", "EYE_ANG", "PELSCL", "THISCL", "THIPOS" } ;
  87.             // MaidVoicePitchでname=keyのvalueをmodの引数として扱ってるmod
  88.             public List<string> IsNotBoolKey    = new List<string> { "EYETOCAM", "HEADTOCAM", "PITCH", "MABATAKI", "FACE_ANIME_SPEED", "EYE_RATIO" } ;
  89.  
  90.             public string XmlFormat;
  91.             public List<string> sKey = new List<string>();
  92.  
  93.             public Dictionary<string, string>   sDescription  = new Dictionary<string, string>();
  94.             public Dictionary<string, bool>     bForced       = new Dictionary<string, bool>();
  95.             public Dictionary<string, bool>     bEnabled      = new Dictionary<string, bool>();
  96.             public Dictionary<string, string>   sType         = new Dictionary<string, string>();
  97.  
  98.             public Dictionary<string, string[]> sPropName     = new Dictionary<string, string[]>();
  99.             public Dictionary<string, Dictionary<string, float>>  fValue        = new Dictionary<string, Dictionary<string, float>>();
  100.             public Dictionary<string, Dictionary<string, float>>  fVmin         = new Dictionary<string, Dictionary<string, float>>();
  101.             public Dictionary<string, Dictionary<string, float>>  fVmax         = new Dictionary<string, Dictionary<string, float>>();
  102.             public Dictionary<string, Dictionary<string, string>> sVType        = new Dictionary<string, Dictionary<string, string>>();
  103.             public Dictionary<string, Dictionary<string, string>> sLabel        = new Dictionary<string, Dictionary<string, string>>();
  104.             public Dictionary<string, Dictionary<string, string>> sMatchPattern = new Dictionary<string, Dictionary<string, string>>();
  105.  
  106.             public int KeyCount { get{return sKey.Count;} }
  107.             public int ValCount(string key) { return sPropName[key].Length; }
  108.  
  109.         //--------
  110.  
  111.             public ModsParam()
  112.             {
  113.                 Init();
  114.             }
  115.  
  116.             public bool Init()
  117.             {
  118.                 if(!loadModsParamXML())
  119.                 {
  120.                     Debug.LogError("AddModsSlider : loadModsParamXML() failed.");
  121.                     return false;
  122.                 }
  123.  
  124.                 return true;
  125.             }
  126.  
  127.  
  128.             private bool loadModsParamXML()
  129.             {
  130.                 if (!File.Exists(XmlFileName))
  131.                 {
  132.                     Debug.LogError("AddModsSlider : \"" + XmlFileName + "\" does not exist.");
  133.                     return false;
  134.                 }
  135.  
  136.                 XmlDocument doc = new XmlDocument();
  137.                 doc.Load(XmlFileName);
  138.  
  139.                  XmlNode mods = doc.DocumentElement;
  140.                  XmlFormat = ((XmlElement)mods).GetAttribute("format");
  141.                 if (XmlFormat != "1.1")
  142.                 {
  143.                     Debug.LogError("AddModsSlider : "+ AddModsSlider.Version +" requires fomart=\"1.1\" of ModsParam.xml.");
  144.                     return false;
  145.                 }
  146.  
  147.                 XmlNodeList modNodeS = mods.SelectNodes("/mods/mod");
  148.                 if (!(modNodeS.Count > 0))
  149.                 {
  150.                     Debug.LogError("AddModsSlider :  \"" + XmlFileName + "\" has no <mod>elements.");
  151.                     return false;
  152.                 }
  153.  
  154.                 sKey.Clear();
  155.  
  156.                 foreach(XmlNode modNode in modNodeS)
  157.                 {    
  158.                     // mod属性
  159.                     string key = ((XmlElement)modNode).GetAttribute("id");
  160.                     if(key != "" && !sKey.Contains(key)) sKey.Add(key);
  161.                     else continue;
  162.  
  163.                     bool f = false;
  164.                     sDescription[key] = ((XmlElement)modNode).GetAttribute("description");
  165.                     bEnabled[key] = (Boolean.TryParse(((XmlElement)modNode).GetAttribute("enabled"), out f)) ? f : true;
  166.                     bForced[key] = (Boolean.TryParse(((XmlElement)modNode).GetAttribute("forced"), out f)) ? f : true;
  167.  
  168.                     sType[key] = ((XmlElement)modNode).GetAttribute("type");
  169.                     if (sType[key] == "") sType[key] = "slider";
  170.                     if (sType[key] == "toggle") continue;
  171.  
  172.                     XmlNodeList valueNodeS = ((XmlElement)modNode).GetElementsByTagName("value");
  173.                     if (!(valueNodeS.Count > 0)) continue;
  174.                    
  175.                     sPropName[key]     = new string[valueNodeS.Count];
  176.                     fValue[key]        = new Dictionary<string, float>();
  177.                     fVmin[key]         = new Dictionary<string, float>();
  178.                     fVmax[key]         = new Dictionary<string, float>();
  179.                     sVType[key]        = new Dictionary<string, string>();
  180.                     sLabel[key]        = new Dictionary<string, string>();
  181.                     sMatchPattern[key] = new Dictionary<string, string>();
  182.                    
  183.                     // value属性
  184.                     int j = 0;
  185.                     foreach (XmlNode valueNode in valueNodeS)
  186.                     {
  187.                         float x = 0f;
  188.                        
  189.                         string prop = ((XmlElement)valueNode).GetAttribute("prop_name");
  190.                         if (prop != "" && Array.IndexOf(sPropName[key], prop) < 0 ) sPropName[key][j] = prop;
  191.                         else
  192.                         {    
  193.                             sKey.Remove(key);
  194.                             break;
  195.                         }
  196.                        
  197.                         fVmin[key][prop] = Single.TryParse(((XmlElement)valueNode).GetAttribute("min"), out x) ? x : 0f;
  198.                         fVmax[key][prop] = Single.TryParse(((XmlElement)valueNode).GetAttribute("max"), out x) ? x : 0f;
  199.  
  200.                         sVType[key][prop] = ((XmlElement)valueNode).GetAttribute("type");
  201.                         switch (sVType[key][prop])
  202.                         {
  203.                             case "num":   break;
  204.                             case "scale": break;
  205.                             case "int" : break;
  206.                             default : sVType[key][prop] = "num"; break;
  207.                         }
  208.  
  209.                         sLabel[key][prop] = ((XmlElement)valueNode).GetAttribute("label");
  210.                         sMatchPattern[key][prop] = ((XmlElement)valueNode).GetAttribute("match_pattern");
  211.  
  212.                         j++;
  213.                     }
  214.                     if (j == 0) sKey.Remove(key);
  215.                 }
  216.                
  217.                 return true;
  218.             }
  219.  
  220.  
  221.         }
  222.  
  223.         private class PixelValues
  224.         {
  225.             public float BaseWidth = 1280f;
  226.             public float PropRatio = 0.6f;
  227.             public int Margin;
  228.  
  229.             private Dictionary<string, int> font = new Dictionary<string, int>();
  230.             private Dictionary<string, int> line = new Dictionary<string, int>();
  231.             private Dictionary<string, int> sys =  new Dictionary<string, int>();
  232.  
  233.             public PixelValues()
  234.             {
  235.                 Margin = PropPx(10);
  236.  
  237.                 font["C1"] = 11;
  238.                  font["C2"] = 12;
  239.                 font["H1"] = 14;
  240.                 font["H2"] = 16;
  241.                 font["H3"] = 20;
  242.  
  243.                 line["C1"] = 14;
  244.                 line["C2"] = 18;
  245.                 line["H1"] = 22;
  246.                 line["H2"] = 24;
  247.                 line["H3"] = 30;
  248.  
  249.                 sys["Menu.Height"] = 45;
  250.                 sys["OkButton.Height"] = 95;
  251.  
  252.                 sys["HScrollBar.Width"] = 15;
  253.             }
  254.            
  255.             public int Font(string key) { return PropPx(font[key]); }
  256.             public int Line(string key) { return PropPx(line[key]); }
  257.             public int Sys(string key)  { return PropPx(sys[key]); }
  258.  
  259.             public int Font_(string key) { return font[key]; }
  260.             public int Line_(string key) { return line[key]; }
  261.             public int Sys_(string key)  { return sys[key]; }
  262.  
  263.             public Rect PropScreen(float left, float top, float width, float height)
  264.             {
  265.                 return new Rect((int)((Screen.width - Margin * 2) * left + Margin)
  266.                                ,(int)((Screen.height - Margin * 2) * top + Margin)
  267.                                ,(int)((Screen.width - Margin * 2) * width)
  268.                                ,(int)((Screen.height - Margin * 2) * height));
  269.             }
  270.  
  271.             public Rect PropScreenMH(float left, float top, float width, float height)
  272.             {
  273.                 Rect r = PropScreen(left, top, width, height);
  274.                 r.y += Sys("Menu.Height");
  275.                 r.height -= (Sys("Menu.Height") + Sys("OkButton.Height"));
  276.                
  277.                 return r;
  278.             }
  279.  
  280.             public Rect PropScreenMH(float left, float top, float width, float height, Vector2 last)
  281.             {
  282.                 Rect r = PropScreen((float)(left/(last.x - Margin * 2)), (float)(top/(last.y - Margin * 2)), width, height);
  283.                 r.height -= (Sys("Menu.Height") + Sys("OkButton.Height"));
  284.                
  285.                 return r;
  286.             }
  287.  
  288.             public Rect InsideRect(Rect rect)
  289.             {
  290.                 return new Rect(Margin, Margin, rect.width - Margin * 2, rect.height - Margin * 2);
  291.             }
  292.  
  293.             public Rect InsideRect(Rect rect, int height)
  294.             {
  295.                 return new Rect(Margin, Margin, rect.width - Margin * 2, height);
  296.             }
  297.  
  298.             public int PropPx(int px)
  299.             {
  300.                 return (int)(px * (1f + (Screen.width/BaseWidth - 1f) * PropRatio));
  301.             }
  302.         }
  303.        
  304.     //--------
  305.  
  306.         public void Awake()
  307.         {
  308.             mp = new ModsParam();
  309.             pv = new PixelValues();
  310.             lastScreenSize = new Vector2(Screen.width, Screen.height);
  311.         }
  312.  
  313.         public void OnLevelWasLoaded(int level)
  314.         {
  315.             sceneLevel = level;
  316.  
  317.             if (sceneLevel == 9)
  318.             {
  319.                
  320.             }
  321.             else if (sceneLevel == 5)
  322.             {
  323.                 xmlLoad = mp.Init();
  324.                 oneLoad = false;
  325.                 winRect = pv.PropScreenMH(1f - modsSliderWidth, 0f, modsSliderWidth, 1f);
  326.             }
  327.         }
  328.  
  329.         public void Update()
  330.         {
  331.             if (sceneLevel == 9)
  332.             {
  333.             }
  334.             else if (sceneLevel == 5 && xmlLoad)
  335.             {
  336.                 if (Input.GetKeyDown(KeyCode.F5)) visible = !visible;
  337.             }
  338.             else
  339.             {
  340.                 if(visible) visible = false;
  341.             }
  342.         }
  343.  
  344.         public void OnGUI()
  345.         {
  346.             if (!visible) return;
  347.            
  348.             GUIStyle winStyle = "box";
  349.             winStyle.fontSize = pv.Font("C1");
  350.             winStyle.alignment = TextAnchor.UpperRight;
  351.  
  352.             if (sceneLevel == 9)
  353.             {
  354.  
  355.             }
  356.             else if (sceneLevel == 5 && xmlLoad)
  357.             {
  358.                 freeComment = null;
  359.                 maid =  GameMain.Instance.CharacterMgr.GetMaid(0);
  360.                 if (maid == null) return;
  361.  
  362.                 if (maid.Param != null && maid.Param.status != null && maid.Param.status.free_comment != null)
  363.                 {
  364.                     freeComment = maid.Param.status.free_comment;
  365.                 }
  366.  
  367.                 if(freeComment != null && Input.GetKey(KeyCode.F4)) {
  368.                     checkFreeComment();
  369.                 }
  370.  
  371.                 if (GUI.changed || !oneLoad) getExSaveData();
  372.                    
  373.                 if (lastScreenSize != new Vector2(Screen.width, Screen.height))
  374.                 {
  375.                     winRect = pv.PropScreenMH(winRect.x, winRect.y, modsSliderWidth, 1f, lastScreenSize);
  376.                     lastScreenSize = new Vector2(Screen.width, Screen.height);
  377.                 }
  378.                 winRect = GUI.Window(0, winRect, addModsSlider, AddModsSlider.Version, winStyle);
  379.                 oneLoad = true;
  380.             }
  381.          }
  382.  
  383.     //--------
  384.  
  385.  
  386.         private void addModsSlider(int winID)
  387.          {
  388.             int mod_num = mp.KeyCount;
  389.             Rect baseRect = pv.InsideRect(this.winRect);
  390.             Rect headerRect = new Rect(baseRect.x, baseRect.y, baseRect.width, pv.Line("H3"));
  391.             Rect scrollRect = new Rect(baseRect.x, baseRect.y + headerRect.height + pv.Margin
  392.                                       ,baseRect.width + pv.PropPx(5), baseRect.height - headerRect.height - pv.Margin);
  393.             Rect conRect = new Rect(0, 0 ,scrollRect.width - pv.Sys_("HScrollBar.Width") - pv.Margin , 0);
  394.             Rect outRect = new Rect();
  395.             GUIStyle lStyle = "label";
  396.             GUIStyle tStyle = "toggle";
  397.             Color color = new Color(1f, 1f, 1f, 0.98f);
  398.  
  399.             for (int i=0; i<mod_num; i++)
  400.             {
  401.                 string key = mp.sKey[i];
  402.  
  403.                 if (mp.CantDisable.Contains(key)) mp.bEnabled[key] = true;
  404.                 if (checkWS(key)) mp.bEnabled[key] = false;
  405.  
  406.                 conRect.height += pv.Line("H1");
  407.                 if(mp.sType[key] != "toggle" && mp.bEnabled[key])
  408.                 {
  409.                     for (int j=0; j<mp.ValCount(key); j++) conRect.height += pv.Line("H1");
  410.                     conRect.height += pv.Margin * 2;
  411.                 }
  412.                 else conRect.height += pv.Margin;
  413.             }
  414.  
  415.             lStyle.normal.textColor = color;
  416.             tStyle.normal.textColor = color;
  417.             lStyle.fontSize = pv.Font("H3");
  418.             drawWinHeader(headerRect, "Mods Slider", lStyle);
  419.  
  420.             // スクロールビュー
  421.             scrollViewVector = GUI.BeginScrollView(scrollRect, scrollViewVector, conRect);
  422.  
  423.             // 各modスライダー
  424.             outRect.Set(0, 0, conRect.width, 0);
  425.             for (int i=0; i<mod_num; i++)
  426.             {
  427.                 string key = mp.sKey[i];
  428.  
  429.                 //----
  430.                 outRect.width = conRect.width;
  431.                 outRect.height  = pv.Line("H1");
  432.                 color = (mp.bEnabled[key]) ? new Vector4(1f, 1f, 1f, 0.98f) : new Vector4(0.8f, 0.8f, 0.8f, 0.8f);
  433.                 lStyle.normal.textColor = color;
  434.                 tStyle.normal.textColor = color;
  435.                
  436.                 if (mp.CantDisable.Contains(key) || checkWS(key))  // ON/OFFフラグの無いmodとWIDESLIDER無効化状態でのWS必須modはトグル非表示
  437.                 {
  438.                     string s = mp.sDescription[key]+" ("+key+")";
  439.                     lStyle.fontSize = pv.Font("H1");
  440.                     if (checkWS(key))
  441.                     {
  442.                         s = "WIDESLIDER必須:" + s;
  443.                         lStyle.normal.textColor = new Vector4(0.8f, 0.1f, 0.1f, 0.9f);
  444.  
  445.                     }
  446.                     GUI.Label(outRect, s, lStyle);
  447.                 }
  448.                 else
  449.                 {
  450.                     tStyle.fontSize = pv.Font("H1");
  451.                     mp.bEnabled[key] = GUI.Toggle(outRect, mp.bEnabled[key], mp.sDescription[key]+" ("+key+")", tStyle);
  452.                 }
  453.                 outRect.y += outRect.height;
  454.  
  455.                 if (mp.sType[key] == "toggle" || !mp.bEnabled[key])
  456.                 {
  457.                     outRect.y += pv.Margin;
  458.                     continue;
  459.                 }
  460.                 //----
  461.  
  462.                 int val_num = mp.ValCount(key);
  463.                 for (int j=0; j<val_num; j++)
  464.                 {
  465.                     string prop = mp.sPropName[key][j];
  466.                    
  467.                     float value = mp.fValue[key][prop];
  468.                     float vmin = mp.fVmin[key][prop];
  469.                     float vmax = mp.fVmax[key][prop];
  470.                     string label = mp.sLabel[key][prop] +" : "+ value.ToString("F");
  471.                     string vType = mp.sVType[key][prop];
  472.  
  473.                     outRect.width = conRect.width;
  474.                     outRect.height  = pv.Line("H1");
  475.                     lStyle.fontSize = pv.Font("H1");
  476.                     if (value < vmin) value = vmin;
  477.                     if (value > vmax) value = vmax;
  478.                     if (vType == "scale" && vmin < 1f)
  479.                     {
  480.                         if (vmin < 0f) vmin = 0f;
  481.                         if (value < 0f) value = 0f;
  482.  
  483.                         float tmpmin = -Mathf.Abs(vmax - 1f);
  484.                         float tmpmax = Mathf.Abs(vmax - 1f);
  485.                         float tmp = (value < 1f) ? tmp = Mathf.Abs((1f-value)/(1f-vmin)) * tmpmin : value - 1f;
  486.  
  487.                         if(tmp < tmpmin) tmp = tmpmin;
  488.                         if(tmp > tmpmax) tmp = tmpmax;
  489.  
  490.                         tmp = drawModValueSlider(outRect, tmp, tmpmin, tmpmax, label, lStyle);
  491.  
  492.                         mp.fValue[key][prop] = (tmp < 0f) ? 1f - tmp/tmpmin * Mathf.Abs(1f-vmin) : 1f + tmp;
  493.                     }
  494.                     else if (vType == "int")
  495.                     {
  496.                         value = (int)Mathf.Round(value);
  497.                         mp.fValue[key][prop] = (int)Mathf.Round(drawModValueSlider(outRect, value, vmin, vmax, label, lStyle));
  498.                     }
  499.                     else mp.fValue[key][prop] = drawModValueSlider(outRect, value, vmin, vmax, label, lStyle);
  500.  
  501.                     outRect.y += outRect.height;
  502.                 }
  503.  
  504.                 outRect.y += pv.Margin * 2;
  505.             }
  506.  
  507.             GUI.EndScrollView();
  508.             GUI.DragWindow();
  509.            
  510.             if (GUI.changed || !oneLoad) setExSaveData();
  511.         }
  512.  
  513.         private void drawWinHeader(Rect rect, string s, GUIStyle style)
  514.         {
  515.             GUI.Label(rect, s, style);
  516.             {
  517.                 ;
  518.             }
  519.         }
  520.  
  521.         private float drawModValueSlider(Rect outRect, float value, float min, float max, string label, GUIStyle lstyle)
  522.         {
  523.             float conWidth = outRect.width;
  524.            
  525.             outRect.width = conWidth * 0.3f;
  526.             GUI.Label(outRect, label, lstyle);
  527.             outRect.x += outRect.width;
  528.            
  529.             outRect.width = conWidth * 0.7f;
  530.             outRect.y += pv.PropPx(5);
  531.             return GUI.HorizontalSlider(outRect, value, min, max);
  532.         }
  533.  
  534.     //--------
  535.  
  536.         private void checkFreeComment()
  537.         {
  538.             for(int i=0; i<mp.KeyCount; i++)
  539.             {
  540.                 string key = mp.sKey[i];
  541.            
  542.                 Match match = Regex.Match(freeComment, getMatchPattern(key));
  543.                
  544.                 if (mp.sType[key] == "toggle")
  545.                 {
  546.                      mp.bEnabled[key] = (match.Groups.Count > 1) ? true : false;
  547.                 }
  548.                 else if (match.Groups.Count > mp.ValCount(key))
  549.                 {
  550.                     int val_num = mp.ValCount(key);
  551.                     bool tpf = true;
  552.  
  553.                     for(int j=0; j<val_num; j++)
  554.                     {
  555.                         float f = 0f;
  556.                         string prop = mp.sPropName[key][j];
  557.                    
  558.                         mp.bEnabled[key] = true;
  559.                         tpf &= Single.TryParse(match.Groups[j + 1].Value, out f);
  560.                         if(tpf) mp.fValue[key][prop] = f;
  561.  
  562.                     }
  563.                     if(!tpf) mp.bEnabled[key] = false;
  564.                 }
  565.                 else mp.bEnabled[key] = false;
  566.             }
  567.         }
  568.  
  569.         private string getMatchPattern(string key)
  570.         {
  571.             if (mp.sType[key] == "toggle") return "#("+ key + ")#";
  572.              
  573.             string s = "#" + key;
  574.             int val_num = mp.ValCount(key);
  575.            
  576.             for(int j=0; j<val_num; j++)
  577.             {
  578.                 string prop = mp.sPropName[key][j];
  579.                 s += (j==0) ? "=" : ",";
  580.                
  581.                 if(mp.sMatchPattern[key][prop] == "")
  582.                 {
  583.                     s += mp.DefMatchPattern;
  584.                 }
  585.                 else
  586.                 {
  587.                     s += mp.sMatchPattern[key][prop];
  588.                 }                
  589.             }
  590.             s += "#";
  591.            
  592.             return s;
  593.         }
  594.  
  595.         private bool checkWS(string key)
  596.         {
  597.             return mp.sKey.Contains("WIDESLIDER") && !mp.bEnabled["WIDESLIDER"] && mp.NeedsWideSlider.Contains(key);
  598.         }
  599.  
  600.     //--------
  601.  
  602.         private void getExSaveData()
  603.         {
  604.             for (int i=0; i<mp.KeyCount; i++)
  605.             {
  606.                 string key = mp.sKey[i];
  607.  
  608.                 if (mp.IsNotBoolKey.Contains(key)) // name=keyにBool以外数値が入ってるmod用
  609.                 {
  610.                     float f = ExSaveData.GetFloat(maid, "CM3D2.MaidVoicePitch", key, float.NaN);
  611.                     if (float.IsNaN(f)) f = 0f;
  612.  
  613.                     mp.fValue[key][key + ".value"] = f;
  614.                 }
  615.                 else
  616.                 {
  617.                     mp.bEnabled[key] = ExSaveData.GetBool(maid, "CM3D2.MaidVoicePitch", key, false);
  618.  
  619.                     if (mp.sType[key] != "toggle")
  620.                     {
  621.                         for (int j=0; j<mp.ValCount(key); j++)
  622.                         {
  623.                             string prop = mp.sPropName[key][j];
  624.    
  625.                             float f = ExSaveData.GetFloat(maid, "CM3D2.MaidVoicePitch", mp.sPropName[key][j], float.NaN);
  626.                             if (!float.IsNaN(f)) mp.fValue[key][prop] = f;
  627.                             else                 mp.fValue[key][prop] = 0f;
  628.                         }
  629.                     }
  630.                 }
  631.             }
  632.             // WideSlider前提modのWideSlider無効時スライダー無効化
  633.             for (int i=0; i<mp.KeyCount; i++) if (checkWS(mp.sKey[i])) mp.bEnabled[mp.sKey[i]] = false;
  634.         }
  635.  
  636.         private void setExSaveData()
  637.         {
  638.             for (int i=0; i<mp.KeyCount; i++)
  639.             {
  640.                 string key = mp.sKey[i];
  641.                
  642.                 if (mp.IsNotBoolKey.Contains(key)) // name=keyにBool以外の数値が入ってるmod用
  643.                 {
  644.                     ExSaveData.SetFloat(maid, "CM3D2.MaidVoicePitch", key, mp.fValue[key][key + ".value"]);
  645.                 }
  646.                 else
  647.                 {
  648.                     // ON/OFFフラグの無いmodは name=key value=bool を書き出さない
  649.                     if (!mp.CantDisable.Contains(key)) ExSaveData.SetBool(maid, "CM3D2.MaidVoicePitch", key, mp.bEnabled[key]);
  650.                    
  651.                     if (mp.sType[key] != "toggle")
  652.                     {
  653.                         for (int j=0; j<mp.ValCount(key); j++)
  654.                         {
  655.                             string prop = mp.sPropName[key][j];
  656.                             ExSaveData.SetFloat(maid, "CM3D2.MaidVoicePitch", prop, mp.fValue[key][prop]);
  657.                         }
  658.                     }
  659.                 }
  660.             }
  661.         }
  662.  
  663.     //--------
  664.    
  665.     }
  666. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement