DeskItemWindow.cs 12 KB

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