开始开发大厅烹饪功能
This commit is contained in:
@ -22,3 +22,8 @@ function Class(a, b, c) end
|
||||
slua = {
|
||||
createDelegate = function(func) end
|
||||
}
|
||||
|
||||
--- @class KismetSystemLibrary
|
||||
KismetSystemLibrary = {
|
||||
K2_ClearTimerHandle = function() end
|
||||
}
|
||||
|
||||
@ -5,6 +5,9 @@ function HearthMain:OnInitialized()
|
||||
self.BtnBack.OnClicked:Add(function()
|
||||
WidgetUtils.Hide(self, "HearthMain")
|
||||
end)
|
||||
self.BtnOpenRecipe.OnClicked:Add(function()
|
||||
WidgetUtils.Show(self, "RecipeMenu")
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
|
||||
19
Content/Lua/HomeLand/UI/Hearth/RecipeMenu.lua
Normal file
19
Content/Lua/HomeLand/UI/Hearth/RecipeMenu.lua
Normal file
@ -0,0 +1,19 @@
|
||||
local WidgetUtils = require("Utils.UI.WidgetUtils")
|
||||
local RecipeMenu = {}
|
||||
|
||||
function RecipeMenu:OnInitialized()
|
||||
self.BtnConfirm.OnClicked:Add(function()
|
||||
WidgetUtils.Hide(self, "RecipeMenu")
|
||||
local work_top = WidgetUtils.Show(self, "HearthWorkTop")
|
||||
if work_top ~= nil then
|
||||
work_top:setup_task()
|
||||
end
|
||||
end)
|
||||
|
||||
self.BtnClose.OnClicked:Add(function()
|
||||
WidgetUtils.Hide(self, "RecipeMenu")
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
return Class(nil, nil, RecipeMenu)
|
||||
79
Content/Lua/HomeLand/UI/Hearth/Widgets/CookingBench.lua
Normal file
79
Content/Lua/HomeLand/UI/Hearth/Widgets/CookingBench.lua
Normal file
@ -0,0 +1,79 @@
|
||||
local CookingBench = {}
|
||||
local KismetSystemLibrary = import("KismetSystemLibrary")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
function CookingBench:ctor()
|
||||
self.is_cooking = false
|
||||
self.temperature = 0
|
||||
self.max_temperature = 200
|
||||
self.burn_timer = nil
|
||||
end
|
||||
|
||||
function CookingBench:OnInitialized()
|
||||
self.WBP_Rabbit.OnClicked:Add(function() self:OnRabbitClicked()end)
|
||||
end
|
||||
|
||||
function CookingBench:Construct()
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end
|
||||
|
||||
|
||||
function CookingBench:Destruct()
|
||||
self.is_cooking = false
|
||||
self:UpdateFireState()
|
||||
end
|
||||
|
||||
|
||||
function CookingBench:OnRabbitClicked()
|
||||
if self.is_cooking then
|
||||
local new_value = self.temperature + 8
|
||||
if new_value > self.max_temperature then
|
||||
self.temperature = self.max_temperature
|
||||
else
|
||||
self.temperature = new_value
|
||||
end
|
||||
else
|
||||
self.is_cooking = true
|
||||
self.temperature = 100
|
||||
self.burn_timer = KismetSystemLibrary.K2_SetTimerDelegate(
|
||||
slua.createDelegate(function()
|
||||
local new_value = self.temperature - 1
|
||||
if new_value > 0 then
|
||||
self.temperature = new_value
|
||||
else
|
||||
self.temperature = 0
|
||||
self.is_cooking = false
|
||||
KismetSystemLibrary.K2_ClearTimerHandle(self, self.burn_timer)
|
||||
self.burn_timer = nil
|
||||
end
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end),
|
||||
0.1, true, true, 0, 0
|
||||
)
|
||||
end
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end
|
||||
|
||||
function CookingBench:UpdateCookState()
|
||||
if self.temperature > 0 then
|
||||
self.WBP_CookingProcess:SetVisible(true)
|
||||
local percent = self.temperature / self.max_temperature
|
||||
self.WBP_CookingProcess.TemperatureProcess:SetPercent(percent)
|
||||
else
|
||||
self.WBP_CookingProcess:SetVisible(false)
|
||||
end
|
||||
end
|
||||
|
||||
function CookingBench:UpdateFireState()
|
||||
if self.is_cooking == true then
|
||||
self.CookingFireImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
else
|
||||
self.CookingFireImg:SetVisibility(ESlateVisibility.Collapsed)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, CookingBench)
|
||||
28
Content/Lua/HomeLand/UI/Hearth/Widgets/CookingPot.lua
Normal file
28
Content/Lua/HomeLand/UI/Hearth/Widgets/CookingPot.lua
Normal file
@ -0,0 +1,28 @@
|
||||
-- 锅的控件
|
||||
local CookingPot = {}
|
||||
local Emitter = require("Utils.Emitter")
|
||||
|
||||
function CookingPot:ctor()
|
||||
self.cook_slot_clicked_handle = nil
|
||||
end
|
||||
|
||||
|
||||
function CookingPot:Construct()
|
||||
self.cook_slot_clicked_handle = Emitter.OnEvent(
|
||||
"cook_slot_clicked",
|
||||
function(slot) self:OnCookSlotClicked(slot) end
|
||||
)
|
||||
end
|
||||
|
||||
function CookingPot:Destruct()
|
||||
Emitter.OffEvent("cook_slot_clicked", self.cook_slot_clicked_handle)
|
||||
end
|
||||
|
||||
function CookingPot:OnCookSlotClicked(slot)
|
||||
local item = slot:ConsumeMaterial()
|
||||
if item == nil then end
|
||||
self:PlayAnimation(self.Anim_Cook, 0, 1, 0, 1, false)
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, CookingPot)
|
||||
42
Content/Lua/HomeLand/UI/Hearth/Widgets/CookingSlot.lua
Normal file
42
Content/Lua/HomeLand/UI/Hearth/Widgets/CookingSlot.lua
Normal file
@ -0,0 +1,42 @@
|
||||
local CookingSlot = {}
|
||||
local Emitter = require("Utils.Emitter")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
|
||||
|
||||
|
||||
function CookingSlot:ctor()
|
||||
self.cook_item = nil
|
||||
end
|
||||
|
||||
function CookingSlot:OnInitialized()
|
||||
self.MainBtn.OnClicked:Add(function()
|
||||
Emitter.EmitEvent("cook_slot_clicked", self)
|
||||
end)
|
||||
end
|
||||
|
||||
function CookingSlot:SetCookMaterial(cook_item)
|
||||
self.cook_item = cook_item
|
||||
self:RefreshDisplay()
|
||||
end
|
||||
|
||||
function CookingSlot:SetEmpty()
|
||||
self.CookingMaterialImg:SetVisibility(ESlateVisibility.Collapsed)
|
||||
end
|
||||
|
||||
function CookingSlot:RefreshDisplay()
|
||||
self:SetEmpty()
|
||||
if self.cook_item then
|
||||
self.CookingMaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
end
|
||||
end
|
||||
|
||||
function CookingSlot:ConsumeMaterial()
|
||||
-- if self.cook_item == nil then return end
|
||||
local item = self.cook_item
|
||||
self:SetCookMaterial(nil)
|
||||
return item
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, CookingSlot)
|
||||
@ -0,0 +1,4 @@
|
||||
local IngredientsWidget = {}
|
||||
|
||||
|
||||
return Class(nil, nil, IngredientsWidget)
|
||||
@ -0,0 +1,3 @@
|
||||
local WorkTableWidget = {}
|
||||
|
||||
return Class(nil, nil, WorkTableWidget)
|
||||
17
Content/Lua/HomeLand/UI/Hearth/WorkTop/WorkTopPanel.lua
Normal file
17
Content/Lua/HomeLand/UI/Hearth/WorkTop/WorkTopPanel.lua
Normal file
@ -0,0 +1,17 @@
|
||||
local WidgetUtils = require("Utils.UI.WidgetUtils")
|
||||
local WorkTopPanel = {}
|
||||
|
||||
function WorkTopPanel:OnInitialized()
|
||||
self.BtnBack.OnClicked:Add(function()
|
||||
WidgetUtils.Hide(self, "HearthWorkTop")
|
||||
end)
|
||||
self.BtnNext.OnClicked:Add(function()
|
||||
WidgetUtils.Hide(self, "HearthWorkTop")
|
||||
end)
|
||||
end
|
||||
|
||||
function WorkTopPanel:setup_task()
|
||||
|
||||
end
|
||||
|
||||
return Class(nil, nil, WorkTopPanel)
|
||||
53
Content/Lua/Utils/Emitter.lua
Normal file
53
Content/Lua/Utils/Emitter.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local Emitter = {
|
||||
EventHandlers = {}
|
||||
}
|
||||
|
||||
-- 注册事件监听
|
||||
function Emitter.OnEvent(eventName, handler)
|
||||
if not eventName or type(handler) ~= "function" then
|
||||
print("[EventSystem] Invalid event registration")
|
||||
return
|
||||
end
|
||||
|
||||
if not Emitter.EventHandlers[eventName] then
|
||||
Emitter.EventHandlers[eventName] = {}
|
||||
end
|
||||
|
||||
table.insert(Emitter.EventHandlers[eventName], handler)
|
||||
return handler -- 返回handler用于注销
|
||||
end
|
||||
|
||||
-- 触发事件
|
||||
function Emitter.EmitEvent(eventName, ...)
|
||||
local handlers = Emitter.EventHandlers[eventName]
|
||||
if not handlers then return end
|
||||
|
||||
print("[EventSystem] Emitting event: " .. eventName)
|
||||
for i = #handlers, 1, -1 do -- 倒序遍历允许在回调中移除事件
|
||||
local success, err = pcall(handlers[i], ...)
|
||||
if not success then
|
||||
print("[EventSystem] Error in handler: " .. tostring(err))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 注销事件
|
||||
function Emitter.OffEvent(eventName, handler)
|
||||
local handlers = Emitter.EventHandlers[eventName]
|
||||
if not handlers then return end
|
||||
|
||||
for i = #handlers, 1, -1 do
|
||||
if handlers[i] == handler then
|
||||
table.remove(handlers, i)
|
||||
end
|
||||
end
|
||||
|
||||
if #handlers == 0 then
|
||||
Emitter.EventHandlers[eventName] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
return Emitter
|
||||
Reference in New Issue
Block a user