DeskItemWindow.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. using System;
  2. using System.Collections.Generic;
  3. using com.workman.cm3d2.scene.dailyEtc;
  4. using I2.Loc;
  5. using UnityEngine;
  6. using wf;
  7. public class DeskItemWindow : BasePhotoWindow
  8. {
  9. public override string windowName
  10. {
  11. get
  12. {
  13. return this.InitTitle;
  14. }
  15. }
  16. public override void Awake()
  17. {
  18. base.Awake();
  19. this.camera_move_support_ = base.gameObject.AddComponent<WfCameraMoveSupport>();
  20. this.PartsPopUpList.onChangePopUpListValue.Add(new Action<KeyValuePair<string, UnityEngine.Object>>(this.OnChangePopUpList));
  21. this.PartsTransForm.onChangeAxisVisibleType.Add(new Action(this.OnChangeAxisVisibleType));
  22. this.CheckBoxVisible.onClick.Add(new Action<WFCheckBox>(this.OnClickVisible));
  23. this.CheckBoxSeasonalVisible.onClick.Add(new Action<WFCheckBox>(this.OnClickSeasonalVisible));
  24. }
  25. public override void Start()
  26. {
  27. base.Start();
  28. base.SetButtonEnabled(BasePhotoWindow.BtnType.Help, true, false);
  29. base.GetButtonOnClickEventList(BasePhotoWindow.BtnType.Help).Add(new Action(this.OnClickHelp));
  30. if (string.IsNullOrEmpty(GameMain.Instance.BgMgr.GetBGName()))
  31. {
  32. GameMain.Instance.BgMgr.ChangeBg(DailyAPI.dayBg);
  33. }
  34. List<DeskManager.InstansData> item_inst_data = DeskManager.item_inst_data;
  35. int num = 0;
  36. foreach (DeskManager.InstansData instansData in item_inst_data)
  37. {
  38. if (instansData.item_data != null && instansData.IsPossessing() && !(instansData.item_object == null))
  39. {
  40. int category_id = instansData.item_data.category_id;
  41. if (!this.category_dic_.ContainsKey(category_id))
  42. {
  43. this.category_dic_.Add(category_id, new List<DeskManager.InstansData>());
  44. }
  45. this.category_dic_[category_id].Add(instansData);
  46. num = System.Math.Max(num, this.category_dic_[category_id].Count);
  47. DeskItemWindow.UIObject uiobject = DeskItemWindow.UIObject.Create(instansData.item_object);
  48. uiobject.axis_obj.offsetScale = instansData.item_data.init_ui_position_scale;
  49. uiobject.axis_obj.ScaleMinMax = new Vector2(this.PartsTransForm.ScaleInput.SliderMin, this.PartsTransForm.ScaleInput.SliderMax);
  50. if (GameMain.Instance.VRMode)
  51. {
  52. MeshRenderer componentInChildren = uiobject.axis_obj.GetComponentInChildren<MeshRenderer>();
  53. if (componentInChildren != null)
  54. {
  55. componentInChildren.enabled = false;
  56. }
  57. BoxCollider[] componentsInChildren = uiobject.axis_obj.GetComponentsInChildren<BoxCollider>();
  58. foreach (BoxCollider boxCollider in componentsInChildren)
  59. {
  60. boxCollider.enabled = false;
  61. }
  62. }
  63. uiobject.rotate_obj.offsetScale = instansData.item_data.init_ui_position_scale;
  64. this.uiobject_dic_.Add(instansData.item_object, uiobject);
  65. }
  66. }
  67. foreach (KeyValuePair<int, List<DeskManager.InstansData>> keyValuePair in this.category_dic_)
  68. {
  69. keyValuePair.Value.Sort((DeskManager.InstansData a, DeskManager.InstansData b) => a.id - b.id);
  70. }
  71. for (int j = 0; j < num; j++)
  72. {
  73. GameObject gameObject = Utility.CreatePrefab(this.PartsTabPabel.gameObject, "ScenePhotoMode/WindowListItemBig", true);
  74. }
  75. List<KeyValuePair<string, UnityEngine.Object>> list = new List<KeyValuePair<string, UnityEngine.Object>>();
  76. foreach (KeyValuePair<int, List<DeskManager.InstansData>> keyValuePair2 in this.category_dic_)
  77. {
  78. list.Add(new KeyValuePair<string, UnityEngine.Object>(DeskManager.item_category_data_dic[keyValuePair2.Key], null));
  79. }
  80. this.PartsPopUpList.popup_value_list = list;
  81. if (0 < this.PartsPopUpList.popup_value_list.Count)
  82. {
  83. this.PartsPopUpList.SetPopupValue(this.PartsPopUpList.popup_value_list[0].Key);
  84. }
  85. if (2 <= list.Count)
  86. {
  87. this.WindowSize.y = this.WindowSize.y + 30f;
  88. base.ResizeWindow();
  89. Transform transform = UTY.GetChildObject(base.gameObject, "Parent/ContentParent", false).transform;
  90. Vector3 localPosition = transform.localPosition;
  91. localPosition.y -= 30f;
  92. transform.localPosition = localPosition;
  93. transform = UTY.GetChildObject(base.gameObject, "Parent/ListParent", false).transform;
  94. localPosition = transform.localPosition;
  95. localPosition.y -= 30f;
  96. transform.localPosition = localPosition;
  97. }
  98. }
  99. protected void OnChangePopUpList(KeyValuePair<string, UnityEngine.Object> popup_val)
  100. {
  101. if (this.select_pop_up_value_name_ == popup_val.Key)
  102. {
  103. return;
  104. }
  105. this.select_pop_up_value_name_ = popup_val.Key;
  106. int num = -1;
  107. foreach (KeyValuePair<int, string> keyValuePair in DeskManager.item_category_data_dic)
  108. {
  109. if (keyValuePair.Value == popup_val.Key)
  110. {
  111. num = keyValuePair.Key;
  112. break;
  113. }
  114. }
  115. if (num < 0)
  116. {
  117. return;
  118. }
  119. List<DeskManager.InstansData> list = null;
  120. if (this.category_dic_.ContainsKey(num))
  121. {
  122. list = this.category_dic_[num];
  123. }
  124. if (list == null)
  125. {
  126. return;
  127. }
  128. Transform transform = this.PartsTabPabel.gameObject.transform;
  129. for (int i = 0; i < transform.childCount; i++)
  130. {
  131. if (i < list.Count)
  132. {
  133. DeskManager.InstansData instansData = list[i];
  134. GameObject gameObject = transform.GetChild(i).gameObject;
  135. gameObject.SetActive(true);
  136. string name = instansData.item_data.name;
  137. gameObject.name = instansData.id.ToString();
  138. UILabel componentInChildren = gameObject.GetComponentInChildren<UILabel>();
  139. componentInChildren.text = name;
  140. Localize component = componentInChildren.GetComponent<Localize>();
  141. if (component != null)
  142. {
  143. component.SetTerm("SceneDeskCustomize/" + name);
  144. }
  145. int j = componentInChildren.width;
  146. componentInChildren.width = 0;
  147. componentInChildren.MakePixelPerfect();
  148. while (j < componentInChildren.width)
  149. {
  150. componentInChildren.fontSize--;
  151. componentInChildren.width = 0;
  152. componentInChildren.MakePixelPerfect();
  153. }
  154. componentInChildren.width = j;
  155. UIWFTabButton component2 = gameObject.GetComponent<UIWFTabButton>();
  156. component2.onSelect.Clear();
  157. EventDelegate.Add(component2.onSelect, new EventDelegate.Callback(this.OnSelectItem));
  158. }
  159. else
  160. {
  161. transform.GetChild(i).gameObject.SetActive(false);
  162. }
  163. }
  164. UIGrid component3 = this.PartsTabPabel.GetComponent<UIGrid>();
  165. this.PartsTabPabel.UpdateChildren();
  166. Utility.ResetNGUI(component3);
  167. Utility.ResetNGUI(this.PartsScrollView);
  168. this.PartsTabPabel.Select(component3.GetChild(0).GetComponentInChildren<UIWFTabButton>());
  169. if (this.category_dic_.Count <= 1)
  170. {
  171. this.PartsPopUpList.gameObject.SetActive(false);
  172. }
  173. }
  174. protected void OnSelectItem()
  175. {
  176. if (!UIWFSelectButton.current.isSelected)
  177. {
  178. return;
  179. }
  180. int num = int.Parse(UIWFSelectButton.current.name);
  181. GameObject gameObject = null;
  182. DeskManager.InstansData instansData = null;
  183. List<DeskManager.InstansData> item_inst_data = DeskManager.item_inst_data;
  184. int num2 = 0;
  185. while (num2 < item_inst_data.Count && gameObject == null)
  186. {
  187. if (item_inst_data[num2].id == num)
  188. {
  189. gameObject = item_inst_data[num2].item_object;
  190. instansData = item_inst_data[num2];
  191. }
  192. num2++;
  193. }
  194. KeyValuePair<string, UnityEngine.Object> keyValuePair = new KeyValuePair<string, UnityEngine.Object>(string.Empty, gameObject);
  195. this.select_item_ = null;
  196. GameObject target_object = (!(keyValuePair.Value == null)) ? (keyValuePair.Value as GameObject) : null;
  197. this.CheckBoxVisible.enabled = false;
  198. this.CheckBoxSeasonalVisible.visible = false;
  199. if (keyValuePair.Value == null)
  200. {
  201. this.PartsTransForm.SetObject(null);
  202. return;
  203. }
  204. if (instansData == null)
  205. {
  206. return;
  207. }
  208. this.PartsTransForm.SetObject(target_object, instansData.item_data.init_position, instansData.item_data.init_rotation, instansData.item_data.init_scale);
  209. this.select_item_ = instansData;
  210. if (this.select_item_.item_data.seasonal)
  211. {
  212. this.CheckBoxSeasonalVisible.text = "特定期間のみ表示する(" + this.select_item_.item_data.seasonal_month[0].ToString() + "月)";
  213. }
  214. this.UpdateUI();
  215. }
  216. public void UpdateVisible()
  217. {
  218. if (this.select_item_ == null)
  219. {
  220. this.CheckBoxVisible.enabled = false;
  221. this.CheckBoxSeasonalVisible.visible = false;
  222. return;
  223. }
  224. this.CheckBoxVisible.enabled = true;
  225. this.CheckBoxVisible.check = this.select_item_.visible;
  226. if (this.select_item_.item_data.seasonal)
  227. {
  228. this.CheckBoxSeasonalVisible.visible = true;
  229. this.CheckBoxSeasonalVisible.check = this.select_item_.only_season_visible;
  230. }
  231. else
  232. {
  233. this.CheckBoxSeasonalVisible.visible = false;
  234. }
  235. List<DeskManager.InstansData> item_inst_data = DeskManager.item_inst_data;
  236. for (int i = 0; i < item_inst_data.Count; i++)
  237. {
  238. if (!(item_inst_data[i].item_object == null))
  239. {
  240. if (!item_inst_data[i].item_data.seasonal || !item_inst_data[i].visible || item_inst_data[i] == this.select_item_)
  241. {
  242. item_inst_data[i].item_object.SetActive(item_inst_data[i].visible);
  243. }
  244. else if (item_inst_data[i].only_season_visible)
  245. {
  246. item_inst_data[i].item_object.SetActive(item_inst_data[i].IsNowMonthSeason());
  247. }
  248. }
  249. }
  250. }
  251. public void UpdateUI()
  252. {
  253. this.UpdateVisible();
  254. this.OnChangeAxisVisibleType();
  255. }
  256. protected void OnChangeAxisVisibleType()
  257. {
  258. if (this.select_item_ == null)
  259. {
  260. return;
  261. }
  262. GameObject item_object = this.select_item_.item_object;
  263. WindowPartsTransform.AxisVisibleType axis_visible_type = this.PartsTransForm.axis_visible_type;
  264. foreach (KeyValuePair<GameObject, DeskItemWindow.UIObject> keyValuePair in this.uiobject_dic_)
  265. {
  266. DeskItemWindow.UIObject value = keyValuePair.Value;
  267. if (axis_visible_type == WindowPartsTransform.AxisVisibleType.UnVisible || item_object != keyValuePair.Key || !item_object.activeSelf)
  268. {
  269. value.axis_obj.Visible = false;
  270. value.rotate_obj.Visible = false;
  271. }
  272. else if (axis_visible_type == WindowPartsTransform.AxisVisibleType.Position)
  273. {
  274. value.axis_obj.Visible = true;
  275. value.rotate_obj.Visible = false;
  276. }
  277. else if (axis_visible_type == WindowPartsTransform.AxisVisibleType.Rotate)
  278. {
  279. value.axis_obj.Visible = false;
  280. value.rotate_obj.Visible = true;
  281. }
  282. }
  283. }
  284. public void OnClickCameraFocus()
  285. {
  286. if (this.select_item_ == null || this.select_item_.item_object == null)
  287. {
  288. return;
  289. }
  290. Transform transform = this.select_item_.item_object.transform;
  291. Vector3 position = transform.position;
  292. float distance = 1.6f;
  293. Vector2 aroundAngle = new Vector2(-90f, 4.7f);
  294. this.camera_move_support_.StartCameraPosition(position, distance, aroundAngle);
  295. }
  296. protected void OnClickVisible(WFCheckBox checkbox)
  297. {
  298. if (this.select_item_ == null)
  299. {
  300. return;
  301. }
  302. this.select_item_.visible = checkbox.check;
  303. this.UpdateUI();
  304. }
  305. protected void OnClickSeasonalVisible(WFCheckBox checkbox)
  306. {
  307. if (this.select_item_ == null || !this.select_item_.item_data.seasonal)
  308. {
  309. return;
  310. }
  311. this.select_item_.only_season_visible = checkbox.check;
  312. this.UpdateUI();
  313. }
  314. protected void OnClickHelp()
  315. {
  316. uGUITutorialPanel.OpenTutorial("SceneDeskCustomize", null, true);
  317. }
  318. public WFCheckBox CheckBoxVisible;
  319. public WFCheckBox CheckBoxSeasonalVisible;
  320. public WindowPartsPopUpList PartsPopUpList;
  321. public WindowPartsTransform PartsTransForm;
  322. public UIWFTabPanel PartsTabPabel;
  323. public UIScrollView PartsScrollView;
  324. private SortedDictionary<int, List<DeskManager.InstansData>> category_dic_ = new SortedDictionary<int, List<DeskManager.InstansData>>();
  325. private Dictionary<GameObject, DeskItemWindow.UIObject> uiobject_dic_ = new Dictionary<GameObject, DeskItemWindow.UIObject>();
  326. private DeskManager.InstansData select_item_;
  327. private string select_pop_up_value_name_ = string.Empty;
  328. private WfCameraMoveSupport camera_move_support_;
  329. public class UIObject
  330. {
  331. private UIObject()
  332. {
  333. }
  334. public static DeskItemWindow.UIObject Create(GameObject target_obj)
  335. {
  336. return new DeskItemWindow.UIObject
  337. {
  338. target_obj = target_obj,
  339. rotate_obj = PhotoWindowManager.CreateWorldTransformRotate(target_obj, false),
  340. axis_obj = PhotoWindowManager.CreateWorldTransformAxis(target_obj, false, false)
  341. };
  342. }
  343. public WorldTransformAxis axis_obj;
  344. public GizmoRender rotate_obj;
  345. public GameObject target_obj;
  346. }
  347. }