OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
inventorymenu.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/Widget>
4#include <Tempest/Texture2d>
5#include <Tempest/Timer>
6
8#include "game/inventory.h"
9
10class Npc;
11class Item;
12class Inventory;
13class Interactive;
14class World;
15class KeyCodec;
16
17class InventoryMenu : public Tempest::Widget {
18 public:
19 InventoryMenu(const KeyCodec& key);
21
22 enum class State:uint8_t {
23 Closed=0,
24 Equip,
25 Chest,
26 Trade,
27 Ransack,
29 };
30
31 enum class LootMode:uint8_t {
32 Normal=0,
33 Stack,
34 Ten,
36 };
37
38 enum class DrawPass:uint8_t {
39 Back,
40 Front
41 };
42
43 void close();
44 void open(Npc& pl);
45 void trade(Npc& pl,Npc& tr);
46 bool ransack(Npc& pl,Npc& tr);
47 void open(Npc& pl,Interactive& chest);
48 State isOpen() const;
49 bool isActive() const;
50 void onWorldChanged();
51
52 void tick(uint64_t dt);
53 void draw(Tempest::Encoder<Tempest::CommandBuffer>& cmd);
54 void paintNumOverlay(Tempest::PaintEvent& e);
55
56 void keyDownEvent (Tempest::KeyEvent& e) override;
57 void keyRepeatEvent(Tempest::KeyEvent& e) override;
58 void keyUpEvent (Tempest::KeyEvent& e) override;
59
60 protected:
61 void paintEvent (Tempest::PaintEvent& e) override;
62
63 void mouseDownEvent (Tempest::MouseEvent& event) override;
64 void mouseUpEvent (Tempest::MouseEvent& event) override;
65 void mouseWheelEvent(Tempest::MouseEvent& event) override;
66
67 private:
68 struct Page;
69 struct InvPage;
70 struct TradePage;
71 struct RansackPage;
72
73 struct PageLocal final {
74 size_t sel = 0;
75 size_t scroll = 0;
76 };
77
78 const KeyCodec& keycodec;
79
80 const Tempest::Texture2d* tex =nullptr;
81 const Tempest::Texture2d* slot=nullptr;
82 const Tempest::Texture2d* selT=nullptr;
83 const Tempest::Texture2d* selU=nullptr;
84
85 State state =State::Closed;
86 Npc* player =nullptr;
87 Npc* trader =nullptr;
88 Interactive* chest =nullptr;
89
90 std::unique_ptr<Page> pageOth, pagePl;
91 PageLocal pageLocal[2];
92
93 uint8_t page =0;
94 Tempest::Timer takeTimer;
95 size_t takeCount =0;
96 LootMode lootMode =LootMode::Normal;
97 InventoryRenderer renderer;
98
99 size_t columsCount = 5;
100 int32_t scrollDelta = 0;
101
102 size_t rowsCount() const;
103
104 Tempest::Size slotSize() const;
105 int infoHeight() const;
106 size_t pagesCount() const;
107
108 const Page& activePage();
109 PageLocal& activePageSel();
110 const World* world() const;
111
112 void processMove(Tempest::KeyEvent& e);
113 void moveLeft(bool usePage);
114 void moveRight(bool usePage);
115 void moveUp();
116 void moveDown();
117
118 void onItemAction(uint8_t slotHint);
119 void onTakeStuff();
120 void adjustScroll();
121 void drawAll (Tempest::Painter& p, Npc& player, DrawPass pass);
122 void drawItems (Tempest::Painter& p, DrawPass pass, const Page &inv, const PageLocal &sel, int x, int y, int wcount, int hcount);
123 void drawSlot (Tempest::Painter& p, DrawPass pass, const Inventory::Iterator& it,
124 const Page& page, const PageLocal &sel, int x, int y, size_t id);
125 void drawGold (Tempest::Painter& p, Npc &player, int x, int y);
126 void drawHeader(Tempest::Painter& p, std::string_view title, int x, int y);
127 void drawInfo (Tempest::Painter& p);
128 };
void keyUpEvent(Tempest::KeyEvent &e) override
bool ransack(Npc &pl, Npc &tr)
void keyDownEvent(Tempest::KeyEvent &e) override
void mouseDownEvent(Tempest::MouseEvent &event) override
bool isActive() const
void trade(Npc &pl, Npc &tr)
void paintEvent(Tempest::PaintEvent &e) override
void tick(uint64_t dt)
void mouseUpEvent(Tempest::MouseEvent &event) override
void keyRepeatEvent(Tempest::KeyEvent &e) override
void draw(Tempest::Encoder< Tempest::CommandBuffer > &cmd)
void paintNumOverlay(Tempest::PaintEvent &e)
State isOpen() const
void open(Npc &pl)
void mouseWheelEvent(Tempest::MouseEvent &event) override
Definition item.h:14
Definition npc.h:25
Definition world.h:31