mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-16 13:58:43 +01:00
Give visual indication of vote/fav requests being in progress
This commit is contained in:
parent
09ba266165
commit
165ea90d6a
@ -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())
|
||||
|
@ -106,6 +106,7 @@ private:
|
||||
bool saveReuploadAllowed;
|
||||
ui::Button * downVoteButton;
|
||||
ui::Button * upVoteButton;
|
||||
void ResetVoteButtons();
|
||||
ui::Button * tagSimulationButton;
|
||||
ui::Button * clearSimButton;
|
||||
SplitButton * loginButton;
|
||||
|
@ -30,6 +30,7 @@ namespace ui
|
||||
ui::Colour BackgroundInactive;
|
||||
ui::Colour BackgroundActive;
|
||||
ui::Colour BackgroundDisabled;
|
||||
bool BackgroundPulse = false;
|
||||
|
||||
ui::Colour TextHover;
|
||||
ui::Colour TextInactive;
|
||||
|
@ -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 <cmath>
|
||||
#include <numbers>
|
||||
|
||||
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<float> * 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);
|
||||
|
@ -60,7 +60,11 @@ PreviewView::PreviewView(std::unique_ptr<VideoBuffer> 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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user