Attempt to improve HUD pos (@MoNTE48 and @kilbith)
This commit is contained in:
parent
2b4dad6f1a
commit
a6deb4287d
|
@ -172,12 +172,11 @@ local timeout = 2
|
|||
local function add_text(player)
|
||||
local player_name = player:get_player_name()
|
||||
hud[player_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0.975},
|
||||
offset = {x = 0, y = -100},
|
||||
alignment = {x = 0, y = 0},
|
||||
number = 0xFFFFFF,
|
||||
text = "",
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0.91},
|
||||
offset = {x = 0, y = -25},
|
||||
alignment = {x = 0, y = 0},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
default
|
||||
default
|
||||
hud
|
|
@ -5,12 +5,14 @@ local modpath = minetest.get_modpath(modname)
|
|||
|
||||
dofile(modpath .. "/override.lua")
|
||||
|
||||
local MAX_LEVEL = 40
|
||||
local MAX_HUD_XP = 32
|
||||
local MAX_LEVEL = 40
|
||||
|
||||
local ORB_LIFETIME = 60
|
||||
local ORB_SOUND_INTERVAL = 0.01
|
||||
local ORB_COLLECT_RADIUS = 3
|
||||
|
||||
local xp, hud = {}, {}
|
||||
local xp, _hud = {}, {}
|
||||
|
||||
local get_objs_rad = minetest.get_objects_inside_radius
|
||||
local get_players = minetest.get_connected_players
|
||||
|
@ -34,39 +36,28 @@ local function init_data(player, reset)
|
|||
end
|
||||
end
|
||||
|
||||
hud.register("xp_bar", {
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
size = {x = 31, y = 13},
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = -249, y = -79},
|
||||
text = "expbar_full.png",
|
||||
background = "expbar_empty.png",
|
||||
number = MAX_HUD_XP,
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
init_data(player)
|
||||
|
||||
hud[name] = {
|
||||
-- background (empty bar)
|
||||
hud = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 0.97},
|
||||
offset = {x = -191, y = -29},
|
||||
scale = {x = 1, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
text = "expbar_empty.png",
|
||||
number = MAX_HUD_XP,
|
||||
}),
|
||||
|
||||
-- foreground (filling bar)
|
||||
hud2 = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 0.97},
|
||||
offset = {x = -191, y = -29},
|
||||
scale = {x = 1, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
text = "expbar_full.png",
|
||||
}),
|
||||
|
||||
_hud[name] = {
|
||||
-- level number
|
||||
hud3 = player:hud_add({
|
||||
lvl = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
texture = ("xp_blank"),
|
||||
position = {x = 0.495, y = 0.976},
|
||||
offset = {x = 6, y = -42},
|
||||
alignment = {x = -0.5, y = -1},
|
||||
position = {x = 0.5, y = 0.91},
|
||||
offset = {x = 0, y = -25},
|
||||
alignment = {x = 0, y = 0},
|
||||
number = 0x3cff00,
|
||||
text = "",
|
||||
})
|
||||
|
@ -155,11 +146,11 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
end
|
||||
|
||||
player:hud_change(hud[name].hud2, "number", xp[name].xp_bar)
|
||||
player:hud_change(hud[name].hud3, "text", xp[name].level)
|
||||
hud.change_item(player, "xp_bar", {number = xp[name].xp_bar})
|
||||
|
||||
player:hud_change(hud[name].hud3, "offset",
|
||||
{x = (xp[name].level >= 10 and 13 or 6), y = -42})
|
||||
player:hud_change(_hud[name].lvl, "text", xp[name].level)
|
||||
--player:hud_change(_hud[name].lvl, "offset",
|
||||
-- {x = (xp[name].level >= 10 and 13 or 6), y = -202})
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -185,7 +176,7 @@ minetest.register_entity("experience:orb", {
|
|||
self.last_color_change = self.last_color_change or 0
|
||||
self.color_ratio = self.color_ratio or 0
|
||||
|
||||
if self.timer > 60 then
|
||||
if self.timer > ORB_LIFETIME then
|
||||
obj:remove()
|
||||
elseif self.timer >= self.last_color_change + 0.001 then
|
||||
if self.color_ratio >= 120 then
|
||||
|
|
15
src/hud.cpp
15
src/hud.cpp
|
@ -328,20 +328,17 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||
core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y);
|
||||
std::wstring text = unescape_enriched(utf8_to_wide(e->text));
|
||||
core::dimension2d<u32> textsize = font->getDimension(text.c_str());
|
||||
if (e->pos.X == 0.5) {
|
||||
if (e->pos.X > 0.45 && e->pos.X < 0.55) {
|
||||
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
|
||||
#if defined(__ANDROID__)
|
||||
(e->align.Y - 1.0) * (textsize.Height) * 4);
|
||||
#elif defined(__IOS__)
|
||||
(e->align.Y - 1.0) * (textsize.Height) * 3 * g_settings->getFloat("hud_scaling"));
|
||||
#if defined(__ANDROID__) || defined(__IOS__)
|
||||
(e->align.Y - 1.0) * (textsize.Height) * 7 * g_settings->getFloat("hud_scaling"));
|
||||
#else
|
||||
(e->align.Y - 1.0) * (textsize.Height / 2));
|
||||
(e->align.Y - 1.0) * (textsize.Height / 2));
|
||||
#endif
|
||||
v2s32 offs(e->offset.X, e->offset.Y);
|
||||
font->draw(text.c_str(), size + pos + offset + offs, color);
|
||||
font->draw(text.c_str(), size + pos + offset, color);
|
||||
} else {
|
||||
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
|
||||
(e->align.Y - 1.0) * (textsize.Height / 2));
|
||||
(e->align.Y - 1.0) * (textsize.Height / 2));
|
||||
v2s32 offs(e->offset.X, e->offset.Y);
|
||||
font->draw(text.c_str(), size + pos + offset + offs, color);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue