nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
bag_window.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_BAG_WINDOW_H_
2#define NANOMMO_CLIENT_BAG_WINDOW_H_
3
4#include <cstdint>
5#include <optional>
6#include <string>
7#include <utility>
8#include <vector>
9
10#include "content/items.h"
11#include "protocol/nanommo.pb.h"
12
13namespace nanommo {
14
15/// What a tooltip says of the stack: its item's name, where it's worn, what
16/// it adds, what this one rolled, what using one does, and how many stack.
17std::vector<std::string> ItemLines(const ItemTable& items,
18 const items::Stack& stack);
19
20/// The first slot of the bag with nothing in it, if it has one.
21std::optional<uint32_t> FirstEmptySlot(const protocol::Inventory& bag);
22
23/// What double-clicking the stack at the place does: in the bag, using it if
24/// it's used, or else wearing it if it's worn, and taking it off if it's worn
25/// now, into the first empty slot of the bag.
26std::optional<protocol::ItemAction> QuickAction(const ItemTable& items,
27 const protocol::Inventory& bag,
28 const protocol::Place& place);
29
30/// Draws a slot of the bag, or one that's worn, of the size: the item's icon
31/// in its tint, with how many there are. A player drags an item from one slot
32/// onto another to move it, wear it or take it off, with Shift for half the
33/// stack: it follows the mouse, and each slot it's over lights green if the
34/// server would let it go there, and red if not. They double-click it to use,
35/// wear or take it off, and right-click it for a menu that throws it away
36/// too. Returns what they ask for, which the server does or refuses. A slot
37/// that's locked, as one offered in a trade is, does none of that, and shows
38/// its item faint.
39std::optional<protocol::ItemAction> ItemSlot(const ItemTable& items,
40 const protocol::Inventory& bag,
41 const protocol::Place& place,
42 float size, bool locked = false);
43
44/// Draws a stack, or nothing, in a slot of the size that doesn't drag: its
45/// icon, how many, and its lines when the mouse is over it, with the edge
46/// lit in the colour, if there's one. Returns whether it was clicked.
47bool StackSlot(const ItemTable& items, const items::Stack* stack, float size,
48 uint32_t edge = 0);
49
50/// Within a drag and drop target: where the item that's let go of over it was
51/// dragged from, in the bag or worn, once it's let go of.
52std::optional<protocol::Place> AcceptItem();
53
54/// The bag, in a window of its own, which I opens and closes. An item dragged
55/// out of it, or off the player, and let go of over nothing is thrown away,
56/// once the player says so. Build it each frame, open or not, so that it sees
57/// an item let go of from what's worn too.
58class BagWindow {
59 public:
60 explicit BagWindow(ItemTable items) : items_(std::move(items)) {}
61
62 bool* mutable_visible() { return &visible_; }
63 bool visible() const { return visible_; }
64 void Toggle() { visible_ = !visible_; }
65
66 /// What's offered in a trade stays in its slot until the trade's over.
67 std::optional<protocol::ItemAction> Build(
68 const protocol::Inventory& bag, const protocol::TradeSide& offered = {});
69
70 private:
71 /// Asks whether to throw away what's at throwing_.
72 std::optional<protocol::ItemAction> BuildThrowAway(
73 const protocol::Inventory& bag);
74
75 ItemTable items_;
76 bool visible_ = false;
77 std::optional<protocol::Place> throwing_;
78};
79
80} // namespace nanommo
81
82#endif // NANOMMO_CLIENT_BAG_WINDOW_H_
std::optional< protocol::ItemAction > Build(const protocol::Inventory &bag, const protocol::TradeSide &offered={})
What's offered in a trade stays in its slot until the trade's over.
BagWindow(ItemTable items)
Definition bag_window.h:60
bool * mutable_visible()
Definition bag_window.h:62
bool visible() const
Definition bag_window.h:63
Definition chat.cc:9
std::optional< uint32_t > FirstEmptySlot(const protocol::Inventory &bag)
The first slot of the bag with nothing in it, if it has one.
std::optional< protocol::ItemAction > QuickAction(const ItemTable &items, const protocol::Inventory &bag, const protocol::Place &place)
std::optional< protocol::Place > AcceptItem()
std::optional< protocol::ItemAction > ItemSlot(const ItemTable &items, const protocol::Inventory &bag, const protocol::Place &place, float size, bool locked)
bool StackSlot(const ItemTable &items, const items::Stack *stack, float size, uint32_t edge)
std::vector< std::string > ItemLines(const ItemTable &items, const items::Stack &stack)
The items in the items file, by id.
Definition items.h:18