1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

Add support for suppressing game actions from being handled, minor changes to actions

This allows to e.g. prevent ACTION_TOGGLEHELPSCREEN from being handled by
the game, and instead use a node's catch action functionality to handle the event.

Add related Lua functions:
- setIgnoreAction()
- isIgnoreAction()
- sendAction()
This commit is contained in:
fgenesis 2013-07-11 23:49:39 +02:00
parent 9e66c4cd69
commit 3ad6eedd37
7 changed files with 71 additions and 13 deletions

View file

@ -4508,6 +4508,9 @@ Vector Avatar::getVectorToCursor(bool trueMouse)
void Avatar::action(int id, int state)
{
if(dsq->game->isIgnoreAction((AquariaActions)id))
return;
if (id == ACTION_PRIMARY) { if (state) lmbd(); else lmbu(); }
if (id == ACTION_SECONDARY) { if (state) rmbd(); else rmbu(); }

View file

@ -96,6 +96,9 @@ enum AquariaActions
ACTION_FOODRIGHT,
ACTION_FOODDROP,
ACTION_TOGGLEMENU,
ACTION_SWIMUP = 100,
ACTION_SWIMDOWN,

View file

@ -3939,7 +3939,7 @@ void Game::createInGameMenu()
menu[8]->useSound("Click");
menu[8]->position = Vector(400+60, 350);
menu[9]->event.set(MakeFunctionEvent(Game, onToggleHelpScreen));
menu[9]->event.set(MakeFunctionEvent(Game, toggleHelpScreen));
menu[9]->useQuad("gui/icon-help");
menu[9]->useGlow("particles/glow", gs, gs);
menu[9]->useSound("Click");
@ -5846,6 +5846,9 @@ void Game::action(int id, int state)
}
}
if(isIgnoreAction((AquariaActions)id))
return;
if (id == ACTION_TOGGLEHELPSCREEN && !state)
{
onToggleHelpScreen();
@ -5853,6 +5856,13 @@ void Game::action(int id, int state)
}
if (id == ACTION_ESC && !state) onPressEscape();
if (id == ACTION_PRIMARY && !state) onLeftMouseButton();
if (id == ACTION_TOGGLEMENU)
{
if(state)
showInGameMenu();
else
hideInGameMenu();
}
if (id == ACTION_TOGGLEWORLDMAP && !state)
{
if (foodMenu)
@ -6129,6 +6139,8 @@ void Game::applyState()
dsq->resetLayerPasses();
ignoredActions.clear();
cameraLerpDelay = 0;
playingSongInMenu = -1;
sceneColor2 = Vector(1,1,1);
@ -7825,7 +7837,7 @@ void Game::toggleHelpScreen(bool on, const std::string &label)
helpCancel->position = Vector(750, 600-20);
helpCancel->followCamera = 1;
//helpCancel->rotation.z = 90;
helpCancel->event.set(MakeFunctionEvent(Game, onToggleHelpScreen));
helpCancel->event.set(MakeFunctionEvent(Game, toggleHelpScreen));
helpCancel->scale = Vector(0.9, 0.9);
helpCancel->guiInputLevel = 100;
addRenderObject(helpCancel, LR_HELP);
@ -7978,7 +7990,7 @@ void Game::onPressEscape()
if (optionsMenu || keyConfigMenu)
onOptionsCancel();
else
hideInGameMenu();
action(ACTION_TOGGLEMENU, 0); // hide menu
}
}
return;
@ -7987,7 +7999,7 @@ void Game::onPressEscape()
if (!paused)
{
if (core->getNestedMains() == 1 && !core->isStateJumpPending())
showInGameMenu();
action(ACTION_TOGGLEMENU, 1); // show menu
}
else
{
@ -10991,4 +11003,15 @@ void Game::learnedRecipe(Recipe *r, bool effects)
}
}
void Game::setIgnoreAction(AquariaActions ac, bool ignore)
{
if (ignore)
ignoredActions.insert(ac);
else
ignoredActions.erase(ac);
}
bool Game::isIgnoreAction(AquariaActions ac) const
{
return ignoredActions.find(ac) != ignoredActions.end();
}

View file

@ -1001,14 +1001,19 @@ public:
void enqueuePreviewRecipe();
void toggleHelpScreen(bool on, const std::string &label="");
void onToggleHelpScreen();
void toggleHelpScreen() { action(ACTION_TOGGLEHELPSCREEN, 0); }
void setWorldPaused(bool b) { worldPaused = b; }
bool isWorldPaused() const { return worldPaused; }
void setIgnoreAction(AquariaActions ac, bool ignore);
bool isIgnoreAction(AquariaActions ac) const;
protected:
void toggleHelpScreen(bool on, const std::string &label="");
void onToggleHelpScreen();
void onHelpUp();
void onHelpDown();
bool helpWasPaused;
@ -1181,9 +1186,6 @@ protected:
void toggleSceneEditor();
#endif
signed char grid[MAX_GRID][MAX_GRID];
@ -1197,10 +1199,10 @@ protected:
std::string selectedChoice;
void warpCameraTo(Vector position);
std::set<int> ignoredActions;
private:
Ingredients ingredients;
};

View file

@ -357,7 +357,7 @@ void MiniMapRender::onUpdate(float dt)
{
doubleClickDelay = 0;
if (!core->isStateJumpPending())
dsq->game->showInGameMenu();
dsq->game->action(ACTION_TOGGLEMENU, 1);
btn = true;
}
break;

View file

@ -1673,6 +1673,30 @@ luaFunc(debugBreak)
luaReturnNil();
}
luaFunc(setIgnoreAction)
{
dsq->game->setIgnoreAction((AquariaActions)lua_tointeger(L, 1), getBool(L, 2));
luaReturnNil();
}
luaFunc(isIgnoreAction)
{
luaReturnBool(dsq->game->isIgnoreAction((AquariaActions)lua_tointeger(L, 1)));
}
luaFunc(sendAction)
{
AquariaActions ac = (AquariaActions)lua_tointeger(L, 1);
int state = lua_tointeger(L, 2);
int mask = lua_tointeger(L, 3);
if(!mask)
mask = -1;
if(mask & 1)
dsq->game->action(ac, state);
if((mask & 2) && dsq->game->avatar)
dsq->game->avatar->action(ac, state);
luaReturnNil();
}
luaFunc(randRange)
{
@ -8044,6 +8068,9 @@ static const struct {
{"loadfile", l_loadfile_caseinsensitive},
luaRegister(debugBreak),
luaRegister(setIgnoreAction),
luaRegister(isIgnoreAction),
luaRegister(sendAction),
luaRegister(shakeCamera),
luaRegister(upgradeHealth),

View file

@ -865,7 +865,7 @@ WorldMapRender::WorldMapRender() : RenderObject(), ActionMapper()
void WorldMapRender::onToggleHelpScreen()
{
game->onToggleHelpScreen();
game->toggleHelpScreen();
}
void WorldMapRender::bindInput()