BasePhotoWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public abstract class BasePhotoWindow : MonoBehaviour
  5. {
  6. public void ResizeWindow()
  7. {
  8. int num = (int)this.WindowSize.x;
  9. int num2 = (int)this.WindowSize.y;
  10. this.WindowSize.x = (float)num;
  11. this.WindowSize.y = (float)num2;
  12. UTY.GetChildObject(base.gameObject, "Parent", false).GetComponent<BoxCollider>().size = new Vector3((float)num, (float)num2, 1f);
  13. UTY.GetChildObject(base.gameObject, "Parent", false).GetComponent<BoxCollider>().center = new Vector3((float)(num - 200) / 2f, (float)(num2 - 200) / -2f, 1f);
  14. UTY.GetChildObject(base.gameObject, "Parent/BG", false).GetComponent<UIWidget>().width = num;
  15. UTY.GetChildObject(base.gameObject, "Parent/BG", false).GetComponent<UIWidget>().height = num2;
  16. UTY.GetChildObject(base.gameObject, "Parent/BG2", false).GetComponent<UIWidget>().width = num;
  17. UTY.GetChildObject(base.gameObject, "Parent/BG2", false).GetComponent<UIWidget>().height = num2 - 20;
  18. UTY.GetChildObject(base.gameObject, "Parent/BG2", false).transform.localPosition = new Vector3(-100f, (float)((num2 - 100) * -1), 0f);
  19. UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar", false).GetComponent<UIWidget>().width = num;
  20. UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar/Btn", false).transform.localPosition = new Vector3((float)(num - 10), -10f, 0f);
  21. (this.windowTitle = UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar/Text", false).GetComponent<UILabel>()).text = this.InitTitle;
  22. }
  23. public virtual void SetWindowTitle(string title)
  24. {
  25. this.windowTitle.text = title;
  26. }
  27. public virtual void Awake()
  28. {
  29. GameObject gameObject = GameObject.Find("/UI Root");
  30. NDebug.Assert(gameObject != null, "BasePhotoWindow\nRootを見つけられませんでした");
  31. this.uiCamera = gameObject.GetComponent<UIRoot>().GetComponentInChildren<Camera>();
  32. this.ResizeWindow();
  33. base.transform.parent.GetComponent<BasePhotoWindowManager>().Reset();
  34. this.bgWidget = UTY.GetChildObject(base.gameObject, "Parent/BG", false).GetComponent<UIWidget>();
  35. this.bgWidget2 = UTY.GetChildObject(base.gameObject, "Parent/BG2", false).GetComponent<UIWidget>();
  36. this.content_game_object_ = UTY.GetChildObject(base.gameObject, "Parent/ContentParent", false);
  37. GameObject childObject = UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar", false);
  38. if (this.panel_ == null)
  39. {
  40. this.panel_ = base.GetComponentInChildren<UIPanel>();
  41. }
  42. this.title_bar_label_ = UTY.GetChildObject(childObject, "Text", false).GetComponent<UILabel>();
  43. Dictionary<BasePhotoWindow.BtnType, string> dictionary = new Dictionary<BasePhotoWindow.BtnType, string>();
  44. dictionary.Add(BasePhotoWindow.BtnType.Help, "ヘルプ");
  45. dictionary.Add(BasePhotoWindow.BtnType.Min, "最小化");
  46. dictionary.Add(BasePhotoWindow.BtnType.Reset, "UI位置初期化");
  47. dictionary.Add(BasePhotoWindow.BtnType.End, "閉じる");
  48. this.btn_dic_ = new Dictionary<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>>();
  49. for (int i = 0; i <= 3; i++)
  50. {
  51. BasePhotoWindow.BtnType key = (BasePhotoWindow.BtnType)i;
  52. this.btn_dic_.Add(key, new KeyValuePair<UIButton, List<Action>>(UTY.GetChildObject(childObject, "Btn/" + key.ToString(), false).GetComponent<UIButton>(), new List<Action>()));
  53. EventDelegate.Add(this.btn_dic_[key].Key.onClick, new EventDelegate.Callback(this.OnButtonClickEvent));
  54. this.mini_btn_init_pos_.Add(key, this.btn_dic_[key].Key.transform.localPosition);
  55. if (dictionary.ContainsKey(key))
  56. {
  57. UIButton key2 = this.btn_dic_[key].Key;
  58. EventDelegate eventDelegate = new EventDelegate(this, "OnBtnMouseHoverIn");
  59. eventDelegate.parameters[0].value = dictionary[key];
  60. key2.gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
  61. EventDelegate.Add(key2.gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
  62. EventDelegate.Add(key2.gameObject.GetComponent<UIEventTrigger>().onDragStart, new EventDelegate.Callback(this.OnMouseHoverOut));
  63. }
  64. }
  65. this.window_active_delegate_ = new EventDelegate(new EventDelegate.Callback(this.ActiveWindow));
  66. this.init_pos_ = base.transform.localPosition;
  67. for (int j = 0; j <= 3; j++)
  68. {
  69. this.SetButtonEnabled((BasePhotoWindow.BtnType)j, false, false);
  70. }
  71. this.GetButtonOnClickEventList(BasePhotoWindow.BtnType.Reset).Add(delegate
  72. {
  73. this.ResetPosition();
  74. });
  75. this.SetButtonEnabled(BasePhotoWindow.BtnType.Reset, true, false);
  76. if (!this.InitVisible)
  77. {
  78. this.visible = false;
  79. }
  80. if (this.subWindows == null)
  81. {
  82. this.subWindows = new BasePhotoSubWindow[0];
  83. }
  84. foreach (BasePhotoSubWindow basePhotoSubWindow in this.subWindows)
  85. {
  86. basePhotoSubWindow.Initizalize(this);
  87. }
  88. }
  89. public virtual void Start()
  90. {
  91. }
  92. public virtual void OnEnable()
  93. {
  94. if (this.visible && !this.IsWindowInTheScreen())
  95. {
  96. this.ResetPosition();
  97. this.panelDirty = 6;
  98. }
  99. }
  100. public virtual void Update()
  101. {
  102. if (0 < this.panelDirty)
  103. {
  104. this.panelDirty--;
  105. if (this.panel_ != null && this.panelDirty % 2 == 0)
  106. {
  107. UIPanel[] componentsInChildren = base.GetComponentsInChildren<UIPanel>();
  108. if (componentsInChildren != null)
  109. {
  110. foreach (UIPanel uipanel in componentsInChildren)
  111. {
  112. uipanel.SetDirty();
  113. }
  114. }
  115. }
  116. }
  117. }
  118. public virtual void UpdateChildren()
  119. {
  120. UIEventTrigger[] componentsInChildren = base.GetComponentsInChildren<UIEventTrigger>(true);
  121. for (int i = 0; i < componentsInChildren.Length; i++)
  122. {
  123. if (componentsInChildren[i].onPress.IndexOf(this.window_active_delegate_) < 0)
  124. {
  125. componentsInChildren[i].onPress.Add(this.window_active_delegate_);
  126. }
  127. }
  128. }
  129. public virtual void ActiveWindow()
  130. {
  131. this.mgr_.ActiveWindow(this);
  132. }
  133. public void SetButtonEnabled(BasePhotoWindow.BtnType type, bool enabled, bool force_update = false)
  134. {
  135. this.btn_dic_[type].Key.gameObject.SetActive(enabled);
  136. foreach (KeyValuePair<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>> keyValuePair in this.btn_dic_)
  137. {
  138. keyValuePair.Value.Key.transform.localPosition = this.mini_btn_init_pos_[keyValuePair.Key];
  139. }
  140. UIGrid component = this.btn_dic_[BasePhotoWindow.BtnType.Help].Key.transform.parent.gameObject.GetComponent<UIGrid>();
  141. if (component != null)
  142. {
  143. if (force_update)
  144. {
  145. component.Reposition();
  146. }
  147. else
  148. {
  149. component.repositionNow = true;
  150. }
  151. }
  152. }
  153. public List<Action> GetButtonOnClickEventList(BasePhotoWindow.BtnType type)
  154. {
  155. return this.btn_dic_[type].Value;
  156. }
  157. public virtual void OnButtonClickEvent()
  158. {
  159. int instanceID = UIButton.current.GetInstanceID();
  160. foreach (KeyValuePair<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>> keyValuePair in this.btn_dic_)
  161. {
  162. if (instanceID == keyValuePair.Value.Key.GetInstanceID())
  163. {
  164. List<Action> value = keyValuePair.Value.Value;
  165. for (int i = 0; i < value.Count; i++)
  166. {
  167. value[i]();
  168. }
  169. }
  170. }
  171. }
  172. public virtual void ResetPosition()
  173. {
  174. base.transform.localPosition = this.init_pos_;
  175. }
  176. public virtual bool IsWindowInTheScreen()
  177. {
  178. if (this.uiCamera == null)
  179. {
  180. return true;
  181. }
  182. int margin = -30;
  183. Rect windowRectFromScreenPoint = this.GetWindowRectFromScreenPoint(margin);
  184. Rect rect = new Rect(0f, 0f, (float)Screen.width, (float)Screen.height);
  185. windowRectFromScreenPoint.position = new Vector3(windowRectFromScreenPoint.position.x, windowRectFromScreenPoint.y, 0f);
  186. bool flag = rect.Overlaps(windowRectFromScreenPoint);
  187. return rect.Overlaps(windowRectFromScreenPoint);
  188. }
  189. public virtual void OnActiveChangeWindowEvent(bool is_active)
  190. {
  191. }
  192. public virtual void SetWindowManager(BasePhotoWindowManager mgr)
  193. {
  194. this.mgr_ = mgr;
  195. }
  196. public string title
  197. {
  198. get
  199. {
  200. return this.title_bar_label_.text;
  201. }
  202. set
  203. {
  204. this.title_bar_label_.text = value;
  205. }
  206. }
  207. public int depth
  208. {
  209. get
  210. {
  211. return this.panel.GetComponentInChildren<UIPanel>().depth / 10;
  212. }
  213. set
  214. {
  215. int num = value * 10;
  216. UIPanel[] componentsInChildren = this.panel.gameObject.GetComponentsInChildren<UIPanel>(true);
  217. for (int i = 0; i < componentsInChildren.Length; i++)
  218. {
  219. componentsInChildren[i].depth = num++;
  220. }
  221. }
  222. }
  223. public virtual bool baseDraw
  224. {
  225. get
  226. {
  227. return this.bgWidget.alpha != 0f;
  228. }
  229. set
  230. {
  231. UIRect uirect = this.bgWidget;
  232. float alpha = (float)((!value) ? 0 : 1);
  233. this.bgWidget2.alpha = alpha;
  234. uirect.alpha = alpha;
  235. }
  236. }
  237. public virtual bool visible
  238. {
  239. get
  240. {
  241. return this.panel.alpha != 0f;
  242. }
  243. set
  244. {
  245. this.panel.alpha = (float)((!value) ? 0 : 1);
  246. if (value && !this.IsWindowInTheScreen())
  247. {
  248. this.ResetPosition();
  249. this.panelDirty = 6;
  250. }
  251. }
  252. }
  253. public UIPanel panel
  254. {
  255. get
  256. {
  257. if (this.panel_ == null)
  258. {
  259. this.panel_ = base.GetComponentInChildren<UIPanel>();
  260. }
  261. return this.panel_;
  262. }
  263. }
  264. public EventDelegate window_active_delegate
  265. {
  266. get
  267. {
  268. return this.window_active_delegate_;
  269. }
  270. }
  271. public virtual GameObject content_game_object
  272. {
  273. get
  274. {
  275. return this.content_game_object_;
  276. }
  277. }
  278. public Dictionary<string, Dictionary<string, string>> GetWoldStoreData()
  279. {
  280. return this.mgr.GetWoldStoreData(this.windowName);
  281. }
  282. public virtual KeyValuePair<string, Dictionary<string, string>> Serialize()
  283. {
  284. string key = base.gameObject.name + "title";
  285. Dictionary<string, string> dictionary = new Dictionary<string, string>();
  286. Vector3 localPosition = base.transform.localPosition;
  287. dictionary.Add("pos", string.Concat(new string[]
  288. {
  289. localPosition.x.ToString("G9"),
  290. ",",
  291. localPosition.y.ToString("G9"),
  292. ",",
  293. localPosition.z.ToString("G9")
  294. }));
  295. dictionary.Add("visible", this.visible.ToString());
  296. for (int i = 0; i < this.subWindows.Length; i++)
  297. {
  298. dictionary.Add(i.ToString() + ":visible", this.subWindows[i].visible.ToString());
  299. }
  300. return new KeyValuePair<string, Dictionary<string, string>>(key, dictionary);
  301. }
  302. public virtual void Deserialize(Dictionary<string, Dictionary<string, string>> data)
  303. {
  304. string key = base.gameObject.name + "title";
  305. if (!data.ContainsKey(key))
  306. {
  307. return;
  308. }
  309. Dictionary<string, string> dictionary = data[key];
  310. string[] array = dictionary["pos"].Split(new char[]
  311. {
  312. ','
  313. });
  314. base.transform.localPosition = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
  315. if (dictionary.ContainsKey("visible"))
  316. {
  317. this.visible = bool.Parse(dictionary["visible"]);
  318. }
  319. for (int i = 0; i < this.subWindows.Length; i++)
  320. {
  321. string key2 = i.ToString() + ":visible";
  322. if (dictionary.ContainsKey(key2))
  323. {
  324. this.subWindows[i].visible = bool.Parse(dictionary[key2]);
  325. }
  326. }
  327. }
  328. public Rect GetWindowRectFromScreenPoint()
  329. {
  330. return this.GetWindowRectFromScreenPoint(0);
  331. }
  332. public Rect GetWindowRectFromScreenPoint(int margin)
  333. {
  334. Vector3 position = this.bgWidget.transform.position;
  335. this.bgWidget.transform.localPosition = new Vector3(this.bgWidget.transform.localPosition.x - (float)margin, this.bgWidget.transform.localPosition.y + (float)margin, 0f);
  336. Vector2 vector = new Vector2(this.WindowSize.x + (float)(margin * 2), this.WindowSize.y + (float)(margin * 2));
  337. Vector3 vector2 = this.uiCamera.WorldToScreenPoint(this.bgWidget.transform.position);
  338. Rect result = default(Rect);
  339. result.position = new Vector2(vector2.x, (float)Screen.height - vector2.y);
  340. Vector3 position2 = this.bgWidget.transform.position;
  341. Vector3 vector3 = this.uiCamera.WorldToScreenPoint(this.bgWidget.transform.position);
  342. this.bgWidget.transform.localPosition = this.bgWidget.transform.localPosition + new Vector3(vector.x, -vector.y, 0f);
  343. Vector3 vector4 = this.uiCamera.WorldToScreenPoint(this.bgWidget.transform.position);
  344. this.bgWidget.transform.position = position2;
  345. float x = vector4.x - vector3.x;
  346. float y = (float)Screen.height - vector4.y - ((float)Screen.height - vector3.y);
  347. result.size = new Vector2(x, y);
  348. this.bgWidget.transform.position = position;
  349. return result;
  350. }
  351. public BasePhotoWindowManager mgr
  352. {
  353. get
  354. {
  355. return this.mgr_;
  356. }
  357. }
  358. public abstract string windowName { get; }
  359. protected void OnBtnMouseHoverIn(string text)
  360. {
  361. MouseExposition @object = MouseExposition.GetObject();
  362. @object.text = text;
  363. }
  364. protected void OnMouseHoverOut()
  365. {
  366. MouseExposition @object = MouseExposition.GetObject();
  367. @object.text = string.Empty;
  368. }
  369. public string InitTitle = "キャラクター";
  370. public Vector2 WindowSize;
  371. public bool InitVisible = true;
  372. public BasePhotoSubWindow[] subWindows;
  373. private UIWidget bgWidget;
  374. private UIWidget bgWidget2;
  375. private int panelDirty;
  376. private UILabel windowTitle;
  377. protected Camera uiCamera;
  378. protected UILabel title_bar_label_;
  379. protected UIPanel panel_;
  380. protected BasePhotoWindowManager mgr_;
  381. protected Dictionary<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>> btn_dic_;
  382. protected EventDelegate window_active_delegate_;
  383. protected GameObject content_game_object_;
  384. protected Vector3 init_pos_;
  385. private Dictionary<BasePhotoWindow.BtnType, Vector3> mini_btn_init_pos_ = new Dictionary<BasePhotoWindow.BtnType, Vector3>();
  386. public enum BtnType
  387. {
  388. Help,
  389. Reset,
  390. Min,
  391. End
  392. }
  393. }