mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 14:28:30 +01:00
Expose SDL button codes to Lua
Also sanitize GameController mouse up reason and related code.
This commit is contained in:
parent
059697aba0
commit
8763d6e75f
@ -544,11 +544,11 @@ bool GameController::MouseDown(int x, int y, unsigned button)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool GameController::MouseUp(int x, int y, unsigned button, char type)
|
||||
bool GameController::MouseUp(int x, int y, unsigned button, MouseupReason reason)
|
||||
{
|
||||
MouseUpEvent ev(x, y, button, type);
|
||||
MouseUpEvent ev(x, y, button, reason);
|
||||
bool ret = commandInterface->HandleEvent(LuaEvents::mouseup, &ev);
|
||||
if (type)
|
||||
if (reason != mouseUpNormal)
|
||||
return ret;
|
||||
if (ret && foundSignID != -1 && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
||||
{
|
||||
@ -764,7 +764,7 @@ void GameController::Tick()
|
||||
void GameController::Blur()
|
||||
{
|
||||
// Tell lua that mouse is up (even if it really isn't)
|
||||
MouseUp(0, 0, 0, 1);
|
||||
MouseUp(0, 0, 0, mouseUpBlur);
|
||||
BlurEvent ev;
|
||||
commandInterface->HandleEvent(LuaEvents::blur, &ev);
|
||||
}
|
||||
|
@ -58,6 +58,13 @@ private:
|
||||
|
||||
void OpenSaveDone();
|
||||
public:
|
||||
enum MouseupReason
|
||||
{
|
||||
mouseUpNormal,
|
||||
mouseUpBlur,
|
||||
mouseUpDrawEnd,
|
||||
};
|
||||
|
||||
bool HasDone;
|
||||
GameController();
|
||||
~GameController();
|
||||
@ -68,7 +75,7 @@ public:
|
||||
|
||||
bool MouseMove(int x, int y, int dx, int dy);
|
||||
bool MouseDown(int x, int y, unsigned button);
|
||||
bool MouseUp(int x, int y, unsigned button, char type);
|
||||
bool MouseUp(int x, int y, unsigned button, MouseupReason reason);
|
||||
bool MouseWheel(int x, int y, int d);
|
||||
bool TextInput(String text);
|
||||
bool TextEditing(String text);
|
||||
|
@ -1067,7 +1067,7 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
|
||||
{
|
||||
isMouseDown = false;
|
||||
drawMode = DrawPoints;
|
||||
c->MouseUp(x, y, 0, 2);
|
||||
c->MouseUp(x, y, 0, GameController::mouseUpDrawEnd);
|
||||
}
|
||||
}
|
||||
mouseInZoom = newMouseInZoom;
|
||||
@ -1748,7 +1748,7 @@ void GameView::DoMouseDown(int x, int y, unsigned button)
|
||||
|
||||
void GameView::DoMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
if(c->MouseUp(x, y, button, 0))
|
||||
if(c->MouseUp(x, y, button, GameController::mouseUpNormal))
|
||||
Window::DoMouseUp(x, y, button);
|
||||
}
|
||||
|
||||
|
@ -510,6 +510,11 @@ static void initLuaSDLKeys(lua_State *l)
|
||||
SETCONST(l, KMOD_SHIFT);
|
||||
SETCONST(l, KMOD_ALT);
|
||||
SETCONST(l, KMOD_GUI);
|
||||
SETCONST(l, SDL_BUTTON_LEFT);
|
||||
SETCONST(l, SDL_BUTTON_MIDDLE);
|
||||
SETCONST(l, SDL_BUTTON_RIGHT);
|
||||
SETCONST(l, SDL_BUTTON_X1);
|
||||
SETCONST(l, SDL_BUTTON_X2);
|
||||
}
|
||||
|
||||
#undef SETCONST
|
||||
|
@ -518,6 +518,9 @@ void LuaScriptInterface::initInterfaceAPI()
|
||||
//Ren shortcut
|
||||
lua_getglobal(l, "interface");
|
||||
initLuaSDLKeys(l);
|
||||
lua_pushinteger(l, GameController::mouseUpNormal); lua_setfield(l, -2, "MOUSE_UP_NORMAL");
|
||||
lua_pushinteger(l, GameController::mouseUpBlur); lua_setfield(l, -2, "MOUSE_UP_BLUR");
|
||||
lua_pushinteger(l, GameController::mouseUpDrawEnd); lua_setfield(l, -2, "MOUSE_UP_DRAW_END");
|
||||
lua_setglobal(l, "ui");
|
||||
|
||||
Luna<LuaWindow>::Register(l);
|
||||
|
Loading…
x
Reference in New Issue
Block a user