Move EventTypes inside LuaEvents to prevent global scope pollution

This commit is contained in:
Tamás Bálint Misius
2018-11-16 21:57:02 +01:00
committed by jacob1
parent a8489ba6f5
commit 531229daa9
5 changed files with 30 additions and 30 deletions

View File

@@ -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) 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 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 && y<YRES && x<XRES && !gameView->GetPlacingSave() && !gameView->GetPlacingZoom()) if (ret && y<YRES && x<XRES && !gameView->GetPlacingSave() && !gameView->GetPlacingZoom())
{ {
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y)); 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 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) if (type)
return ret; return ret;
if (ret && foundSignID != -1 && y<YRES && x<XRES && !gameView->GetPlacingSave()) if (ret && foundSignID != -1 && y<YRES && x<XRES && !gameView->GetPlacingSave())
@@ -707,17 +707,17 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
bool GameController::MouseWheel(int x, int y, int d) 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) 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 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) if (repeat)
return ret; return ret;
if (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 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) if (repeat)
return ret; return ret;
if (ret) if (ret)

View File

@@ -26,7 +26,7 @@ public:
virtual void OnTick() { } 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 int Command(String command);
virtual String FormatCommand(String command); virtual String FormatCommand(String command);

View File

@@ -98,6 +98,9 @@ public:
int PushToStack(lua_State *l) override { return 0; } int PushToStack(lua_State *l) override { return 0; }
}; };
class LuaEvents
{
public:
enum EventTypes { enum EventTypes {
keypress, keypress,
keyrelease, keyrelease,
@@ -109,9 +112,6 @@ enum EventTypes {
tick tick
}; };
class LuaEvents
{
public:
static int RegisterEventHook(lua_State* l, ByteString eventName); static int RegisterEventHook(lua_State* l, ByteString eventName);
static int UnregisterEventHook(lua_State* l, ByteString eventName); static int UnregisterEventHook(lua_State* l, ByteString eventName);
static bool HandleEvent(LuaScriptInterface * luacon_ci, Event * event, ByteString eventName); static bool HandleEvent(LuaScriptInterface * luacon_ci, Event * event, ByteString eventName);

View File

@@ -3303,14 +3303,14 @@ void LuaScriptInterface::initEventAPI()
lua_getglobal(l, "event"); lua_getglobal(l, "event");
lua_setglobal(l, "evt"); lua_setglobal(l, "evt");
lua_pushinteger(l, EventTypes::keypress); lua_setfield(l, -2, "keypress"); lua_pushinteger(l, LuaEvents::keypress); lua_setfield(l, -2, "keypress");
lua_pushinteger(l, EventTypes::keyrelease); lua_setfield(l, -2, "keyrelease"); lua_pushinteger(l, LuaEvents::keyrelease); lua_setfield(l, -2, "keyrelease");
lua_pushinteger(l, EventTypes::textinput); lua_setfield(l, -2, "textinput"); lua_pushinteger(l, LuaEvents::textinput); lua_setfield(l, -2, "textinput");
lua_pushinteger(l, EventTypes::mousedown); lua_setfield(l, -2, "mousedown"); lua_pushinteger(l, LuaEvents::mousedown); lua_setfield(l, -2, "mousedown");
lua_pushinteger(l, EventTypes::mouseup); lua_setfield(l, -2, "mouseup"); lua_pushinteger(l, LuaEvents::mouseup); lua_setfield(l, -2, "mouseup");
lua_pushinteger(l, EventTypes::mousemove); lua_setfield(l, -2, "mousemove"); lua_pushinteger(l, LuaEvents::mousemove); lua_setfield(l, -2, "mousemove");
lua_pushinteger(l, EventTypes::mousewheel); lua_setfield(l, -2, "mousewheel"); lua_pushinteger(l, LuaEvents::mousewheel); lua_setfield(l, -2, "mousewheel");
lua_pushinteger(l, EventTypes::tick); lua_setfield(l, -2, "tick"); lua_pushinteger(l, LuaEvents::tick); lua_setfield(l, -2, "tick");
} }
int LuaScriptInterface::event_register(lua_State * l) int LuaScriptInterface::event_register(lua_State * l)
@@ -3335,7 +3335,7 @@ int LuaScriptInterface::event_getmodifiers(lua_State * l)
return 1; 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)); return LuaEvents::HandleEvent(this, event, ByteString::Build("tptevents-", eventType));
} }
@@ -3349,7 +3349,7 @@ void LuaScriptInterface::OnTick()
lua_setfield(l, -2, "NUM_PARTS"); lua_setfield(l, -2, "NUM_PARTS");
} }
lua_pop(l, 1); lua_pop(l, 1);
HandleEvent(EventTypes::tick, new TickEvent()); HandleEvent(LuaEvents::tick, new TickEvent());
} }
int LuaScriptInterface::Command(String command) int LuaScriptInterface::Command(String command)

View File

@@ -186,7 +186,7 @@ public:
LuaScriptInterface(GameController * c, GameModel * m); LuaScriptInterface(GameController * c, GameModel * m);
virtual void OnTick(); virtual void OnTick();
virtual bool HandleEvent(EventTypes eventType, Event * event); virtual bool HandleEvent(LuaEvents::EventTypes eventType, Event * event);
virtual void Init(); virtual void Init();
virtual void SetWindow(ui::Window * window); virtual void SetWindow(ui::Window * window);