//NOTE: selectitem = 0 -> no selected; selectitem 1-based void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset, InventoryList *mainlist, u16 selectitem, u16 direction) { #ifdef HAVE_TOUCHSCREENGUI if ( (g_touchscreengui) && (offset == 0)) g_touchscreengui->resetHud(); #endif s32 height = m_hotbar_imagesize + m_padding * 2; s32 width = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2); if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) { width = m_hotbar_imagesize + m_padding * 2; height = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2); } // Position of upper left corner of bar v2s32 pos = upperleftpos; if (hotbar_image != player->hotbar_image) { hotbar_image = player->hotbar_image; if (hotbar_image != "") use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image); else use_hotbar_image = false; } if (hotbar_selected_image != player->hotbar_selected_image) { hotbar_selected_image = player->hotbar_selected_image; if (hotbar_selected_image != "") use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image); else use_hotbar_selected_image = false; } /* draw customized item background */ if (use_hotbar_image) { core::rect<s32> imgrect2(-m_padding/2, -m_padding/2, width+m_padding/2, height+m_padding/2); core::rect<s32> rect2 = imgrect2 + pos; video::ITexture *texture = tsrc->getTexture(hotbar_image); core::dimension2di imgsize(texture->getOriginalSize()); driver->draw2DImage(texture, rect2, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, hbar_colors, true); } for (s32 i = offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) { v2s32 steppos; s32 fullimglen = m_hotbar_imagesize + m_padding * 2; core::rect<s32> imgrect(0, 0, m_hotbar_imagesize, m_hotbar_imagesize); switch (direction) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-(m_padding + (i - offset) * fullimglen), m_padding); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(m_padding, m_padding + (i - offset) * fullimglen); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(m_padding, -(m_padding + (i - offset) * fullimglen)); break; default: steppos = v2s32(m_padding + (i - offset) * fullimglen, m_padding); break; } drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i +1) == selectitem ); #ifdef HAVE_TOUCHSCREENGUI if (g_touchscreengui) g_touchscreengui->registerHudItem(i, (imgrect + pos + steppos)); #endif } }
//NOTE: selectitem = 0 -> no selected; selectitem 1-based void Hud::drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount, InventoryList *mainlist, u16 selectitem, u16 direction) { s32 padding = imgsize / 12; s32 height = imgsize + padding * 2; s32 width = itemcount * (imgsize + padding * 2); if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) { width = imgsize + padding * 2; height = itemcount * (imgsize + padding * 2); } s32 fullimglen = imgsize + padding * 2; // Position of upper left corner of bar v2s32 pos = upperleftpos; // Draw background color /*core::rect<s32> barrect(0,0,width,height); barrect += pos; video::SColor bgcolor(255,128,128,128); driver->draw2DRectangle(bgcolor, barrect, NULL);*/ core::rect<s32> imgrect(0, 0, imgsize, imgsize); const video::SColor hbar_color(255, 255, 255, 255); const video::SColor hbar_colors[] = {hbar_color, hbar_color, hbar_color, hbar_color}; if (hotbar_image != player->hotbar_image) { hotbar_image = player->hotbar_image; if (hotbar_image != "") use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image); else use_hotbar_image = false; } if (hotbar_selected_image != player->hotbar_selected_image) { hotbar_selected_image = player->hotbar_selected_image; if (hotbar_selected_image != "") use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image); else use_hotbar_selected_image = false; } if (use_hotbar_image) { core::rect<s32> imgrect2(-padding/2, -padding/2, width+padding/2, height+padding/2); core::rect<s32> rect2 = imgrect2 + pos; video::ITexture *texture = tsrc->getTexture(hotbar_image); core::dimension2di imgsize(texture->getOriginalSize()); driver->draw2DImage(texture, rect2, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, hbar_colors, true); } for (s32 i = 0; i < itemcount; i++) { const ItemStack &item = mainlist->getItem(i); v2s32 steppos; switch (direction) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-(padding + i * fullimglen), padding); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(padding, padding + i * fullimglen); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(padding, -(padding + i * fullimglen)); break; default: steppos = v2s32(padding + i * fullimglen, padding); } core::rect<s32> rect = imgrect + pos + steppos; if (selectitem == i + 1) { if (use_hotbar_selected_image) { core::rect<s32> imgrect2(-padding*2, -padding*2, height, height); rect = imgrect2 + pos + steppos; video::ITexture *texture = tsrc->getTexture(hotbar_selected_image); core::dimension2di imgsize(texture->getOriginalSize()); driver->draw2DImage(texture, rect, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, hbar_colors, true); rect = imgrect + pos + steppos; } else { rect = imgrect + pos + steppos; video::SColor c_outside(255,255,0,0); //video::SColor c_outside(255,0,0,0); //video::SColor c_inside(255,192,192,192); s32 x1 = rect.UpperLeftCorner.X; s32 y1 = rect.UpperLeftCorner.Y; s32 x2 = rect.LowerRightCorner.X; s32 y2 = rect.LowerRightCorner.Y; // Black base borders driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x1 - padding, y1 - padding), v2s32(x2 + padding, y1) ), NULL); driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x1 - padding, y2), v2s32(x2 + padding, y2 + padding) ), NULL); driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x1 - padding, y1), v2s32(x1, y2) ), NULL); driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x2, y1), v2s32(x2 + padding, y2) ), NULL); /*// Light inside borders driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x1 - padding/2, y1 - padding/2), v2s32(x2 + padding/2, y1) ), NULL); driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x1 - padding/2, y2), v2s32(x2 + padding/2, y2 + padding/2) ), NULL); driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x1 - padding/2, y1), v2s32(x1, y2) ), NULL); driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x2, y1), v2s32(x2 + padding/2, y2) ), NULL); */ } } video::SColor bgcolor2(128, 0, 0, 0); if (!use_hotbar_image) driver->draw2DRectangle(bgcolor2, rect, NULL); drawItemStack(driver, font, item, rect, NULL, gamedef); } }