Change brush size with [ and ] keys, change order of drawing for Lua, Fix print and tpt.log so they log to the console when it is open

This commit is contained in:
Simon Robertshaw 2012-04-04 21:47:58 +01:00
parent 89cdeef9ad
commit ea51cde1f0
8 changed files with 63 additions and 18 deletions

View File

@ -31,7 +31,7 @@ public:
virtual bool OnMouseWheel(int x, int y, int d) {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 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 bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;}
virtual void OnTick(float dt) {} virtual void OnTick() {}
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();

View File

@ -13,6 +13,9 @@ Simulation * luacon_sim;
LuaScriptInterface * luacon_ci; LuaScriptInterface * luacon_ci;
Graphics * luacon_g; Graphics * luacon_g;
bool *luacon_currentCommand;
string *luacon_lastError;
int *lua_el_func, *lua_el_mode; int *lua_el_func, *lua_el_mode;
int getPartIndex_curIdx; int getPartIndex_curIdx;

View File

@ -13,7 +13,8 @@
#include "LuaScriptHelper.h" #include "LuaScriptHelper.h"
LuaScriptInterface::LuaScriptInterface(GameModel * m): LuaScriptInterface::LuaScriptInterface(GameModel * m):
CommandInterface(m) CommandInterface(m),
currentCommand(false)
{ {
int i = 0, j; int i = 0, j;
char tmpname[12]; char tmpname[12];
@ -77,6 +78,9 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m):
{NULL,NULL} {NULL,NULL}
}; };
luacon_currentCommand = &currentCommand;
luacon_lastError = &lastError;
luacon_model = m; luacon_model = m;
luacon_sim = m->GetSimulation(); luacon_sim = m->GetSimulation();
luacon_g = ui::Engine::Ref().g; luacon_g = ui::Engine::Ref().g;
@ -246,7 +250,7 @@ bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, boo
return luacon_keyevent(key, /*TODO: sdl_mod*/0, LUACON_KUP); return luacon_keyevent(key, /*TODO: sdl_mod*/0, LUACON_KUP);
} }
void LuaScriptInterface::OnTick(float dt) void LuaScriptInterface::OnTick()
{ {
if(luacon_mousedown) if(luacon_mousedown)
luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS); luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS);
@ -257,11 +261,13 @@ int LuaScriptInterface::Command(std::string command)
{ {
int ret; int ret;
lastError = ""; lastError = "";
currentCommand = true;
if((ret = luaL_dostring(l, command.c_str()))) if((ret = luaL_dostring(l, command.c_str())))
{ {
lastError = luacon_geterror(); lastError = luacon_geterror();
Log(LogError, lastError); //Log(LogError, lastError);
} }
currentCommand = false;
return ret; return ret;
} }
@ -977,6 +983,9 @@ int luatpt_setconsole(lua_State* l)
int luatpt_log(lua_State* l) int luatpt_log(lua_State* l)
{ {
if((*luacon_currentCommand) && !(*luacon_lastError).length())
(*luacon_lastError) = luaL_optstring(l, 1, "");
else
luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, 1, "")); luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, 1, ""));
return 0; return 0;
} }

View File

@ -36,6 +36,7 @@ extern "C"
class LuaScriptInterface: public CommandInterface { class LuaScriptInterface: public CommandInterface {
int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton; int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton;
bool luacon_mousedown; bool luacon_mousedown;
bool currentCommand;
public: public:
lua_State *l; lua_State *l;
LuaScriptInterface(GameModel * m); LuaScriptInterface(GameModel * m);
@ -45,7 +46,7 @@ public:
virtual bool OnMouseWheel(int x, int y, int d); virtual bool OnMouseWheel(int x, int y, int d);
virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); 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 bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
virtual void OnTick(float dt); virtual void OnTick();
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();

View File

@ -174,9 +174,13 @@ void GameController::PlaceClipboard(ui::Point position)
} }
} }
void GameController::AdjustBrushSize(int direction) void GameController::AdjustBrushSize(int direction, bool logarithmic)
{ {
ui::Point newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction, direction); ui::Point newSize(0, 0);
if(logarithmic)
newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction * ((gameModel->GetBrush()->GetRadius().X/10)>0?gameModel->GetBrush()->GetRadius().X/10:1), direction * ((gameModel->GetBrush()->GetRadius().Y/10)>0?gameModel->GetBrush()->GetRadius().Y/10:1));
else
newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction, direction);
if(newSize.X<0) if(newSize.X<0)
newSize.X = 0; newSize.X = 0;
if(newSize.Y<0) if(newSize.Y<0)
@ -184,9 +188,13 @@ void GameController::AdjustBrushSize(int direction)
gameModel->GetBrush()->SetRadius(newSize); gameModel->GetBrush()->SetRadius(newSize);
} }
void GameController::AdjustZoomSize(int direction) void GameController::AdjustZoomSize(int direction, bool logarithmic)
{ {
int newSize = gameModel->GetZoomSize()+direction; int newSize;
if(logarithmic)
newSize = gameModel->GetZoomSize()+direction;
else
newSize = gameModel->GetZoomSize()+(((gameModel->GetZoomSize()/10)>0?(gameModel->GetZoomSize()/10):1)*direction);
if(newSize<5) if(newSize<5)
newSize = 5; newSize = 5;
if(newSize>64) if(newSize>64)
@ -333,9 +341,13 @@ bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl
return commandInterface->OnKeyRelease(key, character, shift, ctrl, alt); return commandInterface->OnKeyRelease(key, character, shift, ctrl, alt);
} }
void GameController::Tick()
{
commandInterface->OnTick();
}
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)
{ {

View File

@ -54,11 +54,12 @@ public:
bool MouseWheel(int x, int y, int d); bool MouseWheel(int x, int y, int d);
bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
void Tick();
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, bool logarithmic = false);
void AdjustZoomSize(int direction); void AdjustZoomSize(int direction, bool logarithmic = false);
void DrawPoints(int toolSelection, queue<ui::Point*> & pointQueue); void DrawPoints(int toolSelection, queue<ui::Point*> & pointQueue);
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2); void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2); void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);

