1
0
mirror of https://github.com/mt-mods/hangglider.git synced 2025-06-23 12:10:18 +02:00

Cleanup HUD code (#21)

This commit is contained in:
Niklp 2025-05-24 23:49:24 +02:00 committed by GitHub
parent 071fe93cf5
commit f970874855
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,22 +42,23 @@ if enable_flak then
}) })
end end
local function set_hud_overlay(player, name, image) local function set_hud_overlay(player, name, show)
if not enable_hud_overlay then if not enable_hud_overlay then
return return
end end
if not hud_overlay_ids[name] then if not hud_overlay_ids[name] and show == true then
hud_overlay_ids[name] = player:hud_add({ hud_overlay_ids[name] = player:hud_add({
hud_elem_type = "image", hud_elem_type = "image",
text = image, text = "hangglider_overlay.png",
position = {x = 0, y = 0}, position = {x = 0, y = 0},
scale = {x = -100, y = -100}, scale = {x = -100, y = -100},
alignment = {x = 1, y = 1}, alignment = {x = 1, y = 1},
offset = {x = 0, y = 0}, offset = {x = 0, y = 0},
z_index = -150 z_index = -150
}) })
else elseif hud_overlay_ids[name] and show == false then
player:hud_change(hud_overlay_ids[name], "text", image) player:hud_remove(hud_overlay_ids[name])
hud_overlay_ids[name] = nil
end end
end end
@ -175,7 +176,7 @@ local function hangglider_step(self, dtime)
if not gliding then if not gliding then
remove_physics_overrides(player) remove_physics_overrides(player)
hanggliding_players[name] = nil hanggliding_players[name] = nil
set_hud_overlay(player, name, "blank.png") set_hud_overlay(player, name, false)
end end
end end
end end
@ -202,7 +203,7 @@ local function hangglider_use(stack, player)
textures = {"wool_white.png^[multiply:#"..color, "default_wood.png"} textures = {"wool_white.png^[multiply:#"..color, "default_wood.png"}
}) })
end end
set_hud_overlay(player, name, "hangglider_overlay.png") set_hud_overlay(player, name, true)
set_physics_overrides(player, {jump = 0, gravity = 0.25}) set_physics_overrides(player, {jump = 0, gravity = 0.25})
hanggliding_players[name] = true hanggliding_players[name] = true
if hangglider_uses > 0 then if hangglider_uses > 0 then
@ -211,7 +212,7 @@ local function hangglider_use(stack, player)
return stack return stack
end end
else else
set_hud_overlay(player, name, "blank.png") set_hud_overlay(player, name, false)
remove_physics_overrides(player) remove_physics_overrides(player)
hanggliding_players[name] = nil hanggliding_players[name] = nil
end end