384 lines
9.8 KiB
C#
384 lines
9.8 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-08
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "MainWindow.View" company="Kimch"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class MainWindow
|
|
{
|
|
public enum PageType
|
|
{
|
|
World = 0,
|
|
Kungfu = 1,
|
|
Map = 2,
|
|
Cha = 3,
|
|
Shop = 4,
|
|
}
|
|
|
|
#region Field
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
ToggleGroup __goToggles;
|
|
[KUIFlag]
|
|
GameObject __goPanels;
|
|
[KUIFlag]
|
|
GameObject __goTop;
|
|
|
|
[KUIFlag]
|
|
GameObject __goMainMission;
|
|
[KUIFlag]
|
|
GameObject __goFunction;
|
|
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private Toggle[] _toggles;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private GameObject[] _panels;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private TopWidget _topWidget;
|
|
/// <summary>
|
|
/// 功能区域
|
|
/// </summary>
|
|
private FunctionWidget _functionWidget;
|
|
//主线任务模块
|
|
private MainMissionWidget _missionWidget2;
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public PageType pageType
|
|
{
|
|
get;
|
|
private set;
|
|
} = PageType.Map;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
|
|
var panelCanvas = __goPanels.GetComponent<Canvas>();
|
|
panelCanvas.overrideSorting = true;
|
|
panelCanvas.sortingOrder = 96;
|
|
|
|
_topWidget = __goTop.AddComponent<TopWidget>();
|
|
_missionWidget2 = __goMainMission.AddComponent<MainMissionWidget>();
|
|
_functionWidget = __goFunction.AddComponent<FunctionWidget>();
|
|
|
|
//var childCount = __goPanels.transform.childCount;
|
|
//_panels = new GameObject[childCount];
|
|
//for (int i = 0; i < childCount; i++)
|
|
//{
|
|
// _panels[i] = __goPanels.transform.GetChild(i).gameObject;
|
|
//}
|
|
|
|
_toggles = __goToggles.GetComponentsInChildren<Toggle>();
|
|
for (int i = 0; i < _toggles.Length; i++)
|
|
{
|
|
_toggles[i].onValueChanged.AddListener(this.OnToggleValueChanged);
|
|
}
|
|
|
|
_panels = new GameObject[_toggles.Length];
|
|
_panels[2] = __goPanels.transform.GetChild(0).gameObject;
|
|
//for (int i = 0; i < _panels.Length; i++)
|
|
//{
|
|
// _panels[i] = __goPanels.transform.GetChild(0).gameObject;
|
|
//}
|
|
|
|
StartCoroutine(LoadPanel("ui_w_main_kungfu", (int)PageType.Kungfu));
|
|
StartCoroutine(LoadPanel("ui_w_main_cha", (int)PageType.Cha));
|
|
StartCoroutine(LoadPanel("ui_w_main_world", (int)PageType.World));
|
|
StartCoroutine(LoadPanel("ui_w_main_shop", (int)PageType.Shop));
|
|
//
|
|
this.ShowPanel((int)PageType.Map);
|
|
}
|
|
|
|
private System.Collections.IEnumerator LoadPanel(string name, int index)
|
|
{
|
|
for (int i = 5 - index; i >= 0; i--)
|
|
{
|
|
yield return null;
|
|
}
|
|
yield return null;
|
|
yield return null;
|
|
yield return null;
|
|
//var handle = AssetProxy.Instance.TryGetTemporaryAssetAsync<GameObject>(name);
|
|
var handle = AssetProxy.Instance.TryInstantiateAsync(name, __goPanels.transform);
|
|
yield return handle;
|
|
//var panelGO = Object.Instantiate(handle.Result);
|
|
var panelGO = handle.Result;
|
|
panelGO.SetActive(false);
|
|
panelGO.name = name;
|
|
//panelGO.transform.SetParent(__goPanels.transform, false);
|
|
panelGO.transform.SetSiblingIndex(index);
|
|
_panels[index] = panelGO;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void RefreshView()
|
|
{
|
|
RefreshUnlock();
|
|
RefreshMission();
|
|
}
|
|
|
|
public void RefreshMission()
|
|
{
|
|
var mission = MissionProxy.Instance.mainMission;
|
|
_missionWidget2.SetData(mission);
|
|
}
|
|
|
|
private void RefreshUnlock()
|
|
{
|
|
SetSystemUnlock((int)PageType.World, FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Jianghu));
|
|
SetSystemUnlock((int)PageType.Kungfu, FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Kungfu));
|
|
//SetSystemUnlock((int)PageType.Cha, FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Cha));
|
|
SetSystemUnlock((int)PageType.Shop, FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Shop));
|
|
|
|
var nextFunction = FunctionProxy.Instance.GetNextFunction();
|
|
_functionWidget.SetData(nextFunction);
|
|
}
|
|
|
|
private void SetSystemUnlock(int index, bool unlock)
|
|
{
|
|
if (_toggles[index].group == unlock)
|
|
return;
|
|
#if UNITY_EDITOR
|
|
Debug.Log("Unlock System " + index);
|
|
#endif
|
|
_toggles[index].onValueChanged.RemoveAllListeners();
|
|
var redPoint = _toggles[index].transform.Find("!RedPoint");
|
|
if (redPoint)
|
|
{
|
|
redPoint.gameObject.SetActive(unlock);
|
|
}
|
|
var icon = _toggles[index].transform.Find("Background/Image");
|
|
if (icon)
|
|
{
|
|
var gray = icon.GetComponent<KUIGray>();
|
|
if (gray)
|
|
gray.SetGray(!unlock);
|
|
}
|
|
|
|
if (unlock)
|
|
{
|
|
_toggles[index].group = __goToggles;
|
|
_toggles[index].onValueChanged.AddListener(this.OnToggleValueChanged);
|
|
}
|
|
else
|
|
{
|
|
_toggles[index].group = null;
|
|
if (index == 0)
|
|
_toggles[index].onValueChanged.AddListener(this.OnLockedToggleValueChanged0);
|
|
else if (index == 1)
|
|
_toggles[index].onValueChanged.AddListener(this.OnLockedToggleValueChanged1);
|
|
else if (index == 3)
|
|
_toggles[index].onValueChanged.AddListener(this.OnLockedToggleValueChanged3);
|
|
else if (index == 4)
|
|
_toggles[index].onValueChanged.AddListener(this.OnLockedToggleValueChanged4);
|
|
}
|
|
}
|
|
|
|
//public void FunctionUnlockStart(int index)//功能开启动画使用
|
|
//{
|
|
// Debug.Log("传进来数值:" + index);
|
|
// var icon = _toggles[index].transform.Find("Background/Image");
|
|
// if (icon)
|
|
// {
|
|
// Debug.Log("传进来4时可以进入");
|
|
// var gray = icon.GetComponent<KUIGray>();
|
|
// if (gray)
|
|
// {
|
|
// Debug.Log("获取到组件没问题");
|
|
// gray.SetGray(false);
|
|
// }
|
|
// }
|
|
//}
|
|
//public void FunctionUnlockEnd(int index)
|
|
//{
|
|
// var icon = _toggles[index].transform.Find("Background/Image");
|
|
// if (icon)
|
|
// {
|
|
// var gray = icon.GetComponent<KUIGray>();
|
|
// if (gray)
|
|
// gray.SetGray(true);
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sortingOrder">0 还原</param>
|
|
public void ShowTop(int sortingOrder)
|
|
{
|
|
__goTop.SetActive(true);
|
|
var topCanvas = __goTop.GetComponent<Canvas>();
|
|
if (sortingOrder > 0)
|
|
{
|
|
topCanvas.overrideSorting = true;
|
|
topCanvas.sortingOrder = sortingOrder;
|
|
}
|
|
else
|
|
{
|
|
topCanvas.overrideSorting = false;
|
|
}
|
|
}
|
|
|
|
public void OpenPage(int index, object data)
|
|
{
|
|
_toggles[index].isOn = true;
|
|
if ((int)PageType.Map == index && "reload".Equals(data))
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void ShowPanel(int index)
|
|
{
|
|
if (_panels != null && index >= 0 && index < _panels.Length)
|
|
{
|
|
var panel = _panels[index];
|
|
if (panel && !panel.name.StartsWith("*"))
|
|
{
|
|
this.pageType = (PageType)index;
|
|
panel.SetActive(true);
|
|
|
|
for (int i = 0; i < _panels.Length; i++)
|
|
{
|
|
if (i != index)
|
|
{
|
|
if (_panels[i])
|
|
_panels[i].SetActive(false);
|
|
}
|
|
}
|
|
|
|
// 主界面
|
|
var isMapPage = index == (int)PageType.Map;
|
|
__goMainMission.SetActive(isMapPage);
|
|
__goFunction.SetActive(isMapPage);
|
|
|
|
_topWidget.OnPageChange(index);
|
|
|
|
KStatistics.Instance.ReportButtonClick("主界面button", panel.name);
|
|
}
|
|
else
|
|
{
|
|
//OpenWindow<TipsBox>("暂未开放");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnToggleValueChanged(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
int index = 0;
|
|
for (int i = 0; i < _toggles.Length; i++)
|
|
{
|
|
if (_toggles[i].isOn)
|
|
{
|
|
index = i;
|
|
break;
|
|
}
|
|
}
|
|
this.ShowPanel(index);
|
|
|
|
for (int i = 0; i < _toggles.Length; i++)
|
|
{
|
|
_toggles[i].GetComponent<LayoutElement>().minWidth = _toggles[i].isOn ? 280f : 170f;
|
|
_toggles[i].graphic.gameObject.SetActive(_toggles[i].isOn);
|
|
_toggles[i].targetGraphic.gameObject.SetActive(!_toggles[i].isOn);
|
|
}
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
}
|
|
|
|
private void OnLockedToggleValueChanged0(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Jianghu);
|
|
if (function != null)
|
|
ToastBox.ShowText(function.lockTips);
|
|
}
|
|
//写死的 注意后面
|
|
_toggles[(int)PageType.World].isOn = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 未解锁
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
private void OnLockedToggleValueChanged1(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Kungfu);
|
|
if (function != null)
|
|
ToastBox.ShowText(function.lockTips);
|
|
}
|
|
//写死的 注意后面
|
|
_toggles[(int)PageType.Kungfu].isOn = false;
|
|
}
|
|
|
|
private void OnLockedToggleValueChanged3(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Cha);
|
|
if (function != null)
|
|
ToastBox.ShowText(function.lockTips);
|
|
}
|
|
//写死的 注意后面
|
|
_toggles[(int)PageType.Cha].isOn = false;
|
|
}
|
|
|
|
private void OnLockedToggleValueChanged4(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Shop);
|
|
if (function != null)
|
|
ToastBox.ShowText(function.lockTips);
|
|
}
|
|
//写死的 注意后面
|
|
_toggles[(int)PageType.Shop].isOn = false;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|