BasePhotoWindow.cs 13 KB

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