View File

@ -693,6 +693,12 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
selectPoint1 = selectPoint2; selectPoint1 = selectPoint2;
c->OpenStamps(); c->OpenStamps();
break; break;
case ']':
c->AdjustBrushSize(1, true);
break;
case '[':
c->AdjustBrushSize(-1, true);
break;
} }
} }
@ -739,6 +745,8 @@ void GameView::OnTick(float dt)
c->DrawFill(toolIndex, currentMouse); c->DrawFill(toolIndex, currentMouse);
} }
c->Update(); c->Update();
if(lastLogEntry > -0.1f)
lastLogEntry -= 0.16*dt;
} }
void GameView::DoMouseMove(int x, int y, int dx, int dy) void GameView::DoMouseMove(int x, int y, int dx, int dy)
@ -777,6 +785,13 @@ void GameView::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bo
Window::DoKeyRelease(key, character, shift, ctrl, alt); Window::DoKeyRelease(key, character, shift, ctrl, alt);
} }
void GameView::DoDraw()
{
Window::DoDraw();
c->Tick();
}
void GameView::NotifyZoomChanged(GameModel * sender) void GameView::NotifyZoomChanged(GameModel * sender)
{ {
zoomEnabled = sender->GetZoomEnabled(); zoomEnabled = sender->GetZoomEnabled();
@ -786,7 +801,7 @@ void GameView::NotifyLogChanged(GameModel * sender, string entry)
{ {
logEntries.push_front(entry); logEntries.push_front(entry);
lastLogEntry = 100.0f; lastLogEntry = 100.0f;
if(logEntries.size()>10) if(logEntries.size()>20)
logEntries.pop_back(); logEntries.pop_back();
} }
@ -900,15 +915,18 @@ void GameView::OnDraw()
int startX = 20; int startX = 20;
int startY = YRES-20; int startY = YRES-20;
if(lastLogEntry>0.1 && logEntries.size()) int startAlpha;
if(lastLogEntry>0.1f && logEntries.size())
{ {
startAlpha = 2.55f*lastLogEntry;
deque<string>::iterator iter; deque<string>::iterator iter;
for(iter = logEntries.begin(); iter != logEntries.end(); iter++) for(iter = logEntries.begin(); iter != logEntries.end() && startAlpha>0; iter++)
{ {
string message = (*iter); string message = (*iter);
startY -= 14; startY -= 13;
g->fillrect(startX-3, startY-3, Graphics::textwidth((char*)message.c_str())+6, 14, 0, 0, 0, 100); 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); g->drawtext(startX, startY, message.c_str(), 255, 255, 255, startAlpha);
startAlpha-=14;
} }
} }
} }

View File

@ -101,6 +101,7 @@ public:
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 //Top-level handers, for Lua interface
virtual void DoDraw();
virtual void DoMouseMove(int x, int y, int dx, int dy); virtual void DoMouseMove(int x, int y, int dx, int dy);
virtual void DoMouseDown(int x, int y, unsigned button); virtual void DoMouseDown(int x, int y, unsigned button);
virtual void DoMouseUp(int x, int y, unsigned button); virtual void DoMouseUp(int x, int y, unsigned button);