R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
connect_form.hpp
Go to the documentation of this file.
1
3#pragma once
5
6#include <array>
7#include <cstddef>
8#include <cstdint>
9#include <string>
10#include <string_view>
11#include <variant>
12
13namespace rtype {
14
16enum class ConnectField : std::uint8_t {
18 Host,
20 Port,
22 Name,
23};
24
26inline constexpr std::size_t connect_field_count = 3;
27
35public:
37 static constexpr std::size_t max_host = 45;
39 static constexpr std::size_t max_port = 5;
41 static constexpr std::size_t max_name = 16;
42
46 explicit ConnectForm(const ClientSettings& settings);
47
50 [[nodiscard]] ConnectField focused() const noexcept;
51
54 void focus(ConnectField field) noexcept;
55
57 void next() noexcept;
58
60 void previous() noexcept;
61
69 [[nodiscard]] static bool accepts(ConnectField field, char character) noexcept;
70
75 [[nodiscard]] static std::size_t max_length(ConnectField field) noexcept;
76
82 bool type(char character);
83
85 void erase() noexcept;
86
92 bool set_text(ConnectField field, std::string_view text);
93
97 [[nodiscard]] const std::string& text(ConnectField field) const;
98
104 [[nodiscard]] std::variant<ClientSettings, std::string> submit() const;
105
106private:
107 std::array<std::string, connect_field_count> fields_;
108 ConnectField focused_ = ConnectField::Name;
109};
110
111} // namespace rtype
What the player types on the connect screen, checked before joining.
Definition connect_form.hpp:34
ConnectField focused() const noexcept
The focused field, which type() and erase() change.
void erase() noexcept
Removes the last character of the focused field, if any.
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 constexpr std::size_t max_name
Longest name, in bytes of UTF-8, as LoginRequest allows.
Definition connect_form.hpp:41
ConnectForm(const ClientSettings &settings)
Creates the form, filled with settings (the command line's, or the last ones used),...
static constexpr std::size_t max_port
Longest port: five digits.
Definition connect_form.hpp:39
void next() noexcept
Focuses the next field, the first after the last one.
static constexpr std::size_t max_host
Longest address: an IPv6 address with its brackets fits.
Definition connect_form.hpp:37
std::variant< ClientSettings, std::string > submit() const
Checks the fields and gives the settings to join with.
void focus(ConnectField field) noexcept
Focuses a field.
const std::string & text(ConnectField field) const
Text of a field.
void previous() noexcept
Focuses the previous field, the last before the first one.
bool set_text(ConnectField field, std::string_view text)
Replaces the text of a field, as edited in a text field.
bool type(char character)
Adds an ASCII character at the end of the focused field.
The client's session with the server: TCP login, then UDP binding (RFC section 3).
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
ConnectField
A field of the connect screen.
Definition connect_form.hpp:16
@ Name
Player name.
@ Port
TCP port of the server.
@ Host
Address of the server.
constexpr std::size_t connect_field_count
Number of fields of ConnectField.
Definition connect_form.hpp:26
What the client needs to join a server.
Definition client_session.hpp:70