Luanti 5.17.0-dev
Loading...
Searching...
No Matches
guiInventoryList.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "inventorymanager.h"
8#include <IGUIElement.h>
9#include <IGUIEnvironment.h>
10#include "irr_v2d.h"
11
12
13class GUIFormSpecMenu;
14
15class GUIInventoryList : public gui::IGUIElement
16{
17public:
18 struct ItemSpec
19 {
20 ItemSpec() = default;
21
22 ItemSpec(const InventoryLocation &a_inventoryloc,
23 const std::string &a_listname,
24 s32 a_i,
25 const v2s32 slotsize) :
26 inventoryloc(a_inventoryloc),
27 listname(a_listname),
28 i(a_i),
30 {
31 }
32
33 bool operator==(const ItemSpec& other) const
34 {
35 return inventoryloc == other.inventoryloc &&
36 listname == other.listname && i == other.i;
37 }
38
39 bool isValid() const { return i != -1; }
40
42 std::string listname;
43 s32 i = -1;
45 };
46
47 // options for inventorylists that are setable with the lua api
48 struct Options {
49 // whether a one-pixel border for the slots should be drawn and its color
50 bool slotborder = false;
51 video::SColor slotbordercolor = video::SColor(200, 0, 0, 0);
52 // colors for normal and highlighted slot background
53 video::SColor slotbg_n = video::SColor(255, 128, 128, 128);
54 video::SColor slotbg_h = video::SColor(255, 192, 192, 192);
55 };
56
57 GUIInventoryList(gui::IGUIEnvironment *env,
58 gui::IGUIElement *parent,
59 s32 id,
60 const core::rect<s32> &rectangle,
61 InventoryManager *invmgr,
62 const InventoryLocation &inventoryloc,
63 const std::string &listname,
64 const v2s32 &geom,
65 const s32 start_item_i,
66 const v2s32 &slot_size,
67 const v2f32 &slot_spacing,
68 GUIFormSpecMenu *fs_menu,
69 const Options &options,
70 gui::IGUIFont *font);
71
72 void draw() override;
73
74 bool OnEvent(const SEvent &event) override;
75
76 bool isPointInside(const core::position2d<s32> &point) const override;
77
78 void setHoveredIndex(s32 item_i);
79
81 {
82 return m_inventoryloc;
83 }
84
85 const std::string &getListname() const
86 {
87 return m_listname;
88 }
89
90 void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h)
91 {
92 m_options.slotbg_n = slotbg_n;
93 m_options.slotbg_h = slotbg_h;
94 }
95
96 void setSlotBorders(bool slotborder, const video::SColor &slotbordercolor)
97 {
98 m_options.slotborder = slotborder;
99 m_options.slotbordercolor = slotbordercolor;
100 }
101
102 const v2s32 getSlotSize() const noexcept
103 {
104 return m_slot_size;
105 }
106
107 // returns -1 if no item is at pos p
108 s32 getItemIndexAtPos(v2s32 p) const;
109
110private:
113 const std::string m_listname;
114
115 // the specified width and height of the shown inventorylist in itemslots
117 // the first item's index in inventory
118 const s32 m_start_item_i;
119
120 // specifies how large the slot rects are
122 // specifies how large the space between slots is (space between is spacing-size)
124
125 // the GUIFormSpecMenu can have an item selected and co.
127
129
130 // the font
131 gui::IGUIFont *m_font;
132
133 // the index of the hovered item; -1 if no item is hovered
135
136 // we do not want to write a warning on every draw
138};
Definition guiFormSpecMenu.h:88
void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h)
Definition guiInventoryList.h:90
bool isPointInside(const core::position2d< s32 > &point) const override
Definition guiInventoryList.cpp:243
const s32 m_start_item_i
Definition guiInventoryList.h:118
void setHoveredIndex(s32 item_i)
Definition guiInventoryList.cpp:248
s32 m_hovered_i
Definition guiInventoryList.h:134
const std::string & getListname() const
Definition guiInventoryList.h:85
s32 getItemIndexAtPos(v2s32 p) const
Definition guiInventoryList.cpp:253
const v2s32 getSlotSize() const noexcept
Definition guiInventoryList.h:102
GUIFormSpecMenu * m_fs_menu
Definition guiInventoryList.h:126
const v2f32 m_slot_spacing
Definition guiInventoryList.h:123
GUIInventoryList(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, const core::rect< s32 > &rectangle, InventoryManager *invmgr, const InventoryLocation &inventoryloc, const std::string &listname, const v2s32 &geom, const s32 start_item_i, const v2s32 &slot_size, const v2f32 &slot_spacing, GUIFormSpecMenu *fs_menu, const Options &options, gui::IGUIFont *font)
Definition guiInventoryList.cpp:12
const InventoryLocation & getInventoryloc() const
Definition guiInventoryList.h:80
void setSlotBorders(bool slotborder, const video::SColor &slotbordercolor)
Definition guiInventoryList.h:96
bool OnEvent(const SEvent &event) override
Definition guiInventoryList.cpp:226
Options m_options
Definition guiInventoryList.h:128
bool m_already_warned
Definition guiInventoryList.h:137
const v2s32 m_geom
Definition guiInventoryList.h:116
const InventoryLocation m_inventoryloc
Definition guiInventoryList.h:112
gui::IGUIFont * m_font
Definition guiInventoryList.h:131
void draw() override
Definition guiInventoryList.cpp:42
InventoryManager * m_invmgr
Definition guiInventoryList.h:111
const v2s32 m_slot_size
Definition guiInventoryList.h:121
const std::string m_listname
Definition guiInventoryList.h:113
Definition inventorymanager.h:96
core::vector2d< f32 > v2f32
Definition irr_v2d.h:15
core::vector2d< s32 > v2s32
Definition irr_v2d.h:13
v2s32 slotsize
Definition guiInventoryList.h:44
ItemSpec(const InventoryLocation &a_inventoryloc, const std::string &a_listname, s32 a_i, const v2s32 slotsize)
Definition guiInventoryList.h:22
bool isValid() const
Definition guiInventoryList.h:39
bool operator==(const ItemSpec &other) const
Definition guiInventoryList.h:33
InventoryLocation inventoryloc
Definition guiInventoryList.h:41
s32 i
Definition guiInventoryList.h:43
std::string listname
Definition guiInventoryList.h:42
Definition guiInventoryList.h:48
video::SColor slotbg_h
Definition guiInventoryList.h:54
bool slotborder
Definition guiInventoryList.h:50
video::SColor slotbordercolor
Definition guiInventoryList.h:51
video::SColor slotbg_n
Definition guiInventoryList.h:53
Definition inventorymanager.h:18
static std::string p(std::string path)
Definition test_filesys.cpp:66