---@class WBP_ResourceGrade_C:UUserWidget ---@field Button_Select_1 UButton ---@field Button_Select_2 UButton ---@field Button_Select_3 UButton ---@field Button_Select_4 UButton ---@field Image_Select_1 UImage ---@field Image_Select_2 UImage ---@field Image_Select_3 UImage ---@field Image_Select_4 UImage ---@field Panel_BG UWBP_WidgetHeader_C ---@field TextBlock_MidAttack UTextBlock ---@field TextBlock_MidHealth UTextBlock ---@field TextBlock_Select_1 UTextBlock ---@field TextBlock_Select_2 UTextBlock ---@field TextBlock_Select_3 UTextBlock ---@field TextBlock_Select_4 UTextBlock ---@field TextBlock_SeniorAttack UTextBlock ---@field TextBlock_SeniorHealth UTextBlock ---@field TextBlock_SuperAttack UTextBlock ---@field TextBlock_SuperHealth UTextBlock --Edit Below-- local WBP_ResourceGrade = { bInitDoOnce = false, ButtonList = {}, ImageList = {}, TextBlockList = {}, -- AttackTimer = nil; }; function WBP_ResourceGrade:Construct() self.Panel_BG:Construct() for i = 1, 4 do local IndexStr = tostring(i) self.ButtonList[i] = self["Button_Select_"..IndexStr] self.ImageList[i] = self["Image_Select_"..IndexStr] self.TextBlockList[i] = self["TextBlock_Select_"..IndexStr] self.ButtonList[i].OnClicked:Add(function() self:RequestChangeResourceGrade(i) end, self) end self:SetRecommend() EventSystem:AddListener(EventType.OnResourceGradeChanged, WBP_ResourceGrade.OnResourceGradeChanged, self) end function WBP_ResourceGrade:SetRecommend() local ResourceTable = { [EQualityType.Primary] = { Health = "0", Attack = "0", Recommend = 0, }, [EQualityType.Middle] = { Health = '1w', Attack = "2000", Recommend = 0, }, [EQualityType.Senior] = { Health = "4w", Attack = '8000', Recommend = 0, }, [EQualityType.Super] = { Health = "10w", Attack = "1.3w", Recommend = 0, }, } self.TextBlock_MidHealth:SetText('生命值:'.. ResourceTable[EQualityType.Middle].Health) self.TextBlock_MidAttack:SetText('威力值:'.. ResourceTable[EQualityType.Middle].Attack) self.TextBlock_SeniorHealth:SetText('生命值:'.. ResourceTable[EQualityType.Senior].Health) self.TextBlock_SeniorAttack:SetText('威力值:'.. ResourceTable[EQualityType.Senior].Attack) self.TextBlock_SuperHealth:SetText('生命值:'.. ResourceTable[EQualityType.Super].Health) self.TextBlock_SuperAttack:SetText('威力值:'.. ResourceTable[EQualityType.Super].Attack) end function WBP_ResourceGrade:Destruct() EventSystem:RemoveListener(EventType.OnResourceGradeChanged, WBP_ResourceGrade.OnResourceGradeChanged, self) self.ButtonList = {} self.ImageList = {} self.TextBlockList = {} end function WBP_ResourceGrade:OnShowPanel() local PC = GameDataManager.GetLocalPlayerController() local CurResourceGrade = PC.ResourceGrade self:OnResourceGradeChanged(CurResourceGrade) --if self.AttackTimer == nil then -- self.AttackTimer = EventSystem.SetTimerLoop(self, function() -- self:SetButtonEnable() -- end, 0.5) -- -- NewPlayerGuideManager:RemoveGuide(12) --end end function WBP_ResourceGrade:OnClosePanel() --if self.AttackTimer ~= nil then -- EventSystem.StopTimer(self.AttackTimer) --end end function WBP_ResourceGrade:OnResourceGradeChanged(InResourceGrade) if type(InResourceGrade) ~= 'number' or InResourceGrade < 1 or InResourceGrade > 4 then return end for index, TextBlock in pairs(self.TextBlockList) do if index == InResourceGrade then TextBlock:SetText("当前选择") self.ImageList[index]:SetVisibility(ESlateVisibility.HitTestInvisible) else TextBlock:SetText("待选择") self.ImageList[index]:SetVisibility(ESlateVisibility.Collapsed) end end end function WBP_ResourceGrade:RequestChangeResourceGrade(PendingGrade) local PC = STExtraGameplayStatics.GetFirstPlayerController(self) if PC.ResourceGrade == PendingGrade then return end UnrealNetwork.CallUnrealRPC(PC, PC, "ServerRPC_SetResourceGrade", PendingGrade) end ResourceRecommendTable = { 0, 2000, 6000, 11000 } function WBP_ResourceGrade:SetButtonEnable() -- 获取威力值 print(string.format('[WBP_ResourceGrade:SetButtonEnable] 执行')) local PS = GameDataManager.GetLocalPlayerState(); local Attack = 0 for i, v in pairs(PS.Attributes) do Attack = Attack + v.Base_Attack end print(string.format('[WBP_ResourceGrade:SetButtonEnable] Attack = ' .. tostring(Attack))) for i = 1, 4 do local IsTrue = Attack >= ResourceRecommendTable[i] print(string.format('[WBP_ResourceGrade:SetButtonEnable] IsTrue = ' .. tostring(IsTrue))) self.ButtonList[i]:SetIsEnabled(IsTrue) -- 再将颜色设置为不正常的颜色 if IsTrue then self.ButtonList[i]:SetColorAndOpacity({ R = 0.5, G = 0.5, B = 0.5, A = 0.8}) else self.ButtonList[i]:SetColorAndOpacity({ R = 0, G = 0, B = 0, A = 0}) end end end return WBP_ResourceGrade;