开始开发大厅烹饪功能
This commit is contained in:
		
							
								
								
									
										79
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/CookingBench.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/CookingBench.lua
									
									
									
									
									
										Normal 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) | ||||
							
								
								
									
										28
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/CookingPot.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/CookingPot.lua
									
									
									
									
									
										Normal 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) | ||||
							
								
								
									
										42
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/CookingSlot.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/CookingSlot.lua
									
									
									
									
									
										Normal 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) | ||||
		Reference in New Issue
	
	Block a user