C#:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust;
using Oxide.Game.Rust.Cui;
using ProtoBuf;
using Rust;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("BLHelp", "Molik", "1.0.0")]
class BLHelp : RustPlugin
{
#region Конфиг
private ConfigData cfg { get; set; }
private class ConfigData
{
[JsonProperty("Включить открытие при заходе?")]
public bool coonect = false;
[JsonProperty("Список кнопок")]
public Dictionary<string, TextInfo> _itemList = new Dictionary<string, TextInfo>();
public static ConfigData GetNewConf()
{
var newConfig = new ConfigData();
newConfig._itemList = new Dictionary<string, TextInfo>()
{
["Первая страница"] = new TextInfo()
{
Lable = "Текст",
Text = "Бла бла бла бла бла"
},
["Вторая страница"] = new TextInfo()
{
Lable = "Текст",
Text = "Бла бла бла бла бла"
},
["Третья страница"] = new TextInfo()
{
Lable = "Текст",
Text = "Бла бла бла бла бла"
},
["Четвертая страница"] = new TextInfo()
{
Lable = "Текст",
Text = "Бла бла бла бла бла"
},
};
return newConfig;
}
}
protected override void LoadDefaultConfig()
{
cfg = ConfigData.GetNewConf();
}
protected override void SaveConfig()
{
Config.WriteObject(cfg);
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
cfg = Config.ReadObject<ConfigData>();
}
catch
{
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
class TextInfo
{
public string Lable;
public string Text;
}
#endregion
#region Commands
[ChatCommand("help")]
private void cmdOpenGUI(BasePlayer player) => MAIN(player);
[ChatCommand("info")]
private void cmdOpenGUIv2(BasePlayer player) => MAIN(player);
[ConsoleCommand("info_page")]
private void HandlerPage(ConsoleSystem.Arg args)
{
BasePlayer player = args.Player();
MAIN(player, int.Parse(args.Args[0]));
EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
#endregion
#region GUI
private void MAIN(BasePlayer player, int page = 0)
{
CuiHelper.DestroyUi(player, ".Back");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiPanel
{
CursorEnabled = true,
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
Image = { Color = $"{HexToRustFormat("#322D2499")}", Material = "assets/content/ui/uibackgroundblur.mat" }
}, "Overlay", ".Back");
container.Add(new CuiButton
{
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "-300 -300", OffsetMax = "300 300" },
Button = { Color = "0 0 0 0", Close = ".Back" },
Text = { Text = "" }
}, ".Back");
container.Add(new CuiPanel
{
CursorEnabled = true,
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400 -195", OffsetMax = "400 255" },
Image = { Color = HexToRustFormat("#74706A7F"), Material = "assets/icons/greyout.mat" }
}, ".Back", ".Main");
string Label = cfg._itemList.ElementAt(page).Value.Lable;
string mes = cfg._itemList.ElementAt(page).Value.Text;
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-265 100", OffsetMax = "400 220" },
Text = { Text = Label, Align = TextAnchor.UpperCenter, Font = "robotocondensed-bold.ttf", FontSize = 20, Color = "0.9 0.9 0.9 0.7" }
}, ".Main");
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-220 -170", OffsetMax = "400 190" },
Text = { Text = mes, Align = TextAnchor.UpperLeft, Font = "robotocondensed-regular.ttf", FontSize = 15, Color = "1 1 1 0.7" }
}, ".Main");
int x = 0;
int count = cfg._itemList.Count;
foreach (var button in cfg._itemList)
{
string color = page == x ? "0.53 0.77 0.35 0.8" : "0 0 0 0";
container.Add(new CuiButton
{
RectTransform = { AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"15 -{70 + (45 * x)}", OffsetMax = $"170 -{30 + (45 * x)}" },
Button = { Color = "0 0 0 0.5", Material = "assets/content/ui/uibackgroundblur.mat", Command = $"info_page {x}" },
Text = { Text = button.Key, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", FontSize = 16, Color = "1 1 1 0.9" }
}, ".Main", ".BButton");
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0", OffsetMax = "0 2" },
Image = { Color = color, Material = "assets/icons/greyout.mat" }
}, ".BButton");
x++;
}
CuiHelper.AddUi(player, container);
}
#endregion
#region HELPSUKA
string HexToRustFormat(string hex)
{
if (string.IsNullOrEmpty(hex)) hex = "#FFFFFFFF";
var str = hex.Trim('#');
if (str.Length == 6) str += "FF";
if (str.Length != 8) throw new Exception(hex);
var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);
Color color = new Color32(r, g, b, a);
return $"{color.r:F2} {color.g:F2} {color.b:F2} {color.a:F2}";
}
#endregion
}
}