diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 0cbb2e48e..8bc4e525f 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -622,12 +622,12 @@ void GameController::CutRegion(ui::Point point1, ui::Point point2, bool includeP bool GameController::MouseMove(int x, int y, int dx, int dy) { - return commandInterface->HandleEvent(EventTypes::mousemove, new MouseMoveEvent(x, y, dx, dy)); + return commandInterface->HandleEvent(LuaEvents::mousemove, new MouseMoveEvent(x, y, dx, dy)); } bool GameController::MouseDown(int x, int y, unsigned button) { - bool ret = commandInterface->HandleEvent(EventTypes::mousedown, new MouseDownEvent(x, y, button)); + bool ret = commandInterface->HandleEvent(LuaEvents::mousedown, new MouseDownEvent(x, y, button)); if (ret && yGetPlacingSave() && !gameView->GetPlacingZoom()) { ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y)); @@ -649,7 +649,7 @@ bool GameController::MouseDown(int x, int y, unsigned button) bool GameController::MouseUp(int x, int y, unsigned button, char type) { - bool ret = commandInterface->HandleEvent(EventTypes::mouseup, new MouseUpEvent(x, y, button, type)); + bool ret = commandInterface->HandleEvent(LuaEvents::mouseup, new MouseUpEvent(x, y, button, type)); if (type) return ret; if (ret && foundSignID != -1 && yGetPlacingSave()) @@ -707,17 +707,17 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type) bool GameController::MouseWheel(int x, int y, int d) { - return commandInterface->HandleEvent(EventTypes::mousewheel, new MouseWheelEvent(x, y, d)); + return commandInterface->HandleEvent(LuaEvents::mousewheel, new MouseWheelEvent(x, y, d)); } bool GameController::TextInput(String text) { - return commandInterface->HandleEvent(EventTypes::textinput, new TextInputEvent(text)); + return commandInterface->HandleEvent(LuaEvents::textinput, new TextInputEvent(text)); } bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - bool ret = commandInterface->HandleEvent(EventTypes::keypress, new KeyEvent(key, scan, repeat, shift, ctrl, alt)); + bool ret = commandInterface->HandleEvent(LuaEvents::keypress, new KeyEvent(key, scan, repeat, shift, ctrl, alt)); if (repeat) return ret; if (ret) @@ -796,7 +796,7 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c bool GameController::KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - bool ret = commandInterface->HandleEvent(EventTypes::keyrelease, new KeyEvent(key, scan, repeat, shift, ctrl, alt)); + bool ret = commandInterface->HandleEvent(LuaEvents::keyrelease, new KeyEvent(key, scan, repeat, shift, ctrl, alt)); if (repeat) return ret; if (ret) diff --git a/src/lua/CommandInterface.h b/src/lua/CommandInterface.h index 09d338fb6..d247a28f1 100644 --- a/src/lua/CommandInterface.h +++ b/src/lua/CommandInterface.h @@ -26,7 +26,7 @@ public: virtual void OnTick() { } - virtual bool HandleEvent(EventTypes eventType, Event * event) { return true; } + virtual bool HandleEvent(LuaEvents::EventTypes eventType, Event * event) { return true; } virtual int Command(String command); virtual String FormatCommand(String command); diff --git a/src/lua/LuaEvents.h b/src/lua/LuaEvents.h index b57704893..374f937fa 100644 --- a/src/lua/LuaEvents.h +++ b/src/lua/LuaEvents.h @@ -98,20 +98,20 @@ public: int PushToStack(lua_State *l) override { return 0; } }; -enum EventTypes { - keypress, - keyrelease, - textinput, - mousedown, - mouseup, - mousemove, - mousewheel, - tick -}; - class LuaEvents { public: + enum EventTypes { + keypress, + keyrelease, + textinput, + mousedown, + mouseup, + mousemove, + mousewheel, + tick + }; + static int RegisterEventHook(lua_State* l, ByteString eventName); static int UnregisterEventHook(lua_State* l, ByteString eventName); static bool HandleEvent(LuaScriptInterface * luacon_ci, Event * event, ByteString eventName); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index d0d82e400..f99e554ad 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3303,14 +3303,14 @@ void LuaScriptInterface::initEventAPI() lua_getglobal(l, "event"); lua_setglobal(l, "evt"); - lua_pushinteger(l, EventTypes::keypress); lua_setfield(l, -2, "keypress"); - lua_pushinteger(l, EventTypes::keyrelease); lua_setfield(l, -2, "keyrelease"); - lua_pushinteger(l, EventTypes::textinput); lua_setfield(l, -2, "textinput"); - lua_pushinteger(l, EventTypes::mousedown); lua_setfield(l, -2, "mousedown"); - lua_pushinteger(l, EventTypes::mouseup); lua_setfield(l, -2, "mouseup"); - lua_pushinteger(l, EventTypes::mousemove); lua_setfield(l, -2, "mousemove"); - lua_pushinteger(l, EventTypes::mousewheel); lua_setfield(l, -2, "mousewheel"); - lua_pushinteger(l, EventTypes::tick); lua_setfield(l, -2, "tick"); + lua_pushinteger(l, LuaEvents::keypress); lua_setfield(l, -2, "keypress"); + lua_pushinteger(l, LuaEvents::keyrelease); lua_setfield(l, -2, "keyrelease"); + lua_pushinteger(l, LuaEvents::textinput); lua_setfield(l, -2, "textinput"); + lua_pushinteger(l, LuaEvents::mousedown); lua_setfield(l, -2, "mousedown"); + lua_pushinteger(l, LuaEvents::mouseup); lua_setfield(l, -2, "mouseup"); + lua_pushinteger(l, LuaEvents::mousemove); lua_setfield(l, -2, "mousemove"); + lua_pushinteger(l, LuaEvents::mousewheel); lua_setfield(l, -2, "mousewheel"); + lua_pushinteger(l, LuaEvents::tick); lua_setfield(l, -2, "tick"); } int LuaScriptInterface::event_register(lua_State * l) @@ -3335,7 +3335,7 @@ int LuaScriptInterface::event_getmodifiers(lua_State * l) return 1; } -bool LuaScriptInterface::HandleEvent(EventTypes eventType, Event * event) +bool LuaScriptInterface::HandleEvent(LuaEvents::EventTypes eventType, Event * event) { return LuaEvents::HandleEvent(this, event, ByteString::Build("tptevents-", eventType)); } @@ -3349,7 +3349,7 @@ void LuaScriptInterface::OnTick() lua_setfield(l, -2, "NUM_PARTS"); } lua_pop(l, 1); - HandleEvent(EventTypes::tick, new TickEvent()); + HandleEvent(LuaEvents::tick, new TickEvent()); } int LuaScriptInterface::Command(String command) diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index 5270720f0..040627db7 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -186,7 +186,7 @@ public: LuaScriptInterface(GameController * c, GameModel * m); virtual void OnTick(); - virtual bool HandleEvent(EventTypes eventType, Event * event); + virtual bool HandleEvent(LuaEvents::EventTypes eventType, Event * event); virtual void Init(); virtual void SetWindow(ui::Window * window);