From f4b7e1a5707850aad9f6c122c05de4d2f9ede074 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 1 Dec 2012 18:36:42 +0100 Subject: New elements in formspec, item_image and item_image_button. Fixed also game bug drawing dragged item behind fields, buttons etc. --- src/guiFormSpecMenu.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++--- src/guiFormSpecMenu.h | 4 +++ 2 files changed, 89 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 618141d24..66ac4c08f 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -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"<(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"<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 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( + core::position2d(tooltip_x, tooltip_y), + core::dimension2d(tooltip_width, tooltip_height))); + } + } + } + + /* + Draw dragged item stack + */ + drawSelectedItem(); } void GUIFormSpecMenu::updateSelectedItem() diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h index e6a2efe42..86235900d 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -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 rect; + std::string tooltip; }; public: @@ -209,6 +212,7 @@ protected: core::array m_inventorylists; core::array m_backgrounds; core::array m_images; + core::array m_itemimages; core::array m_fields; ItemSpec *m_selected_item; -- cgit v1.2.3