From 06d3e8182d018ca613f177f6ff7a3bbb6494cc79 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 28 May 2018 17:07:04 -0400 Subject: Various additions Various additions, updates, and bugfixes while making mahjong solitare. --- src/client/callbackhandeler.cpp | 70 +++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 9 deletions(-) (limited to 'src/client/callbackhandeler.cpp') diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp index cf24cd2..fc44cbc 100644 --- a/src/client/callbackhandeler.cpp +++ b/src/client/callbackhandeler.cpp @@ -40,6 +40,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ bool callerregistered = guifuncs.find(caller) != guifuncs.end(); bool callerhasfunc = guifuncs[caller].find(get) != guifuncs[caller].end(); if (callerregistered && callerhasfunc){ + printf("Found a callback for this event\n"); return guifuncs[caller][get](e); } return false; @@ -49,16 +50,67 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ SEvent::SMouseInput se = e.MouseInput; //printf("X: %d Y: %d\n",se.X, se.Y); - lua_getglobal(L,"GAME");//{} - lua_getfield(L,-1,"onMouseMove");//{},onMouseMove() - if(!lua_isnil(L,-1)){ - lua_pushnumber(L,se.X); - lua_pushnumber(L,se.Y); - lua_call(L,2,0); - lua_pop(L,1); - }else{ - lua_pop(L,2); + switch(se.Event){ + case EMIE_MOUSE_MOVED:{ + lua_getglobal(L,"GAME");//{} + lua_getfield(L,-1,"onMouseMove");//{},onMouseMove() + if(!lua_isnil(L,-1)){ + lua_pushnumber(L,se.X); + lua_pushnumber(L,se.Y); + lua_call(L,2,0); + lua_pop(L,1); + }else{ + lua_pop(L,2); + } + break; } + case EMIE_LMOUSE_PRESSED_DOWN: + case EMIE_RMOUSE_PRESSED_DOWN: + case EMIE_MMOUSE_PRESSED_DOWN:{ + lua_getglobal(L,"GAME"); + lua_getfield(L,-1,"onMouseDown"); + if(!lua_isnil(L,-1)){ + lua_pushnumber(L,se.X); + lua_pushnumber(L,se.Y); + lua_pushnumber(L,se.Event); + lua_call(L,3,0); + lua_pop(L,1); + }else{ + lua_pop(L,2); + } + break; + } + case EMIE_LMOUSE_LEFT_UP: + case EMIE_RMOUSE_LEFT_UP: + case EMIE_MMOUSE_LEFT_UP:{ + lua_getglobal(L,"GAME"); + lua_getfield(L,-1,"onMouseUp"); + if(!lua_isnil(L,-1)){ + lua_pushnumber(L,se.X); + lua_pushnumber(L,se.Y); + lua_pushnumber(L,se.Event); + lua_call(L,3,0); + lua_pop(L,1); + }else{ + lua_pop(L,2); + } + break; + } + case EMIE_MOUSE_WHEEL:{ + lua_getglobal(L,"GAME"); + lua_getfield(L,-1,"onMouseWheel"); + if(!lua_isnil(L,-1)){ + lua_pushnumber(L,se.X); + lua_pushnumber(L,se.Y); + lua_pushnumber(L,se.Wheel); + lua_call(L,3,0); + lua_pop(L,1); + }else{ + lua_pop(L,2); + } + } + } + break; } case EET_KEY_INPUT_EVENT:{ -- cgit v1.2.3-70-g09d2