mirror of
https://github.com/technix/ham_radio.git
synced 2024-11-27 17:33:49 +01:00
better hud
This commit is contained in:
parent
858e601fe2
commit
9c3cd7a851
90
hud.lua
90
hud.lua
@ -1,38 +1,80 @@
|
|||||||
|
|
||||||
function ham_radio.init_hud(player)
|
function ham_radio.toggle_hud(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
ham_radio.playerhuds[name] = player:hud_add({
|
local item = player:get_wielded_item()
|
||||||
|
|
||||||
|
-- remove hud if user does not wield a receiver
|
||||||
|
if item:get_name() ~= "ham_radio:receiver" then
|
||||||
|
if ham_radio.is_receiver_wielded[name] then
|
||||||
|
player:hud_remove(ham_radio.playerhuds[name].background)
|
||||||
|
player:hud_remove(ham_radio.playerhuds[name].frequency)
|
||||||
|
player:hud_remove(ham_radio.playerhuds[name].signal_meter)
|
||||||
|
player:hud_remove(ham_radio.playerhuds[name].signal_level)
|
||||||
|
ham_radio.is_receiver_wielded[name] = false
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- if hud is already enabled, pass
|
||||||
|
if ham_radio.is_receiver_wielded[name] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- create hud
|
||||||
|
ham_radio.is_receiver_wielded[name] = true
|
||||||
|
|
||||||
|
local hud_pos = ham_radio.settings.hud_pos
|
||||||
|
|
||||||
|
ham_radio.playerhuds[name] = {
|
||||||
|
background = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = hud_pos,
|
||||||
|
offset = { x = -250, y = 20 },
|
||||||
|
text = "ham_radio_hud_bg.png",
|
||||||
|
scale = { x = 2, y = 3 },
|
||||||
|
alignment = { x = 1, y = 0 },
|
||||||
|
}),
|
||||||
|
frequency = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = "",
|
text = "",
|
||||||
position = ham_radio.settings.hud_pos,
|
position = hud_pos,
|
||||||
offset = { x = ham_radio.settings.hud_offset.x, y = ham_radio.settings.hud_offset.y },
|
offset = { x = 0, y = 0 },
|
||||||
alignment = ham_radio.settings.hud_alignment,
|
alignment = 0,
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
scale= { x = 100, y = 20 },
|
scale= { x = 100, y = 20 },
|
||||||
|
}),
|
||||||
|
signal_meter = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = hud_pos,
|
||||||
|
offset = { x = -220, y = 30 },
|
||||||
|
text = "ham_radio_hud_indicator_empty.png",
|
||||||
|
scale = { x = 2, y = 2 },
|
||||||
|
alignment = { x = 1, y = 0 },
|
||||||
|
}),
|
||||||
|
signal_level = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = hud_pos,
|
||||||
|
offset = { x = -220, y = 30 },
|
||||||
|
text = "ham_radio_hud_indicator_full.png",
|
||||||
|
scale = { x = 0, y = 2 },
|
||||||
|
alignment = { x = 1, y = 0 },
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function ham_radio:update_hud_display(player)
|
function ham_radio:update_hud_display(player)
|
||||||
local transmitter_signal = 0
|
|
||||||
|
|
||||||
local name = player:get_player_name()
|
if not ham_radio.toggle_hud(player) then
|
||||||
local item = player:get_wielded_item()
|
|
||||||
|
|
||||||
if item:get_name() ~= "ham_radio:receiver" then
|
|
||||||
if self.playerlocators[name] then
|
|
||||||
player:hud_change(self.playerhuds[name], "text", "")
|
|
||||||
self.playerlocators[name] = false
|
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.playerlocators[name] = true
|
|
||||||
|
|
||||||
local meta = item:get_meta()
|
local transmitter_signal = 0
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local meta = player:get_wielded_item():get_meta()
|
||||||
local frequency = meta:get_string("frequency")
|
local frequency = meta:get_string("frequency")
|
||||||
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "Configured freq:"..frequency)
|
|
||||||
|
|
||||||
if frequency ~= nil and frequency ~= "" then
|
if frequency ~= nil and frequency ~= "" then
|
||||||
local transmitter = self.read_transmitter(frequency)
|
local transmitter = self.read_transmitter(frequency)
|
||||||
-- minetest.chat_send_player(player:get_player_name(), "Found transmitter:"..minetest.serialize(transmitter))
|
-- minetest.chat_send_player(player:get_player_name(), "Found transmitter:"..minetest.serialize(transmitter))
|
||||||
@ -45,15 +87,17 @@ function ham_radio:update_hud_display(player)
|
|||||||
--local indicator = string.rep('|', transmitter.distance)..string.rep('|', transmitter.signal)..string.rep(':', 25-(transmitter.distance + transmitter.signal))
|
--local indicator = string.rep('|', transmitter.distance)..string.rep('|', transmitter.signal)..string.rep(':', 25-(transmitter.distance + transmitter.signal))
|
||||||
local indicator = string.rep('|', transmitter_signal)..string.rep(':', 20 - transmitter_signal)
|
local indicator = string.rep('|', transmitter_signal)..string.rep(':', 20 - transmitter_signal)
|
||||||
|
|
||||||
local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]"..indicator
|
--local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]"..indicator
|
||||||
|
local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]"
|
||||||
player:hud_change(self.playerhuds[name], "text", text)
|
player:hud_change(self.playerhuds[name].frequency, "text", text)
|
||||||
|
player:hud_change(self.playerhuds[name].signal_level, "scale", { x = (transmitter_signal * 20) / 200 or 0.1, y = 2 })
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_newplayer(ham_radio.init_hud)
|
minetest.register_on_newplayer(ham_radio.toggle_hud)
|
||||||
minetest.register_on_joinplayer(ham_radio.init_hud)
|
minetest.register_on_joinplayer(ham_radio.toggle_hud)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
ham_radio.is_receiver_wielded[name] = false
|
||||||
ham_radio.playerhuds[player:get_player_name()] = nil
|
ham_radio.playerhuds[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
6
init.lua
6
init.lua
@ -5,11 +5,9 @@ ham_radio = rawget(_G, "ham_radio") or {}
|
|||||||
|
|
||||||
ham_radio = {
|
ham_radio = {
|
||||||
playerhuds = {},
|
playerhuds = {},
|
||||||
playerlocators = {},
|
is_receiver_wielded = {},
|
||||||
settings = {
|
settings = {
|
||||||
hud_pos = { x = 0.45, y = 0.7 },
|
hud_pos = { x = 0.5, y = 0.8 },
|
||||||
hud_offset = { x = 15, y = 15 },
|
|
||||||
hud_alignment = { x = 1, y = 0 }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
textures/ham_radio_hud_bg.png
Normal file
BIN
textures/ham_radio_hud_bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 251 B |
BIN
textures/ham_radio_hud_indicator_empty.png
Normal file
BIN
textures/ham_radio_hud_indicator_empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 B |
BIN
textures/ham_radio_hud_indicator_full.png
Normal file
BIN
textures/ham_radio_hud_indicator_full.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 174 B |
BIN
textures/indicator.xcf
Normal file
BIN
textures/indicator.xcf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user