/*
-Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
return;
const ItemDefinition &def = item.getDefinition(gamedef->idef());
- video::ITexture *texture = def.inventory_texture;
+ video::ITexture *texture = gamedef->idef()->getInventoryTexture(def.name, gamedef);
// Draw the inventory texture
if(texture != NULL)
GUIFormSpecMenu
*/
-GUIFormSpecMenu::GUIFormSpecMenu(gui::IGUIEnvironment* env,
+GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
InventoryManager *invmgr,
IGameDef *gamedef
):
- GUIModalMenu(env, parent, id, menumgr),
+ GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
+ m_device(dev),
m_invmgr(invmgr),
m_gamedef(gamedef),
m_form_src(NULL),
delete m_selected_item;
delete m_form_src;
+ delete m_text_dst;
}
void GUIFormSpecMenu::removeChildren()
m_inventorylists.clear();
m_images.clear();
+ m_backgrounds.clear();
+ m_itemimages.clear();
m_fields.clear();
Strfnd f(m_formspec_string);
while(f.atend() == false)
{
- std::string type = trim(f.next("["));
+ std::string type = trim(f.next_esc("["));
if(type == "invsize" || type == "size")
{
v2f invsize;
- invsize.X = stof(f.next(","));
+ invsize.X = stof(f.next_esc(","));
if(type == "size")
{
- invsize.Y = stof(f.next("]"));
+ invsize.Y = stof(f.next_esc("]"));
}
else{
- invsize.Y = stof(f.next(";"));
- errorstream<<"WARNING: invsize is deprecated, use size"<<std::endl;
- f.next("]");
+ invsize.Y = stof(f.next_esc(";"));
+ f.next_esc("]");
}
- infostream<<"size ("<<invsize.X<<","<<invsize.Y<<")"<<std::endl;
+ infostream<<"Form size ("<<invsize.X<<","<<invsize.Y<<")"<<std::endl;
padding = v2s32(screensize.Y/40, screensize.Y/40);
spacing = v2s32(screensize.Y/12, screensize.Y/13);
}
else if(type == "list")
{
- std::string name = f.next(";");
+ std::string name = f.next_esc(";");
InventoryLocation loc;
if(name == "context" || name == "current_name")
loc = m_current_inventory_location;
else
loc.deSerialize(name);
- std::string listname = f.next(";");
+ std::string listname = f.next_esc(";");
v2s32 pos = basepos;
- pos.X += stof(f.next(",")) * (float)spacing.X;
- pos.Y += stof(f.next(";")) * (float)spacing.Y;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
v2s32 geom;
- geom.X = stoi(f.next(","));
- geom.Y = stoi(f.next(";"));
+ geom.X = stoi(f.next_esc(","));
+ geom.Y = stoi(f.next_esc(";"));
infostream<<"list inv="<<name<<", listname="<<listname
<<", pos=("<<pos.X<<","<<pos.Y<<")"
<<", geom=("<<geom.X<<","<<geom.Y<<")"
<<std::endl;
- f.next("]");
+ std::string start_i_s = f.next_esc("]");
+ s32 start_i = 0;
+ if(start_i_s != "")
+ start_i = stoi(start_i_s);
if(bp_set != 2)
- errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
- m_inventorylists.push_back(ListDrawSpec(loc, listname, pos, geom));
+ errorstream<<"WARNING: invalid use of list without a size[] element"<<std::endl;
+ m_inventorylists.push_back(ListDrawSpec(loc, listname, pos, geom, start_i));
}
else if(type == "image")
{
v2s32 pos = basepos;
- pos.X += stof(f.next(",")) * (float)spacing.X;
- pos.Y += stof(f.next(";")) * (float)spacing.Y;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
v2s32 geom;
- geom.X = stof(f.next(",")) * (float)imgsize.X;
- geom.Y = stof(f.next(";")) * (float)imgsize.Y;
- std::string name = f.next("]");
+ geom.X = stof(f.next_esc(",")) * (float)imgsize.X;
+ geom.Y = stof(f.next_esc(";")) * (float)imgsize.Y;
+ std::string name = f.next_esc("]");
infostream<<"image name="<<name
<<", pos=("<<pos.X<<","<<pos.Y<<")"
<<", geom=("<<geom.X<<","<<geom.Y<<")"
<<std::endl;
if(bp_set != 2)
- errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
+ errorstream<<"WARNING: invalid use of image without a size[] element"<<std::endl;
m_images.push_back(ImageDrawSpec(name, pos, geom));
}
- else if(type == "field")
+ else if(type == "item_image")
{
- std::string fname = f.next(";");
- std::string flabel = f.next(";");
-
+ v2s32 pos = basepos;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
+ v2s32 geom;
+ geom.X = stof(f.next_esc(",")) * (float)imgsize.X;
+ geom.Y = stof(f.next_esc(";")) * (float)imgsize.Y;
+ std::string name = f.next_esc("]");
+ infostream<<"item name="<<name
+ <<", pos=("<<pos.X<<","<<pos.Y<<")"
+ <<", geom=("<<geom.X<<","<<geom.Y<<")"
+ <<std::endl;
+ if(bp_set != 2)
+ errorstream<<"WARNING: invalid use of item_image without a size[] element"<<std::endl;
+ m_itemimages.push_back(ImageDrawSpec(name, pos, geom));
+ }
+ else if(type == "background")
+ {
+ v2s32 pos = basepos;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X - ((float)spacing.X-(float)imgsize.X)/2;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y - ((float)spacing.Y-(float)imgsize.Y)/2;
+ v2s32 geom;
+ geom.X = stof(f.next_esc(",")) * (float)spacing.X;
+ geom.Y = stof(f.next_esc(";")) * (float)spacing.Y;
+ std::string name = f.next_esc("]");
+ infostream<<"image name="<<name
+ <<", pos=("<<pos.X<<","<<pos.Y<<")"
+ <<", geom=("<<geom.X<<","<<geom.Y<<")"
+ <<std::endl;
+ if(bp_set != 2)
+ errorstream<<"WARNING: invalid use of background without a size[] element"<<std::endl;
+ m_backgrounds.push_back(ImageDrawSpec(name, pos, geom));
+ }
+ else if(type == "field" || type == "textarea")
+ {
+ std::string fname = f.next_esc(";");
+ std::string flabel = f.next_esc(";");
+
if(fname.find(",") == std::string::npos && flabel.find(",") == std::string::npos)
{
+ if (type == "textarea")
+ errorstream<<"WARNING: Textarea connot be unpositioned"<<std::endl;
+
if(!bp_set)
{
rect = core::rect<s32>(
bp_set = 1;
}
else if(bp_set == 2)
- errorstream<<"WARNING: invalid use of unpositioned field in inventory"<<std::endl;
+ errorstream<<"WARNING: invalid use of unpositioned "<<type<<" in inventory"<<std::endl;
v2s32 pos = basepos;
pos.Y = ((m_fields.size()+2)*60);
pos.Y = stof(fname.substr(fname.find(",")+1)) * (float)spacing.Y;
v2s32 geom;
geom.X = (stof(flabel.substr(0,flabel.find(","))) * (float)spacing.X)-(spacing.X-imgsize.X);
- pos.Y += (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y)/2;
+ if (type == "textarea")
+ {
+ geom.Y = (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y) - (spacing.Y-imgsize.Y);
+ pos.Y += 15;
+ }
+ else
+ {
+ pos.Y += (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y)/2;
+ pos.Y -= 15;
+ geom.Y = 30;
+ }
+
+ rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
- rect = core::rect<s32>(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15);
- fname = f.next(";");
- flabel = f.next(";");
+ fname = f.next_esc(";");
+ flabel = f.next_esc(";");
if(bp_set != 2)
- errorstream<<"WARNING: invalid use of positioned field without a size[] element"<<std::endl;
+ errorstream<<"WARNING: invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
}
- std::string odefault = f.next("]");
+ std::string odefault = f.next_esc("]");
std::string fdefault;
-
+
// fdefault may contain a variable reference, which
// needs to be resolved from the node metadata
if(m_form_src)
else
fdefault = odefault;
+ fdefault = unescape_string(fdefault);
+ flabel = unescape_string(flabel);
+
FieldSpec spec = FieldSpec(
narrow_to_wide(fname.c_str()),
narrow_to_wide(flabel.c_str()),
narrow_to_wide(fdefault.c_str()),
258+m_fields.size()
);
-
- // three cases: field and no label, label and no field, label and field
- if (flabel == "")
- {
- spec.send = true;
- gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
- Environment->setFocus(e);
- irr::SEvent evt;
- evt.EventType = EET_KEY_INPUT_EVENT;
- evt.KeyInput.Key = KEY_END;
- evt.KeyInput.PressedDown = true;
- e->OnEvent(evt);
- }
- else if (fname == "")
+ // three cases: field name and no label, label and field, label name and no field
+ gui::IGUIEditBox *e;
+ if (fname == "")
{
- // set spec field id to 0, this stops submit searching for a value that isn't there
+ // spec field id to 0, this stops submit searching for a value that isn't there
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
}
else
{
spec.send = true;
- gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
+ e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
Environment->setFocus(e);
- rect.UpperLeftCorner.Y -= 15;
- rect.LowerRightCorner.Y -= 15;
- Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
-
- irr::SEvent evt;
- evt.EventType = EET_KEY_INPUT_EVENT;
- evt.KeyInput.Key = KEY_END;
- evt.KeyInput.PressedDown = true;
- e->OnEvent(evt);
+
+ if (type == "textarea")
+ {
+ e->setMultiLine(true);
+ e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
+ } else {
+ irr::SEvent evt;
+ evt.KeyInput.Key = KEY_END;
+ evt.EventType = EET_KEY_INPUT_EVENT;
+ evt.KeyInput.PressedDown = true;
+ e->OnEvent(evt);
+ }
+
+ if (flabel != "")
+ {
+ rect.UpperLeftCorner.Y -= 15;
+ rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 15;
+ Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
+ }
}
-
+
m_fields.push_back(spec);
}
else if(type == "label")
{
- v2s32 pos;
- pos.X = stof(f.next(",")) * (float)spacing.X;
- pos.Y = stof(f.next(";")) * (float)spacing.Y;
+ v2s32 pos = padding;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
- std::string flabel = f.next("]");
+ std::string flabel = f.next_esc("]");
if(bp_set != 2)
errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
+ flabel = unescape_string(flabel);
+
FieldSpec spec = FieldSpec(
narrow_to_wide(""),
narrow_to_wide(flabel.c_str()),
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
m_fields.push_back(spec);
}
- else if(type == "button")
+ else if(type == "button" || type == "button_exit")
{
- v2s32 pos;
- pos.X = stof(f.next(",")) * (float)spacing.X;
- pos.Y = stof(f.next(";")) * (float)spacing.Y;
+ v2s32 pos = padding;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
v2s32 geom;
- geom.X = (stof(f.next(",")) * (float)spacing.X)-(spacing.X-imgsize.X);
- pos.Y += (stof(f.next(";")) * (float)imgsize.Y)/2;
+ geom.X = (stof(f.next_esc(",")) * (float)spacing.X)-(spacing.X-imgsize.X);
+ pos.Y += (stof(f.next_esc(";")) * (float)imgsize.Y)/2;
rect = core::rect<s32>(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15);
- std::string fname = f.next(";");
- std::string flabel = f.next("]");
+ std::string fname = f.next_esc(";");
+ std::string flabel = f.next_esc("]");
if(bp_set != 2)
errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
+ flabel = unescape_string(flabel);
+
FieldSpec spec = FieldSpec(
narrow_to_wide(fname.c_str()),
narrow_to_wide(flabel.c_str()),
258+m_fields.size()
);
spec.is_button = true;
+ if(type == "button_exit")
+ spec.is_exit = true;
Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
m_fields.push_back(spec);
}
- else if(type == "image_button")
+ else if(type == "image_button" || type == "image_button_exit")
{
- v2s32 pos;
- pos.X = stof(f.next(",")) * (float)spacing.X;
- pos.Y = stof(f.next(";")) * (float)spacing.Y;
+ v2s32 pos = padding;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
v2s32 geom;
- geom.X = (stof(f.next(",")) * (float)spacing.X)-(spacing.X-imgsize.X);
- geom.Y = (stof(f.next(";")) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
+ geom.X = (stof(f.next_esc(",")) * (float)spacing.X)-(spacing.X-imgsize.X);
+ geom.Y = (stof(f.next_esc(";")) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
- std::string fimage = f.next(";");
- std::string fname = f.next(";");
- std::string flabel = f.next("]");
+ std::string fimage = f.next_esc(";");
+ std::string fname = f.next_esc(";");
+ std::string flabel = f.next_esc("]");
if(bp_set != 2)
errorstream<<"WARNING: invalid use of image_button without a size[] element"<<std::endl;
+ flabel = unescape_string(flabel);
+
FieldSpec spec = FieldSpec(
narrow_to_wide(fname.c_str()),
narrow_to_wide(flabel.c_str()),
258+m_fields.size()
);
spec.is_button = true;
+ if(type == "image_button_exit")
+ spec.is_exit = true;
video::ITexture *texture = m_gamedef->tsrc()->getTextureRaw(fimage);
gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
+ e->setUseAlphaChannel(true);
e->setImage(texture);
e->setPressedImage(texture);
e->setScaleImage(true);
m_fields.push_back(spec);
}
+ else if(type == "item_image_button")
+ {
+ v2s32 pos = padding;
+ pos.X += stof(f.next_esc(",")) * (float)spacing.X;
+ pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
+ v2s32 geom;
+ geom.X = (stof(f.next_esc(",")) * (float)spacing.X)-(spacing.X-imgsize.X);
+ geom.Y = (stof(f.next_esc(";")) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
+ rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+ std::string fimage = f.next_esc(";");
+ std::string fname = f.next_esc(";");
+ std::string flabel = f.next_esc("]");
+ if(bp_set != 2)
+ errorstream<<"WARNING: invalid use of item_image_button without a size[] element"<<std::endl;
+ IItemDefManager *idef = m_gamedef->idef();
+ ItemStack item;
+ item.deSerialize(fimage, idef);
+ video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
+ std::string tooltip = item.getDefinition(idef).description;
+ flabel = unescape_string(flabel);
+ FieldSpec spec = FieldSpec(
+ narrow_to_wide(fname.c_str()),
+ narrow_to_wide(flabel.c_str()),
+ narrow_to_wide(fimage.c_str()),
+ 258+m_fields.size()
+ );
+ gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
+ e->setUseAlphaChannel(true);
+ e->setImage(texture);
+ e->setPressedImage(texture);
+ e->setScaleImage(true);
+ spec.is_button = true;
+ rect+=basepos-padding;
+ spec.rect=rect;
+ if (tooltip!="")
+ spec.tooltip=tooltip;
+ m_fields.push_back(spec);
+ }
else
{
// Ignore others
- std::string ts = f.next("]");
+ std::string ts = f.next_esc("]");
infostream<<"Unknown DrawSpec: type="<<type<<", data=\""<<ts<<"\""
<<std::endl;
}
size.Y-rect.getHeight()-5);
const wchar_t *text = wgettext("Left click: Move all items, Right click: Move single item");
Environment->addStaticText(text, rect, false, true, this, 256);
+ delete[] text;
changeCtype("C");
}
// If there's fields, add a Proceed button
v2s32 size = DesiredRect.getSize();
rect = core::rect<s32>(size.X/2-70, pos.Y, (size.X/2-70)+140, pos.Y+30);
- Environment->addButton(rect, this, 257, wgettext("Proceed"));
+ wchar_t* text = wgettext("Proceed");
+ Environment->addButton(rect, this, 257, text);
+ delete[] text;
}
changeCtype("C");
}
for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
{
+ s32 item_i = i + s.start_item_i;
s32 x = (i%s.geom.X) * spacing.X;
s32 y = (i/s.geom.X) * spacing.Y;
v2s32 p0(x,y);
core::rect<s32> rect = imgrect + s.pos + p0;
if(rect.isPointInside(p))
{
- return ItemSpec(s.inventoryloc, s.listname, i);
+ return ItemSpec(s.inventoryloc, s.listname, item_i);
}
}
}
for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
{
+ u32 item_i = i + s.start_item_i;
+ if(item_i >= ilist->getSize())
+ break;
s32 x = (i%s.geom.X) * spacing.X;
s32 y = (i/s.geom.X) * spacing.Y;
v2s32 p(x,y);
core::rect<s32> rect = imgrect + s.pos + p;
ItemStack item;
if(ilist)
- item = ilist->getItem(i);
+ item = ilist->getItem(item_i);
bool selected = m_selected_item
&& m_invmgr->getInventory(m_selected_item->inventoryloc) == inv
}
}
+ m_pointer = m_device->getCursorControl()->getPosition();
+
updateSelectedItem();
gui::IGUISkin* skin = Environment->getSkin();
m_tooltip_element->setVisible(false);
/*
- Draw items
- Phase 0: Item slot rectangles
- Phase 1: Item images; prepare tooltip
+ Draw backgrounds
*/
-
- for(int phase=0; phase<=1; phase++)
- for(u32 i=0; i<m_inventorylists.size(); i++)
+ for(u32 i=0; i<m_backgrounds.size(); i++)
{
- drawList(m_inventorylists[i], phase);
+ const ImageDrawSpec &spec = m_backgrounds[i];
+ video::ITexture *texture =
+ m_gamedef->tsrc()->getTextureRaw(spec.name);
+ // Image size on screen
+ core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
+ // Image rectangle on screen
+ core::rect<s32> rect = imgrect + spec.pos;
+ const video::SColor color(255,255,255,255);
+ const video::SColor colors[] = {color,color,color,color};
+ driver->draw2DImage(texture, rect,
+ core::rect<s32>(core::position2d<s32>(0,0),
+ core::dimension2di(texture->getOriginalSize())),
+ NULL/*&AbsoluteClippingRect*/, colors, true);
}
-
+
+ /*
+ Draw images
+ */
for(u32 i=0; i<m_images.size(); i++)
{
const ImageDrawSpec &spec = m_images[i];
core::dimension2di(texture->getOriginalSize())),
NULL/*&AbsoluteClippingRect*/, colors, true);
}
-
+
/*
- Draw dragged item stack
+ Draw item images
*/
- drawSelectedItem();
+ for(u32 i=0; i<m_itemimages.size(); i++)
+ {
+ const ImageDrawSpec &spec = m_itemimages[i];
+ IItemDefManager *idef = m_gamedef->idef();
+ ItemStack item;
+ item.deSerialize(spec.name, idef);
+ video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
+ // Image size on screen
+ core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
+ // Image rectangle on screen
+ core::rect<s32> rect = imgrect + spec.pos;
+ const video::SColor color(255,255,255,255);
+ const video::SColor colors[] = {color,color,color,color};
+ driver->draw2DImage(texture, rect,
+ core::rect<s32>(core::position2d<s32>(0,0),
+ core::dimension2di(texture->getOriginalSize())),
+ NULL/*&AbsoluteClippingRect*/, colors, true);
+ }
+
+ /*
+ Draw items
+ Phase 0: Item slot rectangles
+ Phase 1: Item images; prepare tooltip
+ If backgrounds used, do not draw Item slot rectangles
+ */
+ int start_phase=0;
+ if (m_backgrounds.size() > 0) start_phase=1;
+ for(int phase=start_phase; phase<=1; phase++)
+ for(u32 i=0; i<m_inventorylists.size(); i++)
+ {
+ drawList(m_inventorylists[i], phase);
+ }
/*
Call base class
*/
gui::IGUIElement::draw();
+
+ /*
+ Draw fields/buttons tooltips
+ */
+ for(u32 i=0; i<m_fields.size(); i++)
+ {
+ const FieldSpec &spec = m_fields[i];
+ if (spec.tooltip != "")
+ {
+ core::rect<s32> rect = spec.rect;
+ if (rect.isPointInside(m_pointer))
+ {
+ m_tooltip_element->setVisible(true);
+ this->bringToFront(m_tooltip_element);
+ m_tooltip_element->setText(narrow_to_wide(spec.tooltip).c_str());
+ s32 tooltip_x = m_pointer.X + 15;
+ s32 tooltip_y = m_pointer.Y + 15;
+ s32 tooltip_width = m_tooltip_element->getTextWidth() + 15;
+ s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
+ m_tooltip_element->setRelativePosition(core::rect<s32>(
+ core::position2d<s32>(tooltip_x, tooltip_y),
+ core::dimension2d<s32>(tooltip_width, tooltip_height)));
+ }
+ }
+ }
+
+ /*
+ Draw dragged item stack
+ */
+ drawSelectedItem();
}
void GUIFormSpecMenu::updateSelectedItem()
{
+ // WARNING: BLACK MAGIC
+ // See if there is a stack suited for our current guess.
+ // If such stack does not exist, clear the guess.
+ if(m_selected_content_guess.name != "")
+ {
+ bool found = false;
+ for(u32 i=0; i<m_inventorylists.size() && !found; i++){
+ const ListDrawSpec &s = m_inventorylists[i];
+ Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
+ if(!inv)
+ continue;
+ InventoryList *list = inv->getList(s.listname);
+ if(!list)
+ continue;
+ for(s32 i=0; i<s.geom.X*s.geom.Y && !found; i++){
+ u32 item_i = i + s.start_item_i;
+ if(item_i >= list->getSize())
+ continue;
+ ItemStack stack = list->getItem(item_i);
+ if(stack.name == m_selected_content_guess.name &&
+ stack.count == m_selected_content_guess.count){
+ found = true;
+ if(m_selected_item){
+ // If guessed stack is already selected, all is fine
+ if(m_selected_item->inventoryloc == s.inventoryloc &&
+ m_selected_item->listname == s.listname &&
+ m_selected_item->i == (s32)item_i &&
+ m_selected_amount == stack.count){
+ break;
+ }
+ delete m_selected_item;
+ m_selected_item = NULL;
+ }
+ infostream<<"Client: Changing selected content guess to "
+ <<s.inventoryloc.dump()<<" "<<s.listname
+ <<" "<<item_i<<std::endl;
+ m_selected_item = new ItemSpec(s.inventoryloc, s.listname, item_i);
+ m_selected_amount = stack.count;
+ break;
+ }
+ }
+ }
+ if(!found){
+ infostream<<"Client: Discarding selected content guess: "
+ <<m_selected_content_guess.getItemString()<<std::endl;
+ m_selected_content_guess.name = "";
+ }
+ }
// If the selected stack has become empty for some reason, deselect it.
// If the selected stack has become smaller, adjust m_selected_amount.
if(m_selected_item)
}
}
m_text_dst->gotText(fields);
- delete m_text_dst;
- m_text_dst = NULL;
}
}
return true;
}
}
- if(event.EventType==EET_MOUSE_INPUT_EVENT
- && event.MouseInput.Event == EMIE_MOUSE_MOVED)
- {
- // Mouse moved
- m_pointer = v2s32(event.MouseInput.X, event.MouseInput.Y);
- }
if(event.EventType==EET_MOUSE_INPUT_EVENT
&& event.MouseInput.Event != EMIE_MOUSE_MOVED)
{
// Mouse event other than movement
- v2s32 p(event.MouseInput.X, event.MouseInput.Y);
- m_pointer = p;
-
// Get selected item and hovered/clicked item (s)
updateSelectedItem();
- ItemSpec s = getItemAtPos(p);
+ ItemSpec s = getItemAtPos(m_pointer);
Inventory *inv_selected = NULL;
Inventory *inv_s = NULL;
InventoryList *list = inv_s->getList(s.listname);
if(list == NULL){
- errorstream<<"InventoryMenu: The selected inventory list \""
+ verbosestream<<"InventoryMenu: The selected inventory list \""
<<s.listname<<"\" does not exist"<<std::endl;
s.i = -1; // make it invalid again
break;
}
if((u32)s.i >= list->getSize()){
- errorstream<<"InventoryMenu: The selected inventory list \""
+ infostream<<"InventoryMenu: The selected inventory list \""
<<s.listname<<"\" is too small (i="<<s.i<<", size="
<<list->getSize()<<")"<<std::endl;
s.i = -1; // make it invalid again
// Check how many items can be moved
move_amount = stack_from.count = MYMIN(move_amount, stack_from.count);
ItemStack leftover = stack_to.addItem(stack_from, m_gamedef->idef());
- if(leftover.count == stack_from.count)
+ // If source stack cannot be added to destination stack at all,
+ // they are swapped
+ if(leftover.count == stack_from.count && leftover.name == stack_from.name)
{
- // Swap the stacks
- m_selected_amount -= stack_to.count;
+ m_selected_amount = stack_to.count;
+ // In case the server doesn't directly swap them but instead
+ // moves stack_to somewhere else, set this
+ m_selected_content_guess = stack_to;
+ m_selected_content_guess_inventory = s.inventoryloc;
}
+ // Source stack goes fully into destination stack
else if(leftover.empty())
{
- // Item fits
m_selected_amount -= move_amount;
+ m_selected_content_guess = ItemStack(); // Clear
}
+ // Source stack goes partly into destination stack
else
{
- // Item only fits partially
move_amount -= leftover.count;
m_selected_amount -= move_amount;
+ m_selected_content_guess = ItemStack(); // Clear
}
infostream<<"Handing IACTION_MOVE to manager"<<std::endl;
}
else if(drop_amount > 0)
{
+ m_selected_content_guess = ItemStack(); // Clear
+
// Send IACTION_DROP
assert(m_selected_item && m_selected_item->isValid());
}
else if(craft_amount > 0)
{
+ m_selected_content_guess = ItemStack(); // Clear
+
// Send IACTION_CRAFT
assert(s.isValid());
m_selected_item = NULL;
m_selected_amount = 0;
m_selected_dragging = false;
+ m_selected_content_guess = ItemStack();
}
}
if(event.EventType==EET_GUI_EVENT)
{
s.send = true;
acceptInput();
- quitMenu();
- return true;
+ if(s.is_exit){
+ quitMenu();
+ return true;
+ }else{
+ s.send = false;
+ // Restore focus to the full form
+ Environment->setFocus(this);
+ return true;
+ }
}
}
}