From 165ea90d6a0e2b6464beab0e923db151908a3c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 16 Jan 2025 12:58:24 +0100 Subject: [PATCH] Give visual indication of vote/fav requests being in progress --- src/gui/game/GameView.cpp | 93 ++++++++++++++++++++------------- src/gui/game/GameView.h | 1 + src/gui/interface/Appearance.h | 1 + src/gui/interface/Button.cpp | 9 +++- src/gui/preview/PreviewView.cpp | 7 ++- 5 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 7db05e05a..c9b467a42 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -267,20 +267,22 @@ GameView::GameView(): SetSaveButtonTooltips(); AddComponent(saveSimulationButton); - upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(39, 15), "", "Like this save"); + upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(39, 15), "", ""); upVoteButton->SetIcon(IconVoteUp); upVoteButton->Appearance.Margin.Top+=2; upVoteButton->Appearance.Margin.Left+=2; currentX+=38; AddComponent(upVoteButton); - downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(15, 15), "", "Dislike this save"); + downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(15, 15), "", ""); downVoteButton->SetIcon(IconVoteDown); downVoteButton->Appearance.Margin.Bottom+=2; downVoteButton->Appearance.Margin.Left+=2; currentX+=16; AddComponent(downVoteButton); + ResetVoteButtons(); + tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(WINDOWW - 402, 15), "[no tags set]", "Add simulation tags"); tagSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tagSimulationButton->SetIcon(IconTag); @@ -779,9 +781,18 @@ void GameView::NotifyInfoTipChanged(GameModel * sender) infoTipPresence = 120; } +void GameView::ResetVoteButtons() +{ + upVoteButton->SetToolTip("Like this save"); + downVoteButton->SetToolTip("Dislike this save"); + upVoteButton->Appearance.BackgroundPulse = false; + downVoteButton->Appearance.BackgroundPulse = false; +} + void GameView::NotifySaveChanged(GameModel * sender) { saveReuploadAllowed = true; + ResetVoteButtons(); if (sender->GetSave()) { if (introText > 50) @@ -794,32 +805,41 @@ void GameView::NotifySaveChanged(GameModel * sender) saveSimulationButton->SetShowSplit(false); reloadButton->Enabled = true; upVoteButton->Enabled = sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetUser().Username != sender->GetSave()->GetUserName(); - if(sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetSave()->GetVote()==1) - { - upVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 128, 30, 255)); - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 108, 10, 255)); - upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 108, 10, 255)); - } - else - { - upVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 20, 20)); - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); - upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); - } + + auto upVoteButtonColor = [this](bool active) { + if(active) + { + upVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 128, 30, 255)); + upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 108, 10, 255)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 108, 10, 255)); + } + else + { + upVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 20, 20)); + upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + } + }; + auto upvoted = sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetSave()->GetVote() == 1; + upVoteButtonColor(upvoted); downVoteButton->Enabled = upVoteButton->Enabled; - if (sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetSave()->GetVote()==-1) - { - downVoteButton->Appearance.BackgroundHover = (ui::Colour(128, 20, 30, 255)); - downVoteButton->Appearance.BackgroundInactive = (ui::Colour(108, 0, 10, 255)); - downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(108, 0, 10, 255)); - } - else - { - downVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 20, 20)); - downVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); - downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); - } + auto downVoteButtonColor = [this](bool active) { + if (active) + { + downVoteButton->Appearance.BackgroundHover = (ui::Colour(128, 20, 30, 255)); + downVoteButton->Appearance.BackgroundInactive = (ui::Colour(108, 0, 10, 255)); + downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(108, 0, 10, 255)); + } + else + { + downVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 20, 20)); + downVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + } + }; + auto downvoted = sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetSave()->GetVote() == -1; + downVoteButtonColor(downvoted); if (sender->GetUser().UserID) { @@ -832,15 +852,18 @@ void GameView::NotifySaveChanged(GameModel * sender) downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100); } - if (sender->GetSave()->GetVote() == 1) - upVoteButton->SetActionCallback({ [this] { c->Vote(0); } }); - else - upVoteButton->SetActionCallback({ [this] { c->Vote(1); } }); - - if (sender->GetSave()->GetVote() == -1) - downVoteButton->SetActionCallback({ [this] { c->Vote(0) ;} }); - else - downVoteButton->SetActionCallback({ [this] { c->Vote(-1) ;} }); + upVoteButton->SetActionCallback({ [this, upVoteButtonColor, upvoted] { + upVoteButtonColor(true); + upVoteButton->SetToolTip("Saving vote..."); + upVoteButton->Appearance.BackgroundPulse = true; + c->Vote(upvoted ? 0 : 1); + } }); + downVoteButton->SetActionCallback({ [this, downVoteButtonColor, downvoted] { + downVoteButtonColor(true); + downVoteButton->SetToolTip("Saving vote..."); + downVoteButton->Appearance.BackgroundPulse = true; + c->Vote(downvoted ? 0 : -1); + } }); tagSimulationButton->Enabled = sender->GetSave()->GetID(); if (sender->GetSave()->GetID()) diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 7528d6187..87eb73aac 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -106,6 +106,7 @@ private: bool saveReuploadAllowed; ui::Button * downVoteButton; ui::Button * upVoteButton; + void ResetVoteButtons(); ui::Button * tagSimulationButton; ui::Button * clearSimButton; SplitButton * loginButton; diff --git a/src/gui/interface/Appearance.h b/src/gui/interface/Appearance.h index a82fd3ce6..54c8a315c 100644 --- a/src/gui/interface/Appearance.h +++ b/src/gui/interface/Appearance.h @@ -30,6 +30,7 @@ namespace ui ui::Colour BackgroundInactive; ui::Colour BackgroundActive; ui::Colour BackgroundDisabled; + bool BackgroundPulse = false; ui::Colour TextHover; ui::Colour TextInactive; diff --git a/src/gui/interface/Button.cpp b/src/gui/interface/Button.cpp index 8319ce2a7..5392cfff6 100644 --- a/src/gui/interface/Button.cpp +++ b/src/gui/interface/Button.cpp @@ -1,10 +1,11 @@ #include "gui/interface/Button.h" - #include "gui/interface/Window.h" - +#include "gui/interface/Engine.h" #include "graphics/Graphics.h" #include "Misc.h" #include "Colour.h" +#include +#include namespace ui { @@ -113,6 +114,10 @@ void Button::Draw(const Point& screenPos) } bgColour = Appearance.BackgroundInactive; + if (Appearance.BackgroundPulse) + { + backgroundColour.Alpha = uint8_t(backgroundColour.Alpha * ((std::sin(Engine::Ref().LastTick() / 1000.f * std::numbers::pi_v * 2.f) + 1.f) / 2.f)); + } g->BlendFilledRect(RectSized(Position + Vec2{ 1, 1 }, Size - Vec2{ 2, 2 }), backgroundColour); if(Appearance.Border == 1) g->BlendRect(RectSized(Position, Size), borderColour); diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 9b0824b74..113a1a8d7 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -60,7 +60,11 @@ PreviewView::PreviewView(std::unique_ptr newSavePreview): favButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; favButton->SetTogglable(true); favButton->SetIcon(IconFavourite); - favButton->SetActionCallback({ [this] { c->FavouriteSave(); } }); + favButton->SetActionCallback({ [this] { + favButton->SetToggleState(true); + favButton->Appearance.BackgroundPulse = true; + c->FavouriteSave(); + } }); favButton->Enabled = Client::Ref().GetAuthUser().UserID?true:false; AddComponent(favButton); @@ -530,6 +534,7 @@ void PreviewView::UpdateLoadStatus() void PreviewView::NotifySaveChanged(PreviewModel * sender) { + favButton->Appearance.BackgroundPulse = false; auto *save = sender->GetSaveInfo(); if(save) {