54 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
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) |