ColorPaletteManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. using System;
  2. using System.Collections.Generic;
  3. using MaidStatus;
  4. using UnityEngine;
  5. using wf;
  6. public class ColorPaletteManager : EmptyWindow
  7. {
  8. private EyePartsTab selectEyeType
  9. {
  10. get
  11. {
  12. return this.maid.status.eyePartsTab;
  13. }
  14. set
  15. {
  16. this.maid.status.eyePartsTab = value;
  17. }
  18. }
  19. public override void Awake()
  20. {
  21. base.Awake();
  22. this.init_pos_ = this.resetWindowPos;
  23. this.uiManager.onChangeValue = new Action<ColorPaletteUIManager>(this.OnChangeUIValue);
  24. this.categoryTabPanel.Start();
  25. UIWFTabButton[] componentsInChildren = this.categoryTabPanel.GetComponentsInChildren<UIWFTabButton>(false);
  26. foreach (UIWFTabButton uiwftabButton in componentsInChildren)
  27. {
  28. EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnSelectCategory));
  29. }
  30. this.eyeTypeTabPanel.Start();
  31. componentsInChildren = this.eyeTypeTabPanel.GetComponentsInChildren<UIWFTabButton>(false);
  32. foreach (UIWFTabButton uiwftabButton2 in componentsInChildren)
  33. {
  34. EventDelegate.Add(uiwftabButton2.onSelect, new EventDelegate.Callback(this.OnSelectEyeType));
  35. }
  36. if (this.colorPresetGrid != null)
  37. {
  38. for (int k = 0; k < this.colorPresetNum; k++)
  39. {
  40. GameObject gameObject = Utility.CreatePrefab(this.colorPresetGrid.gameObject, "SceneEdit\\ColorPalette\\Prefabs\\ColorPresetItem", true);
  41. ColorPresetItem component = gameObject.GetComponent<ColorPresetItem>();
  42. component.slotNo = k;
  43. component.onSaveColorPresetEvent = new Func<ColorPaletteManager.ColorData>(this.OnSaveColorPreset);
  44. component.onLoadColorPresetEvent = new Action<Dictionary<string, int>>(this.OnLoadColorPreset);
  45. }
  46. Utility.ResetNGUI(this.colorPresetGrid);
  47. }
  48. this.UpdateChildren();
  49. this.baseDraw = false;
  50. }
  51. public void Call(int maidNo, MaidParts.PARTS_COLOR colorType)
  52. {
  53. base.gameObject.SetActive(true);
  54. this.visible = true;
  55. this.maid = GameMain.Instance.CharacterMgr.GetMaid(maidNo);
  56. this.category = ColorPaletteManager.Category.Main;
  57. this.colorData = ColorPaletteManager.ColorData.Create(this.maid, colorType);
  58. UIWFTabButton[] componentsInChildren = this.categoryTabPanel.GetComponentsInChildren<UIWFTabButton>(true);
  59. componentsInChildren[2].gameObject.SetActive(this.colorData.enabledOutLine);
  60. if (this.colorData.enabledOutLine)
  61. {
  62. componentsInChildren[0].pixelSnap = true;
  63. componentsInChildren[0].normalSprite = "colorpalette_tab_s_basecolor";
  64. componentsInChildren[1].pixelSnap = true;
  65. componentsInChildren[1].normalSprite = "colorpalette_tab_s_shadowcolor";
  66. }
  67. else
  68. {
  69. componentsInChildren[0].pixelSnap = true;
  70. componentsInChildren[0].normalSprite = "colorpalette_tab_basecolor";
  71. componentsInChildren[1].pixelSnap = true;
  72. componentsInChildren[1].normalSprite = "colorpalette_tab_shadowcolor";
  73. }
  74. Vector3 localPosition = componentsInChildren[1].transform.localPosition;
  75. Vector3 localPosition2 = new Vector3(componentsInChildren[0].transform.localPosition.x + (float)componentsInChildren[0].GetComponent<UIWidget>().width, localPosition.y, localPosition.z);
  76. componentsInChildren[1].transform.localPosition = localPosition2;
  77. componentsInChildren = this.eyeTypeTabPanel.GetComponentsInChildren<UIWFTabButton>(true);
  78. foreach (UIWFTabButton uiwftabButton in componentsInChildren)
  79. {
  80. uiwftabButton.gameObject.SetActive(colorType == MaidParts.PARTS_COLOR.EYE_L || colorType == MaidParts.PARTS_COLOR.EYE_R);
  81. }
  82. if ((colorType == MaidParts.PARTS_COLOR.EYE_L || colorType == MaidParts.PARTS_COLOR.EYE_R) && this.selectEyeType == EyePartsTab.LR)
  83. {
  84. ColorPaletteManager.ColorData obj;
  85. if (colorType == MaidParts.PARTS_COLOR.EYE_L)
  86. {
  87. obj = ColorPaletteManager.ColorData.Create(this.maid, MaidParts.PARTS_COLOR.EYE_R);
  88. }
  89. else
  90. {
  91. obj = ColorPaletteManager.ColorData.Create(this.maid, MaidParts.PARTS_COLOR.EYE_L);
  92. }
  93. if (!this.colorData.EqualsData(obj))
  94. {
  95. this.maid.status.eyePartsTab = EyePartsTab.R;
  96. }
  97. }
  98. if (colorType == MaidParts.PARTS_COLOR.EYE_L || colorType == MaidParts.PARTS_COLOR.EYE_R)
  99. {
  100. this.SetEyeSelect(this.selectEyeType);
  101. }
  102. else
  103. {
  104. this.SetCategory(this.category);
  105. }
  106. }
  107. public void Close()
  108. {
  109. this.visible = false;
  110. base.gameObject.SetActive(false);
  111. }
  112. public void ResetUIPos()
  113. {
  114. this.ResetPosition();
  115. }
  116. public void SetCategory(ColorPaletteManager.Category category)
  117. {
  118. UIWFTabButton[] componentsInChildren = this.categoryTabPanel.GetComponentsInChildren<UIWFTabButton>(false);
  119. if (category == ColorPaletteManager.Category.OutLine && componentsInChildren.Length < 3)
  120. {
  121. category = (this.category = ColorPaletteManager.Category.Main);
  122. }
  123. this.categoryTabPanel.Select(componentsInChildren[(int)category]);
  124. }
  125. public void SetEyeSelect(EyePartsTab eyeType)
  126. {
  127. UIWFTabButton[] componentsInChildren = this.eyeTypeTabPanel.GetComponentsInChildren<UIWFTabButton>(false);
  128. this.eyeTypeTabPanel.Select(componentsInChildren[this.PartsTypeToIndex(eyeType)]);
  129. }
  130. private void UpdateUI()
  131. {
  132. ColorPaletteManager.ColorData.CommonItem commonItem;
  133. if (this.category == ColorPaletteManager.Category.Main)
  134. {
  135. commonItem = this.colorData.main;
  136. }
  137. else if (this.category == ColorPaletteManager.Category.Shadow)
  138. {
  139. commonItem = this.colorData.shadow;
  140. }
  141. else
  142. {
  143. commonItem = this.colorData.outline;
  144. }
  145. this.uiManager.visibleShadowRate = (this.category == ColorPaletteManager.Category.Main || this.category == ColorPaletteManager.Category.Shadow);
  146. int shadowRate = (!this.uiManager.visibleShadowRate) ? 0 : this.colorData.shadowRate;
  147. this.uiManager.hue = commonItem.hue;
  148. this.uiManager.chroma = commonItem.chroma;
  149. this.uiManager.brightness = commonItem.brightness;
  150. this.uiManager.contrast = commonItem.contrast;
  151. this.uiManager.shadowRate = shadowRate;
  152. }
  153. private void OnChangeUIValue(ColorPaletteUIManager mgr)
  154. {
  155. if (this.maid == null)
  156. {
  157. return;
  158. }
  159. if (this.category == ColorPaletteManager.Category.Main)
  160. {
  161. this.colorData.main.hue = this.uiManager.hue;
  162. this.colorData.main.chroma = this.uiManager.chroma;
  163. this.colorData.main.brightness = this.uiManager.brightness;
  164. this.colorData.main.contrast = this.uiManager.contrast;
  165. this.colorData.shadowRate = this.uiManager.shadowRate;
  166. }
  167. else if (this.category == ColorPaletteManager.Category.Shadow)
  168. {
  169. this.colorData.shadow.hue = this.uiManager.hue;
  170. this.colorData.shadow.chroma = this.uiManager.chroma;
  171. this.colorData.shadow.brightness = this.uiManager.brightness;
  172. this.colorData.shadow.contrast = this.uiManager.contrast;
  173. this.colorData.shadowRate = this.uiManager.shadowRate;
  174. }
  175. else if (this.category == ColorPaletteManager.Category.OutLine)
  176. {
  177. this.colorData.outline.hue = this.uiManager.hue;
  178. this.colorData.outline.chroma = this.uiManager.chroma;
  179. this.colorData.outline.brightness = this.uiManager.brightness;
  180. this.colorData.outline.contrast = this.uiManager.contrast;
  181. }
  182. ColorPaletteManager.ColorData.Apply(this.maid, this.colorData);
  183. if ((this.colorData.colorType == MaidParts.PARTS_COLOR.EYE_L || this.colorData.colorType == MaidParts.PARTS_COLOR.EYE_R) && this.selectEyeType == EyePartsTab.LR)
  184. {
  185. ColorPaletteManager.ColorData data = ColorPaletteManager.ColorData.Create(this.maid, MaidParts.PARTS_COLOR.EYE_L);
  186. data.colorType = MaidParts.PARTS_COLOR.EYE_R;
  187. ColorPaletteManager.ColorData.Apply(this.maid, data);
  188. }
  189. }
  190. private void OnSelectCategory()
  191. {
  192. if (!UIWFSelectButton.selected)
  193. {
  194. return;
  195. }
  196. UIWFTabButton[] componentsInChildren = this.categoryTabPanel.GetComponentsInChildren<UIWFTabButton>(true);
  197. ColorPaletteManager.Category category = ColorPaletteManager.Category.Main;
  198. for (int i = 0; i < componentsInChildren.Length; i++)
  199. {
  200. if (componentsInChildren[i] == UIWFSelectButton.current)
  201. {
  202. category = (ColorPaletteManager.Category)i;
  203. break;
  204. }
  205. }
  206. this.category = category;
  207. this.UpdateUI();
  208. }
  209. private void OnSelectEyeType()
  210. {
  211. if (!UIWFSelectButton.selected)
  212. {
  213. return;
  214. }
  215. UIWFTabButton[] componentsInChildren = this.eyeTypeTabPanel.GetComponentsInChildren<UIWFTabButton>(true);
  216. int index = 0;
  217. for (int i = 0; i < componentsInChildren.Length; i++)
  218. {
  219. if (componentsInChildren[i] == UIWFSelectButton.current)
  220. {
  221. index = i;
  222. break;
  223. }
  224. }
  225. this.selectEyeType = this.IndexToEyePartsType(index);
  226. if (this.selectEyeType == EyePartsTab.LR)
  227. {
  228. ColorPaletteManager.ColorData data = ColorPaletteManager.ColorData.Create(this.maid, MaidParts.PARTS_COLOR.EYE_L);
  229. data.colorType = MaidParts.PARTS_COLOR.EYE_R;
  230. ColorPaletteManager.ColorData.Apply(this.maid, data);
  231. }
  232. MaidParts.PARTS_COLOR colorType = MaidParts.PARTS_COLOR.EYE_L;
  233. if (this.selectEyeType == EyePartsTab.R)
  234. {
  235. colorType = MaidParts.PARTS_COLOR.EYE_R;
  236. }
  237. this.colorData = ColorPaletteManager.ColorData.Create(this.maid, colorType);
  238. this.SetCategory(this.category);
  239. }
  240. private EyePartsTab IndexToEyePartsType(int index)
  241. {
  242. return (index != 0) ? ((index != 1) ? EyePartsTab.LR : EyePartsTab.R) : EyePartsTab.L;
  243. }
  244. private int PartsTypeToIndex(EyePartsTab tab)
  245. {
  246. return (tab != EyePartsTab.L) ? ((tab != EyePartsTab.R) ? 2 : 1) : 0;
  247. }
  248. private ColorPaletteManager.ColorData OnSaveColorPreset()
  249. {
  250. return this.colorData;
  251. }
  252. private void OnLoadColorPreset(Dictionary<string, int> data)
  253. {
  254. this.colorData = ColorPaletteManager.ColorData.RestoreData(this.colorData.colorType, data);
  255. ColorPaletteManager.ColorData.Apply(this.maid, this.colorData);
  256. if (this.colorData.colorType == MaidParts.PARTS_COLOR.EYE_L || this.colorData.colorType == MaidParts.PARTS_COLOR.EYE_R)
  257. {
  258. this.SetEyeSelect(this.selectEyeType);
  259. }
  260. else
  261. {
  262. this.SetCategory(this.category);
  263. }
  264. }
  265. [SerializeField]
  266. private ColorPaletteUIManager uiManager;
  267. [SerializeField]
  268. private UIWFTabPanel categoryTabPanel;
  269. [SerializeField]
  270. private UIWFTabPanel eyeTypeTabPanel;
  271. [SerializeField]
  272. private UIGrid colorPresetGrid;
  273. [SerializeField]
  274. private int colorPresetNum;
  275. [SerializeField]
  276. private Vector3 resetWindowPos;
  277. private ColorPaletteManager.Category category;
  278. private Maid maid;
  279. private ColorPaletteManager.ColorData colorData;
  280. public enum Category
  281. {
  282. Main,
  283. Shadow,
  284. OutLine
  285. }
  286. public struct ColorData
  287. {
  288. public bool EqualsData(ColorPaletteManager.ColorData obj)
  289. {
  290. return this.enabledOutLine == obj.enabledOutLine && this.shadowRate == obj.shadowRate && this.shadowRate == obj.shadowRate && this.main.Equals(obj.main) && this.shadow.Equals(obj.shadow) && this.outline.Equals(obj.outline);
  291. }
  292. public Dictionary<string, int> GetStoreData()
  293. {
  294. Dictionary<string, int> result = new Dictionary<string, int>();
  295. Action<string, ColorPaletteManager.ColorData.CommonItem> action = delegate(string connectName, ColorPaletteManager.ColorData.CommonItem writeData)
  296. {
  297. result.Add(connectName + "_hue", writeData.hue);
  298. result.Add(connectName + "_chroma", writeData.chroma);
  299. result.Add(connectName + "_brightness", writeData.brightness);
  300. result.Add(connectName + "_contrast", writeData.contrast);
  301. };
  302. action("main", this.main);
  303. action("shadow", this.shadow);
  304. result.Add("shadowRate", this.shadowRate);
  305. result.Add("existOutLineData", (!this.enabledOutLine) ? 0 : 1);
  306. if (this.enabledOutLine)
  307. {
  308. action("outline", this.outline);
  309. }
  310. return result;
  311. }
  312. public static ColorPaletteManager.ColorData RestoreData(MaidParts.PARTS_COLOR colorType, Dictionary<string, int> storeData)
  313. {
  314. ColorPaletteManager.ColorData result = default(ColorPaletteManager.ColorData);
  315. result.colorType = colorType;
  316. result.enabledOutLine = (colorType == MaidParts.PARTS_COLOR.HAIR || colorType == MaidParts.PARTS_COLOR.SKIN);
  317. Func<string, ColorPaletteManager.ColorData.CommonItem> func = (string connectName) => new ColorPaletteManager.ColorData.CommonItem
  318. {
  319. hue = storeData[connectName + "_hue"],
  320. chroma = storeData[connectName + "_chroma"],
  321. brightness = storeData[connectName + "_brightness"],
  322. contrast = storeData[connectName + "_contrast"]
  323. };
  324. result.main = func("main");
  325. result.shadow = func("shadow");
  326. result.shadowRate = storeData["shadowRate"];
  327. if (result.enabledOutLine && storeData["existOutLineData"] == 1)
  328. {
  329. result.outline = func("outline");
  330. }
  331. return result;
  332. }
  333. public static ColorPaletteManager.ColorData Create(Maid maid, MaidParts.PARTS_COLOR colorType)
  334. {
  335. ColorPaletteManager.ColorData result = default(ColorPaletteManager.ColorData);
  336. if (colorType == MaidParts.PARTS_COLOR.HAIR || colorType == MaidParts.PARTS_COLOR.HAIR_OUTLINE)
  337. {
  338. colorType = MaidParts.PARTS_COLOR.HAIR;
  339. }
  340. else if (colorType == MaidParts.PARTS_COLOR.SKIN || colorType == MaidParts.PARTS_COLOR.SKIN_OUTLINE)
  341. {
  342. colorType = MaidParts.PARTS_COLOR.SKIN;
  343. }
  344. result.colorType = colorType;
  345. result.enabledOutLine = (colorType == MaidParts.PARTS_COLOR.HAIR || colorType == MaidParts.PARTS_COLOR.HAIR_OUTLINE || colorType == MaidParts.PARTS_COLOR.SKIN || colorType == MaidParts.PARTS_COLOR.SKIN_OUTLINE);
  346. MaidParts.PartsColor partsColor = maid.Parts.GetPartsColor(colorType);
  347. result.main.hue = partsColor.m_nMainHue;
  348. result.main.chroma = partsColor.m_nMainChroma;
  349. result.main.brightness = partsColor.m_nMainBrightness;
  350. result.main.contrast = partsColor.m_nMainContrast;
  351. result.shadow.hue = partsColor.m_nShadowHue;
  352. result.shadow.chroma = partsColor.m_nShadowChroma;
  353. result.shadow.brightness = partsColor.m_nShadowBrightness;
  354. result.shadow.contrast = partsColor.m_nShadowContrast;
  355. result.shadowRate = partsColor.m_nShadowRate;
  356. if (result.enabledOutLine)
  357. {
  358. MaidParts.PartsColor partsColor2 = (colorType != MaidParts.PARTS_COLOR.HAIR && colorType != MaidParts.PARTS_COLOR.HAIR_OUTLINE) ? maid.Parts.GetPartsColor(MaidParts.PARTS_COLOR.SKIN_OUTLINE) : maid.Parts.GetPartsColor(MaidParts.PARTS_COLOR.HAIR_OUTLINE);
  359. result.outline.hue = partsColor2.m_nMainHue;
  360. result.outline.chroma = partsColor2.m_nMainChroma;
  361. result.outline.brightness = partsColor2.m_nMainBrightness;
  362. result.outline.contrast = partsColor2.m_nMainContrast;
  363. }
  364. return result;
  365. }
  366. public static void Apply(Maid maid, ColorPaletteManager.ColorData data)
  367. {
  368. MaidParts.PartsColor f_cColor = default(MaidParts.PartsColor);
  369. f_cColor.m_nMainHue = data.main.hue;
  370. f_cColor.m_nMainChroma = data.main.chroma;
  371. f_cColor.m_nMainBrightness = data.main.brightness;
  372. f_cColor.m_nMainContrast = data.main.contrast;
  373. f_cColor.m_nShadowHue = data.shadow.hue;
  374. f_cColor.m_nShadowChroma = data.shadow.chroma;
  375. f_cColor.m_nShadowBrightness = data.shadow.brightness;
  376. f_cColor.m_nShadowContrast = data.shadow.contrast;
  377. f_cColor.m_nShadowRate = data.shadowRate;
  378. if (data.enabledOutLine)
  379. {
  380. MaidParts.PartsColor f_cColor2 = default(MaidParts.PartsColor);
  381. f_cColor2.m_nMainHue = data.outline.hue;
  382. f_cColor2.m_nMainChroma = data.outline.chroma;
  383. f_cColor2.m_nMainBrightness = data.outline.brightness;
  384. f_cColor2.m_nMainContrast = data.outline.contrast;
  385. if (data.colorType == MaidParts.PARTS_COLOR.HAIR)
  386. {
  387. maid.Parts.SetPartsColor(MaidParts.PARTS_COLOR.HAIR_OUTLINE, f_cColor2);
  388. }
  389. else
  390. {
  391. maid.Parts.SetPartsColor(MaidParts.PARTS_COLOR.SKIN_OUTLINE, f_cColor2);
  392. }
  393. }
  394. maid.Parts.SetPartsColor(data.colorType, f_cColor);
  395. }
  396. public MaidParts.PARTS_COLOR colorType;
  397. public bool enabledOutLine;
  398. public int shadowRate;
  399. public ColorPaletteManager.ColorData.CommonItem main;
  400. public ColorPaletteManager.ColorData.CommonItem shadow;
  401. public ColorPaletteManager.ColorData.CommonItem outline;
  402. public struct CommonItem
  403. {
  404. public bool Equals(ColorPaletteManager.ColorData.CommonItem obj)
  405. {
  406. return this.hue == obj.hue && this.chroma == obj.chroma && this.brightness == obj.brightness && this.contrast == obj.contrast;
  407. }
  408. public int hue;
  409. public int chroma;
  410. public int brightness;
  411. public int contrast;
  412. }
  413. }
  414. }