Hud Item name - move in statbars.lua, fix iOS position, other

This commit is contained in:
MoNTE48 2019-05-27 00:36:33 +02:00
parent de5f3a152d
commit 102bfa89ea
6 changed files with 72 additions and 61 deletions

View File

@ -31,6 +31,6 @@ assert(loadfile(gamepath.."falling.lua"))(builtin_shared)
dofile(gamepath.."features.lua") dofile(gamepath.."features.lua")
dofile(gamepath.."voxelarea.lua") dofile(gamepath.."voxelarea.lua")
dofile(gamepath.."forceloading.lua") dofile(gamepath.."forceloading.lua")
--dofile(gamepath.."statbars.lua") dofile(gamepath.."statbars.lua")
profiler = nil profiler = nil

View File

@ -229,57 +229,3 @@ end
function core.cancel_shutdown_requests() function core.cancel_shutdown_requests()
core.request_shutdown("", false, -1) core.request_shutdown("", false, -1)
end end
local hud, timer, wield = {}, {}, {}
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.965},
offset = {x = 0, y = -75},
alignment = {x = 0, y = 0},
number = 0xFFFFFF,
text = "",
})
end
core.register_on_joinplayer(function(player)
core.after(0, add_text, player)
end)
core.register_globalstep(function(dtime)
local players = core.get_connected_players()
for i = 1, #players do
local player = players[i]
local player_name = player:get_player_name()
local wielded_item = player:get_wielded_item()
local wielded_item_name = wielded_item:get_name()
timer[player_name] = timer[player_name] and timer[player_name] + dtime or 0
wield[player_name] = wield[player_name] or ""
if timer[player_name] > timeout and hud[player_name] then
player:hud_change(hud[player_name], "text", "")
timer[player_name] = 0
return
end
if hud[player_name] and wielded_item_name ~= wield[player_name] then
wield[player_name] = wielded_item_name
timer[player_name] = 0
local def = core.registered_items[wielded_item_name]
local meta = wielded_item:get_meta()
local meta_desc = meta:get_string("description")
meta_desc = meta_desc:gsub("\27", ""):gsub("%(c@#%w%w%w%w%w%w%)", "")
local description = meta_desc ~= "" and meta_desc or
(def and (def.description:match("(.-)\n") or def.description) or "")
player:hud_change(hud[player_name], "text", description)
end
end
end)

View File

@ -1,5 +1,5 @@
-- cache setting -- cache setting
local enable_damage = core.settings:get_bool("enable_damage") --[[local enable_damage = core.settings:get_bool("enable_damage")
local health_bar_definition = local health_bar_definition =
{ {
@ -162,4 +162,69 @@ end
core.register_on_joinplayer(initialize_builtin_statbars) core.register_on_joinplayer(initialize_builtin_statbars)
core.register_on_leaveplayer(cleanup_builtin_statbars) core.register_on_leaveplayer(cleanup_builtin_statbars)
core.register_playerevent(player_event_handler) core.register_playerevent(player_event_handler)]]
-- Hud Item name
local hud, timer, wield = {}, {}, {}
local timeout = 2
local textposition
core.register_on_joinplayer(function(player)
if PLATFORM == "iOS" then
textposition = {x = 0.5, y = 0.89}
else
textposition = {x = 0.5, y = 0.975}
end
end)
local function add_text(player)
local player_name = player:get_player_name()
hud[player_name] = player:hud_add({
hud_elem_type = "text",
position = textposition,
offset = {x = 0, y = -75},
alignment = {x = 0, y = 0},
number = 0xFFFFFF,
text = "",
})
end
core.register_on_joinplayer(function(player)
core.after(1, add_text, player)
end)
core.register_globalstep(function(dtime)
local players = core.get_connected_players()
for i = 1, #players do
local player = players[i]
local player_name = player:get_player_name()
local wielded_item = player:get_wielded_item()
local wielded_item_name = wielded_item:get_name()
timer[player_name] = timer[player_name] and timer[player_name] + dtime or 0
wield[player_name] = wield[player_name] or ""
if timer[player_name] > timeout and hud[player_name] then
player:hud_change(hud[player_name], "text", "")
timer[player_name] = 0
return
end
if hud[player_name] and wielded_item_name ~= wield[player_name] then
wield[player_name] = wielded_item_name
timer[player_name] = 0
local def = core.registered_items[wielded_item_name]
local meta = wielded_item:get_meta()
local meta_desc = meta:get_string("description")
meta_desc = meta_desc:gsub("\27", ""):gsub("%(c@#%w%w%w%w%w%w%)", "")
local description = meta_desc ~= "" and meta_desc or
(def and (def.description:match("(.-)\n") or def.description) or "")
player:hud_change(hud[player_name], "text", description)
end
end
end)

View File

@ -97,9 +97,9 @@ return {
cbf_formspec = function(tabview, name, tabdata) cbf_formspec = function(tabview, name, tabdata)
local version = core.get_version() local version = core.get_version()
return "label[0.1,-0.1;MultiCraft Open Source Project, ver. " .. version.string .. "]" .. return "label[0.1,-0.1;MultiCraft Open Source Project, ver. " .. version.string .. "]" ..
"label[0.1,0.2;Copyright (c) 2014-2019 MultiCraft Developement Team]" .. "label[0.1,0.3;Copyright (c) 2014-2019 MultiCraft Developement Team]" ..
"label[0.1,0.5;Home page: https://github.com/MultiCraftProject/MultiCraft]" .. "label[0.1,0.7;Home page: https://github.com/MultiCraftProject/MultiCraft]" ..
"label[0.1,0.8;Licence: LGPLv3.0+ and CC-BY-SA 3.0]" .. "label[0.1,1.1;Licence: LGPLv3.0+ and CC-BY-SA 3.0]" ..
"tablecolumns[color;text]" .. "tablecolumns[color;text]" ..
"tableoptions[background=#999999;highlight=#00000000;border=true]" .. "tableoptions[background=#999999;highlight=#00000000;border=true]" ..
"table[0,1.6;11.8,3.8;list_credits;" .. "table[0,1.6;11.8,3.8;list_credits;" ..

View File

@ -49,7 +49,7 @@ local function get_formspec(tabview, name, tabdata)
"local_creative_" .. "local_creative_" ..
tostring(creative_mode) .. "_btn.png") .. tostring(creative_mode) .. "_btn.png") ..
";cb_creative_mode;;true;false]" .. ";cb_creative_mode;;true;false]" ..
"textlist[-0.025,0.01;6.3,4.63;sp_worlds;" .. "textlist[-0.01,0;6.28,4.64;sp_worlds;" ..
menu_render_worldlist() .. menu_render_worldlist() ..
";" .. index .. ";true]" ";" .. index .. ";true]"
return retval return retval

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 434 B