Advertisement
Guest User

InfoPanel

a guest
May 13th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 91.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. using UnityEngine;
  7.  
  8. using Newtonsoft.Json;
  9.  
  10. using Oxide.Core;
  11. using Oxide.Core.Plugins;
  12. using Oxide.Game.Rust.Cui;
  13.  
  14. namespace Oxide.Plugins
  15. {
  16.     [Info("InfoPanel", "Ghosst", "0.9.3", ResourceId = 1356)]
  17.     [Description("A little panel with useful informations.")]
  18.     public class InfoPanel : RustPlugin
  19.     {
  20.         #region DefaultConfigs
  21.         private static string DefaultFontColor = "1 1 1 1";
  22.         #endregion
  23.  
  24.         private Timer TestTimer;
  25.  
  26.         private Dictionary<string, Dictionary<string, IPanel>> PlayerPanels = new Dictionary<string, Dictionary<string, IPanel>>();
  27.         private Dictionary<string, Dictionary<string, IPanel>> PlayerDockPanels = new Dictionary<string, Dictionary<string, IPanel>>();
  28.  
  29.         private Dictionary<string, List<string>> LoadedPluginPanels = new Dictionary<string, List<string>>();
  30.  
  31.         #region DefaultConfig
  32.  
  33.         private static PluginConfig Settings;
  34.  
  35.         private readonly List<string> TimeFormats = new List<string>
  36.         {
  37.             {"H:mm"},
  38.             {"HH:mm"},
  39.             {"h:mm"},
  40.             {"h:mm tt"},
  41.         };
  42.  
  43.         PluginConfig DefaultConfig()
  44.         {
  45.             var DefaultConfig = new PluginConfig
  46.             {
  47.                 ThirdPartyPanels = new Dictionary<string, Dictionary<string, PanelConfig>>(),
  48.  
  49.                 Messages = Messages,
  50.                 TimeFormats = TimeFormats,
  51.                 CompassDirections = new Dictionary<string, string>
  52.                 {
  53.                     {"n","North"},
  54.                     {"ne","Northeast"},
  55.                     {"e","East"},
  56.                     {"se","Southeast"},
  57.                     {"s","South"},
  58.                     {"sw","Southwest"},
  59.                     {"w","West"},
  60.                     {"nw","Northwest"},
  61.                 },
  62.                 Docks = new Dictionary<string, DockConfig>
  63.                 {
  64.                     { "BottomDock", new DockConfig
  65.                         {
  66.                             Available = true,
  67.                             Width = 0.99f,
  68.                             Height = 0.030f,
  69.                             AnchorX = "Left",
  70.                             AnchorY = "Bottom",
  71.                             Margin = "0.005 0.005 0.005 0.005",
  72.                             BackgroundColor = "0 0 0 0.4",
  73.                         }
  74.                     },
  75.                     { "TopDock", new DockConfig
  76.                         {
  77.                             Available = true,
  78.                             Width = 0.99f,
  79.                             Height = 0.030f,
  80.                             AnchorX = "Left",
  81.                             AnchorY = "Top",
  82.                             Margin = "0.005 0.005 0.005 0.005",
  83.                             BackgroundColor = "0 0 0 0.4",
  84.                         }
  85.                     },
  86.                 },
  87.  
  88.                 Panels = new Dictionary<string, PanelConfig>
  89.                 {
  90.                     {"Clock", new PanelConfig
  91.                         {
  92.                             Available = true,
  93.                             Dock = "BottomDock",
  94.                             Order = 1,
  95.                             AnchorX = "Left",
  96.                             AnchorY = "Bottom",
  97.                             Margin = "0 0 0 0",
  98.                             Width = 0.045f,
  99.                             Height = 0.95f,
  100.                             BackgroundColor = "0.1 0.1 0.1 0",
  101.                             Text = new PanelTextConfig
  102.                             {
  103.                                 Align = TextAnchor.MiddleCenter,
  104.                                 FontColor = DefaultFontColor,
  105.                                 FontSize = 14,
  106.                                 Margin = "0 0.01 0 0.01",
  107.                             },
  108.                             PanelSettings = new Dictionary<string,object>
  109.                             {
  110.                                 { "ClockUpdateFrequency (seconds)" ,ClockUpdateFrequency },
  111.                                 { "TimeFormat", "HH:mm" }
  112.                             }
  113.                         }
  114.                     },
  115.                     { "MessageBox", new PanelConfig
  116.                         {
  117.                             Available = true,
  118.                             Dock = "BottomDock",
  119.                             Order = 7,
  120.                             AnchorX = "Right",
  121.                             AnchorY = "Bottom",
  122.                             Margin = "0 0 0 0.005",
  123.                             Width = 0.3f,
  124.                             Height = 0.95f,
  125.                             BackgroundColor = "0 0 0 0.4",
  126.                             Text = new PanelTextConfig
  127.                             {
  128.                                 Align = TextAnchor.MiddleCenter,
  129.                                 FontColor = DefaultFontColor,
  130.                                 FontSize = 14,
  131.                             },
  132.                             PanelSettings = new Dictionary<string,object>
  133.                             {
  134.                                 { "MessageUpdateFrequency (seconds)", MessageUpdateFrequency },
  135.                                 { "MsgOrder","normal" }
  136.                             }
  137.                         }
  138.                     },
  139.                     { "Coordinates", new PanelConfig
  140.                         {
  141.                             Available = true,
  142.                             Dock = "BottomDock",
  143.                             Order = 7,
  144.                             AnchorX = "Left",
  145.                             AnchorY = "Bottom",
  146.                             Margin = "0 0 0 0.005",
  147.                             Width = 0.095f,
  148.                             Height = 0.95f,
  149.                             BackgroundColor = "0 0 0 0.4" ,
  150.                             Image = new PanelImageConfig
  151.                             {
  152.                                 Order =  1,
  153.                                 Width = 0.13f,
  154.                                 Height = 0.8f,
  155.                                 Margin = "0 0.01 0.1 0.01",
  156.                                 Url = "http://i.imgur.com/Kr1pQ5b.png",
  157.                             },
  158.                             Text = new PanelTextConfig
  159.                             {
  160.                                 Order =  2,
  161.                                 Width = 0.848f,
  162.                                 Height = 1f,
  163.                                 Align = TextAnchor.MiddleCenter,
  164.                                 FontColor = DefaultFontColor,
  165.                                 FontSize = 12,
  166.                                 Margin = "0 0.02 0 0",
  167.                             },
  168.                             PanelSettings = new Dictionary<string,object>
  169.                             {
  170.                                 { "RefreshRate(s)", "3" },
  171.                             }
  172.                         }
  173.                     },
  174.                     { "Compass", new PanelConfig
  175.                         {
  176.                             Available = true,
  177.                             Dock = "BottomDock",
  178.                             Order = 8,
  179.                             AnchorX = "Left",
  180.                             AnchorY = "Bottom",
  181.                             Margin = "0 0 0 0.005",
  182.                             Width = 0.07f,
  183.                             Height = 0.95f,
  184.                             BackgroundColor = "0 0 0 0.4" ,
  185.                             Image = new PanelImageConfig
  186.                             {
  187.                                 Order =  1,
  188.                                 Width = 0.188f,
  189.                                 Height = 0.8f,
  190.                                 Margin = "0 0.01 0.1 0.03",
  191.                                 Url = "http://i.imgur.com/dG5nOOJ.png",
  192.                             },
  193.                             Text = new PanelTextConfig
  194.                             {
  195.                                 Order =  2,
  196.                                 Width = 0.76f,
  197.                                 Height = 1f,
  198.                                 Align = TextAnchor.MiddleCenter,
  199.                                 FontColor = DefaultFontColor,
  200.                                 FontSize = 12,
  201.                                 Margin = "0 0.02 0 0",
  202.                             },
  203.                             PanelSettings = new Dictionary<string,object>
  204.                             {
  205.                                 { "RefreshRate(s)", "1" },
  206.                                 { "TextOrAngle", "text" }
  207.                             }
  208.                         }
  209.                     },
  210.                     { "OPlayers", new PanelConfig
  211.                         {
  212.                             Available = true,
  213.                             Dock = "BottomDock",
  214.                             Order = 2,
  215.                             AnchorX = "Left",
  216.                             AnchorY = "Bottom",
  217.                             Margin = "0 0 0 0.005",
  218.                             Width = 0.07f,
  219.                             Height = 0.95f,
  220.                             BackgroundColor = "0 0 0 0.4" ,
  221.                             Image = new PanelImageConfig
  222.                             {
  223.                                 Order =  1,
  224.                                 Width = 0.17f,
  225.                                 Height = 0.8f,
  226.                                 Margin = "0 0.05 0.1 0.05",
  227.                                 Url = "http://i.imgur.com/n9EYIWi.png",
  228.                             },
  229.                             Text = new PanelTextConfig
  230.                             {
  231.                                 Order =  2,
  232.                                 Width = 0.68f,
  233.                                 Height = 1f,
  234.                                 Align = TextAnchor.MiddleCenter,
  235.                                 FontColor = DefaultFontColor,
  236.                                 FontSize = 14,
  237.                             }
  238.                         }
  239.                     },
  240.                     { "Sleepers", new PanelConfig
  241.                         {
  242.                             Available = true,
  243.                             Dock = "BottomDock",
  244.                             Order = 3,
  245.                             AnchorX = "Left",
  246.                             AnchorY = "Bottom",
  247.                             Margin = "0 0 0 0.005",
  248.                             Width = 0.055f,
  249.                             Height = 0.95f,
  250.                             BackgroundColor = "0 0 0 0.4",
  251.                             Image = new PanelImageConfig
  252.                             {
  253.                                 Order =  1,
  254.                                 Width = 0.22f,
  255.                                 Height = 0.8f,
  256.                                 Margin = "0 0.05 0.1 0.05",
  257.                                 Url = "http://i.imgur.com/XIIZkqD.png",
  258.                             },
  259.                             Text = new PanelTextConfig
  260.                             {
  261.                                 Order =  2,
  262.                                 Width = 0.63f,
  263.                                 Height = 1f,
  264.                                 Align = TextAnchor.MiddleCenter,
  265.                                 FontColor = DefaultFontColor,
  266.                                 FontSize = 14,
  267.                             }
  268.                         }
  269.                     },
  270.                     { "AirdropEvent", new PanelConfig
  271.                         {
  272.                             Available = true,
  273.                             Dock = "BottomDock",
  274.                             Order =  4,
  275.                             AnchorX = "Left",
  276.                             AnchorY = "Bottom",
  277.                             Margin = "0 0 0 0.005",
  278.                             Width = 0.018f,
  279.                             Height = 0.95f,
  280.                             BackgroundColor = "0 0 0 0.4",
  281.                             Image = new PanelImageConfig
  282.                                 {
  283.                                     Order =  1,
  284.                                     Width = 0.8f,
  285.                                     Height = 0.8f,
  286.                                     Margin = "0 0.1 0.1 0.1",
  287.                                     Url = "http://i.imgur.com/dble6vf.png",
  288.                                 },
  289.                             PanelSettings = new Dictionary<string,object>
  290.                             {
  291.                                 { "InactiveColor", "1 1 1 0.1" },
  292.                                 { "ActiveColor", "0 1 0 1" },
  293.                             }
  294.                         }
  295.                     },
  296.                     { "HelicopterEvent", new PanelConfig
  297.                         {
  298.                             Available = true,
  299.                             Dock = "BottomDock",
  300.                             Order = 5,
  301.                             AnchorX = "Left",
  302.                             AnchorY = "Bottom",
  303.                             Margin = "0 0 0 0.0005",
  304.                             Width = 0.020f,
  305.                             Height = 0.95f,
  306.                             BackgroundColor = "0 0 0 0.4",
  307.                             Image = new PanelImageConfig
  308.                             {
  309.                                 Order =  1,
  310.                                 Width = 0.75f,
  311.                                 Height = 0.8f,
  312.                                 Margin = "0 0.15 0.1 0.1",
  313.                                 Url = "http://i.imgur.com/hTTyTTx.png",
  314.                             },
  315.                             PanelSettings = new Dictionary<string,object>
  316.                             {
  317.                                 { "InactiveColor", "1 1 1 0.1" },
  318.                                 { "ActiveColor", "0.7 0.2 0.2 1" },
  319.                             }
  320.  
  321.                         }
  322.                     },
  323.                     { "Radiation", new PanelConfig
  324.                         {
  325.                             Available = true,
  326.                             Dock = "BottomDock",
  327.                             Order = 6,
  328.                             AnchorX = "Left",
  329.                             AnchorY = "Bottom",
  330.                             Margin = "0 0 0 0.0005",
  331.                             Width = 0.020f,
  332.                             Height = 0.95f,
  333.                             BackgroundColor = "0 0 0 0.4",
  334.                             Image = new PanelImageConfig
  335.                             {
  336.                                 Order =  1,
  337.                                 Width = 0.75f,
  338.                                 Height = 0.8f,
  339.                                 Margin = "0 0.15 0.1 0.1",
  340.                                 Url = "http://i.imgur.com/owVdFsK.png",
  341.                             },
  342.                             PanelSettings = new Dictionary<string,object>
  343.                             {
  344.                                 { "InactiveColor", "1 1 1 0.1" },
  345.                                 { "ActiveColor", "1 1 0 1" },
  346.                                 { "RefreshRate(s)", "3"}
  347.                             }
  348.  
  349.                         }
  350.                     }
  351.                 }
  352.             };
  353.  
  354.             return DefaultConfig;
  355.         }
  356.  
  357.         class PluginConfig
  358.         {
  359.             //public Dictionary<string, string> Settings { get; set; }
  360.  
  361.             public Dictionary<string, DockConfig> Docks { get; set; }
  362.             public Dictionary<string, PanelConfig> Panels { get; set; }
  363.  
  364.             public Dictionary<string, Dictionary<string, PanelConfig>> ThirdPartyPanels { get; set; }
  365.  
  366.             public List<string> Messages { get; set; }
  367.             public List<string> TimeFormats { get; set; }
  368.             public Dictionary<string, string> CompassDirections { get; set; }
  369.  
  370.             public T GetPanelSettingsValue<T>(string Panel, string Setting, T defaultValue)
  371.             {
  372.                 PanelConfig panelConfig;
  373.                 if (!Panels.TryGetValue(Panel, out panelConfig))
  374.                     return defaultValue;
  375.  
  376.                 if (panelConfig.PanelSettings == null)
  377.                     return defaultValue;
  378.  
  379.                 object value;
  380.                 if (!panelConfig.PanelSettings.TryGetValue(Setting, out value))
  381.                     return defaultValue;
  382.  
  383.                 return (T)Convert.ChangeType(value, typeof(T));
  384.             }
  385.  
  386.             public bool CheckPanelAvailability(string Panel)
  387.             {
  388.                 PanelConfig panelConfig;
  389.                 if (!Panels.TryGetValue(Panel, out panelConfig))
  390.                     return false;
  391.  
  392.                 if (!panelConfig.Available)
  393.                     return false;
  394.  
  395.                 DockConfig dockConfig;
  396.                 return Docks.TryGetValue(panelConfig.Dock, out dockConfig) && dockConfig.Available;
  397.             }
  398.  
  399.         }
  400.  
  401.         class DockConfig
  402.         {
  403.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  404.             public bool Available { get; set; } = true;
  405.  
  406.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  407.             public string AnchorX { get; set; } = "Left";
  408.  
  409.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  410.             public string AnchorY { get; set; } = "Bottom";
  411.  
  412.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  413.             public float Width { get; set; } = 0.05f;
  414.  
  415.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  416.             public float Height { get; set; } = 0.95f;
  417.  
  418.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  419.             public string BackgroundColor { get; set; } = "0 0 0 0.4";
  420.  
  421.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  422.             public string Margin { get; set; } = "0 0 0 0.005";
  423.  
  424.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  425.             public PanelImageConfig Image { get; set; }
  426.         }
  427.  
  428.         class BasePanelConfig
  429.         {
  430.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  431.             public bool Available { get; set; } = true;
  432.  
  433.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  434.             public string AnchorX { get; set; } = "Left";
  435.  
  436.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  437.             public string AnchorY { get; set; } = "Bottom";
  438.  
  439.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  440.             public float Width { get; set; } = 0.05f;
  441.  
  442.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  443.             public float Height { get; set; } = 0.95f;
  444.  
  445.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  446.             public int Order { get; set; }
  447.  
  448.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  449.             public string BackgroundColor { get; set; } = "0 0 0 0.4";
  450.  
  451.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  452.             public string Margin { get; set; } = "0 0 0 0.005";
  453.         }
  454.  
  455.         class PanelConfig : BasePanelConfig
  456.         {
  457.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  458.             public bool Autoload { get; set; } = true;
  459.  
  460.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  461.             public string Dock { get; set; } = "BottomDock";
  462.  
  463.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  464.             public Dictionary<string, object> PanelSettings { get; set; }
  465.  
  466.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  467.             public PanelImageConfig Image { get; set; }
  468.  
  469.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  470.             public PanelTextConfig Text { get; set; }
  471.  
  472.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  473.             public float FadeOut { get; set; }
  474.         }
  475.  
  476.         class PanelTextConfig : BasePanelConfig
  477.         {
  478.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  479.             public new float Width { get; set; } = 1f;
  480.  
  481.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  482.             public TextAnchor Align { get; set; } = TextAnchor.MiddleCenter;
  483.  
  484.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  485.             public string FontColor { get; set; } = "1 1 1 1";
  486.  
  487.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  488.             public int FontSize { get; set; } = 14;
  489.  
  490.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  491.             public string Content { get; set; } = "No Content";
  492.  
  493.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  494.             public float FadeIn { get; set; }
  495.  
  496.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  497.             public float FadeOut { get; set; }
  498.         }
  499.  
  500.         class PanelImageConfig : BasePanelConfig
  501.         {
  502.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  503.             public new float Width { get; set; } = 1f;
  504.  
  505.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  506.             public string Url { get; set; }
  507.  
  508.             [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  509.             public string Color { get; set; } = null;
  510.         }
  511.  
  512.         protected void LoadConfigValues()
  513.         {
  514.             Settings = Config.ReadObject<PluginConfig>();
  515.  
  516.             var UnOrderPanels = Settings.Panels.Where(p => p.Value.Order == 0).ToDictionary(s => s.Key, s => s.Value);
  517.  
  518.             if (UnOrderPanels.Count == 0)
  519.             {
  520.                 return;
  521.             }
  522.  
  523.             PrintWarning("Reordering Panels.");
  524.  
  525.             foreach (var PanelCfg in UnOrderPanels)
  526.             {
  527.                 //int HighestSiblingOrder = Settings.Panels.Where(p => p.Value.Dock == Settings.Panels[PanelName].Dock && p.Value.AnchorX == Settings.Panels[PanelName].AnchorX).Max(m => m.Value.Order);
  528.                 Settings.Panels[PanelCfg.Key].Order = PanelReOrder(PanelCfg.Value.Dock, PanelCfg.Value.AnchorX);
  529.             }
  530.  
  531.             Config.WriteObject(Settings, true);
  532.             PrintWarning("Config Saved.");
  533.         }
  534.  
  535.         int PanelReOrder(string DockName, string AnchorX)
  536.         {
  537.             var SiblingPanels = Settings.Panels.Where(p => p.Value.Dock == DockName && p.Value.AnchorX == AnchorX);
  538.  
  539.             var Max = 0;
  540.             if (SiblingPanels.Any())
  541.             {
  542.                 Max = SiblingPanels.Max(m => m.Value.Order);
  543.             }
  544.  
  545.             foreach (var pPanelCfg in Settings.ThirdPartyPanels)
  546.             {
  547.                 if (pPanelCfg.Value.Count == 0) { continue; }
  548.  
  549.                 var SiblingPluginPAnels = pPanelCfg.Value.Where(p => p.Value.Dock == DockName && p.Value.AnchorX == AnchorX);
  550.  
  551.                 if (SiblingPluginPAnels.Any())
  552.                 {
  553.                     var PluginMax = pPanelCfg.Value.Where(p => p.Value.Dock == DockName && p.Value.AnchorX == AnchorX).Max(m => m.Value.Order);
  554.                     if (PluginMax > Max)
  555.                     {
  556.                         Max = PluginMax;
  557.                     }
  558.                 }
  559.             }
  560.             return Max + 1;
  561.         }
  562.  
  563.         #endregion
  564.  
  565.         #region Hooks
  566.  
  567.         protected override void LoadDefaultConfig()
  568.         {
  569.             Config.Clear();
  570.             Config.WriteObject(DefaultConfig(), true);
  571.             PrintWarning("Default configuration file created.");
  572.         }
  573.  
  574.         void Init()
  575.         {
  576.             LoadConfigValues();
  577.             LoadData();
  578.         }
  579.  
  580.         void OnServerInitialized()
  581.         {
  582.             Clock = new Watch
  583.             (
  584.                 Settings.GetPanelSettingsValue("Clock", "ClockUpdateFrequency (seconds)", ClockUpdateFrequency),
  585.                 Settings.CheckPanelAvailability("Clock")
  586.             );
  587.  
  588.             MessageBox = new Messenger
  589.             (
  590.                 Settings.Messages,
  591.                 Settings.GetPanelSettingsValue("MessageBox", "MessageUpdateFrequency (seconds)", MessageUpdateFrequency),
  592.                 Settings.GetPanelSettingsValue("MessageBox", "MsgOrder", "normal")
  593.             );
  594.  
  595.             Airplane = new AirplaneEvent();
  596.             Helicopter = new HelicopterEvent();
  597.  
  598.             CompassObj = new Compass
  599.             (
  600.                 Settings.GetPanelSettingsValue("Compass", "RefreshRate(s)", 1)
  601.             );
  602.  
  603.             Rad = new Radiation
  604.             (
  605.                 Settings.GetPanelSettingsValue("Radiation", "RefreshRate(s)", 3)
  606.             );
  607.  
  608.             Coord = new Coordinates
  609.             (
  610.                 Settings.GetPanelSettingsValue("Coordinates", "RefreshRate(s)", 3)
  611.             );
  612.  
  613.             foreach (var player in BasePlayer.activePlayerList)
  614.             {
  615.                 LoadPanels(player);
  616.                 InitializeGUI(player);
  617.             }
  618.  
  619.             if (Settings.CheckPanelAvailability("Radiation"))
  620.             {
  621.                 RadiationUpdater = timer.Repeat(Rad.RefreshRate, 0, () => Rad.Refresh(storedData, PlayerPanels));
  622.             }
  623.  
  624.             if (Settings.CheckPanelAvailability("Coordinates"))
  625.             {
  626.                 CoordUpdater = timer.Repeat(Coord.RefreshRate, 0, () => Coord.Refresh(storedData, PlayerPanels));
  627.             }
  628.  
  629.             if (Settings.CheckPanelAvailability("MessageBox"))
  630.             {
  631.                 MsgUpdater = timer.Repeat(MessageBox.RefreshRate, 0, () => MessageBox.Refresh(storedData, PlayerPanels));
  632.             }
  633.  
  634.             if (Settings.CheckPanelAvailability("Clock"))
  635.             {
  636.                 TimeUpdater = timer.Repeat(Clock.RefresRate, 0, () => Clock.Refresh(storedData, PlayerPanels));
  637.             }
  638.  
  639.             if (Settings.CheckPanelAvailability("Compass"))
  640.             {
  641.                 CompassUpdater = timer.Repeat(CompassObj.RefreshRate, 0, () => CompassObj.Refresh(storedData, PlayerPanels));
  642.             }
  643.  
  644.             //TestTimer = timer.Repeat(5, 0, () => TestSH());
  645.  
  646.             ActivePlanes = UnityEngine.Object.FindObjectsOfType<CargoPlane>().ToList();
  647.  
  648.             if (ActivePlanes.Count > 0)
  649.             {
  650.                 CheckAirplane();
  651.             }
  652.             else
  653.             {
  654.                 Airplane.Refresh(storedData, PlayerPanels);
  655.             }
  656.  
  657.             ActiveHelicopters = UnityEngine.Object.FindObjectsOfType<BaseHelicopter>().ToList();
  658.  
  659.             if (ActiveHelicopters.Count > 0)
  660.             {
  661.                 CheckHelicopter();
  662.             }
  663.             else
  664.             {
  665.                 Helicopter.Refresh(storedData, PlayerPanels);
  666.             }
  667.         }
  668.  
  669.         void OnPlayerInit(BasePlayer player)
  670.         {
  671.             if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
  672.             {
  673.                 timer.Once(2, () => OnPlayerInit(player));
  674.                 return;
  675.             }
  676.             //Ha player connection alatt kickelve volt akkor nem hat rá az onDisconnect, ezért itt is ellenőrizni kell....
  677.             if (PlayerPanels.ContainsKey(player.UserIDString))
  678.             {
  679.                 PlayerPanels.Remove(player.UserIDString);
  680.             }
  681.  
  682.             if (PlayerDockPanels.ContainsKey(player.UserIDString))
  683.             {
  684.                 PlayerDockPanels.Remove(player.UserIDString);
  685.             }
  686.  
  687.             timer.In(1, () => GUITimerInit(player));
  688.         }
  689.  
  690.         void OnPlayerDisconnected(BasePlayer player)
  691.         {
  692.             PlayerPanels.Remove(player.UserIDString);
  693.             PlayerDockPanels.Remove(player.UserIDString);
  694.  
  695.             timer.Once(2, RefreshOnlinePlayers);
  696.             timer.Once(2, RefreshSleepers);
  697.         }
  698.  
  699.         void OnPlayerSleepEnded(BasePlayer player)
  700.         {
  701.             timer.Once(2, RefreshSleepers);
  702.         }
  703.  
  704.         private void OnEntitySpawned(BaseEntity Entity)
  705.         {
  706.             if (Entity == null) return;
  707.             if (Entity is BaseHelicopter && Settings.Panels["HelicopterEvent"].Available)
  708.             {
  709.                 ActiveHelicopters.Add((BaseHelicopter) Entity);
  710.  
  711.                 if (HelicopterTimer == false)
  712.                 {
  713.                     CheckHelicopter();
  714.                 }
  715.             }
  716.  
  717.  
  718.             if (Entity is CargoPlane && Settings.Panels["AirdropEvent"].Available)
  719.             {
  720.                 ActivePlanes.Add((CargoPlane) Entity);
  721.  
  722.                 if (AirplaneTimer == false)
  723.                 {
  724.                     CheckAirplane();
  725.                 }
  726.             }
  727.         }
  728.  
  729.         private void Unload()
  730.         {
  731.             foreach (var player in BasePlayer.activePlayerList)
  732.                 DestroyGUI(player);
  733.  
  734.             SaveData();
  735.  
  736.             PlayerPanels.Clear();
  737.             PlayerDockPanels.Clear();
  738.  
  739.             Err.Clear();
  740.             ErrD.Clear();
  741.             ErrB.Clear();
  742.             ErrA.Clear();
  743.  
  744.             storedData = null;
  745.             Settings = null;
  746.         }
  747.  
  748.         void OnPluginUnloaded(Plugin plugin)
  749.         {
  750.             if (!Settings.ThirdPartyPanels.ContainsKey(plugin.Title)) return;
  751.             var PluginPanels = LoadedPluginPanels[plugin.Title];
  752.  
  753.             foreach(var PanelName in PluginPanels)
  754.             {
  755.                 foreach (var pair in PlayerPanels)
  756.                 {
  757.                     if(pair.Value.ContainsKey(PanelName))
  758.                     {
  759.                         pair.Value[PanelName].DestroyPanel();
  760.                     }
  761.  
  762.                     pair.Value[PanelName].Remover();
  763.                 }
  764.             }
  765.  
  766.             LoadedPluginPanels.Remove(plugin.Title);
  767.         }
  768.  
  769.         void OnServerSave()
  770.         {
  771.             SaveData();
  772.         }
  773.  
  774.         void OnServerShutdown()
  775.         {
  776.             SaveData();
  777.         }
  778.  
  779.         #endregion
  780.  
  781.         #region PanelLoad
  782.         /// <summary>
  783.         /// Panelek betöltése egy adott játékosnak.
  784.         /// </summary>
  785.         /// <param name="Player"></param>
  786.         private void LoadPanels(BasePlayer Player)
  787.         {
  788.             foreach(var Docks in Settings.Docks)
  789.             {
  790.                 if (!Settings.Docks[Docks.Key].Available)
  791.                     continue;
  792.                 LoadDockPanel(Docks.Key, Player);
  793.             }
  794.  
  795.             var playerDockPanel = PlayerDockPanels[Player.UserIDString];
  796.             foreach (var grouppedByDock in Settings.Panels.GroupBy(g => g.Value.Dock).ToDictionary(gd => gd.Key, gd => gd.Select(p => p).ToDictionary(gk => gk.Key, gk => gk.Value)))
  797.             {
  798.                 if (!Settings.Docks[grouppedByDock.Key].Available)
  799.                     continue;
  800.  
  801.                 foreach (var panelCfg in grouppedByDock.Value)
  802.                 {
  803.                     if (!Settings.CheckPanelAvailability(panelCfg.Key))
  804.                         continue;
  805.  
  806.                     LoadPanel(playerDockPanel[grouppedByDock.Key], panelCfg.Key, panelCfg.Value);
  807.                 }
  808.             }
  809.  
  810.             foreach(var loadedPluginPanel in LoadedPluginPanels)
  811.             {
  812.                 foreach(var panelName in loadedPluginPanel.Value)
  813.                 {
  814.                     Dictionary<string, PanelConfig> panelConfigs;
  815.                     PanelConfig panelConfig;
  816.                     if (!Settings.ThirdPartyPanels.TryGetValue(loadedPluginPanel.Key, out panelConfigs)
  817.                         || !panelConfigs.TryGetValue(panelName, out panelConfig)
  818.                         || !panelConfig.Available)
  819.                         continue;
  820.  
  821.                     LoadPanel(playerDockPanel[panelConfig.Dock], panelName, panelConfig);
  822.                 }
  823.             }
  824.         }
  825.  
  826.         private IPanel LoadDockPanel(string DockName, BasePlayer Player)
  827.         {
  828.             var DockPanel = new IPanel(DockName, Player, PlayerPanels, PlayerDockPanels);
  829.             var dockConfig = Settings.Docks[DockName];
  830.             DockPanel.Width = dockConfig.Width;
  831.             DockPanel.Height = dockConfig.Height;
  832.             DockPanel.AnchorX = dockConfig.AnchorX;
  833.             DockPanel.AnchorY = dockConfig.AnchorY;
  834.             DockPanel.Margin = Vector4Parser(dockConfig.Margin);
  835.             DockPanel.BackgroundColor = ColorEx.Parse(dockConfig.BackgroundColor);
  836.             DockPanel.IsDock = true;
  837.  
  838.             //LoadedDocks.Add(DockName, DockPanel);
  839.  
  840.             Dictionary<string, IPanel> panels;
  841.             if(!PlayerDockPanels.TryGetValue(Player.UserIDString, out panels))
  842.                 PlayerDockPanels.Add(Player.UserIDString, panels = new Dictionary<string, IPanel>());
  843.             panels.Add(DockName, DockPanel);
  844.  
  845.             return DockPanel;
  846.         }
  847.  
  848.         private void LoadPanel(IPanel Dock, string PanelName, PanelConfig PCfg)
  849.         {
  850.             var Panel = Dock.AddPanel(PanelName);
  851.             Panel.Width = PCfg.Width;
  852.             Panel.Height = PCfg.Height;
  853.             Panel.AnchorX = PCfg.AnchorX;
  854.             Panel.AnchorY = PCfg.AnchorY;
  855.             Panel.Margin = Vector4Parser(PCfg.Margin);
  856.             Panel.BackgroundColor = ColorEx.Parse(PCfg.BackgroundColor);
  857.             Panel.Order = PCfg.Order;
  858.             Panel.Autoload = PCfg.Autoload;
  859.             Panel.IsPanel = true;
  860.             Panel.DockName = Dock.Name;
  861.             Panel.FadeOut = Dock.FadeOut;
  862.  
  863.             if (PCfg.Text != null)
  864.             {
  865.                 var Text = Panel.AddText(PanelName + "Text");
  866.                 Text.Width = PCfg.Text.Width;
  867.                 Text.Height = PCfg.Text.Height;
  868.                 Text.Margin = Vector4Parser(PCfg.Text.Margin);
  869.                 Text.Content = PCfg.Text.Content;
  870.                 Text.FontColor = ColorEx.Parse(PCfg.Text.FontColor);
  871.                 Text.FontSize = PCfg.Text.FontSize;
  872.                 Text.Align = PCfg.Text.Align;
  873.                 Text.Order = PCfg.Text.Order;
  874.                 Text.FadeOut = PCfg.Text.FadeOut;
  875.                 Text.TextComponent.FadeIn = PCfg.Text.FadeIn;
  876.             }
  877.  
  878.             if (PCfg.Image != null)
  879.             {
  880.                 var Image = Panel.AddImage(PanelName + "Image");
  881.                 Image.Width = PCfg.Image.Width;
  882.                 Image.Height = PCfg.Image.Height;
  883.                 Image.Margin = Vector4Parser(PCfg.Image.Margin);
  884.                 Image.Url = PCfg.Image.Url;
  885.                 Image.Order = PCfg.Image.Order;
  886.                 if (PCfg.Image.Color != null)
  887.                     Image.Color = ColorEx.Parse(PCfg.Image.Color);
  888.             }
  889.         }
  890.  
  891.         #endregion
  892.  
  893.         #region Clock
  894.  
  895.         private Watch Clock;
  896.         private int ClockUpdateFrequency = 4;
  897.         private Timer TimeUpdater;
  898.  
  899.         public class Watch
  900.         {
  901.             string ClockFormat = "HH:mm";
  902.             public int RefresRate = 4;
  903.             public bool Available = true;
  904.  
  905.             TOD_Sky Sky = TOD_Sky.Instance;
  906.  
  907.             public Watch(int RefreshRate, bool Available)
  908.             {
  909.                 RefresRate = RefreshRate;
  910.                 this.Available = Available;
  911.             }
  912.  
  913.             public string GetServerTime(string PlayerID, StoredData storedData)
  914.             {
  915.                 return DateTime.Now.AddHours(storedData.GetPlayerPanelSettings(PlayerID, "Clock", "Offset", 0)).ToString(storedData.GetPlayerPanelSettings(PlayerID, "Clock", "TimeFormat", ClockFormat), CultureInfo.InvariantCulture);
  916.             }
  917.  
  918.             public string GetSkyTime(string PlayerID, StoredData storedData)
  919.             {
  920.                 return Sky.Cycle.DateTime.ToString(storedData.GetPlayerPanelSettings(PlayerID, "Clock", "TimeFormat", ClockFormat), CultureInfo.InvariantCulture);
  921.             }
  922.  
  923.             public string ShowTime(string PlayerID, StoredData storedData)
  924.             {
  925.                 if (storedData.GetPlayerPanelSettings(PlayerID, "Clock", "Type", "Game") == "Server")
  926.                     return GetServerTime(PlayerID, storedData);
  927.  
  928.                 return GetSkyTime(PlayerID, storedData);
  929.             }
  930.  
  931.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  932.             {
  933.                 if (!Settings.CheckPanelAvailability("Clock"))
  934.                     return;
  935.  
  936.                 foreach (var panel in panels)
  937.                 {
  938.                     IPanel iPanel;
  939.                     if (!panel.Value.TryGetValue("ClockText", out iPanel)) continue;
  940.                     var showTime = ShowTime(panel.Key, storedData);
  941.                     var panelText = (IPanelText)iPanel;
  942.                     if (!showTime.Equals(panelText.Content))
  943.                     {
  944.                         panelText.Content = showTime;
  945.                         panelText.Refresh();
  946.                     }
  947.                 }
  948.             }
  949.         }
  950.  
  951.         #endregion
  952.  
  953.         #region MessageBox
  954.  
  955.         private Messenger MessageBox;
  956.         private Timer MsgUpdater;
  957.         private int MessageUpdateFrequency = 20;
  958.         private List<string> Messages = new List<string>() { "Welcome!", "Beware! You Are Not Alone!", "Leeeeeeeeeeeroy Jenkins" };
  959.         private bool MessageBoxAvailable = true;
  960.  
  961.  
  962.         public class Messenger
  963.         {
  964.             List<string> Messages;
  965.             public int RefreshRate = 20;
  966.             private int Counter = 0;
  967.             private string MsgOrder = "normal";
  968.  
  969.             public Messenger(List<string> msgs, int RefreshRate,string MsgOrder)
  970.             {
  971.                 Messages = msgs;
  972.                 this.RefreshRate = RefreshRate;
  973.                 this.MsgOrder = MsgOrder;
  974.  
  975.                 if (MsgOrder == "random")
  976.                 {
  977.                     Counter = Core.Random.Range(0, Messages.Count - 1);
  978.                 }
  979.  
  980.             }
  981.  
  982.             public string GetMessage()
  983.             {
  984.                 return Messages[Counter];
  985.             }
  986.  
  987.             private void RefreshCounter()
  988.             {
  989.                 if (MsgOrder == "random")
  990.                 {
  991.                     var OldCounter = Counter;
  992.                     var NewCounter = Core.Random.Range(0, Messages.Count - 1);
  993.  
  994.                     if(OldCounter == NewCounter)
  995.                     {
  996.                         if(NewCounter+1 <= Messages.Count-1)
  997.                         {
  998.                             Counter = NewCounter + 1;
  999.                             return;
  1000.                         }
  1001.                         else if(NewCounter - 1 >= 0)
  1002.                         {
  1003.                             Counter = NewCounter - 1;
  1004.                             return;
  1005.                         }
  1006.                     }
  1007.  
  1008.                     Counter = NewCounter;
  1009.                     return;
  1010.                 }
  1011.  
  1012.                 Counter++;
  1013.                 if (Counter >= Messages.Count)
  1014.                     Counter = 0;
  1015.             }
  1016.  
  1017.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  1018.             {
  1019.                 if (!Settings.CheckPanelAvailability("MessageBox"))
  1020.                     return;
  1021.  
  1022.                 foreach (var panel in panels)
  1023.                 {
  1024.                     IPanel iPanel;
  1025.                     if (!panel.Value.TryGetValue("MessageBoxText", out iPanel)) continue;
  1026.                     var message = GetMessage();
  1027.                     var panelText = (IPanelText)iPanel;
  1028.                     if (!message.Equals(panelText.Content))
  1029.                     {
  1030.                         panelText.Content = message;
  1031.                         panelText.Refresh();
  1032.                     }
  1033.                 }
  1034.  
  1035.                 RefreshCounter();
  1036.             }
  1037.  
  1038.         }
  1039.         #endregion
  1040.  
  1041.         #region Events
  1042.         private Timer HeliAttack;
  1043.         private Timer RadiationUpdater;
  1044.  
  1045.         private AirplaneEvent Airplane;
  1046.         private List<CargoPlane> ActivePlanes;
  1047.         private bool AirplaneTimer = false;
  1048.  
  1049.         private HelicopterEvent Helicopter;
  1050.         private List<BaseHelicopter> ActiveHelicopters;
  1051.         private bool HelicopterTimer = false;
  1052.  
  1053.         private Radiation Rad;
  1054.  
  1055.         private BaseHelicopter ActiveHelicopter;
  1056.  
  1057.         public class AirplaneEvent
  1058.         {
  1059.             public bool isActive = false;
  1060.             public Color ImageColor;
  1061.  
  1062.             public AirplaneEvent()
  1063.             {
  1064.                 ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("AirdropEvent", "InactiveColor", "1 1 1 0.1"));
  1065.             }
  1066.  
  1067.             public void SetActivity(bool active)
  1068.             {
  1069.                 isActive = active;
  1070.  
  1071.                 if (isActive)
  1072.                 {
  1073.                     ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("AirdropEvent", "ActiveColor", "0 1 0 1"));
  1074.                     return;
  1075.                 }
  1076.                 ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("AirdropEvent", "InactiveColor", "1 1 1 0.1"));
  1077.                 return;
  1078.             }
  1079.  
  1080.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  1081.             {
  1082.                 if (!Settings.CheckPanelAvailability("AirdropEvent"))
  1083.                     return;
  1084.  
  1085.                 foreach (var panel in panels)
  1086.                 {
  1087.                     IPanel iPanel;
  1088.                     if (!panel.Value.TryGetValue("AirdropEventImage", out iPanel)) continue;
  1089.                     var panelRawImage = (IPanelRawImage)iPanel;
  1090.                     if (panelRawImage.Color != ImageColor)
  1091.                     {
  1092.                         panelRawImage.Color = ImageColor;
  1093.                         panelRawImage.Refresh();
  1094.                     }
  1095.                 }
  1096.             }
  1097.         }
  1098.  
  1099.         public class HelicopterEvent
  1100.         {
  1101.             public bool isActive = false;
  1102.             public Color ImageColor;
  1103.  
  1104.             public HelicopterEvent()
  1105.             {
  1106.                 ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("HelicopterEvent", "InactiveColor", "1 1 1 0.1"));
  1107.             }
  1108.  
  1109.             public void SetActivity(bool active)
  1110.             {
  1111.                 isActive = active;
  1112.  
  1113.                 if (isActive)
  1114.                 {
  1115.                     ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("HelicopterEvent", "ActiveColor", "1 0 0 1"));
  1116.                     return;
  1117.                 }
  1118.  
  1119.                 ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("HelicopterEvent", "InactiveColor", "1 1 1 0.1"));
  1120.             }
  1121.  
  1122.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  1123.             {
  1124.                 if (!Settings.CheckPanelAvailability("HelicopterEvent"))
  1125.                     return;
  1126.  
  1127.                 foreach (var panel in panels)
  1128.                 {
  1129.                     IPanel iPanel;
  1130.                     if (!panel.Value.TryGetValue("HelicopterEventImage", out iPanel)) continue;
  1131.                     var panelRawImage = (IPanelRawImage)iPanel;
  1132.                     if (panelRawImage.Color != ImageColor)
  1133.                     {
  1134.                         panelRawImage.Color = ImageColor;
  1135.                         panelRawImage.Refresh();
  1136.                     }
  1137.                 }
  1138.             }
  1139.         }
  1140.  
  1141.         public class Radiation
  1142.         {
  1143.             bool isActive = false;
  1144.             public Color ImageColor;
  1145.             public int RefreshRate = 3;
  1146.  
  1147.             public Radiation(int RefreshRate)
  1148.             {
  1149.                 isActive = ConVar.Server.radiation;
  1150.                 this.RefreshRate = RefreshRate;
  1151.                 if (isActive)
  1152.                 {
  1153.                     ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("Radiation", "ActiveColor", "1 1 0 1"));
  1154.                 }
  1155.                 else
  1156.                 {
  1157.                     ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("Radiation", "InactiveColor", "1 1 1 0.1"));
  1158.                 }
  1159.             }
  1160.  
  1161.             public void SetActivity(bool active)
  1162.             {
  1163.                 isActive = active;
  1164.  
  1165.                 if (isActive)
  1166.                 {
  1167.                     ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("Radiation", "ActiveColor", "1 0 0 1"));
  1168.                     return;
  1169.                 }
  1170.  
  1171.                 ImageColor = ColorEx.Parse(Settings.GetPanelSettingsValue("Radiation", "InactiveColor", "1 1 1 0.1"));
  1172.             }
  1173.  
  1174.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  1175.             {
  1176.                 if (isActive == ConVar.Server.radiation)
  1177.                     return;
  1178.  
  1179.                 SetActivity(ConVar.Server.radiation);
  1180.  
  1181.                 if (!Settings.CheckPanelAvailability("Radiation"))
  1182.                     return;
  1183.  
  1184.                 foreach (var panel in panels)
  1185.                 {
  1186.                     IPanel iPanel;
  1187.                     if (!panel.Value.TryGetValue("RadiationImage", out iPanel)) continue;
  1188.                     var panelRawImage = (IPanelRawImage)iPanel;
  1189.                     if (panelRawImage.Color != ImageColor)
  1190.                     {
  1191.                         panelRawImage.Color = ImageColor;
  1192.                         panelRawImage.Refresh();
  1193.                     }
  1194.                 }
  1195.             }
  1196.         }
  1197.  
  1198.         public void CheckAirplane()
  1199.         {
  1200.             ActivePlanes.RemoveAll(p => !p.IsValid() || !p.gameObject.activeInHierarchy);
  1201.             if (ActivePlanes.Count > 0)
  1202.             {
  1203.                 if(Airplane.isActive == false)
  1204.                 {
  1205.                     Airplane.SetActivity(true);
  1206.                     Airplane.Refresh(storedData, PlayerPanels);
  1207.                 }
  1208.  
  1209.                 AirplaneTimer = true;
  1210.                 timer.In(10, CheckAirplane);
  1211.                 return;
  1212.             }
  1213.  
  1214.             Airplane.SetActivity(false);
  1215.             Airplane.Refresh(storedData, PlayerPanels);
  1216.             AirplaneTimer = false;
  1217.         }
  1218.  
  1219.         public void CheckHelicopter()
  1220.         {
  1221.             ActiveHelicopters.RemoveAll(p => !p.IsValid() || !p.gameObject.activeInHierarchy);
  1222.  
  1223.             if (ActiveHelicopters.Count > 0)
  1224.             {
  1225.  
  1226.                 if (Helicopter.isActive == false)
  1227.                 {
  1228.                     Helicopter.SetActivity(true);
  1229.                     Helicopter.Refresh(storedData, PlayerPanels);
  1230.                 }
  1231.  
  1232.                 HelicopterTimer = true;
  1233.                 timer.In(5, CheckHelicopter);
  1234.                 return;
  1235.             }
  1236.  
  1237.             Helicopter.SetActivity(false);
  1238.             Helicopter.Refresh(storedData, PlayerPanels);
  1239.             HelicopterTimer = false;
  1240.         }
  1241.  
  1242.         #endregion
  1243.  
  1244.         #region Coordinates
  1245.  
  1246.         private Coordinates Coord;
  1247.  
  1248.         private Timer CoordUpdater;
  1249.  
  1250.         public class Coordinates
  1251.         {
  1252.             public int RefreshRate = 3;
  1253.  
  1254.             public Coordinates(int RefreshRate)
  1255.             {
  1256.                 this.RefreshRate = RefreshRate;
  1257.             }
  1258.  
  1259.             public string GetCoord(string PlayerID)
  1260.             {
  1261.                 var player = BasePlayer.activePlayerList.FirstOrDefault(p => p.UserIDString == PlayerID);
  1262.                 return $"X: {player.transform.position.x.ToString("0")} | Z: {player.transform.position.z.ToString("0")}";
  1263.             }
  1264.  
  1265.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  1266.             {
  1267.                 if (!Settings.CheckPanelAvailability("Coordinates"))
  1268.                     return;
  1269.  
  1270.                 foreach (var panel in panels)
  1271.                 {
  1272.                     IPanel iPanel;
  1273.                     if (!panel.Value.TryGetValue("CoordinatesText", out iPanel)) continue;
  1274.                     var coord = GetCoord(panel.Key);
  1275.                     var panelText = (IPanelText)iPanel;
  1276.                     if (!coord.Equals(panelText.Content))
  1277.                     {
  1278.                         panelText.Content = coord;
  1279.                         panelText.Refresh();
  1280.                     }
  1281.                 }
  1282.             }
  1283.         }
  1284.         #endregion
  1285.  
  1286.         #region Compass
  1287.  
  1288.         private Compass CompassObj;
  1289.  
  1290.         private Timer CompassUpdater;
  1291.  
  1292.         public class Compass
  1293.         {
  1294.             public int RefreshRate = 3;
  1295.  
  1296.             public Compass(int RefreshRate)
  1297.             {
  1298.                 this.RefreshRate = RefreshRate;
  1299.             }
  1300.  
  1301.             public string GetDirection(string PlayerID)
  1302.             {
  1303.                 var player = BasePlayer.activePlayerList.FirstOrDefault(p => p.UserIDString == PlayerID);
  1304.  
  1305.                 var PCurrent = player.eyes.rotation.eulerAngles;
  1306.  
  1307.                 string str = $"{PCurrent.y.ToString("0")}°";
  1308.  
  1309.                 if (Settings.GetPanelSettingsValue("Compass", "TextOrAngle", "text") == "text")
  1310.                 {
  1311.                     if (PCurrent.y > 337.5 || PCurrent.y < 22.5)
  1312.                         str = Settings.CompassDirections["n"];
  1313.                     else if (PCurrent.y > 22.5 && PCurrent.y < 67.5)
  1314.                         str = Settings.CompassDirections["ne"];
  1315.                     else if (PCurrent.y > 67.5 && PCurrent.y < 112.5)
  1316.                         str = Settings.CompassDirections["e"];
  1317.                     else if (PCurrent.y > 112.5 && PCurrent.y < 157.5)
  1318.                         str = Settings.CompassDirections["se"];
  1319.                     else if (PCurrent.y > 157.5 && PCurrent.y < 202.5)
  1320.                         str = Settings.CompassDirections["s"];
  1321.                     else if (PCurrent.y > 202.5 && PCurrent.y < 247.5)
  1322.                         str = Settings.CompassDirections["sw"];
  1323.                     else if (PCurrent.y > 247.5 && PCurrent.y < 292.5)
  1324.                         str = Settings.CompassDirections["w"];
  1325.                     else if (PCurrent.y > 292.5 && PCurrent.y < 337.5)
  1326.                         str = Settings.CompassDirections["nw"];
  1327.                 }
  1328.  
  1329.                 return str;
  1330.             }
  1331.  
  1332.             public void Refresh(StoredData storedData, Dictionary<string, Dictionary<string, IPanel>> panels)
  1333.             {
  1334.                 if (!Settings.CheckPanelAvailability("Compass"))
  1335.                 {
  1336.                     return;
  1337.                 }
  1338.  
  1339.                 foreach (var panel in panels)
  1340.                 {
  1341.                     if (panel.Value.ContainsKey("CompassText"))
  1342.                     {
  1343.                         var direction = GetDirection(panel.Key);
  1344.                         var panelText = (IPanelText)panel.Value["CompassText"];
  1345.                         if (!direction.Equals(panelText.Content))
  1346.                         {
  1347.                             panelText.Content = direction;
  1348.                             panelText.Refresh();
  1349.                         }
  1350.                     }
  1351.                 }
  1352.             }
  1353.         }
  1354.  
  1355.         #endregion
  1356.  
  1357.         #region Commands
  1358.  
  1359.         [ChatCommand("ipanel")]
  1360.         private void IPanelCommand(BasePlayer player, string command, string[] args)
  1361.         {
  1362.             if (args.Length == 0)
  1363.             {
  1364.                 var Str = "InfoPanel Available Commands:\n";
  1365.                 Str += "<b><color=#ffa500ff>/ipanel</color></b> - Chat Command list \n";
  1366.                 Str += "<b><color=#ffa500ff>/ipanel <hide|show></color></b>- To hide or show the panel. \n";
  1367.                 Str += "<b><color=#ffa500ff>/ipanel clock game</color></b> - Change to game time. \n";
  1368.                 Str += "<b><color=#ffa500ff>/ipanel clock server <offset></color></b> - Change to server time.\n Offset: Add hours to the clock. (-23 - 23) \n";
  1369.                 Str += "<b><color=#ffa500ff>/ipanel timeformat</color></b> - To change time format. \n";
  1370.  
  1371.                 PrintToChat(player, Str);
  1372.  
  1373.                 return;
  1374.             }
  1375.  
  1376.             switch (args[0])
  1377.             {
  1378.                 case "hide":
  1379.                     if (!storedData.GetPlayerSettings(player.UserIDString, "enable", true))
  1380.                     {
  1381.                         break;
  1382.                     }
  1383.  
  1384.                     ChangePlayerSettings(player, "enable", "false");
  1385.                     DestroyGUI(player);
  1386.                     break;
  1387.                 case "show":
  1388.                     if (storedData.GetPlayerSettings(player.UserIDString, "enable", true))
  1389.                     {
  1390.                         break;
  1391.                     }
  1392.  
  1393.                     ChangePlayerSettings(player, "enable", "true");
  1394.                     RevealGUI(player);
  1395.                     break;
  1396.  
  1397.                 case "clock":
  1398.                     if (args[1] == "server")
  1399.                     {
  1400.                         ChangePlayerPanelSettings(player, "Clock", "Type", "Server");
  1401.  
  1402.                         if (args.Length == 3)
  1403.                         {
  1404.                             var offset = 0;
  1405.  
  1406.                             if (int.TryParse(args[2], out offset) && offset > -23 && offset < 23)
  1407.                             {
  1408.                                 ChangePlayerPanelSettings(player, "Clock", "Offset", offset.ToString());
  1409.                             }
  1410.                         }
  1411.  
  1412.                     }
  1413.                     else if (args[1] == "game")
  1414.                     {
  1415.                         ChangePlayerPanelSettings(player, "Clock", "Type", "Game");
  1416.                     }
  1417.                     break;
  1418.                 case "timeformat":
  1419.                     if (args.Length == 1)
  1420.                     {
  1421.                         var Str = "Available Time Formats:\n";
  1422.  
  1423.                         for (var index = 0; index < Settings.TimeFormats.Count; index++)
  1424.                         {
  1425.                             Str += $"[<color=#ffa500ff>{index}</color>] - {DateTime.Now.ToString(Settings.TimeFormats[index])}\n";
  1426.                         }
  1427.  
  1428.                         PrintToChat(player, Str+"Usage: /ipanel timeformat <color=#ffa500ff> NUMBER </color>");
  1429.                     }
  1430.                     else if(args.Length == 2)
  1431.                     {
  1432.                         var TimeFormat = 0;
  1433.                         if (int.TryParse(args[1], out TimeFormat) && TimeFormat >= 0 && TimeFormat < Settings.TimeFormats.Count)
  1434.                         {
  1435.                             ChangePlayerPanelSettings(player, "Clock", "TimeFormat", TimeFormats[TimeFormat]);
  1436.                         }
  1437.                     }
  1438.                     break;
  1439.                 default:
  1440.                     PrintToChat(player, "Wrong Command!");
  1441.                     break;
  1442.             };
  1443.  
  1444.         }
  1445.  
  1446.         [ChatCommand("iptest")]
  1447.         private void IPaCommand(BasePlayer player, string command, string[] args)
  1448.         {
  1449.  
  1450.         }
  1451.  
  1452.         [ChatCommand("iperr")]
  1453.         private void IPCommand(BasePlayer player, string command, string[] args)
  1454.         {
  1455.             /*
  1456.             foreach (string item in Err)
  1457.             {
  1458.                 Puts(item);
  1459.             }*/
  1460.  
  1461.             /*foreach (KeyValuePair<string,Dictionary<string,IPanel>> item in PlayerDockPanels)
  1462.             {
  1463.                 foreach (KeyValuePair<string, IPanel> itemm in item.Value)
  1464.                 {
  1465.                     Puts(itemm.Key);
  1466.                 }
  1467.             }*/
  1468.             /*
  1469.             foreach (KeyValuePair<string, int> item in ErrB.OrderBy(k => k.Key))
  1470.             {
  1471.                 Puts(item.Key + " - " + item.Value);
  1472.             }*/
  1473.            /*
  1474.             foreach (KeyValuePair<string, List<string>> item in ErrA)
  1475.             {
  1476.                 Puts(item.Key + " -> ");
  1477.  
  1478.                 foreach (string itemm in item.Value)
  1479.                 {
  1480.                     Puts(itemm);
  1481.                 }
  1482.  
  1483.                 Puts("--------");
  1484.             }*/
  1485.  
  1486.             Err.Clear();
  1487.             ErrA.Clear();
  1488.             ErrB.Clear();
  1489.         }
  1490.  
  1491.         #endregion
  1492.  
  1493.         #region StoredData
  1494.  
  1495.         public static StoredData storedData;
  1496.  
  1497.         public class StoredData
  1498.         {
  1499.             public Dictionary<string, PlayerSettings> Players;
  1500.  
  1501.             public StoredData()
  1502.             {
  1503.                 Players = new Dictionary<string, PlayerSettings>();
  1504.             }
  1505.  
  1506.             public bool CheckPlayerData(BasePlayer Player)
  1507.             {
  1508.                 return Players.ContainsKey(Player.UserIDString);
  1509.             }
  1510.  
  1511.             public T GetPlayerSettings<T>(string PlayerID, string Key, T DefaultValue)
  1512.             {
  1513.                 PlayerSettings playerSettings;
  1514.                 if (Players.TryGetValue(PlayerID, out playerSettings))
  1515.                     return playerSettings.GetSetting(Key, DefaultValue);
  1516.                 return DefaultValue;
  1517.             }
  1518.  
  1519.             public T GetPlayerPanelSettings<T>(BasePlayer Player, string Panel, string Key, T DefaultValue)
  1520.             {
  1521.                 PlayerSettings playerSettings;
  1522.                 if (Players.TryGetValue(Player.UserIDString, out playerSettings))
  1523.                     return playerSettings.GetPanelSetting(Panel, Key, DefaultValue);
  1524.                 return DefaultValue;
  1525.             }
  1526.  
  1527.             public T GetPlayerPanelSettings<T>(string PlayerID, string Panel, string Key, T DefaultValue)
  1528.             {
  1529.                 PlayerSettings playerSettings;
  1530.                 if (Players.TryGetValue(PlayerID, out playerSettings))
  1531.                     return playerSettings.GetPanelSetting(Panel, Key, DefaultValue);
  1532.                 return DefaultValue;
  1533.             }
  1534.  
  1535.         }
  1536.  
  1537.         public class PlayerSettings
  1538.         {
  1539.             public string UserId;
  1540.             public Dictionary<string, string> Settings;
  1541.             public Dictionary<string, Dictionary<string, string>> PanelSettings;
  1542.  
  1543.             public PlayerSettings()
  1544.             {
  1545.                 Settings = new Dictionary<string, string>();
  1546.                 PanelSettings = new Dictionary<string, Dictionary<string, string>>();
  1547.             }
  1548.  
  1549.             public PlayerSettings(BasePlayer player)
  1550.             {
  1551.                 UserId = player.UserIDString;
  1552.                 Settings = new Dictionary<string, string>();
  1553.                 PanelSettings = new Dictionary<string, Dictionary<string, string>>();
  1554.             }
  1555.  
  1556.             public void SetSetting(string Key, string Value)
  1557.             {
  1558.                 Settings[Key] = Value;
  1559.             }
  1560.  
  1561.             public void SetPanelSetting(string Panel, string Key, string Value)
  1562.             {
  1563.                 Dictionary<string, string> settings;
  1564.                 if (!PanelSettings.TryGetValue(Panel, out settings))
  1565.                     PanelSettings.Add(Panel, settings = new Dictionary<string, string>());
  1566.  
  1567.                 settings[Key] = Value;
  1568.             }
  1569.  
  1570.             public T GetPanelSetting<T>(string Panel, string Key, T DefaultValue)
  1571.             {
  1572.                 Dictionary<string, string> PanelConfig;
  1573.                 if (!PanelSettings.TryGetValue(Panel, out PanelConfig))
  1574.                     return DefaultValue;
  1575.  
  1576.                 string value;
  1577.                 if (!PanelConfig.TryGetValue(Key, out value))
  1578.                     return DefaultValue;
  1579.  
  1580.                 if (value == null)
  1581.                     return DefaultValue;
  1582.                 return (T)Convert.ChangeType(value, typeof(T));
  1583.             }
  1584.  
  1585.  
  1586.             public T GetSetting<T>(string Key, T DefaultValue)
  1587.             {
  1588.  
  1589.                 string value;
  1590.                 if (!Settings.TryGetValue(Key, out value))
  1591.                     return DefaultValue;
  1592.  
  1593.                 if (value == null)
  1594.                     return DefaultValue;
  1595.  
  1596.                 return (T)Convert.ChangeType(value, typeof(T));
  1597.             }
  1598.  
  1599.         }
  1600.  
  1601.         public void LoadData()
  1602.         {
  1603.             storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("InfoPanel_db");
  1604.             if (storedData == null)
  1605.             {
  1606.                 storedData = new StoredData();
  1607.                 SaveData();
  1608.             }
  1609.         }
  1610.  
  1611.         public void SaveData()
  1612.         {
  1613.             Interface.Oxide.DataFileSystem.WriteObject("InfoPanel_db", storedData);
  1614.         }
  1615.  
  1616.         public void ChangePlayerSettings(BasePlayer player, string Key, string Value)
  1617.         {
  1618.             PlayerSettings playerSettings;
  1619.             if (!storedData.Players.TryGetValue(player.UserIDString, out playerSettings))
  1620.                 storedData.Players[player.UserIDString] = playerSettings = new PlayerSettings(player);
  1621.             playerSettings.SetSetting(Key, Value);
  1622.         }
  1623.  
  1624.         public void ChangePlayerPanelSettings(BasePlayer player, string Panel, string Key, string Value)
  1625.         {
  1626.             PlayerSettings playerSettings;
  1627.             if (!storedData.Players.TryGetValue(player.UserIDString, out playerSettings))
  1628.                 storedData.Players[player.UserIDString] = playerSettings = new PlayerSettings(player);
  1629.             playerSettings.SetPanelSetting(Panel, Key, Value);
  1630.         }
  1631.  
  1632.  
  1633.         #endregion
  1634.  
  1635.         public List<string> Err = new List<string>();
  1636.         public Dictionary<string, List<string>> ErrA = new Dictionary<string,List<string>>();
  1637.         public Dictionary<string, int> ErrB = new Dictionary<string, int>();
  1638.         public Dictionary<string,int> ErrD = new Dictionary<string,int>();
  1639.  
  1640.         #region IPanelClass
  1641.         [JsonObject(MemberSerialization.OptIn)]
  1642.         public class IPanel
  1643.         {
  1644.             #region Class Variables
  1645.  
  1646.             [JsonProperty("name")]
  1647.             public string Name { get; set; }
  1648.  
  1649.             [JsonProperty("parent")]
  1650.             public string ParentName { get; set; } = "HUD/Overlay";
  1651.  
  1652.             [JsonProperty("components")]
  1653.             public List<ICuiComponent> Components = new List<ICuiComponent>();
  1654.  
  1655.             [JsonProperty("fadeOut")]
  1656.             public float FadeOut { get; set; }
  1657.  
  1658.             //Left-Right
  1659.             public Vector2 HorizontalPosition { get; set; } = new Vector2(0f, 1f);
  1660.  
  1661.             //Bottom-Top
  1662.             public Vector2 VerticalPosition { get; set; } = new Vector2(0f, 1f);
  1663.  
  1664.             public string AnchorX { get; set; } = "Left";
  1665.  
  1666.             public string AnchorY { get; set; } = "Bottom";
  1667.  
  1668.             public Vector4 Padding = Vector4.zero;
  1669.             public Vector4 Margin { get; set; } = Vector4.zero;
  1670.  
  1671.             public float Width { get; set; } = 1f;
  1672.  
  1673.             public float Height { get; set; } = 1f;
  1674.  
  1675.             public Color _BGColor = Color.black;
  1676.             public Color BackgroundColor
  1677.             {
  1678.                 get
  1679.                 {
  1680.                     return _BGColor;
  1681.                 }
  1682.                 set
  1683.                 {
  1684.                     _BGColor = value;
  1685.  
  1686.                     if (ImageComponent == null)
  1687.                     {
  1688.                         ImageComponent = new CuiImageComponent();
  1689.                         Components.Insert(0, ImageComponent);
  1690.                     }
  1691.  
  1692.                     ImageComponent.Color = $"{value.r} {value.g} {value.b} {value.a}";
  1693.                 }
  1694.             }
  1695.  
  1696.             public int Order = 0;
  1697.  
  1698.             public float _VerticalOffset = 0f;
  1699.             public float VerticalOffset
  1700.             {
  1701.                 get
  1702.                 {
  1703.                     return _VerticalOffset;
  1704.                 }
  1705.  
  1706.                 set
  1707.                 {
  1708.                     _VerticalOffset = value;
  1709.                     SetVerticalPosition();
  1710.                 }
  1711.             }
  1712.  
  1713.             //public Dictionary<string, IPanel> Childs = new Dictionary<string, IPanel>();
  1714.             public List<string> Childs = new List<string>();
  1715.  
  1716.             //Components
  1717.             public CuiRectTransformComponent RecTransform;
  1718.             public CuiImageComponent ImageComponent;
  1719.  
  1720.             //public bool ChildsChanged = false;
  1721.  
  1722.             BasePlayer Owner = null;
  1723.  
  1724.             public string DockName = null;
  1725.  
  1726.             public bool IsActive = false;
  1727.             public bool IsHidden = false;
  1728.  
  1729.             public bool IsPanel = false;
  1730.             public bool IsDock = false;
  1731.  
  1732.             public bool Autoload = true;
  1733.             private Dictionary<string, Dictionary<string, IPanel>> playerPanels;
  1734.             private Dictionary<string, Dictionary<string, IPanel>> playerDockPanels;
  1735.             #endregion
  1736.  
  1737.             public IPanel(string name, BasePlayer Player, Dictionary<string, Dictionary<string, IPanel>> playerPanels, Dictionary<string, Dictionary<string, IPanel>> playerDockPanels)
  1738.             {
  1739.  
  1740.                 Name = name;
  1741.                 Owner = Player;
  1742.                 this.playerPanels = playerPanels;
  1743.                 this.playerDockPanels = playerDockPanels;
  1744.  
  1745.                 //LoadedPanels.Add(this._Name, this);
  1746.  
  1747.                 Dictionary<string, IPanel> playerPanel;
  1748.                 if (!playerPanels.TryGetValue(Player.UserIDString, out playerPanel))
  1749.                     playerPanels.Add(Player.UserIDString, playerPanel = new Dictionary<string, IPanel>());
  1750.                 playerPanel.Add(name, this);
  1751.  
  1752.                 RecTransform = new CuiRectTransformComponent();
  1753.                 Components.Add(RecTransform);
  1754.             }
  1755.  
  1756.             public void SetAnchorXY(string Horizontal, string Vertical)
  1757.             {
  1758.                 AnchorX = Horizontal;
  1759.                 AnchorY = Vertical;
  1760.             }
  1761.  
  1762.             #region Positioning
  1763.  
  1764.             //x,y,z,w
  1765.             public void SetHorizontalPosition()
  1766.             {
  1767.                 float Left;
  1768.                 float Right;
  1769.                 var Offset = GetOffset();
  1770.  
  1771.                 if (AnchorX == "Right")
  1772.                 {
  1773.                     Right = 1f;
  1774.                     Left = Right - (Width);
  1775.  
  1776.                     HorizontalPosition = new Vector2(Left, Right) - new Vector2(Offset - Margin.y, Offset - Margin.y);
  1777.                 }
  1778.                 else
  1779.                 {
  1780.                     Left = 0f;
  1781.                     Right = Left + (Width);
  1782.  
  1783.                     HorizontalPosition = new Vector2(Left, Right) + new Vector2(Offset + Margin.w, Offset + Margin.w);
  1784.                 }
  1785.  
  1786.                 RecTransform.AnchorMin = $"{HorizontalPosition.x} {VerticalPosition.x}";
  1787.                 RecTransform.AnchorMax = $"{HorizontalPosition.y} {VerticalPosition.y}";
  1788.             }
  1789.  
  1790.             public void SetVerticalPosition()
  1791.             {
  1792.                 float Top;
  1793.                 float Bottom;
  1794.  
  1795.                 if (AnchorY == "Top")
  1796.                 {
  1797.                     Top = 1f;
  1798.                     Bottom = Top - (Height);
  1799.                     VerticalPosition = new Vector2(Bottom, Top) + new Vector2(_VerticalOffset - Margin.x, _VerticalOffset - Margin.x);
  1800.                 }
  1801.                 else
  1802.                 {
  1803.                     Bottom = 0f;
  1804.                     Top = Bottom + (Height);
  1805.  
  1806.                     VerticalPosition = new Vector2(Bottom, Top) + new Vector2(_VerticalOffset + Margin.z, _VerticalOffset + Margin.z);
  1807.                 }
  1808.  
  1809.                 RecTransform.AnchorMin = $"{HorizontalPosition.x} {VerticalPosition.x}";
  1810.                 RecTransform.AnchorMax = $"{HorizontalPosition.y} {VerticalPosition.y}";
  1811.             }
  1812.  
  1813.             float FullWidth()
  1814.             {
  1815.                 return Width + Margin.y + Margin.w;
  1816.             }
  1817.  
  1818.             float GetSiblingsFullWidth()
  1819.             {
  1820.                 return 1f;
  1821.             }
  1822.             #endregion
  1823.  
  1824.             #region Json
  1825.             public string ToJson()
  1826.             {
  1827.                 SetHorizontalPosition();
  1828.                 SetVerticalPosition();
  1829.  
  1830.                 return JsonConvert.SerializeObject(
  1831.                     this,
  1832.                     new JsonSerializerSettings
  1833.                     {
  1834.                         NullValueHandling = NullValueHandling.Ignore,
  1835.                         DefaultValueHandling = DefaultValueHandling.Ignore
  1836.                     }
  1837.                 );
  1838.             }
  1839.  
  1840.  
  1841.             public float GetOffset()
  1842.             {
  1843.                 // Előző testvérek ugyan azzal az anchorX-el
  1844.  
  1845.                 var Offset = 0f;
  1846.  
  1847.                 var Parent = GetPanel(ParentName);
  1848.  
  1849.                 if (Parent == null)
  1850.                 {
  1851.                     return Offset;
  1852.                 }
  1853.  
  1854.                 var Siblings = Parent.GetChilds().Where(c => c.Value.AnchorX == AnchorX && c.Value.Order <= Order && c.Value.IsActive && c.Value.Name != Name).Select(c => c.Value).OrderBy(s => s.Order).ToList();
  1855.  
  1856.                 foreach (var Sibling in Siblings)
  1857.                 {
  1858.                     Offset += Sibling.Width + Sibling.Margin.y + Sibling.Margin.w;
  1859.                 }
  1860.  
  1861.                 return Offset;
  1862.             }
  1863.  
  1864.             public string GetJson(bool Brackets = true)
  1865.             {
  1866.                 var Panel = ToJson();
  1867.  
  1868.                 if (Brackets)
  1869.                 {
  1870.                     return $"[{Panel}]";
  1871.                 }
  1872.                 return Panel;
  1873.             }
  1874.  
  1875.             #endregion
  1876.  
  1877.             #region Childs
  1878.  
  1879.             public int GetLastChild()
  1880.             {
  1881.                 if (Childs.Count == 0)
  1882.                 {
  1883.                     return 0;
  1884.                 }
  1885.                 else
  1886.                 {
  1887.                     return GetChilds().Max(p => p.Value.Order);
  1888.                 }
  1889.             }
  1890.  
  1891.             public IPanelText AddText(string Name)
  1892.             {
  1893.                 var Text = new IPanelText(Name, Owner, playerPanels, playerDockPanels) {ParentName = this.Name};
  1894.                 Childs.Add(Name);
  1895.                 return Text;
  1896.             }
  1897.  
  1898.             public IPanelRawImage AddImage(string Name)
  1899.             {
  1900.                 var Image = new IPanelRawImage(Name, Owner, playerPanels, playerDockPanels) {ParentName = this.Name};
  1901.                 Childs.Add(Name);
  1902.                 return Image;
  1903.             }
  1904.  
  1905.             public IPanel AddPanel(string Name)
  1906.             {
  1907.                 var Panel = new IPanel(Name, Owner, playerPanels, playerDockPanels) {ParentName = this.Name};
  1908.                 Childs.Add(Name);
  1909.                 return Panel;
  1910.             }
  1911.  
  1912.             #endregion
  1913.  
  1914.             #region Selectors
  1915.  
  1916.             List<string> GetActiveAfterThis()
  1917.             {
  1918.                 var Panels = playerPanels[Owner.UserIDString]
  1919.                     .Where(p => p.Value.IsActive && p.Value.Order > Order && p.Value.ParentName == ParentName && p.Value.AnchorX == AnchorX)
  1920.                     .OrderBy(s => s.Value.Order)
  1921.                     .Select(k => k.Key)
  1922.                     .ToList();
  1923.  
  1924.                 return Panels;
  1925.             }
  1926.  
  1927.             public Dictionary<string, IPanel> GetChilds()
  1928.             {
  1929.                 return playerPanels[Owner.UserIDString].Where(x => Childs.Contains(x.Key)).ToDictionary(se => se.Key, se => se.Value);
  1930.             }
  1931.  
  1932.             public IPanel GetParent()
  1933.             {
  1934.                 if (GetPanel(ParentName) != null)
  1935.                 {
  1936.                     return GetPanel(ParentName);
  1937.                 }
  1938.  
  1939.                 return null;
  1940.             }
  1941.  
  1942.             public List<IPanel> GetSiblings()
  1943.             {
  1944.                 var Parent = GetPanel(ParentName);
  1945.  
  1946.                 if(Parent != null)
  1947.                 {
  1948.                     return Parent.GetChilds().Where(c => c.Value.AnchorX == AnchorX && c.Value.Name != Name).Select(c => c.Value).OrderBy(s => s.Order).ToList();
  1949.                 }
  1950.  
  1951.                 return new List<IPanel>();
  1952.             }
  1953.  
  1954.             public IPanel GetPanel(string PName)
  1955.             {
  1956.                 Dictionary<string, IPanel> panels;
  1957.                 IPanel panel;
  1958.                 if (playerPanels.TryGetValue(Owner.UserIDString, out panels) && panels.TryGetValue(PName, out panel))
  1959.                 {
  1960.                     return panel;
  1961.                 }
  1962.  
  1963.                 return null;
  1964.             }
  1965.  
  1966.             public IPanel GetDock()
  1967.             {
  1968.                 if (DockName == null) return null;
  1969.  
  1970.                 Dictionary<string, IPanel> panels;
  1971.                 IPanel panel;
  1972.                 if (playerDockPanels.TryGetValue(Owner.UserIDString, out panels) && panels.TryGetValue(DockName, out panel))
  1973.                 {
  1974.                     return panel;
  1975.                 }
  1976.  
  1977.                 return null;
  1978.             }
  1979.  
  1980.             #endregion
  1981.  
  1982.             #region GUI
  1983.  
  1984.  
  1985.             public void Hide()
  1986.             {
  1987.                 foreach (var Panel in GetChilds().Where(p => p.Value.IsActive))
  1988.                 {
  1989.                     Panel.Value.Hide();
  1990.                 }
  1991.  
  1992.                 CuiHelper.DestroyUi(Owner, Name);
  1993.                 //CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(this.Owner.net.connection), null, "DestroyUI", new Facepunch.ObjectList(this._Name));
  1994.             }
  1995.  
  1996.             public void Reveal()
  1997.             {
  1998.  
  1999.                 //Interface.Oxide.LogInfo(GetJson()); //TODO
  2000.                 CuiHelper.AddUi(Owner, GetJson());
  2001.                 //CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(this.Owner.net.connection), null, "AddUI", new Facepunch.ObjectList(GetJson()));
  2002.  
  2003.                 IsActive = true;
  2004.                 IsHidden = false;
  2005.  
  2006.                 foreach (var Child in GetChilds().Where(p => p.Value.Autoload || p.Value.IsActive).OrderBy(s => s.Value.Order))
  2007.                 {
  2008.                     Child.Value.Reveal();
  2009.                 }
  2010.  
  2011.             }
  2012.  
  2013.             void ReDrawPanels(List<string> PanelsName)
  2014.             {
  2015.                 foreach (var PanelName in PanelsName)
  2016.                 {
  2017.                     GetPanel(PanelName)?.DestroyPanel(false);
  2018.                 }
  2019.  
  2020.                 foreach (var PanelName in PanelsName)
  2021.                 {
  2022.                     GetPanel(PanelName)?.ShowPanel();
  2023.                 }
  2024.             }
  2025.  
  2026.             /// <summary>
  2027.             /// Panel megjelenítése.
  2028.             /// </summary>
  2029.             /// <param name="player"></param>
  2030.             public void ShowPanel(bool Childs = true)
  2031.             {
  2032.                 if (storedData.GetPlayerSettings(Owner.UserIDString, "enable", true))
  2033.                 {
  2034.                     var Dock = GetDock();
  2035.                     if(Dock != null && Dock.IsActive == false)
  2036.                     {
  2037.                         Dock.ShowPanel(false);
  2038.                     }
  2039.  
  2040.                     var ActivePanelsAfterThis = GetActiveAfterThis();
  2041.  
  2042.                     foreach (var PanelName in ActivePanelsAfterThis)
  2043.                     {
  2044.                         GetPanel(PanelName)?.DestroyPanel(false);
  2045.                     }
  2046.  
  2047.                     //ErrB.Add(this.Name + ErrB.Count,ActivePanelsAfterThis.Count);
  2048.  
  2049.                     if (storedData.GetPlayerSettings(Owner.UserIDString, "enable", true))
  2050.                     {
  2051.                         //Interface.Oxide.LogInfo(GetJson()); //TODO
  2052.                         CuiHelper.AddUi(Owner, GetJson());
  2053.                         //CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(this.Owner.net.connection), null, "AddUI", new Facepunch.ObjectList(GetJson()));
  2054.                     }
  2055.  
  2056.                     IsActive = true;
  2057.                     IsHidden = false;
  2058.  
  2059.                     if(Childs)
  2060.                     {
  2061.                         foreach (var Child in GetChilds().Where(p => p.Value.Autoload || p.Value.IsActive).OrderBy(s => s.Value.Order))
  2062.                         {
  2063.                             Child.Value.ShowPanel();
  2064.                         }
  2065.                     }
  2066.  
  2067.                     foreach (var PanelName in ActivePanelsAfterThis)
  2068.                     {
  2069.                         GetPanel(PanelName)?.ShowPanel();
  2070.                     }
  2071.  
  2072.                 }
  2073.                 else
  2074.                 {
  2075.                     ShowPanelIfHidden();
  2076.                 }
  2077.             }
  2078.  
  2079.             void ShowPanelIfHidden(bool Childs = true)
  2080.             {
  2081.                 IsActive = true;
  2082.                 IsHidden = true;
  2083.                 if (Childs)
  2084.                 {
  2085.                     foreach (var Child in GetChilds().Where(p => p.Value.Autoload || p.Value.IsActive).OrderBy(s => s.Value.Order))
  2086.                     {
  2087.                         Child.Value.ShowPanel();
  2088.                     }
  2089.                 }
  2090.             }
  2091.  
  2092.  
  2093.             public void DestroyPanel( bool Redraw = true)
  2094.             {
  2095.  
  2096.                 foreach (var Panel in GetChilds().Where(p => p.Value.IsActive))
  2097.                 {
  2098.                     Panel.Value.DestroyPanel(false);
  2099.                 }
  2100.  
  2101.                 CuiHelper.DestroyUi(Owner, Name);
  2102.                 //CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(this.Owner.net.connection), null, "DestroyUI", new Facepunch.ObjectList(this._Name));
  2103.  
  2104.                 IsActive = false;
  2105.  
  2106.                 if (Redraw)
  2107.                 {
  2108.                     ReDrawPanels(GetActiveAfterThis());
  2109.                 }
  2110.  
  2111.                 var Dock = GetDock();
  2112.                 if(Dock?.GetChilds().Count(p => p.Value.IsActive) == 0) Dock.DestroyPanel();
  2113.             }
  2114.  
  2115.  
  2116.             public virtual void Refresh()
  2117.             {
  2118.                 DestroyPanel();
  2119.                 ShowPanel();
  2120.             }
  2121.  
  2122.             #endregion
  2123.  
  2124.             #region Util
  2125.  
  2126.             public void Remover()
  2127.             {
  2128.                 foreach (var Child in GetChilds())
  2129.                 {
  2130.                     Child.Value.Remover();
  2131.                 }
  2132.  
  2133.                 GetPanel(ParentName).Childs.Remove(Name);
  2134.                 playerPanels[Owner.UserIDString].Remove(Name);
  2135.             }
  2136.  
  2137.             protected string ColorToString(Color color)
  2138.             {
  2139.                 return $"{color.r} {color.g} {color.b} {color.a}";
  2140.             }
  2141.  
  2142.             #endregion
  2143.         }
  2144.  
  2145.         public class IPanelText : IPanel
  2146.         {
  2147.             public string Content
  2148.             {
  2149.                 get
  2150.                 {
  2151.                     return TextComponent.Text;
  2152.                 }
  2153.                 set
  2154.                 {
  2155.                     TextComponent.Text = value;
  2156.                 }
  2157.             }
  2158.             public TextAnchor Align
  2159.             {
  2160.                 get
  2161.                 {
  2162.                     return TextComponent.Align;
  2163.                 }
  2164.  
  2165.                 set
  2166.                 {
  2167.                     TextComponent.Align = value;
  2168.                 }
  2169.             }
  2170.             public int FontSize {
  2171.                 get
  2172.                 {
  2173.                     return TextComponent.FontSize;
  2174.                 }
  2175.                 set
  2176.                 {
  2177.                     TextComponent.FontSize = value;
  2178.                 }
  2179.             }
  2180.             public Color _FontColor = Color.white;
  2181.             public Color FontColor
  2182.             {
  2183.                 get
  2184.                 {
  2185.                     return _FontColor;
  2186.                 }
  2187.                 set
  2188.                 {
  2189.                     _FontColor = value;
  2190.                     TextComponent.Color = $"{value.r} {value.g} {value.b} {value.a}";
  2191.                 }
  2192.             }
  2193.  
  2194.             public CuiTextComponent TextComponent;
  2195.  
  2196.             public IPanelText(string Name, BasePlayer Player, Dictionary<string, Dictionary<string, IPanel>> playerPanels, Dictionary<string, Dictionary<string, IPanel>> playerDockPanels) : base(Name, Player, playerPanels, playerDockPanels)
  2197.             {
  2198.                 TextComponent = new CuiTextComponent();
  2199.                 Components.Insert(0, TextComponent);
  2200.             }
  2201.  
  2202.             public void RefreshText(BasePlayer player, string text)
  2203.             {
  2204.                 DestroyPanel();
  2205.                 Content = text;
  2206.                 ShowPanel();
  2207.             }
  2208.         }
  2209.  
  2210.         public class IPanelRawImage : IPanel
  2211.         {
  2212.             public string Url
  2213.             {
  2214.                 get
  2215.                 {
  2216.                     return RawImageComponent.Url;
  2217.                 }
  2218.                 set
  2219.                 {
  2220.                     RawImageComponent.Url = value;
  2221.                 }
  2222.             }
  2223.  
  2224.             public Color _Color;
  2225.             public Color Color
  2226.             {
  2227.                 get
  2228.                 {
  2229.                     return _Color;
  2230.                 }
  2231.                 set
  2232.                 {
  2233.                     _Color = value;
  2234.                     RawImageComponent.Color = ColorToString(value);
  2235.                 }
  2236.             }
  2237.  
  2238.             public CuiRawImageComponent RawImageComponent;
  2239.  
  2240.             public IPanelRawImage(string Name, BasePlayer Player, Dictionary<string, Dictionary<string, IPanel>> playerPanels, Dictionary<string, Dictionary<string, IPanel>> playerDockPanels) : base(Name, Player, playerPanels, playerDockPanels)
  2241.             {
  2242.                 RawImageComponent = new CuiRawImageComponent();
  2243.                 Components.Insert(0, RawImageComponent);
  2244.             }
  2245.         }
  2246.  
  2247.         #endregion
  2248.  
  2249.         #region GUI
  2250.  
  2251.         private void DestroyGUI(BasePlayer player)
  2252.         {
  2253.             foreach (var Dock in PlayerDockPanels[player.UserIDString])
  2254.             {
  2255.                 Dock.Value.DestroyPanel(false);
  2256.             }
  2257.         }
  2258.  
  2259.         void GUITimerInit(BasePlayer player)
  2260.         {
  2261.             if (player == null) return;
  2262.  
  2263.             if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
  2264.             {
  2265.                 timer.In(2, () => GUITimerInit(player));
  2266.             }
  2267.             else if (!PlayerDockPanels.ContainsKey(player.UserIDString))
  2268.             {
  2269.                 LoadPanels(player);
  2270.                 InitializeGUI(player);
  2271.  
  2272.                 RefreshOnlinePlayers();
  2273.             }
  2274.         }
  2275.  
  2276.         private void InitializeGUI(BasePlayer player)
  2277.         {
  2278.             if (!storedData.GetPlayerSettings(player.UserIDString, "enable", true))
  2279.             {
  2280.                 return;
  2281.             }
  2282.  
  2283.             foreach (var Panel in PlayerPanels[player.UserIDString])
  2284.             {
  2285.                 switch (Panel.Key)
  2286.                 {
  2287.                     case "ClockText":
  2288.                         ((IPanelText) Panel.Value).Content = Clock.ShowTime(player.UserIDString, storedData);
  2289.                         break;
  2290.                     case "OPlayersText":
  2291.                         ((IPanelText) Panel.Value).Content = BasePlayer.activePlayerList.Count + "/" + ConVar.Server.maxplayers;
  2292.                         break;
  2293.                     case "SleepersText":
  2294.                         ((IPanelText) Panel.Value).Content = BasePlayer.sleepingPlayerList.Count.ToString();
  2295.                         break;
  2296.                     case "MessageBoxText":
  2297.                         ((IPanelText) Panel.Value).Content = MessageBox.GetMessage();
  2298.                         break;
  2299.                     case "CoordinatesText":
  2300.                         ((IPanelText) Panel.Value).Content = Coord.GetCoord(player.UserIDString);
  2301.                         break;
  2302.                     case "RadiationImage":
  2303.                         ((IPanelRawImage) Panel.Value).Color = Rad.ImageColor;
  2304.                         break;
  2305.                     case "AirdropEventImage":
  2306.                         ((IPanelRawImage) Panel.Value).Color = Airplane.ImageColor;
  2307.                         break;
  2308.                     case "HelicopterEventImage":
  2309.                         ((IPanelRawImage) Panel.Value).Color = Helicopter.ImageColor;
  2310.                         break;
  2311.                     case "CompassText":
  2312.                         ((IPanelText) Panel.Value).Content = CompassObj.GetDirection(player.UserIDString);
  2313.                         break;
  2314.                 }
  2315.             }
  2316.  
  2317.             foreach (var Dock in PlayerDockPanels[player.UserIDString])
  2318.             {
  2319.                 if(Dock.Value.Childs.Count != 0)
  2320.                 {
  2321.                     Dock.Value.ShowPanel();
  2322.                 }
  2323.             }
  2324.  
  2325.         }
  2326.  
  2327.         private void RevealGUI(BasePlayer player)
  2328.         {
  2329.             foreach (var Dock in PlayerDockPanels[player.UserIDString])
  2330.             {
  2331.                 if (Dock.Value.Childs.Count != 0)
  2332.                 {
  2333.                     Dock.Value.ShowPanel();
  2334.                 }
  2335.             }
  2336.         }
  2337.  
  2338.         private void RefreshOnlinePlayers()
  2339.         {
  2340.             foreach (var panel in PlayerPanels)
  2341.             {
  2342.                 if (Settings.GetPanelSettingsValue("OPlayers", "Available", true) && panel.Value.ContainsKey("OPlayersText"))
  2343.                 {
  2344.                     var panelText = (IPanelText)panel.Value["OPlayersText"];
  2345.                     panelText.Content = $"{BasePlayer.activePlayerList.Count}/{ConVar.Server.maxplayers}";
  2346.                     panelText.Refresh();
  2347.                 }
  2348.             }
  2349.         }
  2350.  
  2351.         private void RefreshSleepers()
  2352.         {
  2353.             foreach (var panel in PlayerPanels)
  2354.             {
  2355.                 if (Settings.GetPanelSettingsValue("Sleepers", "Available", true) && panel.Value.ContainsKey("SleepersText"))
  2356.                 {
  2357.                     var panelText = (IPanelText)panel.Value["SleepersText"];
  2358.                     panelText.Content = BasePlayer.sleepingPlayerList.Count.ToString();
  2359.                     panelText.Refresh();
  2360.                 }
  2361.             }
  2362.         }
  2363.  
  2364.         #endregion
  2365.  
  2366.         #region API
  2367.  
  2368.         /// <summary>
  2369.         /// Panel beírása a configba.
  2370.         /// </summary>
  2371.         /// <param name="PluginName"></param>
  2372.         /// <param name="PanelName"></param>
  2373.         /// <param name="json"></param>
  2374.         /// <returns></returns>
  2375.         private bool PanelRegister(string PluginName,string PanelName, string json)
  2376.         {
  2377.             List<string> loadedPlugin;
  2378.             if (LoadedPluginPanels.TryGetValue(PluginName, out loadedPlugin) && loadedPlugin.Contains(PanelName))
  2379.             {
  2380.                 return true;
  2381.             }
  2382.  
  2383.             var Cfg = JsonConvert.DeserializeObject<PanelConfig>(json);
  2384.  
  2385.             Dictionary<string, PanelConfig> thirdPartyPanel;
  2386.             if (!Settings.ThirdPartyPanels.TryGetValue(PluginName, out thirdPartyPanel))
  2387.                 Settings.ThirdPartyPanels.Add(PluginName, thirdPartyPanel = new Dictionary<string, PanelConfig>());
  2388.  
  2389.             //Ha a plugin panelja még nem volt bejegyezve
  2390.             if (!thirdPartyPanel.ContainsKey(PanelName))
  2391.             {
  2392.                 Cfg.Order = PanelReOrder(Cfg.Dock, Cfg.AnchorX);
  2393.                 thirdPartyPanel.Add(PanelName, Cfg);
  2394.  
  2395.                 Config.WriteObject(Settings, true);
  2396.                 PrintWarning($"New panel added to the config file: {PanelName}");
  2397.             }
  2398.  
  2399.             foreach (var Docks in PlayerDockPanels)
  2400.             {
  2401.                 if(Docks.Value.ContainsKey(Cfg.Dock))
  2402.                 {
  2403.                     LoadPanel(Docks.Value[Cfg.Dock], PanelName, Cfg);
  2404.                 }
  2405.             }
  2406.  
  2407.             if (!LoadedPluginPanels.TryGetValue(PluginName, out loadedPlugin))
  2408.                 LoadedPluginPanels.Add(PluginName, loadedPlugin = new List<string>());
  2409.             loadedPlugin.Add(PanelName);
  2410.  
  2411.             return true;
  2412.         }
  2413.  
  2414.         private bool ShowPanel(string PluginName,string PanelName, string PlayerId = null)
  2415.         {
  2416.             if (!Settings.ThirdPartyPanels[PluginName][PanelName].Available)
  2417.             {
  2418.                 return false;
  2419.             }
  2420.  
  2421.             if (PlayerId != null && PlayerPanels.ContainsKey(PlayerId))
  2422.             {
  2423.                 PlayerPanels[PlayerId][PanelName].ShowPanel();
  2424.                 return true;
  2425.             }
  2426.  
  2427.             foreach(var PlayerID in PlayerPanels.Keys)
  2428.             {
  2429.                 PlayerPanels[PlayerID][PanelName].ShowPanel();
  2430.             }
  2431.  
  2432.             return true;
  2433.         }
  2434.  
  2435.         private bool HidePanel(string PluginName,string PanelName, string PlayerId = null)
  2436.         {
  2437.             if (!Settings.ThirdPartyPanels[PluginName][PanelName].Available)
  2438.             {
  2439.                 return false;
  2440.             }
  2441.  
  2442.             if (PlayerId != null && PlayerPanels.ContainsKey(PlayerId))
  2443.             {
  2444.                 PlayerPanels[PlayerId][PanelName].DestroyPanel();
  2445.                 return true;
  2446.             }
  2447.  
  2448.             foreach (var PlayerID in PlayerPanels.Keys)
  2449.             {
  2450.                 PlayerPanels[PlayerID][PanelName].DestroyPanel();
  2451.             }
  2452.  
  2453.             return true;
  2454.         }
  2455.  
  2456.         private bool RefreshPanel(string PluginName,string PanelName, string PlayerId = null)
  2457.         {
  2458.             if (!Settings.ThirdPartyPanels[PluginName][PanelName].Available)
  2459.             {
  2460.                 return false;
  2461.             }
  2462.  
  2463.             if (PlayerId != null && PlayerPanels.ContainsKey(PlayerId))
  2464.             {
  2465.                 PlayerPanels[PlayerId][PanelName].DestroyPanel();
  2466.                 PlayerPanels[PlayerId][PanelName].ShowPanel();
  2467.                 return true;
  2468.             }
  2469.  
  2470.             foreach (var PlayerID in PlayerPanels.Keys)
  2471.             {
  2472.                 PlayerPanels[PlayerID][PanelName].DestroyPanel();
  2473.                 PlayerPanels[PlayerID][PanelName].ShowPanel();
  2474.             }
  2475.  
  2476.             return true;
  2477.         }
  2478.  
  2479.         private void SetPanelAttribute(string PluginName,string PanelName, string Attribute, string Value, string PlayerId = null )
  2480.         {
  2481.             if (PlayerId != null && PlayerPanels.ContainsKey(PlayerId))
  2482.             {
  2483.                 var Panel = PlayerPanels[PlayerId][PanelName];
  2484.                 var PropInfo = Panel.GetType().GetProperty(Attribute);
  2485.  
  2486.                 if (PropInfo == null)
  2487.                 {
  2488.                     PrintWarning("Wrong Attribute name: " + Attribute);
  2489.                     return;
  2490.                 }
  2491.  
  2492.                 if (Attribute == "FontColor" || Attribute == "BackgroundColor")
  2493.                 {
  2494.                     PropInfo.SetValue(Panel, ColorEx.Parse(Value), null);
  2495.                 }
  2496.                 else if (Attribute == "Margin")
  2497.                 {
  2498.                     PropInfo.SetValue(Panel, Vector4Parser(Value), null);
  2499.                 }
  2500.                 else
  2501.                 {
  2502.                     var ConvertedValue = Convert.ChangeType(Value, PropInfo.PropertyType);
  2503.  
  2504.                     PropInfo.SetValue(Panel, ConvertedValue, null);
  2505.                 }
  2506.  
  2507.                 return;
  2508.             }
  2509.  
  2510.             foreach (var playerID in PlayerPanels.Keys)
  2511.             {
  2512.                 var Panel = PlayerPanels[playerID][PanelName];
  2513.                 var PropInfo = Panel.GetType().GetProperty(Attribute);
  2514.  
  2515.                 if (PropInfo == null)
  2516.                 {
  2517.                     PrintWarning("Wrong Attribute name: " + Attribute);
  2518.                     return;
  2519.                 }
  2520.  
  2521.                 if (Attribute == "FontColor" || Attribute == "BackgroundColor")
  2522.                 {
  2523.                     PropInfo.SetValue(Panel, ColorEx.Parse(Value), null);
  2524.                 }
  2525.                 else if (Attribute == "Margin")
  2526.                 {
  2527.                     PropInfo.SetValue(Panel, Vector4Parser(Value), null);
  2528.                 }
  2529.                 else
  2530.                 {
  2531.                     var ConvertedValue = Convert.ChangeType(Value, PropInfo.PropertyType);
  2532.  
  2533.                     PropInfo.SetValue(Panel, ConvertedValue, null);
  2534.                 }
  2535.             }
  2536.         }
  2537.  
  2538.         private bool SendPanelInfo(string PluginName, List<string> Panels)
  2539.         {
  2540.             Dictionary<string, PanelConfig> panelConfig;
  2541.             if(!Settings.ThirdPartyPanels.TryGetValue(PluginName, out panelConfig))
  2542.             {
  2543.                 return false;
  2544.             }
  2545.  
  2546.             var Removable =panelConfig.Keys.Except(Panels).ToList();
  2547.  
  2548.             foreach(var item in Removable)
  2549.             {
  2550.                 panelConfig.Remove(item);
  2551.             }
  2552.  
  2553.             if(Removable.Count > 0)
  2554.             {
  2555.                 Config.WriteObject(Settings, true);
  2556.                 PrintWarning($"Config File refreshed! {Removable.Count} panel removed!");
  2557.             }
  2558.  
  2559.             return true;
  2560.         }
  2561.  
  2562.         private bool IsPlayerGUILoaded(string PlayerId)
  2563.         {
  2564.             return PlayerPanels.ContainsKey(PlayerId);
  2565.         }
  2566.  
  2567.         #endregion
  2568.  
  2569.         #region Utility
  2570.         internal static Vector4 Vector4Parser(string p)
  2571.         {
  2572.             var strArrays = p.Split(' ');
  2573.             if ((int)strArrays.Length != 4)
  2574.             {
  2575.                 return Vector4.zero;
  2576.             }
  2577.             return new Vector4(float.Parse(strArrays[0]), float.Parse(strArrays[1]), float.Parse(strArrays[2]), float.Parse(strArrays[3]));
  2578.         }
  2579.         #endregion
  2580.     }
  2581. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement