Skip to content

Commit

Permalink
Remove invisible CRACKER and CRACKER2 menu sections
Browse files Browse the repository at this point in the history
Also add elem.NUM_MENUSECTIONS, which specifies the range of valid ui.menuEnabled inputs and MenuSection element property values.
  • Loading branch information
LBPHacker committed Apr 26, 2024
1 parent 6ce8e10 commit 4179155
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/gui/game/GameModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ void GameModel::BuildMenus()
elementTools.clear();

//Create menus
for (int i = 0; i < SC_TOTAL; i++)
for (auto &section : sd.msections)
{
menuList.push_back(new Menu(sd.msections[i].icon, sd.msections[i].name, sd.msections[i].doshow));
menuList.push_back(new Menu(section.icon, section.name, section.doshow));
}

//Build menus from Simulation elements
Expand All @@ -284,7 +284,7 @@ void GameModel::BuildMenus()
tempTool = new ElementTool(i, elements[i].Name, elements[i].Description, elements[i].Colour, elements[i].Identifier, elements[i].IconGenerator);
}

if (elements[i].MenuSection >= 0 && elements[i].MenuSection < SC_TOTAL && elements[i].MenuVisible)
if (elements[i].MenuSection >= 0 && elements[i].MenuSection < int(sd.msections.size()) && elements[i].MenuVisible)
{
menuList[elements[i].MenuSection]->AddTool(tempTool);
}
Expand Down
4 changes: 4 additions & 0 deletions src/lua/LuaElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ static int getByName(lua_State *L)

void LuaElements::Open(lua_State *L)
{
auto &sd = SimulationData::CRef();
static const luaL_Reg reg[] = {
#define LFUNC(v) { #v, v }
LFUNC(allocate),
Expand All @@ -850,6 +851,7 @@ void LuaElements::Open(lua_State *L)
lua_newtable(L);
luaL_register(L, NULL, reg);
#define LCONST(v) lua_pushinteger(L, int(v)); lua_setfield(L, -2, #v)
#define LCONSTAS(k, v) lua_pushinteger(L, int(v)); lua_setfield(L, -2, k)
LCONST(TYPE_PART);
LCONST(TYPE_LIQUID);
LCONST(TYPE_SOLID);
Expand Down Expand Up @@ -885,10 +887,12 @@ void LuaElements::Open(lua_State *L)
LCONST(SC_LIFE);
LCONST(SC_TOOL);
LCONST(SC_DECO);
LCONSTAS("NUM_MENUSECTIONS", int(sd.msections.size()));
LCONST(UPDATE_AFTER);
LCONST(UPDATE_REPLACE);
LCONST(UPDATE_BEFORE);
LCONST(NUM_UPDATEMODES);
#undef LCONSTAS
#undef LCONST
lua_pushvalue(L, -1);
lua_setglobal(L, "elements");
Expand Down
10 changes: 7 additions & 3 deletions src/lua/LuaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ static int activeMenu(lua_State *L)
lua_pushinteger(L, lsi->gameModel->GetActiveMenu());
return 1;
}
auto &sd = SimulationData::CRef();
int menuid = luaL_checkint(L, 1);
if (menuid >= 0 && menuid < SC_TOTAL)
if (menuid >= 0 && menuid < int(sd.msections.size()))
lsi->gameController->SetActiveMenu(menuid);
else
return luaL_error(L, "Invalid menu");
Expand All @@ -399,8 +400,11 @@ static int activeMenu(lua_State *L)
static int menuEnabled(lua_State *L)
{
int menusection = luaL_checkint(L, 1);
if (menusection < 0 || menusection >= SC_TOTAL)
return luaL_error(L, "Invalid menu");
{
auto &sd = SimulationData::CRef();
if (menusection < 0 || menusection >= int(sd.msections.size()))
return luaL_error(L, "Invalid menu");
}
int acount = lua_gettop(L);
if (acount == 1)
{
Expand Down
2 changes: 0 additions & 2 deletions src/simulation/SimulationData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ static std::vector<menu_section> LoadMenus()
{0xE057, String("Tools"), 0, 1},
{0xE067, String("Favorites"), 0, 1},
{0xE064, String("Decoration tools"), 0, 1},
{0xE048, String("Cracker"), 0, 0},
{0xE048, String("Cracker!"), 0, 0},
};
}

Expand Down
3 changes: 0 additions & 3 deletions src/simulation/SimulationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ constexpr int SC_LIFE = 12;
constexpr int SC_TOOL = 13;
constexpr int SC_FAVORITES = 14;
constexpr int SC_DECO = 15;
constexpr int SC_CRACKER = 16;
constexpr int SC_CRACKER2 = 17;
constexpr int SC_TOTAL = 16;

constexpr int O_WL_WALLELEC = 122;
constexpr int O_WL_EWALL = 123;
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/elements/BIZRG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ void Element::Element_BIZRG()
Identifier = "DEFAULT_PT_BIZRG";
Name = "BIZG";
Colour = 0x00FFBB_rgb;
MenuVisible = 1;
MenuSection = SC_CRACKER2;
MenuVisible = 0;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 1.0f;
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/elements/BIZRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ void Element::Element_BIZRS()
Identifier = "DEFAULT_PT_BIZRS";
Name = "BIZS";
Colour = 0x00E455_rgb;
MenuVisible = 1;
MenuSection = SC_CRACKER2;
MenuVisible = 0;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/E116.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void Element::Element_E116()
Name = "EQVE";
Colour = 0xFFE0A0_rgb;
MenuVisible = 0;
MenuSection = SC_CRACKER2;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.7f;
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/elements/FRZW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ void Element::Element_FRZW()
Identifier = "DEFAULT_PT_FRZW";
Name = "FRZW";
Colour = 0x1020C0_rgb;
MenuVisible = 1;
MenuSection = SC_CRACKER2;
MenuVisible = 0;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.6f;
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/elements/LOLZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ void Element::Element_LOLZ()
Identifier = "DEFAULT_PT_LOLZ";
Name = "LOLZ";
Colour = 0x569212_rgb;
MenuVisible = 1;
MenuSection = SC_CRACKER2;
MenuVisible = 0;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/elements/LOVE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ void Element::Element_LOVE()
Identifier = "DEFAULT_PT_LOVE";
Name = "LOVE";
Colour = 0xFF30FF_rgb;
MenuVisible = 1;
MenuSection = SC_CRACKER2;
MenuVisible = 0;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/elements/MORT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ void Element::Element_MORT()
Identifier = "DEFAULT_PT_MORT";
Name = "MORT";
Colour = 0xE0E0E0_rgb;
MenuVisible = 1;
MenuSection = SC_CRACKER2;
MenuVisible = 0;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/PSTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void Element::Element_PSTS()
Name = "PSTS";
Colour = 0x776677_rgb;
MenuVisible = 0;
MenuSection = SC_CRACKER;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/SHLD2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void Element::Element_SHLD2()
Name = "SHD2";
Colour = 0x777777_rgb;
MenuVisible = 0;
MenuSection = SC_CRACKER2;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/SHLD3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void Element::Element_SHLD3()
Name = "SHD3";
Colour = 0x444444_rgb;
MenuVisible = 0;
MenuSection = SC_CRACKER2;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/SHLD4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void Element::Element_SHLD4()
Name = "SHD4";
Colour = 0x212121_rgb;
MenuVisible = 0;
MenuSection = SC_CRACKER2;
MenuSection = SC_SPECIAL;
Enabled = 1;

Advection = 0.0f;
Expand Down

0 comments on commit 4179155

Please sign in to comment.