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