准备制作食材预处理流程,为lua直接读data table做基建

...
This commit is contained in:
2025-08-19 03:23:36 +08:00
parent 6fafddc43d
commit 626808fde9
29 changed files with 328 additions and 51 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,14 +1,39 @@
local WidgetUtils = require("Utils.UI.WidgetUtils")
local Emitter = require("Utils.Emitter")
local HearthMain = {}
function HearthMain:ctor()
self.switch_to_prep_cook_station_handle = nil
end
function HearthMain:OnInitialized()
self.BtnBack.OnClicked:Add(function()
WidgetUtils.Hide(self, "HearthMain")
end)
self.BtnOpenRecipe.OnClicked:Add(function()
WidgetUtils.Show(self, "RecipeMenu")
self:BP_Close()
end)
end
function HearthMain:Construct()
self.switch_to_prep_cook_station_handle = Emitter.OnEvent(
"switch_to_prep_station", function() self:SwitchToPrepCookStation() end
)
end
function HearthMain:Destruct()
Emitter.OffEvent("switch_to_prep_station", self.switch_to_prep_cook_station_handle)
end
function HearthMain:SwitchToPrepCookStation()
if self:IsAnimationPlaying(self.Anim_StartPrepCook) then
return
end
self:PlayAnimation(self.Anim_StartPrepCook, 0, 1, 0, 1, false)
end
function HearthMain:OnAnimationFinished(anim)
if anim == self.Anim_StartPrepCook then
WidgetUtils.Show(self, "PreCookStation")
print("HearthMain:OnAnimationFinished")
end
end
return Class(nil, nil, HearthMain)

View File

@ -0,0 +1,40 @@
local PreCookStationPanel = {}
local PRE_COOK_TOOL_CNT = 3
function PreCookStationPanel:ctor()
self.cook_tool_slots = {}
end
function PreCookStationPanel:OnInitialized()
self.BackBtn.OnClicked:Add(function() self:BP_Close() end)
self.cook_tool_slots = {}
for i = 1, PRE_COOK_TOOL_CNT do
local slot_name = "PreCookToolSlot_" .. tostring(i)
table.insert(self.cook_tool_slots, self[slot_name])
end
end
function PreCookStationPanel:Construct()
self:Refresh()
end
function PreCookStationPanel:Destruct()
end
function PreCookStationPanel:Refresh()
self:RefreshPreCookTools()
end
function PreCookStationPanel:RefreshPreCookTools()
local display_tools = {"PCT0001"}
for i = 1, PRE_COOK_TOOL_CNT do
self.cook_tool_slots[i]:SetPreCookToolID(display_tools[i])
end
end
return Class(nil, nil, PreCookStationPanel)

View File

@ -0,0 +1,11 @@
local CookPrepStationEntry = {}
local Emitter = require("Utils.Emitter")
function CookPrepStationEntry:OnInitialized()
self.MainBtn.OnClicked:Add(function()
Emitter.EmitEvent("switch_to_prep_station")
end)
end
return Class(nil, nil, CookPrepStationEntry)

View File

@ -88,11 +88,11 @@ end
function CookingBench:UpdateCookState()
if self.temperature > 0 then
self.WBP_CookingProcess:SetVisible(true)
self.WBP_CookingProcess:BP_SetVisible(true)
local percent = self.temperature / self.max_temperature
self.WBP_CookingProcess.TemperatureProcess:SetPercent(percent)
else
self.WBP_CookingProcess:SetVisible(false)
self.WBP_CookingProcess:BP_SetVisible(false)
end
end

View File

@ -0,0 +1,35 @@
local DataTableUtils = require("Utils.DataTableUtils")
local PreCookSlot = {}
function PreCookSlot:OnInitialized()
end
function PreCookSlot:Construct()
end
function PreCookSlot:Destruct()
end
function PreCookSlot:Reset()
end
function PreCookSlot:SetPreCookToolID(pre_cook_tool_id)
self:Reset()
if not pre_cook_tool_id then return end
local row_data = DataTableUtils.GetDataTableRow("PreCookItemConfig", pre_cook_tool_id)
if not row_data then
return
end
self.SlotImg:SetBrushFromSoftTexture(row_data.DisplayResource, true)
print("PreCookSlot:SetPreCookToolID", row_data)
end
return Class(nil, nil, PreCookSlot)

View File

@ -1,7 +1,7 @@
local HomeLandHud = {}
function HomeLandHud:ReceiveBeginPlay()
self:ShowWidget("HomeLandMain")
self:BP_PushWidget("HomeLandMain")
end
return Class(nil, nil, HomeLandHud)

View File

@ -0,0 +1,39 @@
local DataTableUtils = {}
local BusyGamePlayLibrary = import("BusyGamePlayLibrary")
function DataTableUtils.GetDataTable(table_name)
return BusyGamePlayLibrary.GetGameDataTable(table_name)
end
function DataTableUtils.GetDataTableRow(table_name, row_name)
local data_table = DataTableUtils.GetDataTable(table_name)
if not data_table then
return nil
end
return data_table:FindRow(row_name)
end
--[[
LuaExtensionMethod.cpp:22-28
// 封装函数示例
static int FindRowWrapper(lua_State* L) {
UDataTable* dataTable = LuaObject::checkUD<UDataTable>(L, 1);
FName rowName = LuaObject::checkValue<FName>(L, 2);
UScriptStruct* rowStruct = LuaObject::checkUD<UScriptStruct>(L, 3);
// 使用反射调用 FindRow
uint8* rowData = dataTable->FindRowUnchecked(rowName);
if (rowData && rowStruct) {
// 将结果推送到 Lua
return LuaObject::pushStruct(L, rowStruct, rowData);
}
return LuaObject::pushNil(L);
}
这段代码中pushStruct只接受两个参数如何改
]]
return DataTableUtils

View File

@ -10,10 +10,10 @@ end
function WidgetUtils.Show(wco, widget_name)
local hud = GetHud(wco)
if not hud then return end
return hud:ShowWidget(widget_name)
return hud:BP_PushWidget(widget_name)
end
function WidgetUtils.Hide(wco, widget_name)
function WidgetUtils.Close(wco, widget_name)
local hud = GetHud(wco)
if not hud then return end
return hud:PopWidget(widget_name)