C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Facepunch.Models.Database;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
[Info("InfoTab", "XAVIER", "1.0.0")]
public class InfoTab : RustPlugin {
[PluginReference]
private Plugin ImageLibrary;
void OnServerInitialized() {
if (ImageLibrary == null || !ImageLibrary.IsLoaded) {
PrintError("IMAGE LIBRARY IS NOT INSTALLED!");
}
else {
var imagesList = new Dictionary<string, string>();
if (!imagesList.ContainsKey("https://i.imgur.com/SwlgPMk.png")) // image igrok
imagesList.Add("https://i.imgur.com/SwlgPMk.png", "https://i.imgur.com/SwlgPMk.png");
if (!imagesList.ContainsKey("https://i.imgur.com/i0qM6av.png")) // vpered
imagesList.Add("https://i.imgur.com/i0qM6av.png", "https://i.imgur.com/i0qM6av.png");
if (!imagesList.ContainsKey("https://i.imgur.com/DabDXq4.png")) // nazad
imagesList.Add("https://i.imgur.com/DabDXq4.png", "https://i.imgur.com/DabDXq4.png");
if (!imagesList.ContainsKey("https://i.imgur.com/wTmqCgQ.png")) // palka
imagesList.Add("https://i.imgur.com/wTmqCgQ.png", "https://i.imgur.com/wTmqCgQ.png");
ImageLibrary?.Call("ImportImageList", Title, imagesList, 0UL, true);
}
}
public string HexToCuiColor(string HEX, float Alpha = 100) {
if (string.IsNullOrEmpty(HEX)) HEX = "#FFFFFF";
var str = HEX.Trim('#');
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);
return $"{(double) r / 255} {(double) g / 255} {(double) b / 255} {Alpha / 100}";
}
[ConsoleCommand("open.infotab")]
void OpenInfo(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
CuiHelper.DestroyUi(player, "StaticMenu");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiElement {
Parent = "UI_MenuLayer", Name = "StaticMenu", Components = {
new CuiImageComponent {
Color = "0 0 0 0"
}
, new CuiRectTransformComponent {
AnchorMin = "0.125 0.08333331", AnchorMax = "0.8755208 0.8324074"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0.8850433", AnchorMax = "1 0.8862795", OffsetMax = "0 0"
}
, Button = {
Color = HexToCuiColor("#FBFBFF", 20)
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 23, Color = HexToCuiColor("#BFBFBF"), Align = TextAnchor.MiddleCenter
}
}
, "StaticMenu");
container.Add(new CuiElement {
Parent = "StaticMenu", Components = {
new CuiRawImageComponent {
FadeIn = 0.3f, Png = (string)ImageLibrary.Call("GetImage", "https://i.imgur.com/wTmqCgQ.png")
}
, new CuiRectTransformComponent {
AnchorMin = "0.04788342 0", AnchorMax = "0.06453852 0.8850433"
}
}
}
);
container.Add(new CuiElement {
Parent = "StaticMenu", Components = {
new CuiRawImageComponent {
FadeIn = 0.3f, Png = (string)ImageLibrary.Call("GetImage", "https://i.imgur.com/SwlgPMk.png")
}
, new CuiRectTransformComponent {
AnchorMin = "0.5634975 0", AnchorMax = "1 0.7132263"
}
}
}
);
CuiHelper.AddUi(player, container);
var select = config._infoBlock.FirstOrDefault();
OpenMenuInfo(player, select.Key);
player.SendConsoleCommand($"info.tab select {select.Key}");
}
void OpenMenuInfo(BasePlayer player, string button) {
CuiElementContainer container = new CuiElementContainer();
for (int i = 0; i < config._infoBlock.Count; i++) {
CuiHelper.DestroyUi(player, "StaticMenu" + $".{i}.ListButton");
}
foreach (var check in config._infoBlock.Select((i, t) => new {
A = i, B = t
}
)) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"{0.04510755 + check.B * 0.0700 - Math.Floor((double) check.B / 9) * 9 * 0.0700} {0.8850433 - Math.Floor((double) check.B / 9) * 0.305}", AnchorMax = $"{0.1235253 + check.B * 0.0700 - Math.Floor((double) check.B / 9) * 9 * 0.0700} {0.998764 - Math.Floor((double) check.B / 9) * 0.305}", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = button == check.A.Key ? "" : $"info.tab select {check.A.Key}"
}
, Text = {
Color = button == check.A.Key ? HexToCuiColor("#FBFBFF") : HexToCuiColor($"#FBFBFF", 50), Text = check.A.Key, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 12
}
}
, "StaticMenu", "StaticMenu" + $".{check.B}.ListButton");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0.01086855"
}
, Button = {
Color = button == check.A.Key ? HexToCuiColor("#FBFBFF") : HexToCuiColor($"#BFBFBF", 0),
}
, Text = {
Text = $"", Align = TextAnchor.LowerRight, Font = "robotocondensed-bold.ttf", FontSize = 15
}
}
, "StaticMenu" + $".{check.B}.ListButton");
}
CuiHelper.AddUi(player, container);
}
[ConsoleCommand("info.tab")]
void ConsoleInfo(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if (args.Args[0] == "select") {
var name = args.Args[1];
var select = config._infoBlock.FirstOrDefault(p => p.Key == name);
OpenMenuInfo(player, name);
OpenSelectInfo(player, select, 1);
}
else if (args.Args[0] == "page") {
var name = args.Args[1];
var select = config._infoBlock.FirstOrDefault(p => p.Key == name);
int page = 1;
if (int.TryParse(args.Args[2], out page)) {
OpenSelectInfo(player, select, page);
}
}
}
void OpenSelectInfo(BasePlayer player, KeyValuePair<string, List<string>> list, int page) {
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, "StaticMenu" + "InfoTabTittle");
CuiHelper.DestroyUi(player, "StaticMenu" + "InfoTabText");
CuiHelper.DestroyUi(player, "StaticMenu" + ".back");
CuiHelper.DestroyUi(player, "StaticMenu" + ".next");
int pagex = page + 1;
container.Add(new CuiElement {
Parent = "StaticMenu", Name = "StaticMenu" + ".next", Components = {
new CuiRawImageComponent {
Png = (string)ImageLibrary?.Call("GetImage", "https://i.imgur.com/i0qM6av.png"),
}
, new CuiRectTransformComponent {
AnchorMin = "0.03955585 0.07911004", AnchorMax = "0.07286607 0.1384426"
}
,
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Color = "0 0 0 0", Command = pagex > 0 && (pagex - 1) * 1 < list.Value.Count ? $"info.tab page {list.Key} {page + 1}" : ""
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, "StaticMenu" + ".next");
container.Add(new CuiElement {
Parent = "StaticMenu", Name = "StaticMenu" + ".back", Components = {
new CuiRawImageComponent {
Png = (string)ImageLibrary?.Call("GetImage", "https://i.imgur.com/DabDXq4.png"),
}
, new CuiRectTransformComponent {
AnchorMin = "0.03955585 0.1582202", AnchorMax = "0.07286607 0.2175528"
}
,
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Color = "0 0 0 0", Command = page != 1 ? $"info.tab page {list.Key} {page - 1}" : ""
}
, Text = {
Text = "", Font = "robotocondensed-regular.ttf", FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, "StaticMenu" + ".back");
container.Add(new CuiLabel {
Text = {
Text = list.Key, Font = "robotocondensed-regular.ttf", FontSize = 16, Align = TextAnchor.MiddleLeft, Color = HexToCuiColor("#FBFBFF")
}
, RectTransform = {
AnchorMin = $"0.08605134 0.7812114", AnchorMax = $"0.5634975 0.825711"
}
,
}
, "StaticMenu", "StaticMenu" + "InfoTabTittle");
foreach (var check in list.Value.Select((i, t) => new {
A = i, B = t - (page - 1) * 1
}
).Skip((page - 1) * 1).Take(1)) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"{0.08605134 + check.B * 0.400 - Math.Floor((double)check.B / 1) * 1 * 0.400} {0.2187886 - Math.Floor((double)check.B / 1) * 0.135}", AnchorMax = $"{0.5294935 + check.B * 0.400 - Math.Floor((double)check.B / 1) * 1 * 0.400} {0.7515452 - Math.Floor((double)check.B / 1) * 0.135}", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = $"",
}
, Text = {
Text = check.A, Align = TextAnchor.UpperLeft, Font = "robotocondensed-regular.ttf", FontSize = 12, Color = HexToCuiColor($"#FBFBFF", 40),
}
}
, "StaticMenu", "StaticMenu" + "InfoTabText");
}
CuiHelper.AddUi(player, container);
}
#region Configuration
private PluginConfig config;
protected override void LoadDefaultConfig() {
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig() {
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
if (config.PluginVersion < Version) UpdateConfigValues();
Config.WriteObject(config, true);
}
private void UpdateConfigValues() {
PluginConfig baseConfig = PluginConfig.DefaultConfig();
if (config.PluginVersion < new VersionNumber(1, 0, 8)) {
PrintWarning("Config update detected! Updating config values...");
PrintWarning("Config update completed!");
}
config.PluginVersion = Version;
}
protected override void SaveConfig() {
Config.WriteObject(config);
}
private class PluginConfig {
[JsonProperty("Настройка информации")]
public Dictionary<string, List<string>> _infoBlock = new Dictionary<string, List<string>>();
[JsonProperty("Verison Configuration")]
public VersionNumber PluginVersion = new VersionNumber();
public static PluginConfig DefaultConfig() {
return new PluginConfig() {
_infoBlock = new Dictionary<string, List<string>>() {
["Чат"]
= new List<string>() {
{
"1.Запрещено предлагать сделать действия, приводящие к нежеланному выходу с сервера.\n2.К таким действиям относится нажатие alt+f4, прописывание disconnect в консоль и прочие подобные действия, о значении которых другие игроки могут не знать.\n3.Запрещена любая клевета, дезинформация или ложь про игроков, администрацию и сервер.\n4.Запрещено выдавать себя за администратора, модератора или любого ютубера, если Вы на самом деле им не являетесь."
}
, {
"Еще какой то текст\nТут вот да"
}
, {
"Еще какой то текст\nТут вот да"
}
,
}
, ["Плагины"] = new List<string>() {
{
"Еще какой то текст\nТут вот да"
}
, {
"Еще какой то текст\nТут вот да"
}
, {
"Еще какой то текст\nТут вот да"
}
,
}
}
, PluginVersion = new VersionNumber(),
}
;
}
}
#endregion
}
}