665 lines
23 KiB
C#
665 lines
23 KiB
C#
using cfg;
|
||
using cfg.ActorCfg;
|
||
using Cysharp.Threading.Tasks;
|
||
using Framework;
|
||
using Gameplay;
|
||
using Gameplay.Common;
|
||
using Gameplay.Level;
|
||
using Gameplay.Net;
|
||
using PhxhSDK;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
|
||
public class UI_ItemDetailInfoController : UIWindow
|
||
{
|
||
#region UI
|
||
//UI GameObj
|
||
///Auto Gen Start///
|
||
public Image Image_BG;
|
||
public Image Image_Name;
|
||
public TMP_Text Text_Name1;
|
||
public Image Image_Item;
|
||
public TMP_Text Text_Have;
|
||
public TMP_Text Text_InfoNum;
|
||
public TMP_Text Text_Describe;
|
||
public Image Image_UseBG;
|
||
public Button Button_Min;
|
||
public TMP_Text Text_Min;
|
||
public Button Button_Minus;
|
||
public Button Button_Plus;
|
||
public Button Button_Max;
|
||
public TMP_Text Text_Max;
|
||
public TMP_Text Text_UseNum;
|
||
public Button Button_UseConfirm;
|
||
public TMP_Text Text_Use;
|
||
public Button Button_From;
|
||
public TMP_Text Text_From1;
|
||
public Image Image_Open;
|
||
public TMP_Text Text_From2;
|
||
public Button Button_0;
|
||
public TMP_Text Text_LevelInfo1;
|
||
public TMP_Text Text_GoTo1;
|
||
public TMP_Text Text_Name2;
|
||
public Button Button_ChooseConfirm;
|
||
public TMP_Text Text_Choose;
|
||
|
||
///Auto Gen End///
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// <20><>Ʒ<EFBFBD><C6B7><EFBFBD>鴰<EFBFBD><E9B4B0>
|
||
/// </summary>
|
||
class ItemInfoPopup : UIGameObjectWrapper
|
||
{
|
||
public enum ItemInfoPanelState
|
||
{
|
||
Info,
|
||
Choose
|
||
}
|
||
GameObject BG;
|
||
GameObject ItemInfopanel;
|
||
GameObject ItemChoosepanel;
|
||
|
||
InfoPanel infoPanel;
|
||
ChoosePanel choosePanel;
|
||
|
||
Action closeWindowAction;
|
||
|
||
#region PanelClass
|
||
/// <summary>
|
||
/// <20><>Ʒ<EFBFBD><C6B7>Ϣ<EFBFBD><CFA2><EFBFBD>
|
||
/// </summary>
|
||
class InfoPanel : UIGameObjectWrapper
|
||
{
|
||
int ID;
|
||
DataItem dataItem;
|
||
int usageAmount = 1;
|
||
private bool hideUseBtn;
|
||
|
||
#region UIGameObj
|
||
GameObject UseTextInput;
|
||
GameObject UseConfirmButton;
|
||
TextMeshProUGUI NameText;
|
||
Image itemIcon;
|
||
TextMeshProUGUI itemCount;
|
||
GameObject itemFrom;
|
||
TextMeshProUGUI itemInfoText;
|
||
GameObject MinButton;
|
||
GameObject MinusButton;
|
||
GameObject PlusButton;
|
||
GameObject MaxButton;
|
||
PhxhScrollView scrollView;
|
||
#endregion
|
||
|
||
ItemInfoPopup parentPopup;
|
||
|
||
public InfoPanel(GameObject Root, bool hideUseBtn = false, bool isScale = false) : base(Root, isScale)
|
||
{
|
||
this.hideUseBtn = hideUseBtn;
|
||
Root.SetActive(true);
|
||
Binder(Root);
|
||
|
||
BindPanelButtons();
|
||
|
||
SetSourcePanel();
|
||
}
|
||
|
||
public async void Show(int itemID, ItemInfoPopup parent)
|
||
{
|
||
IsScaleShow = true;
|
||
|
||
ID = itemID;
|
||
this.parentPopup = parent;
|
||
usageAmount = 1;
|
||
|
||
dataItem = CategoryManager.Instance.GetItemData(itemID);
|
||
|
||
string itemName = CommonUtils.GetLocalizeText(dataItem.NameLocal);
|
||
NameText.text = itemName;
|
||
var spritePath = CommonUtils.GetItemPath(itemID);
|
||
itemIcon.sprite = await LoadAssetAsync<Sprite>(spritePath);
|
||
itemCount.text = Actor.Instance.Item.GetItemCount(itemID).ToString();
|
||
|
||
UpdateItemButtons(dataItem.Type == ItemType.Useable || CategoryManager.Instance.ItemJumpType(itemID) != cfg.JumpFuncType.None, dataItem.BatchUsing);
|
||
//<2F><>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><DFBB><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʾʹ<CABE>ð<EFBFBD>ť
|
||
|
||
itemFrom.SetActive(AcquisitionAmount() > 0);//<2F>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>Դʱ<D4B4><CAB1>ʾ<EFBFBD><CABE>Դ<EFBFBD><D4B4>ť
|
||
|
||
string introduction = CommonUtils.GetLocalizeText(dataItem.IntroductionKey);
|
||
itemInfoText.text = introduction;
|
||
|
||
CommonUtils.GetGameObject(itemFrom, "Image_Open").SetActive(false);
|
||
}
|
||
|
||
public void Hide()
|
||
{
|
||
IsScaleShow = false;
|
||
Dispose();
|
||
}
|
||
|
||
void Binder(GameObject Root)
|
||
{
|
||
UseConfirmButton = CommonUtils.GetGameObject(Root, "ImageBG/Button_UseConfirm");
|
||
UseTextInput = CommonUtils.GetGameObject(Root, "ImageBG/Image_UseBG");
|
||
NameText = CommonUtils.GetComponent<TextMeshProUGUI>(Root, "ImageBG/Image_Name/Text_Name1");
|
||
itemIcon = CommonUtils.GetComponent<Image>(Root, "ImageBG/Image_Item");
|
||
itemCount = CommonUtils.GetComponent<TextMeshProUGUI>(Root, "ImageBG/Image_Item/Text_InfoNum");
|
||
itemFrom = CommonUtils.GetGameObject(Root, "ImageBG/Button_From");
|
||
itemInfoText = GetComponent<TextMeshProUGUI>("ImageBG/Image_Item/Text_Describe");
|
||
MinButton = CommonUtils.GetGameObject(Root, "ImageBG/Image_UseBG/Button_Min");
|
||
MinusButton = CommonUtils.GetGameObject(Root, "ImageBG/Image_UseBG/Button_Minus");
|
||
PlusButton = CommonUtils.GetGameObject(Root, "ImageBG/Image_UseBG/Button_Plus");
|
||
MaxButton = CommonUtils.GetGameObject(Root, "ImageBG/Image_UseBG/Button_Max");
|
||
}
|
||
|
||
void UpdateItemButtons(bool isItemUsable, bool isItemBatchUse)
|
||
{
|
||
if(!hideUseBtn)
|
||
{
|
||
UseConfirmButton.SetActive(isItemUsable);
|
||
UseTextInput.SetActive(isItemUsable && isItemBatchUse);
|
||
}
|
||
else
|
||
{
|
||
UseConfirmButton.SetActive(false);
|
||
UseTextInput.SetActive(false);
|
||
}
|
||
|
||
TextMeshProUGUI amountText = CommonUtils.GetComponent<TextMeshProUGUI>(UseTextInput, "Text_UseNum");
|
||
amountText.text = usageAmount.ToString();
|
||
}
|
||
|
||
void BindPanelButtons()
|
||
{
|
||
CommonUtils.BindButton(itemFrom.GetComponent<Button>(), () =>
|
||
{
|
||
GameObject panel = CommonUtils.GetGameObject(itemFrom, "Image_Open");
|
||
panel.SetActive(!panel.activeSelf);
|
||
scrollView.UpdateData(true);
|
||
});
|
||
CommonUtils.BindButton(MinButton.GetComponent<Button>(), () =>
|
||
{
|
||
UpdateUsageAmount(1);
|
||
});
|
||
CommonUtils.BindButton(MinusButton.GetComponent<Button>(), () =>
|
||
{
|
||
UpdateUsageAmount(usageAmount - 1);
|
||
});
|
||
CommonUtils.BindButton(PlusButton.GetComponent<Button>(), () =>
|
||
{
|
||
UpdateUsageAmount(usageAmount + 1);
|
||
});
|
||
CommonUtils.BindButton(MaxButton.GetComponent<Button>(), () =>
|
||
{
|
||
UpdateUsageAmount(MaxAmount());
|
||
});
|
||
CommonUtils.BindButton(UseConfirmButton.GetComponent<Button>(), UseItem);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <20><>Ʒ<EFBFBD><C6B7>Դ<EFBFBD><D4B4><EFBFBD>
|
||
/// </summary>
|
||
void SetSourcePanel()
|
||
{
|
||
scrollView = CommonUtils.GetComponent<PhxhScrollView>(itemFrom, "Image_Open/PhxhScrollView");
|
||
|
||
scrollView.SetItemCountFunc(AcquisitionAmount);
|
||
//scrollView.SetItemSizeFunc((int index) => new Vector2(SOURCE_BUTTON_WIDTH, SOURCE_BUTTON_HEIGHT));
|
||
scrollView.SetUpdateFunc((int index, RectTransform item) =>
|
||
{
|
||
item.gameObject.SetActive(true);
|
||
|
||
item.GetComponent<Button>().onClick.RemoveAllListeners();
|
||
int JumpID = dataItem.Acquisition[index];
|
||
|
||
TextMeshProUGUI itemSourceText = CommonUtils.GetComponent<TextMeshProUGUI>(item.gameObject, "Text_LevelInfo1");
|
||
TMP_Text Text_GoTo1 = CommonUtils.GetComponent<TMP_Text>(item.gameObject, "Text_GoTo1");
|
||
|
||
if (JumpID > 100000)//TODO <20><EFBFBD><F3B6A8B2><EFBFBD><EFBFBD>Ƴ<EFBFBD>updatefunc
|
||
{
|
||
itemSourceText.text = LevelManager.Instance.LevelIDToNum(JumpID) + " " + LevelManager.Instance.LevelIDToName(JumpID);
|
||
|
||
CommonUtils.BindButton(item.gameObject.GetComponent<Button>(), () =>
|
||
{
|
||
JumpToLevel(JumpID);
|
||
});
|
||
var btn = item.gameObject.GetComponent<Button>();
|
||
if (btn == null)
|
||
return;
|
||
|
||
if (LevelManager.Instance.CheckLevelUnlock(JumpID))
|
||
{
|
||
btn.interactable = true;
|
||
itemSourceText.color = Color.white;
|
||
CommonUtils.GetComponent<Image>(item.gameObject, "icon").color = new Color(1, 1, 1, 1);
|
||
Text_GoTo1.text = CommonUtils.GetLocalizeText("Package_JumpTo");
|
||
}
|
||
else
|
||
{
|
||
btn.interactable = false;
|
||
itemSourceText.color = new Color(.2f, .2f, .2f, 1);
|
||
CommonUtils.GetComponent<Image>(item.gameObject, "icon").color = new Color(1, 1, 1, .5f);
|
||
Text_GoTo1.text = CommonUtils.GetLocalizeText("Package_Lock");
|
||
}
|
||
}
|
||
else//<2F>̵<EFBFBD><CCB5><EFBFBD>ת
|
||
{
|
||
var data = ShopManager.Instance.GetShopData(JumpID);
|
||
itemSourceText.text = CommonUtils.GetLocalizeText(data.Name);
|
||
CommonUtils.BindButton(item.gameObject.GetComponent<Button>(), () =>
|
||
{
|
||
JumpToShop(JumpID);
|
||
});
|
||
|
||
var btn = item.gameObject.GetComponent<Button>();
|
||
btn.interactable = true;
|
||
itemSourceText.color = Color.white;
|
||
CommonUtils.GetComponent<Image>(item.gameObject, "icon").color = new Color(1, 1, 1, 1);
|
||
Text_GoTo1.text = CommonUtils.GetLocalizeText("Package_JumpTo");
|
||
}
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
int AcquisitionAmount()
|
||
{
|
||
if (dataItem != null && dataItem.Acquisition != null)
|
||
{
|
||
return dataItem.Acquisition.Length;
|
||
}
|
||
|
||
DebugUtil.LogError("<22><EFBFBD><DEB5><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>δ<EFBFBD><CEB4><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>Դ! <20><><EFBFBD><EFBFBD>id: " + ID);
|
||
return 0;
|
||
}
|
||
|
||
void UpdateUsageAmount(int amount)
|
||
{
|
||
usageAmount = amount;
|
||
if (usageAmount < 1)
|
||
{
|
||
usageAmount = 1;
|
||
}
|
||
if (usageAmount > MaxAmount())
|
||
{
|
||
usageAmount = MaxAmount();
|
||
}
|
||
TextMeshProUGUI amountText = CommonUtils.GetComponent<TextMeshProUGUI>(UseTextInput, "Text_UseNum");
|
||
amountText.text = usageAmount.ToString();
|
||
}
|
||
int MaxAmount()
|
||
{
|
||
return (int)CategoryManager.Instance.GetItemCount(ID);
|
||
}
|
||
void UseItem()
|
||
{
|
||
DataItem data = CategoryManager.Instance.GetItemData(ID);
|
||
ItemUseType useType = (ItemUseType)data.Param1;
|
||
DebugUtil.Log("use item, item id is: " + ID + " type is: " + useType);
|
||
if (useType == ItemUseType.SelectableChest)
|
||
{
|
||
DebugUtil.Log("use selectable chest");
|
||
this.Hide();
|
||
parentPopup.ShowPopup(ItemInfoPanelState.Choose, ID);
|
||
}
|
||
else if (useType == ItemUseType.None)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
|
||
{
|
||
JumpFuncType jumpFuncType = CategoryManager.Instance.ItemJumpType(ID);
|
||
if (jumpFuncType != cfg.JumpFuncType.None)
|
||
{
|
||
DebugUtil.Log("jump to: " + jumpFuncType);
|
||
JumpToManager.JumpFunc<int, Action>(jumpFuncType, data.JumpToParam, () =>
|
||
{
|
||
parentPopup.CloseWindow();
|
||
});
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.LogError("cannot use!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.Log("use item!");
|
||
if (EnergyManager.Instance.isItemCanBuyEnergy(ID, GLConfig.Inst.data.EnergyPointID))
|
||
{
|
||
int upperValue = EnergyManager.Instance.MaxConsumeAmountWithoutConvert(ID, out _);
|
||
if (usageAmount > upperValue)
|
||
{
|
||
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("BuyEnergy_failed_overflow"));// ָ<>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
|
||
return;
|
||
}
|
||
}
|
||
CategoryManager.Instance.UseItem(ID, usageAmount);
|
||
parentPopup.HidePopup();
|
||
}
|
||
}
|
||
|
||
void JumpToLevel(int level)
|
||
{
|
||
if (LevelManager.Instance.CheckLevelUnlock(level))
|
||
{
|
||
SignUpManager.Instance.DoNotShowDailyAccumulate = true;
|
||
JumpToManager.JumpFunc<int, Action>(cfg.JumpFuncType.Level_Detail, level, () =>
|
||
{
|
||
parentPopup.CloseWindow();
|
||
});//JumpToLevelDetail(level);
|
||
}
|
||
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, () =>
|
||
{
|
||
parentPopup.CloseWindow();
|
||
});//JumpToShopDetail(ShopId);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>
|
||
/// </summary>
|
||
class ChoosePanel : UIGameObjectWrapper
|
||
{
|
||
int ID;
|
||
|
||
Dictionary<int, ChooseItem> ViewContentButton = new Dictionary<int, ChooseItem>();
|
||
PhxhScrollView itemView;
|
||
Button chooseConfirmButton;
|
||
|
||
ItemInfoPopup parentPopup;
|
||
|
||
int maxChooseAmount = 1;//TODO Ŀǰ<C4BF><C7B0>ѡ<EFBFBD><D1A1><EFBFBD>ֻ<EFBFBD><D6BB>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ʒ<EFBFBD>һ<EFBFBD>
|
||
|
||
List<int> chosenItems = new List<int>();
|
||
|
||
public ChoosePanel(GameObject go, bool hideUseBtn = false, bool isScale = false) : base(go, isScaleShow: isScale)
|
||
{
|
||
go.SetActive(true);
|
||
itemView = GetComponent<PhxhScrollView>("ImageBG/PhxhScrollView");
|
||
chooseConfirmButton = GetComponent<Button>("ImageBG/Button_ChooseConfirm");
|
||
|
||
itemView.SetItemCountFunc(ChooseItemsCount);
|
||
itemView.SetUpdateFunc(UpdateItem);
|
||
//itemView.SetItemSizeFunc(CellSize);
|
||
// 隐藏选择按钮
|
||
if (hideUseBtn) chooseConfirmButton.gameObject.SetActive(false);
|
||
|
||
CommonUtils.BindButton(chooseConfirmButton, () =>
|
||
{
|
||
ConfirmChoose();
|
||
});
|
||
}
|
||
|
||
public void Show(int itemID, ItemInfoPopup parent)
|
||
{
|
||
ID = itemID;
|
||
IsScaleShow = true;
|
||
parentPopup = parent;
|
||
|
||
itemView.UpdateData(true);
|
||
}
|
||
public void Hide()
|
||
{
|
||
IsScaleShow = false;
|
||
Dispose();
|
||
}
|
||
public override void Dispose()
|
||
{
|
||
base.Dispose();
|
||
chosenItems.Clear();
|
||
}
|
||
|
||
#region scrollviewFunc
|
||
/// <summary>
|
||
/// <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
int ChooseItemsCount()
|
||
{
|
||
DataItem item = CategoryManager.Instance.GetItemData(ID);
|
||
return item.Selections.Count;
|
||
}
|
||
|
||
//Vector2 CellSize(int index)
|
||
//{
|
||
// return new Vector2(ITEM_BUTTON_WIDTH, ITEM_BUTTON_HEIGHT);
|
||
//}
|
||
|
||
void UpdateItem(int index, RectTransform item)
|
||
{
|
||
var go = item.gameObject;
|
||
go.SetActive(true);
|
||
|
||
if (!ViewContentButton.TryGetValue(go.GetInstanceID(), out ChooseItem Button))
|
||
{
|
||
Button = new ChooseItem(go, ItemChoose);
|
||
ViewContentButton.Add(go.GetInstanceID(), Button);
|
||
}
|
||
DataItem itemData = CategoryManager.Instance.GetItemData(ID);
|
||
var itemCount = itemData.Selections[index];
|
||
|
||
ViewContentButton[go.GetInstanceID()].RefreshData(itemCount.Id, itemCount.Count, chosenItems.Contains(itemCount.Id));
|
||
}
|
||
#endregion
|
||
|
||
#region buttonListener
|
||
void ItemChoose(int itemID)
|
||
{
|
||
if (chosenItems.Contains(itemID))
|
||
{
|
||
chosenItems.Remove(itemID);
|
||
}
|
||
else
|
||
{
|
||
if (maxChooseAmount > 0 && chosenItems.Count >= maxChooseAmount)
|
||
{
|
||
chosenItems.RemoveAt(0);
|
||
}
|
||
chosenItems.Add(itemID);
|
||
}
|
||
itemView.UpdateData(true);
|
||
}
|
||
void ConfirmChoose()
|
||
{
|
||
if (chosenItems.Count > 0)
|
||
{
|
||
int chosenItem = chosenItems[0];
|
||
CategoryManager.Instance.UseItem(ID, itemAmount: 1, chosenItem);
|
||
parentPopup.HidePopup();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5>߰<EFBFBD>ť
|
||
/// </summary>
|
||
class ChooseItem : UIGameObjectWrapper
|
||
{
|
||
int itemID;
|
||
Action<int> callback;
|
||
GameObject chosenCircle;
|
||
|
||
public ChooseItem(GameObject go, Action<int> OnClick, bool isScale = true) : base(go, isScale)
|
||
{
|
||
chosenCircle = CommonUtils.GetGameObject(go, "ChooseRect");
|
||
callback = OnClick;
|
||
CommonUtils.BindButton(go.GetComponent<Button>(), OnButtonClicked);
|
||
}
|
||
|
||
public async void RefreshData(int itemID, int itemCount, bool isChosen)
|
||
{
|
||
if (this.itemID != itemID)
|
||
{
|
||
Dispose();
|
||
Image icon = GetComponent<Image>("ItemIcon");
|
||
var spritePath = CommonUtils.GetItemPath(itemID);
|
||
icon.sprite = await LoadAssetAsync<Sprite>(spritePath);
|
||
|
||
this.itemID = itemID;
|
||
}
|
||
|
||
TextMeshProUGUI countText = GetComponent<TextMeshProUGUI>("ImageCount/TextCount");
|
||
countText.text = itemCount.ToString();
|
||
chosenCircle.SetActive(isChosen);
|
||
}
|
||
|
||
void OnButtonClicked()
|
||
{
|
||
callback?.Invoke(itemID);
|
||
}
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
public ItemInfoPopup(GameObject go, Action closeWindow, bool hideUseBtn = false, bool isScale = true) : base(go, isScaleShow: isScale)
|
||
{
|
||
BG = CommonUtils.GetGameObject(go, "Image_BG");
|
||
closeWindowAction = closeWindow;
|
||
|
||
//info panel
|
||
ItemInfopanel = CommonUtils.GetGameObject(go, "ItemInfo");
|
||
|
||
infoPanel = new InfoPanel(ItemInfopanel, hideUseBtn);
|
||
|
||
//choose panel
|
||
ItemChoosepanel = CommonUtils.GetGameObject(go, "ItemChoose");
|
||
|
||
choosePanel = new ChoosePanel(ItemChoosepanel, hideUseBtn);
|
||
|
||
BG.AddComponent<Button>().onClick.AddListener(() => HidePopup());
|
||
}
|
||
|
||
public void ShowPopup(ItemInfoPanelState panel, int itemID)
|
||
{
|
||
IsScaleShow = true;
|
||
switch (panel)
|
||
{
|
||
case ItemInfoPanelState.Info:
|
||
infoPanel.Show(itemID, this);
|
||
|
||
break;
|
||
case ItemInfoPanelState.Choose:
|
||
choosePanel.Show(itemID, this);
|
||
break;
|
||
}
|
||
}
|
||
|
||
public void HidePopup()
|
||
{
|
||
IsScaleShow = false;
|
||
infoPanel.Hide();
|
||
choosePanel.Hide();
|
||
}
|
||
|
||
public void CloseWindow()
|
||
{
|
||
closeWindowAction.Invoke();
|
||
}
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
ItemInfoPopup panel;
|
||
int ItemID;
|
||
RawImage GaussianBlurMask;
|
||
Action callback;
|
||
|
||
private bool hideUseBtn;
|
||
|
||
// deal with input data
|
||
|
||
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_ItemDetailInfo, data);
|
||
}
|
||
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
var openData = (OpenData)data;
|
||
|
||
ItemID = openData.itemID;
|
||
callback = openData.CloseCallback;
|
||
hideUseBtn = openData.HideUseBtn;
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
//bind UI GameObj
|
||
UI_ItemDetailInfoBinder.GetComponents(this);
|
||
GaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
||
GaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
|
||
|
||
panel = new ItemInfoPopup(gameObject, () =>
|
||
{
|
||
CloseWindow();
|
||
callback?.Invoke();
|
||
}, hideUseBtn: hideUseBtn);
|
||
panel.ShowPopup(ItemInfoPopup.ItemInfoPanelState.Info, ItemID);
|
||
|
||
AddBgClose(OnCloseClick);
|
||
}
|
||
|
||
//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()
|
||
{
|
||
CloseWindow();
|
||
base.OnCloseClick();
|
||
}
|
||
} |