Extract HUD code to rp_hud mod
@ -44,8 +44,6 @@ dofile(minetest.get_modpath("rp_default").."/crafting.lua")
|
|||||||
|
|
||||||
dofile(minetest.get_modpath("rp_default").."/mapgen.lua")
|
dofile(minetest.get_modpath("rp_default").."/mapgen.lua")
|
||||||
|
|
||||||
dofile(minetest.get_modpath("rp_default").."/hud.lua")
|
|
||||||
|
|
||||||
dofile(minetest.get_modpath("rp_default").."/aliases.lua")
|
dofile(minetest.get_modpath("rp_default").."/aliases.lua")
|
||||||
|
|
||||||
default.log("mod:rp_default", "loaded")
|
default.log("mod:rp_default", "loaded")
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name = rp_default
|
name = rp_default
|
||||||
depends = rp_sounds, rp_formspec
|
depends = rp_sounds, rp_formspec
|
||||||
description = Core Repixture mods. Contains most basic blocks and items, chests, furnaces, fertilizer, signs, torches, ladders, buckets
|
description = Core Repixture mods. Contains most basic blocks, items, tools, chests, furnaces, fertilizer, signs, torches, ladders, buckets
|
||||||
|
6
mods/rp_hud/README.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Repixure core mod: rp_hud
|
||||||
|
=========================
|
||||||
|
Adds the HUD for Repixture
|
||||||
|
|
||||||
|
Texture license: CC BY-SA 4.0
|
||||||
|
Source license: LGPLv2.1
|
@ -1,6 +1,6 @@
|
|||||||
-- Based off MT's core builtin/game/statbars.lua, changed a lot to add statbar background and better layout
|
-- Based off MT's core builtin/game/statbars.lua, changed a lot to add statbar background and better layout
|
||||||
|
|
||||||
default.hud={}
|
rp_hud={}
|
||||||
|
|
||||||
local health_bar_definition = {
|
local health_bar_definition = {
|
||||||
hud_elem_type = "statbar",
|
hud_elem_type = "statbar",
|
||||||
@ -28,9 +28,9 @@ local breath_bar_definition = {
|
|||||||
z_index = 1,
|
z_index = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
default.hud.ids={}
|
rp_hud.ids={}
|
||||||
|
|
||||||
function default.hud.initialize_builtin_statbars(player)
|
function rp_hud.initialize_builtin_statbars(player)
|
||||||
if not player:is_player() then
|
if not player:is_player() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -44,8 +44,8 @@ function default.hud.initialize_builtin_statbars(player)
|
|||||||
player:hud_set_hotbar_selected_image("ui_hotbar_selected.png")
|
player:hud_set_hotbar_selected_image("ui_hotbar_selected.png")
|
||||||
player:hud_set_hotbar_image("ui_hotbar_bg.png")
|
player:hud_set_hotbar_image("ui_hotbar_bg.png")
|
||||||
|
|
||||||
if default.hud.ids[name] == nil then
|
if rp_hud.ids[name] == nil then
|
||||||
default.hud.ids[name] = {}
|
rp_hud.ids[name] = {}
|
||||||
-- flags are not transmitted to client on connect, we need to make sure
|
-- flags are not transmitted to client on connect, we need to make sure
|
||||||
-- our current flags are transmitted by sending them actively
|
-- our current flags are transmitted by sending them actively
|
||||||
local flg=player:hud_get_flags()
|
local flg=player:hud_get_flags()
|
||||||
@ -56,36 +56,36 @@ function default.hud.initialize_builtin_statbars(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if minetest.is_yes(minetest.settings:get("enable_damage")) then
|
if minetest.is_yes(minetest.settings:get("enable_damage")) then
|
||||||
if default.hud.ids[name].id_healthbar == nil then
|
if rp_hud.ids[name].id_healthbar == nil then
|
||||||
health_bar_definition.number = player:get_hp()
|
health_bar_definition.number = player:get_hp()
|
||||||
default.hud.ids[name].id_healthbar = player:hud_add(health_bar_definition)
|
rp_hud.ids[name].id_healthbar = player:hud_add(health_bar_definition)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if default.hud.ids[name].id_healthbar ~= nil then
|
if rp_hud.ids[name].id_healthbar ~= nil then
|
||||||
player:hud_remove(default.hud.ids[name].id_healthbar)
|
player:hud_remove(rp_hud.ids[name].id_healthbar)
|
||||||
default.hud.ids[name].id_healthbar = nil
|
rp_hud.ids[name].id_healthbar = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (player:get_breath() < minetest.PLAYER_MAX_BREATH_DEFAULT) then
|
if (player:get_breath() < minetest.PLAYER_MAX_BREATH_DEFAULT) then
|
||||||
if minetest.is_yes(minetest.settings:get("enable_damage")) then
|
if minetest.is_yes(minetest.settings:get("enable_damage")) then
|
||||||
if default.hud.ids[name].id_breathbar == nil then
|
if rp_hud.ids[name].id_breathbar == nil then
|
||||||
breath_bar_definition.number = player:get_breath()*2
|
breath_bar_definition.number = player:get_breath()*2
|
||||||
default.hud.ids[name].id_breathbar = player:hud_add(breath_bar_definition)
|
rp_hud.ids[name].id_breathbar = player:hud_add(breath_bar_definition)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if default.hud.ids[name].id_breathbar ~= nil then
|
if rp_hud.ids[name].id_breathbar ~= nil then
|
||||||
player:hud_remove(default.hud.ids[name].id_breathbar)
|
player:hud_remove(rp_hud.ids[name].id_breathbar)
|
||||||
default.hud.ids[name].id_breathbar = nil
|
rp_hud.ids[name].id_breathbar = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif default.hud.ids[name].id_breathbar ~= nil then
|
elseif rp_hud.ids[name].id_breathbar ~= nil then
|
||||||
player:hud_remove(default.hud.ids[name].id_breathbar)
|
player:hud_remove(rp_hud.ids[name].id_breathbar)
|
||||||
default.hud.ids[name].id_breathbar = nil
|
rp_hud.ids[name].id_breathbar = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function default.hud.cleanup_builtin_statbars(player)
|
function rp_hud.cleanup_builtin_statbars(player)
|
||||||
if not player:is_player() then
|
if not player:is_player() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -96,10 +96,10 @@ function default.hud.cleanup_builtin_statbars(player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
default.hud.ids[name] = nil
|
rp_hud.ids[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function default.hud.player_event_handler(player, eventname)
|
function rp_hud.player_event_handler(player, eventname)
|
||||||
assert(player:is_player())
|
assert(player:is_player())
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
@ -109,32 +109,32 @@ function default.hud.player_event_handler(player, eventname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if eventname == "health_changed" then
|
if eventname == "health_changed" then
|
||||||
default.hud.initialize_builtin_statbars(player)
|
rp_hud.initialize_builtin_statbars(player)
|
||||||
|
|
||||||
if default.hud.ids[name].id_healthbar ~= nil then
|
if rp_hud.ids[name].id_healthbar ~= nil then
|
||||||
player:hud_change(default.hud.ids[name].id_healthbar,"number",player:get_hp())
|
player:hud_change(rp_hud.ids[name].id_healthbar,"number",player:get_hp())
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if eventname == "breath_changed" then
|
if eventname == "breath_changed" then
|
||||||
default.hud.initialize_builtin_statbars(player)
|
rp_hud.initialize_builtin_statbars(player)
|
||||||
|
|
||||||
if default.hud.ids[name].id_breathbar ~= nil then
|
if rp_hud.ids[name].id_breathbar ~= nil then
|
||||||
player:hud_change(default.hud.ids[name].id_breathbar,"number",player:get_breath()*2)
|
player:hud_change(rp_hud.ids[name].id_breathbar,"number",player:get_breath()*2)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if eventname == "hud_changed" then
|
if eventname == "hud_changed" then
|
||||||
default.hud.initialize_builtin_statbars(player)
|
rp_hud.initialize_builtin_statbars(player)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function default.hud.replace_builtin(name, definition)
|
function rp_hud.replace_builtin(name, definition)
|
||||||
if definition == nil or type(definition) ~= "table" or definition.hud_elem_type ~= "statbar" then
|
if definition == nil or type(definition) ~= "table" or definition.hud_elem_type ~= "statbar" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -142,11 +142,11 @@ function default.hud.replace_builtin(name, definition)
|
|||||||
if name == "health" then
|
if name == "health" then
|
||||||
health_bar_definition = definition
|
health_bar_definition = definition
|
||||||
|
|
||||||
for name,ids in pairs(default.hud.ids) do
|
for name,ids in pairs(rp_hud.ids) do
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
if player and default.hud.ids[name].id_healthbar then
|
if player and rp_hud.ids[name].id_healthbar then
|
||||||
player:hud_remove(default.hud.ids[name].id_healthbar)
|
player:hud_remove(rp_hud.ids[name].id_healthbar)
|
||||||
default.hud.initialize_builtin_statbars(player)
|
rp_hud.initialize_builtin_statbars(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -155,11 +155,11 @@ function default.hud.replace_builtin(name, definition)
|
|||||||
if name == "breath" then
|
if name == "breath" then
|
||||||
breath_bar_definition = definition
|
breath_bar_definition = definition
|
||||||
|
|
||||||
for name,ids in pairs(default.hud.ids) do
|
for name,ids in pairs(rp_hud.ids) do
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
if player and default.hud.ids[name].id_breathbar then
|
if player and rp_hud.ids[name].id_breathbar then
|
||||||
player:hud_remove(default.hud.ids[name].id_breathbar)
|
player:hud_remove(rp_hud.ids[name].id_breathbar)
|
||||||
default.hud.initialize_builtin_statbars(player)
|
rp_hud.initialize_builtin_statbars(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -168,8 +168,8 @@ function default.hud.replace_builtin(name, definition)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(default.hud.initialize_builtin_statbars)
|
minetest.register_on_joinplayer(rp_hud.initialize_builtin_statbars)
|
||||||
minetest.register_on_leaveplayer(default.hud.cleanup_builtin_statbars)
|
minetest.register_on_leaveplayer(rp_hud.cleanup_builtin_statbars)
|
||||||
minetest.register_playerevent(default.hud.player_event_handler)
|
minetest.register_playerevent(rp_hud.player_event_handler)
|
||||||
|
|
||||||
default.log("hud", "loaded")
|
default.log("rp_hud", "loaded")
|
3
mods/rp_hud/mod.conf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name = rp_hud
|
||||||
|
depends = rp_default
|
||||||
|
description = Repixture HUD
|
Before Width: | Height: | Size: 177 B After Width: | Height: | Size: 177 B |
Before Width: | Height: | Size: 259 B After Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 477 B After Width: | Height: | Size: 477 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 148 B After Width: | Height: | Size: 148 B |