Skip to content

Commit

Permalink
add tpt.num_menus and tpt.menu_enabled functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Jul 9, 2016
1 parent 8809749 commit b75c831
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -1045,6 +1045,21 @@ std::vector<Menu*> GameController::GetMenuList()
return gameModel->GetMenuList();
}

int GameController::GetNumMenus(bool onlyEnabled)
{
int count = 0;
if (onlyEnabled)
{
std::vector<Menu*> menuList = gameModel->GetMenuList();
for (std::vector<Menu*>::iterator it = menuList.begin(), end = menuList.end(); it != end; ++it)
if ((*it)->GetVisible())
count++;
}
else
count = gameModel->GetMenuList().size();
return count;
}

void GameController::RebuildFavoritesMenu()
{
gameModel->BuildFavoritesMenu();
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -103,6 +103,7 @@ class GameController: public ClientListener
void SetDebugFlags(unsigned int flags) { debugFlags = flags; }
void SetActiveMenu(int menuID);
std::vector<Menu*> GetMenuList();
int GetNumMenus(bool onlyEnabled);
void RebuildFavoritesMenu();
Tool * GetActiveTool(int selection);
void SetActiveTool(int toolSelection, Tool * tool);
Expand Down
9 changes: 0 additions & 9 deletions src/gui/game/GameModel.cpp
Expand Up @@ -248,15 +248,6 @@ void GameModel::BuildMenus()
elementTools.clear();

//Create menus
for (int i = 1; i < SC_TOOL; i++)
{
sim->msections[i].doshow = 0;
}
for (int i = 0; i < PT_NUM; i++)
{
if (sim->elements[i].Enabled && sim->elements[i].MenuVisible)
sim->msections[sim->elements[i].MenuSection].doshow = 1;
}
for (int i = 0; i < SC_TOTAL; i++)
{
menuList.push_back(new Menu((const char)sim->msections[i].icon[0], sim->msections[i].name, sim->msections[i].doshow));
Expand Down
24 changes: 24 additions & 0 deletions src/lua/LegacyLuaAPI.cpp
Expand Up @@ -1800,6 +1800,30 @@ int luatpt_active_menu(lua_State* l)
return 0;
}

int luatpt_menu_enabled(lua_State* l)
{
int menusection = luaL_checkint(l, 1);
if (menusection < 0 || menusection >= SC_TOTAL)
return luaL_error(l, "Invalid menu");
int acount = lua_gettop(l);
if (acount == 1)
{
lua_pushboolean(l, luacon_sim->msections[menusection].doshow);
return 1;
}
luaL_checktype(l, 2, LUA_TBOOLEAN);
int enabled = lua_toboolean(l, 2);
luacon_sim->msections[menusection].doshow = enabled;
luacon_model->BuildMenus();
return 0;
}

int luatpt_num_menus(lua_State* l)
{
lua_pushinteger(l, luacon_controller->GetNumMenus(true));
return 1;
}

int luatpt_decorations_enable(lua_State* l)
{
int acount = lua_gettop(l);
Expand Down
2 changes: 2 additions & 0 deletions src/lua/LuaScriptHelper.h
Expand Up @@ -115,6 +115,8 @@ int luatpt_hud(lua_State* l);
int luatpt_gravity(lua_State* l);
int luatpt_airheat(lua_State* l);
int luatpt_active_menu(lua_State* l);
int luatpt_menu_enabled(lua_State* l);
int luatpt_num_menus(lua_State* l);
int luatpt_decorations_enable(lua_State* l);

int luatpt_heat(lua_State* l);
Expand Down
2 changes: 2 additions & 0 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -188,6 +188,8 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
{"newtonian_gravity", &luatpt_gravity},
{"ambient_heat", &luatpt_airheat},
{"active_menu", &luatpt_active_menu},
{"menu_enabled", &luatpt_menu_enabled},
{"num_menus", &luatpt_num_menus},
{"decorations_enable", &luatpt_decorations_enable},
{"display_mode", &luatpt_cmode_set},
{"throw_error", &luatpt_error},
Expand Down

0 comments on commit b75c831

Please sign in to comment.