96 lines
2.5 KiB
C#
96 lines
2.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Logic.Multilingual;
|
|
using TH1_Logic.Core;
|
|
using TH1_Logic.Net;
|
|
using TH1_Logic.Steam;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIOutsideSelectOptionGroupMono : MonoBehaviour
|
|
{
|
|
|
|
|
|
public List<Button> options = new List<Button>();
|
|
public RectTransform SelectBG;
|
|
public bool Passive;
|
|
public Action<uint> OnOptionClicked;
|
|
|
|
public uint SelectedIndex => _selectedIndex;
|
|
|
|
private uint _selectedIndex;
|
|
private bool _firstShow;
|
|
private Color _blue = new Color32(65,59,107,255);
|
|
public void Init(uint defaultIndex)
|
|
{
|
|
_selectedIndex = defaultIndex;
|
|
_firstShow = false;
|
|
for (int i = 0; i < options.Count; i++)
|
|
{
|
|
options[i].onClick.RemoveAllListeners();
|
|
uint index = (uint)i;
|
|
if(!Passive)
|
|
options[i].onClick.AddListener(() =>
|
|
{
|
|
Select(index);
|
|
OnOptionClicked?.Invoke((uint)index);
|
|
});
|
|
else
|
|
{
|
|
if (i == defaultIndex)
|
|
Select((uint)i);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void OnShow()
|
|
{
|
|
if (_firstShow) return;
|
|
_firstShow = true;
|
|
Select(_selectedIndex);
|
|
}
|
|
public string GetSelectedString()
|
|
{
|
|
if (options.Count <= _selectedIndex) return "";
|
|
return options[(int)_selectedIndex].gameObject.GetComponent<TextMeshProUGUI>()?.text;
|
|
}
|
|
|
|
|
|
public void Select(uint index)
|
|
{
|
|
if (index >= options.Count) return;
|
|
for(int i = 0;i < options.Count; i++)
|
|
if (i == index)
|
|
{
|
|
var pos = options[i].gameObject.GetComponent<RectTransform>().anchoredPosition;
|
|
var text = options[i].gameObject.GetComponent<TextMeshProUGUI>();
|
|
if(text != null)text.color = Color.white;
|
|
SelectBG.anchoredPosition = pos;
|
|
Debug.LogWarning("Found!!!!");
|
|
}
|
|
else
|
|
{
|
|
var text = options[i].gameObject.GetComponent<TextMeshProUGUI>();
|
|
if (text != null)
|
|
text.color = Passive ? Color.gray : _blue;
|
|
//text.color = Color.black;
|
|
|
|
}
|
|
_selectedIndex = index;
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|