New elements in formspec, item_image and item_image_button.
Fixed also game bug drawing dragged item behind fields, buttons etc.master
parent
fa50341a71
commit
f4b7e1a570
|
@ -697,6 +697,10 @@ image[<X>,<Y>;<W>,<H>;<texture name>]
|
|||
^ Show an image
|
||||
^ Position and size units are inventory slots
|
||||
|
||||
item_image[<X>,<Y>;<W>,<H>;<item name>]
|
||||
^ Show an inventory image of registered item/node
|
||||
^ Position and size units are inventory slots
|
||||
|
||||
background[<X>,<Y>;<W>,<H>;<texture name>]
|
||||
^ Use a background. Inventory rectangles are not drawn then.
|
||||
^ Position and size units are inventory slots
|
||||
|
@ -738,6 +742,12 @@ image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
|
|||
^ image is the filename of an image
|
||||
^ Position and size units are inventory slots
|
||||
|
||||
item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]
|
||||
^ x, y, w, h, name and label work as per button
|
||||
^ item name is the registered name of an item/node,
|
||||
tooltip will be made out of its descritption
|
||||
^ Position and size units are inventory slots
|
||||
|
||||
button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]
|
||||
^ When clicked, fields will be sent and the form will quit.
|
||||
|
||||
|
|
|
@ -201,6 +201,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
m_inventorylists.clear();
|
||||
m_images.clear();
|
||||
m_backgrounds.clear();
|
||||
m_itemimages.clear();
|
||||
m_fields.clear();
|
||||
|
||||
Strfnd f(m_formspec_string);
|
||||
|
@ -283,6 +284,23 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
errorstream<<"WARNING: invalid use of image without a size[] element"<<std::endl;
|
||||
m_images.push_back(ImageDrawSpec(name, pos, geom));
|
||||
}
|
||||
else if(type == "item_image")
|
||||
{
|
||||
v2s32 pos = basepos;
|
||||
pos.X += stof(f.next(",")) * (float)spacing.X;
|
||||
pos.Y += stof(f.next(";")) * (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("]");
|
||||
errorstream<<"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;
|
||||
|
@ -484,6 +502,43 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
|
||||
m_fields.push_back(spec);
|
||||
}
|
||||
else if(type == "item_image_button")
|
||||
{
|
||||
v2s32 pos = padding;
|
||||
pos.X += stof(f.next(",")) * (float)spacing.X;
|
||||
pos.Y += stof(f.next(";")) * (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);
|
||||
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("]");
|
||||
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 = item.getDefinition(idef).inventory_texture;
|
||||
std::string tooltip = item.getDefinition(idef).description;
|
||||
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
|
||||
|
@ -767,15 +822,40 @@ void GUIFormSpecMenu::drawMenu()
|
|||
drawList(m_inventorylists[i], phase);
|
||||
}
|
||||
|
||||
/*
|
||||
Draw dragged item stack
|
||||
*/
|
||||
drawSelectedItem();
|
||||
|
||||
/*
|
||||
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()
|
||||
|
|
|
@ -133,6 +133,7 @@ class GUIFormSpecMenu : public GUIModalMenu
|
|||
send = false;
|
||||
is_button = false;
|
||||
is_exit = false;
|
||||
tooltip="";
|
||||
}
|
||||
std::wstring fname;
|
||||
std::wstring flabel;
|
||||
|
@ -141,6 +142,8 @@ class GUIFormSpecMenu : public GUIModalMenu
|
|||
bool send;
|
||||
bool is_button;
|
||||
bool is_exit;
|
||||
core::rect<s32> rect;
|
||||
std::string tooltip;
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -209,6 +212,7 @@ protected:
|
|||
core::array<ListDrawSpec> m_inventorylists;
|
||||
core::array<ImageDrawSpec> m_backgrounds;
|
||||
core::array<ImageDrawSpec> m_images;
|
||||
core::array<ImageDrawSpec> m_itemimages;
|
||||
core::array<FieldSpec> m_fields;
|
||||
|
||||
ItemSpec *m_selected_item;
|
||||
|
|
Loading…
Reference in New Issue