From 6bea667659f4003953dd23396cbcb3c0e56b6b30 Mon Sep 17 00:00:00 2001 From: zeeZ Date: Wed, 18 May 2011 16:38:50 +0200 Subject: [PATCH] Optionally add player health bars to map markers. --- configuration.txt | 1 + web/css/dynmap_style.css | 13 +++++++++++++ web/images/heart.png | Bin 0 -> 180 bytes web/js/map.js | 4 +++- web/js/playermarkers.js | 9 +++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 web/images/heart.png diff --git a/configuration.txt b/configuration.txt index b8bdd5f3..cce26db2 100644 --- a/configuration.txt +++ b/configuration.txt @@ -117,6 +117,7 @@ web: messagettl: 5 - type: playermarkers showplayerfaces: true + showplayerhealth: true #- type: digitalclock - type: timeofdayclock showdigitalclock: true diff --git a/web/css/dynmap_style.css b/web/css/dynmap_style.css index 8788a1b4..7edbfd2a 100644 --- a/web/css/dynmap_style.css +++ b/web/css/dynmap_style.css @@ -529,6 +529,19 @@ border-radius: 3px; } +.dynmap .playerHealth { + position: absolute; + bottom: 3px; + left: 34px; + height: 11px; + + background: url(../images/heart.png) rgba(0,0,0,0.6) repeat-x left center; + padding: 1px 0; + + -moz-border-radius: 3px; + border-radius: 3px; +} + /******************* * Compass diff --git a/web/images/heart.png b/web/images/heart.png new file mode 100644 index 0000000000000000000000000000000000000000..59134b27b1cf8926051252a5044795ba4f41a1d7 GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{Vk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X!aQ9ZLn>}1{rUgjp4pKh_)C1m4||T}4UM0C3>@3mMnCL& z$mVdfCtbP0l+XkKuYNv~ literal 0 HcmV?d00001 diff --git a/web/js/map.js b/web/js/map.js index 36612377..b69a29af 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -452,7 +452,8 @@ DynMap.prototype = { var me = this; var player = me.players[update.name] = { name: update.name, - location: new Location(me.worlds[update.world], parseFloat(update.x), parseFloat(update.y), parseFloat(update.z)) + location: new Location(me.worlds[update.world], parseFloat(update.x), parseFloat(update.y), parseFloat(update.z)), + health: update.health }; $(me).trigger('playeradded', [ player ]); @@ -494,6 +495,7 @@ DynMap.prototype = { updatePlayer: function(player, update) { var me = this; var location = player.location = new Location(me.worlds[update.world], parseFloat(update.x), parseFloat(update.y), parseFloat(update.z)); + player.health = update.health; $(me).trigger('playerupdated', [ player ]); diff --git a/web/js/playermarkers.js b/web/js/playermarkers.js index 9271e351..7574b4ff 100644 --- a/web/js/playermarkers.js +++ b/web/js/playermarkers.js @@ -22,6 +22,12 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) { playerImage.remove(); }); } + if (configuration.showplayerhealth) { + player.healthBar = $('
') + .addClass('playerHealth') + .css('width', (player.health/2*9) + 'px') + .appendTo(div); + } }); }); $(dynmap).bind('playerremoved', function(event, player) { @@ -33,5 +39,8 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) { var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z); player.marker.toggle(dynmap.world === player.location.world); player.marker.setPosition(markerPosition); + // Update health + if (configuration.showplayerhealth) + player.healthBar.css('width', (player.health/2*9) + 'px'); }); }; \ No newline at end of file