123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using wf;
- public class SelectButtonCtrl : MonoBehaviour
- {
- public void Awake()
- {
- if (this.Panel == null)
- {
- this.Panel = base.transform.parent.gameObject.GetComponent<UIPanel>();
- }
- this.grid = base.GetComponent<UIGrid>();
- this.scrollView = base.transform.parent.GetComponent<UIScrollView>();
- }
- public void CreateSelectButtons(List<KeyValuePair<string, KeyValuePair<string, bool>>> listSelectBtn, Action<string, string> onClickCallBack, UnityEngine.Object selectBtnPrefab)
- {
- this.grid.cellHeight = 0f;
- this.m_OnClickCallBack = null;
- this.m_OnClickCallEvent = null;
- this.ClearExistSelectButton();
- this.m_OnClickCallBack = onClickCallBack;
- this.m_listSelectBtn = new List<KeyValuePair<string, SelectButtonCtrl.SelectButton>>();
- int num = 0;
- foreach (KeyValuePair<string, KeyValuePair<string, bool>> keyValuePair in listSelectBtn)
- {
- GameObject gameObject = UnityEngine.Object.Instantiate(selectBtnPrefab) as GameObject;
- for (int i = 0; i < gameObject.transform.childCount; i++)
- {
- UIButton component = gameObject.transform.GetChild(i).GetComponent<UIButton>();
- EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.ClickSelectButton));
- component.isEnabled = keyValuePair.Value.Value;
- }
- gameObject.name = "selectButton_" + num;
- gameObject.transform.parent = base.transform;
- gameObject.transform.localScale = Vector3.one;
- gameObject.transform.localPosition = Vector3.zero;
- gameObject.transform.rotation = Quaternion.identity;
- SubtitleDisplayManager component2 = gameObject.GetComponent<SubtitleDisplayManager>();
- if (component2 != null)
- {
- component2.SetTextFromScriptStyle(keyValuePair.Key);
- }
- else
- {
- UILabel component3 = UTY.GetChildObject(gameObject, "Single/Option", false).GetComponent<UILabel>();
- component3.text = MessageClass.GetTranslationText(keyValuePair.Key).Key;
- }
- SelectButtonCtrl.SelectButton selectButton = new SelectButtonCtrl.SelectButton();
- selectButton.m_btnName = gameObject.name;
- selectButton.m_goSelectBtn = gameObject;
- selectButton.m_msg = keyValuePair.Key;
- selectButton.m_tag = keyValuePair.Value.Key;
- if (GameMain.Instance.VRMode)
- {
- UIButton[] componentsInChildren = gameObject.GetComponentsInChildren<UIButton>(true);
- foreach (UIButton uibutton in componentsInChildren)
- {
- uibutton.defaultColor = new Color(0.8f, 0.8f, 0.8f, 1f);
- }
- }
- this.m_listSelectBtn.Add(new KeyValuePair<string, SelectButtonCtrl.SelectButton>(selectButton.m_btnName, selectButton));
- num++;
- }
- Utility.ResetNGUI(this.grid);
- this.scrollView.verticalScrollBar.gameObject.SetActive(true);
- Utility.ResetNGUI(this.scrollView);
- this.scrollView.verticalScrollBar.value = 0f;
- this.scrollView.verticalScrollBar.alpha = 0f;
- this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
- base.StartCoroutine("FadeIn");
- }
- private IEnumerator FadeIn()
- {
- this.scrollView.GetComponent<UIPanel>().alpha = 0f;
- yield return null;
- yield return null;
- this.scrollView.GetComponent<UIPanel>().alpha = 1f;
- yield break;
- }
- public void SetPanelAlpha(float value)
- {
- this.Awake();
- this.Panel.alpha = value;
- }
- public bool IsPlayingEffect()
- {
- return this.m_EffectStat != SelectButtonCtrl.EffectStat.Null;
- }
- public void ClearExistSelectButton()
- {
- IEnumerator enumerator = base.transform.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj = enumerator.Current;
- Transform transform = (Transform)obj;
- UnityEngine.Object.Destroy(transform.gameObject);
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- }
- public void ClickSelectButton()
- {
- string b = string.Empty;
- b = UIButton.current.transform.parent.name;
- foreach (KeyValuePair<string, SelectButtonCtrl.SelectButton> keyValuePair in this.m_listSelectBtn)
- {
- GameObject goSelectBtn = keyValuePair.Value.m_goSelectBtn;
- if (keyValuePair.Key == b)
- {
- TweenAlpha tweenAlpha;
- if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
- {
- tweenAlpha = TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
- }
- else
- {
- tweenAlpha = TweenAlpha.Begin(keyValuePair.Value.m_goSelectBtn, 1f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
- }
- EventDelegate.Set(tweenAlpha.onFinished, new EventDelegate.Callback(this.OnFinished));
- if (this.m_OnClickCallBack != null)
- {
- string text = keyValuePair.Value.m_msg;
- string tag = keyValuePair.Value.m_tag;
- Action<string, string> tmp = this.m_OnClickCallBack;
- this.m_OnClickCallEvent = delegate()
- {
- tmp(text, tag);
- };
- this.m_OnClickCallBack = null;
- }
- }
- else
- {
- for (int i = 0; i < goSelectBtn.transform.childCount; i++)
- {
- TweenAlpha component = goSelectBtn.transform.GetChild(i).GetComponent<TweenAlpha>();
- component.onFinished = null;
- }
- if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
- {
- TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
- }
- else
- {
- TweenAlpha.Begin(goSelectBtn, 0.3f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
- }
- }
- BoxCollider[] componentsInChildren = goSelectBtn.GetComponentsInChildren<BoxCollider>();
- foreach (BoxCollider boxCollider in componentsInChildren)
- {
- boxCollider.enabled = false;
- }
- }
- this.scrollView.verticalScrollBar.alpha = 0f;
- this.scrollView.verticalScrollBar.gameObject.SetActive(false);
- this.m_EffectStat = SelectButtonCtrl.EffectStat.EndOut;
- }
- private void OnFinished()
- {
- if (this.dragMat == null)
- {
- this.dragMat = base.transform.parent.parent.Find("DragMat").gameObject;
- }
- this.dragMat.SetActive(false);
- this.ClearExistSelectButton();
- this.grid.cellHeight = 93f;
- Utility.ResetNGUI(this.scrollView);
- this.scrollView.verticalScrollBar.alpha = 0f;
- this.scrollView.verticalScrollBar.value = 0f;
- this.scrollView.verticalScrollBar.gameObject.SetActive(false);
- this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
- if (this.m_OnClickCallEvent != null)
- {
- this.m_OnClickCallEvent();
- }
- this.m_OnClickCallEvent = null;
- }
- private void Update()
- {
- if (this.scrollRest)
- {
- Utility.ResetNGUI(this.scrollView);
- this.scrollView.verticalScrollBar.value = 0f;
- this.scrollView.verticalScrollBar.alpha = 0f;
- this.scrollView.verticalScrollBar.ForceUpdate();
- this.scrollRest = false;
- }
- if (GameMain.Instance.CMSystem.SubtitleType == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle && this.grid.cellHeight != 110f)
- {
- this.grid.cellHeight = 110f;
- Utility.ResetNGUI(this.grid);
- this.scrollRest = true;
- }
- else if (GameMain.Instance.CMSystem.SubtitleType != SubtitleDisplayManager.DisplayType.OriginalAndSubtitle && this.grid.cellHeight != 93f)
- {
- this.grid.cellHeight = 93f;
- Utility.ResetNGUI(this.grid);
- this.scrollRest = true;
- }
- }
- [SerializeField]
- private GameObject dragMat;
- private UIPanel Panel;
- private List<KeyValuePair<string, SelectButtonCtrl.SelectButton>> m_listSelectBtn;
- private Action<string, string> m_OnClickCallBack;
- private Action m_OnClickCallEvent;
- private SelectButtonCtrl.EffectStat m_EffectStat;
- private UIGrid grid;
- private UIScrollView scrollView;
- private bool scrollRest;
- private enum EffectStat
- {
- Null,
- StartIn,
- EndOut
- }
- private class SelectButton
- {
- public string m_btnName { get; set; }
- public string m_msg { get; set; }
- public string m_tag { get; set; }
- public GameObject m_goSelectBtn { get; set; }
- public override string ToString()
- {
- return string.Format("SelectButton=[m_btnName={0}, m_msg={1}, m_tag={2}, m_goSelectBtn={3}]", new object[]
- {
- this.m_btnName,
- this.m_msg,
- this.m_tag,
- this.m_goSelectBtn
- });
- }
- }
- }
|