From e65c9e21433a2a8b6ed350d2a03d390dc6ca412d Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 31 Jan 2020 01:14:59 +0100 Subject: [PATCH] Display status effect icons --- mods/bed/init.lua | 3 +- mods/bed/textures/bed_effect.png | Bin 0 -> 228 bytes mods/hunger/init.lua | 3 +- mods/hunger/textures/hunger_effect_eating.png | Bin 0 -> 172 bytes mods/player_effects/init.lua | 41 +++++++++++++++++- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 mods/bed/textures/bed_effect.png create mode 100644 mods/hunger/textures/hunger_effect_eating.png diff --git a/mods/bed/init.lua b/mods/bed/init.lua index 98e4d2b..4072d0b 100644 --- a/mods/bed/init.lua +++ b/mods/bed/init.lua @@ -475,7 +475,8 @@ player_effects.register_effect( speed = 0, jump = 0, gravity = 0, - } + }, + icon = "bed_effect.png", }) -- Achievements diff --git a/mods/bed/textures/bed_effect.png b/mods/bed/textures/bed_effect.png new file mode 100644 index 0000000000000000000000000000000000000000..c398a22e2877c7f172b3d38744a764ef3780fa16 GIT binary patch literal 228 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFP2=EDU1=7W7-aR$Z#>U3au63T- zSCz3Ta%Qp5nKNe^66`lE%ia_jIn&1{G`=q(W8#b&m*qTm=Ye_{OM?7@862M7NCR?` zJY5_^Di~!?nlmy5O0*n&zdvT*-dS%ROqsx&$Srp#o-HLJIL`^gld WBD3EjOLZC0HU>{uKbLh*2~7aIby4mB literal 0 HcmV?d00001 diff --git a/mods/hunger/init.lua b/mods/hunger/init.lua index b66ca8e..757e2ea 100644 --- a/mods/hunger/init.lua +++ b/mods/hunger/init.lua @@ -382,5 +382,6 @@ player_effects.register_effect( duration = 2, physics = { speed = 0.6, - } + }, + icon = "hunger_effect_eating.png", }) diff --git a/mods/hunger/textures/hunger_effect_eating.png b/mods/hunger/textures/hunger_effect_eating.png new file mode 100644 index 0000000000000000000000000000000000000000..94e19aabfab8b02d923965d9afd0a7a13d4067da GIT binary patch literal 172 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|Y$ZW{!9W@a@|Lkr1X78fE{-7; zjL8g5k4*BF1f5F#eN7x$t~R@G-MGQ$vpk(se?)WB^8C~r=$d`9<1`b>`-qXAh(9YR^aLkDG$FI74>`uAtyH>!I!dY PK$d#C`njxgN@xNAK+`nT literal 0 HcmV?d00001 diff --git a/mods/player_effects/init.lua b/mods/player_effects/init.lua index adb15f3..666ba9c 100644 --- a/mods/player_effects/init.lua +++ b/mods/player_effects/init.lua @@ -4,6 +4,7 @@ -- local S = minetest.get_translator("player_effects") +local DISPLAY_ICONS = true player_effects = {} @@ -34,12 +35,44 @@ local function load_effects() end end +local huds = {} + +local function display_effect_icons(player) + if not DISPLAY_ICONS then + return + end + + local name = player:get_player_name() + for _,h in pairs(huds[name]) do + player:hud_remove(h) + end + huds[name] = {} + local i = 0 + for en, _ in pairs(player_effects.effects[name]) do + local effect = player_effects.get_registered_effect(en) + if effect.icon then + local id = player:hud_add({ + hud_elem_type = "image", + position = { x = 1, y = 0 }, + offset = { x = -52 - i*52, y = 270 }, + text = effect.icon, + scale = { x = 3, y = 3 }, + size = { x = 16, y = 16 }, + alignment = { x = 1, y = 1 }, + }) + table.insert(huds[name], id) + i = i + 1 + end + end +end + function player_effects.register_effect(name, def) local rd = { title = def.title or name, -- good-looking name of the effect description = def.description or S("The @1 effect", name), -- description of what the effect does duration = def.duration or 1, -- how long the effect lasts, <0 is infinite and has to be disabled manually - physics = def.physics or {} -- physics overrides for the player + physics = def.physics or {}, -- physics overrides for the player + icon = def.icon, -- effect icon for HUD } player_effects.registered_effects[name] = rd @@ -85,6 +118,7 @@ function player_effects.apply_effect(player, ename) end player:set_physics_override(phys) + display_effect_icons(player) save_effects() end @@ -115,6 +149,7 @@ function player_effects.remove_effect(player, ename) player:set_physics_override(phys) player_effects.effects[player:get_player_name()][ename] = nil + display_effect_icons(player) save_effects() end @@ -140,6 +175,8 @@ function player_effects.refresh_effects(player) player:set_physics_override(phys) + display_effect_icons(player) + save_effects() end @@ -148,6 +185,7 @@ function player_effects.clear_effects(player) player:set_physics_override({speed = 1, jump = 1, gravity = 1}) player_effects.effects[player:get_player_name()] = {} + display_effect_icons(player) save_effects() end @@ -189,6 +227,7 @@ local function on_joinplayer(player) if player_effects.effects[name] == nil then player_effects.effects[name] = {} end + huds[name] = {} player_effects.refresh_effects(player)