462 lines
16 KiB
C#
462 lines
16 KiB
C#
using cfg;
|
|
using cfg.ActorCfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay;
|
|
using Gameplay.Level;
|
|
using PhxhSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
public class UI_UsingItemController : UIWindow
|
|
{
|
|
#region UI
|
|
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Image Image_MiddleBg_Normal;
|
|
public Image Image_ItemIcon_Normal;
|
|
public TMP_Text Text_have_Normal;
|
|
public TMP_Text Text_ItemIntroduce_Normal;
|
|
public TMP_Text Text_ItemType_Normal;
|
|
public Image Image_UseNumBg_Normal;
|
|
public Button Button_Decrease_Normal;
|
|
public Image Image_Decrease_Normal;
|
|
public Button Button_Add_Normal;
|
|
public Image Image_Add_Normal;
|
|
public TMP_Text Text_Num_Normal;
|
|
public Button Button_Zero_Normal;
|
|
public TMP_Text Text_Zero_Normal;
|
|
public Button Button_Max_Normal;
|
|
public TMP_Text Text_Max_Normal;
|
|
public Button Button_Use_Normal;
|
|
public TMP_Text Text_ItemName_Normal;
|
|
public Button Button_Source_Normal;
|
|
public Button Button_Close_Normal;
|
|
public Button Button_Close;
|
|
public TMP_Text Text_ItemName_Source;
|
|
public Button Button_Source;
|
|
public Image Image_MiddleBg_source;
|
|
public Image Image_ItemIcon_Source;
|
|
public TMP_Text Text_have;
|
|
public TMP_Text Text_ItemIntroduce;
|
|
public TMP_Text Text_ItemType;
|
|
public Image Image_UseNumBg_source;
|
|
public Button Button_Decrease;
|
|
public Image Image_Decrease;
|
|
public Button Button_Add;
|
|
public Image Image_Add;
|
|
public Image Image_NumBg;
|
|
public TMP_Text Text_Num_Source;
|
|
public Button Button_Zero;
|
|
public TMP_Text Text_Zero;
|
|
public Button Button_Max;
|
|
public TMP_Text Text_Max;
|
|
public Button Button_Use;
|
|
public RecycleView ScrollView_Source;
|
|
public Image Image_Bg;
|
|
public TMP_Text Text_Left;
|
|
public TMP_Text Text_Right;
|
|
public Button Button_Go;
|
|
public Image Image_TopBlackBar;
|
|
public Image Image_BottomBlackBar;
|
|
|
|
///Auto Gen End///
|
|
|
|
#endregion
|
|
|
|
#region class
|
|
class OpenData
|
|
{
|
|
public int itemID;
|
|
public Action CloseCallback;
|
|
public bool HideUseBtn;
|
|
|
|
public OpenData(int itemID, Action CloseCallback, bool hideUseBtn)
|
|
{
|
|
this.HideUseBtn = hideUseBtn;
|
|
this.itemID = itemID;
|
|
this.CloseCallback = CloseCallback;
|
|
}
|
|
}
|
|
class ItemSourceTab : UIGameObjectWrapper
|
|
{
|
|
public TMP_Text Text_Source;
|
|
public Button Button_Jump;
|
|
public TMP_Text Text_GoTo;
|
|
public TMP_Text Text_lock;
|
|
|
|
public Action CloseAction;
|
|
|
|
int JumpID;
|
|
|
|
public ItemSourceTab(GameObject root, Action closeAction, bool isScaleShow = true) : base(root, isScaleShow)
|
|
{
|
|
Text_Source = GetComponent<TMP_Text>("Text_Left");
|
|
Button_Jump = GetComponent<Button>("Button_Go");
|
|
Text_GoTo = GetComponent<TMP_Text>("Button_Go/Text (TMP)");
|
|
Text_lock = GetComponent<TMP_Text>("Text_Right");
|
|
|
|
CloseAction = closeAction;
|
|
CommonUtils.BindButton(Button_Jump, JumpClick);
|
|
}
|
|
|
|
public void SetInfo(int ID)
|
|
{
|
|
JumpID = ID;
|
|
if (JumpID > 100000)//TO Level
|
|
{
|
|
Text_Source.text = string.Format("{0} {1}", LevelManager.Instance.LevelIDToNum(JumpID), LevelManager.Instance.LevelIDToName(JumpID));
|
|
|
|
if (LevelManager.Instance.CheckLevelUnlock(JumpID))
|
|
{
|
|
Button_Jump.gameObject.SetActive(true);
|
|
//Text_Source.color = Color.white;
|
|
//CommonUtils.GetComponent<Image>(item.gameObject, "icon").color = new Color(1, 1, 1, 1);
|
|
Text_GoTo.text = CommonUtils.GetLocalizeText("Package_JumpTo");
|
|
Text_lock.text = "";
|
|
}
|
|
else
|
|
{
|
|
Button_Jump.gameObject.SetActive(false);
|
|
//Text_Source.color = new Color(.2f, .2f, .2f, 1);
|
|
//CommonUtils.GetComponent<Image>(item.gameObject, "icon").color = new Color(1, 1, 1, .5f);
|
|
Text_lock.text = CommonUtils.GetLocalizeText("Package_Lock");
|
|
}
|
|
}
|
|
else//TO Shop
|
|
{
|
|
var data = ShopManager.Instance.GetShopData(JumpID);
|
|
Text_Source.text = CommonUtils.GetLocalizeText(data.Name);
|
|
|
|
Button_Jump.gameObject.SetActive(true);
|
|
//Text_Source.color = Color.white;
|
|
//CommonUtils.GetComponent<Image>(item.gameObject, "icon").color = new Color(1, 1, 1, 1);
|
|
Text_GoTo.text = CommonUtils.GetLocalizeText("Package_JumpTo");
|
|
Text_lock.text = "";
|
|
}
|
|
}
|
|
|
|
void JumpClick()
|
|
{
|
|
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
|
|
if (JumpID > 100000)
|
|
{
|
|
JumpToLevel(JumpID);
|
|
}
|
|
else
|
|
{
|
|
JumpToShop(JumpID);
|
|
}
|
|
}
|
|
|
|
void JumpToLevel(int level)
|
|
{
|
|
if (LevelManager.Instance.CheckLevelUnlock(level))
|
|
{
|
|
SignUpManager.Instance.DoNotShowDailyAccumulate = true;
|
|
JumpToManager.JumpFunc<int, Action>(cfg.JumpFuncType.Level_Detail, level, () =>
|
|
{
|
|
CloseAction?.Invoke();
|
|
});
|
|
}
|
|
else
|
|
DebugUtil.Log("level is locked: " + level);
|
|
}
|
|
void JumpToShop(int ShopId)
|
|
{
|
|
var shopCfg = TableManager.Instance.Tables.Shop;
|
|
if (!shopCfg.DataMap.ContainsKey(ShopId))
|
|
{
|
|
DebugUtil.Log("Jump to shop detail failed, shop id not found: " + ShopId);
|
|
return;
|
|
}
|
|
|
|
SignUpManager.Instance.DoNotShowDailyAccumulate = true;
|
|
JumpToManager.JumpFunc<int, Action>(JumpFuncType.Item_Shop, ShopId, () =>
|
|
{
|
|
CloseAction?.Invoke();
|
|
});
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
private int ItemID;
|
|
private int UseCount = 1;
|
|
private bool hideUseBtn;
|
|
private bool isShowingSource = false;
|
|
private bool ShowingSource
|
|
{
|
|
get
|
|
{
|
|
return isShowingSource;
|
|
}
|
|
set
|
|
{
|
|
isShowingSource = value;
|
|
NormalNode.SetActive(!isShowingSource);
|
|
SourceNode.SetActive(isShowingSource);
|
|
if (isShowingSource)
|
|
{
|
|
RefreshSourceNode();
|
|
}
|
|
else
|
|
{
|
|
RefreshNormalNode();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 跳转关闭界面时回调
|
|
/// </summary>
|
|
private Action onWindowCloseCallback;
|
|
private Dictionary<int, ItemSourceTab> dicScrollItem = new();
|
|
|
|
private GameObject NormalNode;
|
|
private GameObject SourceNode;
|
|
|
|
public static UniTask<UIWindow> Open(int itemID, Action JumpCloseCallback, bool hideUseBtn = false)
|
|
{
|
|
CommonUtils.CaptureScreenshot();
|
|
var data = new OpenData(itemID, JumpCloseCallback, hideUseBtn);
|
|
return UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_UsingItem, data);
|
|
}
|
|
|
|
// deal with input data
|
|
public override void PreLoad(object data = null)
|
|
{
|
|
var openData = (OpenData)data;
|
|
|
|
ItemID = openData.itemID;
|
|
onWindowCloseCallback = openData.CloseCallback;
|
|
hideUseBtn = openData.HideUseBtn;
|
|
|
|
var spritePath = CommonUtils.GetItemPath(ItemID);
|
|
AssetManager.Instance.PostPreload<Sprite>(spritePath).Forget();
|
|
}
|
|
|
|
// Use this for initialization
|
|
public override void OnInit()
|
|
{
|
|
//bind UI GameObj
|
|
UI_UsingItemBinder.GetComponents(this);
|
|
|
|
NormalNode = FindObj("MainNode/NormalNode");
|
|
SourceNode = FindObj("MainNode/SourceNode");
|
|
|
|
AddBgClose(OnCloseClick);
|
|
|
|
#region bind_button
|
|
BindButton(Button_Close, OnCloseClick);
|
|
BindButton(Button_Close_Normal, OnCloseClick);
|
|
BindButton(Button_Source, () => { SwitchSourcePanel(false); });
|
|
BindButton(Button_Source_Normal, () => { SwitchSourcePanel(true); });
|
|
BindButton(Button_Decrease, () => RefreshCountClick(--UseCount));
|
|
BindButton(Button_Decrease_Normal, () => RefreshCountClick(--UseCount));
|
|
BindButton(Button_Add, () => RefreshCountClick(++UseCount));
|
|
BindButton(Button_Add_Normal, () => RefreshCountClick(++UseCount));
|
|
BindButton(Button_Zero, () => RefreshCountClick(1));
|
|
BindButton(Button_Zero_Normal, () => RefreshCountClick(1));
|
|
BindButton(Button_Max, () => RefreshCountClick((int)CategoryManager.Instance.GetItemCount(ItemID)));
|
|
BindButton(Button_Max_Normal, () => RefreshCountClick((int)CategoryManager.Instance.GetItemCount(ItemID)));
|
|
BindButton(Button_Use, OnUseClick);
|
|
BindButton(Button_Use_Normal, OnUseClick);
|
|
#endregion
|
|
|
|
ScrollView_Source.Init(RefreshItem);
|
|
var dataItem = CategoryManager.Instance.GetItemData(ItemID);
|
|
Button_Source.gameObject.SetActive(dataItem.Acquisition.Length > 0);
|
|
Button_Source_Normal.gameObject.SetActive(dataItem.Acquisition.Length > 0);
|
|
|
|
ShowingSource = false;
|
|
}
|
|
private void RefreshItem(GameObject cell, int index)
|
|
{
|
|
if (!dicScrollItem.TryGetValue(cell.GetInstanceID(), out ItemSourceTab item))
|
|
{
|
|
item = new ItemSourceTab(cell, () =>
|
|
{
|
|
CloseWindow();
|
|
onWindowCloseCallback?.Invoke();
|
|
});
|
|
dicScrollItem.Add(cell.GetInstanceID(), item);
|
|
}
|
|
var dataItem = CategoryManager.Instance.GetItemData(ItemID);
|
|
item.SetInfo(dataItem.Acquisition[index]);
|
|
}
|
|
|
|
void RefreshNormalNode()
|
|
{
|
|
var dataItem = CategoryManager.Instance.GetItemData(ItemID);
|
|
Text_ItemName_Normal.text = CommonUtils.GetLocalizeText(dataItem.NameLocal);
|
|
Text_ItemType_Normal.text = CommonUtils.GetLocalizeText(dataItem.IntroductionTitleKey);
|
|
Text_ItemIntroduce_Normal.text = CommonUtils.GetLocalizeText(dataItem.IntroductionKey);
|
|
|
|
if (dataItem.HideStockNumber)
|
|
{
|
|
Text_have_Normal.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
Text_have_Normal.text = CategoryManager.Instance.GetItemCount(ItemID).ToString();
|
|
}
|
|
if (hideUseBtn)
|
|
{
|
|
Image_UseNumBg_Normal.gameObject.SetActive(false);
|
|
Button_Use_Normal.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
//可使用道具或有跳转功能时显示使用按钮
|
|
Button_Use_Normal.gameObject.SetActive(dataItem.Type == ItemType.Useable || CategoryManager.Instance.ItemJumpType(ItemID) != cfg.JumpFuncType.None);
|
|
Image_UseNumBg_Normal.gameObject.SetActive(dataItem.Type == ItemType.Useable
|
|
&& dataItem.Param1 == (int)ItemUseType.ItemExchange
|
|
&& dataItem.MaxUseCount != 1);
|
|
}
|
|
|
|
var size = new Vector2(1203, 663) + (Button_Use_Normal.IsActive() ? new Vector2(0, 100) : new Vector2(0, 0));
|
|
size += (Image_UseNumBg_Normal.IsActive() ? new Vector2(0, 100) : new Vector2(0, 0));
|
|
NormalNode.GetComponent<RectTransform>().sizeDelta = size;
|
|
|
|
Text_Num_Normal.text = UseCount.ToString();
|
|
|
|
var spritePath = CommonUtils.GetItemPath(ItemID);
|
|
Image_ItemIcon_Normal.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(spritePath);
|
|
}
|
|
|
|
void RefreshSourceNode()
|
|
{
|
|
var dataItem = CategoryManager.Instance.GetItemData(ItemID);
|
|
Text_ItemName_Source.text = CommonUtils.GetLocalizeText(dataItem.NameLocal);
|
|
Text_ItemType.text = CommonUtils.GetLocalizeText(dataItem.IntroductionTitleKey);
|
|
Text_ItemIntroduce.text = CommonUtils.GetLocalizeText(dataItem.IntroductionKey);
|
|
|
|
if (dataItem.HideStockNumber)
|
|
{
|
|
Text_have.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
Text_have.text = CategoryManager.Instance.GetItemCount(ItemID).ToString();
|
|
}
|
|
|
|
if (hideUseBtn)
|
|
{
|
|
Image_UseNumBg_source.gameObject.SetActive(false);
|
|
Button_Use.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
//可使用道具或有跳转功能时显示使用按钮
|
|
Button_Use.gameObject.SetActive(dataItem.Type == ItemType.Useable || CategoryManager.Instance.ItemJumpType(ItemID) != cfg.JumpFuncType.None);
|
|
Image_UseNumBg_source.gameObject.SetActive(dataItem.Type == ItemType.Useable
|
|
&& dataItem.Param1 == (int)ItemUseType.ItemExchange
|
|
&& dataItem.MaxUseCount != 1);
|
|
}
|
|
|
|
var size = new Vector2(1832, 663) + (Button_Use.IsActive() ? new Vector2(0, 100) : new Vector2(0, 0));
|
|
size += (Image_UseNumBg_source.IsActive() ? new Vector2(0, 100) : new Vector2(0, 0));
|
|
SourceNode.GetComponent<RectTransform>().sizeDelta = size;
|
|
var lineImage = FindObj("MainNode/SourceNode/Image");
|
|
lineImage.GetComponent<RectTransform>().sizeDelta = new Vector2(3, size.y - 200);
|
|
Text_Num_Source.text = UseCount.ToString();
|
|
|
|
var spritePath = CommonUtils.GetItemPath(ItemID);
|
|
Image_ItemIcon_Source.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(spritePath);
|
|
|
|
ScrollView_Source.ShowList(dataItem.Acquisition.Length);
|
|
}
|
|
|
|
void RefreshCountClick(int ItemCount)
|
|
{
|
|
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
|
|
UseCount = (int)Mathf.Clamp(ItemCount, 1, CategoryManager.Instance.GetItemCount(ItemID));
|
|
Text_Num_Normal.text = UseCount.ToString();
|
|
Text_Num_Source.text = UseCount.ToString();
|
|
}
|
|
|
|
//invoke when open window
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when close window
|
|
protected override void OnHideWindow()
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when destroy
|
|
public override void OnRelease()
|
|
{
|
|
base.OnRelease();
|
|
}
|
|
|
|
protected override void OnCloseClick()
|
|
{
|
|
base.OnCloseClick();
|
|
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
|
|
CloseWindow();
|
|
}
|
|
|
|
#region Button_click
|
|
void SwitchSourcePanel(bool value)
|
|
{
|
|
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
|
|
ShowingSource = value;
|
|
}
|
|
void OnUseClick()
|
|
{
|
|
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
|
|
if (CategoryManager.Instance.ItemJumpType(ItemID) != cfg.JumpFuncType.None)
|
|
{
|
|
var dataItem = CategoryManager.Instance.GetItemData(ItemID);
|
|
JumpToManager.JumpFunc<int, Action>(CategoryManager.Instance.ItemJumpType(ItemID), dataItem.JumpToParam, () =>
|
|
{
|
|
CloseWindow();
|
|
onWindowCloseCallback?.Invoke();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
//CategoryManager.Instance.UseItem(ItemID, UseCount);
|
|
var dataItem = CategoryManager.Instance.GetItemData(ItemID);
|
|
var itemType = (ItemUseType)dataItem.Param1;
|
|
|
|
if (itemType == ItemUseType.ItemExchange)
|
|
{
|
|
//普通道具使用直接进行道具转换,不会打开二级窗口
|
|
CategoryManager.Instance.UseItem(ItemID, UseCount);
|
|
CloseWindow();
|
|
}
|
|
else
|
|
{
|
|
//礼包类型打开二级窗口
|
|
var count = CategoryManager.Instance.GetItemCount(ItemID);
|
|
CloseWindow();
|
|
int useCount = (int)count;
|
|
if (dataItem.MaxUseCount > 0)
|
|
{
|
|
useCount = (int)Math.Min(dataItem.MaxUseCount, count);
|
|
}
|
|
UI_GiftItemController.Open(ItemID, useCount);
|
|
}
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
}
|