|
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using UnityEngine;
-
- namespace CIG
- {
- public class TabView : MonoBehaviour
- {
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event TabView.TabIndexChangedEventHandler TabIndexChangedEvent;
-
- private void FireTabIndexChangedEvent(int oldIndex)
- {
- if (this.TabIndexChangedEvent != null)
- {
- this.TabIndexChangedEvent(oldIndex, this._activeTabIndex);
- }
- }
-
- private void Awake()
- {
- this._activeTabIndex = 0;
- this._orderedTabButtonViews[this._activeTabIndex].IsActive = true;
- }
-
- public void OnTabButtonClicked(TabButtonView tabButtonView)
- {
- SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.ButtonClick);
- this.UpdateActiveTab(tabButtonView);
- }
-
- public int ActiveTabIndex
- {
- get
- {
- return this._activeTabIndex;
- }
- set
- {
- if (value < 0 || value >= this._orderedTabButtonViews.Count)
- {
- UnityEngine.Debug.LogWarningFormat("Cannot change ActiveTabIndex to {0} because it it our of bounds[0~{1}]", new object[]
- {
- value,
- this._orderedTabButtonViews.Count - 1
- });
- return;
- }
- if (this._activeTabIndex != value)
- {
- this.UpdateActiveTab(this._orderedTabButtonViews[value]);
- }
- }
- }
-
- public void SetTabActive(int index, bool value)
- {
- if (index < 0 || index >= this._orderedTabButtonViews.Count)
- {
- UnityEngine.Debug.LogWarningFormat("Cannot set tab active to {0} because it it our of bounds[0~{1}]", new object[]
- {
- value,
- this._orderedTabButtonViews.Count - 1
- });
- return;
- }
- this._orderedTabButtonViews[index].gameObject.SetActive(value);
- }
-
- public bool IsTabActive(int index)
- {
- if (index < 0 || index >= this._orderedTabButtonViews.Count)
- {
- UnityEngine.Debug.LogWarningFormat("Cannot get tab active state because it it our of bounds[0~{0}]", new object[]
- {
- this._orderedTabButtonViews.Count - 1
- });
- return false;
- }
- return this._orderedTabButtonViews[index].gameObject.activeSelf;
- }
-
- public int TotalTabsAmount
- {
- get
- {
- return this._orderedTabButtonViews.Count;
- }
- }
-
- public void UpdateBadge(int index, bool isActive)
- {
- if (index >= 0 && index < this._orderedTabButtonViews.Count)
- {
- this._orderedTabButtonViews[index].UpdateBadge(isActive);
- }
- }
-
- public void UpdateBadge(int index, int amount)
- {
- if (index >= 0 && index < this._orderedTabButtonViews.Count)
- {
- this._orderedTabButtonViews[index].UpdateBadge(amount);
- }
- }
-
- public ILocalizedString GetLocalizedTitle(int index)
- {
- return (index < 0 || index >= this._orderedTabButtonViews.Count) ? Localization.EmptyLocalizedString : this._orderedTabButtonViews[index].LocalizedTitle;
- }
-
- public ILocalizedString LocalizedTitle
- {
- get
- {
- return this.GetLocalizedTitle(this._activeTabIndex);
- }
- }
-
- private void UpdateActiveTab(TabButtonView activeTab)
- {
- int activeTabIndex = this._activeTabIndex;
- this._orderedTabButtonViews[activeTabIndex].IsActive = false;
- this._activeTabIndex = this._orderedTabButtonViews.IndexOf(activeTab);
- activeTab.IsActive = true;
- this.FireTabIndexChangedEvent(activeTabIndex);
- }
-
- [SerializeField]
- private List<TabButtonView> _orderedTabButtonViews;
-
- private int _activeTabIndex;
-
- public delegate void TabIndexChangedEventHandler(int oldIndex, int newIndex);
- }
- }
|