Files
BusyRabbit/Content/Lua/HomeLand/UI/Hearth/Widgets/CookingPot.lua
2025-08-07 00:15:18 +08:00

45 lines
1.4 KiB
Lua

-- 锅的控件
local CookingPot = {}
local Utils = require("GamePlay.Utils")
local Emitter = require("Utils.Emitter")
local ESlateVisibility = import("ESlateVisibility")
function CookingPot:ctor()
self.cook_material_change_handle = nil
end
function CookingPot:Construct()
self.MaterialImg:SetVisibility(ESlateVisibility.Collapsed)
self.cook_material_change_handle = Emitter.OnEvent(
"cook_material_change",
function(cook_material_id, is_auto_push) self:OnCookMaterialChange(cook_material_id, is_auto_push) end
)
end
function CookingPot:Destruct()
Emitter.OffEvent("cook_material_change", self.cook_material_change_handle)
end
function CookingPot:OnCookMaterialChange(cook_material_id, is_auto_push)
print(cook_material_id, is_auto_push)
local config = Utils.GetHomelandItemDesc(cook_material_id)
if config == nil then return end
self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.MaterialImg:SetBrushFromSoftTexture(config.DisplayResource, true)
if not is_auto_push then
self:PlayAnimation(self.Anim_Cook, 0, 1, 0, 1, false)
end
end
function CookingPot:OnCookSlotClicked(config)
if config == nil then return end
self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.MaterialImg:SetBrushFromSoftTexture(config.DisplayResource, true)
self:PlayAnimation(self.Anim_Cook, 0, 1, 0, 1, false)
end
return Class(nil, nil, CookingPot)