UGCProjects/GZJ/Script/UI/WBP_TechnologyPanel_Item.lua
2025-01-08 22:46:12 +08:00

124 lines
4.0 KiB
Lua

---@class WBP_TechnologyPanel_Item_C:UUserWidget
---@field Button_Buy UButton
---@field Img_Icon_Technology UImage
---@field Overlay_Buy UOverlay
---@field Panel_Limit UHorizontalBox
---@field TextBlock_6 UTextBlock
---@field TextBlock_BuffDesc UTextBlock
---@field TextBlock_BuffValue UTextBlock
---@field TextBlock_Cost UTextBlock
---@field TextBlock_Limit UTextBlock
---@field WidgetSwitcher_Buy UWidgetSwitcher
---@field Index int32
---@field Icon UTexture2D
---@field Desc FText
---@field BuffValue float
---@field BuyLimit int32
---@field Limit bool
---@field BuyCost int32
--Edit Below--
local WBP_TechnologyPanel_Item = {
bInitDoOnce = false;
NextNum = 0;
};
function WBP_TechnologyPanel_Item:Construct()
self:LuaInit()
local PC = STExtraGameplayStatics.GetFirstPlayerController(self)
if PC and PC:GetCurPlayerState() then
local Val = PC:GetCurPlayerState().TechBuyNum[self.Index]
if Val ~= nil then
if Tables.Tech[self.Index].bLimit and Tables.Tech[self.Index].LimitNum <= Val then
self:SetCanNotBuy()
self.BuyCost = Tables.Tech[self.Index].KillingPoints(Val)
else
self.BuyCost = Tables.Tech[self.Index].KillingPoints(Val + 1)
end
end
end
self.Img_Icon_Technology:SetBrushFromTexture(UE.LoadObject(Tables.Tech[self.Index].Icon))
print("WBP_TechnologyPanel_Item_Fun_" .. "Construct " .. "self.Index : " .. self.Index .. " self.BuyCost : " .. self.BuyCost)
EventSystem:AddListener(EventType.PlayerBuyTechSucceed, WBP_TechnologyPanel_Item.BuyTechSucceed, self)
end
function WBP_TechnologyPanel_Item:Destruct()
EventSystem:RemoveListener(EventType.PlayerBuyTechSucceed, WBP_TechnologyPanel_Item.BuyTechSucceed, self)
end
function WBP_TechnologyPanel_Item:LuaInit()
if self.bInitDoOnce then
return
end
self.bInitDoOnce = true
self.TextBlock_BuffValue:BindingProperty("Text", self.TextBlock_BuffValue_Text, self)
self.Panel_Limit:BindingProperty("Visibility", self.Panel_Limit_Visibility, self)
self.TextBlock_Limit:BindingProperty("Text", self.TextBlock_Limit_Text, self)
self.Button_Buy.OnClicked:Add(self.Button_Buy_OnClicked, self)
self.TextBlock_Cost:BindingProperty("Text", self.TextBlock_Cost_Text, self)
end
function WBP_TechnologyPanel_Item:TextBlock_BuffValue_Text(ReturnValue)
if self.BuffValue >= 1 then
self.TextBlock_6:SetVisibility(ESlateVisibility.Collapsed)
return string.format('%.0f', self.BuffValue)
end
self.TextBlock_6:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
return tostring(math.ceil(self.BuffValue * 100.0));
end
function WBP_TechnologyPanel_Item:Panel_Limit_Visibility(ReturnValue)
return self.BuyLimit <= 0 and ESlateVisibility.Collapsed or ESlateVisibility.SelfHitTestInvisible
end
function WBP_TechnologyPanel_Item:TextBlock_Limit_Text(ReturnValue)
return tostring(self.BuyLimit);
end
function WBP_TechnologyPanel_Item:TextBlock_Cost_Text(ReturnValue)
return tostring(self.BuyCost);
end
function WBP_TechnologyPanel_Item:CheckMoney(InMoney)
local PS = GameDataManager.GetLocalPlayerState();
return PS.KillPoint.Current > InMoney
end
function WBP_TechnologyPanel_Item:GetMoney()
return Tables.Tech[self.Index].KillingPoints(self.NextNum)
end
function WBP_TechnologyPanel_Item:Button_Buy_OnClicked()
if self:CheckMoney(self:GetMoney()) then
local PC = STExtraGameplayStatics.GetFirstPlayerController(self)
UnrealNetwork.CallUnrealRPC(PC, PC, "ServerRPC_BuyTech", self.Index)
EventSystem:SendEvent(EventType.ForceGuide_TechBuy)
else
UIManager:GetPanel(EUIType.Tech):SetAlert(true)
end
NewPlayerGuideManager:RemoveGuide(16)
return nil;
end
function WBP_TechnologyPanel_Item:BuyTechSucceed(TechID, BuyNum)
if TechID == self.Index then
if Tables.Tech[TechID].Limit == true then
self.BuyLimit = self.BuyLimit - 1
end
if Tables.Tech[TechID].bLimit and Tables.Tech[TechID].LimitNum <= BuyNum then
self:SetCanNotBuy()
else
self.NextNum = BuyNum + 1
self.BuyCost = Tables.Tech[TechID].KillingPoints(BuyNum + 1)
end
end
end
function WBP_TechnologyPanel_Item:SetCanNotBuy()
self.WidgetSwitcher_Buy:SetActiveWidgetIndex(1)
end
return WBP_TechnologyPanel_Item;