OpenTTD Source: src/network/network_chat_gui.cpp File Reference

OpenTTD Source 15.0-beta1

Data Structures | Functions | Variables
network_chat_gui.cpp File Reference

GUI for handling chat messages. More...

`#include "../stdafx.h"`
`#include "../strings_func.h"`
`#include "../autocompletion.h"`
`#include "../blitter/factory.hpp"`
`#include "../console_func.h"`
`#include "../video/video_driver.hpp"`
`#include "../querystring_gui.h"`
`#include "../town.h"`
`#include "../window_func.h"`
`#include "../toolbar_gui.h"`
`#include "../core/geometry_func.hpp"`
`#include "../zoom_func.h"`
`#include "../timer/timer.h"`
`#include "../timer/timer_window.h"`
`#include "network.h"`
`#include "network_client.h"`
`#include "network_base.h"`
`#include "../widgets/network_chat_widget.h"`
`#include "table/strings.h"`
`#include "../safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | ChatMessage
| Container for a message. More...
class | NetworkChatAutoCompletion
struct | NetworkChatWindow
| Window to enter the chat message in. More...

## Functions
static bool | HaveChatMessages (bool show_all)
| Test if there are any chat messages to display.
void CDECL | NetworkAddChatMessage (TextColour colour, uint duration, const std::string &message)
| Add a text message to the 'chat window' to be shown.
void | NetworkReInitChatBoxSize ()
| Initialize all font-dependent chat box sizes.
void | NetworkInitChatMessage ()
| Initialize all buffers of the chat visualisation.
void | NetworkUndrawChatMessage ()
| Hide the chatbox.
void | NetworkDrawChatMessage ()
| Draw the chat message-box.
static void | SendChat (const std::string &buf, DestType type, int dest)
| Send an actual chat message.
void | ShowNetworkChatQueryWindow (DestType type, int dest)
| Show the chat window.

## Variables
static const uint | NETWORK_CHAT_LINE_SPACING = 3
| Spacing between chat lines.
static std::deque< ChatMessage > | _chatmsg_list
| The actual chat message list.
static bool | _chatmessage_dirty = false
| Does the chat message need repainting?
static bool | _chatmessage_visible = false
| Is a chat message visible.
static uint | MAX_CHAT_MESSAGES = 0
| The limit of chat messages to show.
static std::chrono::steady_clock::time_point | _chatmessage_dirty_time
| Time the chat history was marked dirty.
static PointDimension | _chatmsg_box
| The chatbox grows from the bottom so the coordinates are pixels from the left and pixels from the bottom.
static ReusableBuffer< uint8_t > | _chatmessage_backup
| Backup in case text is moved.
static IntervalTimer< TimerWindow > | network_message_expired_interval (std::chrono::seconds(1), [](auto) { auto now=std::chrono::steady_clock::now();for(auto &cmsg :_chatmsg_list) { if(now > cmsg.remove_time &&_chatmessage_dirty_time< cmsg.remove_time) { _chatmessage_dirty_time=now;_chatmessage_dirty=true;break;} } })
| Check if a message is expired on a regular interval.
static constexpr NWidgetPart | _nested_chat_window_widgets []
| The widgets of the chat window.
static WindowDesc | _chat_window_desc (WDP_MANUAL, nullptr, 0, 0, WC_SEND_NETWORK_MSG, WC_NONE, 0, _nested_chat_window_widgets)
| The description of the chat window.

## Detailed Description

GUI for handling chat messages.

Definition in file network_chat_gui.cpp.

## Function Documentation

## ◆ HaveChatMessages()

static bool HaveChatMessages | ( | bool | show_all | ) |
| inlinestatic

Test if there are any chat messages to display.

Parameters

  show_all | Set if all messages should be included, instead of unexpired only.

Returns
  True iff there are chat messages to display.

Definition at line 68 of file network_chat_gui.cpp.

References _chatmsg_list.

Referenced by NetworkDrawChatMessage().

## ◆ NetworkAddChatMessage()

void CDECL NetworkAddChatMessage | ( | TextColour | colour,
|  | uint | duration,
|  | const std::string & | message
| ) |  |

Add a text message to the 'chat window' to be shown.

Parameters

  colour | The colour this message is to be shown in
  duration | The duration of the chat message in seconds
  message | message itself

Definition at line 86 of file network_chat_gui.cpp.

References _chatmessage_dirty, _chatmessage_dirty_time, _chatmsg_list, ChatMessage::colour, MAX_CHAT_MESSAGES, ChatMessage::message, and ChatMessage::remove_time.

## ◆ NetworkDrawChatMessage()

void NetworkDrawChatMessage | ( |  | ) |

Draw the chat message-box.

Definition at line 181 of file network_chat_gui.cpp.

References _chatmessage_backup, _chatmessage_dirty, _chatmessage_visible, _chatmsg_box, _chatmsg_list, ReusableBuffer< T >::Allocate(), Blitter::CopyToBuffer(), DrawStringMultiLine(), FILLRECT_RECOLOUR, FindWindowByClass(), FS_NORMAL, GetCharacterHeight(), BlitterFactory::GetCurrentBlitter(), VideoDriver::GetInstance(), GetStringLineCount(), GfxFillRect(), HaveChatMessages(), ICONSOLE_FULL, VideoDriver::MakeDirty(), MAX_CHAT_MESSAGES, Blitter::MoveTo(), NETWORK_CHAT_LINE_SPACING, NetworkUndrawChatMessage(), PALETTE_TO_TRANSPARENT, SA_BOTTOM, SA_FORCE, SA_LEFT, ScaleGUITrad(), SetDParamStr(), and WC_SEND_NETWORK_MSG.

Referenced by UpdateWindows().

## ◆ NetworkInitChatMessage()

void NetworkInitChatMessage | ( |  | ) |

Initialize all buffers of the chat visualisation.

Definition at line 109 of file network_chat_gui.cpp.

References _chatmessage_visible, _chatmsg_box, _chatmsg_list, _settings_client, ClientSettings::gui, MAX_CHAT_MESSAGES, GUISettings::network_chat_box_height, GUISettings::network_chat_box_width_pct, NetworkReInitChatBoxSize(), and ScaleGUITrad().

## ◆ NetworkReInitChatBoxSize()

void NetworkReInitChatBoxSize | ( |  | ) |

Initialize all font-dependent chat box sizes.

Definition at line 102 of file network_chat_gui.cpp.

References _chatmsg_box, FS_NORMAL, GetCharacterHeight(), MAX_CHAT_MESSAGES, NETWORK_CHAT_LINE_SPACING, and ScaleGUITrad().

Referenced by NetworkInitChatMessage(), and ReInitAllWindows().

## ◆ NetworkUndrawChatMessage()

void NetworkUndrawChatMessage | ( |  | ) |

Hide the chatbox.

Definition at line 121 of file network_chat_gui.cpp.

References _chatmessage_backup, _chatmessage_dirty, _chatmessage_dirty_time, _chatmessage_visible, _chatmsg_box, Blitter::CopyFromBuffer(), CursorVars::draw_size, ReusableBuffer< T >::GetBuffer(), BlitterFactory::GetCurrentBlitter(), VideoDriver::GetInstance(), VideoDriver::MakeDirty(), Blitter::MoveTo(), and CursorVars::visible.

Referenced by NetworkDrawChatMessage(), RedrawScreenRect(), and ReInitAllWindows().

## ◆ SendChat()

static void SendChat | ( | const std::string & | buf,
|  | DestType | type,
|  | int | dest
| ) |  |
| static

Send an actual chat message.

Parameters

  buf | The message to send.
  type | The type of destination.
  dest | The actual destination index.

Definition at line 255 of file network_chat_gui.cpp.

References _network_server, CLIENT_ID_SERVER, NetworkServerSendChat(), and ClientNetworkGameSocketHandler::SendChat().

Referenced by NetworkChatWindow::OnClick().

## ◆ ShowNetworkChatQueryWindow()

void ShowNetworkChatQueryWindow | ( | DestType | type,
|  | int | dest
| ) |  |

Show the chat window.

Parameters

  type | The type of destination.
  dest | The actual destination index.

Definition at line 445 of file network_chat_gui.cpp.

References _chat_window_desc, CloseWindowByClass(), and WC_SEND_NETWORK_MSG.

Referenced by NetworkClientListWindow::OnClickClientChat(), NetworkClientListWindow::OnClickCompanyChat(), and MainWindow::OnHotkey().

## Variable Documentation

## ◆ _chatmessage_backup

ReusableBuffer<uint8_t> _chatmessage_backup
| static

Backup in case text is moved.

Definition at line 61 of file network_chat_gui.cpp.

Referenced by NetworkDrawChatMessage(), and NetworkUndrawChatMessage().

## ◆ _chatmessage_dirty

bool _chatmessage_dirty = false
| static

Does the chat message need repainting?

Definition at line 46 of file network_chat_gui.cpp.

Referenced by NetworkAddChatMessage(), NetworkDrawChatMessage(), and NetworkUndrawChatMessage().

## ◆ _chatmessage_dirty_time

std::chrono::steady_clock::time_point _chatmessage_dirty_time
| static

Time the chat history was marked dirty.

This is used to determine if expired messages have recently expired and should cause a redraw to hide them.

Definition at line 54 of file network_chat_gui.cpp.

Referenced by NetworkAddChatMessage(), and NetworkUndrawChatMessage().

## ◆ _chatmessage_visible

bool _chatmessage_visible = false
| static

Is a chat message visible.

Definition at line 47 of file network_chat_gui.cpp.

Referenced by NetworkDrawChatMessage(), NetworkInitChatMessage(), and NetworkUndrawChatMessage().

## ◆ _chatmsg_box

PointDimension _chatmsg_box
| static

The chatbox grows from the bottom so the coordinates are pixels from the left and pixels from the bottom.

The height is the maximum height.

Definition at line 60 of file network_chat_gui.cpp.

Referenced by NetworkDrawChatMessage(), NetworkInitChatMessage(), NetworkReInitChatBoxSize(), and NetworkUndrawChatMessage().

## ◆ _chatmsg_list

std::deque<ChatMessage> _chatmsg_list
| static

The actual chat message list.

Definition at line 45 of file network_chat_gui.cpp.

Referenced by HaveChatMessages(), NetworkAddChatMessage(), NetworkDrawChatMessage(), and NetworkInitChatMessage().

## ◆ _nested_chat_window_widgets

constexpr NWidgetPart _nested_chat_window_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY, WID_NC_CLOSE),
NWidget(WWT_PANEL, COLOUR_GREY, WID_NC_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetAlignment(SA_VERT_CENTER | SA_RIGHT), SetDataTip(STR_NULL, STR_NULL),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NC_TEXTBOX), SetMinimalSize(100, 0), SetPadding(1, 0, 1, 0), SetResize(1, 0),
SetDataTip(STR_NETWORK_CHAT_OSKTITLE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NC_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
EndContainer(),
EndContainer(),
EndContainer(),
}
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:345
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition gfx_type.h:349
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1228
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1137
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1170
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
WID_NC_SENDBUTTON
@ WID_NC_SENDBUTTON
Send button.
Definition network_chat_widget.h:19
WID_NC_BACKGROUND
@ WID_NC_BACKGROUND
Background of the window.
Definition network_chat_widget.h:16
WID_NC_CLOSE
@ WID_NC_CLOSE
Close button.
Definition network_chat_widget.h:15
WID_NC_TEXTBOX
@ WID_NC_TEXTBOX
Textbox.
Definition network_chat_widget.h:18
WID_NC_DESTINATION
@ WID_NC_DESTINATION
Destination.
Definition network_chat_widget.h:17
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:113
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:71
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:58

The widgets of the chat window.

Definition at line 417 of file network_chat_gui.cpp.

## ◆ MAX_CHAT_MESSAGES

uint MAX_CHAT_MESSAGES = 0
| static

The limit of chat messages to show.

Definition at line 48 of file network_chat_gui.cpp.

Referenced by NetworkAddChatMessage(), NetworkDrawChatMessage(), NetworkInitChatMessage(), and NetworkReInitChatBoxSize().

## ◆ NETWORK_CHAT_LINE_SPACING

const uint NETWORK_CHAT_LINE_SPACING = 3
| static

Spacing between chat lines.

Definition at line 35 of file network_chat_gui.cpp.

Referenced by NetworkDrawChatMessage(), and NetworkReInitChatBoxSize().