刀光预研
初步实现了刀光交互效果
This commit is contained in:
@ -1,23 +1,79 @@
|
||||
|
||||
local EPreCookSlotType = import("EPreCookSlotType")
|
||||
|
||||
--- @class PreCookStationPanel
|
||||
--- @field WBP_PreCookCenter PreCookCenterWidget
|
||||
local PreCookStationPanel = {}
|
||||
|
||||
--- @class PreCookManager
|
||||
local PreCookManager = {}
|
||||
|
||||
local PRE_COOK_TOOL_CNT = 3
|
||||
local PRE_COOK_CONTAINER_CNT = 3
|
||||
local PRE_COOK_MATERIAL_CNT = 5
|
||||
|
||||
|
||||
function PreCookStationPanel:ctor()
|
||||
self.cook_tool_slots = {}
|
||||
end
|
||||
function PreCookStationPanel:OnInitialized()
|
||||
self.BackBtn.OnClicked:Add(function() self:BP_Close() end)
|
||||
self.cook_container_slots = {}
|
||||
self.cook_raw_slots = {}
|
||||
self.cook_finished_slots = {}
|
||||
|
||||
self.cook_tool_slots = {}
|
||||
self.all_slots = {
|
||||
[EPreCookSlotType.PreCookTool] = self.cook_tool_slots,
|
||||
[EPreCookSlotType.PreCookContainer] = self.cook_container_slots,
|
||||
[EPreCookSlotType.PreCookRawMaterial] = self.cook_raw_slots,
|
||||
[EPreCookSlotType.PreCookFinishedMaterial] = self.cook_finished_slots,
|
||||
}
|
||||
|
||||
self.slot_clicked_callback = {
|
||||
[EPreCookSlotType.PreCookTool] = self.OnToolsSlotClicked,
|
||||
[EPreCookSlotType.PreCookContainer] = self.OnContainerSlotClicked,
|
||||
[EPreCookSlotType.PreCookRawMaterial] = self.OnRawMaterialSlotClicked,
|
||||
[EPreCookSlotType.PreCookFinishedMaterial] = self.OnFinishedMaterialSlotClicked,
|
||||
}
|
||||
|
||||
self.actived_tool_slot_idx = nil --正在使用的预处理工具
|
||||
self.actived_container_slot_idx = nil -- 正在使用的预处理容器
|
||||
end
|
||||
|
||||
function PreCookStationPanel:OnInitialized()
|
||||
|
||||
self.BackBtn.OnClicked:Add(function() self:BP_Close() end)
|
||||
|
||||
for i = 1, PRE_COOK_TOOL_CNT do
|
||||
local slot_name = "PreCookToolSlot_" .. tostring(i)
|
||||
table.insert(self.cook_tool_slots, self[slot_name])
|
||||
end
|
||||
|
||||
for i = 1, PRE_COOK_CONTAINER_CNT do
|
||||
local slot_name = "PreCookContainer_" .. tostring(i)
|
||||
table.insert(self.cook_container_slots, self[slot_name])
|
||||
end
|
||||
|
||||
for i = 1, PRE_COOK_MATERIAL_CNT do
|
||||
local raw_name = "PreCookRawMaterial_" .. tostring(i)
|
||||
local finished_name = "PreCookFinishedMaterial_" .. tostring(i)
|
||||
table.insert(self.cook_raw_slots, self[raw_name])
|
||||
table.insert(self.cook_finished_slots, self[finished_name])
|
||||
end
|
||||
|
||||
self.pre_cook_click_handles = {}
|
||||
for slot_type, slots in pairs(self.all_slots) do
|
||||
local callback = self.slot_clicked_callback[slot_type] or function(_, _) end
|
||||
for idx, slot in pairs(slots) do
|
||||
local handle = slot:BP_BindLuaEvent("PreCookSlotClicked", function()
|
||||
callback(self, idx)
|
||||
end)
|
||||
table.insert(self.pre_cook_click_handles, handle)
|
||||
end
|
||||
end
|
||||
|
||||
self.WBP_PreCookCenter:SetEmpty()
|
||||
end
|
||||
|
||||
function PreCookStationPanel:Construct()
|
||||
|
||||
self:Refresh()
|
||||
end
|
||||
|
||||
@ -27,14 +83,102 @@ end
|
||||
|
||||
function PreCookStationPanel:Refresh()
|
||||
self:RefreshPreCookTools()
|
||||
self:RefreshPreCookContainer()
|
||||
self:RefreshPreCookRawMaterial()
|
||||
end
|
||||
|
||||
function PreCookStationPanel:RefreshPreCookTools()
|
||||
local display_tools = {"PCT0001"}
|
||||
local display_tools = {"PCT0001", "PCT0002"}
|
||||
for i = 1, PRE_COOK_TOOL_CNT do
|
||||
self.cook_tool_slots[i]:SetPreCookToolID(display_tools[i])
|
||||
print(self.cook_tool_slots[i], i)
|
||||
self.cook_tool_slots[i]:SetPreCookTool(display_tools[i])
|
||||
end
|
||||
end
|
||||
|
||||
function PreCookStationPanel:RefreshPreCookContainer()
|
||||
local display_containers = {"PCC0001", "PCC0002"}
|
||||
for i = 1, PRE_COOK_CONTAINER_CNT do
|
||||
self.cook_container_slots[i]:SetPreCookContainer(display_containers[i])
|
||||
end
|
||||
end
|
||||
|
||||
function PreCookStationPanel:RefreshPreCookRawMaterial()
|
||||
local display_containers = {"PCM0001", "PCM0002", "400001"}
|
||||
for i = 1, PRE_COOK_MATERIAL_CNT do
|
||||
self.cook_raw_slots[i]:SetPreCookContainer(display_containers[i])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function PreCookStationPanel:OnPreCookSlotClicked(slot_type, slot_item_id)
|
||||
local slots = self.all_slots[slot_type]
|
||||
if not slots then return end
|
||||
for _, slot in pairs(slots) do
|
||||
if slot:GetSlotItemID() == slot_item_id then
|
||||
slot:ActiveSlot()
|
||||
else
|
||||
slot:DeactiveSlot()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PreCookStationPanel:OnToolsSlotClicked(idx)
|
||||
-- 过滤掉空的选择
|
||||
local new_active_slot = self.cook_tool_slots[idx]
|
||||
local slot_item_id = new_active_slot:GetSlotItemID()
|
||||
if not slot_item_id then return end
|
||||
|
||||
-- 点了正在使用的,放回去
|
||||
if idx == self.actived_tool_slot_idx then
|
||||
new_active_slot:DeactiveToolSlot()
|
||||
self.actived_tool_slot_idx = nil
|
||||
print("deactive only", idx)
|
||||
return
|
||||
end
|
||||
|
||||
-- 之前有其他工具正在使用,放回去
|
||||
if self.actived_tool_slot_idx then
|
||||
self.cook_tool_slots[self.actived_tool_slot_idx]:DeactiveToolSlot()
|
||||
print("deactive old", idx)
|
||||
end
|
||||
|
||||
-- 使用新的工具
|
||||
new_active_slot:ActiveToolSlot()
|
||||
self.actived_tool_slot_idx = idx
|
||||
print("active new", idx)
|
||||
end
|
||||
|
||||
function PreCookStationPanel:OnContainerSlotClicked(idx)
|
||||
local new_active_slot = self.cook_container_slots[idx] --- @type PreCookSlot
|
||||
local old_active_slot = self.cook_container_slots[self.actived_container_slot_idx] ---@type PreCookSlot
|
||||
|
||||
if new_active_slot == old_active_slot then
|
||||
self.actived_container_slot_idx = nil
|
||||
old_active_slot:DeactiveContianerSlot()
|
||||
self.WBP_PreCookCenter:RemoveContainer()
|
||||
return
|
||||
end
|
||||
if old_active_slot then
|
||||
old_active_slot:DeactiveContianerSlot()
|
||||
end
|
||||
new_active_slot:ActiveContainerSlot()
|
||||
self.actived_container_slot_idx = idx
|
||||
|
||||
self.WBP_PreCookCenter:AddContainer(new_active_slot:GetSlotItemID())
|
||||
end
|
||||
|
||||
|
||||
function PreCookStationPanel:OnRawMaterialSlotClicked(idx)
|
||||
local material_slot = self.cook_raw_slots[idx] --- @type PreCookSlot
|
||||
local material_id = material_slot:GetSlotItemID()
|
||||
if not material_id then return end
|
||||
material_slot:PushSlotItem()
|
||||
self.WBP_PreCookCenter:AddCookMaterial(material_id)
|
||||
end
|
||||
|
||||
function PreCookStationPanel:OnFinishedMaterialSlotClicked(idx)
|
||||
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, PreCookStationPanel)
|
||||
Reference in New Issue
Block a user