Show save button thumbnail in the preview if it's available

This is good enough for now but also more limited than I'd like because if the thumbnail arrives (gets rendered or downloaded) later than the preview is opened, it's never shown.
This commit is contained in:
Tamás Bálint Misius
2023-05-13 12:34:23 +02:00
parent 843f414291
commit a9d231587c
11 changed files with 34 additions and 23 deletions

View File

@@ -1213,7 +1213,7 @@ void GameController::OpenSaveDone()
void GameController::OpenSavePreview(int saveID, int saveDate, bool instant) void GameController::OpenSavePreview(int saveID, int saveDate, bool instant)
{ {
activePreview = new PreviewController(saveID, saveDate, instant, [this] { OpenSaveDone(); }); activePreview = new PreviewController(saveID, saveDate, instant, [this] { OpenSaveDone(); }, nullptr);
ui::Engine::Ref().ShowWindow(activePreview->GetView()); ui::Engine::Ref().ShowWindow(activePreview->GetView());
} }
@@ -1221,7 +1221,7 @@ void GameController::OpenSavePreview()
{ {
if(gameModel->GetSave()) if(gameModel->GetSave())
{ {
activePreview = new PreviewController(gameModel->GetSave()->GetID(), 0, false, [this] { OpenSaveDone(); }); activePreview = new PreviewController(gameModel->GetSave()->GetID(), 0, false, [this] { OpenSaveDone(); }, nullptr);
ui::Engine::Ref().ShowWindow(activePreview->GetView()); ui::Engine::Ref().ShowWindow(activePreview->GetView());
} }
} }

View File

@@ -21,6 +21,7 @@ class SearchController;
class PreviewController; class PreviewController;
class RenderController; class RenderController;
class CommandInterface; class CommandInterface;
class VideoBuffer;
class Tool; class Tool;
class Menu; class Menu;
class SaveInfo; class SaveInfo;

View File

@@ -401,4 +401,13 @@ void SaveButton::DoSelection()
actionCallback.selected(); actionCallback.selected();
} }
std::unique_ptr<VideoBuffer> SaveButton::CloneThumbnail() const
{
if (thumbnail)
{
return std::make_unique<VideoBuffer>(*thumbnail);
}
return nullptr;
}
} /* namespace ui */ } /* namespace ui */

View File

@@ -75,6 +75,11 @@ public:
void DoAltAction2(); void DoAltAction2();
void DoSelection(); void DoSelection();
inline void SetActionCallback(SaveButtonAction action) { actionCallback = action; } inline void SetActionCallback(SaveButtonAction action) { actionCallback = action; }
// TODO: clone the request instead because sometimes the user of CloneThumbnail might end up
// with a nullptr even though the thumbnail for the SaveButton will eventually arrive.
std::unique_ptr<VideoBuffer> CloneThumbnail() const;
protected: protected:
bool isButtonDown, state, isMouseInside, selected, selectable; bool isButtonDown, state, isMouseInside, selected, selectable;
}; };

View File

