刀光预研
初步实现了刀光交互效果
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -81,13 +81,9 @@ function CookManager:CheckFinishStatus() | ||||
| end | ||||
|  | ||||
| function CookManager:AddCookMaterial(cook_material_id, is_auto_push) | ||||
|     local BusyGamePlayLibrary = import("BusyGamePlayLibrary") | ||||
|  | ||||
|     local config = Utils.GetDataTableConfig( | ||||
|         "CookMaterialStateConfig", cook_material_id | ||||
|     ) | ||||
|     BusyGamePlayLibrary.SetTest(config) | ||||
|     print("?>????", config) | ||||
|     if not config then | ||||
|         print("ERROR: can't find ", cook_material_id, " in CookMaterialStateConfig") | ||||
|         return | ||||
|  | ||||
							
								
								
									
										0
									
								
								Content/Lua/GamePlay/CookSystem/PreCookManager.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								Content/Lua/GamePlay/CookSystem/PreCookManager.lua
									
									
									
									
									
										Normal file
									
								
							| @ -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) | ||||
							
								
								
									
										175
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/PreCookCenterWidget.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/PreCookCenterWidget.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,175 @@ | ||||
| local DataTableUtils = require("Utils.DataTableUtils") | ||||
| local ESlateVisibility = import("ESlateVisibility") | ||||
| local SlateBlueprintLibrary = import("SlateBlueprintLibrary") | ||||
| local WidgetLayoutLibrary = import("WidgetLayoutLibrary") | ||||
|  | ||||
|  | ||||
|  | ||||
| --- @class PreCookCenterWidget | ||||
| --- @field ImgContainer table | ||||
| --- @field ImgCookMaterial table | ||||
| local PreCookCenterWidget = {} | ||||
|  | ||||
| function PreCookCenterWidget:ctor() | ||||
|     self.mouse_tracks = {} | ||||
|     self.is_pressed = false | ||||
| end | ||||
|  | ||||
|  | ||||
| function PreCookCenterWidget:OnInitialized() | ||||
|     self.bHasScriptImplementedTick = true | ||||
|  | ||||
|     self.BtnMain.OnReleased:Add(function() | ||||
|         -- self.bHasScriptImplementedTick = false | ||||
|         self.is_pressed = false | ||||
|         print("release") | ||||
|     end) | ||||
|     self.BtnMain.OnPressed:Add(function() | ||||
|         self.mouse_tracks = {} | ||||
|         self.is_pressed = true | ||||
|         -- self.bHasScriptImplementedTick = true | ||||
|         print("pressed") | ||||
|     end) | ||||
|     -- self.BtnMain.OnClicked:Add(function() | ||||
|     --     print("onclicked") | ||||
|     -- end) | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:Construct() | ||||
|     -- self.bHasScriptImplementedTick = true | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:Destruct() | ||||
|  | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:SetEmpty() | ||||
|     self.ImgContainer:SetVisibility(ESlateVisibility.Collapsed) | ||||
|     self.ImgCookMaterial:SetVisibility(ESlateVisibility.Collapsed) | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:AddContainer(pre_cook_contianer_id) | ||||
|     local row = DataTableUtils.GetDataTableRow("PreCookItemConfig", pre_cook_contianer_id) | ||||
|     if not row then return end | ||||
|     self.ImgContainer:SetBrushFromSoftTexture(row.CenterDisplayResource, true) | ||||
|     self.ImgContainer:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:RemoveContainer() | ||||
|     self.ImgContainer:SetVisibility(ESlateVisibility.Collapsed) | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:AddCookMaterial(pre_cook_material_id) | ||||
|     local row = DataTableUtils.GetDataTableRow("PreCookItemConfig", pre_cook_material_id) | ||||
|     if not row then return end | ||||
|     self.ImgCookMaterial:SetBrushFromSoftTexture(row.CenterDisplayResource, true) | ||||
|     self.ImgCookMaterial:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||
| end | ||||
|  | ||||
|  | ||||
| local function UpdateOldMouseTrack(old_mouse_tracks, delta_time) | ||||
|     local new_mouse_tracks = {} | ||||
|     -- local new_track = {x=fixed_x, y=fixed_y, remain=1.0} | ||||
|     for _, track in pairs(old_mouse_tracks) do | ||||
|         track.remain = track.remain - delta_time | ||||
|         if track.remain > 0 then | ||||
|             table.insert(new_mouse_tracks, track) | ||||
|         end | ||||
|     end | ||||
|     return new_mouse_tracks | ||||
| end | ||||
|  | ||||
| --- 将鼠标的轨迹坐标规范到以起始点到终点所连直线为x轴的坐标系下 | ||||
| local function NormalizeTrackParam(mouse_tracks) | ||||
|  | ||||
| end | ||||
|  | ||||
| --- 根据指定点坐标,求解三次样条参数 | ||||
| local function GetSplineParams(normalize_params) | ||||
|  | ||||
| end | ||||
|  | ||||
| local function UpdateCutMaskByTracks(widget, mouse_tracks) | ||||
|     local FVector2D = import("Vector2D") | ||||
|     local FWidgetTransform = import("WidgetTransform") | ||||
|     if #mouse_tracks < 2 then return end | ||||
|  | ||||
|     local translation, scale = FVector2D(), FVector2D() | ||||
|     local render_transform = FWidgetTransform() | ||||
|     local first_point, last_point = mouse_tracks[1], mouse_tracks[#mouse_tracks] | ||||
|     local delta_x = last_point.X - first_point.X | ||||
|     local delta_y = last_point.Y - first_point.Y | ||||
|     local mask_length = (delta_x^2 + delta_y^2)^0.5 | ||||
|  | ||||
|  | ||||
|  | ||||
|     translation.X, translation.Y = first_point.X, first_point.Y | ||||
|     scale.X, scale.Y = mask_length / 512, 1 | ||||
|     render_transform.Scale = scale | ||||
|     render_transform.Translation = translation | ||||
|     render_transform.Angle = (math.atan(delta_y, delta_x) / (2 * math.pi)) * 360 | ||||
|     -- render_transform.Scale = FVector2D(mask_length / 512, 1) | ||||
|     print(render_transform.Angle, math.atan(delta_y, delta_x)) | ||||
|  | ||||
|     widget:SetRenderTransform(render_transform) | ||||
| --[[ | ||||
|  | ||||
| 	/** The amount to translate the widget in slate units */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Transform, meta=( Delta = "1" )) | ||||
| 	FVector2D Translation; | ||||
|  | ||||
| 	/** The scale to apply to the widget */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Transform, meta=( UIMin = "-5", UIMax = "5", Delta = "0.05" )) | ||||
| 	FVector2D Scale; | ||||
|  | ||||
| 	/** The amount to shear the widget in slate units */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Transform, meta=( UIMin = "-89", ClampMin = "-89", UIMax = "89", ClampMax = "89", Delta = "1" )) | ||||
| 	FVector2D Shear; | ||||
|  | ||||
| 	/** The angle in degrees to rotate */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Transform, meta=( UIMin = "-180", UIMax = "180", Delta = "1" )) | ||||
| 	float Angle; | ||||
|  | ||||
| ]] | ||||
|  | ||||
| end | ||||
|  | ||||
| function PreCookCenterWidget:Tick(geometry, delta_time) | ||||
|     local size = SlateBlueprintLibrary.GetLocalSize(geometry) | ||||
|     local cursor_pos = WidgetLayoutLibrary.GetMousePositionOnViewport(self) | ||||
|     local left_top = SlateBlueprintLibrary.GetLocalTopLeft(geometry) | ||||
|     local fixed_x = math.min(math.max(cursor_pos.X - left_top.X, 0), size.X) | ||||
|     local fixed_y = math.min(math.max(cursor_pos.Y - left_top.Y, 0), size.Y) | ||||
|  | ||||
|     local mouse_tracks = UpdateOldMouseTrack(self.mouse_tracks, delta_time) | ||||
|  | ||||
|     if self.is_pressed then | ||||
|         table.insert(mouse_tracks, {X=fixed_x, Y=fixed_y, remain=0.5}) | ||||
|     end | ||||
|  | ||||
|     -- 计算样条参数 | ||||
|     local normalize_params = NormalizeTrackParam(mouse_tracks) | ||||
|     local A, B, C, D = GetSplineParams(normalize_params)  -- Ax^3 + Bx^2 + Cx + D | ||||
|  | ||||
|     -- 计算划痕位置 | ||||
|  | ||||
|     UpdateCutMaskByTracks(self.ImgMask, mouse_tracks) | ||||
|  | ||||
|     self.mouse_tracks = mouse_tracks | ||||
|  | ||||
|  | ||||
|     -- print(fixed_x, fixed_y, #self.mouse_tracks) | ||||
| end | ||||
|  | ||||
|  | ||||
|  | ||||
| -- function PreCookCenterWidget:LuaMouseButtonDown() | ||||
| --     print("on mouse button down") | ||||
| -- end | ||||
|  | ||||
| -- function PreCookCenterWidget:LuaMouseButtonUp() | ||||
| --     print("on mouse button up") | ||||
| -- end | ||||
|  | ||||
|  | ||||
| return Class(nil, nil, PreCookCenterWidget) | ||||
| @ -1,8 +1,15 @@ | ||||
| local DataTableUtils = require("Utils.DataTableUtils") | ||||
| local Emitter = require("Utils.Emitter") | ||||
| local EPreCookSlotType = import("EPreCookSlotType") | ||||
|  | ||||
| --- @class PreCookSlot | ||||
| local PreCookSlot = {} | ||||
|  | ||||
| function PreCookSlot:OnInitialized() | ||||
|     self.slot_item_id = nil | ||||
|     self.is_slot_item_active = false | ||||
|  | ||||
|     self.BtnMain.OnClicked:Add(function() self:BP_EmitLuaEvent("PreCookSlotClicked") end) | ||||
| end | ||||
|  | ||||
| function PreCookSlot:Construct() | ||||
| @ -18,18 +25,57 @@ function PreCookSlot:Reset() | ||||
|  | ||||
| end | ||||
|  | ||||
| function PreCookSlot:SetPreCookToolID(pre_cook_tool_id) | ||||
|     self:Reset() | ||||
|     if not pre_cook_tool_id then return end | ||||
| function PreCookSlot:GetSlotType() | ||||
|     return self.PreCookSlotType | ||||
| end | ||||
|  | ||||
|     local row_data = DataTableUtils.GetDataTableRow("PreCookItemConfig", pre_cook_tool_id) | ||||
| function PreCookSlot:GetSlotItemID() | ||||
|     return self.slot_item_id | ||||
| end | ||||
|  | ||||
| function PreCookSlot:SetPreCookItemID(pre_cook_item_id) | ||||
|     self:Reset() | ||||
|     if not pre_cook_item_id then return end | ||||
|  | ||||
|     local row_data = DataTableUtils.GetDataTableRow("PreCookItemConfig", pre_cook_item_id) | ||||
|     if not row_data then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     self.SlotImg:SetBrushFromSoftTexture(row_data.DisplayResource, true) | ||||
|     print("PreCookSlot:SetPreCookToolID", row_data) | ||||
|     self.slot_item_id = pre_cook_item_id | ||||
| end | ||||
|  | ||||
| function PreCookSlot:SetPreCookTool(pre_cook_tool_id) | ||||
|     self:SetPreCookItemID(pre_cook_tool_id) | ||||
| end | ||||
|  | ||||
| function PreCookSlot:SetPreCookContainer(pre_cook_container_id) | ||||
|     self:SetPreCookItemID(pre_cook_container_id) | ||||
| end | ||||
|  | ||||
| function PreCookSlot:ActiveToolSlot() | ||||
|     self:PlayAnimation(self.Anim_UseTool, 0, 1, 0, 5, false) | ||||
| end | ||||
|  | ||||
| function PreCookSlot:DeactiveToolSlot() | ||||
|     self:PlayAnimation(self.Anim_UseTool, 0, 1, 1, 1, false) | ||||
| end | ||||
|  | ||||
|  | ||||
| function PreCookSlot:PushSlotItem() | ||||
|     self:PlayAnimation(self.Anim_PushItem, 0, 1, 0, 1, false) | ||||
| end | ||||
|  | ||||
| function PreCookSlot:ActiveContainerSlot() | ||||
|     self:PlayAnimation(self.Anim_PushItem, 0, 1, 0, 1, false) | ||||
| end | ||||
|  | ||||
| function PreCookSlot:DeactiveContianerSlot() | ||||
|     print("PreCookSlot:DeactiveContianerSlot") | ||||
|     self:PlayAnimation(self.Anim_PushItem, 0, 1, 1, 1, false) | ||||
| end | ||||
|  | ||||
|  | ||||
|  | ||||
| return Class(nil, nil, PreCookSlot) | ||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Resource/Material/M_SS.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Resource/Material/M_SS.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Resource/Material/M_SS_Inst.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Resource/Material/M_SS_Inst.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Resource/Material/TilingNoise05.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Resource/Material/TilingNoise05.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Resource/Texture/UI/Homeland/Hearth/PreCook/flour.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Resource/Texture/UI/Homeland/Hearth/PreCook/flour.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Resource/Texture/UI/Homeland/Hearth/PreCook/water.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Resource/Texture/UI/Homeland/Hearth/PreCook/water.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -3,6 +3,7 @@ | ||||
|  | ||||
| #include "Core/PW_UserWidget.h" | ||||
| #include "Core/UI/PW_UIHud.h" | ||||
| #include "slua.h" | ||||
|  | ||||
| UPW_SimpleWidget::UPW_SimpleWidget():bVisible(true){ | ||||
| 	bVisible = true; | ||||
| @ -27,6 +28,67 @@ void UPW_SimpleWidget::BP_SetVisible(bool InVisible){ | ||||
| 	SetVisible(InVisible); | ||||
| } | ||||
|  | ||||
| FLuaWidgetEventHandle UPW_SimpleWidget::BP_BindLuaEvent(const FName& EventName, const FLuaBPVar& InLuaFunction){ | ||||
| 	FLuaWidgetEventHandle Handle; | ||||
| 	if (!InLuaFunction.value.isFunction()) { | ||||
| 		return Handle; | ||||
| 	} | ||||
| 	TMap<int32, slua::LuaVar>& FunctionPool = LuaFuncMappings.FindOrAdd(EventName); | ||||
| 	HandleIndex += 1; | ||||
| 	FunctionPool.Add(HandleIndex, InLuaFunction.value); | ||||
| 	//FunctionPool[HandleIndex] = InLuaFunction.value; | ||||
| 	Handle.EventName = EventName; | ||||
| 	Handle.HandleIndex = HandleIndex; | ||||
| 	return Handle; | ||||
| } | ||||
|  | ||||
|  | ||||
| void UPW_SimpleWidget::BP_UnBindLuaEvent(const FLuaWidgetEventHandle &InHandle){ | ||||
| 	TMap<int32, slua::LuaVar>* FunctionPool = LuaFuncMappings.Find(InHandle.EventName); | ||||
| 	if (FunctionPool == nullptr) { | ||||
| 		return; | ||||
| 	} | ||||
| 	FunctionPool->Remove(InHandle.HandleIndex); | ||||
| } | ||||
|  | ||||
| void UPW_SimpleWidget::BP_EmitLuaEvent(const FName& EventName, const FLuaBPVar& InLuaArgs){ | ||||
| 	TMap<int32, slua::LuaVar>* FunctionPool = LuaFuncMappings.Find(EventName); | ||||
| 	if (FunctionPool == nullptr) { | ||||
| 		return; | ||||
| 	} | ||||
| 	for (auto &Pair : *FunctionPool) { | ||||
| 		slua::LuaVar& Callback = Pair.Value; | ||||
| 		if (!Callback.isFunction()) { | ||||
| 			continue; | ||||
| 		} | ||||
| 		Callback.call(InLuaArgs.value); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| FReply UPW_SimpleWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent){ | ||||
| 	slua::LuaVar SelfTable = GetSelfTable(); | ||||
| 	if (SelfTable.isTable()) { | ||||
| 		slua::LuaVar LuaCallback = SelfTable.getFromTable<slua::LuaVar, FString>(TEXT("LuaMouseButtonDown")); | ||||
| 		if (LuaCallback.isFunction()) { | ||||
| 			LuaCallback.call(); | ||||
| 		} | ||||
| 	} | ||||
| 	return FReply::Unhandled(); | ||||
| 	//return Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent); | ||||
| } | ||||
|  | ||||
| FReply UPW_SimpleWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent){ | ||||
| 	slua::LuaVar SelfTable = GetSelfTable(); | ||||
| 	if (SelfTable.isTable()) { | ||||
| 		slua::LuaVar LuaCallback = SelfTable.getFromTable<slua::LuaVar, FString>(TEXT("LuaMouseButtonUp")); | ||||
| 		if (LuaCallback.isFunction()) { | ||||
| 			LuaCallback.call(); | ||||
| 		} | ||||
| 	} | ||||
| 	return FReply::Unhandled(); | ||||
| 	//return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent); | ||||
| } | ||||
|  | ||||
| void UPW_UserWidget::BP_Close(){ | ||||
| 	APW_UIHud* Hud = Cast<APW_UIHud>(GetPlayerContext().GetHUD()); | ||||
| 	if (!Hud) return; | ||||
|  | ||||
| @ -4,6 +4,7 @@ | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "LuaUserWidget.h" | ||||
| #include "LuaBlueprintLibrary.h" | ||||
| #include "PW_UserWidget.generated.h" | ||||
|  | ||||
| UENUM(BlueprintType) | ||||
| @ -16,6 +17,14 @@ enum class EWidgetLayoutType: uint8 { | ||||
| }; | ||||
|  | ||||
|  | ||||
| USTRUCT(BlueprintType) | ||||
| struct FLuaWidgetEventHandle { | ||||
| 	GENERATED_BODY() | ||||
| 	FName EventName; | ||||
| 	int32 HandleIndex; | ||||
| }; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  */ | ||||
| @ -33,9 +42,29 @@ public: | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	void BP_SetVisible(bool InVisible); | ||||
|  | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	FLuaWidgetEventHandle BP_BindLuaEvent(const FName& EventName, const FLuaBPVar& InLuaFunction); | ||||
|  | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	void BP_UnBindLuaEvent(const FLuaWidgetEventHandle& InHandle); | ||||
|  | ||||
| 	UFUNCTION(BlueprintCallable) | ||||
| 	void BP_EmitLuaEvent(const FName& EventName, const FLuaBPVar& InLuaArgs); | ||||
|  | ||||
| public: | ||||
| 	virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)override; | ||||
|  | ||||
| 	virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)override; | ||||
|  | ||||
|  | ||||
| public: | ||||
| 	UPROPERTY(BlueprintReadOnly) | ||||
| 	bool bVisible; | ||||
|  | ||||
|  | ||||
| protected: // lua相关 | ||||
| 	int32 HandleIndex = 0; | ||||
| 	TMap<FName, TMap<int32, slua::LuaVar>> LuaFuncMappings; | ||||
| }; | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -3,8 +3,16 @@ | ||||
| #include "Engine/Texture2D.h" | ||||
| #include "BusyPreCookTable.generated.h" | ||||
|  | ||||
| UENUM(BlueprintType) | ||||
| enum class EPreCookSlotType: uint8{ | ||||
| 	PreCookTool = 0, | ||||
| 	PreCookContainer = 1, | ||||
| 	PreCookRawMaterial = 2, | ||||
| 	PreCookFinishedMaterial = 3 | ||||
| }; | ||||
|  | ||||
| USTRUCT() | ||||
|  | ||||
| USTRUCT(BlueprintType) | ||||
| struct FBusyPreCookItemConfig: public FTableRowBase { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| @ -20,4 +28,7 @@ struct FBusyPreCookItemConfig: public FTableRowBase { | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "用于显示的资源") | ||||
| 	TSoftObjectPtr<UTexture2D> DisplayResource; | ||||
|  | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "放在中心时的资源") | ||||
| 	TSoftObjectPtr<UTexture2D> CenterDisplayResource; | ||||
|  | ||||
| }; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user