nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
hotbar.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_HOTBAR_H_
2#define NANOMMO_CLIENT_HOTBAR_H_
3
4#include <cstdint>
5#include <optional>
6#include <vector>
7
8#include "client/animator.h"
9#include "content/skills.h"
10#include "protocol/nanommo.pb.h"
11
12namespace nanommo {
13
14/// The skills along the bottom of the screen: the swing first, on Space, then
15/// the others, each on a number key: 1 for the first, and so on, up to nine,
16/// and then a row above it, on the same keys with Shift.
17/// They start in the order of their levels, and the player drags one onto
18/// another to swap them.
19class Hotbar {
20 public:
21 /// A row's worth of number keys.
22 static constexpr int kRow = 9;
23 static constexpr int kMostSlots = 2 * kRow;
24
25 explicit Hotbar(const SkillTable& skills);
26
27 /// Draws each skill with its icon and its key, and how long until it's
28 /// ready, or, while the player doesn't know it, the level it needs, or Learn
29 /// once they've reached it. A skill that hits one monster is red while
30 /// they've picked none, by its id in target, or the player in target_player,
31 /// an opponent in a duel or an enemy at war, as the server runs them up to
32 /// the one they picked, however far. Returns the skill the player used, with
33 /// its key or a click.
34 std::optional<uint32_t> Build(const std::vector<Figure>& figures,
35 const protocol::World& world, uint32_t target,
36 uint32_t target_player = 0);
37
38 /// The skills after the swing, by their ids, in their slots' order.
39 std::vector<uint32_t> Order() const;
40
41 /// Puts the skills in the order, as the player left them: the ones it names
42 /// first, in its order, and any it doesn't after them, as they were.
43 void Arrange(const std::vector<uint32_t>& order);
44
45 /// Whether the player has swapped two skills since this was last asked.
46 bool TakeRearranged();
47
48 private:
49 std::vector<skills::Skill> slots_;
50 /// Whether the first slot is the swing.
51 bool swing_ = false;
52 bool rearranged_ = false;
53};
54
55} // namespace nanommo
56
57#endif // NANOMMO_CLIENT_HOTBAR_H_
static constexpr int kMostSlots
Definition hotbar.h:23
static constexpr int kRow
A row's worth of number keys.
Definition hotbar.h:22
void Arrange(const std::vector< uint32_t > &order)
Definition hotbar.cc:126
std::vector< uint32_t > Order() const
The skills after the swing, by their ids, in their slots' order.
Definition hotbar.cc:118
std::optional< uint32_t > Build(const std::vector< Figure > &figures, const protocol::World &world, uint32_t target, uint32_t target_player=0)
Definition hotbar.cc:141
bool TakeRearranged()
Whether the player has swapped two skills since this was last asked.
Definition hotbar.cc:139
Hotbar(const SkillTable &skills)
Definition hotbar.cc:96
Definition chat.cc:9