ColorPaletteManager.cs 16 KB

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