aboutsummaryrefslogtreecommitdiff
path: root/src/Chatbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chatbar.cpp')
-rw-r--r--src/Chatbar.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/Chatbar.cpp b/src/Chatbar.cpp
index 6a459cc..4273f2c 100644
--- a/src/Chatbar.cpp
+++ b/src/Chatbar.cpp
@@ -1,12 +1,13 @@
#include "../include/Chatbar.hpp"
+#include "../include/MessageBoard.hpp"
#include "../include/ResourceCache.hpp"
#include "../include/Settings.hpp"
-#include "../include/Channel.hpp"
-#include "../include/ChannelSidePanel.hpp"
+#include "../include/RoomSidePanel.hpp"
#include "../include/UsersSidePanel.hpp"
#include "../include/Command.hpp"
#include "../include/ColorScheme.hpp"
-#include "../include/Cache.hpp"
+#include <dchat/Storage.hpp>
+#include <dchat/Room.hpp>
#include <cmath>
#include <cstring>
#include <process.hpp>
@@ -26,7 +27,7 @@ namespace dchat
const float LINE_PADDING_SIDE = 20.0f;
const float LINE_HEIGHT = 1.0f;
- unordered_map<string, string> binds;
+ static unordered_map<string, string> binds;
Chatbar::Chatbar() :
text("", ResourceCache::getFont("fonts/Nunito-Regular.ttf"), FONT_SIZE * Settings::getScaling(), 0),
@@ -49,7 +50,7 @@ namespace dchat
ArgParseException(const string &errMsg) : std::runtime_error(errMsg) {}
};
- string stringRemoveQuotes(const StringView &str)
+ static string stringRemoveQuotes(const StringView &str)
{
string result;
result.reserve(str.size);
@@ -62,7 +63,7 @@ namespace dchat
return result;
}
- vector<string> splitCommandArgs(const StringView &str)
+ static vector<string> splitCommandArgs(const StringView &str)
{
vector<string> result;
ssize offset = 0;
@@ -155,7 +156,7 @@ namespace dchat
}
}
- void Chatbar::processEvent(const sf::Event &event, Cache &cache, Channel *channel)
+ void Chatbar::processEvent(const sf::Event &event, Cache *cache, std::shared_ptr<Room> room, MessageBoard *messageBoard)
{
if(!focused) return;
@@ -181,7 +182,10 @@ namespace dchat
else
{
replaceBinds(msg);
- channel->addMessage(msg);
+ if(room)
+ room->publishMessage(msg);
+ else
+ messageBoard->addOfflineUserMessage(std::move(msg), false);
}
text.setString("");
}
@@ -190,25 +194,25 @@ namespace dchat
}
}
- void Chatbar::draw(sf::RenderWindow &window, Cache &cache)
+ void Chatbar::draw(sf::RenderWindow &window, Cache *cache)
{
auto windowSize = window.getSize();
text.setCharacterSize(FONT_SIZE * Settings::getScaling());
const float fontHeight = text.getFont()->getLineSpacing(text.getCharacterSize());
- sf::RectangleShape lineShape(sf::Vector2f(floor(windowSize.x - ChannelSidePanel::getWidth() - LINE_PADDING_SIDE * Settings::getScaling() * 2.0f), LINE_HEIGHT));
+ sf::RectangleShape lineShape(sf::Vector2f(floor(windowSize.x - RoomSidePanel::getWidth() - LINE_PADDING_SIDE * Settings::getScaling() * 2.0f), LINE_HEIGHT));
lineShape.setFillColor(ColorScheme::getBackgroundColor() + sf::Color(10, 10, 10));
- lineShape.setPosition(ChannelSidePanel::getWidth() + LINE_PADDING_SIDE * Settings::getScaling(), floor(windowSize.y - getHeight()));
+ lineShape.setPosition(RoomSidePanel::getWidth() + LINE_PADDING_SIDE * Settings::getScaling(), floor(windowSize.y - getHeight()));
window.draw(lineShape);
- sf::Vector2f inputBackgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - PADDING_SIDE * Settings::getScaling() * 2.0f), floor(fontHeight * 1.7f + BOX_PADDING_Y * Settings::getScaling() * 2.0f));
- sf::Vector2f backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth()), floor(getHeight() - LINE_HEIGHT));
+ sf::Vector2f inputBackgroundSize(floor(windowSize.x - RoomSidePanel::getWidth() - PADDING_SIDE * Settings::getScaling() * 2.0f), floor(fontHeight * 1.7f + BOX_PADDING_Y * Settings::getScaling() * 2.0f));
+ sf::Vector2f backgroundSize(floor(windowSize.x - RoomSidePanel::getWidth()), floor(getHeight() - LINE_HEIGHT));
background.setSize(backgroundSize);
- background.setPosition(ChannelSidePanel::getWidth(), floor(windowSize.y - backgroundSize.y));
+ background.setPosition(RoomSidePanel::getWidth(), floor(windowSize.y - backgroundSize.y));
window.draw(background);
- sf::Vector2f inputBackgroundPos(floor(ChannelSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), floor(windowSize.y - inputBackgroundSize.y - PADDING_BOTTOM * Settings::getScaling()));
+ sf::Vector2f inputBackgroundPos(floor(RoomSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), floor(windowSize.y - inputBackgroundSize.y - PADDING_BOTTOM * Settings::getScaling()));
inputBackground.setSize(inputBackgroundSize);
inputBackground.setPosition(inputBackgroundPos);
text.setPosition(floor(inputBackgroundPos.x + BOX_PADDING_X), floor(inputBackgroundPos.y + inputBackgroundSize.y * 0.5f - fontHeight * 0.5f));
@@ -221,7 +225,7 @@ namespace dchat
sf::Vector2f Chatbar::getInputPosition(sf::RenderWindow &window)
{
auto windowSize = window.getSize();
- return { floor(ChannelSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), floor(windowSize.y - getInputSize(window).y - PADDING_BOTTOM * Settings::getScaling()) };
+ return { floor(RoomSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), floor(windowSize.y - getInputSize(window).y - PADDING_BOTTOM * Settings::getScaling()) };
}
sf::Vector2f Chatbar::getInputSize(sf::RenderWindow &window)
@@ -229,7 +233,7 @@ namespace dchat
auto windowSize = window.getSize();
const float fontSize = FONT_SIZE * Settings::getScaling();
const float fontHeight = ResourceCache::getFont("fonts/Nunito-Regular.ttf")->getLineSpacing(fontSize);
- return { floor(windowSize.x - ChannelSidePanel::getWidth() - PADDING_SIDE * Settings::getScaling() * 2.0f), floor(fontHeight * 1.7f + BOX_PADDING_Y * Settings::getScaling() * 2.0f) };
+ return { floor(windowSize.x - RoomSidePanel::getWidth() - PADDING_SIDE * Settings::getScaling() * 2.0f), floor(fontHeight * 1.7f + BOX_PADDING_Y * Settings::getScaling() * 2.0f) };
}
float Chatbar::getHeight()
@@ -246,7 +250,7 @@ namespace dchat
binds[key] = value;
if(updateFile)
- Cache::replaceBindsInFile(binds);
+ replaceBindsInFile(binds);
return true;
}
@@ -258,9 +262,17 @@ namespace dchat
binds.erase(it);
if(updateFile)
- Cache::replaceBindsInFile(binds);
+ replaceBindsInFile(binds);
return true;
}
+
+ void Chatbar::loadBindsFromFile()
+ {
+ dchat::loadBindsFromFile([](const std::string &key, const std::string &value)
+ {
+ binds[key] = value;
+ });
+ }
const unordered_map<string, string>& Chatbar::getBinds()
{