]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gui/guiInventoryList.h
Revert "Make Lint Happy"
[dragonfireclient.git] / src / gui / guiInventoryList.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 GNU Lesser General Public License for more details.
12 You should have received a copy of the GNU Lesser General Public License along
13 with this program; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 */
16
17 #pragma once
18
19 #include "inventorymanager.h"
20 #include "irrlichttypes_extrabloated.h"
21 #include "util/string.h"
22
23 class GUIFormSpecMenu;
24
25 class GUIInventoryList : public gui::IGUIElement
26 {
27 public:
28         struct ItemSpec
29         {
30                 ItemSpec() = default;
31
32                 ItemSpec(const InventoryLocation &a_inventoryloc,
33                                 const std::string &a_listname,
34                                 s32 a_i) :
35                         inventoryloc(a_inventoryloc),
36                         listname(a_listname),
37                         i(a_i)
38                 {
39                 }
40
41                 bool isValid() const { return i != -1; }
42
43                 InventoryLocation inventoryloc;
44                 std::string listname;
45                 s32 i = -1;
46         };
47
48         // options for inventorylists that are setable with the lua api
49         struct Options {
50                 // whether a one-pixel border for the slots should be drawn and its color
51                 bool slotborder = false;
52                 video::SColor slotbordercolor = video::SColor(200, 0, 0, 0);
53                 // colors for normal and highlighted slot background
54                 video::SColor slotbg_n = video::SColor(255, 128, 128, 128);
55                 video::SColor slotbg_h = video::SColor(255, 192, 192, 192);
56         };
57
58         GUIInventoryList(gui::IGUIEnvironment *env,
59                 gui::IGUIElement *parent,
60                 s32 id,
61                 const core::rect<s32> &rectangle,
62                 InventoryManager *invmgr,
63                 const InventoryLocation &inventoryloc,
64                 const std::string &listname,
65                 const v2s32 &geom,
66                 const s32 start_item_i,
67                 const v2s32 &slot_size,
68                 const v2f32 &slot_spacing,
69                 GUIFormSpecMenu *fs_menu,
70                 const Options &options,
71                 gui::IGUIFont *font);
72
73         virtual void draw() override;
74
75         virtual bool OnEvent(const SEvent &event) override;
76
77         const InventoryLocation &getInventoryloc() const
78         {
79                 return m_inventoryloc;
80         }
81
82         const std::string &getListname() const
83         {
84                 return m_listname;
85         }
86
87         void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h)
88         {
89                 m_options.slotbg_n = slotbg_n;
90                 m_options.slotbg_h = slotbg_h;
91         }
92
93         void setSlotBorders(bool slotborder, const video::SColor &slotbordercolor)
94         {
95                 m_options.slotborder = slotborder;
96                 m_options.slotbordercolor = slotbordercolor;
97         }
98
99         // returns -1 if not item is at pos p
100         s32 getItemIndexAtPos(v2s32 p) const;
101
102 private:
103         InventoryManager *m_invmgr;
104         const InventoryLocation m_inventoryloc;
105         const std::string m_listname;
106
107         // the specified width and height of the shown inventorylist in itemslots
108         const v2s32 m_geom;
109         // the first item's index in inventory
110         const s32 m_start_item_i;
111
112         // specifies how large the slot rects are
113         const v2s32 m_slot_size;
114         // specifies how large the space between slots is (space between is spacing-size)
115         const v2f32 m_slot_spacing;
116
117         // the GUIFormSpecMenu can have an item selected and co.
118         GUIFormSpecMenu *m_fs_menu;
119
120         Options m_options;
121
122         // the font
123         gui::IGUIFont *m_font;
124
125         // the index of the hovered item; -1 if no item is hovered
126         s32 m_hovered_i;
127
128         // we do not want to write a warning on every draw
129         bool m_already_warned;
130 };