The name field is not yet used, but should contain a description of what the HUD element represents.
The direction field is the direction in which something is drawn.
0 draws from left to right, 1 draws from right to left, 2 draws from top to bottom, and 3 draws from bottom to top.
+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.
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.
- scale: The scale of the image, with 1 being the original texture size.
Only the X coordinate scale is used.
- text: The name of the texture that is displayed.
+ - alignment: The alignment of the image.
- text
Displays text on the HUD.
- scale: Defines the bounding rectangle of the text.
- text: The text to be displayed in the HUD element.
- 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.
- statbar
Displays a horizontal bar made up of half-images.
- text: The name of the texture that is used.
^ Selected item in inventory. 0 for no item selected.
direction = 0,
^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
+ alignment = {x=0, y=0},
+ ^ See "HUD Element Types"
}
u32 number = readU32(is);
u32 item = readU32(is);
u32 dir = readU32(is);
+ v2f align = readV2F1000(is);
ClientEvent event;
event.type = CE_HUDADD;
event.hudadd.number = number;
event.hudadd.item = item;
event.hudadd.dir = dir;
+ event.hudadd.align = new v2f(align);
m_client_event_queue.push_back(event);
}
else if(command == TOCLIENT_HUDRM)
u32 number;
u32 item;
u32 dir;
+ v2f *align;
} hudadd;
struct{
u32 id;
u32 number
u32 item
u32 dir
+ v2f1000 align
*/
TOCLIENT_HUDRM = 0x50,
delete event.hudadd.name;
delete event.hudadd.scale;
delete event.hudadd.text;
+ delete event.hudadd.align;
continue;
}
e->number = event.hudadd.number;
e->item = event.hudadd.item;
e->dir = event.hudadd.dir;
+ e->align = *event.hudadd.align;
if (id == nhudelem)
player->hud.push_back(e);
delete event.hudadd.name;
delete event.hudadd.scale;
delete event.hudadd.text;
+ delete event.hudadd.align;
}
else if (event.type == CE_HUDRM)
{
case HUD_STAT_DIR:
e->dir = event.hudchange.data;
break;
+ case HUD_STAT_ALIGN:
+ e->align = *event.hudchange.v2fdata;
+ break;
}
delete event.hudchange.v2fdata;
core::rect<s32> rect(0, 0, imgsize.Width * e->scale.X,
imgsize.Height * e->scale.X);
rect += pos;
+ 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;
driver->draw2DImage(texture, rect,
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
NULL, colors, true);
(e->number >> 8) & 0xFF,
(e->number >> 0) & 0xFF);
core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y);
- font->draw(narrow_to_wide(e->text).c_str(), size + pos, color);
+ std::wstring text = narrow_to_wide(e->text);
+ 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);
break; }
case HUD_ELEM_STATBAR:
drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number);
HUD_STAT_TEXT,
HUD_STAT_NUMBER,
HUD_STAT_ITEM,
- HUD_STAT_DIR
+ HUD_STAT_DIR,
+ HUD_STAT_ALIGN
};
struct HudElement {
u32 number;
u32 item;
u32 dir;
+ v2f align;
};
{HUD_STAT_NUMBER, "number"},
{HUD_STAT_ITEM, "item"},
{HUD_STAT_DIR, "direction"},
+ {HUD_STAT_ALIGN, "alignment"},
{0, NULL},
};
elem->item = getintfield_default(L, 2, "item", 0);
elem->dir = getintfield_default(L, 2, "direction", 0);
+ lua_getfield(L, 2, "alignment");
+ elem->align = 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_DIR:
e->dir = lua_tonumber(L, 4);
value = &e->dir;
+ case HUD_STAT_ALIGN:
+ e->align = read_v2f(L, 4);
+ value = &e->align;
}
get_server(L)->hudChange(player, id, stat, value);
writeU32(os, form->number);
writeU32(os, form->item);
writeU32(os, form->dir);
+ writeV2F1000(os, form->align);
// Make data buffer
std::string s = os.str();
switch (stat) {
case HUD_STAT_POS:
case HUD_STAT_SCALE:
+ case HUD_STAT_ALIGN:
writeV2F1000(os, *(v2f *)value);
break;
case HUD_STAT_NAME: