diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-21 08:44:23 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-05-21 08:44:25 +0200 |
commit | 8f275fa7ec9bf14c06cb72edb00bc9a2469d0458 (patch) | |
tree | 1b6c87ba14f08ff0337131fb539200d605368d8a | |
parent | f5aaf1b1cc94e28d4fa423a3d0b8ca286cf7f87d (diff) |
Improve online/offline users (fade offline users, ping on channel init)
-rw-r--r-- | include/Gif.hpp | 1 | ||||
-rw-r--r-- | src/Channel.cpp | 8 | ||||
-rw-r--r-- | src/Gif.cpp | 5 | ||||
-rw-r--r-- | src/MessageBoard.cpp | 1 | ||||
-rw-r--r-- | src/Text.cpp | 2 | ||||
-rw-r--r-- | src/UsersSidePanel.cpp | 12 |
6 files changed, 23 insertions, 6 deletions
diff --git a/include/Gif.hpp b/include/Gif.hpp index 1341049..ebcb5d4 100644 --- a/include/Gif.hpp +++ b/include/Gif.hpp @@ -34,6 +34,7 @@ namespace dchat sf::Vector2f getPosition() const; void setScale(const sf::Vector2f &scale); + void setColor(sf::Color color); void draw(sf::RenderTarget &target, const sf::RenderStates &renderStates = sf::RenderStates::Default); static bool isDataGif(const StringView &data); diff --git a/src/Channel.cpp b/src/Channel.cpp index 41233ad..5043665 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -52,7 +52,7 @@ namespace dchat u64 pingTimestamp = unsignedDeserializer.extract<u64>(); // TODO: A malicious peer can capture the packets and reply them after the user has reconnect and counter has reset, need to fix this somehow. // One solution is for the user to store the counter locally in file and continue using it when reconnecting - if(pingCounter > user->pingCounter) + if(pingTimestamp > user->pingTimestamp) { user->pingCounter = pingCounter; user->pingTimestamp = pingTimestamp; @@ -64,6 +64,12 @@ namespace dchat } return result; }); + + if(localUser->type == User::Type::ONLINE_LOCAL_USER) + { + auto onlineLocalUser = static_cast<OnlineLocalUser*>(localUser); + sendPing(onlineLocalUser->pingCounter + 1, database->getSyncedTimestampUtc().getCombined()); + } } } diff --git a/src/Gif.cpp b/src/Gif.cpp index 2bd18e8..6c18851 100644 --- a/src/Gif.cpp +++ b/src/Gif.cpp @@ -154,6 +154,11 @@ namespace dchat sprite.setScale(scale); } + void Gif::setColor(sf::Color color) + { + sprite.setColor(color); + } + void Gif::draw(sf::RenderTarget &target, const sf::RenderStates &renderState) { double timeElapsedMilli = (double)frameTimer.getElapsedTime().asMilliseconds(); diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index 2e92d7f..c75573a 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -208,6 +208,7 @@ namespace dchat auto gifSize = avatarResult.gif->getSize(); avatarResult.gif->setPosition(sf::Vector2f(floor(position.x), floor(position.y))); avatarResult.gif->setScale(sf::Vector2f(AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.x, AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.y)); + avatarResult.gif->setColor(sf::Color::White); avatarResult.gif->draw(window, circleShader); } } diff --git a/src/Text.cpp b/src/Text.cpp index 025cb92..0e24e73 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -955,6 +955,7 @@ namespace dchat contentByUrlResult.gif->setPosition(pos); contentByUrlResult.gif->setScale(sf::Vector2f(size.x / (float)gifSize.x * widthToHeightRatio, size.y / (float)gifSize.y)); + contentByUrlResult.gif->setColor(sf::Color::White); contentByUrlResult.gif->draw(target); break; } @@ -1004,6 +1005,7 @@ namespace dchat contentByUrlResult.gif->setPosition(pos); contentByUrlResult.gif->setScale(sf::Vector2f(imageHeight / (float)gifSize.x * widthToHeightRatio, imageHeight / (float)gifSize.y)); + contentByUrlResult.gif->setColor(sf::Color::White); contentByUrlResult.gif->draw(target); break; } diff --git a/src/UsersSidePanel.cpp b/src/UsersSidePanel.cpp index 035826f..6ddfbe2 100644 --- a/src/UsersSidePanel.cpp +++ b/src/UsersSidePanel.cpp @@ -24,7 +24,7 @@ namespace dchat const float PADDING_BOTTOM = 20.0f; const i64 USER_TIMEOUT_SEC = 10; - static void renderUser(Cache &cache, User *user, sf::Shader *circleShader, sf::RenderWindow &window, sf::Vector2f &position, const sf::Font *font, const float textHeight) + static void renderUser(Cache &cache, User *user, sf::Shader *circleShader, sf::RenderWindow &window, sf::Vector2f &position, const sf::Font *font, const float textHeight, bool isUserOnline) { // Max avatar size = 1mb const ContentByUrlResult avatarResult = cache.getContentByUrl(user->avatarUrl, 1024 * 1024); @@ -39,6 +39,7 @@ namespace dchat auto textureSize = avatarResult.texture->getSize(); sprite.setPosition(sf::Vector2f(floor(position.x), floor(position.y))); sprite.setScale(sf::Vector2f(AVATAR_DIAMETER * Settings::getScaling() / (float)textureSize.x, AVATAR_DIAMETER * Settings::getScaling() / (float)textureSize.y)); + sprite.setColor(isUserOnline ? sf::Color::White : sf::Color(255, 255, 255, 100)); window.draw(sprite, circleShader); } else if(avatarResult.cachedType == ContentByUrlResult::CachedType::GIF) @@ -46,6 +47,7 @@ namespace dchat auto gifSize = avatarResult.gif->getSize(); avatarResult.gif->setPosition(sf::Vector2f(floor(position.x), floor(position.y))); avatarResult.gif->setScale(sf::Vector2f(AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.x, AVATAR_DIAMETER * Settings::getScaling() / (float)gifSize.y)); + avatarResult.gif->setColor(isUserOnline ? sf::Color::White : sf::Color(255, 255, 255, 100)); avatarResult.gif->draw(window, circleShader); } } @@ -53,7 +55,7 @@ namespace dchat { sf::CircleShape avatarCircle(AVATAR_DIAMETER * 0.5f * Settings::getScaling(), 60 * Settings::getScaling()); avatarCircle.setPosition(sf::Vector2f(floor(position.x), floor(position.y))); - avatarCircle.setFillColor(ColorScheme::getBackgroundColor() + sf::Color(30, 30, 30)); + avatarCircle.setFillColor(isUserOnline ? ColorScheme::getBackgroundColor() + sf::Color(30, 30, 30) : ColorScheme::getBackgroundColor() * sf::Color(255, 255, 255, 100)); window.draw(avatarCircle); } @@ -61,7 +63,7 @@ namespace dchat sf::String str = sf::String::fromUtf8(user->getName().begin(), user->getName().end()); sf::Text text(str, *font, FONT_SIZE * Settings::getScaling()); text.setPosition(floor(position.x + (AVATAR_DIAMETER + AVATAR_PADDING_SIDE) * Settings::getScaling()), floor(position.y + AVATAR_DIAMETER * 0.5f - textHeight * 0.5f)); - text.setFillColor(sf::Color(15, 192, 252)); + text.setFillColor(isUserOnline ? sf::Color(15, 192, 252) : sf::Color(15, 192, 252, 100)); window.draw(text); position.y += ((AVATAR_DIAMETER + PADDING_BOTTOM) * Settings::getScaling()); } @@ -128,7 +130,7 @@ namespace dchat } if(isUserOnline) - renderUser(cache, user, circleShader, window, position, font, textHeight); + renderUser(cache, user, circleShader, window, position, font, textHeight, isUserOnline); } if(numOfflineUsers == 0) return; @@ -156,7 +158,7 @@ namespace dchat } if(!isUserOnline) - renderUser(cache, user, circleShader, window, position, font, textHeight); + renderUser(cache, user, circleShader, window, position, font, textHeight, isUserOnline); } } |