From 1709fd854a2d943de8cc48ee1e092dcb4315f9a6 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 3 Jun 2012 17:18:08 +0300 Subject: Implement image[,;,;] and allow floating-point values in formspec --- src/game.cpp | 5 +-- src/guiInventoryMenu.cpp | 92 +++++++++++++++++++++++++++++++----------------- src/guiInventoryMenu.h | 32 +++++++++++++---- 3 files changed, 88 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 5bc3e7625..768bb5602 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1576,8 +1576,9 @@ void the_game( inventoryloc.setCurrentPlayer(); menu->setFormSpec( - "invsize[8,7;]" - "list[current_player;main;0,3;8,4;]" + "invsize[8,7.5;]" + //"image[1,0.6;1,2;player.png]" + "list[current_player;main;0,3.5;8,4;]" "list[current_player;craft;3,0;3,3;]" "list[current_player;craftpreview;7,1;1,1;]" , inventoryloc); diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp index 859eba1be..492ea1c19 100644 --- a/src/guiInventoryMenu.cpp +++ b/src/guiInventoryMenu.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "log.h" +#include "tile.h" // ITextureSource void drawItemStack(video::IVideoDriver *driver, gui::IGUIFont *font, @@ -181,9 +182,10 @@ void GUIInventoryMenu::regenerateGui(v2u32 screensize) core::rect rect; v2s32 basepos = getBasePos(); - /* Convert m_init_draw_spec to m_draw_spec */ + /* Convert m_init_draw_spec to m_inventorylists */ - m_draw_spec.clear(); + m_inventorylists.clear(); + m_images.clear(); Strfnd f(m_formspec_string); while(f.atend() == false) @@ -191,9 +193,9 @@ void GUIInventoryMenu::regenerateGui(v2u32 screensize) std::string type = trim(f.next("[")); if(type == "invsize") { - v2s16 invsize; - invsize.X = stoi(f.next(",")); - invsize.Y = stoi(f.next(";")); + v2f invsize; + invsize.X = stof(f.next(",")); + invsize.Y = stof(f.next(";")); infostream<<"invsize ("<( screensize.X/2 - size.X/2, @@ -223,18 +225,35 @@ void GUIInventoryMenu::regenerateGui(v2u32 screensize) else loc.deSerialize(name); std::string listname = f.next(";"); - s32 pos_x = stoi(f.next(",")); - s32 pos_y = stoi(f.next(";")); - s32 geom_w = stoi(f.next(",")); - s32 geom_h = stoi(f.next(";")); + v2s32 pos = basepos; + pos.X += stof(f.next(",")) * (float)spacing.X; + pos.Y += stof(f.next(";")) * (float)spacing.Y; + v2s32 geom; + geom.X = stoi(f.next(",")); + geom.Y = stoi(f.next(";")); infostream<<"list inv="< rect(0, 0, size.X-padding.X*2, helptext_h); rect = rect + v2s32(size.X/2 - rect.getWidth()/2, - size.Y-rect.getHeight()-15); + size.Y-rect.getHeight()-5); const wchar_t *text = L"Left click: Move all items, Right click: Move single item"; Environment->addStaticText(text, rect, false, true, this, 256); @@ -281,9 +290,9 @@ GUIInventoryMenu::ItemSpec GUIInventoryMenu::getItemAtPos(v2s32 p) const { core::rect imgrect(0,0,imgsize.X,imgsize.Y); - for(u32 i=0; itsrc()->getTextureRaw(spec.name); + // 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); } /* @@ -491,9 +517,9 @@ void GUIInventoryMenu::updateSelectedItem() // If craftresult is nonempty and nothing else is selected, select it now. if(!m_selected_item) { - for(u32 i=0; igetInventory(s.inventoryloc); diff --git a/src/guiInventoryMenu.h b/src/guiInventoryMenu.h index 4660ab2bf..beb6ef2e8 100644 --- a/src/guiInventoryMenu.h +++ b/src/guiInventoryMenu.h @@ -70,12 +70,12 @@ class GUIInventoryMenu : public GUIModalMenu } ListDrawSpec(const InventoryLocation &a_inventoryloc, const std::string &a_listname, - v2s32 a_pos, v2s32 a_geom) + v2s32 a_pos, v2s32 a_geom): + inventoryloc(a_inventoryloc), + listname(a_listname), + pos(a_pos), + geom(a_geom) { - inventoryloc = a_inventoryloc; - listname = a_listname; - pos = a_pos; - geom = a_geom; } InventoryLocation inventoryloc; @@ -83,6 +83,24 @@ class GUIInventoryMenu : public GUIModalMenu v2s32 pos; v2s32 geom; }; + + struct ImageDrawSpec + { + ImageDrawSpec() + { + } + ImageDrawSpec(const std::string &a_name, + v2s32 a_pos, v2s32 a_geom): + name(a_name), + pos(a_pos), + geom(a_geom) + { + } + std::string name; + v2s32 pos; + v2s32 geom; + }; + public: GUIInventoryMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, @@ -129,7 +147,9 @@ protected: std::string m_formspec_string; InventoryLocation m_current_inventory_location; - core::array m_draw_spec; + + core::array m_inventorylists; + core::array m_images; ItemSpec *m_selected_item; u32 m_selected_amount; -- cgit v1.2.3