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
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
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)
{
activePreview = new PreviewController(saveID, saveDate, instant, [this] { OpenSaveDone(); });
activePreview = new PreviewController(saveID, saveDate, instant, [this] { OpenSaveDone(); }, nullptr);
ui::Engine::Ref().ShowWindow(activePreview->GetView());
}
@ -1221,7 +1221,7 @@ void GameController::OpenSavePreview()
{
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());
}
}

View File

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

View File

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

View File

@ -75,6 +75,11 @@ public:
void DoAltAction2();
void DoSelection();
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:
bool isButtonDown, state, isMouseInside, selected, selectable;
};

View File

@ -7,19 +7,20 @@
#include "client/SaveInfo.h"
#include "client/GameSave.h"
#include "common/platform/Platform.h"
#include "graphics/Graphics.h"
#include "gui/dialogues/ErrorMessage.h"
#include "gui/dialogues/InformationMessage.h"
#include "gui/login/LoginController.h"
#include "gui/login/LoginView.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),
loginWindow(NULL),
HasExited(false)
{
previewModel = new PreviewModel();
previewView = new PreviewView();
previewView = new PreviewView(std::move(thumbnail));
previewModel->AddObserver(previewView);
previewView->AttachController(this);
previewModel->SetDoOpen(instant);

View File

@ -3,6 +3,7 @@
#include <functional>
#include <memory>
class VideoBuffer;
class SaveInfo;
class LoginController;
class PreviewModel;
@ -18,7 +19,7 @@ public:
inline int SaveID() { return saveId; }
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 DoOpen();
void OpenInBrowser();

View File

@ -33,9 +33,8 @@
# undef GetUserName // dammit windows
#endif
PreviewView::PreviewView():
PreviewView::PreviewView(std::unique_ptr<VideoBuffer> newSavePreview):
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+210, (YRES/2)+150)),
savePreview(nullptr),
submitCommentButton(NULL),
addCommentBox(NULL),
commentWarningLabel(NULL),
@ -48,6 +47,11 @@ PreviewView::PreviewView():
commentBoxHeight(20),
commentHelpText(false)
{
if (newSavePreview)
{
newSavePreview->Resize(RES / 2, true);
savePreview = std::move(newSavePreview);
}
showAvatars = ui::Engine::Ref().ShowAvatars;
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)
{
auto *save = sender->GetSaveInfo();
savePreview = nullptr;
if(save)
{
votesUp = save->votesUp;

View File

@ -66,7 +66,7 @@ class PreviewView: public ui::Window
void CheckComment();
public:
void AttachController(PreviewController * controller);
PreviewView();
PreviewView(std::unique_ptr<VideoBuffer> newSavePreviev);
void NotifySaveChanged(PreviewModel * sender);
void NotifyCommentsChanged(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;
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, 0, instantOpen, [this] { OpenSaveDone(); });
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 = new PreviewController(saveID, saveDate, instantOpen, [this] { OpenSaveDone(); }, std::move(thumbnail));
activePreview->GetView()->MakeActiveWindow();
}

View File

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

View File

@ -562,7 +562,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
saves[i]);
saveButton->AddContextMenu(0);
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("user:", saveButton->GetSave()->GetUserName().FromUtf8())); },
[this, saveButton] { c->Selected(saveButton->GetSave()->GetID(), saveButton->GetSelected()); }