所以我一直在倾听有关Lua牌桌的信息,而且我有点卡住了。
local profiles = {
{ text = "Profile 1", name = "Profile 1", func = fuction() loadProfile("Profile 1");, INT = .5, STR = .5, AGI = .5, CRIT = .5, HASTE = .5, MAS = .5, MS = .5, VERS = .5},
{ text = "Profile 2", name = "Profile 2", INT = .6, STR = .6, AGI = .6, CRIT = .6, HASTE = .6, MAS = .6, MS = .6, VERS = .6},
{ text = "Profile 3", name = "Profile 3", INT = .7, STR = .7, AGI = .7, CRIT = .7, HASTE = .7, MAS = .7, MS = .7, VERS = .7},
{ text = "Profile 4", name = "Profile 4", INT = .8, STR = .8, AGI = .8, CRIT = .8, HASTE = .8, MAS = .8, MS = .8, VERS = .8},
}
function loadProfile(name)
--Loop through table using pairs
--Once name is found, load INT into INTELLECTSTAT, etc
end
local profilesDropDown = CreateFrame("Frame", nil, ActualValue, "UIDropDownMenuTemplate")
menuFrame:SetPoint("TOPLEFT", ActualValue, 300, -40)
EasyMenu(profiles, profilesDropDown, ActualValue, 300 , -40, "Profiles");
正如您所看到的那样,我坚持加载信息,当用户点击其中一个菜单项时,它会触发该菜单项的功能,在本例中为loadProfile。
接下来我想我需要遍历表格寻找名称,一旦找到加载所有变量,但我不确定如何做到这一点,或者我是否甚至在表格中构建表格我能做到最好的方式。
最后,我很难理解DropDown在函数调用方面的文档,并且想知道我是否做得对吗? (它在底部http://www.wowwiki.com/API_EasyMenu使用的示例)
感谢所有人提前帮助!
答案 0 :(得分:1)
将GUI与"业务逻辑"混合起来并不优雅。
首先,将配置文件设为一个单独的表:
local profiles = {
["Profile 1"] = {
INT = .5, STR = .5, AGI = .5,
},
["Profile 2"] = {
INT = .6, STR = .6, AGI = .6,
},
}
然后,编写菜单项:
local function loadProfile(_, prof)
INTELLECTSTAT = prof.INT
end
local menuItems = {
{ text = "Profile 1", func = loadProfile, arg1 = profiles["Profile 1"] },
{ text = "Profile 2", func = loadProfile, arg1 = profiles["Profile 2"] },
}
...
EasyMenu(menuItems, ...)
(您可以轻松地以编程方式构建menuItems,而不是像我在这里那样手工制作。)
我不熟悉魔兽世界。我从您链接到的网站上获取了信息:它表示菜单回调have the signature (self, arg1, arg2, checked)。