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