按下 Esc 键时如何关闭 AceGUI 3.0 框架?

Rob*_*per 1 lua world-of-warcraft

我正在将 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")
Run Code Online (Sandbox Code Playgroud)

Rob*_*per 5

作为魔兽世界 API 的一部分,该UISpecialFrames表作为全局变量提供,当按下退出键时,该表中的任何字符串都将从全局变量表中获取作为键;如果该全局变量是一个打开的 WoW 框架,它将被关闭。

这意味着您必须将 WoW 框架声明为全局变量,并将变量的名称添加到UISpecialFrames带有table.insert. 请注意,AceGUI 框架的 WoW 框架存储在其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")
Run Code Online (Sandbox Code Playgroud)