2025-01-04 23:00:19 +08:00

52 lines
2.1 KiB
Lua

---@class WB_PlayerLevel_C:UUserWidget
---@field NewButton_AddExp UNewButton
---@field ProgressBar_EXP UProgressBar
---@field TextBlock_Exp UTextBlock
---@field TextBlock_Level UTextBlock
--Edit Below--
local WB_PlayerLevel = { bInitDoOnce = false; };
--[==[ Construct
function WB_PlayerLevel:Construct()
end
-- Construct ]==]
-- function WB_PlayerLevel:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_PlayerLevel:Destruct()
-- end
function WB_PlayerLevel:Init()
WidgetLibrary.BindButtonClicked(self.NewButton_AddExp, self.ClickAddExp, self)
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.Exp), self.UpdateLevelInfo, self)
self:UpdateLevelInfo()
end
function WB_PlayerLevel:UpdateLevelInfo()
local Exp = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.Exp)
if Exp == nil then Exp = 0 end
local Level, NowLevelExp, ExpRange = LevelConfig.GetLevel(Exp)
self.ProgressBar_EXP:SetPercent(NowLevelExp / ExpRange)
self.TextBlock_Exp:SetText(NowLevelExp .. "/" .. ExpRange)
self.TextBlock_Level:SetText("Lv:" .. Level)
end
function WB_PlayerLevel:ClickAddExp()
local LocalPK = UGCSystemLibrary.GetLocalPlayerKey()
local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation_Strip)
local Gold = ArchiveDataConfig.GetPlayerArchiveDataFromType(LocalPK, ArchiveDataConfig.EArchiveType.Gold)
SecondaryConfirmationWidget:SetValRange(0, Gold and Gold or 0)
SecondaryConfirmationWidget:SetTextInfo(function(Val) return string.format("消耗 %s 个金币兑换%s Exp。", tostring(Val), tostring(Val * PlacementModeConfig.PlacingAttr.RatioGoldToExp)) end)
SecondaryConfirmationWidget:BindConfirmCallBack(self.ConfirmExchangeGoldToExp, self)
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation_Strip, false)
end
function WB_PlayerLevel:ConfirmExchangeGoldToExp(GoldVal)
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "GoldToExp", UGCSystemLibrary.GetLocalPlayerKey(), GoldVal)
end
return WB_PlayerLevel;