226 lines
6.6 KiB
C#
226 lines
6.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using GCGame.Table;
|
|
using UnityEngine.UI;
|
|
using Module.Log;
|
|
|
|
public class WCBookPanel : MonoBehaviour {
|
|
|
|
public static WCBookPanel Instance;
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
InitMenuContainer();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
ReqBookState();
|
|
}
|
|
|
|
public UIContainerBase _MenuItemContainer;
|
|
public Text _SelfRemainTime;
|
|
|
|
public GameObject _CancelBookBtn;
|
|
public Button _BookBtn;
|
|
public Text _BookBtnDesc;
|
|
public GameObject _GoBtn;
|
|
void InitMenuContainer()
|
|
{
|
|
List<int> _IdList = new List<int>();
|
|
foreach (var item in TableManager.GetWeddingCarBook())
|
|
_IdList.Add(item.Key);
|
|
|
|
_MenuItemContainer.InitContentItem(_IdList);
|
|
}
|
|
|
|
private int _CurSelectMenuItemId = -1;
|
|
public void OnMenuItemClick(int menuItemId)
|
|
{
|
|
_CurSelectMenuItemId = menuItemId;
|
|
_MenuItemContainer.ForeachActiveItem<WCBookMenuItem>((item)=> {
|
|
item.ShowMark(_CurSelectMenuItemId == item._MenuItemId);
|
|
});
|
|
|
|
RefreshBookBtnState();
|
|
}
|
|
|
|
void ReqBookState()
|
|
{
|
|
ReqWeddingCarBookInfo req = new ReqWeddingCarBookInfo();
|
|
req.flag = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
private Dictionary<int, int> _MenuItemStateDic = new Dictionary<int, int>();
|
|
private Dictionary<int, int> _MenuItemTimeState = new Dictionary<int, int>();
|
|
public int _SelfBookNodeId = -1;
|
|
private int _CurGoingItemId = -1;
|
|
public void OnPacket(RetWeddingCarBookInfo packet)
|
|
{
|
|
SetSelfBookRemainTime(packet.time);
|
|
|
|
_MenuItemStateDic.Clear();
|
|
_MenuItemTimeState.Clear();
|
|
for (int index = 0; index < packet.bookState.Count; index++)
|
|
{
|
|
_MenuItemStateDic.Add(index + 1, packet.bookState[index]);
|
|
_MenuItemTimeState.Add(index + 1, packet.isInTime[index]);
|
|
if (packet.isInTime[index] == 1)
|
|
_CurGoingItemId = index + 1;
|
|
}
|
|
|
|
_SelfBookNodeId = packet.bookNodeid;
|
|
RefreshMenuItemState();
|
|
|
|
PositionItem();
|
|
if (_SelfBookNodeId != -1)
|
|
{
|
|
OnMenuItemClick(_SelfBookNodeId);
|
|
}
|
|
}
|
|
|
|
void PositionItem()
|
|
{
|
|
var needPositionItemId = _SelfBookNodeId != -1 ? _SelfBookNodeId : _CurGoingItemId;
|
|
if (needPositionItemId == -1)
|
|
return;
|
|
_MenuItemContainer.ForeachActiveItem<WCBookMenuItem>((item) => {
|
|
if(item._MenuItemId == needPositionItemId)
|
|
{
|
|
var pos = _MenuItemContainer.GetItemLocalPosition(item);
|
|
_MenuItemContainer._ContainerObj.anchoredPosition = new Vector2(pos.x, Mathf.Abs(pos.y));
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
void RefreshMenuItemState()
|
|
{
|
|
_MenuItemContainer.ForeachActiveItem<WCBookMenuItem>((item)=> {
|
|
if(_MenuItemStateDic.ContainsKey(item._MenuItemId))
|
|
{
|
|
item.RefreshState(_MenuItemStateDic[item._MenuItemId]);
|
|
}
|
|
else
|
|
{
|
|
LogModule.ErrorLog("没有对应的状态 : " + item._MenuItemId);
|
|
}
|
|
});
|
|
|
|
RefreshBookBtnState();
|
|
}
|
|
|
|
void RefreshBookBtnState()
|
|
{
|
|
if(_CurSelectMenuItemId == -1)
|
|
{
|
|
_BookBtn.gameObject.SetActive(false);
|
|
_CancelBookBtn.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
if(!_MenuItemStateDic.ContainsKey(_CurSelectMenuItemId))
|
|
{
|
|
LogModule.ErrorLog("!_CurSelectMenuItemId.ContainsKey : " + _CurSelectMenuItemId);
|
|
return;
|
|
}
|
|
|
|
var state = _MenuItemStateDic[_CurSelectMenuItemId];
|
|
var timeState = _MenuItemTimeState[_CurSelectMenuItemId];
|
|
if (state != 2 && _CurSelectMenuItemId == _SelfBookNodeId)
|
|
{
|
|
if(timeState != 1) //抵达预约时间前
|
|
{
|
|
_CancelBookBtn.SetActive(true);
|
|
_BookBtn.gameObject.SetActive(false);
|
|
_GoBtn.SetActive(false);
|
|
return;
|
|
}else
|
|
{
|
|
_CancelBookBtn.SetActive(false);
|
|
_BookBtn.gameObject.SetActive(false);
|
|
_GoBtn.SetActive(true);
|
|
return;
|
|
}
|
|
}
|
|
_GoBtn.SetActive(false);
|
|
switch (state)
|
|
{
|
|
case 0:
|
|
{
|
|
_CancelBookBtn.gameObject.SetActive(false);
|
|
_BookBtn.gameObject.SetActive(true);
|
|
_BookBtn.interactable = true;
|
|
_BookBtnDesc.text = StrDictionary.GetClientDictionaryString("#{26014}");
|
|
}
|
|
break;
|
|
case 1:
|
|
{
|
|
//非个人预约
|
|
_CancelBookBtn.gameObject.SetActive(false);
|
|
_BookBtn.gameObject.SetActive(true);
|
|
_BookBtn.interactable = false;
|
|
_BookBtnDesc.text = StrDictionary.GetClientDictionaryString("#{26015}");
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
_CancelBookBtn.gameObject.SetActive(false);
|
|
_BookBtn.gameObject.SetActive(true);
|
|
_BookBtn.interactable = false;
|
|
_BookBtnDesc.text = StrDictionary.GetClientDictionaryString("#{26017}");
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void SetSelfBookRemainTime(int time)
|
|
{
|
|
if (!_SelfRemainTime.text.Equals(time))
|
|
_SelfRemainTime.text = time.ToString();
|
|
}
|
|
|
|
public void OnBookBtn()
|
|
{
|
|
ReqWeddingCarBookTime req = new ReqWeddingCarBookTime();
|
|
req.nodeid = _CurSelectMenuItemId;
|
|
req.option = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
public void OnCancelBookBtn()
|
|
{
|
|
ReqWeddingCarBookTime req = new ReqWeddingCarBookTime();
|
|
req.nodeid = _CurSelectMenuItemId;
|
|
req.option = 0;
|
|
req.SendMsg();
|
|
}
|
|
|
|
public void OnCloseBtn()
|
|
{
|
|
UIManager.CloseUI(UIInfo.WCBookPanel);
|
|
}
|
|
|
|
public void OnGoBtn()
|
|
{
|
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{26018}"),"",delegate() {
|
|
ReqEnterWeddingCar req = new ReqEnterWeddingCar();
|
|
req._type = 1;
|
|
req.SendMsg();
|
|
|
|
UIManager.ShowUI(UIInfo.MarryMovieCtr);
|
|
UIManager.CloseUI(UIInfo.MessageBox);
|
|
OnCloseBtn();
|
|
}, delegate() {
|
|
UIManager.CloseUI(UIInfo.MessageBox);
|
|
OnCloseBtn();
|
|
});
|
|
}
|
|
}
|