| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | local EPreCookSlotType = import("EPreCookSlotType") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | --- @class PreCookStationPanel | 
					
						
							|  |  |  | --- @field WBP_PreCookCenter PreCookCenterWidget | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | local PreCookStationPanel = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | --- @class PreCookManager | 
					
						
							|  |  |  | local PreCookManager = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | local PRE_COOK_TOOL_CNT = 3 | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | local PRE_COOK_CONTAINER_CNT = 3 | 
					
						
							|  |  |  | local PRE_COOK_MATERIAL_CNT = 5 | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function PreCookStationPanel:ctor() | 
					
						
							|  |  |  |     self.cook_tool_slots = {} | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  |     self.cook_container_slots = {} | 
					
						
							|  |  |  |     self.cook_raw_slots = {} | 
					
						
							|  |  |  |     self.cook_finished_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  -- 正在使用的预处理容器 | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | function PreCookStationPanel:OnInitialized() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  |     self.BackBtn.OnClicked:Add(function() self:BP_Close() end) | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for i = 1, PRE_COOK_TOOL_CNT do | 
					
						
							|  |  |  |         local slot_name = "PreCookToolSlot_" .. tostring(i) | 
					
						
							|  |  |  |         table.insert(self.cook_tool_slots, self[slot_name]) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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() | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function PreCookStationPanel:Construct() | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  |     self:Refresh() | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function PreCookStationPanel:Destruct() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function PreCookStationPanel:Refresh() | 
					
						
							|  |  |  |     self:RefreshPreCookTools() | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  |     self:RefreshPreCookContainer() | 
					
						
							|  |  |  |     self:RefreshPreCookRawMaterial() | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function PreCookStationPanel:RefreshPreCookTools() | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  |     local display_tools = {"PCT0001", "PCT0002"} | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  |     for i = 1, PRE_COOK_TOOL_CNT do | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  |         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]) | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-27 00:56:05 +08:00
										 |  |  | 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-19 03:23:36 +08:00
										 |  |  | return Class(nil, nil, PreCookStationPanel) |