ColorPaletteUIManager.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class ColorPaletteUIManager : MonoBehaviour
  6. {
  7. public int hue
  8. {
  9. get
  10. {
  11. return (int)System.Math.Round((double)(this.sliderHue.value * 255f), MidpointRounding.AwayFromZero);
  12. }
  13. set
  14. {
  15. List<EventDelegate> onChange = this.sliderHue.onChange;
  16. this.sliderHue.onChange = null;
  17. value = wf.Math.RoundMinMax(value, 0, 255);
  18. this.sliderHue.value = (float)System.Math.Round((double)((float)value / 255f), 2, MidpointRounding.AwayFromZero);
  19. this.sliderHue.onChange = onChange;
  20. UTY.ConvertColorHue(this.hue, this.byteArrayPickerGray, ref this.tmpTxt2dColoField);
  21. }
  22. }
  23. public int chroma
  24. {
  25. get
  26. {
  27. return (int)System.Math.Round((double)(this.sliderChroma.value * 255f), MidpointRounding.AwayFromZero);
  28. }
  29. set
  30. {
  31. List<EventDelegate> onChange = this.sliderChroma.onChange;
  32. this.sliderChroma.onChange = null;
  33. value = wf.Math.RoundMinMax(value, 0, 255);
  34. this.sliderChroma.value = (float)System.Math.Round((double)((float)value / 255f), 2, MidpointRounding.AwayFromZero);
  35. this.sliderChroma.onChange = onChange;
  36. this.labelChroma.text = this.chroma.ToString();
  37. this.UpdatePickerPosition();
  38. }
  39. }
  40. public int brightness
  41. {
  42. get
  43. {
  44. return (int)System.Math.Round((double)(this.sliderBrightness.value * 510f), MidpointRounding.AwayFromZero);
  45. }
  46. set
  47. {
  48. List<EventDelegate> onChange = this.sliderBrightness.onChange;
  49. this.sliderBrightness.onChange = null;
  50. value = wf.Math.RoundMinMax(value, 0, 510);
  51. this.sliderBrightness.value = (float)System.Math.Round((double)((float)value / 510f), 2, MidpointRounding.AwayFromZero);
  52. this.sliderBrightness.onChange = onChange;
  53. this.labelBrightness.text = this.brightness.ToString();
  54. this.UpdatePickerPosition();
  55. }
  56. }
  57. public int contrast
  58. {
  59. get
  60. {
  61. return (int)System.Math.Round((double)(this.sliderContrast.value * 200f), MidpointRounding.AwayFromZero);
  62. }
  63. set
  64. {
  65. List<EventDelegate> onChange = this.sliderContrast.onChange;
  66. this.sliderContrast.onChange = null;
  67. value = wf.Math.RoundMinMax(value, 0, 200);
  68. this.sliderContrast.value = (float)System.Math.Round((double)((float)value / 200f), 2, MidpointRounding.AwayFromZero);
  69. this.sliderContrast.onChange = onChange;
  70. this.labelContrast.text = this.contrast.ToString();
  71. }
  72. }
  73. public int shadowRate
  74. {
  75. get
  76. {
  77. return (int)System.Math.Round((double)(this.sliderShadowRate.value * 255f), MidpointRounding.AwayFromZero);
  78. }
  79. set
  80. {
  81. List<EventDelegate> onChange = this.sliderShadowRate.onChange;
  82. this.sliderShadowRate.onChange = null;
  83. value = wf.Math.RoundMinMax(value, 0, 255);
  84. this.sliderShadowRate.value = (float)System.Math.Round((double)((float)value / 255f), 2, MidpointRounding.AwayFromZero);
  85. this.sliderShadowRate.onChange = onChange;
  86. this.labelShadowRate.text = this.shadowRate.ToString();
  87. }
  88. }
  89. public bool visibleShadowRate
  90. {
  91. get
  92. {
  93. return this.shadowRateObject.activeSelf;
  94. }
  95. set
  96. {
  97. this.shadowRateObject.SetActive(value);
  98. }
  99. }
  100. public bool visible
  101. {
  102. get
  103. {
  104. return base.gameObject.activeSelf;
  105. }
  106. set
  107. {
  108. base.gameObject.SetActive(value);
  109. }
  110. }
  111. private void Awake()
  112. {
  113. this.shadowRateObject = UTY.GetChildObject(base.gameObject, "ColorAdjustment/ShadowRate", false);
  114. this.sliderHue = UTY.GetChildObject(base.gameObject, "PickerPalette/HueSlider", false).GetComponent<UISlider>();
  115. EventDelegate.Add(this.sliderHue.onChange, new EventDelegate.Callback(this.OnChangeValueSlider));
  116. this.sliderChroma = UTY.GetChildObject(base.gameObject, "ColorAdjustment/Saturation/SatSlider", false).GetComponent<UISlider>();
  117. EventDelegate.Add(this.sliderChroma.onChange, new EventDelegate.Callback(this.OnChangeValueSlider));
  118. this.sliderBrightness = UTY.GetChildObject(base.gameObject, "ColorAdjustment/Brightness/BriSlider", false).GetComponent<UISlider>();
  119. EventDelegate.Add(this.sliderBrightness.onChange, new EventDelegate.Callback(this.OnChangeValueSlider));
  120. this.sliderContrast = UTY.GetChildObject(base.gameObject, "ColorAdjustment/Contrast/ContrastSlider", false).GetComponent<UISlider>();
  121. EventDelegate.Add(this.sliderContrast.onChange, new EventDelegate.Callback(this.OnChangeValueSlider));
  122. this.sliderShadowRate = UTY.GetChildObject(base.gameObject, "ColorAdjustment/ShadowRate/ShadowRateSlider", false).GetComponent<UISlider>();
  123. EventDelegate.Add(this.sliderShadowRate.onChange, new EventDelegate.Callback(this.OnChangeValueSlider));
  124. this.labelChroma = UTY.GetChildObject(base.gameObject, "ColorAdjustment/Saturation/Number", false).GetComponent<UILabel>();
  125. this.labelBrightness = UTY.GetChildObject(base.gameObject, "ColorAdjustment/Brightness/Number", false).GetComponent<UILabel>();
  126. this.labelContrast = UTY.GetChildObject(base.gameObject, "ColorAdjustment/Contrast/Number", false).GetComponent<UILabel>();
  127. this.labelShadowRate = UTY.GetChildObject(base.gameObject, "ColorAdjustment/ShadowRate/Number", false).GetComponent<UILabel>();
  128. this.m_palettePanel = UTY.GetChildObject(base.gameObject, "PickerPalette/PalettePanel", false).GetComponent<UIPanel>();
  129. this.m_spSelector = UTY.GetChildObject(this.m_palettePanel.gameObject, "Palette/Selecter", false).GetComponent<UISprite>();
  130. this.uiMainCamera = this.m_palettePanel.root.transform.Find("Camera").GetComponent<Camera>();
  131. this.txtColorField = UTY.GetChildObject(this.m_palettePanel.gameObject, "Palette", false).GetComponent<UITexture>();
  132. Texture2D texture2D = Resources.Load("SceneEdit/ColorPalette/Texture/cm3d2_ColorPalette_PickerGray 1") as Texture2D;
  133. this.byteArrayPickerGray = UTY.GetPixelArray(texture2D);
  134. this.tmpTxt2dColoField = new Texture2D(texture2D.width, texture2D.height, TextureFormat.RGBA32, false, true);
  135. this.txtColorField.mainTexture = this.tmpTxt2dColoField;
  136. UIEventTrigger component = this.m_palettePanel.GetComponent<UIEventTrigger>();
  137. EventDelegate.Add(component.onPress, new EventDelegate.Callback(this.OnMouseDownPalettePanel));
  138. EventDelegate.Add(component.onRelease, new EventDelegate.Callback(this.OnMouseUpPalettePanel));
  139. }
  140. private void Update()
  141. {
  142. if (this.ispickerDrag)
  143. {
  144. this.MovePalettePanelClickPos(UICamera.lastTouchPosition);
  145. }
  146. }
  147. public void UpdatePickerPosition()
  148. {
  149. this.m_spSelector.transform.localPosition = new Vector3((float)this.txtColorField.width * this.sliderChroma.value, -((float)this.txtColorField.height * (1f - this.sliderBrightness.value)));
  150. }
  151. public void MovePalettePanelClickPos(Vector3 clickPos)
  152. {
  153. Vector3 position = this.uiMainCamera.ScreenToWorldPoint(clickPos);
  154. Vector3 vector = this.m_palettePanel.transform.InverseTransformPoint(position);
  155. Vector3 size = this.m_palettePanel.GetComponent<BoxCollider>().size;
  156. Vector2 vector2 = new Vector2((float)this.m_spSelector.width, (float)this.m_spSelector.height);
  157. int num = (int)(this.m_palettePanel.width / 2f + vector.x - vector2.x / 2f);
  158. int num2 = (int)(this.m_palettePanel.height / 2f - vector.y - vector2.y / 2f);
  159. num = wf.Math.RoundMinMax(num, 0, (int)size.x);
  160. num2 = wf.Math.RoundMinMax(num2, 0, (int)size.y);
  161. int num3 = this.SelectorPosToMainChromaNum(num);
  162. int num4 = this.SelectorPosToMainBrightness(num2);
  163. this.sliderChroma.value = (float)num3 / 255f;
  164. this.sliderBrightness.value = (float)num4 / 510f;
  165. this.labelChroma.text = num3.ToString();
  166. this.labelBrightness.text = num4.ToString();
  167. if (this.onChangeValue != null)
  168. {
  169. this.onChangeValue(this);
  170. }
  171. }
  172. private void OnMouseDownPalettePanel()
  173. {
  174. int num = -1;
  175. if (UICamera.currentTouchID == num)
  176. {
  177. if (!GameMain.Instance.VRMode)
  178. {
  179. this.MovePalettePanelClickPos(Input.mousePosition);
  180. }
  181. else
  182. {
  183. this.MovePalettePanelClickPos(GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMouseCurrentSidePos());
  184. }
  185. this.ispickerDrag = true;
  186. }
  187. }
  188. private void OnMouseUpPalettePanel()
  189. {
  190. this.ispickerDrag = false;
  191. }
  192. private void OnChangeValueSlider()
  193. {
  194. if (UIProgressBar.current == this.sliderHue)
  195. {
  196. UTY.ConvertColorHue(this.hue, this.byteArrayPickerGray, ref this.tmpTxt2dColoField);
  197. }
  198. else if (UIProgressBar.current == this.sliderChroma)
  199. {
  200. this.labelChroma.text = this.chroma.ToString();
  201. }
  202. else if (UIProgressBar.current == this.sliderBrightness)
  203. {
  204. this.labelBrightness.text = this.brightness.ToString();
  205. }
  206. else if (UIProgressBar.current == this.sliderContrast)
  207. {
  208. this.labelContrast.text = this.contrast.ToString();
  209. }
  210. else if (UIProgressBar.current == this.sliderShadowRate)
  211. {
  212. this.labelShadowRate.text = this.shadowRate.ToString();
  213. }
  214. this.UpdatePickerPosition();
  215. if (this.onChangeValue != null)
  216. {
  217. this.onChangeValue(this);
  218. }
  219. }
  220. private int SelectorPosToMainChromaNum(int texturePosX)
  221. {
  222. int num = texturePosX * 255 / this.txtColorField.width;
  223. return wf.Math.RoundMinMax(num, 0, 255);
  224. }
  225. private int SelectorPosToMainBrightness(int texturePosY)
  226. {
  227. int num = (this.txtColorField.height - System.Math.Abs(texturePosY)) * 510 / this.txtColorField.height;
  228. return wf.Math.RoundMinMax(num, 0, 510);
  229. }
  230. public Action<ColorPaletteUIManager> onChangeValue;
  231. private GameObject shadowRateObject;
  232. private UISlider sliderHue;
  233. private UISlider sliderChroma;
  234. private UISlider sliderBrightness;
  235. private UISlider sliderContrast;
  236. private UISlider sliderShadowRate;
  237. private UILabel labelChroma;
  238. private UILabel labelBrightness;
  239. private UILabel labelContrast;
  240. private UILabel labelShadowRate;
  241. private UIPanel m_palettePanel;
  242. private UISprite m_spSelector;
  243. private Camera uiMainCamera;
  244. private UITexture txtColorField;
  245. private Texture2D tmpTxt2dColoField;
  246. private byte[] byteArrayPickerGray;
  247. private bool ispickerDrag;
  248. }