Advertisement
s4000

HealthResourceGlobe

Jul 26th, 2023 (edited)
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | Gaming | 0 0
  1. namespace T4.Plugins.DAV;
  2.  
  3. public class HealthResourceGlobe : BasePlugin, IGameUserInterfacePainter {
  4.     public Feature FontSetting { get; private set; }
  5.  
  6.     public float OffsetX { get; set; } = 0.2f;
  7.     public IFont HealthFont { get; set; } = Services.Render.GetFont(255, 255, 51, 51, fontFamily: "Calibri", bold: true, size: 10, shadowMode: FontShadowMode.None).SetShadowColor(255, 0, 0, 0);
  8.     public IFont BarrierFont { get; set; } = Services.Render.GetFont(255, 255, 255, 255, fontFamily: "Calibri", bold: true, size: 10, shadowMode: FontShadowMode.None).SetShadowColor(255, 0, 0, 0);
  9.     public IFont ResourceFont { get; set; } = Services.Render.GetFont(255, 51, 51, 255, fontFamily: "Calibri", bold: true, size: 10, shadowMode: FontShadowMode.Heavy).SetShadowColor(255, 0, 0, 0);
  10.  
  11. // pluginFunction
  12.     public HealthResourceGlobe() : base(PluginCategory.ActionBar, "display the information of health, barrier & resources") {
  13.         FontSetting = AddFeature(nameof(FontSetting), "FontSetting")
  14.             .AddFontResource(nameof(HealthFont), HealthFont, "font - health")
  15.             .AddFontResource(nameof(BarrierFont), BarrierFont, "font - barrier")
  16.             .AddFontResource(nameof(ResourceFont), ResourceFont, "font - resource")
  17.             .AddFloatResource(nameof(OffsetX), "horizontal offset", 0f, 0.5f,
  18.                 getter: () => OffsetX,
  19.                 setter: newValue => OffsetX = MathF.Round(newValue, 2));
  20.     }
  21.  
  22.     public void PaintGameUserInterface(GameUserInterfaceLayer layer) {
  23.         if (layer != GameUserInterfaceLayer.OverActionBar) return;
  24.  
  25.         var me = Services.Game.MyPlayerActor;
  26.         if (me.HitpointsCur <= 0) return;
  27.  
  28.         var hpControl = Services.UserInterface.HealthBallControl;
  29.         var outMessage = HealthFont.GetTextLayout(ToText(me.HitpointsCur, me.HitpointsMax, me.LifeRegen));
  30.         outMessage.DrawText(hpControl.Left + hpControl.Width * OffsetX, hpControl.Top + hpControl.Height * 0.5f - outMessage.Height);
  31.  
  32.         if (me.BarrierOn && me.BarrierAmount > 0) {
  33.             outMessage = BarrierFont.GetTextLayout(ToText(me.BarrierAmount, me.HitpointsMax, -1f));
  34.             outMessage.DrawText(hpControl.Left + hpControl.Width * OffsetX, hpControl.Top + hpControl.Height * 0.5f);
  35.         }
  36.  
  37.         if (me.PrimaryResourceType != ResourceType.None) {
  38.             var resControl = Services.UserInterface.ResourceBallControl;
  39.             outMessage = ResourceFont.GetTextLayout(ToText(me.PrimaryResourceCur, me.PrimaryResourceMax, me.PrimaryResourceRegen));
  40.             outMessage.DrawText(resControl.Left + resControl.Width * OffsetX, resControl.Top + (resControl.Height - outMessage.Height) / 2);
  41.         }
  42.     }
  43. // pluginFunction end
  44.  
  45.     private string ToText(float curValue, float maxValue, float regValue) {
  46.         var output = curValue.ToString("#,##0") + "\n" + (curValue / maxValue).ToString("0%") + "\n";
  47.         if (regValue > 0 && curValue < maxValue)
  48.             output += "+" + regValue.ToString("#,##0") + "/s";
  49.  
  50.         return output;
  51.     }
  52. }
Tags: t4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement