CommandInterface, Mouse, Keyboard and Tick events, on screen log, print redirected to tpt.log
This commit is contained in:
parent
299c1da9ae
commit
89cdeef9ad
@ -33,7 +33,7 @@ std::string CommandInterface::FormatCommand(std::string command)
|
|||||||
|
|
||||||
void CommandInterface::Log(LogType type, std::string message)
|
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)
|
int CommandInterface::GetPropertyOffset(std::string key_, FormatType & format)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define KITTY_H_
|
#define KITTY_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
//#include "game/GameModel.h"
|
//#include "game/GameModel.h"
|
||||||
|
|
||||||
class GameModel;
|
class GameModel;
|
||||||
@ -24,7 +25,13 @@ public:
|
|||||||
int GetParticleType(std::string type);
|
int GetParticleType(std::string type);
|
||||||
void Log(LogType type, std::string message);
|
void Log(LogType type, std::string message);
|
||||||
//void AttachGameModel(GameModel * m);
|
//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 int Command(std::string command);
|
||||||
virtual std::string FormatCommand(std::string command);
|
virtual std::string FormatCommand(std::string command);
|
||||||
std::string GetLastError();
|
std::string GetLastError();
|
||||||
|
@ -84,6 +84,12 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m):
|
|||||||
|
|
||||||
l = lua_open();
|
l = lua_open();
|
||||||
luaL_openlibs(l);
|
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);
|
luaL_register(l, "tpt", tptluaapi);
|
||||||
|
|
||||||
tptProperties = lua_gettop(l);
|
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)
|
int LuaScriptInterface::Command(std::string command)
|
||||||
@ -753,7 +796,7 @@ int luacon_step(int mx, int my, int selectl, int selectr){
|
|||||||
if (callret)
|
if (callret)
|
||||||
{
|
{
|
||||||
// failed, TODO: better error reporting
|
// failed, TODO: better error reporting
|
||||||
printf("%s\n",luacon_geterror());
|
luacon_ci->Log(CommandInterface::LogError, luacon_geterror());//("%s\n",luacon_geterror());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,18 @@ extern "C"
|
|||||||
#define LUACON_EL_MODIFIED_MENUS 0x4
|
#define LUACON_EL_MODIFIED_MENUS 0x4
|
||||||
|
|
||||||
class LuaScriptInterface: public CommandInterface {
|
class LuaScriptInterface: public CommandInterface {
|
||||||
|
int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton;
|
||||||
|
bool luacon_mousedown;
|
||||||
public:
|
public:
|
||||||
lua_State *l;
|
lua_State *l;
|
||||||
LuaScriptInterface(GameModel * m);
|
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 int Command(std::string command);
|
||||||
virtual std::string FormatCommand(std::string command);
|
virtual std::string FormatCommand(std::string command);
|
||||||
virtual ~LuaScriptInterface();
|
virtual ~LuaScriptInterface();
|
||||||
|
@ -303,8 +303,39 @@ void GameController::CopyRegion(ui::Point point1, ui::Point point2)
|
|||||||
gameModel->SetClipboard(saveData, saveSize);
|
gameModel->SetClipboard(saveData, saveSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GameController::MouseMove(int x, int y, int dx, int dy)
|
||||||
|
{
|
||||||
|
return commandInterface->OnMouseMove(x, y, dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameController::MouseDown(int x, int y, unsigned button)
|
||||||
|
{
|
||||||
|
return commandInterface->OnMouseDown(x, y, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameController::MouseUp(int x, int y, unsigned button)
|
||||||
|
{
|
||||||
|
return commandInterface->OnMouseUp(x, y, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameController::MouseWheel(int x, int y, int d)
|
||||||
|
{
|
||||||
|
return commandInterface->OnMouseWheel(x, y, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
return commandInterface->OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
return commandInterface->OnKeyRelease(key, character, shift, ctrl, alt);
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::Update()
|
void GameController::Update()
|
||||||
{
|
{
|
||||||
|
commandInterface->OnTick(1.0f);
|
||||||
gameModel->GetSimulation()->update_particles();
|
gameModel->GetSimulation()->update_particles();
|
||||||
if(renderOptions && renderOptions->HasExited)
|
if(renderOptions && renderOptions->HasExited)
|
||||||
{
|
{
|
||||||
|
@ -47,6 +47,14 @@ public:
|
|||||||
GameController();
|
GameController();
|
||||||
~GameController();
|
~GameController();
|
||||||
GameView * GetView();
|
GameView * GetView();
|
||||||
|
|
||||||
|
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);
|
||||||
|
bool MouseWheel(int x, int y, int d);
|
||||||
|
bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
void SetZoomEnabled(bool zoomEnable);
|
void SetZoomEnabled(bool zoomEnable);
|
||||||
void SetZoomPosition(ui::Point position);
|
void SetZoomPosition(ui::Point position);
|
||||||
void AdjustBrushSize(int direction);
|
void AdjustBrushSize(int direction);
|
||||||
|
@ -457,6 +457,19 @@ void GameModel::SetStamp(Save * newStamp)
|
|||||||
notifyStampChanged();
|
notifyStampChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameModel::Log(string message)
|
||||||
|
{
|
||||||
|
consoleLog.push_front(message);
|
||||||
|
if(consoleLog.size()>100)
|
||||||
|
consoleLog.pop_back();
|
||||||
|
notifyLogChanged(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
deque<string> GameModel::GetLog()
|
||||||
|
{
|
||||||
|
return consoleLog;
|
||||||
|
}
|
||||||
|
|
||||||
void GameModel::notifyColourSelectorColourChanged()
|
void GameModel::notifyColourSelectorColourChanged()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < observers.size(); i++)
|
for(int i = 0; i < observers.size(); i++)
|
||||||
@ -576,3 +589,11 @@ void GameModel::notifyClipboardChanged()
|
|||||||
observers[i]->NotifyClipboardChanged(this);
|
observers[i]->NotifyClipboardChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameModel::notifyLogChanged(string entry)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifyLogChanged(this, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define GAMEMODEL_H
|
#define GAMEMODEL_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
#include "search/Save.h"
|
#include "search/Save.h"
|
||||||
#include "simulation/Simulation.h"
|
#include "simulation/Simulation.h"
|
||||||
#include "interface/Colour.h"
|
#include "interface/Colour.h"
|
||||||
@ -35,6 +36,7 @@ private:
|
|||||||
//unsigned char * clipboardData;
|
//unsigned char * clipboardData;
|
||||||
Save * stamp;
|
Save * stamp;
|
||||||
Save * clipboard;
|
Save * clipboard;
|
||||||
|
deque<string> consoleLog;
|
||||||
vector<GameView*> observers;
|
vector<GameView*> observers;
|
||||||
vector<Tool*> toolList;
|
vector<Tool*> toolList;
|
||||||
vector<Menu*> menuList;
|
vector<Menu*> menuList;
|
||||||
@ -64,6 +66,7 @@ private:
|
|||||||
void notifyStampChanged();
|
void notifyStampChanged();
|
||||||
void notifyColourSelectorColourChanged();
|
void notifyColourSelectorColourChanged();
|
||||||
void notifyColourSelectorVisibilityChanged();
|
void notifyColourSelectorVisibilityChanged();
|
||||||
|
void notifyLogChanged(string entry);
|
||||||
public:
|
public:
|
||||||
GameModel();
|
GameModel();
|
||||||
~GameModel();
|
~GameModel();
|
||||||
@ -110,6 +113,8 @@ public:
|
|||||||
void SetStamp(Save * newStamp);
|
void SetStamp(Save * newStamp);
|
||||||
void AddStamp(unsigned char * saveData, int saveSize);
|
void AddStamp(unsigned char * saveData, int saveSize);
|
||||||
void SetClipboard(unsigned char * saveData, int saveSize);
|
void SetClipboard(unsigned char * saveData, int saveSize);
|
||||||
|
void Log(string message);
|
||||||
|
deque<string> GetLog();
|
||||||
Save * GetClipboard();
|
Save * GetClipboard();
|
||||||
Save * GetStamp();
|
Save * GetStamp();
|
||||||
};
|
};
|
||||||
|
@ -741,11 +741,55 @@ void GameView::OnTick(float dt)
|
|||||||
c->Update();
|
c->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::DoMouseMove(int x, int y, int dx, int dy)
|
||||||
|
{
|
||||||
|
if(c->MouseMove(x, y, dx, dy))
|
||||||
|
Window::DoMouseMove(x, y, dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::DoMouseDown(int x, int y, unsigned button)
|
||||||
|
{
|
||||||
|
if(c->MouseDown(x, y, button))
|
||||||
|
Window::DoMouseDown(x, y, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::DoMouseUp(int x, int y, unsigned button)
|
||||||
|
{
|
||||||
|
if(c->MouseUp(x, y, button))
|
||||||
|
Window::DoMouseUp(x, y, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::DoMouseWheel(int x, int y, int d)
|
||||||
|
{
|
||||||
|
if(c->MouseWheel(x, y, d))
|
||||||
|
Window::DoMouseWheel(x, y, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
if(c->KeyPress(key, character, shift, ctrl, alt))
|
||||||
|
Window::DoKeyPress(key, character, shift, ctrl, alt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
if(c->KeyRelease(key, character, shift, ctrl, alt))
|
||||||
|
Window::DoKeyRelease(key, character, shift, ctrl, alt);
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::NotifyZoomChanged(GameModel * sender)
|
void GameView::NotifyZoomChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
zoomEnabled = sender->GetZoomEnabled();
|
zoomEnabled = sender->GetZoomEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::NotifyLogChanged(GameModel * sender, string entry)
|
||||||
|
{
|
||||||
|
logEntries.push_front(entry);
|
||||||
|
lastLogEntry = 100.0f;
|
||||||
|
if(logEntries.size()>10)
|
||||||
|
logEntries.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::NotifyClipboardChanged(GameModel * sender)
|
void GameView::NotifyClipboardChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
if(clipboardThumb)
|
if(clipboardThumb)
|
||||||
@ -853,5 +897,19 @@ void GameView::OnDraw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int startX = 20;
|
||||||
|
int startY = YRES-20;
|
||||||
|
if(lastLogEntry>0.1 && logEntries.size())
|
||||||
|
{
|
||||||
|
deque<string>::iterator iter;
|
||||||
|
for(iter = logEntries.begin(); iter != logEntries.end(); iter++)
|
||||||
|
{
|
||||||
|
string message = (*iter);
|
||||||
|
startY -= 14;
|
||||||
|
g->fillrect(startX-3, startY-3, Graphics::textwidth((char*)message.c_str())+6, 14, 0, 0, 0, 100);
|
||||||
|
g->drawtext(startX, startY, message.c_str(), 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <deque>
|
||||||
|
#include <string>
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
#include "GameModel.h"
|
#include "GameModel.h"
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
@ -41,6 +43,8 @@ private:
|
|||||||
//UI Elements
|
//UI Elements
|
||||||
vector<ui::Button*> menuButtons;
|
vector<ui::Button*> menuButtons;
|
||||||
vector<ToolButton*> toolButtons;
|
vector<ToolButton*> toolButtons;
|
||||||
|
deque<string> logEntries;
|
||||||
|
float lastLogEntry;
|
||||||
ui::Button * searchButton;
|
ui::Button * searchButton;
|
||||||
ui::Button * reloadButton;
|
ui::Button * reloadButton;
|
||||||
ui::Button * saveSimulationButton;
|
ui::Button * saveSimulationButton;
|
||||||
@ -88,12 +92,22 @@ public:
|
|||||||
void NotifyColourSelectorColourChanged(GameModel * sender);
|
void NotifyColourSelectorColourChanged(GameModel * sender);
|
||||||
void NotifyClipboardChanged(GameModel * sender);
|
void NotifyClipboardChanged(GameModel * sender);
|
||||||
void NotifyStampChanged(GameModel * sender);
|
void NotifyStampChanged(GameModel * sender);
|
||||||
|
void NotifyLogChanged(GameModel * sender, string entry);
|
||||||
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
virtual void OnMouseUp(int x, int y, unsigned button);
|
virtual void OnMouseUp(int x, int y, unsigned button);
|
||||||
virtual void OnMouseWheel(int x, int y, int d);
|
virtual void OnMouseWheel(int x, int y, int d);
|
||||||
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
|
//Top-level handers, for Lua interface
|
||||||
|
virtual void DoMouseMove(int x, int y, int dx, int dy);
|
||||||
|
virtual void DoMouseDown(int x, int y, unsigned button);
|
||||||
|
virtual void DoMouseUp(int x, int y, unsigned button);
|
||||||
|
virtual void DoMouseWheel(int x, int y, int d);
|
||||||
|
virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
virtual void DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
//virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
|
//virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
|
||||||
//virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
|
//virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
|
||||||
virtual void OnTick(float dt);
|
virtual void OnTick(float dt);
|
||||||
|
Loading…
Reference in New Issue
Block a user