Advertisement
s4000

DAV_FriendList

Dec 4th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.DAV
  7. {
  8.     public class DAV_FriendList : BasePlugin, IInGameTopPainter {
  9.         public int MaxLength { get; set; }
  10.         public IFont TextFont { get; set; }
  11.         public IBrush DefaultBrush { get; set; }
  12.         public Dictionary<string, string> MyFriendList { get; set; } = new Dictionary<string, string> ();
  13.         public Dictionary<string, IBrush> HighLightBrushs { get; set; } = new Dictionary<string, IBrush>();
  14.  
  15.         private IUiElement FdListSlot { get; set; }
  16.         private IUiElement FdListContainer1 { get; set; }
  17.         private IUiElement FdListContainer2 { get; set; }
  18.         private string UiPathFriend { get; set; } = "Root.NormalLayer.BattleNetFriendsList_main.LayoutRoot.OverlayContainer.FriendsListContent.SocialListContainer.SocialList.FriendsListContainer.FriendsList._content._stackpanel._item";
  19.  
  20.         public DAV_FriendList() {
  21.             Enabled = true;
  22.         }
  23.  
  24.         public override void Load(IController hud) {
  25.             base.Load(hud);
  26.  
  27.             MaxLength = 20;
  28.             MyFriendList.Add("Friend1", "My_Team");
  29.             MyFriendList.Add("Friend2", "My_CLAN");
  30.  
  31.             TextFont = Hud.Render.CreateFont("Arial", 8, 255, 225, 255, 102, true, false, true);
  32.             DefaultBrush = Hud.Render.CreateBrush(255, 255, 255, 51, 4f);
  33.             HighLightBrushs.Add("My_Team", Hud.Render.CreateBrush(255, 255, 128, 51, 4f));
  34.             // SharpDX.Direct2D1.DashStyle : Dash, DashDot, DashDotDot, Dot, Solid
  35.  
  36.             FdListSlot = Hud.Render.GetUiElement("Root.NormalLayer.BattleNetFriendsList_main.LayoutRoot.OverlayContainer.FriendsListContent");
  37.             FdListContainer1 = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetFriendsList_main.LayoutRoot.OverlayContainer.FriendsListContent.SocialListContainer", FdListSlot, null);
  38.             FdListContainer2 = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetFriendsList_main.LayoutRoot.OverlayContainer.FriendsListContent.SocialListContainer.SocialList", FdListSlot, null);
  39.         }
  40.  
  41.         public void PaintTopInGame(ClipState clipState) {
  42.             if (clipState != ClipState.AfterClip) return;
  43.             if (!FdListSlot.Visible) return;
  44.  
  45.             for (var i = 0; i < MaxLength; i++) {
  46.                 var Slot = Hud.Render.RegisterUiElement(UiPathFriend + i.ToString() + ".Name", FdListSlot, null);
  47.                 if (Slot == null || !Slot.Visible) continue;
  48.                 if (Slot.Rectangle.Bottom < FdListContainer1.Rectangle.Y || Slot.Rectangle.Y > FdListContainer1.Rectangle.Bottom) continue;
  49.  
  50.                 var fdName = Slot.ReadText(System.Text.Encoding.UTF8, true);
  51.                 if (string.IsNullOrEmpty(fdName)) continue;
  52.  
  53.                 if (MyFriendList.TryGetValue(NameTrim(fdName), out var profileN)) {
  54.                     var usedBrush = HighLightBrushs.ContainsKey(profileN) ? HighLightBrushs[profileN] : DefaultBrush;
  55.                     usedBrush.DrawRectangle(FdListContainer2.Rectangle.X, Slot.Rectangle.Y, FdListContainer2.Rectangle.Width, 2 * Slot.Rectangle.Height);
  56.  
  57.                     var textLayout = TextFont.GetTextLayout(profileN);
  58.                     TextFont.DrawText(textLayout, FdListContainer2.Rectangle.Right - textLayout.Metrics.Width - 2.2f * Slot.Rectangle.Height, Slot.Rectangle.Y + 2);
  59.                 }
  60.             }
  61.         }
  62.  
  63.         public string NameTrim(string input) {
  64.             var result = Regex.Replace(input, @"\<(.*)\> ", "");
  65.             return Regex.Replace(result, @"\ {(.*)}", "");
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement