Advertisement
Vlad-00003

QuickMenu patch

Apr 26th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.58 KB | None | 0 0
  1. --- QuickMenu.cs    Thu Apr 27 02:44:12 2017
  2. +++ QuickMenu_new.cs    Thu Apr 27 02:42:35 2017
  3. @@ -8,7 +8,7 @@
  4.  
  5.  namespace Oxide.Plugins
  6.  {
  7. -    [Info("QuickMenu", "Xianith", "0.0.4", ResourceId = 2419)]
  8. +    [Info("QuickMenu", "Xianith. Edited by Vlad-00003", "0.0.6")]
  9.  
  10.      class QuickMenu : RustPlugin
  11.      {
  12. @@ -19,18 +19,21 @@
  13.  
  14.          private Dictionary<string, string> UIColors = new Dictionary<string, string>
  15.          {
  16. -           {"dark", "0.1 0.1 0.1 0.98" },
  17. -           {"blue", "0.16 0.34 0.49 1.0" },
  18. -           {"red", "0.56 0.20 0.15 1.0" },
  19. -           {"green", "0.31 0.37 0.20 1.0" },
  20. -           {"grey", "0.34 0.34 0.34 1.0" },
  21. -           {"lightgrey", "1 1 1 1.0" },
  22. -           {"lightblue", "0.56 0.74 0.89 1.0" },
  23. -           {"lightgreen", "0.60 0.70 0.51 1.0" },
  24. -           {"lightred", "0.96 0.60 0.55 1.0" }
  25. +            {"dark", "0.1 0.1 0.1 0.98" },
  26. +            {"blue", "0.16 0.34 0.49 1.0" },
  27. +            {"red", "0.56 0.20 0.15 1.0" },
  28. +            {"green", "0.31 0.37 0.20 1.0" },
  29. +            {"grey", "0.34 0.34 0.34 1.0" },
  30. +            {"lightgrey", "1 1 1 1.0" },
  31. +            {"lightblue", "0.56 0.74 0.89 1.0" },
  32. +            {"lightgreen", "0.60 0.70 0.51 1.0" },
  33. +            {"lightred", "0.96 0.60 0.55 1.0" },
  34. +            {"deeppink", "1 0.078 0.576 1.0" },
  35. +            {"gold", "1 0.843 0 1.0"}
  36.          };
  37.  
  38. -        private string quickMenuKey;
  39. +        //private string quickMenuKey;
  40. +        private Dictionary<BasePlayer, string> HelpButtons = new Dictionary<BasePlayer, string>();
  41.  
  42.          private string TopButtonColor;
  43.          private string TopButtonFontColor;
  44. @@ -57,6 +60,11 @@
  45.          private string BottomButtonText;
  46.          private string BottomButtonCommand;
  47.  
  48. +        private string HelpButtonColor;
  49. +        private string HelpButtonText;
  50. +        private string HelpButtonAnchorMax;
  51. +        private string HelpButtonAnchorMin;
  52. +
  53.          private object GetConfig(string menu, string datavalue, object defaultValue)
  54.          {
  55.              var data = Config[menu] as Dictionary<string, object>;
  56. @@ -79,7 +87,7 @@
  57.          void LoadVariables()
  58.          {
  59.  
  60. -            quickMenuKey = Convert.ToString(GetConfig("Settings", "Hot key", "f6"));
  61. +            //quickMenuKey = Convert.ToString(GetConfig("Settings", "Hot key", "f6"));
  62.              TopButtonColor = Convert.ToString(GetConfig("Top Button", "Color", "green"));
  63.              TopButtonText = Convert.ToString(GetConfig("Top Button", "Text", "Trade Accept"));
  64.              TopButtonCommand = Convert.ToString(GetConfig("Top Button", "Command", "chat.say /trade accept"));
  65. @@ -93,18 +101,26 @@
  66.              BottomButtonText = Convert.ToString(GetConfig("Bottom Button", "Text", "CANCEL"));
  67.              // BottomButtonCommand = Convert.ToString(GetConfig("Bottom Button", "Command", "UI_QuickMenu"));
  68.  
  69. -            if (TopButtonColor != "green" && TopButtonColor != "red" && TopButtonColor != "blue")
  70. +            HelpButtonColor = Convert.ToString(GetConfig("Help button", "Color", "red"));
  71. +            HelpButtonText = Convert.ToString(GetConfig("Help button", "Text", "Open quick menu"));
  72. +            HelpButtonAnchorMax = Convert.ToString(GetConfig("Help button", "Anchor Max", "0.75 0.108"));
  73. +            HelpButtonAnchorMin = Convert.ToString(GetConfig("Help button", "Anchor Min", "0.644 0.025"));
  74. +            
  75. +            if(!UIColors.ContainsKey(TopButtonColor))
  76.                  TopButtonColor = "grey";
  77. -
  78. -            if (MidTopButtonColor != "green" && MidTopButtonColor != "red" && MidTopButtonColor != "blue")
  79. +            
  80. +            if (!UIColors.ContainsKey(MidTopButtonColor))
  81.                  MidTopButtonColor = "grey";
  82. -
  83. -            if (MidBottomButtonColor != "green" && MidBottomButtonColor != "red" && MidBottomButtonColor != "blue")
  84. +            
  85. +            if (!UIColors.ContainsKey(MidBottomButtonColor))
  86.                  MidBottomButtonColor = "grey";
  87.  
  88. -            if (BottomButtonColor != "green" && BottomButtonColor != "red" && BottomButtonColor != "blue")
  89. +            if (!UIColors.ContainsKey(BottomButtonColor))
  90.                  BottomButtonColor = "grey";
  91. -            
  92. +
  93. +            if (!UIColors.ContainsKey(HelpButtonColor))
  94. +                HelpButtonColor = "grey";
  95. +
  96.              if (!Changed) return;
  97.              SaveConfig();
  98.              Changed = false;
  99. @@ -129,7 +145,8 @@
  100.          {
  101.              foreach (BasePlayer player in BasePlayer.activePlayerList)
  102.              {
  103. -                player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  104. +                //player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  105. +                AddHelpButton(player);
  106.              }
  107.          }
  108.  
  109. @@ -137,24 +154,77 @@
  110.          {
  111.              foreach (BasePlayer player in BasePlayer.activePlayerList)
  112.              {
  113. -                player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  114. +                //player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  115. +                if (HelpButtons.ContainsKey(player))
  116. +                {
  117. +                    CuiHelper.DestroyUi(player, HelpButtons[player]);
  118. +                    CuiHelper.DestroyUi(player, "quickMenu");
  119. +                }
  120.              }
  121.          }
  122. +        void Unload()
  123. +        {
  124. +            HotKeyUnbind();
  125. +        }
  126.  
  127.          private void OnPlayerInit(BasePlayer player)
  128.          {
  129. -            if (player != null)
  130. +            //if (player != null)
  131. +            //{
  132. +            //    player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  133. +            //}
  134. +            if (player == null)
  135. +                return;
  136. +
  137. +            if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
  138.              {
  139. -                player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  140. +                timer.Once(2, () => OnPlayerInit(player));
  141. +                return;
  142.              }
  143. +            AddHelpButton(player);
  144.          }
  145.  
  146.          private void OnPlayerDisconnected(BasePlayer player)
  147.          {
  148. -             player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  149. +            //player.Command($"bind {quickMenuKey} \"UI_QuickMenu\"");
  150. +            if (HelpButtons.ContainsKey(player))
  151. +            {
  152. +                CuiHelper.DestroyUi(player, HelpButtons[player]);
  153. +            }
  154. +            CuiHelper.DestroyUi(player, "quickMenu");
  155.          }
  156.          #endregion Binding
  157. -
  158. +        private void AddHelpButton(BasePlayer player)
  159. +        {
  160. +            CuiElementContainer main = new CuiElementContainer();
  161. +            var button = new CuiButton
  162. +            {
  163. +                Button =
  164. +                {
  165. +                    Command = "UI_QuickMenu",
  166. +                    Color = UIColors[$"{HelpButtonColor}"]
  167. +                },
  168. +                RectTransform =
  169. +                {
  170. +                    AnchorMin = HelpButtonAnchorMin,
  171. +                    AnchorMax = HelpButtonAnchorMax
  172. +                },
  173. +                Text =
  174. +                {
  175. +                    Text = HelpButtonText,
  176. +                    FontSize = 14,
  177. +                    Align = TextAnchor.MiddleCenter
  178. +                }
  179. +            };
  180. +            var HelpButtonName = main.Add(button);
  181. +            if (HelpButtons.ContainsKey(player))
  182. +            {
  183. +                CuiHelper.DestroyUi(player, HelpButtons[player]);
  184. +                HelpButtons.Remove(player);
  185. +            }
  186. +            CuiHelper.AddUi(player, main);
  187. +            HelpButtons.Add(player, HelpButtonName);
  188. +        }
  189.          public void QuickMenuGuiCreate(BasePlayer player)
  190.          {
  191.              if (player == null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement