#include "guiInventoryMenu.h"
#include "constants.h"
-void drawInventoryItem(gui::IGUIEnvironment* env,
+void drawInventoryItem(video::IVideoDriver *driver,
+ gui::IGUIFont *font,
InventoryItem *item, core::rect<s32> rect,
const core::rect<s32> *clip)
{
- gui::IGUISkin* skin = env->getSkin();
- if (!skin)
+ if(item == NULL)
return;
- video::IVideoDriver* driver = env->getVideoDriver();
video::ITexture *texture = NULL;
-
- if(item != NULL)
- {
- texture = item->getImage();
- }
+ texture = item->getImage();
if(texture != NULL)
{
}
else
{
- video::SColor bgcolor(128,128,128,128);
+ video::SColor bgcolor(255,50,50,128);
driver->draw2DRectangle(bgcolor, rect, clip);
}
- if(item != NULL)
+ if(font != NULL)
{
- gui::IGUIFont *font = skin->getFont();
std::string text = item->getText();
if(font && text != "")
{
- core::rect<s32> rect2(rect.UpperLeftCorner,
- (core::dimension2d<u32>(rect.getWidth(), 15)));
+ v2u32 dim = font->getDimension(narrow_to_wide(text).c_str());
+ v2s32 sdim(dim.X,dim.Y);
+
+ core::rect<s32> rect2(
+ /*rect.UpperLeftCorner,
+ core::dimension2d<u32>(rect.getWidth(), 15)*/
+ rect.LowerRightCorner - sdim,
+ sdim
+ );
video::SColor bgcolor(128,0,0,0);
driver->draw2DRectangle(bgcolor, rect2, clip);
-
+
font->draw(text.c_str(), rect2,
video::SColor(255,255,255,255), false, false,
clip);
gui::IGUIElement* parent, s32 id,
Inventory *inventory,
Queue<InventoryAction*> *actions,
- int *active_menu_count):
- GUIModalMenu(env, parent, id, active_menu_count)
+ IMenuManager *menumgr):
+ GUIModalMenu(env, parent, id, menumgr)
{
m_inventory = inventory;
m_selected_item = NULL;
GUIInventoryMenu::~GUIInventoryMenu()
{
+ removeChildren();
+
if(m_selected_item)
delete m_selected_item;
}
+void GUIInventoryMenu::removeChildren()
+{
+ {
+ gui::IGUIElement *e = getElementFromId(256);
+ if(e != NULL)
+ e->remove();
+ }
+}
+
void GUIInventoryMenu::regenerateGui(v2u32 screensize)
{
+ // Remove children
+ removeChildren();
+
padding = v2s32(24,24);
spacing = v2s32(60,56);
imgsize = v2s32(48,48);
+ s32 helptext_h = 15;
+
v2s32 size(
padding.X*2+spacing.X*(8-1)+imgsize.X,
- padding.Y*2+spacing.Y*(7-1)+imgsize.Y
+ padding.Y*2+spacing.Y*(7-1)+imgsize.Y + helptext_h
);
core::rect<s32> rect(
basepos + v2s32(spacing.X*3, spacing.Y*0), v2s32(3, 3)));
m_draw_positions.push_back(ListDrawSpec("craftresult",
basepos + v2s32(spacing.X*7, spacing.Y*1), v2s32(1, 1)));
+
+ // Add children
+ {
+ core::rect<s32> rect(0, 0, size.X-padding.X*2, helptext_h);
+ rect = rect + v2s32(size.X/2 - rect.getWidth()/2,
+ size.Y-rect.getHeight()-15);
+ const wchar_t *text =
+ L"Left click: Move all items, Right click: Move single item";
+ Environment->addStaticText(text, rect, false, true, this, 256);
+ }
}
GUIInventoryMenu::ItemSpec GUIInventoryMenu::getItemAtPos(v2s32 p) const
{
video::IVideoDriver* driver = Environment->getVideoDriver();
+ // Get font
+ gui::IGUIFont *font = NULL;
+ gui::IGUISkin* skin = Environment->getSkin();
+ if (skin)
+ font = skin->getFont();
+
InventoryList *ilist = m_inventory->getList(s.listname);
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
-
+
for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
{
s32 x = (i%s.geom.X) * spacing.X;
driver->draw2DRectangle(video::SColor(255,255,0,0),
core::rect<s32>(rect.UpperLeftCorner - v2s32(2,2),
rect.LowerRightCorner + v2s32(2,2)),
- &AbsoluteClippingRect);
+ &AbsoluteClippingRect);
+ }
+
+ if(item)
+ {
+ drawInventoryItem(driver, font, item,
+ rect, &AbsoluteClippingRect);
+ }
+ else
+ {
+ video::SColor bgcolor(255,128,128,128);
+ driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
}
- drawInventoryItem(Environment, item,
- rect, &AbsoluteClippingRect);
}
}
m_inventory->getList(m_selected_item->listname);
InventoryList *list_to =
m_inventory->getList(s.listname);
+ // Indicates whether source slot completely empties
+ bool source_empties = false;
if(list_from && list_to
&& list_from->getItem(m_selected_item->i) != NULL)
{
dstream<<"Queueing IACTION_MOVE"<<std::endl;
- IMoveAction *a =
- new IMoveAction();
+ IMoveAction *a = new IMoveAction();
a->count = right ? 1 : 0;
a->from_name = m_selected_item->listname;
a->from_i = m_selected_item->i;
a->to_name = s.listname;
a->to_i = s.i;
m_actions->push_back(a);
+
+ if(list_from->getItem(m_selected_item->i)->getCount()==1)
+ source_empties = true;
}
- bool source_empties = false;
- if(list_from && list_from->getItem(m_selected_item->i)->getCount()==1)
- source_empties = true;
+ // Remove selection if target was left-clicked or source
+ // slot was emptied
if(right == false || source_empties)
{
delete m_selected_item;