OpenTTD Source  1.11.2
network_chat_gui.cpp File Reference
#include <stdarg.h>
#include "../stdafx.h"
#include "../strings_func.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 "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...
 
struct  NetworkChatWindow
 Window to enter the chat message in. More...
 

Functions

static uint GetChatMessageCount ()
 Count the chat messages. More...
 
void CDECL NetworkAddChatMessage (TextColour colour, uint duration, const char *message,...)
 Add a text message to the 'chat window' to be shown. More...
 
void NetworkReInitChatBoxSize ()
 Initialize all font-dependent chat box sizes.
 
void NetworkInitChatMessage ()
 Initialize all buffers of the chat visualisation.
 
void NetworkUndrawChatMessage ()
 Hide the chatbox.
 
void NetworkChatMessageLoop ()
 Check if a message is expired.
 
void NetworkDrawChatMessage ()
 Draw the chat message-box.
 
static void SendChat (const char *buf, DestType type, int dest)
 Send an actual chat message. More...
 
void ShowNetworkChatQueryWindow (DestType type, int dest)
 Show the chat window. More...
 

Variables

static const uint NETWORK_CHAT_LINE_SPACING = 3
 The draw buffer must be able to contain the chat message, client name and the "[All]" message, some spaces and possible translations of [All] to other languages. More...
 
static ChatMessage_chatmsg_list = nullptr
 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 bool _chat_tab_completion_active
 Whether tab completion is active.
 
static uint MAX_CHAT_MESSAGES = 0
 The limit of chat messages to show.
 
static PointDimension _chatmsg_box
 The chatbox grows from the bottom so the coordinates are pixels from the left and pixels from the bottom. More...
 
static uint8 * _chatmessage_backup = nullptr
 Backup in case text is moved.
 
static const NWidgetPart _nested_chat_window_widgets []
 The widgets of the chat window. More...
 
static WindowDesc _chat_window_desc (WDP_MANUAL, nullptr, 0, 0, WC_SEND_NETWORK_MSG, WC_NONE, 0, _nested_chat_window_widgets, lengthof(_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

◆ GetChatMessageCount()

static uint GetChatMessageCount ( )
inlinestatic

Count the chat messages.

Returns
The number of chat messages.

Definition at line 64 of file network_chat_gui.cpp.

References _chatmsg_list, and MAX_CHAT_MESSAGES.

Referenced by NetworkAddChatMessage().

◆ NetworkAddChatMessage()

void CDECL NetworkAddChatMessage ( TextColour  colour,
uint  duration,
const char *  message,
  ... 
)

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

Parameters
colourThe colour this message is to be shown in
durationThe duration of the chat message in seconds
messagemessage itself in printf() style

Definition at line 80 of file network_chat_gui.cpp.

References _chatmsg_list, ChatMessage::colour, DRAW_STRING_BUFFER, GetChatMessageCount(), lastof, MAX_CHAT_MESSAGES, ChatMessage::message, strecpy(), TC_IS_PALETTE_COLOUR, Utf8TrimString(), and vseprintf().

◆ SendChat()

static void SendChat ( const char *  buf,
DestType  type,
int  dest 
)
static

Send an actual chat message.

Parameters
bufThe message to send.
typeThe type of destination.
destThe actual destination index.

Definition at line 268 of file network_chat_gui.cpp.

References _network_server, ClientNetworkGameSocketHandler::SendChat(), and StrEmpty().

Referenced by NetworkChatWindow::OnClick().

◆ ShowNetworkChatQueryWindow()

void ShowNetworkChatQueryWindow ( DestType  type,
int  dest 
)

Show the chat window.

Parameters
typeThe type of destination.
destThe actual destination index.

Definition at line 553 of file network_chat_gui.cpp.

References _chat_window_desc, DeleteWindowByClass(), and WC_SEND_NETWORK_MSG.

Variable Documentation

◆ _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 57 of file network_chat_gui.cpp.

Referenced by NetworkInitChatMessage(), and NetworkReInitChatBoxSize().

◆ _nested_chat_window_widgets

const NWidgetPart _nested_chat_window_widgets[]
static
Initial value:
= {
NWidget(WWT_TEXT, COLOUR_GREY, WID_NC_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NULL, STR_NULL),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NC_TEXTBOX), SetMinimalSize(100, 12), 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),
}

The widgets of the chat window.

Definition at line 525 of file network_chat_gui.cpp.

◆ NETWORK_CHAT_LINE_SPACING

const uint NETWORK_CHAT_LINE_SPACING = 3
static

The draw buffer must be able to contain the chat message, client name and the "[All]" message, some spaces and possible translations of [All] to other languages.

Spacing between chat lines.

Definition at line 37 of file network_chat_gui.cpp.

Referenced by NetworkReInitChatBoxSize().

WID_NC_SENDBUTTON
@ WID_NC_SENDBUTTON
Send button.
Definition: network_chat_widget.h:19
WID_NC_DESTINATION
@ WID_NC_DESTINATION
Destination.
Definition: network_chat_widget.h:17
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1055
WID_NC_CLOSE
@ WID_NC_CLOSE
Close button.
Definition: network_chat_widget.h:15
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:939
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1023
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1008
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
WID_NC_TEXTBOX
@ WID_NC_TEXTBOX
Textbox.
Definition: network_chat_widget.h:18
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1123
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:956
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_NC_BACKGROUND
@ WID_NC_BACKGROUND
Background of the window.
Definition: network_chat_widget.h:16