所以我一直在倒在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)
提前感谢所有帮助!
将 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, ...)
(您可以轻松地以编程方式构建菜单项,而不是像我在这里所做的那样手动构建。
我不熟悉魔兽世界。我从您链接到的站点获取了信息:它说菜单回调具有签名(self,arg1,arg2,选中)。