R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
rtype::ConnectForm Class Reference

What the player types on the connect screen, checked before joining. More...

#include </__w/project-rtype/project-rtype/client/network/include/rtype/connect_form.hpp>

Public Member Functions

 ConnectForm (const ClientSettings &settings)
 Creates the form, filled with settings (the command line's, or the last ones used), the name focused.
 
ConnectField focused () const noexcept
 The focused field, which type() and erase() change.
 
void focus (ConnectField field) noexcept
 Focuses a field.
 
void next () noexcept
 Focuses the next field, the first after the last one.
 
void previous () noexcept
 Focuses the previous field, the last before the first one.
 
bool type (char character)
 Adds an ASCII character at the end of the focused field.
 
void erase () noexcept
 Removes the last character of the focused field, if any.
 
bool set_text (ConnectField field, std::string_view text)
 Replaces the text of a field, as edited in a text field.
 
const std::string & text (ConnectField field) const
 Text of a field.
 
std::variant< ClientSettings, std::string > submit () const
 Checks the fields and gives the settings to join with.
 

Static Public Member Functions

static bool accepts (ConnectField field, char character) noexcept
 Tells whether a field takes a character, or a byte of a UTF-8 character.
 
static std::size_t max_length (ConnectField field) noexcept
 Longest text of a field.
 

Static Public Attributes

static constexpr std::size_t max_host = 45
 Longest address: an IPv6 address with its brackets fits.
 
static constexpr std::size_t max_port = 5
 Longest port: five digits.
 
static constexpr std::size_t max_name = 16
 Longest name, in bytes of UTF-8, as LoginRequest allows.
 

Detailed Description

What the player types on the connect screen, checked before joining.

The form only keeps text and its rules: accepts() and max_length() tell what each field holds, type() and set_text() refuse the rest (a letter in the port, a field already full). submit() checks the fields and gives the settings of ClientSession, or a sentence for the player. Nothing here draws or reads the keyboard, so the form is the same with any window; the client edits it through ConnectFields.

Constructor & Destructor Documentation

◆ ConnectForm()

rtype::ConnectForm::ConnectForm ( const ClientSettings &  settings)
explicit

Creates the form, filled with settings (the command line's, or the last ones used), the name focused.

Parameters
settingsServer and player name shown at first.

Member Function Documentation

◆ accepts()

static bool rtype::ConnectForm::accepts ( ConnectField  field,
char  character 
)
staticnoexcept

Tells whether a field takes a character, or a byte of a UTF-8 character.

The address takes letters, digits, ., :, -, [ and ]; the port takes digits; the name takes printable ASCII characters (space included) and the bytes of longer UTF-8 characters, such as accented letters, as the login does.

Parameters
fieldField to type in.
characterCharacter, or a byte of a longer UTF-8 character.
Returns
true if the field takes it.

◆ erase()

void rtype::ConnectForm::erase ( )
noexcept

Removes the last character of the focused field, if any.

◆ focus()

void rtype::ConnectForm::focus ( ConnectField  field)
noexcept

Focuses a field.

Parameters
fieldField to focus.

◆ focused()

ConnectField rtype::ConnectForm::focused ( ) const
noexcept

The focused field, which type() and erase() change.

Returns
The field.

◆ max_length()

static std::size_t rtype::ConnectForm::max_length ( ConnectField  field)
staticnoexcept

Longest text of a field.

Parameters
fieldField.
Returns
max_host, max_port or max_name, in bytes (characters, but for a name with longer UTF-8 characters).

◆ next()

void rtype::ConnectForm::next ( )
noexcept

Focuses the next field, the first after the last one.

◆ previous()

void rtype::ConnectForm::previous ( )
noexcept

Focuses the previous field, the last before the first one.

◆ set_text()

bool rtype::ConnectForm::set_text ( ConnectField  field,
std::string_view  text 
)

Replaces the text of a field, as edited in a text field.

Parameters
fieldField to set.
textNew text in UTF-8; characters the field does not take are left out, and the text is cut to the field's length, never inside a character.
Returns
true if the whole of text was kept.

◆ submit()

std::variant< ClientSettings, std::string > rtype::ConnectForm::submit ( ) const

Checks the fields and gives the settings to join with.

The address must not be empty, the port must be a number from 1 to 65535, and the name 1 to max_name characters. Whether the address is one the client can reach is only known when it joins: ClientSession::start() says so.

Returns
The settings, or a sentence telling the player what to fix.

◆ text()

const std::string & rtype::ConnectForm::text ( ConnectField  field) const

Text of a field.

Parameters
fieldField to read.
Returns
Its text.

◆ type()

bool rtype::ConnectForm::type ( char  character)

Adds an ASCII character at the end of the focused field.

As accepts() says; a byte of a longer UTF-8 character is refused, those characters coming whole through set_text().

Parameters
characterCharacter typed.
Returns
false if the field does not take it or is full; the field is unchanged.

Member Data Documentation

◆ max_host

constexpr std::size_t rtype::ConnectForm::max_host = 45
staticconstexpr

Longest address: an IPv6 address with its brackets fits.

◆ max_name

constexpr std::size_t rtype::ConnectForm::max_name = 16
staticconstexpr

Longest name, in bytes of UTF-8, as LoginRequest allows.

◆ max_port

constexpr std::size_t rtype::ConnectForm::max_port = 5
staticconstexpr

Longest port: five digits.


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