OperateStep.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /****************************************************************************
  2. * 2023.10 DESKTOP-DL7CJI0
  3. ****************************************************************************/
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using QFramework;
  9. using ChivaXR;
  10. using DG.Tweening;
  11. using System.Collections;
  12. using UnityEngine.Tilemaps;
  13. using I2.Loc;
  14. using System.Linq;
  15. namespace QFramework
  16. {
  17. public enum BtnState
  18. {
  19. normal,
  20. highter,
  21. select
  22. }
  23. public partial class OperateStep : UIElement
  24. {
  25. private List<GameObject> itemList = new List<GameObject>();
  26. private List<FistStepItem> firstStepItems = new List<FistStepItem>();
  27. private void Awake()
  28. {
  29. HelpBtn.Button.onClick.AddListener(OnHelpBtnClick);
  30. HelpBtn.isToggle = true;
  31. ToolLibraryBtn.Button.onClick.AddListener(OnToolLibraryBtnClick);
  32. ToolBackPackBtn.Button.onClick.AddListener(OnToolBackPackBtnClick);
  33. AutoPlayBtn.Button.onClick.AddListener(OnAutoPlayBtnClick);
  34. AutoPlayBtn.isToggle = true;
  35. EndExam.Button.onClick.AddListener(OnEndExamBtnClick);
  36. CheckBtn.Button.onClick.AddListener(OnCheckBtnClick);
  37. InstructBtn.Button.onClick.AddListener(OnInstructBtnClick);
  38. OperateLogBtn.onClick.AddListener(OnOperateLogBtnClick);
  39. PlayBtn.onClick.AddListener(OnPlayBtnClick);
  40. PauseBtn.onClick.AddListener(OnPauseBtnClick);
  41. ExpandBtn.onClick.AddListener(OnExpandBtnClick);
  42. ScrollViewCtrl.gameObject.SetActive(false);
  43. }
  44. public void StartOperation()
  45. {
  46. ScrollViewCtrl.gameObject.SetActive(true);
  47. }
  48. /// <summary>
  49. /// 播放按钮点击
  50. /// </summary>
  51. private void OnPlayBtnClick()
  52. {
  53. Time.timeScale = 0;
  54. AudioHelper.AudioPause();
  55. GameObject tmpMiniModelView = GameObject.Find("MiniModelView/CreatModel");
  56. tmpMiniModelView.GetComponentInChildren<AudioSource>()?.Pause();
  57. PauseBtn.gameObject.SetActive(true);
  58. PlayBtn.gameObject.SetActive(false);
  59. RoamCameraController.Instance.SetCameraMoveState(true);
  60. }
  61. /// <summary>
  62. /// 检查按钮点击
  63. /// </summary>
  64. private void OnCheckBtnClick()
  65. {
  66. if (!OperateSetting.Instance.isOpenCheck)
  67. {
  68. CheckBtn.SetBtnState(BtnState.select);
  69. OperateSetting.Instance.isOpenCheck = true;
  70. }
  71. else
  72. {
  73. CheckBtn.SetBtnState(BtnState.normal);
  74. OperateSetting.Instance.isOpenCheck = false;
  75. }
  76. }
  77. /// <summary>
  78. /// 检查按钮点击
  79. /// </summary>
  80. private void OnInstructBtnClick()
  81. {
  82. UIKit.OpenPanel<InstructPanel>(UILevel.PopUI);
  83. }
  84. /// <summary>
  85. /// 暂停按钮点击
  86. /// </summary>
  87. private void OnPauseBtnClick()
  88. {
  89. Time.timeScale = 1;
  90. AudioHelper.AudioPlay();
  91. PlayBtn.gameObject.SetActive(true);
  92. PauseBtn.gameObject.SetActive(false);
  93. GameObject tmpMiniModelView = GameObject.Find("MiniModelView/CreatModel");
  94. tmpMiniModelView.GetComponentInChildren<AudioSource>()?.Play();
  95. RoamCameraController.Instance.SetCameraMoveState(false);
  96. }
  97. public void OnHelpBtnClick()
  98. {
  99. if (!OperateSetting.Instance.ToolPackUILogic.GetHint())
  100. {
  101. HelpBtn.SetBtnState(BtnState.select);
  102. OperateSetting.Instance.ToolPackUILogic.SetHint(true);
  103. }
  104. else
  105. {
  106. HelpBtn.SetBtnState(BtnState.normal);
  107. OperateSetting.Instance.ToolPackUILogic.SetHint(false);
  108. }
  109. }
  110. public void OnAutoPlayBtnClick()
  111. {
  112. if (ProcessManagement.Instance.autoEnterNextProcess)
  113. {
  114. AutoPlayBtn.SetBtnState(BtnState.normal);
  115. ProcessManagement.Instance.autoEnterNextProcess = false;
  116. ProcessManagement.Instance.delayTime = 0;
  117. }
  118. else
  119. {
  120. AutoPlayBtn.SetBtnState(BtnState.select);
  121. ProcessManagement.Instance.autoEnterNextProcess = true;
  122. //如果当前步骤已完成,点击自动播放默认进入下一步
  123. if (ProcessManagement.Instance.GetCurrentProcess().finished)
  124. {
  125. ProcessManagement.Instance.EnterNextProcess();
  126. }
  127. ProcessManagement.Instance.delayTime = 1;
  128. }
  129. }
  130. public void OnEndExamBtnClick()
  131. {
  132. UIKit.GetPanel<PC_OperatePanel>().SubmitResult.gameObject.SetActive(true);
  133. }
  134. /// <summary>
  135. /// 工具背包
  136. /// </summary>
  137. private void OnToolBackPackBtnClick()
  138. {
  139. ToolLibraryForm tmpToolLibraryForm = UIKit.GetPanel<ToolLibraryForm>();
  140. if (tmpToolLibraryForm == null)
  141. {
  142. UIKit.OpenPanel<ToolLibraryForm>(UILevel.PopUI, new ToolLibraryFormData() { toolLibraryType = ToolLibraryType.ToolKit });
  143. }
  144. else if (tmpToolLibraryForm != null && !tmpToolLibraryForm.isActiveAndEnabled)
  145. {
  146. if (tmpToolLibraryForm.Data.toolLibraryType == ToolLibraryType.ToolRoom)
  147. {
  148. UIKit.ClosePanel<ToolLibraryForm>();
  149. UIKit.OpenPanel<ToolLibraryForm>(UILevel.PopUI, new ToolLibraryFormData() { toolLibraryType = ToolLibraryType.ToolKit });
  150. }
  151. else
  152. {
  153. UIKit.ShowPanel<ToolLibraryForm>();
  154. }
  155. }
  156. }
  157. /// <summary>
  158. /// 工具库点击
  159. /// </summary>
  160. private void OnToolLibraryBtnClick()
  161. {
  162. ToolLibraryForm tmpToolLibraryForm = UIKit.GetPanel<ToolLibraryForm>();
  163. if (tmpToolLibraryForm == null)
  164. {
  165. UIKit.OpenPanel<ToolLibraryForm>(UILevel.PopUI, new ToolLibraryFormData() { toolLibraryType = ToolLibraryType.ToolRoom });
  166. }
  167. else if (tmpToolLibraryForm != null && !tmpToolLibraryForm.isActiveAndEnabled)
  168. {
  169. if (tmpToolLibraryForm.Data.toolLibraryType == ToolLibraryType.ToolKit)
  170. {
  171. UIKit.ClosePanel<ToolLibraryForm>();
  172. UIKit.OpenPanel<ToolLibraryForm>(UILevel.PopUI, new ToolLibraryFormData() { toolLibraryType = ToolLibraryType.ToolKit });
  173. }
  174. else
  175. {
  176. UIKit.ShowPanel<ToolLibraryForm>();
  177. }
  178. }
  179. }
  180. public void ShowToolLibraryHighter(bool state)
  181. {
  182. }
  183. private bool isLibraryEnter;
  184. public void SetTitle(string str)
  185. {
  186. Title_LowestLayer.text = Title_MiddleLayer.text = Title_TopLayer.text = str;
  187. }
  188. /// <summary>
  189. /// 将所有列表初始化出来
  190. /// </summary>
  191. public void GenerateFirstStepItemList(Dictionary<string, List<OperationStepDataInfo>> dicStepMsgInfos)
  192. {
  193. int tmpNum = 1;
  194. foreach (var item in dicStepMsgInfos)
  195. {
  196. var tempItem = Instantiate(FistStepItem.gameObject, Content);
  197. FistStepItem tmpStepItem = tempItem.GetComponent<FistStepItem>();
  198. tmpStepItem.GenerateSecondStepItemList(tmpNum, item.Key, item.Value);
  199. firstStepItems.Add(tmpStepItem);
  200. tempItem.SetActive(false);
  201. tmpNum++;
  202. }
  203. }
  204. /// <summary>
  205. /// 展开所有一级列表
  206. /// </summary>
  207. public void ExpandAllFirstStepItem()
  208. {
  209. foreach (var item in firstStepItems)
  210. {
  211. item.gameObject.SetActive(true);
  212. item.SetState(true);
  213. }
  214. }
  215. public void InitList(Dictionary<int, List<object>> dic)
  216. {
  217. if (dic.Count > 0)
  218. {
  219. foreach (var key in dic.Keys)
  220. {
  221. var tempItem = Instantiate(FistStepItem.gameObject, Content);
  222. tempItem.SetActive(false);
  223. //StepItem stepItem = tempItem.GetComponent<StepItem>();
  224. //stepItem.SetItemInfo(key, dic[key][0].ToString());
  225. itemList.Add(tempItem);
  226. }
  227. }
  228. else
  229. {
  230. Debug.LogError("树形步骤表为空!!!");
  231. }
  232. }
  233. /// <summary>
  234. /// 练习模式
  235. /// </summary>
  236. /// <param name="stepID"></param>
  237. public void ShowSecondStepItemByStepId(int stepID)
  238. {
  239. bool tmpResul = false;
  240. foreach (var item in firstStepItems)
  241. {
  242. if (!tmpResul)
  243. {
  244. item.gameObject.SetActive(true);
  245. item.SetState(true);
  246. tmpResul = item.OpenSecondStepItem(stepID);
  247. if (tmpResul) item.Select.gameObject.SetActive(true);
  248. else item.Select.gameObject.SetActive(false);
  249. }
  250. else
  251. {
  252. item.SetState(false);
  253. item.gameObject.SetActive(false);
  254. }
  255. }
  256. Canvas.ForceUpdateCanvases();
  257. ScrollView.verticalNormalizedPosition = 0;
  258. if (Content.transform.GetComponent<RectTransform>().sizeDelta.y >= 929f)
  259. {
  260. BottomImage.gameObject.SetActive(false);
  261. }
  262. else
  263. {
  264. BottomImage.gameObject.SetActive(true);
  265. }
  266. }
  267. /// <summary>
  268. /// 自由练习模式
  269. /// </summary>
  270. /// <param name="stepID"></param>
  271. public void ShowFreeSecondStepItemByStepId(int stepID)
  272. {
  273. FistStepItem tempItem = null;
  274. int firstIndex = 1;
  275. foreach (var item in firstStepItems)
  276. {
  277. //item.gameObject.SetActive(true);
  278. bool tmpResul = item.FinishedSecondStepItem(stepID);
  279. if (tmpResul)
  280. {
  281. tempItem = item;
  282. }
  283. if (item.gameObject.activeSelf)
  284. {
  285. firstIndex++;
  286. }
  287. //else item.Select.gameObject.SetActive(false);
  288. }
  289. if (tempItem != null)
  290. {
  291. if (!tempItem.gameObject.activeSelf)
  292. {
  293. tempItem.RefrushNumIndex(firstIndex);
  294. }
  295. tempItem.Select.gameObject.SetActive(true);
  296. tempItem.gameObject.SetActive(true);
  297. tempItem.SetState(true);
  298. RefreshFreeList();
  299. }
  300. Canvas.ForceUpdateCanvases();
  301. ScrollView.verticalNormalizedPosition = 0;
  302. if (Content.transform.GetComponent<RectTransform>().sizeDelta.y >= 929f)
  303. {
  304. BottomImage.gameObject.SetActive(false);
  305. }
  306. else
  307. {
  308. BottomImage.gameObject.SetActive(true);
  309. }
  310. }
  311. /// <summary>
  312. /// 学习模式
  313. /// </summary>
  314. /// <param name="stepID"></param>
  315. public void SetSecondStepItemSelectByStepId(int stepID)
  316. {
  317. foreach (var item in firstStepItems)
  318. {
  319. item.SetSecondStepItemSelectState(stepID);
  320. }
  321. }
  322. /// <summary>
  323. /// 刷新列表
  324. /// </summary>
  325. /// <param name="stepID"></param>
  326. public void RefreshList(int stepID)
  327. {
  328. Debug.LogError(stepID);
  329. if (itemList.Count > 0 && stepID < itemList.Count)
  330. {
  331. for (int i = 0; i < itemList.Count; i++)
  332. {
  333. itemList[i].SetActive(false);
  334. if (i <= stepID)
  335. {
  336. itemList[i].SetActive(true);
  337. }
  338. }
  339. }
  340. Canvas.ForceUpdateCanvases();
  341. ScrollView.verticalNormalizedPosition = 0;
  342. }
  343. public void RefreshFreeList()
  344. {
  345. foreach (var item in firstStepItems.OrderBy(s => int.Parse(s.Num.text)))
  346. {
  347. if (item.gameObject.activeSelf)
  348. {
  349. item.transform.SetSiblingIndex(int.Parse(item.Num.text)-1);
  350. }
  351. }
  352. foreach (var item in firstStepItems.OrderBy(s => int.Parse(s.Num.text)))
  353. {
  354. if (item.gameObject.activeSelf)
  355. {
  356. item.RefrushFreeSecondSiblingIndex();
  357. }
  358. }
  359. }
  360. bool expande = false;
  361. /// <summary>
  362. /// 菜单展开
  363. /// </summary>
  364. public void OnExpandBtnClick()
  365. {
  366. if (!expande)
  367. {
  368. ScrollViewCtrl.transform.DOMove(ScrollViewCtrlExpandTarget.transform.position, 1f).SetUpdate(true);
  369. ExpandBtn.transform.DOScaleX(-1, 1).SetUpdate(true);
  370. }
  371. else
  372. {
  373. //SetUpdate(ture)设置这个Tween不受Time.scale影响
  374. ScrollViewCtrl.transform.DOMove(ScrollViewCtrlUnExpandTarget.transform.position, 1f).SetUpdate(true);
  375. ExpandBtn.transform.DOScaleX(1, 1).SetUpdate(true);
  376. }
  377. expande = !expande;
  378. }
  379. /// <summary>
  380. /// 操作记录按钮点击
  381. /// </summary>
  382. private void OnOperateLogBtnClick()
  383. {
  384. LogSystemForm logSystemForm = UIKit.GetPanel<LogSystemForm>();
  385. if (logSystemForm == null)
  386. {
  387. logSystemForm = UIKit.OpenPanel<LogSystemForm>(UILevel.PopUI);
  388. }
  389. if (logSystemForm.ScrollView.gameObject.activeSelf)
  390. {
  391. logSystemForm.SetLogState(false);
  392. }
  393. else
  394. {
  395. logSystemForm.SetLogState(true);
  396. }
  397. }
  398. protected override void OnBeforeDestroy()
  399. {
  400. }
  401. }
  402. }