Files
BusyRabbit/Content/Lua/HomeLand/UI/Hearth/Widgets/CookingPot.lua

57 lines
1.8 KiB
Lua
Raw Normal View History

2025-08-01 00:33:26 +08:00
-- 锅的控件
local CookingPot = {}
2025-08-07 00:15:18 +08:00
local Utils = require("GamePlay.Utils")
2025-08-01 00:33:26 +08:00
local Emitter = require("Utils.Emitter")
2025-08-07 00:15:18 +08:00
local ESlateVisibility = import("ESlateVisibility")
2025-08-01 00:33:26 +08:00
function CookingPot:ctor()
2025-08-08 17:22:47 +08:00
self.cookware_click_handle = nil
2025-08-07 00:15:18 +08:00
self.cook_material_change_handle = nil
2025-08-01 00:33:26 +08:00
end
function CookingPot:Construct()
2025-08-07 00:15:18 +08:00
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
2025-08-01 00:33:26 +08:00
)
2025-08-07 00:15:18 +08:00
2025-08-08 17:22:47 +08:00
self.cookware_click_handle = Emitter.OnEvent(
"use_cookward",
function(cookware_id) self:OnUseCookware(cookware_id) end
)
2025-08-01 00:33:26 +08:00
end
function CookingPot:Destruct()
2025-08-07 00:15:18 +08:00
Emitter.OffEvent("cook_material_change", self.cook_material_change_handle)
2025-08-08 17:22:47 +08:00
Emitter.OffEvent("use_cookward", self.cookware_click_handle)
2025-08-07 00:15:18 +08:00
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
2025-08-01 00:33:26 +08:00
end
2025-08-08 17:22:47 +08:00
function CookingPot:OnUseCookware(cookware_id)
self:PlayAnimation(self.Anim_StirFry, 0, 1, 0, 1, false)
end
2025-08-07 00:15:18 +08:00
function CookingPot:OnCookSlotClicked(config)
if config == nil then return end
self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.MaterialImg:SetBrushFromSoftTexture(config.DisplayResource, true)
2025-08-01 00:33:26 +08:00
self:PlayAnimation(self.Anim_Cook, 0, 1, 0, 1, false)
end
return Class(nil, nil, CookingPot)