You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

141 lines
3.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using CIG.Translation;
  5. using CIGEnums;
  6. using SUISS.Core;
  7. using UnityEngine;
  8. namespace CIG
  9. {
  10. public class TabView : MonoBehaviour
  11. {
  12. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  13. public event TabView.TabIndexChangedEventHandler TabIndexChangedEvent;
  14. private void FireTabIndexChangedEvent(int oldIndex)
  15. {
  16. if (this.TabIndexChangedEvent != null)
  17. {
  18. this.TabIndexChangedEvent(oldIndex, this._activeTabIndex);
  19. }
  20. }
  21. private void Awake()
  22. {
  23. this._activeTabIndex = 0;
  24. this._orderedTabButtonViews[this._activeTabIndex].IsActive = true;
  25. }
  26. public void OnTabButtonClicked(TabButtonView tabButtonView)
  27. {
  28. SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.ButtonClick);
  29. this.UpdateActiveTab(tabButtonView);
  30. }
  31. public int ActiveTabIndex
  32. {
  33. get
  34. {
  35. return this._activeTabIndex;
  36. }
  37. set
  38. {
  39. if (value < 0 || value >= this._orderedTabButtonViews.Count)
  40. {
  41. UnityEngine.Debug.LogWarningFormat("Cannot change ActiveTabIndex to {0} because it it our of bounds[0~{1}]", new object[]
  42. {
  43. value,
  44. this._orderedTabButtonViews.Count - 1
  45. });
  46. return;
  47. }
  48. if (this._activeTabIndex != value)
  49. {
  50. this.UpdateActiveTab(this._orderedTabButtonViews[value]);
  51. }
  52. }
  53. }
  54. public void SetTabActive(int index, bool value)
  55. {
  56. if (index < 0 || index >= this._orderedTabButtonViews.Count)
  57. {
  58. UnityEngine.Debug.LogWarningFormat("Cannot set tab active to {0} because it it our of bounds[0~{1}]", new object[]
  59. {
  60. value,
  61. this._orderedTabButtonViews.Count - 1
  62. });
  63. return;
  64. }
  65. this._orderedTabButtonViews[index].gameObject.SetActive(value);
  66. }
  67. public bool IsTabActive(int index)
  68. {
  69. if (index < 0 || index >= this._orderedTabButtonViews.Count)
  70. {
  71. UnityEngine.Debug.LogWarningFormat("Cannot get tab active state because it it our of bounds[0~{0}]", new object[]
  72. {
  73. this._orderedTabButtonViews.Count - 1
  74. });
  75. return false;
  76. }
  77. return this._orderedTabButtonViews[index].gameObject.activeSelf;
  78. }
  79. public int TotalTabsAmount
  80. {
  81. get
  82. {
  83. return this._orderedTabButtonViews.Count;
  84. }
  85. }
  86. public void UpdateBadge(int index, bool isActive)
  87. {
  88. if (index >= 0 && index < this._orderedTabButtonViews.Count)
  89. {
  90. this._orderedTabButtonViews[index].UpdateBadge(isActive);
  91. }
  92. }
  93. public void UpdateBadge(int index, int amount)
  94. {
  95. if (index >= 0 && index < this._orderedTabButtonViews.Count)
  96. {
  97. this._orderedTabButtonViews[index].UpdateBadge(amount);
  98. }
  99. }
  100. public ILocalizedString GetLocalizedTitle(int index)
  101. {
  102. return (index < 0 || index >= this._orderedTabButtonViews.Count) ? Localization.EmptyLocalizedString : this._orderedTabButtonViews[index].LocalizedTitle;
  103. }
  104. public ILocalizedString LocalizedTitle
  105. {
  106. get
  107. {
  108. return this.GetLocalizedTitle(this._activeTabIndex);
  109. }
  110. }
  111. private void UpdateActiveTab(TabButtonView activeTab)
  112. {
  113. int activeTabIndex = this._activeTabIndex;
  114. this._orderedTabButtonViews[activeTabIndex].IsActive = false;
  115. this._activeTabIndex = this._orderedTabButtonViews.IndexOf(activeTab);
  116. activeTab.IsActive = true;
  117. this.FireTabIndexChangedEvent(activeTabIndex);
  118. }
  119. [SerializeField]
  120. private List<TabButtonView> _orderedTabButtonViews;
  121. private int _activeTabIndex;
  122. public delegate void TabIndexChangedEventHandler(int oldIndex, int newIndex);
  123. }
  124. }