diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-04 17:52:34 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-04 17:52:34 (GMT) |
| commit | 89cdeef9ad9c164e9f484cded3096bcbc72b7207 (patch) | |
| tree | 6a26f6313e7cf45a277756890e087201704bab90 /src/cat | |
| parent | 299c1da9ae6b79ddb6cc39477ad31fb1d2a3c566 (diff) | |
| download | powder-89cdeef9ad9c164e9f484cded3096bcbc72b7207.zip powder-89cdeef9ad9c164e9f484cded3096bcbc72b7207.tar.gz | |
CommandInterface, Mouse, Keyboard and Tick events, on screen log, print redirected to tpt.log
Diffstat (limited to 'src/cat')
| -rw-r--r-- | src/cat/CommandInterface.cpp | 2 | ||||
| -rw-r--r-- | src/cat/CommandInterface.h | 9 | ||||
| -rw-r--r-- | src/cat/LuaScriptInterface.cpp | 47 | ||||
| -rw-r--r-- | src/cat/LuaScriptInterface.h | 10 |
4 files changed, 63 insertions, 5 deletions
diff --git a/src/cat/CommandInterface.cpp b/src/cat/CommandInterface.cpp index f434f54..4554b9f 100644 --- a/src/cat/CommandInterface.cpp +++ b/src/cat/CommandInterface.cpp @@ -33,7 +33,7 @@ std::string CommandInterface::FormatCommand(std::string command) void CommandInterface::Log(LogType type, std::string message) { - //Todo Put this info somewhere, an on-screen log output would be nice. + m->Log(message); } int CommandInterface::GetPropertyOffset(std::string key_, FormatType & format) diff --git a/src/cat/CommandInterface.h b/src/cat/CommandInterface.h index c77d83c..8cabdab 100644 --- a/src/cat/CommandInterface.h +++ b/src/cat/CommandInterface.h @@ -9,6 +9,7 @@ #define KITTY_H_ #include <string> +#include <SDL/SDL.h> //#include "game/GameModel.h" class GameModel; @@ -24,7 +25,13 @@ public: int GetParticleType(std::string type); void Log(LogType type, std::string message); //void AttachGameModel(GameModel * m); - virtual void Tick() {} + virtual bool OnMouseMove(int x, int y, int dx, int dy) {return true;} + virtual bool OnMouseDown(int x, int y, unsigned button) {return true;} + virtual bool OnMouseUp(int x, int y, unsigned button) {return true;} + virtual bool OnMouseWheel(int x, int y, int d) {return true;} + virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;} + virtual bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;} + virtual void OnTick(float dt) {} virtual int Command(std::string command); virtual std::string FormatCommand(std::string command); std::string GetLastError(); diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index c7af155..617577b 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -84,6 +84,12 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m): l = lua_open(); luaL_openlibs(l); + + //Replace print function with our screen logging thingy + lua_pushcfunction(l, luatpt_log); + lua_setglobal(l, "print"); + + //Register all tpt functions luaL_register(l, "tpt", tptluaapi); tptProperties = lua_gettop(l); @@ -205,9 +211,46 @@ tpt.partsdata = nil"); } -void LuaScriptInterface::Tick() +bool LuaScriptInterface::OnMouseMove(int x, int y, int dx, int dy) +{ + luacon_mousex = x; + luacon_mousey = y; + return true; +} + +bool LuaScriptInterface::OnMouseDown(int x, int y, unsigned button) +{ + luacon_mousedown = true; + luacon_mousebutton = button; + return luacon_mouseevent(x, y, button, LUACON_MDOWN); +} + +bool LuaScriptInterface::OnMouseUp(int x, int y, unsigned button) { + luacon_mousedown = false; + return luacon_mouseevent(x, y, button, LUACON_MUP); +} +bool LuaScriptInterface::OnMouseWheel(int x, int y, int d) +{ + return true; +} + +bool LuaScriptInterface::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +{ + return luacon_keyevent(key, /*TODO: sdl_mod*/0, LUACON_KDOWN); +} + +bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +{ + return luacon_keyevent(key, /*TODO: sdl_mod*/0, LUACON_KUP); +} + +void LuaScriptInterface::OnTick(float dt) +{ + if(luacon_mousedown) + luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS); + luacon_step(luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr); } int LuaScriptInterface::Command(std::string command) @@ -753,7 +796,7 @@ int luacon_step(int mx, int my, int selectl, int selectr){ if (callret) { // failed, TODO: better error reporting - printf("%s\n",luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, luacon_geterror());//("%s\n",luacon_geterror()); } } } diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index 2fcfc33..b3ecd7a 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -34,10 +34,18 @@ extern "C" #define LUACON_EL_MODIFIED_MENUS 0x4 class LuaScriptInterface: public CommandInterface { + int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton; + bool luacon_mousedown; public: lua_State *l; LuaScriptInterface(GameModel * m); - virtual void Tick(); + virtual bool OnMouseMove(int x, int y, int dx, int dy); + virtual bool OnMouseDown(int x, int y, unsigned button); + virtual bool OnMouseUp(int x, int y, unsigned button); + virtual bool OnMouseWheel(int x, int y, int d); + virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnTick(float dt); virtual int Command(std::string command); virtual std::string FormatCommand(std::string command); virtual ~LuaScriptInterface(); |
