初始化提交
This commit is contained in:
38
Content/Lua/UI/RoleStateWidget.lua
Normal file
38
Content/Lua/UI/RoleStateWidget.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local Widget = {}
|
||||
local Reactive = require("Core.Reactive")
|
||||
|
||||
local function ResetWatcher(widget)
|
||||
if widget.health_watcher then
|
||||
widget.health_watcher:Destroy()
|
||||
widget.health_watcher = nil
|
||||
end
|
||||
if widget.hunger_watcher then
|
||||
widget.hunger_watcher:Destroy()
|
||||
widget.hunger_watcher = nil
|
||||
end
|
||||
end
|
||||
|
||||
function Widget:OnDestroy()
|
||||
|
||||
end
|
||||
|
||||
|
||||
function Widget:Refresh(args)
|
||||
local role = args.role
|
||||
if role == nil then return end
|
||||
self:BindRole(role)
|
||||
end
|
||||
|
||||
function Widget:BindRole(role)
|
||||
ResetWatcher(self)
|
||||
self.health_watcher = Reactive.Watcher(function()
|
||||
self.HealthBar:SetPercent(role:GetHealthPercent())
|
||||
end)
|
||||
|
||||
self.hunger_watcher = Reactive.Watcher(function()
|
||||
self.HungerBar:SetPercent(role:GetHungerPercent())
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
return Class(nil, nil, Widget)
|
||||
Reference in New Issue
Block a user