mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-09 09:56:35 +02:00
Give visual indication of vote/fav requests being in progress
This commit is contained in:
@@ -267,20 +267,22 @@ GameView::GameView():
|
|||||||
SetSaveButtonTooltips();
|
SetSaveButtonTooltips();
|
||||||
AddComponent(saveSimulationButton);
|
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->SetIcon(IconVoteUp);
|
||||||
upVoteButton->Appearance.Margin.Top+=2;
|
upVoteButton->Appearance.Margin.Top+=2;
|
||||||
upVoteButton->Appearance.Margin.Left+=2;
|
upVoteButton->Appearance.Margin.Left+=2;
|
||||||
currentX+=38;
|
currentX+=38;
|
||||||
AddComponent(upVoteButton);
|
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->SetIcon(IconVoteDown);
|
||||||
downVoteButton->Appearance.Margin.Bottom+=2;
|
downVoteButton->Appearance.Margin.Bottom+=2;
|
||||||
downVoteButton->Appearance.Margin.Left+=2;
|
downVoteButton->Appearance.Margin.Left+=2;
|
||||||
currentX+=16;
|
currentX+=16;
|
||||||
AddComponent(downVoteButton);
|
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 = 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->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tagSimulationButton->SetIcon(IconTag);
|
tagSimulationButton->SetIcon(IconTag);
|
||||||
@@ -779,9 +781,18 @@ void GameView::NotifyInfoTipChanged(GameModel * sender)
|
|||||||
infoTipPresence = 120;
|
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)
|
void GameView::NotifySaveChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
saveReuploadAllowed = true;
|
saveReuploadAllowed = true;
|
||||||
|
ResetVoteButtons();
|
||||||
if (sender->GetSave())
|
if (sender->GetSave())
|
||||||
{
|
{
|
||||||
if (introText > 50)
|
if (introText > 50)
|
||||||
@@ -794,7 +805,9 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
saveSimulationButton->SetShowSplit(false);
|
saveSimulationButton->SetShowSplit(false);
|
||||||
reloadButton->Enabled = true;
|
reloadButton->Enabled = true;
|
||||||
upVoteButton->Enabled = sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetUser().Username != sender->GetSave()->GetUserName();
|
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)
|
|
||||||
|
auto upVoteButtonColor = [this](bool active) {
|
||||||
|
if(active)
|
||||||
{
|
{
|
||||||
upVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 128, 30, 255));
|
upVoteButton->Appearance.BackgroundHover = (ui::Colour(20, 128, 30, 255));
|
||||||
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 108, 10, 255));
|
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 108, 10, 255));
|
||||||
@@ -806,9 +819,13 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
||||||
upVoteButton->Appearance.BackgroundDisabled = (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;
|
downVoteButton->Enabled = upVoteButton->Enabled;
|
||||||
if (sender->GetSave()->GetID() && sender->GetUser().UserID && sender->GetSave()->GetVote()==-1)
|
auto downVoteButtonColor = [this](bool active) {
|
||||||
|
if (active)
|
||||||
{
|
{
|
||||||
downVoteButton->Appearance.BackgroundHover = (ui::Colour(128, 20, 30, 255));
|
downVoteButton->Appearance.BackgroundHover = (ui::Colour(128, 20, 30, 255));
|
||||||
downVoteButton->Appearance.BackgroundInactive = (ui::Colour(108, 0, 10, 255));
|
downVoteButton->Appearance.BackgroundInactive = (ui::Colour(108, 0, 10, 255));
|
||||||
@@ -820,6 +837,9 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
downVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
downVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
||||||
downVoteButton->Appearance.BackgroundDisabled = (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)
|
if (sender->GetUser().UserID)
|
||||||
{
|
{
|
||||||
@@ -832,15 +852,18 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100);
|
downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender->GetSave()->GetVote() == 1)
|
upVoteButton->SetActionCallback({ [this, upVoteButtonColor, upvoted] {
|
||||||
upVoteButton->SetActionCallback({ [this] { c->Vote(0); } });
|
upVoteButtonColor(true);
|
||||||
else
|
upVoteButton->SetToolTip("Saving vote...");
|
||||||
upVoteButton->SetActionCallback({ [this] { c->Vote(1); } });
|
upVoteButton->Appearance.BackgroundPulse = true;
|
||||||
|
c->Vote(upvoted ? 0 : 1);
|
||||||
if (sender->GetSave()->GetVote() == -1)
|
} });
|
||||||
downVoteButton->SetActionCallback({ [this] { c->Vote(0) ;} });
|
downVoteButton->SetActionCallback({ [this, downVoteButtonColor, downvoted] {
|
||||||
else
|
downVoteButtonColor(true);
|
||||||
downVoteButton->SetActionCallback({ [this] { c->Vote(-1) ;} });
|
downVoteButton->SetToolTip("Saving vote...");
|
||||||
|
downVoteButton->Appearance.BackgroundPulse = true;
|
||||||
|
c->Vote(downvoted ? 0 : -1);
|
||||||
|
} });
|
||||||
|
|
||||||
tagSimulationButton->Enabled = sender->GetSave()->GetID();
|
tagSimulationButton->Enabled = sender->GetSave()->GetID();
|
||||||
if (sender->GetSave()->GetID())
|
if (sender->GetSave()->GetID())
|
||||||
|
@@ -106,6 +106,7 @@ private:
|
|||||||
bool saveReuploadAllowed;
|
bool saveReuploadAllowed;
|
||||||
ui::Button * downVoteButton;
|
ui::Button * downVoteButton;
|
||||||
ui::Button * upVoteButton;
|
ui::Button * upVoteButton;
|
||||||
|
void ResetVoteButtons();
|
||||||
ui::Button * tagSimulationButton;
|
ui::Button * tagSimulationButton;
|
||||||
ui::Button * clearSimButton;
|
ui::Button * clearSimButton;
|
||||||
SplitButton * loginButton;
|
SplitButton * loginButton;
|
||||||
|
@@ -30,6 +30,7 @@ namespace ui
|
|||||||
ui::Colour BackgroundInactive;
|
ui::Colour BackgroundInactive;
|
||||||
ui::Colour BackgroundActive;
|
ui::Colour BackgroundActive;
|
||||||
ui::Colour BackgroundDisabled;
|
ui::Colour BackgroundDisabled;
|
||||||
|
bool BackgroundPulse = false;
|
||||||
|
|
||||||
ui::Colour TextHover;
|
ui::Colour TextHover;
|
||||||
ui::Colour TextInactive;
|
ui::Colour TextInactive;
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
#include "gui/interface/Button.h"
|
#include "gui/interface/Button.h"
|
||||||
|
|
||||||
#include "gui/interface/Window.h"
|
#include "gui/interface/Window.h"
|
||||||
|
#include "gui/interface/Engine.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "Colour.h"
|
#include "Colour.h"
|
||||||
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@@ -113,6 +114,10 @@ void Button::Draw(const Point& screenPos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bgColour = Appearance.BackgroundInactive;
|
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);
|
g->BlendFilledRect(RectSized(Position + Vec2{ 1, 1 }, Size - Vec2{ 2, 2 }), backgroundColour);
|
||||||
if(Appearance.Border == 1)
|
if(Appearance.Border == 1)
|
||||||
g->BlendRect(RectSized(Position, Size), borderColour);
|
g->BlendRect(RectSized(Position, Size), borderColour);
|
||||||
|
@@ -60,7 +60,11 @@ PreviewView::PreviewView(std::unique_ptr<VideoBuffer> newSavePreview):
|
|||||||
favButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
favButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
favButton->SetTogglable(true);
|
favButton->SetTogglable(true);
|
||||||
favButton->SetIcon(IconFavourite);
|
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;
|
favButton->Enabled = Client::Ref().GetAuthUser().UserID?true:false;
|
||||||
AddComponent(favButton);
|
AddComponent(favButton);
|
||||||
|
|
||||||
@@ -530,6 +534,7 @@ void PreviewView::UpdateLoadStatus()
|
|||||||
|
|
||||||
void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
||||||
{
|
{
|
||||||
|
favButton->Appearance.BackgroundPulse = false;
|
||||||
auto *save = sender->GetSaveInfo();
|
auto *save = sender->GetSaveInfo();
|
||||||
if(save)
|
if(save)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user