123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- 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<uGUICanvasFade>();
- }
- return this.m_uGUICanvasFade;
- }
- }
- private void Init()
- {
- if (this.m_IsInit)
- {
- return;
- }
- this.m_IsInit = true;
- this.m_UIListBanner.tempItem.AddComponent<LifeModeChangeWindow.BannerEnterHandler>();
- 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.<OpenWindow>c__AnonStorey0 <OpenWindow>c__AnonStorey = new LifeModeChangeWindow.<OpenWindow>c__AnonStorey0();
- <OpenWindow>c__AnonStorey.$this = this;
- this.uGUICanvasFade.interactable = false;
- this.uGUICanvasFade.blocksRaycasts = true;
- this.uGUICanvasFade.alpha = 0f;
- this.uGUICanvasFade.FadeIn(0.3f, delegate
- {
- <OpenWindow>c__AnonStorey.$this.uGUICanvasFade.interactable = true;
- });
- this.UpdateNowSelectType();
- Dictionary<GameModeManager.Type, GameModeManager.Data> dataDic = GameModeManager.DataDic;
- <OpenWindow>c__AnonStorey.keyList = new List<GameModeManager.Type>(dataDic.Keys);
- <OpenWindow>c__AnonStorey.valueList = new List<GameModeManager.Data>(dataDic.Values);
- this.m_UIListBanner.Show<Toggle>(dataDic.Count, delegate(int index, Toggle toggle)
- {
- GameModeManager.Type dataType = <OpenWindow>c__AnonStorey.keyList[index];
- GameModeManager.Data data = <OpenWindow>c__AnonStorey.valueList[index];
- if (toggle.image != null)
- {
- Sprite spriteInAtlas = <OpenWindow>c__AnonStorey.$this.GetSpriteInAtlas(<OpenWindow>c__AnonStorey.$this.m_UIAtlasBusinessBannger, data.strBannerImageName);
- if (spriteInAtlas != null)
- {
- toggle.image.sprite = spriteInAtlas;
- }
- }
- if (dataType == <OpenWindow>c__AnonStorey.$this.m_NowSelectType)
- {
- toggle.isOn = true;
- }
- toggle.onValueChanged.AddListener(delegate(bool value)
- {
- if (!value)
- {
- return;
- }
- <OpenWindow>c__AnonStorey.SetNowSelectType(dataType);
- <OpenWindow>c__AnonStorey.UpdateBannerList();
- });
- LifeModeChangeWindow.BannerEnterHandler component = toggle.GetComponent<LifeModeChangeWindow.BannerEnterHandler>();
- component.onPointerEnter = delegate()
- {
- <OpenWindow>c__AnonStorey.UpdateDescription(data.strDescription, data.termDescription);
- };
- component.onPointerExit = delegate()
- {
- <OpenWindow>c__AnonStorey.UpdateDescription(GameModeManager.GetData(<OpenWindow>c__AnonStorey.m_NowSelectType).strDescription, GameModeManager.GetData(<OpenWindow>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<LifeModeChangeWindow.BannerEnterHandler>();
- 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<Sprite> list = new List<Sprite>(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<string, Sprite> m_SpriteDic = new Dictionary<string, Sprite>();
- private class BannerEnterHandler : UIBehaviour, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler
- {
- public Toggle toggle
- {
- get
- {
- if (this.m_Toggle == null)
- {
- this.m_Toggle = base.gameObject.GetComponentInChildren<Toggle>();
- }
- 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;
- }
- }
|