nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
craft_window.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_CRAFT_WINDOW_H_
2#define NANOMMO_CLIENT_CRAFT_WINDOW_H_
3
4#include <cstdint>
5#include <optional>
6#include <utility>
7#include <vector>
8
9#include "client/animator.h"
10#include "content/content.h"
11#include "protocol/nanommo.pb.h"
12
13namespace nanommo {
14
15/// How many of the item are in the bag, in all its slots, and not worn, as a
16/// recipe takes from the bag alone.
17uint32_t HowMany(const protocol::Inventory& bag, uint32_t item);
18
19/// Whether a player of the level can start making the recipe, as the server
20/// would let them: it's of their level or below, and the bag has all it
21/// takes. The server checks for room, and for what's offered in a trade.
22bool CanMake(const recipes::Recipe& recipe, const protocol::Inventory& bag,
23 int level);
24
25/// How far what's being made has got, from 0 to 1, from how long it's been
26/// at, in milliseconds, of its recipe's seconds.
27float MadeShare(const recipes::Recipe& recipe, uint32_t done);
28
29/// The recipes the player knows, which are those of their level or below, in
30/// a window of its own, which K opens and closes: what each takes, as how many
31/// they have of how many it needs, what it makes, and a button to make it,
32/// which is off while they can't. While they're making something, a bar over
33/// the hotbar shows how far it's got, open or not.
35 public:
36 explicit CraftWindow(Content content) : content_(std::move(content)) {}
37
38 bool visible() const { return visible_; }
39 void Toggle() { visible_ = !visible_; }
40
41 /// Draws the bar, while the player's making something, and the window,
42 /// while it's open, with their bag. Returns what they ask for: to start
43 /// making a recipe, or to stop.
44 std::optional<protocol::CraftAction> Build(const std::vector<Figure>& figures,
45 const protocol::Inventory& bag,
46 const protocol::Crafting& making);
47
48 private:
49 void DrawProgress(const protocol::Crafting& making) const;
50
51 Content content_;
52 bool visible_ = false;
53};
54
55} // namespace nanommo
56
57#endif // NANOMMO_CLIENT_CRAFT_WINDOW_H_
bool visible() const
std::optional< protocol::CraftAction > Build(const std::vector< Figure > &figures, const protocol::Inventory &bag, const protocol::Crafting &making)
CraftWindow(Content content)
Definition chat.cc:9
bool CanMake(const recipes::Recipe &recipe, const protocol::Inventory &bag, int level)
float MadeShare(const recipes::Recipe &recipe, uint32_t done)
uint32_t HowMany(const protocol::Inventory &bag, uint32_t item)