70 lines
2.3 KiB
Lua
70 lines
2.3 KiB
Lua
|
---@class WB_ShovelButton_C:UUserWidget
|
||
|
---@field NewButton_Shovel UNewButton
|
||
|
---@field WidgetSwitcher_ChangeShovel UWidgetSwitcher
|
||
|
--Edit Below--
|
||
|
---@type WB_ShovelButton_C
|
||
|
local WB_ShovelButton = {
|
||
|
bInitDoOnce = false;
|
||
|
IsPlayerEnableShovel = false
|
||
|
}
|
||
|
|
||
|
function WB_ShovelButton:Construct()
|
||
|
self:LuaInit();
|
||
|
end
|
||
|
|
||
|
function WB_ShovelButton:LuaInit()
|
||
|
if self.bInitDoOnce then return ; end
|
||
|
self.bInitDoOnce = true;
|
||
|
UGCEventSystem.AddListener(EventTypes.ChangeShovel, self.UpdatePlayerEnableShovel, self)
|
||
|
UGCEventSystem.AddListener(EventTypes.ChangeEnableShovel, self.OnChangeEnableShovel, self)
|
||
|
if LocalPlayerController then
|
||
|
self:UpdatePlayerEnableShovel(LocalPlayerController.PlayerEnableShovel)
|
||
|
end
|
||
|
|
||
|
UGCLogSystem.Log("[WB_ShovelButton:LuaInit] 执行")
|
||
|
|
||
|
UITool.BindButtonClicked(self.NewButton_Shovel, self.ChangePlayerEnableShovel, self)
|
||
|
|
||
|
---- 检查一下当前是什么状态
|
||
|
--if LocalPlayerController then
|
||
|
-- self.NewCheckBox_Enable:SetIsChecked(LocalPlayerController.PlayerEnableShovel);
|
||
|
--end
|
||
|
--
|
||
|
--self.NewCheckBox_Enable.OnCheckStateChanged:Add(function(bIsChecked)
|
||
|
-- -- 发送 RPC
|
||
|
-- UnrealNetwork.CallUnrealRPC(LocalPlayerController, LocalPlayerController, "SetEnableShovel", bIsChecked);
|
||
|
--end, self)
|
||
|
|
||
|
|
||
|
end
|
||
|
|
||
|
function WB_ShovelButton:ChangePlayerEnableShovel()
|
||
|
self.IsPlayerEnableShovel = not self.IsPlayerEnableShovel
|
||
|
UnrealNetwork.CallUnrealRPC(LocalPlayerController, LocalPlayerController, "SetEnableShovel", self.IsPlayerEnableShovel);
|
||
|
end
|
||
|
|
||
|
function WB_ShovelButton:UpdatePlayerEnableShovel(InIsPlayerEnableShovel)
|
||
|
UGCLogSystem.Log("[WB_ShovelButton_UpdatePlayerEnableShovel] IsPlayerEnableShovel:%s", tostring(InIsPlayerEnableShovel))
|
||
|
self.IsPlayerEnableShovel = InIsPlayerEnableShovel
|
||
|
if self.IsPlayerEnableShovel then
|
||
|
self.WidgetSwitcher_ChangeShovel:SetActiveWidgetIndex(1)
|
||
|
else
|
||
|
self.WidgetSwitcher_ChangeShovel:SetActiveWidgetIndex(0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_ShovelButton:OnChangeEnableShovel(EnableShovel)
|
||
|
UGCLogSystem.Log("[WB_ShovelButton:OnChangeEnableShovel] 设置玩家是否可以滑铲:%s", tostring(EnableShovel));
|
||
|
self.NewButton_Shovel:SetIsEnabled(EnableShovel);
|
||
|
self:UpdatePlayerEnableShovel(not EnableShovel);
|
||
|
end
|
||
|
|
||
|
-- function WB_ShovelButton:Tick(MyGeometry, InDeltaTime)
|
||
|
|
||
|
-- end
|
||
|
|
||
|
-- function WB_ShovelButton:Destruct()
|
||
|
|
||
|
-- end
|
||
|
|
||
|
return WB_ShovelButton
|