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/game | |
| 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/game')
| -rw-r--r-- | src/game/GameController.cpp | 31 | ||||
| -rw-r--r-- | src/game/GameController.h | 8 | ||||
| -rw-r--r-- | src/game/GameModel.cpp | 21 | ||||
| -rw-r--r-- | src/game/GameModel.h | 5 | ||||
| -rw-r--r-- | src/game/GameView.cpp | 58 | ||||
| -rw-r--r-- | src/game/GameView.h | 14 |
6 files changed, 137 insertions, 0 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 7b7ba20..b8f60f5 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -303,8 +303,39 @@ void GameController::CopyRegion(ui::Point point1, ui::Point point2) 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() { + 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 cefca8e..3b5ff88 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -47,6 +47,14 @@ public: GameController(); ~GameController(); 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 SetZoomPosition(ui::Point position); void AdjustBrushSize(int direction); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 2a9b69e..6a8f3d8 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -457,6 +457,19 @@ void GameModel::SetStamp(Save * newStamp) 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() { for(int i = 0; i < observers.size(); i++) @@ -576,3 +589,11 @@ void GameModel::notifyClipboardChanged() observers[i]->NotifyClipboardChanged(this); } } + +void GameModel::notifyLogChanged(string entry) +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyLogChanged(this, entry); + } +} diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 7b953c9..7dff6f2 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -2,6 +2,7 @@ #define GAMEMODEL_H #include <vector> +#include <deque> #include "search/Save.h" #include "simulation/Simulation.h" #include "interface/Colour.h" @@ -35,6 +36,7 @@ private: //unsigned char * clipboardData; Save * stamp; Save * clipboard; + deque<string> consoleLog; vector<GameView*> observers; vector<Tool*> toolList; vector<Menu*> menuList; @@ -64,6 +66,7 @@ private: void notifyStampChanged(); void notifyColourSelectorColourChanged(); void notifyColourSelectorVisibilityChanged(); + void notifyLogChanged(string entry); public: GameModel(); ~GameModel(); @@ -110,6 +113,8 @@ public: void SetStamp(Save * newStamp); void AddStamp(unsigned char * saveData, int saveSize); void SetClipboard(unsigned char * saveData, int saveSize); + void Log(string message); + deque<string> GetLog(); Save * GetClipboard(); Save * GetStamp(); }; diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 4067d5a..2ccf2e4 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -741,11 +741,55 @@ void GameView::OnTick(float dt) 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) { 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) { 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); + } + } } } diff --git a/src/game/GameView.h b/src/game/GameView.h index 1be2d96..9658184 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -3,6 +3,8 @@ #include <vector> #include <queue> +#include <deque> +#include <string> #include "GameController.h" #include "GameModel.h" #include "interface/Window.h" @@ -41,6 +43,8 @@ private: //UI Elements vector<ui::Button*> menuButtons; vector<ToolButton*> toolButtons; + deque<string> logEntries; + float lastLogEntry; ui::Button * searchButton; ui::Button * reloadButton; ui::Button * saveSimulationButton; @@ -88,12 +92,22 @@ public: void NotifyColourSelectorColourChanged(GameModel * sender); void NotifyClipboardChanged(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 OnMouseDown(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 OnKeyPress(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 OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {} virtual void OnTick(float dt); |
