Skip to content

Commit

Permalink
only display level up if hud is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jun 23, 2020
1 parent 1693cf2 commit dea2377
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 5 additions & 1 deletion functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ xp_redo.add_xp = function(playername, xp)
if currentRank and currentRank.xp > previousRank.xp then
-- level up
xp_redo.run_hook("rank_change", { playername, sumXp, currentRank })
level_up(player, currentRank)

local state = player:get_attribute(xp_redo.HUD_DISPLAY_STATE_NAME)
if state and state == "on" then
level_up(player, currentRank)
end
end

return sumXp
Expand Down
11 changes: 3 additions & 8 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ local hud = {} -- playername -> data
local HUD_POSITION = {x = xp_redo.hud.posx, y = xp_redo.hud.posy}
local HUD_ALIGNMENT = {x = 1, y = 0}

local HUD_DISPLAY_STATE_NAME = "hud_state"




local setup_hud = function(player)
local playername = player:get_player_name()
if hud[playername] then
Expand All @@ -26,7 +21,7 @@ local setup_hud = function(player)

local data = {}

player:set_attribute(HUD_DISPLAY_STATE_NAME, "on")
player:set_attribute(xp_redo.HUD_DISPLAY_STATE_NAME, "on")

data.info = player:hud_add({
hud_elem_type = "text",
Expand Down Expand Up @@ -96,7 +91,7 @@ local remove_hud = function(player)
local playername = player:get_player_name()
local data = hud[playername]

player:set_attribute(HUD_DISPLAY_STATE_NAME, "off")
player:set_attribute(xp_redo.HUD_DISPLAY_STATE_NAME, "off")


if not data then
Expand Down Expand Up @@ -210,7 +205,7 @@ xp_redo.update_hud = function(player, xp, rank, next_rank)
end

minetest.register_on_joinplayer(function(player)
local state = player:get_attribute(HUD_DISPLAY_STATE_NAME)
local state = player:get_attribute(xp_redo.HUD_DISPLAY_STATE_NAME)
if not state or state == "on" then
setup_hud(player)
end
Expand Down
4 changes: 3 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ xp_redo = {
hud = {
posx = tonumber(minetest.settings:get("xp.hud.offsetx") or 0.8),
posy = tonumber(minetest.settings:get("xp.hud.offsety") or 0.7)
}
},

HUD_DISPLAY_STATE_NAME = "hud_state"
}

-- optional mapserver-bridge stuff below
Expand Down

0 comments on commit dea2377

Please sign in to comment.