using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; using wf; public class LifeModeChangeWindow : MonoBehaviour { private void UpdateNowSelectType() { this.m_NowSelectType = GameModeManager.nowGameMode; } private void SetNowSelectType(GameModeManager.Type type) { this.m_NowSelectType = type; } private void SetNowGameMode() { GameModeManager.nowGameMode = this.m_NowSelectType; } private uGUICanvasFade uGUICanvasFade { get { if (this.m_uGUICanvasFade == null) { this.m_uGUICanvasFade = base.GetComponent(); } return this.m_uGUICanvasFade; } } private void Init() { if (this.m_IsInit) { return; } this.m_IsInit = true; this.m_UIListBanner.tempItem.AddComponent(); this.m_ButtonClose.onClick.AddListener(new UnityAction(this.CloseWindow)); } private void Start() { if (this.m_IsInit) { return; } this.Init(); this.uGUICanvasFade.FadeOut(0f, null); base.gameObject.SetActive(false); } public void Open(Action callback) { this.Init(); this.m_CallbackCloseWindow = callback; this.OpenWindow(); } private void OpenWindow() { LifeModeChangeWindow.c__AnonStorey0 c__AnonStorey = new LifeModeChangeWindow.c__AnonStorey0(); c__AnonStorey.$this = this; this.uGUICanvasFade.interactable = false; this.uGUICanvasFade.blocksRaycasts = true; this.uGUICanvasFade.alpha = 0f; this.uGUICanvasFade.FadeIn(0.3f, delegate { c__AnonStorey.$this.uGUICanvasFade.interactable = true; }); this.UpdateNowSelectType(); Dictionary dataDic = GameModeManager.DataDic; c__AnonStorey.keyList = new List(dataDic.Keys); c__AnonStorey.valueList = new List(dataDic.Values); this.m_UIListBanner.Show(dataDic.Count, delegate(int index, Toggle toggle) { GameModeManager.Type dataType = c__AnonStorey.keyList[index]; GameModeManager.Data data = c__AnonStorey.valueList[index]; if (toggle.image != null) { Sprite spriteInAtlas = c__AnonStorey.$this.GetSpriteInAtlas(c__AnonStorey.$this.m_UIAtlasBusinessBannger, data.strBannerImageName); if (spriteInAtlas != null) { toggle.image.sprite = spriteInAtlas; } } if (dataType == c__AnonStorey.$this.m_NowSelectType) { toggle.isOn = true; } toggle.onValueChanged.AddListener(delegate(bool value) { if (!value) { return; } c__AnonStorey.SetNowSelectType(dataType); c__AnonStorey.UpdateBannerList(); }); LifeModeChangeWindow.BannerEnterHandler component = toggle.GetComponent(); component.onPointerEnter = delegate() { c__AnonStorey.UpdateDescription(data.strDescription, data.termDescription); }; component.onPointerExit = delegate() { c__AnonStorey.UpdateDescription(GameModeManager.GetData(c__AnonStorey.m_NowSelectType).strDescription, GameModeManager.GetData(c__AnonStorey.m_NowSelectType).termDescription); }; }); this.UpdateDescription(GameModeManager.GetData().strDescription, GameModeManager.GetData().termDescription); this.UpdateBannerList(); } private void UpdateBannerList() { foreach (GameObject gameObject in this.m_UIListBanner.ItemArray) { LifeModeChangeWindow.BannerEnterHandler component = gameObject.GetComponent(); component.UpdateColorBlock(); component.toggle.interactable = !component.toggle.isOn; } } private void UpdateDescription(string msg, string termText) { this.m_UITextDescription.text = msg; Utility.SetLocalizeTerm(this.m_UITextDescription, termText, false); } public void CloseWindow() { this.SetNowGameMode(); if (this.m_CallbackCloseWindow != null) { this.m_CallbackCloseWindow(); this.m_CallbackCloseWindow = null; } this.uGUICanvasFade.interactable = false; this.uGUICanvasFade.FadeOut(0.3f, delegate { base.gameObject.SetActive(false); this.uGUICanvasFade.blocksRaycasts = false; this.uGUICanvasFade.alpha = 0f; }); } private Sprite GetSpriteInAtlas(UIAtlas atlas, string resourceName) { Sprite sprite = null; if (this.m_SpriteDic.TryGetValue(resourceName, out sprite)) { return sprite; } sprite = uGUIUtility.GetSpriteInAtlas(atlas, resourceName); this.m_SpriteDic.Add(resourceName, sprite); return sprite; } private void OnDestroy() { if (this == null) { return; } if (base.gameObject == null) { return; } if (this.m_SpriteDic != null) { int count = this.m_SpriteDic.Count; List list = new List(this.m_SpriteDic.Values); for (int i = count - 1; i >= 0; i--) { UnityEngine.Object.Destroy(list[i]); } this.m_SpriteDic.Clear(); list.Clear(); } } private GameModeManager.Type m_NowSelectType; [SerializeField] private uGUIListViewer m_UIListBanner; [SerializeField] private Text m_UITextDescription; [SerializeField] private Button m_ButtonClose; private uGUICanvasFade m_uGUICanvasFade; private Action m_CallbackCloseWindow; private bool m_IsInit; [SerializeField] private UIAtlas m_UIAtlasBusinessBannger; private Dictionary m_SpriteDic = new Dictionary(); private class BannerEnterHandler : UIBehaviour, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler { public Toggle toggle { get { if (this.m_Toggle == null) { this.m_Toggle = base.gameObject.GetComponentInChildren(); } return this.m_Toggle; } } protected override void Start() { this.InitColorBlock(); } private void InitColorBlock() { if (this.m_IsInitColorBlock) { return; } this.m_IsInitColorBlock = true; this.m_ColorBlockDefault = this.toggle.colors; this.m_ColorBlockSelected = this.toggle.colors; this.m_ColorBlockSelected.normalColor = this.m_ColorBlockSelected.highlightedColor; this.m_ColorBlockSelected.disabledColor = this.m_ColorBlockSelected.highlightedColor; this.m_ColorBlockSelected.pressedColor = this.m_ColorBlockSelected.highlightedColor; } public void OnPointerEnter(PointerEventData eventData) { if (this.IsSelecting()) { return; } if (this.onPointerEnter != null) { this.onPointerEnter(); } } public void OnPointerExit(PointerEventData eventData) { if (this.IsSelecting()) { return; } if (this.onPointerExit != null) { this.onPointerExit(); } } private bool IsSelecting() { return this.toggle.isOn; } public void UpdateColorBlock() { this.InitColorBlock(); bool flag = this.IsSelecting(); this.toggle.colors = ((!flag) ? this.m_ColorBlockDefault : this.m_ColorBlockSelected); } public Action onPointerEnter; public Action onPointerExit; private ColorBlock m_ColorBlockDefault; private ColorBlock m_ColorBlockSelected; private Toggle m_Toggle; private bool m_IsInitColorBlock; } }