初始化提交
This commit is contained in:
		
							
								
								
									
										54
									
								
								Content/Lua/UI/Common/PopupMenu/PopupMenuItem.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								Content/Lua/UI/Common/PopupMenu/PopupMenuItem.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| local PopupMenuItem = {} | ||||
| local UIUtils = require("UI.Utils") | ||||
|  | ||||
| function PopupMenuItem:ctor() | ||||
|     self.on_click_callback = nil | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:PreConstruct(IsDesignTime) | ||||
|     if not IsDesignTime then return end | ||||
|     self.TxtMenuName:SetText(self.MenuText) | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:OnInitialized() | ||||
|     self:BindEvent("OnClicked", function() self:OnMenuItemClicked() end) | ||||
|     self:BindEvent("OnHovered", function() self:OnHoverStateChange(true) end) | ||||
|     self:BindEvent("OnUnhovered", function() self:OnHoverStateChange(false) end) | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:Construct() | ||||
|     self.TxtMenuName:SetText(self.MenuText) | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:OnDestroy() | ||||
|     print(self, "PopupMenuItem:OnDestroy") | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:SetContent(name, callback) | ||||
|     self.TxtMenuName:SetText(name) | ||||
|     self.on_click_callback = callback | ||||
|     print(self.TxtMenuName:GetText()) | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:BindEvent(event_name, callback) | ||||
|     self.BtnMain[event_name]:Add(callback) | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:OnHoverStateChange(is_hoverd) | ||||
|     if is_hoverd then | ||||
|         self.ImgBackground.Brush.TintColor = self.ItemHoverdColor | ||||
|     else | ||||
|         self.ImgBackground.Brush.TintColor = self.ItemNormalColor | ||||
|     end | ||||
| end | ||||
|  | ||||
| function PopupMenuItem:OnMenuItemClicked() | ||||
|     print("OnMenuItemClicked") | ||||
|     if self.on_click_callback ~= nil then | ||||
|         self.on_click_callback() | ||||
|     end | ||||
|     UIUtils.HideWidgetByName(self, "MenuPanel") | ||||
| end | ||||
|  | ||||
|  | ||||
| return Class(nil, nil, PopupMenuItem) | ||||
							
								
								
									
										81
									
								
								Content/Lua/UI/Common/PopupMenu/PopupMenuPanel.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								Content/Lua/UI/Common/PopupMenu/PopupMenuPanel.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,81 @@ | ||||
| local PopupMenuPanel = {} | ||||
| local UIUtils = require("UI.Utils") | ||||
| local GameplayStatics = import("GameplayStatics") | ||||
| local WidgetBlueprintLibrary = import("WidgetBlueprintLibrary") | ||||
| local KismetSystemLibrary = import("KismetSystemLibrary") | ||||
|  | ||||
|  | ||||
| local function delay_adjust_content(menu_panel) | ||||
|     local post_callback = function() | ||||
|         local timer = KismetSystemLibrary.K2_SetTimerForNextTickDelegate( | ||||
|             slua.createDelegate(function () | ||||
|                 menu_panel:AdjustMenuContentSize() | ||||
|                 menu_panel.adjust_content_timer = nil | ||||
|             end) | ||||
|         ) | ||||
|         menu_panel.adjust_content_timer = timer | ||||
|     end | ||||
|  | ||||
|     local timer = KismetSystemLibrary.K2_SetTimerForNextTickDelegate( | ||||
|         slua.createDelegate(function () post_callback() end) | ||||
|     ) | ||||
|     menu_panel.adjust_content_timer = timer | ||||
| end | ||||
|  | ||||
| local function CreateMenuItem(panel) | ||||
|     local pc = GameplayStatics.GetPlayerController(panel, 0) | ||||
|     local widget = WidgetBlueprintLibrary.Create(panel, panel.MenuItemClass, pc) | ||||
|     return widget | ||||
| end | ||||
|  | ||||
|  | ||||
| function PopupMenuPanel:ctor() | ||||
|     self.adjust_content_timer = nil | ||||
| end | ||||
|  | ||||
| function PopupMenuPanel:OnInitialized() | ||||
|     self.BtnBackground.OnClicked:Add(function() | ||||
|         UIUtils.CloseWidget(self) | ||||
|     end) | ||||
| end | ||||
|  | ||||
| function PopupMenuPanel:OnDestroy() | ||||
|     print(self, "PopupMenuPanel:OnDestroy") | ||||
| end | ||||
|  | ||||
| function PopupMenuPanel:PreConstruct(IsDesignTime) | ||||
|     if not IsDesignTime then return end | ||||
|     delay_adjust_content(self) | ||||
| end | ||||
|  | ||||
|  | ||||
| function PopupMenuPanel:Construct() | ||||
|     delay_adjust_content(self) | ||||
| end | ||||
|  | ||||
| function PopupMenuPanel:AdjustMenuContentSize() | ||||
|     local all_child_height = 0 | ||||
|     for _, child in pairs(self.MenuItemContainer:GetAllChildren()) do | ||||
|         local design_size = child:GetDesiredSize() | ||||
|         all_child_height = all_child_height + design_size.Y | ||||
|     end | ||||
|     self.ImgBackground.Brush.ImageSize.Y = all_child_height + 20 | ||||
| end | ||||
|  | ||||
|  | ||||
| function PopupMenuPanel:Refresh(args) | ||||
|     self.MainOverlay.Slot:SetPosition(args[1]) | ||||
|     self:SetMenuContents(args[2]) | ||||
| end | ||||
|  | ||||
| function PopupMenuPanel:SetMenuContents(contents) | ||||
|     self.MenuItemContainer:ClearChildren() | ||||
|     for _, content in pairs(contents) do | ||||
|         local widget = CreateMenuItem(self) | ||||
|         self.MenuItemContainer:AddChildToVerticalBox(widget) | ||||
|         widget:SetContent(content[1], content[2]) | ||||
|     end | ||||
|     self:AdjustMenuContentSize() | ||||
| end | ||||
|  | ||||
| return Class(nil, nil,PopupMenuPanel) | ||||
							
								
								
									
										28
									
								
								Content/Lua/UI/Common/TableSwitcher/SwitcherWidget.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Content/Lua/UI/Common/TableSwitcher/SwitcherWidget.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| local SwitcherWidget = {} | ||||
| local ESlateVisibility = import("ESlateVisibility") | ||||
|  | ||||
| function SwitcherWidget:Construct() | ||||
|     self:Reset() | ||||
|     self["ImageNormal"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||
| end | ||||
|  | ||||
| function SwitcherWidget:Reset() | ||||
|     self["ImageHovered"]:SetVisibility(ESlateVisibility.Collapsed) | ||||
|     self["ImageSelected"]:SetVisibility(ESlateVisibility.Collapsed) | ||||
|     self["ImageNormal"]:SetVisibility(ESlateVisibility.Collapsed) | ||||
| end | ||||
|  | ||||
| function SwitcherWidget:OnWidgetStateChange(bIsWidgetHovered, bIsWidgetSelected) | ||||
|     self:Reset() | ||||
|     if bIsWidgetSelected then | ||||
|         self["ImageSelected"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||
|     else | ||||
|         if bIsWidgetHovered then | ||||
|             self["ImageHovered"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||
|         else | ||||
|             self["ImageNormal"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||
|         end | ||||
|     end | ||||
| end | ||||
|  | ||||
| return Class(nil, nil, SwitcherWidget) | ||||
		Reference in New Issue
	
	Block a user