@@ -7,19 +7,20 @@
#include "client/SaveInfo.h" #include "client/SaveInfo.h"
#include "client/GameSave.h" #include "client/GameSave.h"
#include "common/platform/Platform.h" #include "common/platform/Platform.h"
#include "graphics/Graphics.h"
#include "gui/dialogues/ErrorMessage.h" #include "gui/dialogues/ErrorMessage.h"
#include "gui/dialogues/InformationMessage.h" #include "gui/dialogues/InformationMessage.h"
#include "gui/login/LoginController.h" #include "gui/login/LoginController.h"
#include "gui/login/LoginView.h" #include "gui/login/LoginView.h"
#include "Config.h" #include "Config.h"
PreviewController::PreviewController(int saveID, int saveDate, bool instant, std::function<void ()> onDone_): PreviewController::PreviewController(int saveID, int saveDate, bool instant, std::function<void ()> onDone_, std::unique_ptr<VideoBuffer> thumbnail):
saveId(saveID), saveId(saveID),
loginWindow(NULL), loginWindow(NULL),
HasExited(false) HasExited(false)
{ {
previewModel = new PreviewModel(); previewModel = new PreviewModel();
previewView = new PreviewView(); previewView = new PreviewView(std::move(thumbnail));
previewModel->AddObserver(previewView); previewModel->AddObserver(previewView);
previewView->AttachController(this); previewView->AttachController(this);
previewModel->SetDoOpen(instant); previewModel->SetDoOpen(instant);

View File

@@ -3,6 +3,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
class VideoBuffer;
class SaveInfo; class SaveInfo;
class LoginController; class LoginController;
class PreviewModel; class PreviewModel;
@@ -18,7 +19,7 @@ public:
inline int SaveID() { return saveId; } inline int SaveID() { return saveId; }
bool HasExited; bool HasExited;
PreviewController(int saveID, int saveDate, bool instant, std::function<void ()> onDone = nullptr); PreviewController(int saveID, int saveDate, bool instant, std::function<void ()> onDone, std::unique_ptr<VideoBuffer> thumbnail);
void Exit(); void Exit();
void DoOpen(); void DoOpen();
void OpenInBrowser(); void OpenInBrowser();

View File

@@ -33,9 +33,8 @@
# undef GetUserName // dammit windows # undef GetUserName // dammit windows
#endif #endif
PreviewView::PreviewView(): PreviewView::PreviewView(std::unique_ptr<VideoBuffer> newSavePreview):
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+210, (YRES/2)+150)), ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+210, (YRES/2)+150)),
savePreview(nullptr),
submitCommentButton(NULL), submitCommentButton(NULL),
addCommentBox(NULL), addCommentBox(NULL),
commentWarningLabel(NULL), commentWarningLabel(NULL),
@@ -48,6 +47,11 @@ PreviewView::PreviewView():
commentBoxHeight(20), commentBoxHeight(20),
commentHelpText(false) commentHelpText(false)
{ {
if (newSavePreview)
{
newSavePreview->Resize(RES / 2, true);
savePreview = std::move(newSavePreview);
}
showAvatars = ui::Engine::Ref().ShowAvatars; showAvatars = ui::Engine::Ref().ShowAvatars;
favButton = new ui::Button(ui::Point(50, Size.Y-19), ui::Point(51, 19), "Fav"); favButton = new ui::Button(ui::Point(50, Size.Y-19), ui::Point(51, 19), "Fav");
@@ -416,7 +420,6 @@ void PreviewView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ct
void PreviewView::NotifySaveChanged(PreviewModel * sender) void PreviewView::NotifySaveChanged(PreviewModel * sender)
{ {
auto *save = sender->GetSaveInfo(); auto *save = sender->GetSaveInfo();
savePreview = nullptr;
if(save) if(save)
{ {
votesUp = save->votesUp; votesUp = save->votesUp;

View File

@@ -66,7 +66,7 @@ class PreviewView: public ui::Window
void CheckComment(); void CheckComment();
public: public:
void AttachController(PreviewController * controller); void AttachController(PreviewController * controller);
PreviewView(); PreviewView(std::unique_ptr<VideoBuffer> newSavePreviev);
void NotifySaveChanged(PreviewModel * sender); void NotifySaveChanged(PreviewModel * sender);
void NotifyCommentsChanged(PreviewModel * sender); void NotifyCommentsChanged(PreviewModel * sender);
void NotifyCommentsPageChanged(PreviewModel * sender); void NotifyCommentsPageChanged(PreviewModel * sender);

View File

@@ -204,21 +204,12 @@ void SearchController::OpenSaveDone()
} }
} }
void SearchController::OpenSave(int saveID) void SearchController::OpenSave(int saveID, int saveDate, std::unique_ptr<VideoBuffer> thumbnail)
{ {
delete activePreview; delete activePreview;
Graphics * g = searchView->GetGraphics(); Graphics * g = searchView->GetGraphics();
g->BlendFilledRect(RectSized(Vec2{ XRES/3, WINDOWH-20 }, Vec2{ XRES/3, 20 }), 0x000000_rgb .WithAlpha(150)); //dim the "Page X of Y" a little to make the CopyTextButton more noticeable g->BlendFilledRect(RectSized(Vec2{ XRES/3, WINDOWH-20 }, Vec2{ XRES/3, 20 }), 0x000000_rgb .WithAlpha(150)); //dim the "Page X of Y" a little to make the CopyTextButton more noticeable
activePreview = new PreviewController(saveID, 0, instantOpen, [this] { OpenSaveDone(); }); activePreview = new PreviewController(saveID, saveDate, instantOpen, [this] { OpenSaveDone(); }, std::move(thumbnail));
activePreview->GetView()->MakeActiveWindow();
}
void SearchController::OpenSave(int saveID, int saveDate)
{
delete activePreview;
Graphics * g = searchView->GetGraphics();
g->BlendFilledRect(RectSized(Vec2{ XRES/3, WINDOWH-20 }, Vec2{ XRES/3, 20 }), 0x000000_rgb .WithAlpha(150)); //dim the "Page X of Y" a little to make the CopyTextButton more noticeable
activePreview = new PreviewController(saveID, saveDate, instantOpen, [this] { OpenSaveDone(); });
activePreview->GetView()->MakeActiveWindow(); activePreview->GetView()->MakeActiveWindow();
} }

View File

@@ -8,6 +8,7 @@ class PreviewController;
class PreviewController; class PreviewController;
class SearchView; class SearchView;
class SearchModel; class SearchModel;
class VideoBuffer;
class SearchController class SearchController
{ {
private: private:
@@ -42,8 +43,7 @@ public:
void Selected(int saveID, bool selected); void Selected(int saveID, bool selected);
void SelectAllSaves(); void SelectAllSaves();
void InstantOpen(bool instant); void InstantOpen(bool instant);
void OpenSave(int saveID); void OpenSave(int saveID, int saveDate, std::unique_ptr<VideoBuffer> thumbnail);
void OpenSave(int saveID, int saveDate);
void Update(); void Update();
void ClearSelection(); void ClearSelection();
void RemoveSelected(); void RemoveSelected();

View File

@@ -562,7 +562,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
saves[i]); saves[i]);
saveButton->AddContextMenu(0); saveButton->AddContextMenu(0);
saveButton->SetActionCallback({ saveButton->SetActionCallback({
[this, saveButton] { c->OpenSave(saveButton->GetSave()->GetID(), saveButton->GetSave()->GetVersion()); }, [this, saveButton] { c->OpenSave(saveButton->GetSave()->GetID(), saveButton->GetSave()->GetVersion(), saveButton->CloneThumbnail()); },
[this, saveButton] { Search(String::Build("history:", saveButton->GetSave()->GetID())); }, [this, saveButton] { Search(String::Build("history:", saveButton->GetSave()->GetID())); },
[this, saveButton] { Search(String::Build("user:", saveButton->GetSave()->GetUserName().FromUtf8())); }, [this, saveButton] { Search(String::Build("user:", saveButton->GetSave()->GetUserName().FromUtf8())); },
[this, saveButton] { c->Selected(saveButton->GetSave()->GetID(), saveButton->GetSelected()); } [this, saveButton] { c->Selected(saveButton->GetSave()->GetID(), saveButton->GetSelected()); }