PGRData/Script/matrix/xui/xuigoldenminer/shop/XUiShopTipPanel.lua
2024-09-01 22:49:41 +02:00

78 lines
No EOL
2.5 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---@class XGoldenMinerShopTipPanel
---@field _ItemGrid XUiGoldenMinerItemGrid
local XUiShopShopTipPanel = XClass(nil, "XUiShopShopTipPanel")
function XUiShopShopTipPanel:Ctor(ui)
self.GameObject = ui.gameObject
self.Transform = ui.transform
XTool.InitUiObject(self)
self._ItemGrid = false
self.IsShow = false
self:SetActive(false)
self:AddBtnListener()
end
---@param itemGrid XUiGoldenMinerItemGrid
function XUiShopShopTipPanel:Refresh(buffId, itemGrid, positionX)
if not self.BtnSell then
XLog.Error("当前Ui资源与代码不匹配请打包资源")
return
end
self.Transform.position = Vector3(positionX, self.Transform.position.y, self.Transform.position.z)
if buffId then
self:UpdateBuff(buffId)
elseif itemGrid then
self:UpdateItem(itemGrid)
end
end
function XUiShopShopTipPanel:UpdateBuff(buffId)
local buffName = XGoldenMinerConfigs.GetBuffName(buffId)
local buffDesc = XGoldenMinerConfigs.GetBuffDesc(buffId)
local buffIcon = XGoldenMinerConfigs.GetBuffIcon(buffId)
self.TxtName.text = buffName
self.TxtTips.text = buffDesc
self.Txt02.gameObject:SetActiveEx(false)
self.BtnSell.gameObject:SetActiveEx(false)
if not string.IsNilOrEmpty(buffIcon) then
self.RawBuffIcon:SetRawImage(buffIcon)
end
end
---@param itemGrid XUiGoldenMinerItemGrid
function XUiShopShopTipPanel:UpdateItem(itemGrid)
self._ItemGrid = itemGrid
local item = itemGrid:GetItemColumn()
local itemName = XGoldenMinerConfigs.GetItemName(item:GetItemId())
local itemDesc = XGoldenMinerConfigs.GetItemDescribe(item:GetItemId())
local itemIcon = XGoldenMinerConfigs.GetItemIcon(item:GetItemId())
local price = XGoldenMinerConfigs.GetItemSellPrice(item:GetItemId())
self.TxtName.text = itemName
self.TxtTips.text = itemDesc
self.TxtPrice.text = price
self.Txt02.gameObject:SetActiveEx(true)
self.BtnSell.gameObject:SetActiveEx(true)
if not string.IsNilOrEmpty(itemIcon) then
self.RawBuffIcon:SetRawImage(itemIcon)
end
end
function XUiShopShopTipPanel:SetActive(active)
self.IsShow = active
self.GameObject:SetActiveEx(active)
end
--region Ui - BtnListener
function XUiShopShopTipPanel:AddBtnListener()
XUiHelper.RegisterClickEvent(self, self.BtnSell, self.OnBtnSellClick)
end
function XUiShopShopTipPanel:OnBtnSellClick()
XEventManager.DispatchEvent(XEventId.EVENT_GOLDEN_MINER_SHOP_SELL_ITEM, self._ItemGrid)
end
--endregion
return XUiShopShopTipPanel