Skip to content

Commit

Permalink
Add functions to remove GM function buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
daid committed Apr 18, 2016
1 parent c58033e commit e0f7455
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/GMScriptCallback.cpp
Expand Up @@ -27,6 +27,27 @@ static int addGMFunction(lua_State* L)
/// Or to give the GM console certain control over the scenario.
REGISTER_SCRIPT_FUNCTION(addGMFunction);

static int removeGMFunction(lua_State* L)
{
string name = luaL_checkstring(L, 1);

gameGlobalInfo->gm_callback_functions.erase(std::remove_if(gameGlobalInfo->gm_callback_functions.begin(), gameGlobalInfo->gm_callback_functions.end(), [name](const GMScriptCallback& f) { return f.name == name; }), gameGlobalInfo->gm_callback_functions.end());

return 0;
}
/// removeGMFunction(name)
/// Remove a function from the GM console
REGISTER_SCRIPT_FUNCTION(removeGMFunction);

static int clearGMFunctions(lua_State* L)
{
gameGlobalInfo->gm_callback_functions.clear();
return 0;
}
/// clearGMFunctions()
/// Remove all the GM functions from the GM console.
REGISTER_SCRIPT_FUNCTION(clearGMFunctions);

static int getGMSelection(lua_State* L)
{
PVector<SpaceObject> objects;
Expand Down
21 changes: 17 additions & 4 deletions src/screens/gm/gameMasterScreen.cpp
Expand Up @@ -90,10 +90,6 @@ GameMasterScreen::GameMasterScreen()
gm_script_options->setSelectionIndex(-1);
});
gm_script_options->setPosition(20, 130, ATopLeft)->setSize(250, 500);
for(GMScriptCallback& callback : gameGlobalInfo->gm_callback_functions)
{
gm_script_options->addEntry(callback.name, callback.name);
}

order_layout = new GuiAutoLayout(this, "ORDER_LAYOUT", GuiAutoLayout::LayoutVerticalTopToBottom);
order_layout->setPosition(20, 130, ATopLeft)->setSize(250, GuiElement::GuiSizeMax);
Expand Down Expand Up @@ -207,6 +203,23 @@ void GameMasterScreen::update(float delta)
info_items[cnt]->hide();
cnt++;
}

bool gm_functions_changed = gm_script_options->entryCount() != int(gameGlobalInfo->gm_callback_functions.size());
auto it = gameGlobalInfo->gm_callback_functions.begin();
for(int n=0; !gm_functions_changed && n<gm_script_options->entryCount(); n++)
{
if (gm_script_options->getEntryName(n) != it->name)
gm_functions_changed = true;
it++;
}
if (gm_functions_changed)
{
gm_script_options->setOptions({});
for(const GMScriptCallback& callback : gameGlobalInfo->gm_callback_functions)
{
gm_script_options->addEntry(callback.name, callback.name);
}
}
}

void GameMasterScreen::onMouseDown(sf::Vector2f position)
Expand Down

0 comments on commit e0f7455

Please sign in to comment.