C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System.Linq;
namespace Oxide.Plugins {
[Info("XFastButtons", "Monster", "1.0.0")]
class XFastButtons : RustPlugin {
private const bool LanguageEnglish = true;
private const string permUse = "xfastbuttons.use";
private class Buttons {
public string Text;
public string Command;
public string Color;
public string Font;
public bool Individual;
public string Parent;
public string Image;
public string AnchorMinXY;
public string AnchorMaxXY;
public string OffsetMinXY;
public string OffsetMaxXY;
public Buttons(string text, string command, string color, string font, bool individual, string parent, string image, string anchorMinXY, string anchorMaxXY, string offsetMinXY, string offsetMaxXY) {
Text = text;
Command = command;
Color = color;
Font = font;
Individual = individual;
Parent = parent;
Image = image;
AnchorMinXY = anchorMinXY;
AnchorMaxXY = anchorMaxXY;
OffsetMinXY = offsetMinXY;
OffsetMaxXY = offsetMaxXY;
}
}
private Dictionary<ulong, Buttons> _create_edit_buttons = new Dictionary<ulong, Buttons>();
private readonly List<string> _parents = new List<string> {
"Overlay", "Hud", "OverlayNonScaled"
}
, _fonts = new List<string> {
"droidsansmono.ttf", "permanentmarker.ttf", "robotocondensed-bold.ttf", "robotocondensed-regular.ttf"
}
;
private readonly Dictionary<string, string> _anchors = new Dictionary<string, string> {
["0 0"]
= "0 0", ["0.5 0"] = "0.5 0", ["1 0"] = "1 0", ["0 0.5"] = "0 0.5", ["0.5 0.5"] = "0.5 0.5", ["1 0.5"] = "1 0.5", ["0 1"] = "0 1", ["0.5 1"] = "0.5 1", ["1 1"] = "1 1"
}
;
private Dictionary<BasePlayer, DateTime> Cooldowns = new Dictionary<BasePlayer, DateTime>();
private class Offsets {
public int Amount;
public int OffsetMinX;
public int OffsetMinY;
public int OffsetMaxX;
public int OffsetMaxY;
public Offsets(int amount, int offsetminx, int offsetminy, int offsetmaxx, int offsetmaxy) {
Amount = amount;
OffsetMinX = offsetminx;
OffsetMinY = offsetminy;
OffsetMaxX = offsetmaxx;
OffsetMaxY = offsetmaxy;
}
}
private Dictionary<ulong, Offsets> _offsets = new Dictionary<ulong, Offsets>();
private readonly List<(string, string)> _move = new List<(string, string)> {
("+", "fb_open_s_i_move upMinX"), ("+", "fb_open_s_i_move upMinY"), ("+", "fb_open_s_i_move upMaxX"), ("+", "fb_open_s_i_move upMaxY"), ("-", "fb_open_s_i_move downMinX"), ("-", "fb_open_s_i_move downMinY"), ("-", "fb_open_s_i_move downMaxX"), ("-", "fb_open_s_i_move downMaxY")
}
;
private const string _c1 = "0.8 0.8 0.8 0.75";
private const string _c2 = "0.5 0.5 0.5 0.5";
private const string _c3 = "0.8 0.8 0.8 0.375";
private const string _c4 = "0.8 0.8 0.8 1";
private const string _c5 = "0.968 0.917 0.878 0.329";
private const string _c6 = "0.5 0.5 0.5 0.25";
private const string _c7 = "0.5 0.5 0.5 0.4";
private const string _f1 = "robotocondensed-regular.ttf";
#region Reference
[PluginReference]
private Plugin ImageLibrary;
#endregion
#region Config
private FastButtonsConfig config;
private class FastButtonsConfig {
internal class GeneralSetting {
[JsonProperty(LanguageEnglish ? "Maximum number of buttons a player can create" : "Максимальное кол-во кнопок которые может создать игрок")]
public int MaxCustomButtons;
[JsonProperty(LanguageEnglish ? "Maximum number of individual buttons a player can create" : "Максимальное кол-во отдельных кнопок которые может создать игрок")]
public int MaxCustomButtonsIndividual;
[JsonProperty(LanguageEnglish ? "List of server buttons - [ You can only configure parameters - Text, Command, Color, Font ]" : "Список серверных кнопок - [ Вы можете настроить только параметры - Text, Command, Color, Font ]")]
public List<Buttons> ListButtons;
[JsonProperty(LanguageEnglish ? "List of individual server buttons - [ You can configure all parameters ]" : "Список отдельных серверных кнопок - [ Вы можете настроить все параметры ]")]
public List<Buttons> ListButtonsIndividual;
}
internal class GUISetting {
[JsonProperty(LanguageEnglish ? "Color_background_1" : "Цвет_фон_1")]
public string BColor1;
[JsonProperty(LanguageEnglish ? "Color_background_2" : "Цвет_фон_2")]
public string BColor2;
[JsonProperty(LanguageEnglish ? "Close button (icon) color" : "Цвет кнопки (иконки) закрыть")]
public string IconColor;
[JsonProperty(LanguageEnglish ? "Server image list - [ These images are not available to players ]" : "Список серверных изображений - [ Данные изображения недоступны игрокам ]")]
public Dictionary<string, string> ListServerImages;
[JsonProperty(LanguageEnglish ? "Image list - [ These images are available for players to select ]" : "Список изображений - [ Данные изображения доступны игрокам для выбора ]")]
public Dictionary<string, string> ListImages;
[JsonProperty(LanguageEnglish ? "List of button colors" : "Список цветов кнопок")]
public List<string> ListColors;
}
[JsonProperty(LanguageEnglish ? "General setting" : "Общие настройки")]
public GeneralSetting Setting = new GeneralSetting();
[JsonProperty(LanguageEnglish ? "GUI setting" : "Настройки GUI")]
public GUISetting GUI = new GUISetting();
public static FastButtonsConfig GetNewConfiguration() {
return new FastButtonsConfig {
Setting = new GeneralSetting {
MaxCustomButtons = 6, MaxCustomButtonsIndividual = 5, ListButtons = new List<Buttons> {
new Buttons("KIT START", "chat.say \"/kit start\"", "1 0 0 0.5", _f1, false, null, null, null, null, null, null), new Buttons("KIT HOME", "chat.say \"/kit home\"", "1 1 0 0.5", _f1, false, null, null, null, null, null, null), new Buttons("KIT VIP", "chat.say \"/kit vip\"", "0 1 1 0.5", _f1, false, null, null, null, null, null, null), new Buttons("SET HOME", "chat.say /sethome", "1 0.27 0 0.5", _f1, false, null, null, null, null, null, null), new Buttons("HOME - 1", "chat.say \"/home 1\"", "0.2 0.8 0.2 0.5", _f1, false, null, null, null, null, null, null), new Buttons("HOME - 2", "chat.say \"/home 2\"", "0.2 0.8 0.2 0.5", _f1, false, null, null, null, null, null, null)
}
, ListButtonsIndividual = new List<Buttons> {
new Buttons(null, "chat.say /menu", "0 0 0 0", null, true, "Overlay", "FB_SERVER_LOGO", "0 1", "0 1", "5 -55", "55 -5"), new Buttons(null, "chat.say \"/grade 1\"", _c7, null, true, "Overlay", "FB_IMAGE_36", "1 0", "1 0", "-229 16", "-210 35"), new Buttons(null, "chat.say \"/grade 2\"", _c7, null, true, "Overlay", "FB_IMAGE_37", "1 0", "1 0", "-229 37", "-210 56"), new Buttons(null, "chat.say \"/grade 3\"", _c7, null, true, "Overlay", "FB_IMAGE_38", "1 0", "1 0", "-229 58", "-210 77"), new Buttons(null, "chat.say \"/grade 4\"", _c7, null, true, "Overlay", "FB_IMAGE_39", "1 0", "1 0", "-229 79", "-210 98"), new Buttons(null, "chat.say \"/grade 0\"", _c7, null, true, "Overlay", "FB_CANCEL", "1 0", "1 0", "-250 16", "-231 35"), new Buttons(null, "chat.say /remove", _c7, null, true, "Overlay", "FB_REMOVE", "1 0", "1 0", "-250 37", "-231 56"), new Buttons(null, "chat.say /stats", _c7, null, true, "Overlay", "FB_IMAGE_56", "0.5 0", "0.5 0", "-232 18", "-203 47"), new Buttons(null, "chat.say /bskin", _c7, null, true, "Overlay", "FB_IMAGE_57", "0.5 0", "0.5 0", "-263 18", "-234 47"), new Buttons(null, "chat.say /kit", _c7, null, true, "Overlay", "FB_IMAGE_58", "0.5 0", "0.5 0", "-232 49", "-203 78"), new Buttons(null, "chat.say /skin", _c7, null, true, "Overlay", "FB_IMAGE_60", "0.5 0", "0.5 0", "-263 49", "-234 78"),
}
}
, GUI = new GUISetting {
BColor1 = "0.517 0.521 0.509 1", BColor2 = "0.217 0.221 0.209 1", IconColor = "1 1 1 0.75", ListServerImages = new Dictionary<string, string> {
["FB_SERVER_LOGO"]
= "https://i.ibb.co/PNXnns7/000.png", ["FB_CANCEL"] = "https://i.ibb.co/NrGmwvk/002.png", ["FB_REMOVE"] = "https://i.ibb.co/5BvSq2g/003.png"
}
, ListImages = new Dictionary<string, string> {
["FB_IMAGE_01"]
= "https://i.ibb.co/Xy9Bxdx/01.png", ["FB_IMAGE_02"] = "https://i.ibb.co/ZhsGdYh/02.png", ["FB_IMAGE_03"] = "https://i.ibb.co/q1w5701/03.png", ["FB_IMAGE_04"] = "https://i.ibb.co/GcjpQRS/04.png", ["FB_IMAGE_05"] = "https://i.ibb.co/tMXzW5N/05.png", ["FB_IMAGE_06"] = "https://i.ibb.co/6r35Rc6/06.png", ["FB_IMAGE_07"] = "https://i.ibb.co/m5MqV7w/07.png", ["FB_IMAGE_08"] = "https://i.ibb.co/TbjkpMT/08.png", ["FB_IMAGE_09"] = "https://i.ibb.co/PY2SN0N/09.png", ["FB_IMAGE_10"] = "https://i.ibb.co/YtpkCH5/10.png", ["FB_IMAGE_11"] = "https://i.ibb.co/bvW8Snj/11.png", ["FB_IMAGE_12"] = "https://i.ibb.co/RvxWyQT/12.png", ["FB_IMAGE_13"] = "https://i.ibb.co/MhVY9Lg/13.png", ["FB_IMAGE_14"] = "https://i.ibb.co/CsP2Bcc/14.png", ["FB_IMAGE_15"] = "https://i.ibb.co/9qG5rgv/15.png", ["FB_IMAGE_16"] = "https://i.ibb.co/hX4BYpL/16.png", ["FB_IMAGE_17"] = "https://i.ibb.co/VCJgr4q/17.png", ["FB_IMAGE_18"] = "https://i.ibb.co/Lg43PPT/18.png", ["FB_IMAGE_19"] = "https://i.ibb.co/vD1GMKk/19.png", ["FB_IMAGE_20"] = "https://i.ibb.co/Nt9tQNv/20.png", ["FB_IMAGE_21"] = "https://i.ibb.co/Rv3gkq7/21.png", ["FB_IMAGE_22"] = "https://i.ibb.co/dKVGRJ7/22.png", ["FB_IMAGE_23"] = "https://i.ibb.co/YpwxN6p/23.png", ["FB_IMAGE_24"] = "https://i.ibb.co/syGztRF/24.png", ["FB_IMAGE_25"] = "https://i.ibb.co/2jSc1Ch/25.png", ["FB_IMAGE_26"] = "https://i.ibb.co/p3Z08pY/26.png", ["FB_IMAGE_27"] = "https://i.ibb.co/9YrVkg0/27.png", ["FB_IMAGE_28"] = "https://i.ibb.co/HHbS3tR/28.png", ["FB_IMAGE_29"] = "https://i.ibb.co/bzVjLH9/29.png", ["FB_IMAGE_30"] = "https://i.ibb.co/BGDgjkT/30.png", ["FB_IMAGE_31"] = "https://i.ibb.co/YddYrSK/31.png", ["FB_IMAGE_32"] = "https://i.ibb.co/nkjJnPj/32.png", ["FB_IMAGE_33"] = "https://i.ibb.co/J2tGX3M/33.png", ["FB_IMAGE_34"] = "https://i.ibb.co/CvffCjy/34.png", ["FB_IMAGE_35"] = "https://i.ibb.co/dLV7TDq/35.png", ["FB_IMAGE_36"] = "https://i.ibb.co/gyxpKg3/36.png", ["FB_IMAGE_37"] = "https://i.ibb.co/kyJqpNn/37.png", ["FB_IMAGE_38"] = "https://i.ibb.co/2SBpcH1/38.png", ["FB_IMAGE_39"] = "https://i.ibb.co/G3m8YZw/39.png", ["FB_IMAGE_40"] = "https://i.ibb.co/qR2q3vB/40.png", ["FB_IMAGE_41"] = "https://i.ibb.co/NZhW591/41.png", ["FB_IMAGE_42"] = "https://i.ibb.co/rmqvKKw/42.png", ["FB_IMAGE_43"] = "https://i.ibb.co/FnThcgJ/43.png", ["FB_IMAGE_44"] = "https://i.ibb.co/xSsMg0R/44.png", ["FB_IMAGE_45"] = "https://i.ibb.co/N2YbMPw/45.png", ["FB_IMAGE_46"] = "https://i.ibb.co/WgbDxgH/46.png", ["FB_IMAGE_47"] = "https://i.ibb.co/LCt4TPB/47.png", ["FB_IMAGE_48"] = "https://i.ibb.co/d7zMh2W/48.png", ["FB_IMAGE_49"] = "https://i.ibb.co/Sc052qM/49.png", ["FB_IMAGE_50"] = "https://i.ibb.co/4VJV75h/50.png", ["FB_IMAGE_51"] = "https://i.ibb.co/F53P9CP/51.png", ["FB_IMAGE_52"] = "https://i.ibb.co/xhKHVvX/52.png", ["FB_IMAGE_53"] = "https://i.ibb.co/R63NwHC/53.png", ["FB_IMAGE_54"] = "https://i.ibb.co/MktdqYk/54.png", ["FB_IMAGE_55"] = "https://i.ibb.co/L6btMHf/55.png", ["FB_IMAGE_56"] = "https://i.ibb.co/Y85DVh7/56.png", ["FB_IMAGE_57"] = "https://i.ibb.co/5T8Lgv1/57.png", ["FB_IMAGE_58"] = "https://i.ibb.co/ss40N2J/58.png", ["FB_IMAGE_59"] = "https://i.ibb.co/gFnGRbQ/59.png", ["FB_IMAGE_60"] = "https://i.ibb.co/qgTDGKj/60.png"
}
, ListColors = new List<string> {
"0.98 0.5 0.45 0.7", "0.98 0.5 0.45 0.5", "0.98 0.5 0.45 0.3", "1 0 0 0.7", "1 0 0 0.5", "1 0 0 0.3", "1 0.41 0.71 0.7", "1 0.41 0.71 0.5", "1 0.41 0.71 0.3", "1 0.08 0.58 0.7", "1 0.08 0.58 0.5", "1 0.08 0.58 0.3", "1 0.27 0 0.7", "1 0.27 0 0.5", "1 0.27 0 0.3", "1 0.65 0 0.7", "1 0.65 0 0.5", "1 0.65 0 0.3", "1 0.84 0 0.7", "1 0.84 0 0.5", "1 0.84 0 0.3", "1 1 0 0.7", "1 1 0 0.5", "1 1 0 0.3", "1 0.89 0.71 0.7", "1 0.89 0.71 0.5", "1 0.89 0.71 0.3", "0.87 0.63 0.87 0.7", "0.87 0.63 0.87 0.5", "0.87 0.63 0.87 0.3", "1 0 1 0.7", "1 0 1 0.5", "1 0 1 0.3", "0.5 0 0.5 0.7", "0.5 0 0.5 0.5", "0.5 0 0.5 0.3", "0.29 0 0.51 0.7", "0.29 0 0.51 0.5", "0.29 0 0.51 0.3", "0.68 1 0.18 0.7", "0.68 1 0.18 0.5", "0.68 1 0.18 0.3", "0 1 0 0.7", "0 1 0 0.5", "0 1 0 0.3", "0.2 0.8 0.2 0.7", "0.2 0.8 0.2 0.5", "0.2 0.8 0.2 0.3", "0 0.5 0 0.7", "0 0.5 0 0.5", "0 0.5 0 0.3", "0.5 0.5 0 0.7", "0.5 0.5 0 0.5", "0.5 0.5 0 0.3", "0.4 0.8 0.67 0.7", "0.4 0.8 0.67 0.5", "0.4 0.8 0.67 0.3", "0 1 1 0.7", "0 1 1 0.5", "0 1 1 0.3", "0 0.81 0.82 0.7", "0 0.81 0.82 0.5", "0 0.81 0.82 0.3", "0 0 1 0.7", "0 0 1 0.5", "0 0 1 0.3", "0 0 0.55 0.7", "0 0 0.55 0.5", "0 0 0.55 0.3", "0.86 0.86 0.86 0.7", "0.86 0.86 0.86 0.5", "0.86 0.86 0.86 0.3", "0.66 0.66 0.66 0.7", "0.66 0.66 0.66 0.5", "0.66 0.66 0.66 0.3", "0.5 0.5 0.5 0.7", "0.5 0.5 0.5 0.5", "0.5 0.5 0.5 0.3", "0 0 0 0.7", "0 0 0 0.5", "1 1 1 0.7", "1 1 1 0.5", "1 1 1 0.3", "0 0 0 0"
}
}
}
;
}
}
protected override void LoadConfig() {
base.LoadConfig();
try {
config = Config.ReadObject<FastButtonsConfig>();
}
catch {
PrintWarning(LanguageEnglish ? "Configuration read error! Creating a default configuration!" : "Ошибка чтения конфигурации! Создание дефолтной конфигурации!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => config = FastButtonsConfig.GetNewConfiguration();
protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Data
private class Data {
public bool ServerButtons = true;
public bool CustomButtons = true;
public bool ShowButtons = true;
public int ButtonSize = 31;
public int ButtonsOnPage = 6;
public List<Buttons> ListButtons = new List<Buttons>();
public List<Buttons> ListButtonsIndividual = new List<Buttons>();
}
private Dictionary<ulong, Data> StoredData = new Dictionary<ulong, Data>();
private void LoadData(ulong userID) {
var Data = Interface.Oxide.DataFileSystem.ReadObject<Data>($"XDataSystem/XFastButtons/{userID}");
StoredData[userID] = Data ?? new Data();
}
private void SaveData(ulong userID) {
if(StoredData.ContainsKey(userID)) Interface.Oxide.DataFileSystem.WriteObject($"XDataSystem/XFastButtons/{userID}", StoredData[userID]);
}
#endregion
#region Commands
[ConsoleCommand("fb_open_s")]
private void ccmdSettings(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player == null || args?.Args == null) return;
if(Cooldowns.ContainsKey(player)) if(Cooldowns[player].Subtract(DateTime.Now).TotalSeconds >= 0) return;
Cooldowns[player] = DateTime.Now.AddSeconds(0.2f);
if(!permission.UserHasPermission(player.UserIDString, permUse)) {
SendReply(player, lang.GetMessage("NOPERM", this, player.UserIDString));
return;
}
int.TryParse(args.GetString(1), out int index);
bool.TryParse(args.GetString(2), out bool isEdit);
switch(args.GetString(0)) {
case "open" : {
GUISetting(player);
break;
}
case "cancel" : {
_create_edit_buttons.Remove(player.userID);
CuiHelper.DestroyUi(player, ".CE_GUI");
CuiHelper.DestroyUi(player, ".B_CI_GUI");
CuiHelper.DestroyUi(player, ".CBI.EDIT");
break;
}
case "add" : {
if(StoredData[player.userID].ListButtons.Count < config.Setting.MaxCustomButtons) {
_create_edit_buttons[player.userID] = new Buttons("Text", "chat.say /kit start", _c2, _f1, false, null, null, null, null, null, null);
GUICreateEditButton(player);
}
break;
}
case "addSave" : {
if(_create_edit_buttons.ContainsKey(player.userID)) {
StoredData[player.userID].ListButtons.Add(_create_edit_buttons[player.userID]);
_create_edit_buttons.Remove(player.userID);
GUIButtons(player);
GUISetting(player);
}
break;
}
case "remove" : {
if(index >= 0 && index < StoredData[player.userID].ListButtons.Count) {
StoredData[player.userID].ListButtons.RemoveAt(index);
_create_edit_buttons.Remove(player.userID);
GUIButtons(player);
GUISetting(player);
}
break;
}
case "edit" : {
if(index >= 0 && index < StoredData[player.userID].ListButtons.Count) {
var edit = StoredData[player.userID].ListButtons[index];
_create_edit_buttons[player.userID] = new Buttons(edit.Text, edit.Command, edit.Color, edit.Font, false, null, null, null, null, null, null);
GUICreateEditButton(player, index, isEdit);
}
break;
}
case "editSave" : {
if(index >= 0 && index < StoredData[player.userID].ListButtons.Count && _create_edit_buttons.ContainsKey(player.userID)) {
var edit = _create_edit_buttons[player.userID];
StoredData[player.userID].ListButtons[index] = new Buttons(edit.Text, edit.Command, edit.Color, edit.Font, false, null, null, null, null, null, null);
_create_edit_buttons.Remove(player.userID);
GUIButtons(player);
GUISetting(player);
}
break;
}
case "page" : {
int.TryParse(args.GetString(1), out int page);
GUIButtons(player, page);
break;
}
case "option" : {
switch(args.GetString(1)) {
case "serverButtons" : {
StoredData[player.userID].ServerButtons = !StoredData[player.userID].ServerButtons;
if(!StoredData[player.userID].ServerButtons) RemoveServer(player);
break;
}
case "customButtons" : {
StoredData[player.userID].CustomButtons = !StoredData[player.userID].CustomButtons;
if(!StoredData[player.userID].CustomButtons) RemoveCustom(player);
break;
}
case "showButtons" : {
StoredData[player.userID].ShowButtons = !StoredData[player.userID].ShowButtons;
if(!StoredData[player.userID].ShowButtons) {
RemoveServer(player);
RemoveCustom(player);
}
break;
}
case "buttonSize" : {
int.TryParse(args.GetString(2), out int x);
StoredData[player.userID].ButtonSize = x < 10 ? 10 : x;
break;
}
case "buttonsOnPage" : {
int.TryParse(args.GetString(2), out int x);
StoredData[player.userID].ButtonsOnPage = x < 1 ? 1 : x;
break;
}
}
GUIButtons(player);
GUIButtonsIndividual(player);
GUISetting(player);
break;
}
case "optionCreateEdit" : {
if(_create_edit_buttons.ContainsKey(player.userID)) {
switch(args.GetString(3)) {
case "text" : {
_create_edit_buttons[player.userID].Text = string.Join(" ", args.Args.Skip(4));
break;
}
case "command" : {
if(args.Args.Length > 4) {
if(args.Args[4] == "chat.say") _create_edit_buttons[player.userID].Command = $"{args.Args[4]} \"" + string.Join(" ", args.Args.Skip(5)) + "\"";
else _create_edit_buttons[player.userID].Command = string.Join(" ", args.Args.Skip(4));
}
else _create_edit_buttons[player.userID].Command = "chat.say /kit start";
break;
}
case "color" : {
_create_edit_buttons[player.userID].Color = args.GetString(4, _c2).Replace("'", "");
break;
}
case "font" : {
_create_edit_buttons[player.userID].Font = args.GetString(4, _f1);
break;
}
}
GUICreateEditButton(player, index, isEdit);
if(_create_edit_buttons[player.userID].Individual) GUIButtonIndividual(player);
}
break;
}
}
EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
[ConsoleCommand("fb_open_s_i")]
private void ccmdSettingsIndividual(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player == null || args?.Args == null) return;
if(Cooldowns.ContainsKey(player)) if(Cooldowns[player].Subtract(DateTime.Now).TotalSeconds >= 0) return;
Cooldowns[player] = DateTime.Now.AddSeconds(0.2f);
if(!permission.UserHasPermission(player.UserIDString, permUse)) {
SendReply(player, lang.GetMessage("NOPERM", this, player.UserIDString));
return;
}
int.TryParse(args.GetString(1), out int index);
bool.TryParse(args.GetString(2), out bool isEdit);
switch(args.GetString(0)) {
case "add" : {
if(StoredData[player.userID].ListButtonsIndividual.Count < config.Setting.MaxCustomButtonsIndividual) {
_create_edit_buttons[player.userID] = new Buttons("Text", "chat.say /kit start", _c2, _f1, true, "Overlay", "", "1 0.5", "1 0.5", "-25 -25", "25 25");
_offsets[player.userID] = new Offsets(5, -25, -25, 25, 25);
GUICreateEditButton(player);
GUICreateEditButtonIndividual(player);
GUIButtonIndividual(player);
}
break;
}
case "addSave" : {
if(_create_edit_buttons.ContainsKey(player.userID)) {
_create_edit_buttons[player.userID].OffsetMinXY = $"{_offsets[player.userID].OffsetMinX} {_offsets[player.userID].OffsetMinY}";
_create_edit_buttons[player.userID].OffsetMaxXY = $"{_offsets[player.userID].OffsetMaxX} {_offsets[player.userID].OffsetMaxY}";
StoredData[player.userID].ListButtonsIndividual.Add(_create_edit_buttons[player.userID]);
_create_edit_buttons.Remove(player.userID);
_offsets.Remove(player.userID);
GUIButtonsIndividual(player);
GUISetting(player);
CuiHelper.DestroyUi(player, ".CBI.EDIT");
}
break;
}
case "remove" : {
if(index >= 0 && index < StoredData[player.userID].ListButtonsIndividual.Count) {
RemoveCustom(player);
StoredData[player.userID].ListButtonsIndividual.RemoveAt(index);
_create_edit_buttons.Remove(player.userID);
_offsets.Remove(player.userID);
GUIButtonsIndividual(player);
GUISetting(player);
CuiHelper.DestroyUi(player, ".CBI.EDIT");
}
break;
}
case "edit" : {
if(index >= 0 && index < StoredData[player.userID].ListButtonsIndividual.Count) {
var edit = StoredData[player.userID].ListButtonsIndividual[index];
_create_edit_buttons[player.userID] = new Buttons(edit.Text, edit.Command, edit.Color, edit.Font, edit.Individual, edit.Parent, edit.Image, edit.AnchorMinXY, edit.AnchorMaxXY, edit.OffsetMinXY, edit.OffsetMaxXY);
int[] array1 = edit.OffsetMinXY.Split(' ').Select(str => Convert.ToInt32(str)).ToArray();
int[] array2 = edit.OffsetMaxXY.Split(' ').Select(str => Convert.ToInt32(str)).ToArray();
_offsets[player.userID] = new Offsets(5, array1[0], array1[1], array2[0], array2[1]);
GUICreateEditButton(player, index, isEdit);
GUICreateEditButtonIndividual(player);
GUIButtonIndividual(player);
}
break;
}
case "editSave" : {
if(index >= 0 && index < StoredData[player.userID].ListButtonsIndividual.Count && _create_edit_buttons.ContainsKey(player.userID)) {
_create_edit_buttons[player.userID].OffsetMinXY = $"{_offsets[player.userID].OffsetMinX} {_offsets[player.userID].OffsetMinY}";
_create_edit_buttons[player.userID].OffsetMaxXY = $"{_offsets[player.userID].OffsetMaxX} {_offsets[player.userID].OffsetMaxY}";
var edit = _create_edit_buttons[player.userID];
StoredData[player.userID].ListButtonsIndividual[index] = new Buttons(edit.Text, edit.Command, edit.Color, edit.Font, edit.Individual, edit.Parent, edit.Image, edit.AnchorMinXY, edit.AnchorMaxXY, edit.OffsetMinXY, edit.OffsetMaxXY);
_create_edit_buttons.Remove(player.userID);
_offsets.Remove(player.userID);
GUIButtonsIndividual(player);
GUISetting(player);
CuiHelper.DestroyUi(player, ".CBI.EDIT");
}
break;
}
case "anchor" : {
_create_edit_buttons[player.userID].AnchorMinXY = args.GetString(1, "1 0.5").Replace("'", "");
_create_edit_buttons[player.userID].AnchorMaxXY = args.GetString(2, "1 0.5").Replace("'", "");
GUICreateEditButtonIndividual(player);
GUIButtonIndividual(player);
break;
}
case "image" : {
_create_edit_buttons[player.userID].Image = args.GetString(1, "");
_create_edit_buttons[player.userID].Text = "";
GUICreateEditButtonIndividual(player);
GUIButtonIndividual(player);
break;
}
case "parent" : {
_create_edit_buttons[player.userID].Parent = args.GetString(1, "Overlay");
GUICreateEditButtonIndividual(player);
GUIButtonIndividual(player);
break;
}
}
EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
[ConsoleCommand("fb_open_s_i_move")]
private void ccmdSettingsIndividualMove(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player == null || args?.Args == null) return;
if(Cooldowns.ContainsKey(player)) if(Cooldowns[player].Subtract(DateTime.Now).TotalSeconds >= 0) return;
Cooldowns[player] = DateTime.Now.AddSeconds(0.1f);
if(_offsets.ContainsKey(player.userID)) {
int amount = _offsets[player.userID].Amount;
switch(args.GetString(0)) {
case "amount" : {
int.TryParse(args.GetString(1), out int x);
_offsets[player.userID].Amount = x == 0 ? 5 : x;
break;
}
case "upMinX" : {
_offsets[player.userID].OffsetMinX += amount;
break;
}
case "upMinY" : {
_offsets[player.userID].OffsetMinY += amount;
break;
}
case "upMaxX" : {
_offsets[player.userID].OffsetMaxX += amount;
break;
}
case "upMaxY" : {
_offsets[player.userID].OffsetMaxY += amount;
break;
}
case "downMinX" : {
_offsets[player.userID].OffsetMinX -= amount;
break;
}
case "downMinY" : {
_offsets[player.userID].OffsetMinY -= amount;
break;
}
case "downMaxX" : {
_offsets[player.userID].OffsetMaxX -= amount;
break;
}
case "downMaxY" : {
_offsets[player.userID].OffsetMaxY -= amount;
break;
}
}
GUIButtonIndividualMove(player);
GUIButtonIndividual(player);
EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
}
[ConsoleCommand("fb_use_command")]
private void ccmdUseCommand(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player == null || args?.Args == null) return;
player.SendConsoleCommand(args.GetString(0).Replace("'", ""));
}
#endregion
#region Hooks
private void OnServerInitialized() {
PrintWarning("\n-----------------------------\n" + " Author - Monster\n" + " VK - vk.com/idannopol\n" + " Discord - Monster#4837\n" + "-----------------------------");
BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
if(!ImageLibrary) {
PrintError(LanguageEnglish ? "You don't have the plugin installed - ImageLibrary!" : "У вас не установлен плагин - ImageLibrary!");
Interface.Oxide.UnloadPlugin(Name);
return;
}
timer.Every(90, () => {
foreach(BasePlayer player in BasePlayer.activePlayerList) SaveData(player.userID);
}
);
foreach(var img in config.GUI.ListServerImages) ImageLibrary.Call("AddImage", img.Value, img.Key);
foreach(var img in config.GUI.ListImages) ImageLibrary.Call("AddImage", img.Value, img.Key);
InitializeLang();
permission.RegisterPermission(permUse, this);
}
private void Unload() {
foreach(BasePlayer player in BasePlayer.activePlayerList) {
CuiHelper.DestroyUi(player, ".FB_GUI");
CuiHelper.DestroyUi(player, ".BSetting_GUI");
RemoveServer(player);
if(StoredData.ContainsKey(player.userID)) RemoveCustom(player);
SaveData(player.userID);
}
}
private void OnPlayerConnected(BasePlayer player) {
if(player.IsReceivingSnapshot) {
NextTick(() => OnPlayerConnected(player));
return;
}
LoadData(player.userID);
GUIButtons(player);
GUIButtonsIndividual(player);
}
private void OnPlayerDisconnected(BasePlayer player) {
SaveData(player.userID);
StoredData.Remove(player.userID);
}
#endregion
#region RemovePlayerButtonsIndividual
private void RemoveServer(BasePlayer player) {
int x = 0;
foreach(var button in config.Setting.ListButtonsIndividual) {
CuiHelper.DestroyUi(player, $".BI.{x}");
x++;
}
}
private void RemoveCustom(BasePlayer player) {
int x = 0;
foreach(var button in StoredData[player.userID].ListButtonsIndividual) {
CuiHelper.DestroyUi(player, $".CBI.{x}");
x++;
}
CuiHelper.DestroyUi(player, ".CBI.EDIT");
}
#endregion
#region GUI
private void GUIButtons(BasePlayer player, int Page = 0) {
CuiElementContainer container = new CuiElementContainer();
var data = StoredData[player.userID];
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-9.25 0", OffsetMax = "-9.25 0"
}
, Image = {
Color = "0 0 0 0"
}
}
, "Overlay", ".FB_GUI", ".FB_GUI");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "201.5 35.5", OffsetMax = "216.5 50.5"
}
, Button = {
Color = _c5, Sprite = "assets/icons/gear.png", Command = "fb_open_s open"
}
, Text = {
Text = ""
}
}
, ".FB_GUI");
if(data.ShowButtons) {
List<Buttons> list_buttons = new List<Buttons>();
if(data.ServerButtons) list_buttons.AddRange(config.Setting.ListButtons);
if(data.CustomButtons) list_buttons.AddRange(data.ListButtons);
if(list_buttons.Count != 0) {
int x = 0, count = list_buttons.Count, countOnPage = (count - data.ButtonsOnPage * Page) > data.ButtonsOnPage ? data.ButtonsOnPage : count - data.ButtonsOnPage * Page;
foreach(var button in list_buttons.Skip(data.ButtonsOnPage * Page).Take(countOnPage)) {
double offset = -(data.ButtonSize * countOnPage--) + -(1 * countOnPage--);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{offset} 0", OffsetMax = $"{offset + (data.ButtonSize * 2)} 16"
}
, Button = {
Color = button.Color, Command = $"fb_use_command '{button.Command}'"
}
, Text = {
Text = ""
}
}
, ".FB_GUI", ".BUTTON");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = button.Text, Align = TextAnchor.MiddleCenter, Font = button.Font, FontSize = 10, Color = "1 1 1 0.8"
}
}
, ".BUTTON");
x++;
}
bool back = Page != 0;
bool next = list_buttons.Count > ((Page + 1) * data.ButtonsOnPage);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "192.75 18", OffsetMax = "207.75 33"
}
, Button = {
Color = back ? _c5 : "0.968 0.917 0.878 0.129", Sprite = "assets/icons/enter.png", Command = back ? $"fb_open_s page {Page - 1}" : ""
}
, Text = {
Text = ""
}
}
, ".FB_GUI");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "210.25 18", OffsetMax = "225.25 33"
}
, Button = {
Color = next ? _c5 : "0.968 0.917 0.878 0.129", Sprite = "assets/icons/exit.png", Command = next ? $"fb_open_s page {Page + 1}" : ""
}
, Text = {
Text = ""
}
}
, ".FB_GUI");
}
}
CuiHelper.AddUi(player, container);
}
private void GUISetting(BasePlayer player) {
CuiElementContainer container = new CuiElementContainer();
var data = StoredData[player.userID];
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-199.75 79.25", OffsetMax = "180.25 434"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/icons/greyout.mat"
}
}
, "Overlay", ".BSetting_GUI", ".BSetting_GUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
}
, Image = {
Color = config.GUI.BColor2
}
}
, ".BSetting_GUI", ".Setting_GUI");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-23 -23", OffsetMax = "-3.5 -3.5"
}
, Button = {
Color = config.GUI.IconColor, Sprite = "assets/icons/close.png", Close = ".BSetting_GUI"
}
, Text = {
Text = ""
}
}
, ".Setting_GUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-31.5 -31.5", OffsetMax = "-26.5 0"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".Setting_GUI");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -26.5", OffsetMax = "-31.5 0"
}
, Text = {
Text = lang.GetMessage("TITLE", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 13, Color = "1 1 1 0.75"
}
}
, ".Setting_GUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -31.5", OffsetMax = "0 -26.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".Setting_GUI");
Dictionary<string, bool> s_buttons = new Dictionary<string, bool> {
["serverButtons"]
= data.ServerButtons, ["customButtons"] = data.CustomButtons, ["showButtons"] = data.ShowButtons
}
;
float offset = 12770.35f;
int x = 0, y = 0, z = 0;
foreach(var button in s_buttons) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-179.75 + (x * 121.6)} 115.75", OffsetMax = $"{-63.15 + (x * 121.6)} 135.75"
}
, Button = {
Color = button.Value ? "0.35 0.45 0.25 1" : "0.65 0.29 0.24 1", Command = $"fb_open_s option {button.Key}"
}
, Text = {
Text = lang.GetMessage(button.Key, this, player.UserIDString), Align = TextAnchor.MiddleCenter, Font = _f1, FontSize = 12, Color = button.Value ? "0.75 0.95 0.41 1" : "0.92 0.79 0.76 1"
}
}
, ".Setting_GUI");
x++;
}
Dictionary<string, int> s_inputs = new Dictionary<string, int> {
["buttonSize"]
= data.ButtonSize, ["buttonsOnPage"] = data.ButtonsOnPage
}
;
x = 0;
foreach(var input in s_inputs) {
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-78 + (x * 121.5)} 90.75", OffsetMax = $"{-43 + (x * 121.5)} 110.75"
}
, Image = {
Color = _c2
}
}
, ".Setting_GUI", ".INPUT");
container.Add(new CuiElement {
Parent = ".INPUT", Components = {
new CuiInputFieldComponent {
Text = $"{input.Value}", Align = TextAnchor.MiddleCenter, Font = _f1, FontSize = 10, Command = $"fb_open_s option {input.Key}", CharsLimit = 2, NeedsKeyboard = true, Color = _c4
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
}
}
);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "-55 -14", OffsetMax = "55 -1"
}
, Text = {
Text = lang.GetMessage(input.Key, this, player.UserIDString), Align = TextAnchor.MiddleCenter, Font = _f1, FontSize = 9, Color = _c1
}
}
, ".INPUT");
x++;
}
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -101.5", OffsetMax = "0 -96.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".Setting_GUI");
x = 0;
foreach(var button in data.ListButtons.Take(36)) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-180 + (x * 60.4)} {52.65 - (y * 15.6)}", OffsetMax = $"{-122.1 + (x * 60.4)} {65.75 - (y * 15.6)}"
}
, Button = {
Color = button.Color, Command = $"fb_open_s edit {z} true"
}
, Text = {
Text = button.Text, Align = TextAnchor.MiddleCenter, Font = button.Font, FontSize = 9
}
}
, ".Setting_GUI");
x++;
z++;
if(x == 6) {
x = 0;
y++;
}
}
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -36.5", OffsetMax = "0 -31.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".Setting_GUI");
x = 0;
y = 0;
z = 0;
foreach(var button in data.ListButtonsIndividual.Take(36)) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-180 + (x * 60.4)}
// ... [Code preview truncated due to length. Full source in attached file] ...