using System; using System.Collections.Generic; using UnityEngine; namespace Wizard.Dialog.Setting; public class ItemSelect : Item { [SerializeField] private UILabel _title; [SerializeField] private GameObject _state; [SerializeField] private GameObject _separatorLineObj; [SerializeField] private UIButton _button; [SerializeField] private GameObject _list; [SerializeField] private UITable _table; [SerializeField] private BoxCollider _listCollider; private EventDelegate.Callback _onClick; [SerializeField] private GameObject _resolutionItem; [SerializeField] private UIPanel _panel; private string _currentValue; private const int BOTTOM_PADDING = -10; private const int NORMAL_ITEM_SIZE = 188; private Color _originalColor; private const int PANEL_DEPTH_CLOSE = 30; private const int PANEL_DEPTH_OPEN = 50; private UIScrollView _parentScrollView; private List _possibleValues; private List _items; private const int DIRECTION_UP_TABLE_POSITION = 14; private const int DIRECTION_UP_LIST_POSITION = 12; public bool _isOpenDirectionUp; public List PossibleValues => _possibleValues; private void Awake() { _button.onClick.Add(new EventDelegate(delegate { if (_list.activeSelf) { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_CANCEL); } else { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON); } SetListVisible(!_list.activeSelf); })); UIEventListener.Get(_listCollider.gameObject).onPress = delegate { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_CANCEL); SetListVisible(b: false); }; } public void SetPossibleResolutionValues(List possibleValues, bool resizeListSprite) { for (int i = 0; i < possibleValues.Count; i++) { GameObject o = NGUITools.AddChild(_table.gameObject, _resolutionItem); string str = possibleValues[i]; string[] array = str.Split('×'); o.transform.Find("width").gameObject.GetComponent().text = array[0]; o.transform.Find("height").gameObject.GetComponent().text = array[1]; o.SetActive(value: true); if ((bool)_parentScrollView) { o.AddMissingComponent().scrollView = _parentScrollView; } if (resizeListSprite && i == possibleValues.Count - 1) { UISprite component = _list.GetComponent(); component.bottomAnchor.target = o.transform; component.bottomAnchor.relative = 0f; component.bottomAnchor.absolute = -10; } _originalColor = o.GetComponentInChildren().color; UIEventListener.Get(o).onHover = delegate(GameObject g, bool b) { o.GetComponentInChildren().enabled = b; }; UIEventListener.Get(o).onClick = delegate { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON); o.GetComponentInChildren().enabled = false; SetListVisible(b: false); SetResolutionValue(str); if (_onClick != null) { _onClick(); } }; } } public void SetPossibleIdValues(List possibleValues, bool resizeListSprite) { SetPossibleValues(possibleValues, resizeListSprite, (string s) => Data.SystemText.Get(s)); } public void SetPossibleValues(List possibleValues, bool resizeListSprite, Func textChange = null) { if (_possibleValues != null) { _possibleValues.Clear(); } else { _possibleValues = new List(); } if (_items != null) { foreach (GameObject item in _items) { UnityEngine.Object.Destroy(item); } _items.Clear(); } else { _items = new List(); } List list = new List(possibleValues); if (_isOpenDirectionUp) { list.Reverse(); } for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { continue; } GameObject o = NGUITools.AddChild(_table.gameObject, _resolutionItem); _items.Add(o); string str = list[i]; if (textChange != null) { str = textChange(str); } _possibleValues.Add(str); o.transform.Find("width").gameObject.SetActive(value: false); o.transform.Find("height").gameObject.SetActive(value: false); UILabel component = o.transform.Find("center").gameObject.GetComponent(); component.width = 188; component.text = str; o.SetActive(value: true); if ((bool)_parentScrollView) { o.AddMissingComponent().scrollView = _parentScrollView; } _originalColor = o.GetComponentInChildren().color; UIEventListener.Get(o).onHover = delegate(GameObject g, bool b) { o.GetComponentInChildren().enabled = b; }; UIEventListener.Get(o).onClick = delegate { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON); o.GetComponentInChildren().enabled = false; SetListVisible(b: false); SetValue(str); if (_onClick != null) { _onClick(); } }; } if (_isOpenDirectionUp) { _possibleValues.Reverse(); } if (resizeListSprite && _items.Count > 0) { GameObject gameObject = _items[_items.Count - 1]; UISprite component2 = _list.GetComponent(); if (_isOpenDirectionUp) { component2.topAnchor.target = gameObject.transform; component2.topAnchor.relative = 1f; component2.topAnchor.absolute = 10; } else { component2.bottomAnchor.target = gameObject.transform; component2.bottomAnchor.relative = 0f; component2.bottomAnchor.absolute = -10; } } if (_isOpenDirectionUp) { _table.GetComponent().pivot = UIWidget.Pivot.BottomLeft; Vector3 localPosition = _table.transform.localPosition; localPosition.y = 14f; _table.transform.localPosition = localPosition; _table.direction = UITable.Direction.Up; _list.GetComponent().pivot = UIWidget.Pivot.Bottom; Vector3 localPosition2 = _list.transform.localPosition; localPosition2.y = 12f; _list.transform.localPosition = localPosition2; } _table.repositionNow = true; _list.GetComponent().ResetAndUpdateAnchors(); } private void SetListVisible(bool b) { _list.SetActive(b); _listCollider.enabled = b; _panel.depth = (b ? 50 : 30); UISprite component = _list.GetComponent(); component.ResetAndUpdateAnchors(); component.gameObject.SetActive(b); } public void SetResolutionValue(string value) { _currentValue = value; string[] array = value.Split('×'); _state.transform.Find("width").gameObject.GetComponent().text = array[0]; _state.transform.Find("height").gameObject.GetComponent().text = array[1]; } public void SetValue(string value) { _currentValue = value; _state.transform.Find("width").gameObject.SetActive(value: false); _state.transform.Find("height").gameObject.SetActive(value: false); UILabel component = _state.transform.Find("center").gameObject.GetComponent(); component.width = 188; component.text = value; } public string GetValue() { return _currentValue; } public void SetTitleLabel(string title) { _title.text = title; } public override void AddChangeCallback(EventDelegate.Callback callback) { _onClick = (EventDelegate.Callback)Delegate.Combine(_onClick, callback); } public override void SetActive_SeparatorLine(bool isActive) { _separatorLineObj.SetActive(isActive); } public void SetTitleTextLocalPos(Vector3 localPos) { _title.transform.localPosition = localPos; } public void SetToGrey(bool b) { UIManager.SetObjectToGrey(base.gameObject, b); UIManager.SetObjectToGrey(_separatorLineObj, b: false); UISprite[] componentsInChildren = _table.GetComponentsInChildren(includeInactive: true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].color = _originalColor; } } public void SetScrollView(UIScrollView view) { _listCollider.gameObject.AddMissingComponent().scrollView = view; _parentScrollView = view; _button.gameObject.AddMissingComponent().scrollView = view; } }