diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-02 16:01:28 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-04-02 16:01:28 (GMT) |
| commit | efddc12e5d2aadc5eee1927245ad38b9dee89aed (patch) | |
| tree | cf7ad38119f0734609944158e33bbb944925c777 /src/game | |
| parent | 289556ac7078963b6af361f5812dd62e6712359f (diff) | |
| download | powder-efddc12e5d2aadc5eee1927245ad38b9dee89aed.zip powder-efddc12e5d2aadc5eee1927245ad38b9dee89aed.tar.gz | |
Stamps browser, placement + clipboard sampling and placement - No clipboard or stamp thumbnail generation, needs thumbnail generator from SaveLoader
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/GameController.cpp | 38 | ||||
| -rw-r--r-- | src/game/GameController.h | 6 | ||||
| -rw-r--r-- | src/game/GameModel.cpp | 54 | ||||
| -rw-r--r-- | src/game/GameModel.h | 11 | ||||
| -rw-r--r-- | src/game/GameView.cpp | 145 | ||||
| -rw-r--r-- | src/game/GameView.h | 6 |
6 files changed, 219 insertions, 41 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 7b08716..3408ec5 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -86,6 +86,20 @@ public: } }; +class GameController::StampsCallback: public ControllerCallback +{ + GameController * cc; +public: + StampsCallback(GameController * cc_) { cc = cc_; } + virtual void ControllerExit() + { + if(cc->stamps->GetStamp()) + { + cc->gameModel->SetStamp(cc->stamps->GetStamp()); + } + } +}; + GameController::GameController(): search(NULL), renderOptions(NULL), @@ -140,6 +154,24 @@ GameView * GameController::GetView() return gameView; } +void GameController::PlaceStamp(ui::Point position) +{ + if(gameModel->GetStamp()) + { + gameModel->GetSimulation()->Load(position.X, position.Y, gameModel->GetStamp()->data, gameModel->GetStamp()->dataLength); + gameModel->SetPaused(gameModel->GetPaused()); + } +} + +void GameController::PlaceClipboard(ui::Point position) +{ + if(gameModel->GetClipboard()) + { + gameModel->GetSimulation()->Load(position.X, position.Y, gameModel->GetClipboard()->data, gameModel->GetClipboard()->dataLength); + gameModel->SetPaused(gameModel->GetPaused()); + } +} + void GameController::AdjustBrushSize(int direction) { ui::Point newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction, direction); @@ -395,6 +427,12 @@ void GameController::OpenTags() } } +void GameController::OpenStamps() +{ + stamps = new StampsController(new StampsCallback(this)); + ui::Engine::Ref().ShowWindow(stamps->GetView()); +} + void GameController::OpenDisplayOptions() { //TODO: Implement diff --git a/src/game/GameController.h b/src/game/GameController.h index cf26f51..cefca8e 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -12,6 +12,7 @@ #include "ssave/SSaveController.h" #include "tags/TagsController.h" #include "console/ConsoleController.h" +#include "stamps/StampsController.h" //#include "cat/TPTScriptInterface.h" #include "cat/LuaScriptInterface.h" #include "Menu.h" @@ -34,6 +35,7 @@ private: SSaveController * ssave; ConsoleController * console; TagsController * tagsWindow; + StampsController * stamps; CommandInterface * commandInterface; public: class LoginCallback; @@ -41,6 +43,7 @@ public: class RenderCallback; class SSaveCallback; class TagsCallback; + class StampsCallback; GameController(); ~GameController(); GameView * GetView(); @@ -68,6 +71,9 @@ public: void OpenDisplayOptions(); void OpenRenderOptions(); void OpenSaveWindow(); + void OpenStamps(); + void PlaceStamp(ui::Point position); + void PlaceClipboard(ui::Point position); void ClearSim(); void ReloadSim(); void Vote(int direction); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 0106dd7..2a9b69e 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -18,7 +18,8 @@ GameModel::GameModel(): currentUser(0, ""), currentSave(NULL), colourSelector(false), - clipboardData(NULL) + clipboard(NULL), + stamp(NULL) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); @@ -158,6 +159,10 @@ GameModel::~GameModel() } delete sim; delete ren; + if(clipboard) + delete clipboard; + if(stamp) + delete stamp; if(activeTools) delete activeTools; } @@ -414,23 +419,42 @@ void GameModel::ClearSimulation() void GameModel::AddStamp(unsigned char * saveData, int saveSize) { - //Do nothing - - //die alone + Save * tempSave = new Save(0, 0, 0, 0, "", ""); + tempSave->SetData(saveData, saveSize); + Client::Ref().AddStamp(tempSave); + delete tempSave; } void GameModel::SetClipboard(unsigned char * saveData, int saveSize) { - if(clipboardData) - free(clipboardData); - clipboardData = saveData; - clipboardSize = saveSize; + if(clipboard) + delete clipboard; + clipboard = new Save(0, 0, 0, 0, "", ""); + clipboard->SetData(saveData, saveSize); + notifyClipboardChanged(); +} + +Save * GameModel::GetClipboard() +{ + return clipboard; } -unsigned char * GameModel::GetClipboard(int & saveSize) +Save * GameModel::GetStamp() { - saveSize = clipboardSize; - return clipboardData; + return stamp; +} + +void GameModel::SetStamp(Save * newStamp) +{ + if(stamp) + delete stamp; + if(newStamp) + { + stamp = new Save(*newStamp); + } + else + stamp = NULL; + notifyStampChanged(); } void GameModel::notifyColourSelectorColourChanged() @@ -537,6 +561,14 @@ void GameModel::notifyZoomChanged() } } +void GameModel::notifyStampChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyStampChanged(this); + } +} + void GameModel::notifyClipboardChanged() { for(int i = 0; i < observers.size(); i++) diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 14e42ac..7b953c9 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -31,8 +31,10 @@ public: class GameModel { private: - int clipboardSize; - unsigned char * clipboardData; + //int clipboardSize; + //unsigned char * clipboardData; + Save * stamp; + Save * clipboard; vector<GameView*> observers; vector<Tool*> toolList; vector<Menu*> menuList; @@ -59,6 +61,7 @@ private: void notifyUserChanged(); void notifyZoomChanged(); void notifyClipboardChanged(); + void notifyStampChanged(); void notifyColourSelectorColourChanged(); void notifyColourSelectorVisibilityChanged(); public: @@ -104,9 +107,11 @@ public: ui::Point GetZoomPosition(); void SetZoomWindowPosition(ui::Point position); ui::Point GetZoomWindowPosition(); + void SetStamp(Save * newStamp); void AddStamp(unsigned char * saveData, int saveSize); void SetClipboard(unsigned char * saveData, int saveSize); - unsigned char * GetClipboard(int & saveSize); + Save * GetClipboard(); + Save * GetStamp(); }; #endif // GAMEMODEL_H diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 7faeaf1..8c1c14a 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -8,6 +8,7 @@ #include "interface/Colour.h" #include "interface/Keys.h" #include "interface/Slider.h" +#include "search/Thumbnail.h" GameView::GameView(): ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)), @@ -25,7 +26,9 @@ GameView::GameView(): drawModeReset(false), selectMode(SelectNone), selectPoint1(0, 0), - selectPoint2(0, 0) + selectPoint2(0, 0), + stampThumb(NULL), + clipboardThumb(NULL) { int currentX = 1; //Set up UI @@ -467,6 +470,8 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy) { if(selectMode!=SelectNone) { + if(selectMode==PlaceStamp || selectMode==PlaceClipboard) + selectPoint1 = ui::Point(x, y); if(selectPoint1.X!=-1) selectPoint2 = ui::Point(x, y); return; @@ -514,16 +519,46 @@ void GameView::OnMouseUp(int x, int y, unsigned button) { if(selectMode!=SelectNone) { - int x2 = (selectPoint1.X>selectPoint2.X)?selectPoint1.X:selectPoint2.X; - int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; - int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X; - int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y; - if(button==BUTTON_LEFT && x2-x1>0 && y2-y1>0) + if(button==BUTTON_LEFT) { - if(selectMode==SelectCopy) - c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - else if(selectMode==SelectStamp) - c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2)); + if(selectMode==PlaceStamp || selectMode==PlaceClipboard) + { + Thumbnail * tempThumb = selectMode==PlaceStamp?stampThumb:clipboardThumb; + if(tempThumb) + { + int thumbX = selectPoint2.X - (tempThumb->Size.X/2); + int thumbY = selectPoint2.Y - (tempThumb->Size.Y/2); + + if(thumbX<0) + thumbX = 0; + if(thumbX+(tempThumb->Size.X)>=XRES) + thumbX = XRES-tempThumb->Size.X; + + if(thumbY<0) + thumbY = 0; + if(thumbY+(tempThumb->Size.Y)>=YRES) + thumbY = YRES-tempThumb->Size.Y; + + if(selectMode==PlaceStamp) + c->PlaceStamp(ui::Point(thumbX, thumbY)); + if(selectMode==PlaceClipboard) + c->PlaceClipboard(ui::Point(thumbX, thumbY)); + } + } + else + { + int x2 = (selectPoint1.X>selectPoint2.X)?selectPoint1.X:selectPoint2.X; + int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; + int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X; + int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y; + if(x2-x1>0 && y2-y1>0) + { + if(selectMode==SelectCopy) + c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); + else if(selectMode==SelectStamp) + c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2)); + } + } } selectMode = SelectNone; return; @@ -643,6 +678,20 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool selectPoint1 = ui::Point(-1, -1); } break; + case 'v': + if(ctrl && clipboardThumb) + { + selectMode = PlaceClipboard; + selectPoint2 = ui::Point(-1, -1); + selectPoint1 = selectPoint2; + } + break; + case 'l': + selectMode = PlaceStamp; + selectPoint2 = ui::Point(-1, -1); + selectPoint1 = selectPoint2; + c->OpenStamps(); + break; } } @@ -694,7 +743,27 @@ void GameView::NotifyZoomChanged(GameModel * sender) void GameView::NotifyClipboardChanged(GameModel * sender) { - //Could use this to have a mini preview of the clipboard, meh + if(clipboardThumb) + delete clipboardThumb; + if(sender->GetClipboard()) + { + clipboardThumb = new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256)); + } + else + clipboardThumb = NULL; +} + + +void GameView::NotifyStampChanged(GameModel * sender) +{ + if(stampThumb) + delete stampThumb; + if(sender->GetStamp()) + { + stampThumb = new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256)); + } + else + stampThumb = NULL; } void GameView::changeColour() @@ -730,29 +799,53 @@ void GameView::OnDraw() if(selectMode!=SelectNone) { - if(selectPoint1.X==-1) + if(selectMode==PlaceStamp || selectMode==PlaceClipboard) { - g->fillrect(0, 0, XRES, YRES, 0, 0, 0, 100); + Thumbnail * tempThumb = selectMode==PlaceStamp?stampThumb:clipboardThumb; + if(tempThumb && selectPoint2.X!=-1) + { + int thumbX = selectPoint2.X - (tempThumb->Size.X/2); + int thumbY = selectPoint2.Y - (tempThumb->Size.Y/2); + + if(thumbX<0) + thumbX = 0; + if(thumbX+(tempThumb->Size.X)>=XRES) + thumbX = XRES-tempThumb->Size.X; + + if(thumbY<0) + thumbY = 0; + if(thumbY+(tempThumb->Size.Y)>=YRES) + thumbY = YRES-tempThumb->Size.Y; + + g->draw_image(tempThumb->Data, thumbX, thumbY, tempThumb->Size.X, tempThumb->Size.Y, 128); + } } else { - int x2 = (selectPoint1.X>selectPoint2.X)?selectPoint1.X:selectPoint2.X; - int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; - int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X; - int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y; + if(selectPoint1.X==-1) + { + g->fillrect(0, 0, XRES, YRES, 0, 0, 0, 100); + } + else + { + int x2 = (selectPoint1.X>selectPoint2.X)?selectPoint1.X:selectPoint2.X; + int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; + int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X; + int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y; - if(x2>XRES-1) - x2 = XRES-1; - if(y2>YRES-1) - y2 = YRES-1; + if(x2>XRES-1) + x2 = XRES-1; + if(y2>YRES-1) + y2 = YRES-1; - g->fillrect(0, 0, XRES, y1, 0, 0, 0, 100); - g->fillrect(0, y2, XRES, YRES-y2, 0, 0, 0, 100); + g->fillrect(0, 0, XRES, y1, 0, 0, 0, 100); + g->fillrect(0, y2, XRES, YRES-y2, 0, 0, 0, 100); - g->fillrect(0, y1-1, x1, (y2-y1)+2, 0, 0, 0, 100); - g->fillrect(x2, y1-1, XRES-x2, (y2-y1)+2, 0, 0, 0, 100); + g->fillrect(0, y1-1, x1, (y2-y1)+2, 0, 0, 0, 100); + g->fillrect(x2, y1-1, XRES-x2, (y2-y1)+2, 0, 0, 0, 100); - g->xor_rect(x1, y1, (x2-x1)+1, (y2-y1)+1); + g->xor_rect(x1, y1, (x2-x1)+1, (y2-y1)+1); + } } } } diff --git a/src/game/GameView.h b/src/game/GameView.h index 0b31182..1be2d96 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -21,7 +21,7 @@ enum DrawMode enum SelectMode { - SelectNone, SelectStamp, SelectCopy + SelectNone, SelectStamp, SelectCopy, PlaceClipboard, PlaceStamp }; class GameController; @@ -67,6 +67,9 @@ private: ui::Point selectPoint1; ui::Point selectPoint2; + Thumbnail * clipboardThumb; + Thumbnail * stampThumb; + void changeColour(); public: GameView(); @@ -84,6 +87,7 @@ public: void NotifyColourSelectorVisibilityChanged(GameModel * sender); void NotifyColourSelectorColourChanged(GameModel * sender); void NotifyClipboardChanged(GameModel * sender); + void NotifyStampChanged(GameModel * sender); 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); |
