luaengine: make flags explicit (nw)

This commit is contained in:
cracyc 2016-04-09 09:02:07 -05:00
parent db33240862
commit cf8c7fb206
6 changed files with 45 additions and 35 deletions

View File

@ -260,17 +260,17 @@ function cheat.startplugin()
menu[num][1] = "---"
end
menu[num][2] = ""
menu[num][3] = 32 -- MENU_FLAG_DISABLE
menu[num][3] = "off"
elseif not cheat.script.run and not cheat.script.off then
menu[num][2] = "Set"
menu[num][3] = 0
else
if cheat.enabled then
menu[num][2] = "On"
menu[num][3] = 1 -- MENU_FLAG_LEFT_ARROW
menu[num][3] = "l"
else
menu[num][2] = "Off"
menu[num][3] = 2 -- MENU_FLAG_RIGHT_ARROW
menu[num][3] = "r"
end
end
else
@ -280,16 +280,16 @@ function cheat.startplugin()
else
menu[num][2] = "Off"
end
menu[num][3] = 2
menu[num][3] = "r"
else
if cheat.parameter.item then
menu[num][2] = cheat.parameter.item[cheat.parameter.index].text
else
menu[num][2] = cheat.parameter.value
end
menu[num][3] = 1
menu[num][3] = "l"
if cheat.parameter.index < cheat.parameter.last then
menu[num][3] = 3
menu[num][3] = "lr"
end
end
end

View File

@ -139,38 +139,38 @@ function cheatfind.startplugin()
if #devtable == 1 then
menu[1][3] = 0
elseif devsel == 1 then
menu[1][3] = 2
menu[1][3] = "r"
elseif devsel == #devtable then
menu[1][3] = 1
menu[1][3] = "l"
else
menu[1][3] = 3
menu[1][3] = "lr"
end
menu[2] = { "Init", "", 0 }
if next(menu_blocks) then
menu[3] = { "---", "", 32 }
menu[3] = { "---", "", "off" }
menu[4] = {}
menu[4][1] = "Operator"
menu[4][2] = optable[opsel]
if opsel == 1 then
menu[4][3] = 2
menu[4][3] = "r"
elseif opsel == #optable then
menu[4][3] = 1
menu[4][3] = "l"
else
menu[4][3] = 3
menu[4][3] = "lr"
end
menu[5] = {}
menu[5][1] = "Change"
menu[5][2] = change
if change == 0 then
menu[5][2] = "Any"
menu[5][3] = 2
menu[5][3] = "r"
elseif change == 100 then --?
menu[5][3] = 1
menu[5][3] = "l"
else
menu[5][3] = 3
menu[5][3] = "lr"
end
menu[6] = { "Compare", "", 0 }
menu[7] = { "---", "", 32 }
menu[7] = { "---", "", "off" }
for num, list in ipairs(matches) do
for num2, match in ipairs(list) do
if #menu > 50 then

View File

@ -75,12 +75,12 @@ function timer.startplugin()
local function menu_populate()
local time = os.time() - start_time
return {{ "Current time", "", 32 },
{ sectohms(time), "", 32 },
{ "Total time", "", 32 },
{ sectohms(total_time + time), "", 32 },
{ "Play Count", "", 32 },
{ play_count, "", 32 }}
return {{ "Current time", "", "off" },
{ sectohms(time), "", "off" },
{ "Total time", "", "off" },
{ sectohms(total_time + time), "", "off" },
{ "Play Count", "", "off" },
{ play_count, "", "off" }}
end
local function menu_callback(index, event)

View File

@ -1738,9 +1738,8 @@ lua_engine::~lua_engine()
close();
}
std::vector<lua_engine::menu_item> &lua_engine::menu_populate(std::string &menu)
void lua_engine::menu_populate(std::string &menu, std::vector<menu_item> &menu_list)
{
std::vector<menu_item> &menu_list = *global_alloc(std::vector<menu_item>);
std::string field = "menu_pop_" + menu;
lua_settop(m_lua_state, 0);
lua_getfield(m_lua_state, LUA_REGISTRYINDEX, field.c_str());
@ -1748,19 +1747,19 @@ std::vector<lua_engine::menu_item> &lua_engine::menu_populate(std::string &menu)
if(!lua_isfunction(m_lua_state, -1))
{
lua_pop(m_lua_state, 1);
return menu_list;
return;
}
if(int error = lua_pcall(m_lua_state, 0, 1, 0))
{
if(error == 2)
printf("%s\n", lua_tostring(m_lua_state, -1));
lua_pop(m_lua_state, 1);
return menu_list;
return;
}
if(!lua_istable(m_lua_state, -1))
{
lua_pop(m_lua_state, 1);
return menu_list;
return;
}
lua_pushnil(m_lua_state);
@ -1776,14 +1775,13 @@ std::vector<lua_engine::menu_item> &lua_engine::menu_populate(std::string &menu)
item.subtext = lua_tostring(m_lua_state, -1);
lua_pop(m_lua_state, 1);
lua_rawgeti(m_lua_state, -1, 3);
item.flags = lua_tointeger(m_lua_state, -1);
item.flags = lua_tostring(m_lua_state, -1);
lua_pop(m_lua_state, 1);
menu_list.push_back(item);
}
lua_pop(m_lua_state, 1);
}
lua_pop(m_lua_state, 1);
return menu_list;
}
bool lua_engine::menu_callback(std::string &menu, int index, std::string event)

View File

@ -52,9 +52,9 @@ public:
struct menu_item {
std::string text;
std::string subtext;
int flags;
std::string flags;
};
std::vector<menu_item> &menu_populate(std::string &menu);
void menu_populate(std::string &menu, std::vector<menu_item> &menu_list);
bool menu_callback(std::string &menu, int index, std::string event);
void resume(lua_State *L, int nparam = 0, lua_State *root = nullptr);

View File

@ -87,12 +87,24 @@ void ui_menu_plugin_opt::handle()
void ui_menu_plugin_opt::populate()
{
std::vector<lua_engine::menu_item> &menu_list = machine().manager().lua()->menu_populate(m_menu);
std::vector<lua_engine::menu_item> menu_list;
machine().manager().lua()->menu_populate(m_menu, menu_list);
FPTR i = 1;
for(auto &item : menu_list)
item_append(item.text.c_str(), item.subtext.c_str(), item.flags, (void *)i++);
{
UINT32 flags = 0;
if(item.flags == "off")
flags = 32;
else if(item.flags == "l")
flags = 1;
else if(item.flags == "r")
flags = 2;
else if(item.flags == "lr")
flags = 3;
item_append(item.text.c_str(), item.subtext.c_str(), flags, (void *)i++);
}
item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr);
global_free(&menu_list);
}
ui_menu_plugin_opt::~ui_menu_plugin_opt()