Files
JJBB/Assets/Project/Script/GUI/Aucation/AucationLotteryPanel.cs
2024-08-23 15:49:34 +08:00

129 lines
3.3 KiB
C#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using GCGame.Table;
public class AucationLotteryPanel : MonoBehaviour {
public static AucationLotteryPanel Instance;
private void Awake()
{
Instance = this;
}
private void OnDestroy()
{
Instance = null;
}
public Text itemName;
public Text winerName;
private int snatchId = -1;
private bool isGet = false;
private string finalWinerName = null;
private List<string> winerNames = new List<string>();
public bool isRotate = false;
public void GetAllWinerName(GC_SNATCH_ITEM_RET_RESULT packet)
{
if (isRotate)
{
return;
}else
{
InitCountData(); //初始化计时需要的相关数据
}
winerNames.Clear(); //清除上次的缓存
snatchId = packet.ItemIndexId;
isGet = (packet.Result == 1 ? true : false);
finalWinerName = packet.WinnerName;
for(int index = 0; index < packet.betUserNamesCount; index++)
{
winerNames.Add(packet.GetBetUserNames(index));
}
Tab_SnatchTreasure snatchTab = TableManager.GetSnatchTreasureByID(snatchId, 0);
if(snatchTab == null)
{
//关闭当前?
UIManager.CloseUI(UIInfo.AucationLotteryPanel);
return;
}
//一口价 个人投注上限为1 不显示
if(snatchTab.SelfBetMaxNum == 1)
{
UIManager.CloseUI(UIInfo.AucationLotteryPanel);
return;
}
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(snatchTab.ItemId, 0);
if(commonItem == null)
{
UIManager.CloseUI(UIInfo.AucationLotteryPanel);
return;
}
itemName.text = commonItem.Name + "X" + snatchTab.ItemNum;
//开始转动名字
isRotate = true;
}
public void InitCountData()
{
totalTime = 3;
counTime = 0.0f;
counIndex = 0;
isRotate = true;
}
private int totalTime = 3;
private float counTime = 0.0f;
private int counIndex = 0;
private void Update()
{
if(isRotate)
{
counTime += Time.deltaTime;
if (counIndex < winerNames.Count)
{
winerName.text = winerNames[counIndex++];
}else
{
counIndex = 0;
}
if(counTime >= 1.0f)
{
if(--totalTime <= 0)
{
isRotate = false;
winerName.text = finalWinerName; //记录最后的获胜者。
Invoke("CloseWindow", 2.0f); //1s后关闭窗口
}
counTime = 1.0f - counTime;
}
}
}
public void CloseWindow()
{
isRotate = false;
//打开可以自由移动的item
if (isGet)
{
UIManager.ShowUI(UIInfo.AucationRewardPanel, delegate (bool bSucess, object param)
{
if (bSucess)
{
AucationRewardPanel.Instance.GetItemInfo(snatchId);
}
});
}
UIManager.CloseUI(UIInfo.AucationLotteryPanel);
}
}