VisualizeManager.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*===============================================================================
  2. Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
  3. This file is part of the Immersal SDK.
  4. The Immersal SDK cannot be copied, distributed, or made available to
  5. third-parties for commercial purposes without written permission of Immersal Ltd.
  6. Contact sdk@immersal.com for licensing requests.
  7. ===============================================================================*/
  8. using System;
  9. using UnityEngine;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using Immersal.REST;
  13. using Immersal.Samples.Mapping.ScrollList;
  14. namespace Immersal.Samples.Mapping
  15. {
  16. public class VisualizeManager : MonoBehaviour
  17. {
  18. public MappingUIComponent localizeButton = null;
  19. public static List<int> loadJobs = new List<int>();
  20. public event ItemSelected OnItemSelected = null;
  21. public event ItemDeleted OnItemDeleted = null;
  22. public event ItemRestored OnItemRestored = null;
  23. public event SelectorOpened OnSelectorOpened = null;
  24. public event SelectorClosed OnSelectorClosed = null;
  25. public delegate void ItemSelected(SDKJob job);
  26. public delegate void ItemDeleted(SDKJob job);
  27. public delegate void ItemRestored(SDKJob job, bool clear);
  28. public delegate void SelectorOpened();
  29. public delegate void SelectorClosed();
  30. [SerializeField]
  31. private MappingUIComponent m_OptionsButton = null;
  32. [SerializeField]
  33. private MappingUIComponent m_MapDownloadButton = null;
  34. [SerializeField]
  35. private MappingUIComponent m_InfoPanel = null;
  36. [SerializeField]
  37. private GameObject m_MapDownloadList = null;
  38. [SerializeField]
  39. private GameObject m_PromptDeleteMap = null;
  40. [SerializeField]
  41. private GameObject m_PromptRestoreMap = null;
  42. [SerializeField]
  43. private GameObject m_OptionsScrollList = null;
  44. [SerializeField]
  45. private GameObject m_AlignMapsPrompt = null;
  46. private SDKJob m_ActiveFunctionJob = default;
  47. private enum UIState { Default, MapList, Options, AlignMaps};
  48. private UIState currentUIState = UIState.Default;
  49. // for delete / restore
  50. public SDKJob activeFunctionJob
  51. {
  52. set { m_ActiveFunctionJob = value; }
  53. }
  54. public void SetMapListData(SDKJob[] data, List<int> activeMaps)
  55. {
  56. m_MapDownloadList.GetComponent<ScrollListControl>().SetData(data, activeMaps);
  57. }
  58. public void OnListItemSelect(SDKJob job)
  59. {
  60. OnItemSelected?.Invoke(job);
  61. }
  62. public void ToggleDeletePrompt(bool on)
  63. {
  64. m_PromptDeleteMap.SetActive(on);
  65. }
  66. private void OnEnable()
  67. {
  68. ChangeState(UIState.Default);
  69. }
  70. public void ToggleRestoreMapImagesPrompt(bool on)
  71. {
  72. m_PromptRestoreMap.SetActive(on);
  73. }
  74. public void OnListItemDelete()
  75. {
  76. if (m_ActiveFunctionJob.id > 0)
  77. {
  78. OnItemDeleted?.Invoke(m_ActiveFunctionJob);
  79. }
  80. }
  81. public void OnListItemRestore(bool clear)
  82. {
  83. if (m_ActiveFunctionJob.id > 0)
  84. {
  85. OnItemRestored?.Invoke(m_ActiveFunctionJob, clear);
  86. }
  87. }
  88. public void MapList()
  89. {
  90. if (currentUIState == UIState.MapList)
  91. {
  92. ChangeState(UIState.Default);
  93. }
  94. else
  95. {
  96. ChangeState(UIState.MapList);
  97. }
  98. }
  99. public void AlignMapsPrompt()
  100. {
  101. if (currentUIState == UIState.AlignMaps)
  102. {
  103. ChangeState(UIState.Default);
  104. }
  105. else
  106. {
  107. ChangeState(UIState.AlignMaps);
  108. }
  109. }
  110. public void DefaultView()
  111. {
  112. ChangeState(UIState.Default);
  113. }
  114. public void Options()
  115. {
  116. if (currentUIState == UIState.Options)
  117. {
  118. ChangeState(UIState.Default);
  119. }
  120. else
  121. {
  122. ChangeState(UIState.Options);
  123. }
  124. }
  125. private void ChangeState(UIState state)
  126. {
  127. switch (state)
  128. {
  129. case UIState.Default:
  130. m_InfoPanel.Activate();
  131. localizeButton.Activate();
  132. m_OptionsButton.Activate();
  133. m_MapDownloadButton.Activate();
  134. m_MapDownloadList.SetActive(false);
  135. m_OptionsScrollList.SetActive(false);
  136. m_AlignMapsPrompt.SetActive(false);
  137. OnSelectorClosed?.Invoke();
  138. break;
  139. case UIState.MapList:
  140. m_InfoPanel.Disable();
  141. localizeButton.Disable();
  142. m_OptionsButton.Disable();
  143. m_MapDownloadButton.Activate();
  144. m_MapDownloadList.SetActive(true);
  145. m_OptionsScrollList.SetActive(false);
  146. m_AlignMapsPrompt.SetActive(false);
  147. OnSelectorOpened?.Invoke();
  148. break;
  149. case UIState.Options:
  150. m_InfoPanel.Disable();
  151. localizeButton.Disable();
  152. m_OptionsButton.Activate();
  153. m_MapDownloadButton.Disable();
  154. m_MapDownloadList.SetActive(false);
  155. m_OptionsScrollList.SetActive(true);
  156. m_AlignMapsPrompt.SetActive(false);
  157. break;
  158. case UIState.AlignMaps:
  159. m_InfoPanel.Disable();
  160. localizeButton.Disable();
  161. m_OptionsButton.Activate();
  162. m_MapDownloadButton.Disable();
  163. m_MapDownloadList.SetActive(false);
  164. m_OptionsScrollList.SetActive(false);
  165. m_AlignMapsPrompt.SetActive(true);
  166. break;
  167. default:
  168. break;
  169. }
  170. currentUIState = state;
  171. }
  172. }
  173. }