summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-04 20:47:58 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-04 20:47:58 (GMT)
commitea51cde1f07d2a63f824e78c44adad0993115853 (patch)
treea6afee4bafb5de2f91caf1235351b7cc6fc2e606 /src
parent89cdeef9ad9c164e9f484cded3096bcbc72b7207 (diff)
downloadpowder-ea51cde1f07d2a63f824e78c44adad0993115853.zip
powder-ea51cde1f07d2a63f824e78c44adad0993115853.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/cat/CommandInterface.h2
-rw-r--r--src/cat/LuaScriptHelper.h3
-rw-r--r--src/cat/LuaScriptInterface.cpp17
-rw-r--r--src/cat/LuaScriptInterface.h3
-rw-r--r--src/game/GameController.cpp22
-rw-r--r--src/game/GameController.h5
-rw-r--r--src/game/GameView.cpp28
-rw-r--r--src/game/GameView.h1
8 files changed, 63 insertions, 18 deletions
diff --git a/src/cat/CommandInterface.h b/src/cat/CommandInterface.h
index 8cabdab..ca480dd 100644
--- a/src/cat/CommandInterface.h
+++ b/src/cat/CommandInterface.h
@@ -31,7 +31,7 @@ public:
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 void OnTick() {}
virtual int Command(std::string command);
virtual std::string FormatCommand(std::string command);
std::string GetLastError();
diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h
index a9aa02d..b5b885d 100644
--- a/src/cat/LuaScriptHelper.h
+++ b/src/cat/LuaScriptHelper.h
@@ -13,6 +13,9 @@ Simulation * luacon_sim;
LuaScriptInterface * luacon_ci;
Graphics * luacon_g;
+bool *luacon_currentCommand;
+string *luacon_lastError;
+
int *lua_el_func, *lua_el_mode;
int getPartIndex_curIdx;
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 617577b..3da7284 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -13,7 +13,8 @@
#include "LuaScriptHelper.h"
LuaScriptInterface::LuaScriptInterface(GameModel * m):
- CommandInterface(m)
+ CommandInterface(m),
+ currentCommand(false)
{
int i = 0, j;
char tmpname[12];
@@ -77,6 +78,9 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m):
{NULL,NULL}
};
+ luacon_currentCommand = &currentCommand;
+ luacon_lastError = &lastError;
+
luacon_model = m;
luacon_sim = m->GetSimulation();
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);
}
-void LuaScriptInterface::OnTick(float dt)
+void LuaScriptInterface::OnTick()
{
if(luacon_mousedown)
luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS);
@@ -257,11 +261,13 @@ int LuaScriptInterface::Command(std::string command)
{
int ret;
lastError = "";
+ currentCommand = true;
if((ret = luaL_dostring(l, command.c_str())))
{
lastError = luacon_geterror();
- Log(LogError, lastError);
+ //Log(LogError, lastError);
}
+ currentCommand = false;
return ret;
}
@@ -977,7 +983,10 @@ int luatpt_setconsole(lua_State* l)
int luatpt_log(lua_State* l)
{
- luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, 1, ""));
+ if((*luacon_currentCommand) && !(*luacon_lastError).length())
+ (*luacon_lastError) = luaL_optstring(l, 1, "");
+ else
+ luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, 1, ""));
return 0;
}
diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h
index b3ecd7a..a346b1a 100644
--- a/src/cat/LuaScriptInterface.h
+++ b/src/cat/LuaScriptInterface.h
@@ -36,6 +36,7 @@ extern "C"
class LuaScriptInterface: public CommandInterface {
int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton;
bool luacon_mousedown;
+ bool currentCommand;
public:
lua_State *l;
LuaScriptInterface(GameModel * m);
@@ -45,7 +46,7 @@ public:
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 void OnTick();
virtual int Command(std::string command);
virtual std::string FormatCommand(std::string command);
virtual ~LuaScriptInterface();
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index b8f60f5..dfdc12d 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -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)
newSize.X = 0;
if(newSize.Y<0)
@@ -184,9 +188,13 @@ void GameController::AdjustBrushSize(int direction)
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)
newSize = 5;
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);
}
+void GameController::Tick()
+{
+ commandInterface->OnTick();
+}
+
void GameController::Update()
{
- commandInterface->OnTick(1.0f);
gameModel->GetSimulation()->update_particles();
if(renderOptions && renderOptions->HasExited)
{
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 3b5ff88..fffe26a 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -54,11 +54,12 @@ public:
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 Tick();
void SetZoomEnabled(bool zoomEnable);
void SetZoomPosition(ui::Point position);
- void AdjustBrushSize(int direction);
- void AdjustZoomSize(int direction);
+ void AdjustBrushSize(int direction, bool logarithmic = false);
+ void AdjustZoomSize(int direction, bool logarithmic = false);
void DrawPoints(int toolSelection, queue<ui::Point*> & pointQueue);
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 2ccf2e4..d8ea4b8 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -693,6 +693,12 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
selectPoint1 = selectPoint2;
c->OpenStamps();
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->Update();
+ if(lastLogEntry > -0.1f)
+ lastLogEntry -= 0.16*dt;
}
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);
}
+void GameView::DoDraw()
+{
+ Window::DoDraw();
+ c->Tick();
+}
+
+
void GameView::NotifyZoomChanged(GameModel * sender)
{
zoomEnabled = sender->GetZoomEnabled();
@@ -786,7 +801,7 @@ void GameView::NotifyLogChanged(GameModel * sender, string entry)
{
logEntries.push_front(entry);
lastLogEntry = 100.0f;
- if(logEntries.size()>10)
+ if(logEntries.size()>20)
logEntries.pop_back();
}
@@ -900,15 +915,18 @@ void GameView::OnDraw()
int startX = 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;
- for(iter = logEntries.begin(); iter != logEntries.end(); iter++)
+ for(iter = logEntries.begin(); iter != logEntries.end() && startAlpha>0; 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->drawtext(startX, startY, message.c_str(), 255, 255, 255, 255);
+ g->drawtext(startX, startY, message.c_str(), 255, 255, 255, startAlpha);
+ startAlpha-=14;
}
}
}
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 9658184..9843743 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -101,6 +101,7 @@ public:
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
//Top-level handers, for Lua interface
+ virtual void DoDraw();
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);