按下转义键时如何关闭 AceGUI 3.0 Frame?

How to close an AceGUI 3.0 Frame when escape is pressed?

我将 WowAce 的 Ace3 AceGUI 库用于魔兽世界插件。我希望在按下退出键时关闭我的框架,这是游戏中的惯例。

框架是这样创建的:

    local frame = AceGUI:Create("Frame")
    frame:SetTitle("Flare")
    frame:SetStatusText("Ready")
    frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
    frame:SetLayout("List")

作为魔兽世界的一部分API,UISpecialFramestable作为全局变量提供,table中的任何字符串都会被获取当按下转义键时,作为全局变量 table 中的键;如果那个全局变量是一个打开的魔兽世界框架,它将被关闭。

这意味着您必须将您的 WoW Frame 声明为全局变量并将变量的名称添加到 UISpecialFrames table 和 table.insert。请注意,AceGUI Frame 的 WoW Frame 存储在其 frame 键下。放在代码中:

    local frame = AceGUI:Create("Frame")
    frame:SetTitle("Flare")
    frame:SetStatusText("Ready")
    frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
    frame:SetLayout("List")

    -- Add the frame as a global variable under the name `MyGlobalFrameName`
    _G["MyGlobalFrameName"] = frame.frame
    -- Register the global variable `MyGlobalFrameName` as a "special frame"
    -- so that it is closed when the escape key is pressed.
    tinsert(UISpecialFrames, "MyGlobalFrameName")