|
R-Type
Distributed multiplayer game engine in C++
|
In-game chat widget. More...
#include <ChatWidget.hpp>

Public Member Functions | |
| ChatWidget (UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics) | |
| ~ChatWidget ()=default | |
| void | Initialize () |
| Initialize the chat widget. | |
| void | Update () |
| Update the chat widget. | |
| void | Render () |
| Render the chat widget. | |
| void | SetOnMessageSent (std::function< void(const std::string &)> callback) |
| Set callback for when a message is sent. | |
| void | AddMessage (uint32_t playerId, const std::string &playerName, const std::string &message, uint64_t timestamp) |
| Add a message to the chat history. | |
| void | ClearMessages () |
| Clear all messages. | |
| void | SetVisible (bool visible) |
| Set widget visibility. | |
| bool | IsVisible () const |
| Check if widget is visible. | |
| void | SetPosition (float x, float y) |
| Set widget position. | |
Private Member Functions | |
| void | OnTextChanged (const std::string &text) |
| void | SendMessage () |
| std::string | FormatMessage (const ChatMessageData &msg) |
Private Attributes | |
| UI::IUIFactory & | _uiFactory |
| Graphics::IGraphics & | _graphics |
| std::shared_ptr< UI::ITextInput > | _textInput |
| std::function< void(const std::string &)> | _onMessageSent |
| std::deque< ChatMessageData > | _messages |
| bool | _visible = false |
| float | _posX = 0.0f |
| float | _posY = 0.0f |
Static Private Attributes | |
| static constexpr size_t | MAX_MESSAGE_BUFFER = 50 |
| static constexpr size_t | MAX_CHAR_PER_MESSAGE = 256 |
| static constexpr size_t | MAX_VISIBLE_MESSAGES = 6 |
| static constexpr float | WIDGET_WIDTH = 280.0f |
| static constexpr float | WIDGET_HEIGHT = 180.0f |
| static constexpr float | INPUT_HEIGHT = 26.0f |
| static constexpr float | MESSAGE_SPACING = 3.0f |
| static constexpr float | MESSAGE_LINE_HEIGHT = 16.0f |
| static constexpr float | PADDING = 8.0f |
In-game chat widget.
Displays chat messages in bottom-right corner with:
Definition at line 44 of file ChatWidget.hpp.
|
explicit |
Definition at line 14 of file ChatWidget.cpp.
|
default |
| void Game::ChatWidget::AddMessage | ( | uint32_t | playerId, |
| const std::string & | playerName, | ||
| const std::string & | message, | ||
| uint64_t | timestamp | ||
| ) |
Add a message to the chat history.
Definition at line 94 of file ChatWidget.cpp.
References _messages, LOG_DEBUG, and MAX_MESSAGE_BUFFER.
| void Game::ChatWidget::ClearMessages | ( | ) |
|
private |
Definition at line 164 of file ChatWidget.cpp.
References Game::ChatMessageData::message, and Game::ChatMessageData::playerName.
Referenced by Render().
| void Game::ChatWidget::Initialize | ( | ) |
Initialize the chat widget.
Definition at line 17 of file ChatWidget.cpp.
References _textInput, _uiFactory, UI::IUIFactory::CreateTextInput(), INPUT_HEIGHT, LOG_ERROR, LOG_INFO, MAX_CHAR_PER_MESSAGE, OnTextChanged(), PADDING, and WIDGET_WIDTH.

|
inline |
|
private |
Definition at line 122 of file ChatWidget.cpp.
Referenced by Initialize().
| void Game::ChatWidget::Render | ( | ) |
Render the chat widget.
Definition at line 57 of file ChatWidget.cpp.
References _graphics, _messages, _posX, _posY, _textInput, _visible, Graphics::IGraphics::DrawRectangle(), Graphics::IGraphics::DrawRectangleLines(), Graphics::IGraphics::DrawText(), FormatMessage(), INPUT_HEIGHT, MAX_VISIBLE_MESSAGES, MESSAGE_LINE_HEIGHT, MESSAGE_SPACING, PADDING, WIDGET_HEIGHT, and WIDGET_WIDTH.

|
private |
Definition at line 127 of file ChatWidget.cpp.
References _onMessageSent, _textInput, LOG_DEBUG, and LOG_ERROR.
Referenced by Update().
| void Game::ChatWidget::SetOnMessageSent | ( | std::function< void(const std::string &)> | callback | ) |
Set callback for when a message is sent.
Definition at line 90 of file ChatWidget.cpp.
References _onMessageSent.
| void Game::ChatWidget::SetPosition | ( | float | x, |
| float | y | ||
| ) |
| void Game::ChatWidget::SetVisible | ( | bool | visible | ) |
Set widget visibility.
Definition at line 110 of file ChatWidget.cpp.
References _textInput, and _visible.
| void Game::ChatWidget::Update | ( | ) |
Update the chat widget.
Definition at line 44 of file ChatWidget.cpp.
References _textInput, _visible, and SendMessage().

|
private |
Definition at line 101 of file ChatWidget.hpp.
Referenced by Render().
|
private |
Definition at line 106 of file ChatWidget.hpp.
Referenced by AddMessage(), ClearMessages(), and Render().
|
private |
Definition at line 104 of file ChatWidget.hpp.
Referenced by SendMessage(), and SetOnMessageSent().
|
private |
Definition at line 108 of file ChatWidget.hpp.
Referenced by Render(), and SetPosition().
|
private |
Definition at line 109 of file ChatWidget.hpp.
Referenced by Render(), and SetPosition().
|
private |
Definition at line 103 of file ChatWidget.hpp.
Referenced by Initialize(), Render(), SendMessage(), SetVisible(), and Update().
|
private |
Definition at line 100 of file ChatWidget.hpp.
Referenced by Initialize().
|
private |
Definition at line 107 of file ChatWidget.hpp.
Referenced by IsVisible(), Render(), SetVisible(), and Update().
|
staticconstexprprivate |
Definition at line 117 of file ChatWidget.hpp.
Referenced by Initialize(), and Render().
|
staticconstexprprivate |
Definition at line 113 of file ChatWidget.hpp.
Referenced by Initialize().
|
staticconstexprprivate |
Definition at line 112 of file ChatWidget.hpp.
Referenced by AddMessage().
|
staticconstexprprivate |
Definition at line 114 of file ChatWidget.hpp.
Referenced by Render().
|
staticconstexprprivate |
Definition at line 119 of file ChatWidget.hpp.
Referenced by Render().
|
staticconstexprprivate |
Definition at line 118 of file ChatWidget.hpp.
Referenced by Render().
|
staticconstexprprivate |
Definition at line 120 of file ChatWidget.hpp.
Referenced by Initialize(), and Render().
|
staticconstexprprivate |
Definition at line 116 of file ChatWidget.hpp.
Referenced by Render().
|
staticconstexprprivate |
Definition at line 115 of file ChatWidget.hpp.
Referenced by Initialize(), and Render().