FistStepItem.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /****************************************************************************
  2. * 2024.5 LXD
  3. ****************************************************************************/
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using QFramework;
  9. using Google.Protobuf.WellKnownTypes;
  10. using Sirenix.OdinInspector;
  11. using I2.Loc;
  12. using ChivaXR;
  13. namespace QFramework
  14. {
  15. public partial class FistStepItem : UIComponent
  16. {
  17. List<SecondStepItem> m_SecondStepItems = new List<SecondStepItem>();
  18. public Color m_Color;
  19. [LabelText("常态")]
  20. public Sprite m_NormalSprite;
  21. [LabelText("选中")]
  22. public Sprite m_SeLectSprite;
  23. /// <summary>
  24. /// 展开列表
  25. /// </summary>
  26. private bool m_Expand = false;
  27. private string NO_BREAKING_SPACE = "\u00A0";
  28. private void Start()
  29. {
  30. //if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn)
  31. //{
  32. // ExpandBtn.onClick.AddListener(OnExpandBtnClick);
  33. //}
  34. ExpandBtn.onClick.AddListener(OnExpandBtnClick);
  35. }
  36. private void OnExpandBtnClick()
  37. {
  38. SetState(!m_Expand);
  39. }
  40. public bool OpenSecondStepItem(int id)
  41. {
  42. bool tmpResult = false;
  43. foreach (var item in m_SecondStepItems)
  44. {
  45. item.gameObject.SetActive(!tmpResult);
  46. if (int.Parse(item.m_StepMsgInfo.id) == id)
  47. {
  48. tmpResult = true;
  49. item.OnSelect();
  50. }
  51. else
  52. {
  53. item.OnUnSelect();
  54. }
  55. }
  56. return tmpResult;
  57. }
  58. public void SetSecondStepItemSelectState(int id)
  59. {
  60. bool result = false;
  61. foreach (var item in m_SecondStepItems)
  62. {
  63. if (int.Parse(item.m_StepMsgInfo.id) == id)
  64. {
  65. item.OnSelect();
  66. result = true;
  67. }
  68. else
  69. {
  70. item.OnUnSelect();
  71. }
  72. }
  73. if (result)
  74. {
  75. Select.sprite = m_SeLectSprite;
  76. }
  77. else
  78. {
  79. Select.sprite = m_NormalSprite;
  80. }
  81. }
  82. /// <summary>
  83. /// 设置展开状态
  84. /// </summary>
  85. /// <param name="state"></param>
  86. public void SetState(bool state)
  87. {
  88. m_Expand = state;
  89. UnExpand.gameObject.SetActive(!state);
  90. Expand.gameObject.SetActive(state);
  91. if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn && m_Expand == true)
  92. { //练考模式只展开到当前步骤
  93. ShowCurrentSecondStepItem(ProcessManagement.Instance.currentStepID);
  94. }
  95. else
  96. {
  97. ShowAllSecondStepItems(m_Expand);
  98. }
  99. }
  100. public void GenerateSecondStepItemList(int index, string msg, List<OperationStepDataInfo> stepMsgInfos)
  101. {
  102. Num.text = index.ToString();
  103. //Message.text = msg;
  104. OperateStep operateStep = UIKit.GetPanel<PC_OperatePanel>().OperateStep;
  105. int tmpIndex = 1;
  106. foreach (var info in stepMsgInfos)
  107. {
  108. GameObject tmpObj = Instantiate<GameObject>(operateStep.SecondStepItem.gameObject, operateStep.Content);
  109. SecondStepItem tmpSecondStepItem = tmpObj.GetComponent<SecondStepItem>();
  110. tmpSecondStepItem.InitData(index, tmpIndex, info);
  111. m_SecondStepItems.Add(tmpSecondStepItem);
  112. tmpObj.SetActive(false);
  113. tmpIndex++;
  114. }
  115. LocalizedString realText = m_SecondStepItems[0].m_StepMsgInfo.id + "parentStepName";
  116. Message.text = realText;
  117. }
  118. public void ShowAllSecondStepItems(bool state)
  119. {
  120. foreach (var item in m_SecondStepItems)
  121. {
  122. item.gameObject.SetActive(state);
  123. }
  124. }
  125. public void ShowCurrentSecondStepItem(int step)
  126. {
  127. foreach (var item in m_SecondStepItems)
  128. {
  129. if (int.Parse(item.m_StepMsgInfo.id) <= step)
  130. {
  131. item.gameObject.SetActive(true);
  132. }
  133. else
  134. {
  135. item.gameObject.SetActive(false);
  136. }
  137. }
  138. }
  139. protected override void OnBeforeDestroy()
  140. {
  141. }
  142. #region 多语言
  143. public void RefrushLocalization()
  144. {
  145. LocalizedString realText = m_SecondStepItems[0].m_StepMsgInfo.id + "parentStepName";
  146. Message.text = realText;
  147. }
  148. void OnEnable()
  149. {
  150. LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent;
  151. LocalizationManager_OnLocalizeEvent();
  152. }
  153. void OnDisEnable()
  154. {
  155. LocalizationManager.OnLocalizeEvent -= LocalizationManager_OnLocalizeEvent;
  156. }
  157. private void LocalizationManager_OnLocalizeEvent()
  158. {
  159. if (LocalizationConfig.localization)
  160. {
  161. RefrushLocalization();
  162. }
  163. }
  164. #endregion
  165. }
  166. }