159 lines
4.0 KiB
C#
159 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using GCGame.Table;
|
|
|
|
public class WeddingCarPanelCtr : MonoBehaviour {
|
|
|
|
public static WeddingCarPanelCtr Instance;
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
InitMenuItemContainer();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
ReqCurSceneWeddigCarState();
|
|
}
|
|
|
|
public UIContainerSelect _MenuItemContainer;
|
|
public Text _Desc;
|
|
public Text _BtnDesc;
|
|
public UIImgText _CostVal;
|
|
public Image _MoneyIcon;
|
|
|
|
void InitMenuItemContainer()
|
|
{
|
|
List<int> tabIdList = new List<int>();
|
|
foreach(var item in TableManager.GetWeddingCarConfig())
|
|
{
|
|
if (!tabIdList.Contains(item.Key))
|
|
tabIdList.Add(item.Key);
|
|
}
|
|
|
|
if (tabIdList.Count > 0)
|
|
_MenuItemContainer.InitSelectContent(tabIdList, new List<int> { tabIdList [0]}, OnMenuItemClick);
|
|
}
|
|
|
|
private int _CurSelectType = -1;
|
|
public void OnMenuItemClick(object param)
|
|
{
|
|
_CurSelectType = (int)param;
|
|
// ShowMarkIcon(_CurSelectType);
|
|
|
|
var tab = TableManager.GetWeddingCarConfigByID(_CurSelectType, 0);
|
|
if (tab == null)
|
|
{
|
|
Debug.LogError("WeddingCarConfig tab is null : " + _CurSelectType);
|
|
return;
|
|
}
|
|
InitMoneyIcon(tab.CostMoneyType);
|
|
var strId = "#{" + tab.StrId + "}";
|
|
_Desc.text = StrDictionary.GetClientDictionaryString(strId);
|
|
_CostVal.text = tab.CostMoneyVal + "";
|
|
}
|
|
|
|
int _CurMoneyType = -1;
|
|
void InitMoneyIcon(int type)
|
|
{
|
|
if (_CurMoneyType == type)
|
|
return;
|
|
|
|
_CurMoneyType = type;
|
|
LoadAssetBundle.Instance.SetImageSprite(_MoneyIcon, PlayerData.MONEY.GetMoneySpriteStr((MONEYTYPE)type));
|
|
}
|
|
|
|
void ShowMarkIcon(int type)
|
|
{
|
|
_MenuItemContainer.ForeachActiveItem<WeddingCarMenuItem>((item) => {
|
|
item._SelectGO.SetActive(item._CurType == type);
|
|
});
|
|
}
|
|
|
|
public void ReqCurSceneWeddigCarState()
|
|
{
|
|
ReqWeddingCarState req = new ReqWeddingCarState();
|
|
req._SceneInsId = SceneData.SceneInst;
|
|
req.SendMsg();
|
|
}
|
|
|
|
public void OnRemainTimePacket(int endTime)
|
|
{
|
|
if(endTime == -1 || GlobalData.ServerAnsiTime > endTime)
|
|
SetText(0);
|
|
else
|
|
StartCoroutine(CountRemainTime(endTime));
|
|
}
|
|
|
|
IEnumerator CountRemainTime(int endTime)
|
|
{
|
|
while(true)
|
|
{
|
|
yield return new WaitForSeconds(1.0f);
|
|
var remainTime = GlobalData.ServerAnsiTime - endTime;
|
|
if(remainTime > 0)
|
|
{
|
|
SetText(remainTime);
|
|
}
|
|
else
|
|
{
|
|
SetText(0);
|
|
yield break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetText(int remainTime)
|
|
{
|
|
var str = "";
|
|
if (remainTime > 0)
|
|
str = StrDictionary.GetClientDictionaryString("#{26012}") + remainTime;
|
|
else
|
|
str = StrDictionary.GetClientDictionaryString("#{26012}");
|
|
|
|
if (!_BtnDesc.text.Equals(str))
|
|
_BtnDesc.text = str;
|
|
}
|
|
|
|
public void OnReqBtn()
|
|
{
|
|
if(_CurSelectType == -1)
|
|
{
|
|
Debug.LogError("_CurSelectType is -1");
|
|
return;
|
|
}
|
|
|
|
//确认是否立即开始巡游
|
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{86206}"), "",
|
|
delegate ()
|
|
{
|
|
ReqEnterWeddingCar req = new ReqEnterWeddingCar();
|
|
req._type = _CurSelectType;
|
|
req.SendMsg();
|
|
|
|
CloseMessageBox();
|
|
OnCloseBtn();
|
|
}, delegate ()
|
|
{
|
|
CloseMessageBox();
|
|
});
|
|
}
|
|
|
|
void CloseMessageBox()
|
|
{
|
|
UIManager.CloseUI(UIInfo.MessageBox);
|
|
}
|
|
|
|
public void OnCloseBtn()
|
|
{
|
|
UIManager.CloseUI(UIInfo.WeddingCarPanel);
|
|
}
|
|
}
|