57 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
-- 锅的控件
 | 
						|
local CookingPot = {}
 | 
						|
local Utils = require("GamePlay.Utils")
 | 
						|
local Emitter = require("Utils.Emitter")
 | 
						|
local ESlateVisibility = import("ESlateVisibility")
 | 
						|
 | 
						|
function CookingPot:ctor()
 | 
						|
    self.cookware_click_handle = nil
 | 
						|
    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
 | 
						|
    )
 | 
						|
 | 
						|
    self.cookware_click_handle = Emitter.OnEvent(
 | 
						|
        "use_cookward",
 | 
						|
        function(cookware_id) self:OnUseCookware(cookware_id) end
 | 
						|
    )
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
function CookingPot:Destruct()
 | 
						|
    Emitter.OffEvent("cook_material_change", self.cook_material_change_handle)
 | 
						|
    Emitter.OffEvent("use_cookward", self.cookware_click_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:OnUseCookware(cookware_id)
 | 
						|
    self:PlayAnimation(self.Anim_StirFry, 0, 1, 0, 1, false)
 | 
						|
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) |