410 lines
11 KiB
C#
410 lines
11 KiB
C#
using cfg.ActorCfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay;
|
|
using Gameplay.Net;
|
|
using PhxhSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
/// <summary>
|
|
/// 抽卡测试界面
|
|
/// </summary>
|
|
public class UIRaffleController : UIWindow
|
|
{
|
|
/// <summary>
|
|
/// 打开抽卡界面
|
|
/// </summary>
|
|
public static async UniTask<UIWindow> Open()
|
|
{
|
|
return await UIManager.Instance.OpenWindow(UINameConst.UIRaffle);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 卡池类型
|
|
/// </summary>
|
|
private enum E_NowPoolType
|
|
{
|
|
/// <summary>
|
|
/// 普通卡池
|
|
/// </summary>
|
|
Normal,
|
|
Newer,
|
|
/// <summary>
|
|
/// 限定卡池
|
|
/// </summary>
|
|
Limit,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抽取数量类型
|
|
/// </summary>
|
|
private enum E_GachaCount
|
|
{
|
|
/// <summary>
|
|
/// 单抽
|
|
/// </summary>
|
|
One = 1,
|
|
/// <summary>
|
|
/// 十连
|
|
/// </summary>
|
|
Ten = 10
|
|
}
|
|
|
|
/// <summary>
|
|
/// 页签
|
|
/// </summary>
|
|
private class TabItem : UIGameObjectWrapper
|
|
{
|
|
private Button btn;
|
|
/// <summary>
|
|
/// 选中状态
|
|
/// </summary>
|
|
private GameObject goSelect;
|
|
|
|
private RafflePoolForDisplay raffleData;
|
|
/// <summary>
|
|
/// 页签点击回调
|
|
/// </summary>
|
|
private readonly Action<TabItem> tabAction;
|
|
|
|
/// <summary>
|
|
/// 是否选中
|
|
/// </summary>
|
|
public bool IsSelect
|
|
{
|
|
set { goSelect.IsScaleShow(value); }
|
|
}
|
|
|
|
public RafflePoolForDisplay RaffleData
|
|
{
|
|
get { return raffleData; }
|
|
}
|
|
|
|
public TabItem(GameObject root, Action<TabItem> tab) : base(root, true)
|
|
{
|
|
tabAction = tab;
|
|
|
|
btn = GoRoot.GetComponent<Button>();
|
|
goSelect = FindObj("ImageSelect");
|
|
|
|
IsSelect = false;
|
|
|
|
BindButton(btn, OnClick);
|
|
}
|
|
|
|
public void SetInfo(RafflePoolForDisplay rafflePoolForDisplay)
|
|
{
|
|
raffleData = rafflePoolForDisplay;
|
|
|
|
IsScaleShow = true;
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
tabAction?.Invoke(this);
|
|
}
|
|
}
|
|
|
|
#region UI
|
|
/// <summary>
|
|
/// 单抽按钮
|
|
/// </summary>
|
|
private Button btnRaffleOne;
|
|
/// <summary>
|
|
/// 十连抽按钮
|
|
/// </summary>
|
|
private Button btnRaffleTen;
|
|
/// <summary>
|
|
/// 主页
|
|
/// </summary>
|
|
private Button btnHome;
|
|
/// <summary>
|
|
/// 返回
|
|
/// </summary>
|
|
private Button btnBack;
|
|
/// <summary>
|
|
/// 保底按钮
|
|
/// </summary>
|
|
private Button btnBreakEven;
|
|
/// <summary>
|
|
/// 单抽花费文本
|
|
/// </summary>
|
|
private TMP_Text textRaffleOne;
|
|
/// <summary>
|
|
/// 道具1
|
|
/// </summary>
|
|
private TMP_Text textRemain1;
|
|
/// <summary>
|
|
/// 道具2
|
|
/// </summary>
|
|
private TMP_Text textRemain2;
|
|
/// <summary>
|
|
/// 循环列表
|
|
/// </summary>
|
|
private RecycleView recycleView;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 卡池数据列表
|
|
/// </summary>
|
|
public List<RafflePoolForDisplay> listRaffle = new();
|
|
/// <summary>
|
|
/// 页签字典
|
|
/// </summary>
|
|
private readonly Dictionary<int, TabItem> dicTab = new();
|
|
/// <summary>
|
|
/// 当前选中页签
|
|
/// </summary>
|
|
private TabItem curTab;
|
|
|
|
public override void OnInit()
|
|
{
|
|
btnRaffleOne = GetComponent<Button>("ImageBG/Image_Cultivate_BG_Black/RaffleOneBtn");
|
|
btnRaffleTen = GetComponent<Button>("ImageBG/Image_Cultivate_BG_Black/RaffleTenBtn");
|
|
btnBack = GetComponent<Button>("ImageBG/UI_Topbtn/Button_Back");
|
|
btnHome = GetComponent<Button>("ImageBG/UI_Topbtn/Button_Home");
|
|
btnBreakEven = GetComponent<Button>("ImageBG/Image_Cultivate_BG_Black/TianJingShopBtn");
|
|
textRaffleOne = GetComponent<TMP_Text>("ImageBG/Image_Cultivate_BG_Black/RaffleOneBtn/Text (TMP)");
|
|
textRemain1 = GetComponent<TMP_Text>("ImageBG/UI_Topbtn/Remain/remain");
|
|
textRemain2 = GetComponent<TMP_Text>("ImageBG/UI_Topbtn/Remain/remain1");
|
|
recycleView = GetComponent<RecycleView>("ImageBG/ScrollView");
|
|
|
|
recycleView.Init(RefreshItem);
|
|
|
|
BindButton(btnRaffleOne, OnRaffleOne);
|
|
BindButton(btnRaffleTen, OnRaffleTen);
|
|
BindButton(btnBack, OnBackOnClick);
|
|
BindButton(btnHome, OnHomeBtnOnClick);
|
|
BindButton(btnBreakEven, OnBreakEven);
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.UIReturnRaffleResult, (Action<ItemCounts>)OnRecvUIReturnRaffleResult);
|
|
}
|
|
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
listRaffle.Clear();
|
|
for (int i = 0; i < TableManager.Instance.Tables.Gacha.DataList.Count; i++)
|
|
{
|
|
listRaffle.Add(new RafflePoolForDisplay(TableManager.Instance.Tables.Gacha.DataList[i]));
|
|
|
|
}
|
|
|
|
recycleView.ShowList(listRaffle.Count);
|
|
}
|
|
|
|
public override void OnRelease()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.UIReturnRaffleResult, (Action<ItemCounts>)OnRecvUIReturnRaffleResult);
|
|
|
|
base.OnRelease();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取抽取类型的uint值
|
|
/// </summary>
|
|
private uint GetGachaTypeToUInt(DataGacha dataGacha, E_GachaCount gachaCount)
|
|
{
|
|
GachaDrawType res = GachaDrawType.None;
|
|
|
|
switch (gachaCount)
|
|
{
|
|
case E_GachaCount.One:
|
|
{
|
|
foreach (GachaDrawType gachaDrawType in dataGacha.DrawType)
|
|
{
|
|
switch (gachaDrawType)
|
|
{
|
|
case GachaDrawType.LimitOne:
|
|
case GachaDrawType.NormalOne:
|
|
res = gachaDrawType;
|
|
return (uint)res;
|
|
default:
|
|
DebugUtil.LogError("未处理类型");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case E_GachaCount.Ten:
|
|
{
|
|
foreach (GachaDrawType gachaDrawType in dataGacha.DrawType)
|
|
{
|
|
switch (gachaDrawType)
|
|
{
|
|
case GachaDrawType.LimitTen:
|
|
case GachaDrawType.NormalTen:
|
|
res = gachaDrawType;
|
|
return (uint)res;
|
|
default:
|
|
DebugUtil.LogError("未处理类型");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
DebugUtil.LogError("未处理类型");
|
|
}
|
|
return (uint)res;
|
|
}
|
|
|
|
return (uint)res;
|
|
}
|
|
|
|
#region 刷新回调
|
|
/// <summary>
|
|
/// 无限列表刷新单个项
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <param name="itemTransform"></param>
|
|
private void RefreshItem(GameObject cell, int index)
|
|
{
|
|
if (!dicTab.TryGetValue(cell.GetInstanceID(), out TabItem tabItem))
|
|
{
|
|
tabItem = new TabItem(cell, OnTab);
|
|
dicTab[cell.GetInstanceID()] = tabItem;
|
|
}
|
|
|
|
tabItem.SetInfo(listRaffle[index]);
|
|
|
|
if (curTab == null)
|
|
OnTab(tabItem);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新卡池
|
|
/// </summary>
|
|
/// <param name="pool"></param>
|
|
private void RefreshPool(RafflePoolForDisplay pool)
|
|
{
|
|
RefreshRemain();
|
|
RefreshBtn();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新按钮显示
|
|
/// </summary>
|
|
private void RefreshBtn()
|
|
{
|
|
if (curTab == null)
|
|
return;
|
|
|
|
if (curTab.RaffleData.IsFreeOne)
|
|
textRaffleOne.text = "免费抽";
|
|
else
|
|
textRaffleOne.text = "抽奖1次";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新道具显示
|
|
/// </summary>
|
|
private void RefreshRemain()
|
|
{
|
|
if (curTab == null)
|
|
return;
|
|
|
|
DataItem dataItem = TableManager.Instance.Tables.Item.Get(curTab.RaffleData.Cfg.Cost[0].Id);
|
|
textRemain1.text = $"单抽道具: {CommonUtils.GetLocalizeText(dataItem.NameLocal)}X{Actor.Instance.Item.GetItemCount(dataItem.ID)}";
|
|
|
|
dataItem = TableManager.Instance.Tables.Item.Get(curTab.RaffleData.Cfg.Cost[1].Id);
|
|
textRemain2.text = $"十连抽道具: {CommonUtils.GetLocalizeText(dataItem.NameLocal)}X{Actor.Instance.Item.GetItemCount(dataItem.ID)}";
|
|
}
|
|
#endregion
|
|
|
|
#region 按钮点击回调方法
|
|
/// <summary>
|
|
/// 页签
|
|
/// </summary>
|
|
private void OnTab(TabItem tabItem)
|
|
{
|
|
if (curTab == tabItem)
|
|
return;
|
|
|
|
if (curTab != null)
|
|
curTab.IsSelect = false;
|
|
|
|
curTab = tabItem;
|
|
curTab.IsSelect = true;
|
|
|
|
RefreshPool(curTab.RaffleData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回主页
|
|
/// </summary>
|
|
private void OnHomeBtnOnClick()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回
|
|
/// </summary>
|
|
private void OnBackOnClick()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 单抽
|
|
/// </summary>
|
|
private void OnRaffleOne()
|
|
{
|
|
if (curTab == null)
|
|
return;
|
|
|
|
NetHelper.Raffle((uint)curTab.RaffleData.Cfg.Id,
|
|
GetGachaTypeToUInt(curTab.RaffleData.Cfg, E_GachaCount.One),
|
|
curTab.RaffleData.IsFreeOne,
|
|
(uint)E_GachaCount.One);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 十连抽
|
|
/// </summary>
|
|
private void OnRaffleTen()
|
|
{
|
|
if (curTab == null)
|
|
return;
|
|
|
|
NetHelper.Raffle((uint)curTab.RaffleData.Cfg.Id,
|
|
GetGachaTypeToUInt(curTab.RaffleData.Cfg, E_GachaCount.Ten),
|
|
false,
|
|
(uint)E_GachaCount.Ten);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保底
|
|
/// </summary>
|
|
private async void OnBreakEven()
|
|
{
|
|
// NetHelper.PatioExchange(1, 0);
|
|
|
|
/*NormalShopDataForGacha normalShopDataForGacha = new(mNowRafflePool.Cfg.PatioItemList, mNowRafflePool.Cfg.PatioPrice);
|
|
|
|
await UIManager.Instance.OpenWindow(UINameConst.UI_Patio, normalShopDataForGacha);*/
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抽卡结果
|
|
/// </summary>
|
|
/// <param name="itemCounts"></param>
|
|
private async void OnRecvUIReturnRaffleResult(ItemCounts itemCounts)
|
|
{
|
|
if (itemCounts.Ids.Count == 0)
|
|
{
|
|
DebugUtil.LogError("没有东西");
|
|
return;
|
|
}
|
|
|
|
RefreshRemain();
|
|
|
|
await UIManager.Instance.OpenWindow(UINameConst.UIRaffleResult, itemCounts);
|
|
}
|
|
#endregion
|
|
} |