mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 18:13:46 +01:00
Add support for using textures in hotbar
This commit is contained in:
parent
fead7a27ca
commit
439079cad8
70
src/hud.cpp
70
src/hud.cpp
@ -64,6 +64,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
|
|||||||
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
|
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
|
||||||
|
|
||||||
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
|
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
|
||||||
|
use_hotbar_bg_img = tsrc->isKnownSourceImage("hotbar.png");
|
||||||
|
use_hotbar_border_img = tsrc->isKnownSourceImage("hotbar_selected.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -90,6 +92,18 @@ void Hud::drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
|
|||||||
driver->draw2DRectangle(bgcolor, barrect, NULL);*/
|
driver->draw2DRectangle(bgcolor, barrect, NULL);*/
|
||||||
|
|
||||||
core::rect<s32> imgrect(0, 0, imgsize, imgsize);
|
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 (use_hotbar_bg_img) {
|
||||||
|
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.png");
|
||||||
|
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++)
|
for (s32 i = 0; i < itemcount; i++)
|
||||||
{
|
{
|
||||||
@ -112,62 +126,74 @@ void Hud::drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
|
|||||||
|
|
||||||
core::rect<s32> rect = imgrect + pos + steppos;
|
core::rect<s32> rect = imgrect + pos + steppos;
|
||||||
|
|
||||||
if (selectitem == i + 1)
|
if (selectitem == i + 1) {
|
||||||
{
|
if (use_hotbar_border_img) {
|
||||||
video::SColor c_outside(255,255,0,0);
|
core::rect<s32> imgrect2(-padding*2, -padding*2, height, height);
|
||||||
//video::SColor c_outside(255,0,0,0);
|
rect = imgrect2 + pos + steppos;
|
||||||
//video::SColor c_inside(255,192,192,192);
|
video::ITexture *texture = tsrc->getTexture("hotbar_selected.png");
|
||||||
s32 x1 = rect.UpperLeftCorner.X;
|
core::dimension2di imgsize(texture->getOriginalSize());
|
||||||
s32 y1 = rect.UpperLeftCorner.Y;
|
driver->draw2DImage(texture, rect,
|
||||||
s32 x2 = rect.LowerRightCorner.X;
|
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
|
||||||
s32 y2 = rect.LowerRightCorner.Y;
|
NULL, hbar_colors, true);
|
||||||
// Black base borders
|
rect = imgrect + pos + steppos;
|
||||||
driver->draw2DRectangle(c_outside,
|
} 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>(
|
core::rect<s32>(
|
||||||
v2s32(x1 - padding, y1 - padding),
|
v2s32(x1 - padding, y1 - padding),
|
||||||
v2s32(x2 + padding, y1)
|
v2s32(x2 + padding, y1)
|
||||||
), NULL);
|
), NULL);
|
||||||
driver->draw2DRectangle(c_outside,
|
driver->draw2DRectangle(c_outside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x1 - padding, y2),
|
v2s32(x1 - padding, y2),
|
||||||
v2s32(x2 + padding, y2 + padding)
|
v2s32(x2 + padding, y2 + padding)
|
||||||
), NULL);
|
), NULL);
|
||||||
driver->draw2DRectangle(c_outside,
|
driver->draw2DRectangle(c_outside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x1 - padding, y1),
|
v2s32(x1 - padding, y1),
|
||||||
v2s32(x1, y2)
|
v2s32(x1, y2)
|
||||||
), NULL);
|
), NULL);
|
||||||
driver->draw2DRectangle(c_outside,
|
driver->draw2DRectangle(c_outside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x2, y1),
|
v2s32(x2, y1),
|
||||||
v2s32(x2 + padding, y2)
|
v2s32(x2 + padding, y2)
|
||||||
), NULL);
|
), NULL);
|
||||||
/*// Light inside borders
|
/*// Light inside borders
|
||||||
driver->draw2DRectangle(c_inside,
|
driver->draw2DRectangle(c_inside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x1 - padding/2, y1 - padding/2),
|
v2s32(x1 - padding/2, y1 - padding/2),
|
||||||
v2s32(x2 + padding/2, y1)
|
v2s32(x2 + padding/2, y1)
|
||||||
), NULL);
|
), NULL);
|
||||||
driver->draw2DRectangle(c_inside,
|
driver->draw2DRectangle(c_inside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x1 - padding/2, y2),
|
v2s32(x1 - padding/2, y2),
|
||||||
v2s32(x2 + padding/2, y2 + padding/2)
|
v2s32(x2 + padding/2, y2 + padding/2)
|
||||||
), NULL);
|
), NULL);
|
||||||
driver->draw2DRectangle(c_inside,
|
driver->draw2DRectangle(c_inside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x1 - padding/2, y1),
|
v2s32(x1 - padding/2, y1),
|
||||||
v2s32(x1, y2)
|
v2s32(x1, y2)
|
||||||
), NULL);
|
), NULL);
|
||||||
driver->draw2DRectangle(c_inside,
|
driver->draw2DRectangle(c_inside,
|
||||||
core::rect<s32>(
|
core::rect<s32>(
|
||||||
v2s32(x2, y1),
|
v2s32(x2, y1),
|
||||||
v2s32(x2 + padding/2, y2)
|
v2s32(x2 + padding/2, y2)
|
||||||
), NULL);
|
), NULL);
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
video::SColor bgcolor2(128, 0, 0, 0);
|
video::SColor bgcolor2(128, 0, 0, 0);
|
||||||
driver->draw2DRectangle(bgcolor2, rect, NULL);
|
if (!use_hotbar_bg_img)
|
||||||
|
driver->draw2DRectangle(bgcolor2, rect, NULL);
|
||||||
drawItemStack(driver, font, item, rect, NULL, gamedef);
|
drawItemStack(driver, font, item, rect, NULL, gamedef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +248,7 @@ void Hud::drawLuaElements() {
|
|||||||
break; }
|
break; }
|
||||||
default:
|
default:
|
||||||
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
|
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
|
||||||
"of hud element ID " << i << " due to unrecognized type" << std::endl;
|
" of hud element ID " << i << " due to unrecognized type" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,8 @@ public:
|
|||||||
video::SColor crosshair_argb;
|
video::SColor crosshair_argb;
|
||||||
video::SColor selectionbox_argb;
|
video::SColor selectionbox_argb;
|
||||||
bool use_crosshair_image;
|
bool use_crosshair_image;
|
||||||
|
bool use_hotbar_border_img;
|
||||||
|
bool use_hotbar_bg_img;
|
||||||
|
|
||||||
Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
|
Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
|
||||||
gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,
|
gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,
|
||||||
|
Loading…
Reference in New Issue
Block a user