D:\ValheimDev\Dumps\Old\assembly_valheim\TabHandler.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\TabHandler.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.UI; using UnityEngine.UI;
   
public class TabHandler : MonoBehaviour public class TabHandler : MonoBehaviour
{ {
.    private void Awake()     private void Start()
    {     {
        this.Init(true);         this.Init(true);
    }     }
   
    public void Init(bool forceSelect = false)     public void Init(bool forceSelect = false)
    {     {
        int num = -1;         int num = -1;
        for (int i = 0; i < this.m_tabs.Count; i++)         for (int i = 0; i < this.m_tabs.Count; i++)
        {         {
            TabHandler.Tab tab = this.m_tabs[i];             TabHandler.Tab tab = this.m_tabs[i];
            tab.m_button.onClick.AddListener(delegate             tab.m_button.onClick.AddListener(delegate
            {             {
                this.OnClick(tab.m_button);                 this.OnClick(tab.m_button);
            });             });
            Transform transform = tab.m_button.gameObject.transform.Find("Selected");             Transform transform = tab.m_button.gameObject.transform.Find("Selected");
            if (transform)             if (transform)
            {             {
                TMP_Text componentInChildren = transform.GetComponentInChildren<TMP_Text>();                 TMP_Text componentInChildren = transform.GetComponentInChildren<TMP_Text>();
                TMP_Text componentInChildren2 = tab.m_button.GetComponentInChildren<TMP_Text>();                 TMP_Text componentInChildren2 = tab.m_button.GetComponentInChildren<TMP_Text>();
                string text = null;                 string text = null;
                if (componentInChildren2 != null)                 if (componentInChildren2 != null)
                {                 {
                    text = componentInChildren2.text;                     text = componentInChildren2.text;
                }                 }
                else                 else
                {                 {
                    TextMeshProUGUI componentInChildren3 = tab.m_button.GetComponentInChildren<TextMeshProUGUI>();                     TextMeshProUGUI componentInChildren3 = tab.m_button.GetComponentInChildren<TextMeshProUGUI>();
                    if (componentInChildren3 != null)                     if (componentInChildren3 != null)
                    {                     {
                        text = componentInChildren3.text;                         text = componentInChildren3.text;
                    }                     }
                }                 }
                if (componentInChildren != null)                 if (componentInChildren != null)
                {                 {
                    componentInChildren.text = text;                     componentInChildren.text = text;
                }                 }
                else                 else
                {                 {
                    TextMeshProUGUI componentInChildren4 = transform.GetComponentInChildren<TextMeshProUGUI>();                     TextMeshProUGUI componentInChildren4 = transform.GetComponentInChildren<TextMeshProUGUI>();
                    if (componentInChildren4 != null)                     if (componentInChildren4 != null)
                    {                     {
                        componentInChildren4.text = text;                         componentInChildren4.text = text;
                    }                     }
                }                 }
            }             }
            if (tab.m_default)             if (tab.m_default)
            {             {
                num = i;                 num = i;
            }             }
        }         }
        if (num >= 0)         if (num >= 0)
        {         {
            this.SetActiveTab(num, forceSelect, true);             this.SetActiveTab(num, forceSelect, true);
        }         }
        this.gamePad = base.GetComponent<UIGamePad>();         this.gamePad = base.GetComponent<UIGamePad>();
    }     }
   
    private void Update()     private void Update()
    {     {
        int num = 0;         int num = 0;
        if (this.m_gamepadInput && (this.gamePad == null || !this.gamePad.IsBlocked()))         if (this.m_gamepadInput && (this.gamePad == null || !this.gamePad.IsBlocked()))
        {         {
            if (!string.IsNullOrEmpty(this.m_gamepadNavigateLeft) && ZInput.GetButtonDown(this.m_gamepadNavigateLeft))             if (!string.IsNullOrEmpty(this.m_gamepadNavigateLeft) && ZInput.GetButtonDown(this.m_gamepadNavigateLeft))
            {             {
                num = -1;                 num = -1;
            }             }
            else if (!string.IsNullOrEmpty(this.m_gamepadNavigateRight) && ZInput.GetButtonDown(this.m_gamepadNavigateRight))             else if (!string.IsNullOrEmpty(this.m_gamepadNavigateRight) && ZInput.GetButtonDown(this.m_gamepadNavigateRight))
            {             {
                num = 1;                 num = 1;
            }             }
        }         }
        if (this.m_keybaordInput)         if (this.m_keybaordInput)
        {         {
            if (!string.IsNullOrEmpty(this.m_keyboardNavigateLeft) && ZInput.GetButtonDown(this.m_keyboardNavigateLeft))             if (!string.IsNullOrEmpty(this.m_keyboardNavigateLeft) && ZInput.GetButtonDown(this.m_keyboardNavigateLeft))
            {             {
                num = -1;                 num = -1;
            }             }
            else if (!string.IsNullOrEmpty(this.m_keyboardNavigateRight) && ZInput.GetButtonDown(this.m_keyboardNavigateRight))             else if (!string.IsNullOrEmpty(this.m_keyboardNavigateRight) && ZInput.GetButtonDown(this.m_keyboardNavigateRight))
            {             {
                num = 1;                 num = 1;
            }             }
        }         }
        if (this.m_tabKeyInput && ZInput.GetKeyDown(KeyCode.Tab, true))         if (this.m_tabKeyInput && ZInput.GetKeyDown(KeyCode.Tab, true))
        {         {
            num = 1;             num = 1;
        }         }
        if (num != 0)         if (num != 0)
        {         {
            int num2 = this.m_selected + num;             int num2 = this.m_selected + num;
            if (this.m_cycling)             if (this.m_cycling)
            {             {
                if (num2 < 0)                 if (num2 < 0)
                {                 {
                    this.SetActiveTab(this.m_tabs.Count - 1, false, true);                     this.SetActiveTab(this.m_tabs.Count - 1, false, true);
                    return;                     return;
                }                 }
                if (num2 > this.m_tabs.Count - 1)                 if (num2 > this.m_tabs.Count - 1)
                {                 {
                    this.SetActiveTab(0, false, true);                     this.SetActiveTab(0, false, true);
                    return;                     return;
                }                 }
                this.SetActiveTab(num2, false, true);                 this.SetActiveTab(num2, false, true);
                return;                 return;
            }             }
            else             else
            {             {
                this.SetActiveTab(Math.Max(0, Math.Min(this.m_tabs.Count - 1, num2)), false, true);                 this.SetActiveTab(Math.Max(0, Math.Min(this.m_tabs.Count - 1, num2)), false, true);
            }             }
        }         }
    }     }
   
    private void OnClick(Button button)     private void OnClick(Button button)
    {     {
        this.SetActiveTab(button);         this.SetActiveTab(button);
    }     }
   
    private void SetActiveTab(Button button)     private void SetActiveTab(Button button)
    {     {
        for (int i = 0; i < this.m_tabs.Count; i++)         for (int i = 0; i < this.m_tabs.Count; i++)
        {         {
            if (this.m_tabs[i].m_button == button)             if (this.m_tabs[i].m_button == button)
            {             {
                this.SetActiveTab(i, false, true);                 this.SetActiveTab(i, false, true);
                return;                 return;
            }             }
        }         }
    }     }
   
    public void SetActiveTab(int index, bool forceSelect = false, bool invokeOnClick = true)     public void SetActiveTab(int index, bool forceSelect = false, bool invokeOnClick = true)
    {     {
        if (!forceSelect && this.m_selected == index)         if (!forceSelect && this.m_selected == index)
        {         {
            return;             return;
        }         }
        this.m_selected = index;         this.m_selected = index;
        for (int i = 0; i < this.m_tabs.Count; i++)         for (int i = 0; i < this.m_tabs.Count; i++)
        {         {
            TabHandler.Tab tab = this.m_tabs[i];             TabHandler.Tab tab = this.m_tabs[i];
            bool flag = i == index;             bool flag = i == index;
            if (tab.m_page != null)             if (tab.m_page != null)
            {             {
                tab.m_page.gameObject.SetActive(flag);                 tab.m_page.gameObject.SetActive(flag);
            }             }
            tab.m_button.interactable = !flag;             tab.m_button.interactable = !flag;
            Transform transform = tab.m_button.gameObject.transform.Find("Selected");             Transform transform = tab.m_button.gameObject.transform.Find("Selected");
            if (transform)             if (transform)
            {             {
                transform.gameObject.SetActive(flag);                 transform.gameObject.SetActive(flag);
            }             }
            if (flag && invokeOnClick)             if (flag && invokeOnClick)
            {             {
                UnityEvent onClick = tab.m_onClick;                 UnityEvent onClick = tab.m_onClick;
                if (onClick != null)                 if (onClick != null)
                {                 {
                    onClick.Invoke();                     onClick.Invoke();
                }                 }
            }             }
        }         }
        if (ZInput.IsGamepadActive())         if (ZInput.IsGamepadActive())
        {         {
            EffectList setActiveTabEffects = this.m_setActiveTabEffects;             EffectList setActiveTabEffects = this.m_setActiveTabEffects;
            if (setActiveTabEffects != null)             if (setActiveTabEffects != null)
            {             {
                setActiveTabEffects.Create((Player.m_localPlayer != null) ? Player.m_localPlayer.transform.position : Vector3.zero, Quaternion.identity, null, 1f, -1);                 setActiveTabEffects.Create((Player.m_localPlayer != null) ? Player.m_localPlayer.transform.position : Vector3.zero, Quaternion.identity, null, 1f, -1);
            }             }
        }         }
        Action<int> activeTabChanged = this.ActiveTabChanged;         Action<int> activeTabChanged = this.ActiveTabChanged;
        if (activeTabChanged == null)         if (activeTabChanged == null)
        {         {
            return;             return;
        }         }
        activeTabChanged(this.m_selected);         activeTabChanged(this.m_selected);
    }     }
   
    public void SetActiveTabWithoutInvokingOnClick(int index)     public void SetActiveTabWithoutInvokingOnClick(int index)
    {     {
        this.m_selected = index;         this.m_selected = index;
        for (int i = 0; i < this.m_tabs.Count; i++)         for (int i = 0; i < this.m_tabs.Count; i++)
        {         {
            TabHandler.Tab tab = this.m_tabs[i];             TabHandler.Tab tab = this.m_tabs[i];
            bool flag = i == index;             bool flag = i == index;
            if (tab.m_page != null)             if (tab.m_page != null)
            {             {
                tab.m_page.gameObject.SetActive(flag);                 tab.m_page.gameObject.SetActive(flag);
            }             }
            tab.m_button.interactable = !flag;             tab.m_button.interactable = !flag;
            Transform transform = tab.m_button.gameObject.transform.Find("Selected");             Transform transform = tab.m_button.gameObject.transform.Find("Selected");
            if (transform)             if (transform)
            {             {
                transform.gameObject.SetActive(flag);                 transform.gameObject.SetActive(flag);
            }             }
        }         }
    }     }
   
    public int GetActiveTab()     public int GetActiveTab()
    {     {
        return this.m_selected;         return this.m_selected;
    }     }
   
    public event Action<int> ActiveTabChanged;     public event Action<int> ActiveTabChanged;
   
    public bool m_cycling = true;     public bool m_cycling = true;
   
    public bool m_tabKeyInput = true;     public bool m_tabKeyInput = true;
   
    public bool m_keybaordInput;     public bool m_keybaordInput;
   
    public string m_keyboardNavigateLeft = "TabLeft";     public string m_keyboardNavigateLeft = "TabLeft";
   
    public string m_keyboardNavigateRight = "TabRight";     public string m_keyboardNavigateRight = "TabRight";
   
    public bool m_gamepadInput;     public bool m_gamepadInput;
   
    public string m_gamepadNavigateLeft = "JoyTabLeft";     public string m_gamepadNavigateLeft = "JoyTabLeft";
   
    public string m_gamepadNavigateRight = "JoyTabRight";     public string m_gamepadNavigateRight = "JoyTabRight";
   
    public List<TabHandler.Tab> m_tabs = new List<TabHandler.Tab>();     public List<TabHandler.Tab> m_tabs = new List<TabHandler.Tab>();
   
    [Header("Effects")]     [Header("Effects")]
    public EffectList m_setActiveTabEffects = new EffectList();     public EffectList m_setActiveTabEffects = new EffectList();
   
    private int m_selected;     private int m_selected;
   
    private UIGamePad gamePad;     private UIGamePad gamePad;
   
    [Serializable]     [Serializable]
    public class Tab     public class Tab
    {     {
        public Button m_button;         public Button m_button;
   
        public RectTransform m_page;         public RectTransform m_page;
   
        public bool m_default;         public bool m_default;
   
        public UnityEvent m_onClick;         public UnityEvent m_onClick;
    }     }
} }