R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Game::ChatWidget Class Reference

In-game chat widget. More...

#include <ChatWidget.hpp>

Collaboration diagram for Game::ChatWidget:
Collaboration graph

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
 

Detailed Description

In-game chat widget.

Displays chat messages in bottom-right corner with:

  • Scrollable message history (limited buffer)
  • Text input field with character limit
  • Auto-scroll to latest message
  • Only visible in waiting room or in-game

Definition at line 44 of file ChatWidget.hpp.

Constructor & Destructor Documentation

◆ ChatWidget()

Game::ChatWidget::ChatWidget ( UI::IUIFactory uiFactory,
Graphics::IGraphics graphics 
)
explicit

Definition at line 14 of file ChatWidget.cpp.

◆ ~ChatWidget()

Game::ChatWidget::~ChatWidget ( )
default

Member Function Documentation

◆ AddMessage()

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.

◆ ClearMessages()

void Game::ChatWidget::ClearMessages ( )

Clear all messages.

Definition at line 106 of file ChatWidget.cpp.

References _messages.

◆ FormatMessage()

std::string Game::ChatWidget::FormatMessage ( const ChatMessageData msg)
private

Definition at line 164 of file ChatWidget.cpp.

References Game::ChatMessageData::message, and Game::ChatMessageData::playerName.

Referenced by Render().

◆ Initialize()

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.

Here is the call graph for this function:

◆ IsVisible()

bool Game::ChatWidget::IsVisible ( ) const
inline

Check if widget is visible.

Definition at line 88 of file ChatWidget.hpp.

References _visible.

◆ OnTextChanged()

void Game::ChatWidget::OnTextChanged ( const std::string &  text)
private

Definition at line 122 of file ChatWidget.cpp.

Referenced by Initialize().

◆ Render()

◆ SendMessage()

void Game::ChatWidget::SendMessage ( )
private

Definition at line 127 of file ChatWidget.cpp.

References _onMessageSent, _textInput, LOG_DEBUG, and LOG_ERROR.

Referenced by Update().

◆ SetOnMessageSent()

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.

◆ SetPosition()

void Game::ChatWidget::SetPosition ( float  x,
float  y 
)

Set widget position.

Definition at line 117 of file ChatWidget.cpp.

References _posX, and _posY.

◆ SetVisible()

void Game::ChatWidget::SetVisible ( bool  visible)

Set widget visibility.

Definition at line 110 of file ChatWidget.cpp.

References _textInput, and _visible.

◆ Update()

void Game::ChatWidget::Update ( )

Update the chat widget.

Definition at line 44 of file ChatWidget.cpp.

References _textInput, _visible, and SendMessage().

Here is the call graph for this function:

Member Data Documentation

◆ _graphics

Graphics::IGraphics& Game::ChatWidget::_graphics
private

Definition at line 101 of file ChatWidget.hpp.

Referenced by Render().

◆ _messages

std::deque<ChatMessageData> Game::ChatWidget::_messages
private

Definition at line 106 of file ChatWidget.hpp.

Referenced by AddMessage(), ClearMessages(), and Render().

◆ _onMessageSent

std::function<void(const std::string &)> Game::ChatWidget::_onMessageSent
private

Definition at line 104 of file ChatWidget.hpp.

Referenced by SendMessage(), and SetOnMessageSent().

◆ _posX

float Game::ChatWidget::_posX = 0.0f
private

Definition at line 108 of file ChatWidget.hpp.

Referenced by Render(), and SetPosition().

◆ _posY

float Game::ChatWidget::_posY = 0.0f
private

Definition at line 109 of file ChatWidget.hpp.

Referenced by Render(), and SetPosition().

◆ _textInput

std::shared_ptr<UI::ITextInput> Game::ChatWidget::_textInput
private

Definition at line 103 of file ChatWidget.hpp.

Referenced by Initialize(), Render(), SendMessage(), SetVisible(), and Update().

◆ _uiFactory

UI::IUIFactory& Game::ChatWidget::_uiFactory
private

Definition at line 100 of file ChatWidget.hpp.

Referenced by Initialize().

◆ _visible

bool Game::ChatWidget::_visible = false
private

Definition at line 107 of file ChatWidget.hpp.

Referenced by IsVisible(), Render(), SetVisible(), and Update().

◆ INPUT_HEIGHT

constexpr float Game::ChatWidget::INPUT_HEIGHT = 26.0f
staticconstexprprivate

Definition at line 117 of file ChatWidget.hpp.

Referenced by Initialize(), and Render().

◆ MAX_CHAR_PER_MESSAGE

constexpr size_t Game::ChatWidget::MAX_CHAR_PER_MESSAGE = 256
staticconstexprprivate

Definition at line 113 of file ChatWidget.hpp.

Referenced by Initialize().

◆ MAX_MESSAGE_BUFFER

constexpr size_t Game::ChatWidget::MAX_MESSAGE_BUFFER = 50
staticconstexprprivate

Definition at line 112 of file ChatWidget.hpp.

Referenced by AddMessage().

◆ MAX_VISIBLE_MESSAGES

constexpr size_t Game::ChatWidget::MAX_VISIBLE_MESSAGES = 6
staticconstexprprivate

Definition at line 114 of file ChatWidget.hpp.

Referenced by Render().

◆ MESSAGE_LINE_HEIGHT

constexpr float Game::ChatWidget::MESSAGE_LINE_HEIGHT = 16.0f
staticconstexprprivate

Definition at line 119 of file ChatWidget.hpp.

Referenced by Render().

◆ MESSAGE_SPACING

constexpr float Game::ChatWidget::MESSAGE_SPACING = 3.0f
staticconstexprprivate

Definition at line 118 of file ChatWidget.hpp.

Referenced by Render().

◆ PADDING

constexpr float Game::ChatWidget::PADDING = 8.0f
staticconstexprprivate

Definition at line 120 of file ChatWidget.hpp.

Referenced by Initialize(), and Render().

◆ WIDGET_HEIGHT

constexpr float Game::ChatWidget::WIDGET_HEIGHT = 180.0f
staticconstexprprivate

Definition at line 116 of file ChatWidget.hpp.

Referenced by Render().

◆ WIDGET_WIDTH

constexpr float Game::ChatWidget::WIDGET_WIDTH = 280.0f
staticconstexprprivate

Definition at line 115 of file ChatWidget.hpp.

Referenced by Initialize(), and Render().


The documentation for this class was generated from the following files: