From c06afff0a572c34ea4da8b87670e21c67b9c06b7 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Tue, 18 Dec 2012 12:20:52 -0500 Subject: [PATCH] selecting a stamp moves it to the front of the list again (unless you hold ctrl) attempted to do MVC right? --- src/client/Client.cpp | 14 ++++++++++++++ src/client/Client.h | 1 + src/game/GameController.cpp | 2 ++ src/localbrowser/LocalBrowserController.cpp | 10 ++++++++++ src/localbrowser/LocalBrowserController.h | 3 ++- src/localbrowser/LocalBrowserModel.cpp | 13 ++++++++++++- src/localbrowser/LocalBrowserModel.h | 3 +++ src/localbrowser/LocalBrowserView.cpp | 6 +++++- 8 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 0f9de28e3..4c7ac4370 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -909,6 +909,20 @@ RequestStatus Client::UploadSave(SaveInfo & save) return RequestFailure; } +void Client::MoveStampToFront(std::string stampID) +{ + for (std::list::iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator) + { + if((*iterator) == stampID) + { + stampIDs.erase(iterator); + break; + } + } + stampIDs.push_front(stampID); + updateStamps(); +} + SaveFile * Client::GetStamp(std::string stampID) { std::string stampFile = std::string(STAMPS_DIR PATH_SEP + stampID + ".stm"); diff --git a/src/client/Client.h b/src/client/Client.h index bd332739d..0b40012e4 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -121,6 +121,7 @@ public: void RescanStamps(); int GetStampsCount(); SaveFile * GetFirstStamp(); + void MoveStampToFront(std::string stampID); RequestStatus AddComment(int saveID, std::string comment); diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 07d2e63c2..f1e05414b 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -118,6 +118,8 @@ public: if(cc->localBrowser->GetSave()) { cc->gameModel->SetStamp(cc->localBrowser->GetSave()->GetGameSave()); + if (cc->localBrowser->GetMoveToFront()) + Client::Ref().MoveStampToFront(cc->localBrowser->GetSave()->GetName()); cc->LoadStamp(); } } diff --git a/src/localbrowser/LocalBrowserController.cpp b/src/localbrowser/LocalBrowserController.cpp index e932e7239..4719bf1bf 100644 --- a/src/localbrowser/LocalBrowserController.cpp +++ b/src/localbrowser/LocalBrowserController.cpp @@ -152,6 +152,16 @@ void LocalBrowserController::Selected(std::string saveName, bool selected) browserModel->DeselectSave(saveName); } +bool LocalBrowserController::GetMoveToFront() +{ + return browserModel->GetMoveToFront(); +} + +void LocalBrowserController::SetMoveToFront(bool move) +{ + browserModel->SetMoveToFront(move); +} + void LocalBrowserController::Exit() { if(ui::Engine::Ref().GetWindow() == browserView) diff --git a/src/localbrowser/LocalBrowserController.h b/src/localbrowser/LocalBrowserController.h index efa9c9308..236ac075d 100644 --- a/src/localbrowser/LocalBrowserController.h +++ b/src/localbrowser/LocalBrowserController.h @@ -31,7 +31,8 @@ public: void rescanStampsC(); void RefreshSavesList(); void OpenSave(SaveFile * stamp); - void SetStamp(); + bool GetMoveToFront(); + void SetMoveToFront(bool move); void NextPage(); void PrevPage(); void Update(); diff --git a/src/localbrowser/LocalBrowserModel.cpp b/src/localbrowser/LocalBrowserModel.cpp index 9e869ccfb..42f1a6503 100644 --- a/src/localbrowser/LocalBrowserModel.cpp +++ b/src/localbrowser/LocalBrowserModel.cpp @@ -13,7 +13,8 @@ LocalBrowserModel::LocalBrowserModel(): stamp(NULL), - currentPage(1) + currentPage(1), + stampToFront(1) { // TODO Auto-generated constructor stub //stampIDs = Client::Ref().GetStamps(); @@ -61,6 +62,16 @@ void LocalBrowserModel::SetSave(SaveFile * newStamp) stamp = new SaveFile(*newStamp); } +bool LocalBrowserModel::GetMoveToFront() +{ + return stampToFront; +} + +void LocalBrowserModel::SetMoveToFront(bool move) +{ + stampToFront = move; +} + void LocalBrowserModel::UpdateSavesList(int pageNumber) { std::vector tempSavesList = savesList; diff --git a/src/localbrowser/LocalBrowserModel.h b/src/localbrowser/LocalBrowserModel.h index c2a6f9b9d..af8850907 100644 --- a/src/localbrowser/LocalBrowserModel.h +++ b/src/localbrowser/LocalBrowserModel.h @@ -22,6 +22,7 @@ class LocalBrowserModel { std::vector savesList; std::vector observers; int currentPage; + bool stampToFront; void notifySavesListChanged(); void notifyPageChanged(); void notifySelectedChanged(); @@ -35,6 +36,8 @@ public: void RescanStamps(); SaveFile * GetSave(); void SetSave(SaveFile * newStamp); + bool GetMoveToFront(); + void SetMoveToFront(bool move); std::vector GetSelected() { return selected; } void ClearSelected() { selected.clear(); notifySelectedChanged(); } void SelectSave(std::string stampID); diff --git a/src/localbrowser/LocalBrowserView.cpp b/src/localbrowser/LocalBrowserView.cpp index a6efc4cb6..aa759259b 100644 --- a/src/localbrowser/LocalBrowserView.cpp +++ b/src/localbrowser/LocalBrowserView.cpp @@ -210,8 +210,12 @@ void LocalBrowserView::OnMouseWheel(int x, int y, int d) } void LocalBrowserView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { - if(key==KEY_ESCAPE) + if(key == KEY_ESCAPE) c->Exit(); + if (key == KEY_CTRL) + c->SetMoveToFront(false); + else + c->SetMoveToFront(true); } LocalBrowserView::~LocalBrowserView() {