Luanti 5.15.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
79 {
80 return m_inventoryloc;
81 }
82
83 const std::string &getListname() const
84 {
85 return m_listname;
86 }
87
88 void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h)
89 {
90 m_options.slotbg_n = slotbg_n;
91 m_options.slotbg_h = slotbg_h;
92 }
93
94 void setSlotBorders(bool slotborder, const video::SColor &slotbordercolor)
95 {
96 m_options.slotborder = slotborder;
97 m_options.slotbordercolor = slotbordercolor;
98 }
99
100 const v2s32 getSlotSize() const noexcept
101 {
102 return m_slot_size;
103 }
104
105 // returns -1 if not item is at pos p
106 s32 getItemIndexAtPos(v2s32 p) const;
107
108private:
111 const std::string m_listname;
112
113 // the specified width and height of the shown inventorylist in itemslots
115 // the first item's index in inventory
116 const s32 m_start_item_i;
117
118 // specifies how large the slot rects are
120 // specifies how large the space between slots is (space between is spacing-size)
122
123 // the GUIFormSpecMenu can have an item selected and co.
125
127
128 // the font
129 gui::IGUIFont *m_font;
130
131 // the index of the hovered item; -1 if no item is hovered
133
134 // we do not want to write a warning on every draw
136};
Definition guiFormSpecMenu.h:86
Definition guiInventoryList.h:16
void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h)
Definition guiInventoryList.h:88
bool isPointInside(const core::position2d< s32 > &point) const override
Definition guiInventoryList.cpp:192
const s32 m_start_item_i
Definition guiInventoryList.h:116
s32 m_hovered_i
Definition guiInventoryList.h:132
const std::string & getListname() const
Definition guiInventoryList.h:83
s32 getItemIndexAtPos(v2s32 p) const
Definition guiInventoryList.cpp:197
const v2s32 getSlotSize() const noexcept
Definition guiInventoryList.h:100
GUIFormSpecMenu * m_fs_menu
Definition guiInventoryList.h:124
const v2f32 m_slot_spacing
Definition guiInventoryList.h:121
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:78
void setSlotBorders(bool slotborder, const video::SColor &slotbordercolor)
Definition guiInventoryList.h:94
bool OnEvent(const SEvent &event) override
Definition guiInventoryList.cpp:175
Options m_options
Definition guiInventoryList.h:126
bool m_already_warned
Definition guiInventoryList.h:135
const v2s32 m_geom
Definition guiInventoryList.h:114
const InventoryLocation m_inventoryloc
Definition guiInventoryList.h:110
gui::IGUIFont * m_font
Definition guiInventoryList.h:129
void draw() override
Definition guiInventoryList.cpp:42
InventoryManager * m_invmgr
Definition guiInventoryList.h:109
const v2s32 m_slot_size
Definition guiInventoryList.h:119
const std::string m_listname
Definition guiInventoryList.h:111
Definition inventorymanager.h:96
core::vector2d< f32 > v2f32
Definition irr_v2d.h:15
core::vector2d< s32 > v2s32
Definition irr_v2d.h:13
Definition guiInventoryList.h:19
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:64