C#:
// Requires: ServerPanel
// #define TESTING
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using UnityEngine.UI;
#if CARBON
using Carbon.Base;
using Carbon.Modules;
#endif
namespace Oxide.Plugins {
[Info("ServerPanel Installer", "Mevent", "1.1.1")]
public class ServerPanelInstaller : RustPlugin {
#region Fields
[PluginReference]
private Plugin ImageLibrary = null, ServerPanelPopUps = null;
private static ServerPanelInstaller Instance;
private ServerPanel ServerPanel = null;
#if CARBON
private ImageDatabaseModule imageDatabase;
#endif
private bool _enabledImageLibrary;
private const string PERM_ADMIN = "serverpanelinstaller.admin", CmdMainConsole = "UI_ServerPanelInstaller", Layer = "UI.Server.Panel.Installer";
#endregion
#region Hooks
private void Init() {
Instance = this;
}
private void OnServerInitialized() {
ServerPanel = (ServerPanel) plugins.Find(nameof(ServerPanel));
LoadServerPanelTemplatesData();
RegisterPermissions();
RegisterCommands();
}
private void Unload() {
Instance = null;
}
#endregion
#region Commands
private void CmdOpenInstaller(IPlayer covPlayer, string command, string[] args) {
var player = covPlayer.Object as BasePlayer;
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PERM_ADMIN)) {
PrintError($"Player {player.UserIDString} does not have permission to install server panel!");
return;
}
ShowInstallerUI(player);
}
[ConsoleCommand(CmdMainConsole)]
private void ConsoleMainInstaller(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (player == null) return;
switch (arg.GetString(0)) {
case "cancel" : {
PanelInstaller.Destroy(player.userID);
break;
}
case "finish" : {
PanelInstaller.Finish(player.userID);
break;
}
case "change_step" : {
if (!arg.HasArgs(2)) return;
var panelInstaller = PanelInstaller.Get(player.userID);
if (panelInstaller == null) return;
var nextStep = arg.GetInt(1);
switch (nextStep) {
case 4 : {
if (panelInstaller.SelectedTemplate < 0) {
ErrorUi(player, "Please select a template!");
return;
}
break;
}
}
panelInstaller.SetStep(nextStep);
ShowInstallerUI(player);
break;
}
case "set_field" : {
if (!arg.HasArgs(3)) return;
var field = arg.GetString(1);
if (string.IsNullOrEmpty(field)) return;
var value = string.Join(" ", arg.Args.Skip(2));
if (string.IsNullOrEmpty(value)) return;
var panelInstaller = PanelInstaller.Get(player.userID);
if (panelInstaller == null) return;
panelInstaller.SetField(field, value);
UpdateUI(player, container => {
LoopPreConfigFields(player, container);
}
);
break;
}
case "select_template" : {
if (!arg.HasArgs(2)) return;
var templateIndex = arg.GetInt(1);
var panelInstaller = PanelInstaller.Get(player.userID);
if (panelInstaller == null) return;
panelInstaller.SelectTemplate(templateIndex);
UpdateUI(player, container => {
LoopTemplates(player, container);
}
);
break;
}
}
}
#endregion
#region Interface
private const int UI_Installer_Template_Margin_X = 19, UI_Installer_Template_Margin_Y = 20, UI_Installer_Template_Width = 350, UI_Installer_Template_Height = 192;
private void ShowInstallerUI(BasePlayer player) {
var installer = PanelInstaller.GetOrCreate(player.userID);
var container = new CuiElementContainer();
#region Background
container.Add(new CuiPanel {
CursorEnabled = true, Image = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0 0 0 1"
}
, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
}
, "Overlay", Layer, Layer);
#endregion Background
#region Header
container.Add(new CuiPanel {
Image = {
Color = HexToCuiColor("#929292", 5), Material = "assets/content/ui/namefontmaterial.mat",
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -112", OffsetMax = "0 0"
}
}
, Layer, Layer + ".Header", Layer + ".Header");
#region Title
container.Add(new CuiElement {
Parent = Layer + ".Header", Components = {
new CuiTextComponent {
Text = Msg(player, UIHeaderTitle), Font = "robotocondensed-bold.ttf", FontSize = 32, Align = TextAnchor.LowerLeft, Color = "0.6 0.6078432 0.6117647 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "90 46", OffsetMax = "0 0"
}
}
}
);
#endregion Title
#region Description
container.Add(new CuiElement {
Parent = Layer + ".Header", Components = {
new CuiTextComponent {
Text = Msg(player, UIHeaderDescription), Font = "robotocondensed-regular.ttf", FontSize = 14, Align = TextAnchor.UpperLeft, Color = "0.6 0.6078432 0.6117647 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "90 0", OffsetMax = "0 -68"
}
}
}
);
#endregion Description
#region Icon
container.Add(new CuiElement {
Parent = Layer + ".Header", Components = {
new CuiRawImageComponent {
Png = GetImage("ServerPanel_Installer_HeaderIcon")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "45 -20", OffsetMax = "80 20"
}
}
}
);
#endregion Icon
#region Button.Close
container.Add(new CuiPanel {
Image = {
Color = "0.8941177 0.2509804 0.1568628 1", Material = "assets/content/ui/namefontmaterial.mat",
}
, RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-40 -40", OffsetMax = "0 0"
}
}
, Layer + ".Header", Layer + ".Header.Button.Close", Layer + ".Header.Button.Close");
#region Icon
container.Add(new CuiPanel {
Image = {
Color = "1 1 1 0.9", Sprite = "assets/icons/close.png"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-11 -11", OffsetMax = "11 11"
}
}
, Layer + ".Header.Button.Close");
#endregion Icon
container.Add(new CuiElement() {
Parent = Layer + ".Header.Button.Close", Components = {
new CuiButtonComponent() {
Close = Layer, Color = "0 0 0 0"
}
, new CuiRectTransformComponent()
}
}
);
#endregion
#endregion Header
#region Steps
switch (installer.step) {
case 1 : ShowWelcomeStep(player, container, installer.step);
break;
case 2 : ShowDependenciesStep(player, container, installer.step);
break;
case 3 : ShowSelectTemplateStep(player, container, installer.step);
break;
case 4 : ShowPreConfigureStep(player, container, installer.step);
break;
case 5 : ShowFinishStep(player, container);
break;
}
#endregion
CuiHelper.AddUi(player, container);
}
private void ErrorUi(BasePlayer player, string msg) {
var container = new CuiElementContainer();
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Image = {
Color = HexToCuiColor("#161617", 85)
}
}
, "Overlay", Layer + ".Modal", Layer + ".Modal");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-127.5 -75", OffsetMax = "127.5 140"
}
, Image = {
Color = HexToCuiColor("#FF4B4B")
}
}
, Layer + ".Modal", Layer + ".Modal.Main");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -165", OffsetMax = "0 0"
}
, Text = {
Text = "XXX", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", FontSize = 120, Color = HexToCuiColor("#FFFFFF")
}
}
, Layer + ".Modal.Main");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -175", OffsetMax = "0 -155"
}
, Text = {
Text = $"{msg}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 12, Color = HexToCuiColor("#FFFFFF")
}
}
, Layer + ".Modal.Main");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "0 0", OffsetMax = "0 30"
}
, Text = {
Text = "X", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 12, Color = HexToCuiColor("#FFFFFF")
}
, Button = {
Color = HexToCuiColor("#CD3838"), Close = Layer + ".Modal"
}
}
, Layer + ".Modal.Main");
CuiHelper.AddUi(player, container);
}
#region UI.Steps
private void ShowFinishStep(BasePlayer player, CuiElementContainer container) {
#region Background
container.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -360", OffsetMax = "0 248"
}
}
, Layer, Layer + ".Main", Layer + ".Main");
#endregion
#region Label.Welcome
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIFinishTitle), Font = "robotocondensed-regular.ttf", FontSize = 32, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400 196", OffsetMax = "400 252"
}
}
}
);
#endregion Label.Welcome
#region Label.Thank.For.Buy
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIFinishDescription), Font = "robotocondensed-regular.ttf", FontSize = 16, Align = TextAnchor.UpperCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400 -114", OffsetMax = "400 151"
}
}
}
);
#endregion Label.Thank.For.Buy
#region QR.Panel
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-120 63", OffsetMax = "120 137"
}
}
, Layer + ".Main", Layer + ".QR.Panel");
#region qr code
container.Add(new CuiElement {
Parent = Layer + ".QR.Panel", Components = {
new CuiRawImageComponent {
Png = GetImage("ServerPanel_Installer_Mevent_Discord_QR")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "0 -37", OffsetMax = "74 37"
}
}
}
);
#endregion qr code
#region title
container.Add(new CuiElement {
Parent = Layer + ".QR.Panel", Components = {
new CuiTextComponent {
Text = Msg(player, UIQRMeventDiscordTitle), Font = "robotocondensed-regular.ttf", FontSize = 14, Align = TextAnchor.MiddleLeft, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "90 40", OffsetMax = "0 -12"
}
}
}
);
#endregion title
#region description
container.Add(new CuiElement {
Parent = Layer + ".QR.Panel", Components = {
new CuiInputFieldComponent() {
Text = "https://discord.gg/kWtvUaTyBh", Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.UpperLeft, Color = "0.8862745 0.8588235 0.827451 0.5019608", HudMenuInput = true
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "90 0", OffsetMax = "0 -35"
}
}
}
);
#endregion description
#endregion QR.Panel
#region Btn.Start.Install
container.Add(new CuiButton() {
Button = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0 0.372549 0.7176471 1", Command = $"{CmdMainConsole} finish", Close = Layer
}
, Text = {
Text = Msg(player, BtnFinish), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-120 -114", OffsetMax = "120 -54"
}
}
, Layer + ".Main");
#endregion Btn.Start.Install
#region Line
container.Add(new CuiPanel {
Image = {
Color = "0.2156863 0.2156863 0.2156863 0.5019608"
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "360 -127", OffsetMax = "-360 -125"
}
}
, Layer + ".Main");
#endregion Line
}
private const int PreConfig_Field_Margin_X = 19, PreConfig_Field_Margin_Y = 20, PreConfig_Field_Width = 220, PreConfig_Field_Height = 65;
private void ShowPreConfigureStep(BasePlayer player, CuiElementContainer container, int step) {
#region Background
container.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -360", OffsetMax = "0 248"
}
}
, Layer, Layer + ".Main", Layer + ".Main");
#endregion
var panelInstaller = PanelInstaller.Get(player.userID);
#region Label.Welcome
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIPreConfigureTitle), Font = "robotocondensed-regular.ttf", FontSize = 32, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 500", OffsetMax = "0 -52"
}
}
}
);
#endregion Label.Welcome
#region Line
container.Add(new CuiPanel {
Image = {
Color = "0.2156863 0.2156863 0.2156863 0.5019608"
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "280 -127", OffsetMax = "-280 -125"
}
}
, Layer + ".Main");
#endregion Line
#region Label.Thank.For.Buy
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIPreConfigureDescription), Font = "robotocondensed-regular.ttf", FontSize = 16, Align = TextAnchor.UpperCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "50 410", OffsetMax = "-50 -153"
}
}
}
);
#endregion Label.Thank.For.Buy
#region ScrollView
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-360 -616", OffsetMax = "377 -200"
}
}
, Layer + ".Main", Layer + ".ScrollView", Layer + ".ScrollView");
#endregion ScrollView
#region Fields
LoopPreConfigFields(player, container);
#endregion
#region Hover
container.Add(new CuiElement {
Name = Layer + ".Hover", Parent = Layer + ".Main", Components = {
new CuiRawImageComponent {
Color = "0 0 0 1", Sprite = "assets/content/ui/UI.Background.Transparent.Linear.psd"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "0 0", OffsetMax = "0 105"
}
}
}
);
#endregion Hover
#region Btn.Accept
container.Add(new CuiButton() {
Button = {
Color = "0 0.372549 0.7176471 1", Command = $"{CmdMainConsole} change_step {step + 1}"
}
, Text = {
Text = Msg(player, BtnAccept), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "10 20", OffsetMax = "140 62"
}
}
, Layer + ".Main");
#endregion Btn.Accept
#region Btn.Go.Back
container.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-140 20", OffsetMax = "-10 62"
}
, Text = {
Text = Msg(player, BtnGoBack), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 0.6"
}
, Button = {
Color = "0.145098 0.145098 0.145098 1", Command = $"{CmdMainConsole} change_step {step - 1}"
}
,
}
, Layer + ".Main");
#endregion Btn.Go.Back
}
private static void LoopPreConfigFields(BasePlayer player, CuiElementContainer container) {
var panelInstaller = PanelInstaller.Get(player.userID);
var offsetX = 0;
var offsetY = 0;
for (var i = 0; i < panelInstaller.Fields.Count; i++) {
var panelField = panelInstaller.Fields[i];
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{offsetX} {offsetY - PreConfig_Field_Height}", OffsetMax = $"{offsetX + PreConfig_Field_Width} {offsetY}"
}
}
, Layer + ".ScrollView", Layer + $".Fields.{i}", Layer + $".Fields.{i}");
#region Title
container.Add(new CuiElement {
Parent = Layer + $".Fields.{i}", Components = {
new CuiTextComponent {
Text = panelField.Title, Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.UpperLeft, Color = "0.8862745 0.8588235 0.827451 0.5019608"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 42", OffsetMax = "0 0"
}
}
}
);
#endregion Title
#region Input.Panel
container.Add(new CuiPanel {
Image = {
Color = "0.572549 0.572549 0.572549 0.2"
}
, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 0", OffsetMax = "0 -23"
}
}
, Layer + $".Fields.{i}", Layer + $".Fields.{i}.Input.Panel");
#region Value
container.Add(new CuiElement {
Parent = Layer + $".Fields.{i}.Input.Panel", Components = {
new CuiInputFieldComponent() {
Text = $"{panelField.Value}", Font = "robotocondensed-regular.ttf", FontSize = 14, Align = TextAnchor.MiddleLeft, Color = HexToCuiColor("#FFFFFF"), Command = $"{CmdMainConsole} set_field {panelField.Key}", HudMenuInput = true, NeedsKeyboard = true
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "15 0", OffsetMax = "0 0"
}
}
}
);
#endregion Value
#endregion Input.Panel
#region Calculate Position
if ((i + 1) % 3 == 0) {
offsetX = 0;
offsetY = offsetY - PreConfig_Field_Height - PreConfig_Field_Margin_Y;
}
else {
offsetX += PreConfig_Field_Width + PreConfig_Field_Margin_X;
}
#endregion
}
}
private void ShowSelectTemplateStep(BasePlayer player, CuiElementContainer container, int step) {
var panelInstaller = PanelInstaller.Get(player.userID);
if (panelInstaller == null) return;
#region Background
container.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -360", OffsetMax = "0 248"
}
}
, Layer, Layer + ".Main", Layer + ".Main");
#endregion
#region Label.Message
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UISelectTemplateDescription), Font = "robotocondensed-regular.ttf", FontSize = 16, Align = TextAnchor.UpperCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "50 476", OffsetMax = "-50 -60"
}
}
}
);
#endregion Label.Message
#region Line
container.Add(new CuiPanel {
Image = {
Color = HexToCuiColor("#373737", 50)
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "280 -159", OffsetMax = "-280 -157"
}
}
, Layer + ".Main");
#endregion Line
#region ScrollView
var templateLines = Mathf.CeilToInt(_installerData.Templates.Count / 2f);
var totalHeight = templateLines * UI_Installer_Template_Height + (templateLines - 1) * UI_Installer_Template_Margin_Y;
totalHeight += 100;
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-360 -597", OffsetMax = "377 -181"
}
}
, Layer + ".Main", Layer + ".ScrollBackground");
container.Add(new CuiElement() {
Parent = Layer + ".ScrollBackground", Name = Layer + ".ScrollView", DestroyUi = Layer + ".ScrollView", Components = {
new CuiScrollViewComponent {
MovementType = ScrollRect.MovementType.Elastic, Vertical = true, Inertia = true, Horizontal = false, Elasticity = 0.25f, DecelerationRate = 0.3f, ScrollSensitivity = 24f, ContentTransform = new CuiRectTransform {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"0 -{totalHeight}", OffsetMax = "0 0"
}
, VerticalScrollbar = new CuiScrollbar() {
Size = 5f, AutoHide = false, HandleColor = HexToCuiColor("#D74933"),
}
,
}
}
}
);
#endregion ScrollView
#region Templates
LoopTemplates(player, container);
#endregion
#region Hover
container.Add(new CuiElement {
Name = Layer + ".Hover", Parent = Layer + ".Main", Components = {
new CuiRawImageComponent {
Color = "0 0 0 1", Sprite = "assets/content/ui/UI.Background.Transparent.Linear.psd"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "0 0", OffsetMax = "0 105"
}
}
}
);
#endregion Hover
#region Btn.Start.Install
container.Add(new CuiButton() {
Button = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0 0.372549 0.7176471 1", Command = $"{CmdMainConsole} change_step {step + 1}"
}
, Text = {
Text = Msg(player, BtnContinueInstalling), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "10 20", OffsetMax = "140 62"
}
}
, Layer + ".Main");
#endregion Btn.Start.Install
#region Btn.Go.Back
container.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-140 20", OffsetMax = "-10 62"
}
, Text = {
Text = Msg(player, BtnGoBack), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 0.6"
}
, Button = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0.145098 0.145098 0.145098 1", Command = $"{CmdMainConsole} change_step {step - 1}"
}
,
}
, Layer + ".Main");
#endregion Btn.Go.Back
}
private void LoopTemplates(BasePlayer player, CuiElementContainer container) {
var panelInstaller = PanelInstaller.Get(player.userID);
var offsetX = 0;
var offsetY = 0;
for (var i = 0; i < _installerData.Templates.Count; i++) {
var panelTemplate = _installerData.Templates[i];
var isSelected = panelInstaller.SelectedTemplate == i;
container.Add(new CuiElement {
Name = Layer + $".Templates.{i}", DestroyUi = Layer + $".Templates.{i}", Parent = Layer + ".ScrollView", Components = {
new CuiImageComponent() {
Color = "0 0 0 0"
}
, new CuiRectTransformComponent {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{offsetX} {offsetY - UI_Installer_Template_Height}", OffsetMax = $"{offsetX + UI_Installer_Template_Width} {offsetY}"
}
}
}
);
#region Banner Image
container.Add(new CuiElement {
Parent = Layer + $".Templates.{i}", Components = {
new CuiRawImageComponent {
Png = GetImage(panelTemplate.BannerURL)
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-175 0", OffsetMax = "175 160"
}
}
}
);
#endregion
#region Outline
container.Add(new CuiElement {
Parent = Layer + $".Templates.{i}", Components = {
new CuiRawImageComponent {
Png = GetImage(isSelected ? "ServerPanel_Installer_BannerOutline_Selected" : "ServerPanel_Installer_BannerOutline")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 0", OffsetMax = "0 0"
}
}
}
);
#endregion
#region Title
container.Add(new CuiElement {
Parent = Layer + $".Templates.{i}", Components = {
new CuiTextComponent {
Text = panelTemplate.Title, Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleLeft, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "58 160", OffsetMax = "0 0"
}
}
}
);
#endregion
#region Button
container.Add(new CuiElement() {
Parent = Layer + $".Templates.{i}", Components = {
new CuiButtonComponent() {
Color = "0 0 0 0", Command = $"{CmdMainConsole} select_template {i}"
}
, new CuiRectTransformComponent()
}
}
);
#endregion
#region Calculate Position
if ((i + 1) % 2 == 0) {
offsetX = 0;
offsetY = offsetY - UI_Installer_Template_Height - UI_Installer_Template_Margin_Y;
}
else {
offsetX += UI_Installer_Template_Width + UI_Installer_Template_Margin_X;
}
#endregion
}
}
private const int Dependency_Height = 58, Dependency_Margin_Y = 12;
private void ShowDependenciesStep(BasePlayer player, CuiElementContainer container, int step) {
#region Background
container.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -360", OffsetMax = "0 248"
}
}
, Layer, Layer + ".Main", Layer + ".Main");
#endregion
#region Label.Message
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIDependenciesDescription), Font = "robotocondensed-regular.ttf", FontSize = 16, Align = TextAnchor.UpperCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400 171", OffsetMax = "400 244"
}
}
}
);
#endregion Label.Message
#region Line
container.Add(new CuiPanel {
Image = {
Color = "0.2156863 0.2156863 0.2156863 0.5019608"
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "280 -135", OffsetMax = "-280 -133"
}
}
, Layer + ".Main");
#endregion Line
#region ScrollView
var totalHeight = GetInstallerDependencies().Count * Dependency_Height + (GetInstallerDependencies().Count - 1) * Dependency_Margin_Y;
totalHeight += 100;
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-360 -262", OffsetMax = "377 148"
}
}
, Layer + ".Main", Layer + ".ScrollBackground", Layer + ".ScrollBackground");
container.Add(new CuiElement() {
Parent = Layer + ".ScrollBackground", Name = Layer + ".ScrollView", DestroyUi = Layer + ".ScrollView", Components = {
new CuiScrollViewComponent {
MovementType = ScrollRect.MovementType.Elastic, Vertical = true, Inertia = true, Horizontal = false, Elasticity = 0.25f, DecelerationRate = 0.3f, ScrollSensitivity = 24f, ContentTransform = new CuiRectTransform {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"0 -{totalHeight}", OffsetMax = "0 0"
}
, VerticalScrollbar = new CuiScrollbar() {
Size = 5f, AutoHide = false, HandleColor = HexToCuiColor("#D74933"),
}
,
}
}
}
);
#endregion ScrollView
#region Dependencies
var mainOffset = 0;
foreach (var panelDependency in GetInstallerDependencies().OrderByDescending(panelDependency => panelDependency, new PanelDependencyComparer())) {
var status = panelDependency.GetStatus();
container.Add(new CuiPanel {
Image = {
Color = "0.572549 0.572549 0.572549 0.2"
}
, RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"0 {mainOffset - Dependency_Height}", OffsetMax = $"720 {mainOffset}"
}
}
, Layer + ".ScrollView", Layer + $".Dependencies.{panelDependency.PluginName}", Layer + $".Dependencies.{panelDependency.PluginName}");
#region Title
container.Add(new CuiElement {
Parent = Layer + $".Dependencies.{panelDependency.PluginName}", Components = {
new CuiTextComponent {
Text = panelDependency.PluginName, Font = "robotocondensed-bold.ttf", FontSize = 15, Align = TextAnchor.MiddleLeft, Color = HexToCuiColor("#E2DBD3")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "46 0", OffsetMax = "-495 0"
}
}
}
);
#endregion
#region Status.Icon
var colorIcon = GetColorFromDependencyStatus(status);
container.Add(new CuiElement {
Parent = Layer + $".Dependencies.{panelDependency.PluginName}", Components = {
new CuiRawImageComponent {
Color = colorIcon, Sprite = "assets/content/ui/Waypoint.Outline.TeamTop.png"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "18 -9", OffsetMax = "36 9"
}
}
}
);
#endregion Status.Icon
#region Status.Title
container.Add(new CuiElement {
Parent = Layer + $".Dependencies.{panelDependency.PluginName}", Components = {
new CuiTextComponent {
Text = panelDependency.Messages[status].Title, Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.LowerLeft, Color = HexToCuiColor("#E2DBD3")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "250 26", OffsetMax = "0 0"
}
}
}
);
#endregion Status.Title
#region Status.Description
container.Add(new CuiElement {
Parent = Layer + $".Dependencies.{panelDependency.PluginName}", Components = {
new CuiInputFieldComponent() {
Text = panelDependency.Messages[status].Description, ReadOnly = true, Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.UpperLeft, Color = HexToCuiColor("#E2DBD3", 50)
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "250 0", OffsetMax = "0 -35"
}
}
}
);
#endregion Status.Description
#region Line
container.Add(new CuiPanel {
Image = {
Color = "0.2156863 0.2156863 0.2156863 1"
}
, RectTransform = {
AnchorMin = "0 0", AnchorMax = "0 1", OffsetMin = "224 9", OffsetMax = "226 -13"
}
}
, Layer + $".Dependencies.{panelDependency.PluginName}");
#endregion
mainOffset = mainOffset - Dependency_Height - Dependency_Margin_Y;
}
#endregion
#region Hover
container.Add(new CuiElement {
Name = Layer + ".Hover", Parent = Layer + ".Main", Components = {
new CuiRawImageComponent {
Color = "0 0 0 1", Sprite = "assets/content/ui/UI.Background.Transparent.Linear.psd"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "0 0", OffsetMax = "0 105"
}
}
}
);
#endregion Hover
#region Btn.Start.Install
container.Add(new CuiButton() {
Button = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0 0.372549 0.7176471 1", Command = $"{CmdMainConsole} change_step {step + 1}"
}
, Text = {
Text = Msg(player, BtnContinueInstalling), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "10 20", OffsetMax = "140 62"
}
}
, Layer + ".Main");
#endregion Btn.Start.Install
#region Btn.Go.Back
container.Add(new CuiButton() {
RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-140 20", OffsetMax = "-10 62"
}
, Text = {
Text = Msg(player, BtnGoBack), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 0.6"
}
, Button = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0.145098 0.145098 0.145098 1", Command = $"{CmdMainConsole} change_step {step - 1}"
}
,
}
, Layer + ".Main");
#endregion Btn.Go.Back
}
private void ShowWelcomeStep(BasePlayer player, CuiElementContainer container, int step) {
#region Background
container.Add(new CuiPanel() {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -360", OffsetMax = "0 248"
}
}
, Layer, Layer + ".Main", Layer + ".Main");
#endregion
#region Label.Welcome
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIWelcome), Font = "robotocondensed-regular.ttf", FontSize = 32, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400 196", OffsetMax = "400 252"
}
}
}
);
#endregion Label.Welcome
#region Label.Thank.For.Buy
container.Add(new CuiElement {
Parent = Layer + ".Main", Components = {
new CuiTextComponent {
Text = Msg(player, UIThankForBuying), Font = "robotocondensed-regular.ttf", FontSize = 16, Align = TextAnchor.UpperCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400 -84", OffsetMax = "400 151"
}
}
}
);
#endregion Label.Thank.For.Buy
#region Btn.Start.Install
container.Add(new CuiButton() {
Button = {
Material = "assets/content/ui/namefontmaterial.mat", Color = "0 0.372549 0.7176471 1", Command = $"{CmdMainConsole} change_step {step + 1}"
}
, Text = {
Text = Msg(player, BtnStartInstall), Font = "robotocondensed-regular.ttf", FontSize = 15, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 1"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-120 -96", OffsetMax = "120 -36"
}
}
, Layer + ".Main");
#endregion Btn.Start.Install
#region Btn.Cancel
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-120 -151", OffsetMax = "120 -121"
}
}
, Layer + ".Main", Layer + ".Btn.Cancel");
#region Title
container.Add(new CuiElement {
Parent = Layer + ".Btn.Cancel", Components = {
new CuiTextComponent {
Text = Msg(player, BtnCancelAndClose), Font = "robotocondensed-regular.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.8862745 0.8588235 0.827451 0.5019608"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "22 0", OffsetMax = "0 0"
}
}
}
);
#endregion Title
#region Icon
container.Add(new CuiElement {
Parent = Layer + ".Btn.Cancel", Components = {
new CuiImageComponent {
Color = "0.8862745 0.8588235 0.827451 0.5019608", Sprite = "assets/icons/close.png"
}
, new CuiRectTransformCompo
// ... [Code preview truncated due to length. Full source in attached file] ...