UGCProjects/GZJ/Script/UI/WBP_Unpacking_Item.lua

97 lines
3.4 KiB
Lua
Raw Permalink Normal View History

2025-01-08 22:46:12 +08:00
---@class WBP_Unpacking_Item_C:UUserWidget
---@field Button_UnpackInfo UButton
---@field Button_Unpacking1 UButton
---@field Button_Unpacking10 UButton
---@field Image_Icon UImage
---@field Overlay_UnpackInfo UOverlay
---@field TextBlock_Gold1 UTextBlock
---@field TextBlock_Gold10 UTextBlock
---@field WBP_UnpackingInfo UWBP_UnpackingInfo_C
---@field UnpackingLevel int32
---@field PressInfoTime float
--Edit Below--
local WBP_Unpacking_Item = {
bInitDoOnce = false;
bPressInfo = false;
PressTime = 0;
};
function WBP_Unpacking_Item:Construct()
self.Button_Unpacking1.OnClicked:Add(WBP_Unpacking_Item.Unpacking1, self)
self.Button_Unpacking10.OnClicked:Add(WBP_Unpacking_Item.Unpacking10, self)
self.TextBlock_Gold1:SetText(tostring(Tables.Unpacking.LevelCoinPoint[self.UnpackingLevel].CoinPoint1))
self.TextBlock_Gold10:SetText(tostring(Tables.Unpacking.LevelCoinPoint[self.UnpackingLevel].CoinPoint10))
self.Image_Icon:SetBrushFromTexture(UE.LoadObject(Tables.Unpacking.LevelCoinPoint[self.UnpackingLevel].Icon));
self.WBP_UnpackingInfo:SetInfoText(Tables.Unpacking.LevelCoinPoint[self.UnpackingLevel].Info)
self.WBP_UnpackingInfo:SetVisibility(ESlateVisibility.Collapsed)
self.Button_UnpackInfo.OnClicked:Add(WBP_Unpacking_Item.OnClickInfo, self)
self.Button_UnpackInfo.OnPressed:Add(WBP_Unpacking_Item.OnPressInfo, self)
self.Button_UnpackInfo.OnReleased:Add(WBP_Unpacking_Item.OnReleaseInfo, self)
self.bCanEverTick = true
end
function WBP_Unpacking_Item:Tick(MyGeometry, InDeltaTime)
if self.bPressInfo then
self.PressTime = self.PressTime + InDeltaTime
if self.PressTime > self.PressInfoTime then
-- 执行显示操作
self:ShowUnpackItemInfo()
end
else
self.PressTime = 0
end
end
function WBP_Unpacking_Item:Destruct()
self.Button_Unpacking1.OnClicked:Remove(WBP_Unpacking_Item.Unpacking1, self)
self.Button_Unpacking10.OnClicked:Remove(WBP_Unpacking_Item.Unpacking10, self)
end
-- 检查钱够不够
function WBP_Unpacking_Item:CheckMoney(InMoney)
local PS = GameDataManager.GetLocalPlayerState()
return PS.CoinPoint.Current > InMoney;
end
-- 获取当前需要多少钱
function WBP_Unpacking_Item:GetMoney(Level, Count)
return Tables.Unpacking.LevelCoinPoint[Level][string.format('CoinPoint') .. tostring(Count)]
end
function WBP_Unpacking_Item:Unpacking1()
-- 检测当前 Money 够不够
if self:CheckMoney(self:GetMoney(self.UnpackingLevel, 1)) then
local PC = STExtraGameplayStatics.GetFirstPlayerController(self)
UnrealNetwork.CallUnrealRPC(PC, UGCGameSystem.GameState, "Server_RPC_Unpacking", UGCPawnAttrSystem.GetPlayerKeyInt64(PC.Pawn), self.UnpackingLevel, 1)
else
UIManager:GetPanel(EUIType.Unpacking):SetAlert(true)
end
end
function WBP_Unpacking_Item:Unpacking10()
if self:CheckMoney(self:GetMoney(self.UnpackingLevel, 10)) then
local PC = STExtraGameplayStatics.GetFirstPlayerController(self)
UnrealNetwork.CallUnrealRPC(PC, UGCGameSystem.GameState, "Server_RPC_Unpacking", UGCPawnAttrSystem.GetPlayerKeyInt64(PC.Pawn), self.UnpackingLevel, 10)
else
UIManager:GetPanel(EUIType.Unpacking):SetAlert(true)
end
end
function WBP_Unpacking_Item:OnClickInfo()
end
function WBP_Unpacking_Item:OnPressInfo()
self.bPressInfo = true
end
function WBP_Unpacking_Item:OnReleaseInfo()
self.bPressInfo = false
self.WBP_UnpackingInfo:SetVisibility(ESlateVisibility.Collapsed)
end
function WBP_Unpacking_Item:ShowUnpackItemInfo()
self.WBP_UnpackingInfo:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
end
return WBP_Unpacking_Item;