From 7bf446f671541f38d6dc89d207ee6effd3564483 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 3 Jun 2012 16:03:19 +0300 Subject: Reshape inventory menu code --- src/guiInventoryMenu.cpp | 177 ++++++++++++++++------------------------------- 1 file changed, 60 insertions(+), 117 deletions(-) (limited to 'src/guiInventoryMenu.cpp') diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp index e637ab78a..859eba1be 100644 --- a/src/guiInventoryMenu.cpp +++ b/src/guiInventoryMenu.cpp @@ -123,12 +123,10 @@ void drawItemStack(video::IVideoDriver *driver, GUIInventoryMenu::GUIInventoryMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, - v2s16 menu_size, InventoryManager *invmgr, IGameDef *gamedef ): GUIModalMenu(env, parent, id, menumgr), - m_menu_size(menu_size), m_invmgr(invmgr), m_gamedef(gamedef) { @@ -178,42 +176,72 @@ void GUIInventoryMenu::regenerateGui(v2u32 screensize) // Remove children removeChildren(); - /*padding = v2s32(24,24); - spacing = v2s32(60,56); - imgsize = v2s32(48,48);*/ - - padding = v2s32(screensize.Y/40, screensize.Y/40); - spacing = v2s32(screensize.Y/12, screensize.Y/13); - imgsize = v2s32(screensize.Y/15, screensize.Y/15); - + v2s32 size(100,100); s32 helptext_h = 15; - - v2s32 size( - padding.X*2+spacing.X*(m_menu_size.X-1)+imgsize.X, - padding.Y*2+spacing.Y*(m_menu_size.Y-1)+imgsize.Y + helptext_h - ); - - core::rect rect( - screensize.X/2 - size.X/2, - screensize.Y/2 - size.Y/2, - screensize.X/2 + size.X/2, - screensize.Y/2 + size.Y/2 - ); - - DesiredRect = rect; - recalculateAbsolutePosition(false); - + core::rect rect; v2s32 basepos = getBasePos(); + /* Convert m_init_draw_spec to m_draw_spec */ + m_draw_spec.clear(); - for(u16 i=0; i( + screensize.X/2 - size.X/2, + screensize.Y/2 - size.Y/2, + screensize.X/2 + size.X/2, + screensize.Y/2 + size.Y/2 + ); + DesiredRect = rect; + recalculateAbsolutePosition(false); + basepos = getBasePos(); + } + else if(type == "list") + { + std::string name = f.next(";"); + InventoryLocation loc; + if(name == "context" || name == "current_name") + loc = m_current_inventory_location; + 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(";")); + infostream<<"list inv="<OnEvent(event) : false; } -/* - Here is an example traditional set-up sequence for a DrawSpec list: - - std::string furnace_inv_id = "nodemetadata:0,1,2"; - core::array draw_spec; - draw_spec.push_back(GUIInventoryMenu::DrawSpec( - "list", furnace_inv_id, "fuel", - v2s32(2, 3), v2s32(1, 1))); - draw_spec.push_back(GUIInventoryMenu::DrawSpec( - "list", furnace_inv_id, "src", - v2s32(2, 1), v2s32(1, 1))); - draw_spec.push_back(GUIInventoryMenu::DrawSpec( - "list", furnace_inv_id, "dst", - v2s32(5, 1), v2s32(2, 2))); - draw_spec.push_back(GUIInventoryMenu::DrawSpec( - "list", "current_player", "main", - v2s32(0, 5), v2s32(8, 4))); - setDrawSpec(draw_spec); - - Here is the string for creating the same DrawSpec list (a single line, - spread to multiple lines here): - - GUIInventoryMenu::makeDrawSpecArrayFromString( - draw_spec, - "nodemetadata:0,1,2", - "invsize[8,9;]" - "list[current_name;fuel;2,3;1,1;]" - "list[current_name;src;2,1;1,1;]" - "list[current_name;dst;5,1;2,2;]" - "list[current_player;main;0,5;8,4;]"); - - Returns inventory menu size defined by invsize[]. -*/ -v2s16 GUIInventoryMenu::makeDrawSpecArrayFromString( - core::array &draw_spec, - const std::string &data, - const InventoryLocation ¤t_location) -{ - v2s16 invsize(8,9); - Strfnd f(data); - while(f.atend() == false) - { - std::string type = trim(f.next("[")); - //infostream<<"type="<