]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiFormSpecMenu.cpp
Merge pull request #500 from doserj/server_report_missing_deps
[dragonfireclient.git] / src / guiFormSpecMenu.cpp
index 66ac4c08f73540fef8d08099ca90c9b2bf60f594..a1da09ee1615f76817a5f767643af5d970e43cae 100644 (file)
@@ -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)
@@ -293,7 +293,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                        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
+                       infostream<<"item name="<<name
                                        <<", pos=("<<pos.X<<","<<pos.Y<<")"
                                        <<", geom=("<<geom.X<<","<<geom.Y<<")"
                                        <<std::endl;
@@ -318,13 +318,16 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                                errorstream<<"WARNING: invalid use of background without a size[] element"<<std::endl;
                        m_backgrounds.push_back(ImageDrawSpec(name, pos, geom));
                }
-               else if(type == "field")
+               else if(type == "field" || type == "textarea")
                {
                        std::string fname = f.next(";");
                        std::string flabel = f.next(";");
-                       
+
                        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>(
@@ -339,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"<<std::endl;
+                                       errorstream<<"WARNING: invalid use of unpositioned "<<type<<" in inventory"<<std::endl;
 
                                v2s32 pos = basepos;
                                pos.Y = ((m_fields.size()+2)*60);
@@ -353,20 +356,32 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                                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(";");
                                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 fdefault;
-                       
+
                        // fdefault may contain a variable reference, which
                        // needs to be resolved from the node metadata
                        if(m_form_src)
@@ -380,41 +395,40 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                                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")
@@ -519,7 +533,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                        IItemDefManager *idef = m_gamedef->idef();
                        ItemStack item;
                        item.deSerialize(fimage, idef);
-                       video::ITexture *texture = item.getDefinition(idef).inventory_texture;
+                       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()),
@@ -807,7 +821,29 @@ void GUIFormSpecMenu::drawMenu()
                                        core::dimension2di(texture->getOriginalSize())),
                        NULL/*&AbsoluteClippingRect*/, colors, true);
        }
-
+       
+       /*
+               Draw item images
+       */
+       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