nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
login_screen.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_LOGIN_SCREEN_H_
2#define NANOMMO_CLIENT_LOGIN_SCREEN_H_
3
4#include <array>
5#include <cstdint>
6#include <optional>
7#include <string>
8#include <utility>
9#include <vector>
10
11#include "client/animator.h"
12#include "client/offscreen.h"
13#include "client/renderer.h"
14#include "content/figures.pb.h"
15#include "content/items.h"
16#include "content/rig.pb.h"
17#include "protocol/nanommo.pb.h"
18
19namespace nanommo {
20
21/// Before the world: the account's login, then the worlds, then the
22/// account's characters in the world picked, each drawn as it is, turned with
23/// the mouse, to pick one to enter as or delete one, and a screen to make a
24/// new one on, with its name and how it looks: its build, skin and hair. All
25/// of it over embers rising in the dark, with the game's name over the login.
27 public:
28 /// The preview's size, in pixels: enough for it to be sharp at its size on
29 /// a 4K screen.
30 static constexpr int kPreviewWidth = 760;
31 static constexpr int kPreviewHeight = 1012;
32
33 /// With the ClientHash of this client's content, to tell the worlds that
34 /// have other content apart, its items, to dress a new character in the kit
35 /// it'll start with, and its figures and rig, for the looks to choose from.
36 LoginScreen(uint64_t content, const ItemTable& items,
37 const figures::Figures& figures, const rig::Rig& rig)
38 : content_(content), items_(items), figures_(figures), rig_(rig) {}
39
40 /// Draws the screen we're on, and returns what to ask the login server, if
41 /// there's anything: a login, a new account, the characters again, a new or
42 /// a deleted character, or a token to enter the world as one.
43 std::optional<protocol::LoginRequest> Build();
44
45 /// Draws the character picked, for the characters' screen, or the one being
46 /// made, as it's turned, before the frame.
47 void Render(const Renderer& renderer);
48
49 /// What the login server said to what Build asked: the session, the worlds
50 /// and the characters, or an error, such as a name that's taken. A session
51 /// that's run out goes back to the login.
52 void Show(const protocol::LoginReply& reply);
53 void ShowError(std::string error) { error_ = std::move(error); }
54
55 /// The world picked, which a token from an enter request is for.
56 const std::optional<protocol::WorldListing>& world() const { return world_; }
57 /// The name of the character picked, once it's entering.
58 std::string character_name() const;
59
60 /// The character as the preview draws it: its looks, or its id, which they
61 /// come from for a character from before there were looks to choose, and
62 /// what it wears, or the kit a fresh one starts with.
63 static Figure FigureOf(
64 const protocol::CharacterListing& character, const ItemTable& items,
65 const figures::Figures& figures = figures::Figures::default_instance());
66
67 private:
68 enum class Step { kAccount, kWorlds, kCharacters, kCreate };
69
70 std::optional<protocol::LoginRequest> BuildAccount();
71 std::optional<protocol::LoginRequest> BuildWorlds();
72 std::optional<protocol::LoginRequest> BuildCharacters();
73 std::optional<protocol::LoginRequest> BuildCreate();
74 /// The character on its stage, in the middle, to turn and look at, with its
75 /// name and a line under it.
76 void DrawStage(const std::string& name, const std::string& line);
77 /// To the screen that makes a character, which starts with looks picked at
78 /// random, so that no two players start out alike.
79 void StartCreating();
80 void PickAnyLooks();
81 /// The character being made, as the preview draws it.
82 protocol::CharacterListing Draft() const;
83 /// A request with the session, for what comes after the login.
84 protocol::LoginRequest WithSession() const;
85 /// The characters in the world picked, the oldest first.
86 std::vector<const protocol::CharacterListing*> Here() const;
87 int CountIn(const std::string& world) const;
88
89 uint64_t content_;
90 const ItemTable& items_;
91 const figures::Figures& figures_;
92 const rig::Rig& rig_;
93 Step step_ = Step::kAccount;
94 std::string session_;
95 std::vector<protocol::WorldListing> worlds_;
96 std::vector<protocol::CharacterListing> characters_;
97 int selected_world_ = 0;
98 std::optional<protocol::WorldListing> world_;
99 // The character picked, by its id, and how the preview's turned and how
100 // near it is.
101 uint32_t picked_ = 0;
102 float turn_ = 0.0f;
103 float distance_ = 3.6f;
104 bool deleting_ = false;
105 std::array<char, 17> username_{};
106 std::array<char, 129> password_{};
107 std::array<char, 17> new_name_{};
108 // How the character being made looks, so far.
109 protocol::Looks looks_;
110 std::string error_;
111 Offscreen preview_{kPreviewWidth, kPreviewHeight};
112};
113
114} // namespace nanommo
115
116#endif // NANOMMO_CLIENT_LOGIN_SCREEN_H_
void Show(const protocol::LoginReply &reply)
std::string character_name() const
The name of the character picked, once it's entering.
static constexpr int kPreviewWidth
void Render(const Renderer &renderer)
const std::optional< protocol::WorldListing > & world() const
The world picked, which a token from an enter request is for.
static constexpr int kPreviewHeight
LoginScreen(uint64_t content, const ItemTable &items, const figures::Figures &figures, const rig::Rig &rig)
void ShowError(std::string error)
static Figure FigureOf(const protocol::CharacterListing &character, const ItemTable &items, const figures::Figures &figures=figures::Figures::default_instance())
std::optional< protocol::LoginRequest > Build()
Definition chat.cc:9
The items in the items file, by id.
Definition items.h:18