The alignment field specifies how the item will be aligned. It ranges from -1 to 1,
with 0 being the center, -1 is moved to the left/up, and 1 is to the right/down. Fractional
values can be used.
+The offset field specifies a pixel offset from the position. Contrary to position,
+the offset is not scaled to screen size. This allows for some precisely-positioned
+items in the HUD.
Below are the specific uses for fields in each type; fields not listed for that type are ignored.
Note: Future revisions to the HUD API may be incompatible; the HUD API is still in the experimental stages.
Only the X coordinate scale is used.
- text: The name of the texture that is displayed.
- alignment: The alignment of the image.
+ - offset: offset in pixels from position.
- text
Displays text on the HUD.
- scale: Defines the bounding rectangle of the text.
- number: An integer containing the RGB value of the color used to draw the text.
Specify 0xFFFFFF for white text, 0xFF0000 for red, and so on.
- alignment: The alignment of the text.
+ - offset: offset in pixels from position.
- statbar
Displays a horizontal bar made up of half-images.
- text: The name of the texture that is used.
- number: The number of half-textures that are displayed.
If odd, will end with a vertically center-split texture.
- direction
+ - offset: offset in pixels from position.
- inventory
- text: The name of the inventory list to be displayed.
- number: Number of items in the inventory to be displayed.
^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
alignment = {x=0, y=0},
^ See "HUD Element Types"
+ offset = {x=0, y=0},
+ ^ See "HUD Element Types"
}
u32 item = readU32(is);
u32 dir = readU32(is);
v2f align = readV2F1000(is);
+ v2f offset = readV2F1000(is);
ClientEvent event;
event.type = CE_HUDADD;
event.hudadd.item = item;
event.hudadd.dir = dir;
event.hudadd.align = new v2f(align);
+ event.hudadd.offset = new v2f(offset);
m_client_event_queue.push_back(event);
}
else if(command == TOCLIENT_HUDRM)
u32 item;
u32 dir;
v2f *align;
+ v2f *offset;
} hudadd;
struct{
u32 id;
u32 item
u32 dir
v2f1000 align
+ v2f1000 offset
*/
TOCLIENT_HUDRM = 0x50,
delete event.hudadd.scale;
delete event.hudadd.text;
delete event.hudadd.align;
+ delete event.hudadd.offset;
continue;
}
e->item = event.hudadd.item;
e->dir = event.hudadd.dir;
e->align = *event.hudadd.align;
+ e->offset = *event.hudadd.offset;
if (id == nhudelem)
player->hud.push_back(e);
delete event.hudadd.scale;
delete event.hudadd.text;
delete event.hudadd.align;
+ delete event.hudadd.offset;
}
else if (event.type == CE_HUDRM)
{
case HUD_STAT_ALIGN:
e->align = *event.hudchange.v2fdata;
break;
+ case HUD_STAT_OFFSET:
+ e->offset = *event.hudchange.v2fdata;
+ break;
}
delete event.hudchange.v2fdata;
v2s32 offset((e->align.X - 1.0) * ((imgsize.Width * e->scale.X) / 2),
(e->align.Y - 1.0) * ((imgsize.Height * e->scale.X) / 2));
rect += offset;
+ rect += v2s32(e->offset.X, e->offset.Y);
driver->draw2DImage(texture, rect,
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
NULL, colors, true);
core::dimension2d<u32> textsize = font->getDimension(text.c_str());
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
(e->align.Y - 1.0) * (textsize.Height / 2));
- font->draw(text.c_str(), size + pos + offset, color);
+ v2s32 offs(e->offset.X, e->offset.Y);
+ font->draw(text.c_str(), size + pos + offset + offs, color);
+ break; }
+ case HUD_ELEM_STATBAR: {
+ v2s32 offs(e->offset.X, e->offset.Y);
+ drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs);
break; }
- case HUD_ELEM_STATBAR:
- drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number);
- break;
case HUD_ELEM_INVENTORY: {
InventoryList *inv = inventory->getList(e->text);
drawItem(pos, hotbar_imagesize, e->number, inv, e->item, e->dir);
}
-void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count) {
+void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset) {
const video::SColor color(255, 255, 255, 255);
const video::SColor colors[] = {color, color, color, color};
if (corner & HUD_CORNER_LOWER)
p -= srcd.Height;
+ p += offset;
+
v2s32 steppos;
switch (drawdir) {
case HUD_DIR_RIGHT_LEFT:
drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0);
drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT,
- "heart.png", halfheartcount);
+ "heart.png", halfheartcount, v2s32(0, 0));
}
HUD_STAT_NUMBER,
HUD_STAT_ITEM,
HUD_STAT_DIR,
- HUD_STAT_ALIGN
+ HUD_STAT_ALIGN,
+ HUD_STAT_OFFSET
};
struct HudElement {
u32 item;
u32 dir;
v2f align;
+ v2f offset;
};
void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
InventoryList *mainlist, u16 selectitem, u16 direction);
void drawLuaElements();
- void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count);
+ void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset);
void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem);
void resizeHotbar();
{HUD_STAT_ITEM, "item"},
{HUD_STAT_DIR, "direction"},
{HUD_STAT_ALIGN, "alignment"},
+ {HUD_STAT_OFFSET, "offset"},
{0, NULL},
};
elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
lua_pop(L, 1);
+ lua_getfield(L, 2, "offset");
+ elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
+ lua_pop(L, 1);
+
u32 id = get_server(L)->hudAdd(player, elem);
if (id == (u32)-1) {
delete elem;
case HUD_STAT_ALIGN:
e->align = read_v2f(L, 4);
value = &e->align;
+ case HUD_STAT_OFFSET:
+ e->offset = read_v2f(L, 4);
+ value = &e->offset;
}
get_server(L)->hudChange(player, id, stat, value);
writeU32(os, form->item);
writeU32(os, form->dir);
writeV2F1000(os, form->align);
+ writeV2F1000(os, form->offset);
// Make data buffer
std::string s = os.str();
case HUD_STAT_POS:
case HUD_STAT_SCALE:
case HUD_STAT_ALIGN:
+ case HUD_STAT_OFFSET:
writeV2F1000(os, *(v2f *)value);
break;
case HUD_STAT_NAME: