81 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
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) |