X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2FguiFormSpecMenu.cpp;h=a1da09ee1615f76817a5f767643af5d970e43cae;hb=b29834ab02b47a120616b4c807a573a851b3ccd4;hp=7815089b2aeaee51be2cf652e37b013159dd14b8;hpb=5292476841430c55d889b1707cf890638a3dd2a2;p=dragonfireclient.git diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 7815089b2..a1da09ee1 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -46,7 +46,7 @@ void drawItemStack(video::IVideoDriver *driver, 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) @@ -125,13 +125,14 @@ void drawItemStack(video::IVideoDriver *driver, 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), @@ -200,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); @@ -282,6 +284,23 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) errorstream<<"WARNING: invalid use of image without a size[] element"<( @@ -320,7 +342,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) bp_set = 1; } else if(bp_set == 2) - errorstream<<"WARNING: invalid use of unpositioned field in inventory"<(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + - rect = core::rect(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15); fname = f.next(";"); flabel = f.next(";"); if(bp_set != 2) - errorstream<<"WARNING: invalid use of positioned field without a size[] element"<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") @@ -476,12 +509,50 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) 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(",")) * (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(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 = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef); + 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 @@ -697,6 +768,8 @@ void GUIFormSpecMenu::drawMenu() } } + m_pointer = m_device->getCursorControl()->getPosition(); + updateSelectedItem(); gui::IGUISkin* skin = Environment->getSkin(); @@ -748,7 +821,29 @@ void GUIFormSpecMenu::drawMenu() core::dimension2di(texture->getOriginalSize())), NULL/*&AbsoluteClippingRect*/, colors, true); } - + + /* + Draw item images + */ + for(u32 i=0; iidef(); + ItemStack item; + item.deSerialize(spec.name, idef); + video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef); + // Image size on screen + core::rect imgrect(0, 0, spec.geom.X, spec.geom.Y); + // Image rectangle on screen + core::rect 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(core::position2d(0,0), + core::dimension2di(texture->getOriginalSize())), + NULL/*&AbsoluteClippingRect*/, colors, true); + } + /* Draw items Phase 0: Item slot rectangles @@ -763,15 +858,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() @@ -936,24 +1056,15 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) 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;