diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 4bea8edc5..d1319f71b 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -1378,8 +1378,9 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l) int LuaScriptInterface::simulation_loadSave(lua_State * l) { int saveID = luaL_optint(l,1,0); - int history = luaL_optint(l,2,0); //Exact second a previous save was saved - luacon_controller->OpenSavePreview(saveID, history); + int instant = luaL_optint(l,2,0); + int history = luaL_optint(l,3,0); //Exact second a previous save was saved + luacon_controller->OpenSavePreview(saveID, history, instant?true:false); return 0; } diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp index a91f2d877..21e93ab4f 100644 --- a/src/cat/TPTScriptInterface.cpp +++ b/src/cat/TPTScriptInterface.cpp @@ -426,7 +426,7 @@ AnyType TPTScriptInterface::tptS_load(std::deque * words) //Arguments from stack NumberType saveID = eval(words); - c->OpenSavePreview(saveID.Value(), 0); + c->OpenSavePreview(saveID.Value(), 0, false); return NumberType(0); } diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index f4ad0b2de..488d30a7b 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -588,7 +588,7 @@ bool GameController::MouseUp(int x, int y, unsigned button) if (tempSaveID) { if ((*iter).text.c_str()[1] == 'c') - OpenSavePreview(tempSaveID, 0); + OpenSavePreview(tempSaveID, 0, false); else if ((*iter).text.c_str()[1] == 't') { char url[256]; @@ -1096,9 +1096,9 @@ void GameController::LoadSave(SaveInfo * save) gameModel->SetSave(save); } -void GameController::OpenSavePreview(int saveID, int saveDate) +void GameController::OpenSavePreview(int saveID, int saveDate, bool instant) { - activePreview = new PreviewController(saveID, saveDate, new SaveOpenCallback(this)); + activePreview = new PreviewController(saveID, saveDate, instant, new SaveOpenCallback(this)); ui::Engine::Ref().ShowWindow(activePreview->GetView()); } @@ -1106,7 +1106,7 @@ void GameController::OpenSavePreview() { if(gameModel->GetSave()) { - activePreview = new PreviewController(gameModel->GetSave()->GetID(), new SaveOpenCallback(this)); + activePreview = new PreviewController(gameModel->GetSave()->GetID(), false, new SaveOpenCallback(this)); ui::Engine::Ref().ShowWindow(activePreview->GetView()); } } diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 88f426bc6..d723ccb63 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -113,7 +113,7 @@ public: void OpenLogin(); void OpenProfile(); void OpenTags(); - void OpenSavePreview(int saveID, int saveDate); + void OpenSavePreview(int saveID, int saveDate, bool instant); void OpenSavePreview(); void OpenLocalSaveWindow(bool asCurrent); void OpenLocalBrowse(); diff --git a/src/gui/preview/PreviewController.cpp b/src/gui/preview/PreviewController.cpp index 3a7961ae1..f63c6237d 100644 --- a/src/gui/preview/PreviewController.cpp +++ b/src/gui/preview/PreviewController.cpp @@ -8,7 +8,7 @@ #include "gui/login/LoginController.h" #include "Controller.h" -PreviewController::PreviewController(int saveID, int saveDate, ControllerCallback * callback): +PreviewController::PreviewController(int saveID, int saveDate, bool instant, ControllerCallback * callback): HasExited(false), saveId(saveID), saveDate(saveDate), @@ -18,6 +18,7 @@ PreviewController::PreviewController(int saveID, int saveDate, ControllerCallbac previewView = new PreviewView(); previewModel->AddObserver(previewView); previewView->AttachController(this); + previewModel->SetDoOpen(instant); previewModel->UpdateSave(saveID, saveDate); @@ -31,7 +32,7 @@ PreviewController::PreviewController(int saveID, int saveDate, ControllerCallbac this->callback = callback; } -PreviewController::PreviewController(int saveID, ControllerCallback * callback): +PreviewController::PreviewController(int saveID, bool instant, ControllerCallback * callback): HasExited(false), saveId(saveID), saveDate(0), @@ -164,7 +165,7 @@ void PreviewController::OpenInBrowser() bool PreviewController::NextCommentPage() { - if(previewModel->GetCommentsPageNum() < previewModel->GetCommentsPageCount() && previewModel->GetCommentsLoaded()) + if(previewModel->GetCommentsPageNum() < previewModel->GetCommentsPageCount() && previewModel->GetCommentsLoaded() && !previewModel->GetDoOpen()) { previewModel->UpdateComments(previewModel->GetCommentsPageNum()+1); return true; @@ -174,7 +175,7 @@ bool PreviewController::NextCommentPage() bool PreviewController::PrevCommentPage() { - if(previewModel->GetCommentsPageNum()>1 && previewModel->GetCommentsLoaded()) + if(previewModel->GetCommentsPageNum() > 1 && previewModel->GetCommentsLoaded() && !previewModel->GetDoOpen()) { previewModel->UpdateComments(previewModel->GetCommentsPageNum()-1); return true; diff --git a/src/gui/preview/PreviewController.h b/src/gui/preview/PreviewController.h index c5a4306df..223d84615 100644 --- a/src/gui/preview/PreviewController.h +++ b/src/gui/preview/PreviewController.h @@ -22,8 +22,8 @@ public: inline int SaveID() { return saveId; }; bool HasExited; - PreviewController(int saveID, ControllerCallback * callback); - PreviewController(int saveID, int saveDate, ControllerCallback * callback); + PreviewController(int saveID, bool instant, ControllerCallback * callback); + PreviewController(int saveID, int saveDate, bool instant, ControllerCallback * callback); void Exit(); void DoOpen(); void OpenInBrowser(); diff --git a/src/gui/preview/PreviewModel.cpp b/src/gui/preview/PreviewModel.cpp index 88b281b7b..677644517 100644 --- a/src/gui/preview/PreviewModel.cpp +++ b/src/gui/preview/PreviewModel.cpp @@ -139,13 +139,16 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) pthread_create(&updateSaveInfoThread, 0, &PreviewModel::updateSaveInfoT, updateSaveInfoInfo); } - if (!updateSaveCommentsInfo) - updateSaveCommentsInfo = new threadInfo(saveID, commentsPageNumber); - if (updateSaveCommentsInfo->threadFinished) + if (!GetDoOpen()) { - commentsLoaded = false; - updateSaveCommentsInfo->threadFinished = false; - pthread_create(&updateSaveCommentsThread, 0, &PreviewModel::updateSaveCommentsT, updateSaveCommentsInfo); + if (!updateSaveCommentsInfo) + updateSaveCommentsInfo = new threadInfo(saveID, commentsPageNumber); + if (updateSaveCommentsInfo->threadFinished) + { + commentsLoaded = false; + updateSaveCommentsInfo->threadFinished = false; + pthread_create(&updateSaveCommentsThread, 0, &PreviewModel::updateSaveCommentsT, updateSaveCommentsInfo); + } } } diff --git a/src/gui/search/SearchController.cpp b/src/gui/search/SearchController.cpp index 0a8ad9eaf..bd3e4d8de 100644 --- a/src/gui/search/SearchController.cpp +++ b/src/gui/search/SearchController.cpp @@ -36,6 +36,7 @@ SearchController::SearchController(ControllerCallback * callback): HasExited(false), nextQueryTime(0.0f), nextQueryDone(true), + instantOpen(false), searchModel(NULL) { searchModel = new SearchModel(); @@ -46,9 +47,6 @@ SearchController::SearchController(ControllerCallback * callback): searchModel->UpdateSaveList(1, ""); this->callback = callback; - - //Set up interface - //windowPanel.AddChild(); } SaveInfo * SearchController::GetLoadedSave() @@ -180,13 +178,18 @@ void SearchController::Selected(int saveID, bool selected) searchModel->DeselectSave(saveID); } +void SearchController::InstantOpen(bool instant) +{ + instantOpen = instant; +} + void SearchController::OpenSave(int saveID) { if(activePreview) delete activePreview; Graphics * g = ui::Engine::Ref().g; g->fillrect(XRES/3, YRES+MENUSIZE-20, XRES/3, 20, 0, 0, 0, 150); //dim the "Page X of Y" a little to make the CopyTextButton more noticeable - activePreview = new PreviewController(saveID, new OpenCallback(this)); + activePreview = new PreviewController(saveID, instantOpen, new OpenCallback(this)); ui::Engine::Ref().ShowWindow(activePreview->GetView()); } @@ -196,7 +199,7 @@ void SearchController::OpenSave(int saveID, int saveDate) delete activePreview; Graphics * g = ui::Engine::Ref().g; g->fillrect(XRES/3, YRES+MENUSIZE-20, XRES/3, 20, 0, 0, 0, 150); //dim the "Page X of Y" a little to make the CopyTextButton more noticeable - activePreview = new PreviewController(saveID, saveDate, new OpenCallback(this)); + activePreview = new PreviewController(saveID, saveDate, instantOpen, new OpenCallback(this)); ui::Engine::Ref().ShowWindow(activePreview->GetView()); } diff --git a/src/gui/search/SearchController.h b/src/gui/search/SearchController.h index 8d811ab98..40e0b4a12 100644 --- a/src/gui/search/SearchController.h +++ b/src/gui/search/SearchController.h @@ -21,6 +21,7 @@ private: double nextQueryTime; std::string nextQuery; bool nextQueryDone; + bool instantOpen; void removeSelectedC(); void unpublishSelectedC(); public: @@ -37,6 +38,7 @@ public: void ShowOwn(bool show); void ShowFavourite(bool show); void Selected(int saveID, bool selected); + void InstantOpen(bool instant); void OpenSave(int saveID); void OpenSave(int saveID, int saveDate); void Update(); diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index cfa1a3b33..662e756e5 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -712,7 +712,9 @@ void SearchView::OnMouseWheel(int x, int y, int d) } void SearchView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { - if(key==KEY_ESCAPE) + if (key == KEY_ESCAPE) c->Exit(); + if (ctrl) + c->InstantOpen(ctrl); }