Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AlternateSkillBar.cs "$Revision: 2527 $" "$Date: 2019-08-21 14:33:38 +0300 (ke, 21 elo 2019) $"
- // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/797402-alternateskillbar.html
- // https://pastebin.com/FZd2xr7z
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using SharpDX;
- using Turbo.Plugins.Default;
- namespace Turbo.Plugins.JarJar.DefaultUI
- {
- public class AlternateSkillBar : BasePlugin, IInGameTopPainter
- {
- public float offsetX { get; set; } = 0.60f; // Percent-X pos
- public float offsetY { get; set; } = 0.05f; // Percent-Y pos
- public float IconSize { get; set; } = 55.0f; // Icon size.
- public float IconSpacing { get; set; } = 3.0f; // Icon gap.
- public uint HealthPotionTextureid { get; set; } = 3247534500; // See https://ibb.co/wCVDFzz or /plugins_support/_images/d3_potions_textureid.png
- public bool IncludeHeal { get; set; } = true;
- public bool ShowHealAlways { get; set; } = false;
- public Func<IController, IEnumerable<IPlayerSkill>> SkillProvider { get; set; } // Gets skills to show in correct order.
- public List<ActionKey> SkillOrder { get; set; }
- public ISnoPower[] ExcludedSkills { get; set; }
- public ISnoPower[] SkillsWithStack { get; set; }
- public XDAV_SkillPainter SkillPainter { get; set; }
- public AlternateSkillBar() { Enabled = true; Order = 100; }
- public override void Load(IController hud)
- {
- base.Load(hud);
- var p = Hud.Sno.SnoPowers;
- SkillProvider = DefaultSkills;
- SkillOrder = new List<ActionKey>
- {
- ActionKey.Skill1, ActionKey.Skill2, ActionKey.Skill3, ActionKey.Skill4, ActionKey.LeftSkill, ActionKey.RightSkill, ActionKey.Heal
- };
- ExcludedSkills = new ISnoPower[]
- {
- p.Barbarian_Whirlwind,
- p.Crusader_SweepAttack,
- p.DemonHunter_ClusterArrow,
- p.DemonHunter_EvasiveFire,
- p.DemonHunter_Impale,
- p.DemonHunter_Multishot,
- //p.DemonHunter_Vault, // Tumble and Acrobatics has duration or cooldown!
- p.Necromancer_Devour,
- };
- SkillPainter = new XDAV_SkillPainter(Hud)
- {
- SkillsWitchStacks = new Dictionary<uint, int>() // skill sno and iconIdex to read stack count from: skill.Buff.IconCounts[iconIdex].
- {
- { p.Necromancer_BoneArmor.Sno, 0 },
- },
- HealthPotionTextureid = HealthPotionTextureid,
- };
- }
- public void PaintTopInGame(ClipState clipState)
- {
- if (Hud.Render.UiHidden || clipState != ClipState.BeforeClip || Hud.Game.MapMode == MapMode.WaypointMap || Hud.Game.MapMode == MapMode.ActMap || Hud.Game.MapMode == MapMode.Map)
- return;
- var posX = offsetX * Hud.Window.Size.Width;
- var posY = offsetY * Hud.Window.Size.Height;
- foreach (var skill in SkillProvider(Hud))
- {
- var rect = new RectangleF(posX, posY, IconSize, IconSize);
- SkillPainter.Paint(Hud.Game.Me, skill, rect);
- posX += rect.Width + IconSpacing;
- }
- }
- private IEnumerable<IPlayerSkill> DefaultSkills(IController hud)
- {
- var currentSkills = hud.Game.Me.Powers.CurrentSkills.Where(x => !ExcludedSkills.Contains(x.SnoPower)).ToList();
- if (IncludeHeal)
- {
- var heal = hud.Game.Me.Powers.HealthPotionSkill;
- var isOnCooldown = heal.CooldownFinishTick > Hud.Game.CurrentGameTick;
- if (ShowHealAlways || isOnCooldown)
- {
- currentSkills.Add(heal);
- }
- }
- currentSkills.Sort((a, b) => SkillOrder.IndexOf(a.Key).CompareTo(SkillOrder.IndexOf(b.Key)));
- return currentSkills;
- }
- }
- public class XDAV_SkillPainter : ITransparentCollection
- {
- // Original from https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/787962-eng-combin-plugin-of-party-cooldown-archon-downtime.html
- public float ShowDecimalLimit { get; set; } = 1.0f;
- public bool ShowSpinner { get; set; } = true;
- public bool ShowActiveSkillBorder { get; set; } = true;
- public IFont CooldownFont { get; set; }
- public IFont StacksFont { get; set; }
- public IFont ChargesFont { get; set; }
- public IFont ActiveFont { get; set; }
- public IFont SpinnerFont { get; set; }
- public IBrush ActiveSkillBorderBrush { get; set; }
- public Dictionary<uint, int> SkillsWitchStacks { get; set; } = new Dictionary<uint, int>();
- public float MoveUpRectRatio { get; set; } = 0.2f;
- public float MoveDownRectRatio { get; set; } = 0.2f;
- public float MoveLeftRectRatio { get; set; } = 0.2f;
- public uint HealthPotionTextureid = 3247534500;
- private IController Hud { get; set; }
- private readonly string[] spinner = new string[] { "+", "x", "+", "x", "+", "x", "+", "x", "+", "x", };
- public XDAV_SkillPainter(IController hud)
- {
- Hud = hud;
- var color = Color.Gold; // D3 UI shows only progressbar for active time!
- ActiveFont = Hud.Render.CreateFont("tahoma", 10, 255, color.R, color.G, color.B, true, false, 255, 0, 0, 0, true);
- color = Color.White;
- CooldownFont = Hud.Render.CreateFont("tahoma", 10, 255, color.R, color.G, color.B, true, false, 255, 0, 0, 0, true);
- ChargesFont = Hud.Render.CreateFont("tahoma", 10, 255, color.R, color.G, color.B, true, false, 255, 0, 0, 0, true);
- color = Color.LawnGreen;
- StacksFont = Hud.Render.CreateFont("tahoma", 10, 255, color.R, color.G, color.B, true, false, 255, 0, 0, 0, true);
- color = Color.GreenYellow;
- SpinnerFont = Hud.Render.CreateFont("tahoma", 10, 255, color.R, color.G, color.B, true, false, 255, 0, 0, 0, true);
- ActiveSkillBorderBrush = Hud.Render.CreateBrush(200, color.R, color.G, color.B, 3f); // Slightly transparent!
- }
- public virtual void Paint(IPlayer player, IPlayerSkill skill, RectangleF rect)
- {
- // Heal SnoPower 30211 DrinkHealthPotion does not have a texture id :-(
- var texture = skill.SnoPower.NormalIconTextureId != 0
- ? Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId)
- : (Hud.Texture.GetTexture(HealthPotionTextureid) ?? Hud.Texture.EmptySocketTexture);
- if (texture != null)
- {
- texture.Draw(rect.X, rect.Y, rect.Width, rect.Height);
- }
- if (skill.SnoPower.Sno == Hud.Sno.SnoPowers.DemonHunter_Sentry.Sno)
- {
- var count = 0;
- foreach (var actor in Hud.Game.Actors)
- {
- if (actor.SummonerAcdDynamicId == player.SummonerId)
- {
- switch (actor.SnoActor.Sno)
- {
- case ActorSnoEnum._dh_sentry:
- case ActorSnoEnum._dh_sentry_addsmissiles:
- case ActorSnoEnum._dh_sentry_addsduration:
- case ActorSnoEnum._dh_sentry_tether:
- case ActorSnoEnum._dh_sentry_addsheals:
- case ActorSnoEnum._dh_sentry_addsshield:
- count += 1;
- break;
- }
- }
- }
- var text = count.ToString(CultureInfo.InvariantCulture);
- var layout = ActiveFont.GetTextLayout(text);
- ActiveFont.DrawText(layout, rect.X + (rect.Width / 5f), rect.Y + ((rect.Height - layout.Metrics.Height) / 2));
- text = skill.Charges.ToString(CultureInfo.InvariantCulture);
- layout = SpinnerFont.GetTextLayout(text);
- SpinnerFont.DrawText(layout, rect.X + rect.Width - (rect.Width / 5f) - layout.Metrics.Width, rect.Y + ((rect.Height - layout.Metrics.Height) / 2));
- return;
- }
- var remainingSeconds = 0d;
- var stackCount = -1;
- IFont font = null;
- if (skill.BuffIsActive)
- {
- if (SkillsWitchStacks.TryGetValue(skill.SnoPower.Sno, out var iconIdex))
- {
- stackCount = skill.Buff.IconCounts[iconIdex];
- }
- if (ShowActiveSkillBorder)
- {
- // TODO: add alternate border when skill is about about to expire - like BuffPainter.UseAlternateStyleWhenBuffIsAlmostGone.
- ActiveSkillBorderBrush.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height);
- }
- var buff = skill.Buff;
- if (buff.TimeLeftSeconds[0] == 0 && buff.TimeLeftSeconds[1] == 0 && buff.TimeLeftSeconds[2] == 0)
- {
- if (skill.SnoPower.Sno == Hud.Sno.SnoPowers.Wizard_StormArmor.Sno)
- {
- remainingSeconds = buff.TimeLeftSeconds[3]; // At least one rune uses "extra" slot!
- }
- }
- else
- {
- remainingSeconds = Math.Max(buff.TimeLeftSeconds[0], Math.Max(buff.TimeLeftSeconds[1], buff.TimeLeftSeconds[2]));
- }
- font = ActiveFont;
- if (remainingSeconds <= 0)
- {
- remainingSeconds = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
- if (skill.SnoPower.Sno == Hud.Sno.SnoPowers.Wizard_Archon.Sno)
- {
- // Archon does not go to cooldown immediately like other skills!
- font = CooldownFont;
- }
- else if (remainingSeconds <= 0 && ShowSpinner)
- {
- // Show "spinner" if skill is active and timeleft and cooldown are zero (or less)!
- // - e.g. Call Of The Ancients can last until they die.
- var seconds = Hud.Game.CurrentGameTick / 60;
- drawText(SpinnerFont, spinner[seconds % 10], rect);
- return;
- }
- }
- }
- else
- {
- remainingSeconds = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
- font = CooldownFont;
- }
- if (remainingSeconds > 0)
- {
- if (stackCount >= 0)
- {
- var upperRect = new RectangleF(rect.X, rect.Y - (rect.Height * MoveUpRectRatio), rect.Width, rect.Height);
- drawText(font, remainingSeconds, upperRect);
- var lowerRect = new RectangleF(rect.X - (rect.Width * MoveLeftRectRatio), rect.Y + (rect.Height * MoveDownRectRatio), rect.Width, rect.Height);
- var text = stackCount.ToString(CultureInfo.InvariantCulture);
- drawText(ChargesFont, text, lowerRect);
- }
- else
- {
- drawText(font, remainingSeconds, rect);
- }
- }
- else if (skill.Charges > 0)
- {
- var leftRect = new RectangleF(rect.X + (rect.Width * MoveLeftRectRatio), rect.Y + (rect.Height * MoveDownRectRatio), rect.Width, rect.Height);
- var text = skill.Charges.ToString(CultureInfo.InvariantCulture);
- drawText(ChargesFont, text, leftRect);
- }
- else if (stackCount >= 0)
- {
- var lowerRect = new RectangleF(rect.X - (rect.Width * MoveLeftRectRatio), rect.Y + (rect.Height * MoveDownRectRatio), rect.Width, rect.Height);
- var text = stackCount.ToString(CultureInfo.InvariantCulture);
- drawText(ChargesFont, text, lowerRect);
- }
- }
- public IEnumerable<ITransparent> GetTransparents()
- {
- yield return CooldownFont;
- yield return ActiveFont;
- }
- protected void drawText(IFont font, double timeLeft, RectangleF rect)
- {
- var text = "";
- if (timeLeft > ShowDecimalLimit)
- {
- if (timeLeft < 60)
- {
- text = timeLeft.ToString("F0", CultureInfo.InvariantCulture);
- }
- else
- {
- var mins = Convert.ToInt32(Math.Floor(timeLeft / 60.0d));
- var secs = Math.Floor(timeLeft - (mins * 60.0d));
- text = mins.ToString("F0", CultureInfo.InvariantCulture) + ":" + (secs < 10 ? "0" : "") + secs.ToString("F0", CultureInfo.InvariantCulture);
- }
- }
- else
- {
- text = timeLeft.ToString("F1", CultureInfo.InvariantCulture);
- }
- drawText(font, text, rect);
- }
- protected void drawText(IFont font, string text, RectangleF rect)
- {
- var layout = font.GetTextLayout(text);
- font.DrawText(layout, rect.X + ((rect.Width - (float)Math.Ceiling(layout.Metrics.Width)) / 2.0f), rect.Y + ((rect.Height - layout.Metrics.Height) / 2));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement