3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "inventorymanager.h"
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/string.h"
26 class GUIFormSpecMenu;
28 class GUIInventoryList : public gui::IGUIElement
35 ItemSpec(const InventoryLocation &a_inventoryloc,
36 const std::string &a_listname,
38 inventoryloc(a_inventoryloc),
44 bool isValid() const { return i != -1; }
46 InventoryLocation inventoryloc;
51 // options for inventorylists that are setable with the lua api
53 // whether a one-pixel border for the slots should be drawn and its color
54 bool slotborder = false;
55 video::SColor slotbordercolor = video::SColor(200, 0, 0, 0);
56 // colors for normal and highlighted slot background
57 video::SColor slotbg_n = video::SColor(255, 128, 128, 128);
58 video::SColor slotbg_h = video::SColor(255, 192, 192, 192);
61 GUIInventoryList(gui::IGUIEnvironment *env,
62 gui::IGUIElement *parent,
64 const core::rect<s32> &rectangle,
65 InventoryManager *invmgr,
66 const InventoryLocation &inventoryloc,
67 const std::string &listname,
69 const s32 start_item_i,
70 const v2s32 &slot_size,
71 const v2f32 &slot_spacing,
72 GUIFormSpecMenu *fs_menu,
73 const Options &options,
76 virtual void draw() override;
78 virtual bool OnEvent(const SEvent &event) override;
80 const InventoryLocation &getInventoryloc() const
82 return m_inventoryloc;
85 const std::string &getListname() const
90 void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h)
92 m_options.slotbg_n = slotbg_n;
93 m_options.slotbg_h = slotbg_h;
96 void setSlotBorders(bool slotborder, const video::SColor &slotbordercolor)
98 m_options.slotborder = slotborder;
99 m_options.slotbordercolor = slotbordercolor;
102 // returns -1 if not item is at pos p
103 s32 getItemIndexAtPos(v2s32 p) const;
106 InventoryManager *m_invmgr;
107 const InventoryLocation m_inventoryloc;
108 const std::string m_listname;
110 // the specified width and height of the shown inventorylist in itemslots
112 // the first item's index in inventory
113 const s32 m_start_item_i;
115 // specifies how large the slot rects are
116 const v2s32 m_slot_size;
117 // specifies how large the space between slots is (space between is spacing-size)
118 const v2f32 m_slot_spacing;
120 // the GUIFormSpecMenu can have an item selected and co.
121 GUIFormSpecMenu *m_fs_menu;
126 gui::IGUIFont *m_font;
128 // the index of the hovered item; -1 if no item is hovered
131 // we do not want to write a warning on every draw
132 bool m_already_warned;