nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
chat_window.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_CHAT_WINDOW_H_
2#define NANOMMO_CLIENT_CHAT_WINDOW_H_
3
4#include <array>
5#include <cstddef>
6#include <deque>
7#include <optional>
8#include <string>
9#include <string_view>
10
11#include "content/content.h"
12#include "protocol/chat.h"
13#include "protocol/nanommo.pb.h"
14
15namespace nanommo {
16
17/// What a line typed in the chat says to the guild, when it starts with /g
18/// and a space, even if that's nothing, which the server drops, or nothing at
19/// all, for a line to the world.
20std::optional<std::string> GuildLine(std::string_view typed);
21
22/// Who a line typed in the chat asks to trade with, by their name, when it
23/// starts with /trade and a space, or nothing, for any other line.
24std::optional<std::string> TradeName(std::string_view typed);
25
26/// The guild a line typed in the chat asks to war, by its name, when it starts
27/// with /war and a space, or nothing, for any other line.
28std::optional<std::string> WarName(std::string_view typed);
29
30/// What a line typed in the chat does about a duel, when it starts with /duel
31/// and a space: yes or no to the one who asked, yield, or, with a name, asks
32/// that player. Nothing, for any other line.
33std::optional<protocol::DuelAction> DuelLine(std::string_view typed);
34
35/// What's said in the world, in the bottom left, over a field to type in,
36/// which Enter goes to. Its close button folds it into a button, which says
37/// how many lines have come since, and which, or Enter, opens it again.
39 public:
40 /// Draws the lines, or the button while it's closed, with the servers'
41 /// sentences in the language in use, which names the content's by the
42 /// content. Returns what the player says, once Enter sends it.
43 std::optional<std::string> Build(const std::deque<protocol::Chat>& lines,
44 const Content& content);
45
46 /// How many of the lines came after the last one seen while it was open.
47 static std::size_t Unread(const std::deque<protocol::Chat>& lines,
48 const std::optional<protocol::Chat>& seen);
49
50 private:
51 bool open_ = true;
52 // Opened with Enter, so the field takes the keys at once.
53 bool focus_ = false;
54 // The newest line while it was last open.
55 std::optional<protocol::Chat> seen_;
56 // One more for the zero at the end.
57 std::array<char, kMaxChatLength + 1> typing_{};
58};
59
60} // namespace nanommo
61
62#endif // NANOMMO_CLIENT_CHAT_WINDOW_H_
std::optional< std::string > Build(const std::deque< protocol::Chat > &lines, const Content &content)
static std::size_t Unread(const std::deque< protocol::Chat > &lines, const std::optional< protocol::Chat > &seen)
How many of the lines came after the last one seen while it was open.
Definition chat.cc:9
std::optional< std::string > WarName(std::string_view typed)
std::optional< std::string > TradeName(std::string_view typed)
std::optional< protocol::DuelAction > DuelLine(std::string_view typed)
std::optional< std::string > GuildLine(std::string_view typed)