开始开发大厅烹饪功能

This commit is contained in:
2025-08-01 00:33:26 +08:00
parent 608486444e
commit 44fc2371be
25 changed files with 360 additions and 2 deletions

93
.emmyrc.json Normal file
View File

@ -0,0 +1,93 @@
{
"completion": {
"enable": true,
"autoRequire": true,
"autoRequireFunction": "require",
"autoRequireNamingConvention": "keep",
"autoRequireSeparator": ".",
"callSnippet": false,
"postfix": "@",
"baseFunctionIncludesName": true
},
"diagnostics": {
"disable": [
"unnecessary-if"
],
"enable": true,
"globals": [],
"globalsRegex": [],
"severity": {},
"enables": [],
"diagnosticInterval": 500
},
"signature": {
"detailSignatureHelper": true
},
"hint": {
"enable": true,
"paramHint": true,
"indexHint": true,
"localHint": true,
"overrideHint": true,
"metaCallHint": true
},
"runtime": {
"version": "LuaLatest",
"requireLikeFunction": [],
"frameworkVersions": [],
"extensions": [],
"requirePattern": [],
"classDefaultCall": {
"functionName": "",
"forceNonColon": false,
"forceReturnSelf": false
}
},
"workspace": {
"ignoreDir": [],
"ignoreGlobs": [],
"library": [],
"workspaceRoots": [],
"preloadFileSize": 0,
"encoding": "utf-8",
"moduleMap": [],
"reindexDuration": 5000,
"enableReindex": false
},
"resource": {
"paths": []
},
"codeLens": {
"enable": true
},
"strict": {
"requirePath": false,
"typeCall": false,
"arrayIndex": true,
"metaOverrideFileDefine": true,
"docBaseConstMatchBaseType": true
},
"semanticTokens": {
"enable": true
},
"references": {
"enable": true,
"fuzzySearch": true,
"shortStringSearch": false
},
"hover": {
"enable": true
},
"documentColor": {
"enable": true
},
"codeAction": {
"insertSpace": false
},
"inlineValues": {
"enable": true
},
"doc": {
"privateName": []
}
}

View File

@ -20,8 +20,18 @@ NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Change.Role.Health",DevComment="角色生命值发生的变动")
+GameplayTagList=(Tag="Change.Role.Hunger",DevComment="角色饥饿值发生变动")
+GameplayTagList=(Tag="Change.Role.MoveSpeed",DevComment="改变角色移动速度")
+GameplayTagList=(Tag="CookProcess",DevComment="烹饪加工")
+GameplayTagList=(Tag="CookProcess.Cubed",DevComment="切块")
+GameplayTagList=(Tag="CookProcess.Diced",DevComment="切丁")
+GameplayTagList=(Tag="CookProcess.Mashed",DevComment="切泥")
+GameplayTagList=(Tag="CookProcess.Sliced",DevComment="切片操作")
+GameplayTagList=(Tag="GameItem.Building",DevComment="建筑物")
+GameplayTagList=(Tag="GameItem.Food",DevComment="游戏内的可食用物品")
+GameplayTagList=(Tag="Ingredient",DevComment="烹饪食材")
+GameplayTagList=(Tag="Ingredient.Fruit",DevComment="水果类食材")
+GameplayTagList=(Tag="Ingredient.Fruit.Apple",DevComment="苹果")
+GameplayTagList=(Tag="Ingredient.Vegetable",DevComment="蔬菜类食材")
+GameplayTagList=(Tag="Ingredient.Vegetable.Carrot",DevComment="胡萝卜")
+GameplayTagList=(Tag="Recover.Role.Health",DevComment="回复生命值")
+GameplayTagList=(Tag="Recover.Role.Hunger",DevComment="恢复饥饿值")
+GameplayTagList=(Tag="Status.Role.Invincible",DevComment="不掉血标签")

View File

@ -22,3 +22,8 @@ function Class(a, b, c) end
slua = {
createDelegate = function(func) end
}
--- @class KismetSystemLibrary
KismetSystemLibrary = {
K2_ClearTimerHandle = function() end
}

View File

@ -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

View 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)

View 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)

View 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)

View 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)

View File

@ -0,0 +1,4 @@
local IngredientsWidget = {}
return Class(nil, nil, IngredientsWidget)

View File

@ -0,0 +1,3 @@
local WorkTableWidget = {}
return Class(nil, nil, WorkTableWidget)

View 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)

View 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

Binary file not shown.

Binary file not shown.

View File

@ -11,8 +11,7 @@ public class BusyRabbit : ModuleRules
PublicDependencyModuleNames.AddRange(new string[] {
"Core", "CoreUObject", "Engine", "InputCore",
"EnhancedInput", "Paper2D", "UMG", "Slate",
"GameplayAbilities", "GameplayTags","GameplayTasks",
"UnrealEd"
"GameplayAbilities", "GameplayTags","GameplayTasks"
});
PrivateDependencyModuleNames.AddRange(new string[] { });

View File

@ -56,6 +56,9 @@ struct FBusyLevelItemDescription : public FTableRowBase { // 物品描述表头
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "物品关卡内资源")
TSoftObjectPtr<UPaperFlipbook> LevelResource;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "物品标签列表")
FGameplayTagContainer ItemTags;
};