307 lines
11 KiB
C#
307 lines
11 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
|
|
public class AucationResultItemInfo
|
|
{
|
|
public int snatchId;
|
|
public int state; //1.进行中 2.结束
|
|
public int curGoingGroup;
|
|
public int totalHadPutintoCount; //当前组一共投入了多少份
|
|
public int selfHadPutIntoCount;
|
|
public string winerName;
|
|
public int winerPutIntoCount;
|
|
public int putIntoTime;
|
|
public Dictionary<string, int> JoinerAndPutIntoCountDic = new Dictionary<string, int>();
|
|
|
|
public AucationResultItemInfo(int _SnatechId, int _State, int _CurGoingGroup, int _SelfHadPutIntoCount, int _TotalPutIntoCount, string _WinerName, int _WinerPutIntoCount, int _PutIntoTime, Dictionary<string, int> dic)
|
|
{
|
|
snatchId = _SnatechId;
|
|
state = _State;
|
|
curGoingGroup = _CurGoingGroup;
|
|
totalHadPutintoCount = _TotalPutIntoCount;
|
|
selfHadPutIntoCount = _SelfHadPutIntoCount;
|
|
winerName = _WinerName;
|
|
winerPutIntoCount = _WinerPutIntoCount;
|
|
putIntoTime = _PutIntoTime;
|
|
foreach (var info in dic)
|
|
{
|
|
if (JoinerAndPutIntoCountDic.ContainsKey(info.Key))
|
|
{
|
|
JoinerAndPutIntoCountDic[info.Key] = info.Value;
|
|
}else
|
|
{
|
|
JoinerAndPutIntoCountDic.Add(info.Key, info.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SelfAucationResultInfoPanel : MonoBehaviour {
|
|
|
|
public static SelfAucationResultInfoPanel Instance;
|
|
void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
AskForMySelfAucationInfo(); //请求当前页面的信息
|
|
}
|
|
|
|
#region
|
|
public GameObject AucationResultInfoPanel;
|
|
//public GameObject DontHaveInfoIcon;
|
|
|
|
//AucationResultInfoItemPanel
|
|
public GameObject itemPrefab;
|
|
public Transform itemPrefabParent;
|
|
|
|
public Text itemName;
|
|
public Text curState;
|
|
public Text myRate;
|
|
public Text putIntoGroup;
|
|
public Text hadPutInutCount;
|
|
public Image selfHadPutintoMoneyIcon;
|
|
public Text selfHadPutInutCount;
|
|
|
|
public GameObject winerAndPutintoObj; //是否显示获胜者的信息
|
|
public Text winerName;
|
|
public Image winerMoneyIcon;
|
|
public Text winerPutIntoCount;
|
|
|
|
public GameObject dontHavePutintoObj;
|
|
public GameObject itemInfoPanel;
|
|
|
|
public Text spaceCount;
|
|
//前六名玩家信息
|
|
public AucationFirstSixItem[] firstSixInfo;
|
|
#endregion
|
|
|
|
public void AskForMySelfAucationInfo()
|
|
{
|
|
CG_REQ_SNATCH_BET_ITEMS req = (CG_REQ_SNATCH_BET_ITEMS)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SNATCH_BET_ITEMS);
|
|
req.SetType(1);
|
|
req.SendPacket();
|
|
}
|
|
|
|
private List<AucationResultItemInfo> itemInfoList = new List<AucationResultItemInfo>();
|
|
public void GetMySelfAucationInfo(GC_RET_MY_SNATCH_RET_ITEMS packet)
|
|
{
|
|
itemInfoList.Clear(); //个人请求的返回 每次返回的是全部的信息 要清空一遍
|
|
|
|
for (int index = 0; index < packet.mySnatchItemsCount; index++)
|
|
{
|
|
Dictionary<string, int> joinerAndCountDic = new Dictionary<string, int>();
|
|
for(int idx = 0; idx < packet.GetMySnatchItems(index).betUsernamesCount; idx++)
|
|
{
|
|
if(joinerAndCountDic.ContainsKey(packet.GetMySnatchItems(index).GetBetUsernames(idx)))
|
|
{
|
|
joinerAndCountDic[packet.GetMySnatchItems(index).GetBetUsernames(idx)] = packet.GetMySnatchItems(index).GetBetnum(idx);
|
|
}
|
|
else
|
|
{
|
|
joinerAndCountDic.Add(packet.GetMySnatchItems(index).GetBetUsernames(idx), packet.GetMySnatchItems(index).GetBetnum(idx));
|
|
}
|
|
}
|
|
|
|
AucationResultItemInfo itemInfo = new AucationResultItemInfo(packet.GetMySnatchItems(index).ItemIndexId,
|
|
packet.GetMySnatchItems(index).State,
|
|
packet.GetMySnatchItems(index).Group,
|
|
packet.GetMySnatchItems(index).MyBetNum,
|
|
packet.GetMySnatchItems(index).TotalBetNum,
|
|
packet.GetMySnatchItems(index).WinnerName,
|
|
packet.GetMySnatchItems(index).WinnerBetNum,
|
|
packet.GetMySnatchItems(index).SelfBetTm,
|
|
joinerAndCountDic);
|
|
|
|
itemInfoList.Add(itemInfo);
|
|
}
|
|
|
|
//按时间排序
|
|
itemInfoList.Sort(delegate (AucationResultItemInfo infoA, AucationResultItemInfo infoB) {
|
|
return infoA.putIntoTime <= infoB.putIntoTime ? 1 : -1;
|
|
});
|
|
|
|
//判断信息是否显示
|
|
if (itemInfoList.Count > 0)
|
|
{
|
|
AucationResultInfoPanel.gameObject.SetActive(true);
|
|
itemInfoPanel.SetActive(true);
|
|
dontHavePutintoObj.SetActive(false);
|
|
}else
|
|
{
|
|
itemInfoPanel.SetActive(false);
|
|
dontHavePutintoObj.SetActive(true);
|
|
}
|
|
//设置夺宝空间的数量Text
|
|
spaceCount.text = itemInfoList.Count + "/" + 20;
|
|
//创建预设体
|
|
CreateItemPrefab();
|
|
}
|
|
|
|
private List<GameObject> itemPrefabList = new List<GameObject>();
|
|
public void CreateItemPrefab()
|
|
{
|
|
//创建前先清除
|
|
// ClearAllItemPrefabAndList();
|
|
if(itemInfoList.Count > itemPrefabList.Count)
|
|
{
|
|
for(int index = 0; index < itemPrefabList.Count; index++)
|
|
{
|
|
itemPrefabList[index].gameObject.SetActive(true);
|
|
itemPrefabList[index].GetComponent<AucationResultItem>().InitItem(itemInfoList[index], index);
|
|
}
|
|
|
|
for(int index = itemPrefabList.Count; index < itemInfoList.Count; index++)
|
|
{
|
|
GameObject item = GameObject.Instantiate(itemPrefab);
|
|
|
|
item.transform.SetParent(itemPrefabParent);
|
|
item.transform.localPosition = Vector3.zero;
|
|
item.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
item.transform.localScale = Vector3.one;
|
|
|
|
itemPrefabList.Add(item);
|
|
//初始化Item信息
|
|
item.GetComponent<AucationResultItem>().InitItem(itemInfoList[index], index);
|
|
}
|
|
}else
|
|
{
|
|
for (int index = 0; index < itemInfoList.Count; index++)
|
|
{
|
|
itemPrefabList[index].gameObject.SetActive(true);
|
|
itemPrefabList[index].GetComponent<AucationResultItem>().InitItem(itemInfoList[index], index);
|
|
}
|
|
|
|
for(int index = itemInfoList.Count; index < itemPrefabList.Count; index++)
|
|
{
|
|
itemPrefabList[index].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//默认点击第一个
|
|
if (itemInfoList.Count > 0)
|
|
{
|
|
OnResultItemClick(itemInfoList[0].snatchId, 0, itemInfoList[0].curGoingGroup);
|
|
//if (CurSelectedSnatchId <= 0)
|
|
//{
|
|
// OnResultItemClick(itemInfoList[0].snatchId, 0, itemInfoList[0].curGoingGroup);
|
|
//}
|
|
//else
|
|
//{
|
|
// OnResultItemClick(CurSelectedSnatchId, CurSelectedIndex, CurSeletedGroup);
|
|
//}
|
|
}
|
|
}
|
|
|
|
//设置按钮的Toggle背景 设置当前item的信息
|
|
private int CurSelectedSnatchId = -1;
|
|
private int CurSelectedIndex = -1;
|
|
private int CurSeletedGroup = -1;
|
|
public void OnResultItemClick(int snatchId, int _Index, int Group)
|
|
{
|
|
CurSelectedSnatchId = snatchId;
|
|
CurSelectedIndex = _Index;
|
|
CurSeletedGroup = Group;
|
|
for (int index = 0; index < itemInfoList.Count; index++)
|
|
{
|
|
if(itemPrefabList[index].GetComponent<AucationResultItem>().curIndex == _Index)
|
|
{
|
|
itemPrefabList[index].GetComponent<AucationResultItem>().InitItemState(true);
|
|
}else
|
|
{
|
|
itemPrefabList[index].GetComponent<AucationResultItem>().InitItemState(false);
|
|
}
|
|
}
|
|
InitItemInfoPanel();
|
|
}
|
|
|
|
|
|
private int firstSixItemCount = 0;
|
|
private List<Dictionary<string, int>> sixRoleInfoList;
|
|
public void InitItemInfoPanel()
|
|
{
|
|
Tab_SnatchTreasure snatahTab = TableManager.GetSnatchTreasureByID(CurSelectedSnatchId, 0);
|
|
if(snatahTab == null)
|
|
{
|
|
return;
|
|
}
|
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(snatahTab.ItemId, 0);
|
|
if(commonItem == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
itemName.text = commonItem.Name + "X" + snatahTab.ItemNum;
|
|
AucationResultItemInfo itemInfo = null;
|
|
for (int index = 0; index < itemInfoList.Count; index++)
|
|
{
|
|
if(itemInfoList[index].snatchId == CurSelectedSnatchId
|
|
&& itemInfoList[index].curGoingGroup == CurSeletedGroup)
|
|
{
|
|
itemInfo = itemInfoList[index]; //引用
|
|
}
|
|
}
|
|
|
|
if(itemInfo == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(itemInfo.state == 1)
|
|
{
|
|
curState.text = StrDictionary.GetClientDictionaryString("#{42305}");
|
|
winerAndPutintoObj.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
curState.text = StrDictionary.GetClientDictionaryString("#{42306}");
|
|
winerAndPutintoObj.gameObject.SetActive(true);
|
|
winerName.text = itemInfo.winerName;
|
|
LoadAssetBundle.Instance.SetImageSprite(winerMoneyIcon, UICurrencyItem.GetCurrencySprite((MONEYTYPE)snatahTab.BetMoneyType));
|
|
winerPutIntoCount.text = itemInfo.winerPutIntoCount * snatahTab.MoneyNumPerBet + StrDictionary.GetClientDictionaryString("#{42308}", itemInfo.winerPutIntoCount);
|
|
}
|
|
|
|
myRate.text = (((float)itemInfo.selfHadPutIntoCount / (float)snatahTab.TotalBetMaxNum) * 100).ToString("F2") + "%"; //夺宝几率
|
|
|
|
putIntoGroup.text = StrDictionary.GetClientDictionaryString("#{42307}", itemInfo.curGoingGroup); //当前正在进行第几组
|
|
hadPutInutCount.text = itemInfo.totalHadPutintoCount + "/" + snatahTab.TotalBetMaxNum; //当前组一共投入多少份
|
|
//当前组个人投入多少份
|
|
selfHadPutInutCount.text = itemInfo.selfHadPutIntoCount * snatahTab.MoneyNumPerBet + StrDictionary.GetClientDictionaryString("#{42308}", itemInfo.selfHadPutIntoCount);
|
|
//设置个人MoneyIcon
|
|
LoadAssetBundle.Instance.SetImageSprite(selfHadPutintoMoneyIcon, UICurrencyItem.GetCurrencySprite((MONEYTYPE)snatahTab.BetMoneyType));
|
|
|
|
List<KeyValuePair<string, int>> dicList = new List<KeyValuePair<string, int>>(itemInfo.JoinerAndPutIntoCountDic);
|
|
dicList.Sort(delegate (KeyValuePair<string, int> dicA, KeyValuePair<string, int> dicB)
|
|
{
|
|
return dicA.Value >= dicB.Value ? -1 : 1; //dicA.Value.CompareTo(dicB.Value);
|
|
});
|
|
|
|
for(int index = 0; index < firstSixInfo.Length; index++)
|
|
{
|
|
firstSixInfo[index].gameObject.SetActive(index < itemInfo.JoinerAndPutIntoCountDic.Count);
|
|
}
|
|
|
|
for(int index = 0; index < dicList.Count; index++)
|
|
{
|
|
firstSixInfo[index].InitItem(dicList[index].Key, snatahTab.BetMoneyType, dicList[index].Value, snatahTab);
|
|
}
|
|
}
|
|
|
|
public void OnHistroyBtnClick()
|
|
{
|
|
UIManager.ShowUI(UIInfo.AucationSelfRecordPanel);
|
|
}
|
|
}
|