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