C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
// Requires: Arena
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
using System.Globalization;
using System.IO;
namespace Oxide.Plugins {
[Info("ArenaUI", "k1lly0u", "0.1.69")]
[Description("Creates all Arena UI")]
class ArenaUI : RustPlugin {
#region Fields
[PluginReference]
Arena Arena;
[PluginReference]
ArenaStatistics ArenaStatistics;
[PluginReference]
Plugin ImageLibrary, Kits, Spawns, ZoneManager;
private static ArenaUI ins;
private Dictionary<ulong, List<string>> openUi = new Dictionary<ulong, List<string>>();
private Dictionary<ColorType, string> uiColors = new Dictionary<ColorType, string>();
private Dictionary<string, string> itemNames = new Dictionary<string, string>();
private Dictionary<ulong, Arena.ArenaData.EventConfig> eventCreator = new Dictionary<ulong, Arena.ArenaData.EventConfig>();
private Dictionary<ulong, Arena.ArenaData.EventConfig> eventEditorBackup = new Dictionary<ulong, Arena.ArenaData.EventConfig>();
private string dataDirectory = $"file://{Interface.Oxide.DataDirectory}{Path.DirectorySeparatorChar}Arena{Path.DirectorySeparatorChar}Images{Path.DirectorySeparatorChar}";
private bool hasLogo;
public enum UIPanel {
Clock, Menu, Death, Respawn, Class, Scores, Popup, Help, Statistics
}
private enum ColorType {
Button_Selected, Button_Deselected, BG_Main_Transparent, BG_Main_Solid, Panel_Main_Solid, Panel_Main_Transparent, Panel_Alt_Solid, Panel_Alt_Transparent, BG_Main_PartialTransparent, Panel_Event_Full, Panel_Event_Open
}
#endregion
#region Oxide Hooks
private void Loaded() {
Interface.Oxide.DataFileSystem.SaveDatafile("Arena/Images/foldercreator");
lang.RegisterMessages(Messages, this);
}
private void OnServerInitialized() {
ins = this;
Arena.UI = this;
LoadColors();
LoadDefaultImages();
foreach (var item in ItemManager.itemList) {
if (!itemNames.ContainsKey(item.itemid.ToString())) itemNames.Add(item.itemid.ToString(), item.displayName.translated);
}
}
private void Unload() {
if (Arena != null) Arena.isUnloading = true;
foreach (var player in BasePlayer.activePlayerList) DestroyAllUI(player);
Arena.EventManager[] eventGames = UnityEngine.Object.FindObjectsOfType<Arena.EventManager>();
if (eventGames != null) {
foreach (var eventGame in eventGames) UnityEngine.Object.DestroyImmediate(eventGame);
}
Arena.EventPlayer[] eventPlayers = UnityEngine.Object.FindObjectsOfType<Arena.EventPlayer>();
if (eventPlayers != null) {
foreach (var eventPlayer in eventPlayers) UnityEngine.Object.DestroyImmediate(eventPlayer);
}
}
#endregion
#region UI Management
public void AddUI(BasePlayer player, UIPanel panel, CuiElementContainer container) {
if (!openUi.ContainsKey(player.userID)) openUi.Add(player.userID, new List<string>());
openUi[player.userID].Add($"arena.{panel}");
CuiHelper.AddUi(player, container);
}
public void AddUI(BasePlayer player, string panel, CuiElementContainer container) {
if (!openUi.ContainsKey(player.userID)) openUi.Add(player.userID, new List<string>());
openUi[player.userID].Add(panel);
CuiHelper.AddUi(player, container);
}
public void DestroyUI(BasePlayer player, UIPanel panel) {
if (openUi.ContainsKey(player.userID)) openUi[player.userID].Remove($"arena.{panel}");
CuiHelper.DestroyUi(player, $"arena.{panel}");
}
public void DestroyUI(BasePlayer player, string panel) {
if (openUi.ContainsKey(player.userID)) openUi[player.userID].Remove(panel);
CuiHelper.DestroyUi(player, panel);
}
public void DestroyAllUI(BasePlayer player) {
if (openUi.ContainsKey(player.userID)) {
foreach (var element in openUi[player.userID]) CuiHelper.DestroyUi(player, element);
openUi[player.userID].Clear();
}
else {
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Class}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Clock}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Death}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Help}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Menu}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Respawn}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Scores}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Statistics}");
CuiHelper.DestroyUi(player, $"arena.{UIPanel.Popup}");
for (int i = 0; i < 20; i++) CuiHelper.DestroyUi(player, $"arena.{UIPanel.Popup} {i}");
}
}
#endregion
#region Functions
private void LoadColors() {
foreach (var color in configData.UISettings.Colors) uiColors.Add(ParseType<ColorType>(color.Key), UI.Color(color.Value.Hex, color.Value.Alpha));
UI.styleColor = uiColors[ColorType.Button_Selected];
}
public string StripTags(string str) {
if (str.StartsWith("[") && str.Contains("]") && str.Length > str.IndexOf("]")) str = str.Substring(str.IndexOf("]") + 1).Trim();
if (str.StartsWith("[") && str.Contains("]") && str.Length > str.IndexOf("]")) StripTags(str);
return str;
}
public string TrimToSize(string str, int size = 18) {
if (str.Length > size) str = str.Substring(0, size);
return str;
}
private bool HasEventOfType(string type) {
foreach (var eventGame in Arena.events) if (eventGame.Value.config.eventType == type) return true;
return false;
}
private float GetHeight(int num) => 0.89f - (0.06f * num);
private T ParseType<T>(string type) => (T)Enum.Parse(typeof(T), type, true);
#endregion
#region UI
public static class UI {
static public string styleColor;
static public CuiElementContainer ElementContainer(UIPanel panel, string color, UI4 dimensions, bool useCursor = false, string parent = "Overlay") {
var NewElement = new CuiElementContainer() {
{
new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
, CursorEnabled = useCursor
}
, new CuiElement().Parent = parent, $"arena.{panel}"
}
}
;
return NewElement;
}
static public CuiElementContainer Popup(string panelName, string text, int size, UI4 dimensions, TextAnchor align = TextAnchor.MiddleCenter, string parent = "Overlay") {
CuiElementContainer container = new CuiElementContainer() {
{
new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
}
, new CuiElement().Parent = parent, panelName
}
}
;
container.Add(new CuiLabel {
Text = {
FontSize = size, Align = align, Text = text
}
, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
}
, panelName);
return container;
}
static public void Panel(ref CuiElementContainer container, UIPanel panel, string color, UI4 dimensions, bool cursor = false) {
container.Add(new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
, CursorEnabled = cursor
}
, $"arena.{panel}");
}
static public void Label(ref CuiElementContainer container, UIPanel panel, string text, int size, UI4 dimensions, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiLabel {
Text = {
FontSize = size, Align = align, Text = text
}
, RectTransform = {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
}
, $"arena.{panel}");
}
static public void OutlineLabel(ref CuiElementContainer container, UIPanel panel, string color, string text, int size, string distance, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, string parent = "Overlay") {
CuiElement textElement = new CuiElement {
Name = CuiHelper.GetGuid(), Parent = $"arena.{panel}", FadeOut = 0.2f, Components = {
new CuiTextComponent {
Text = text, FontSize = size, Align = TextAnchor.MiddleCenter, FadeIn = 0.2f
}
, new CuiOutlineComponent {
Distance = distance, Color = color
}
, new CuiRectTransformComponent {
AnchorMin = aMin, AnchorMax = aMax
}
}
}
;
container.Add(textElement);
}
static public void Button(ref CuiElementContainer container, UIPanel panel, string color, string text, int size, UI4 dimensions, string command, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = 0f
}
, RectTransform = {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
, Text = {
Text = text, FontSize = size, Align = align
}
}
, $"arena.{panel}");
}
static public void StyledButton(ref CuiElementContainer container, UIPanel panel, string color, string text, int size, UI4 dimensions, string command, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = 0f
}
, RectTransform = {
AnchorMin = $"{dimensions.xMin} {dimensions.yMin}", AnchorMax = $"{dimensions.xMax} {dimensions.yMax}"
}
, Text = {
Text = text, FontSize = size, Align = align
}
}
, $"arena.{panel}");
container.Add(new CuiPanel {
Image = {
Color = styleColor
}
, RectTransform = {
AnchorMin = $"{dimensions.xMin} {dimensions.yMax + 0.0005f}", AnchorMax = $"{dimensions.xMax} {dimensions.yMax + 0.0015f}"
}
}
, $"arena.{panel}");
}
static public void Image(ref CuiElementContainer container, UIPanel panel, string png, UI4 dimensions) {
container.Add(new CuiElement {
Name = CuiHelper.GetGuid(), Parent = $"arena.{panel}", Components = {
new CuiRawImageComponent {
Png = png
}
, new CuiRectTransformComponent {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
}
}
);
}
static public void Input(ref CuiElementContainer container, UIPanel panel, string text, int size, string command, UI4 dimensions) {
container.Add(new CuiElement {
Name = CuiHelper.GetGuid(), Parent = $"arena.{panel}", Components = {
new CuiInputFieldComponent {
Align = TextAnchor.MiddleLeft, CharsLimit = 300, Command = command + text, FontSize = size, IsPassword = false, Text = text
}
, new CuiRectTransformComponent {
AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()
}
}
}
);
}
public static string Color(string hexColor, float alpha) {
if (hexColor.StartsWith("#")) hexColor = hexColor.Substring(1);
int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
}
}
public class UI4 {
public float xMin, yMin, xMax, yMax;
public UI4(float xMin, float yMin, float xMax, float yMax) {
this.xMin = xMin;
this.yMin = yMin;
this.xMax = xMax;
this.yMax = yMax;
}
public string GetMin() => $"{xMin} {yMin}";
public string GetMax() => $"{xMax} {yMax}";
}
#endregion
#region User Interface
#region Main Menu Elements
public void OpenMainMenu(BasePlayer player, string eventType, int eventPage = 0) {
CuiElementContainer container = UI.ElementContainer(UIPanel.Menu, uiColors[ColorType.BG_Main_Solid], new UI4(0, 0, 1, 1), true);
AddMenuHeader(ref container, player.userID, eventType);
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], Arena.configData.ServerSettings.EventOnly ? msg("returntolobby", player.userID) : msg("returntogame", player.userID), 16, new UI4(0.01f, 0.94f, 0.13f, 0.98f), "aui.change.element destroy");
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Main_Solid], new UI4(0.01f, 0.01f, 0.99f, 0.79f));
var eventList = Arena.events.Where(x => x.Value.config.eventType == eventType).ToArray();
if (eventList.Length > 10) {
var maxpages = (eventList.Length - 1) / 10 + 1;
if (eventPage < maxpages - 1) UI.Button(ref container, UIPanel.Menu, uiColors[ColorType.Button_Selected], ">\n>\n>", 10, new UI4(0.975f, 0.36f, 0.99f, 0.44f), $"aui.change.element {eventType.Replace(" ", "<><>")} {eventPage + 1}");
if (eventPage > 0) UI.Button(ref container, UIPanel.Menu, uiColors[ColorType.Button_Selected], "<\n<\n<", 10, new UI4(0.01f, 0.36f, 0.025f, 0.44f), $"aui.change.element {eventType.Replace(" ", "<><>")} {eventPage - 1}");
}
int maxCount = (10 * (eventPage + 1));
if (maxCount > eventList.Length) maxCount = eventList.Length;
int i = 0;
int entryCount = 10 * eventPage;
for (int n = entryCount; n < maxCount; n++) {
Arena.EventManager manager = eventList.ElementAt(n).Value;
CreateEventEntry(ref container, manager, i, player.userID);
i++;
}
DestroyUI(player, UIPanel.Menu);
AddUI(player, UIPanel.Menu, container);
}
private void AddMenuHeader(ref CuiElementContainer container, ulong playerId, string eventType) {
if (hasLogo) UI.Image(ref container, UIPanel.Menu, GetImage("logo"), new UI4(0.005f, 0.85f, 0.995f, 0.99f));
List<string> eventTypes = Arena.eventTypes.Where(x => HasEventOfType(x)).ToList();
for (int j = 0; j < eventTypes.Count; j++) {
float xMin = 0.01f + (0.1205f * j);
float xMax = xMin + 0.12f;
UI.StyledButton(ref container, UIPanel.Menu, eventType == eventTypes[j] ? uiColors[ColorType.Button_Selected] : uiColors[ColorType.Button_Deselected], msg(eventTypes[j], playerId), 15, new UI4(xMin, 0.8f, xMax, 0.84f), eventType == eventTypes[j] ? "" : $"aui.change.element {eventTypes[j].Replace(" ", "<><>")} 0");
}
}
void CreateEventEntry(ref CuiElementContainer container, Arena.EventManager manager, int number, ulong playerId) {
var xPos = number > 4 ? 0.2f * (number - 5) : 0.2f * number;
var yPos = number > 4 ? 0.03f : 0.42f;
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(xPos + 0.03f, yPos + 0.32f, xPos + 0.17f, yPos + 0.36f));
UI.Label(ref container, UIPanel.Menu, manager.eventName, 15, new UI4(xPos + 0.03f, yPos + 0.325f, xPos + 0.17f, yPos + 0.355f));
UI.Image(ref container, UIPanel.Menu, GetImage(string.IsNullOrEmpty(manager.config.eventIcon) ? "placeholder" : manager.config.eventIcon), new UI4(xPos + 0.03f, yPos + 0.065f, xPos + 0.17f, yPos + 0.32f));
UI.Panel(ref container, UIPanel.Menu, manager.eventPlayers.Count == manager.config.maximumPlayers ? uiColors[ColorType.Panel_Event_Full] : manager.eventPlayers.Count < manager.config.maximumPlayers && manager.eventPlayers.Count > 0 ? uiColors[ColorType.Panel_Event_Open] : uiColors[ColorType.Panel_Alt_Solid], new UI4(xPos + 0.03f, yPos + 0.025f, xPos + 0.17f, yPos + 0.065f));
UI.Label(ref container, UIPanel.Menu, manager.status == Arena.EventStatus.Finished || manager.status == Arena.EventStatus.Pending ? $"{msg("waitforplayers", playerId)} ({manager.eventPlayers.Count}/{manager.config.maximumPlayers})" : $"{msg("inprogress", playerId)} ({manager.eventPlayers.Count}/{manager.config.maximumPlayers})", 10, new UI4(xPos + 0.03f, yPos + 0.035f, xPos + 0.17f, yPos + 0.065f));
bool hasPermission = !string.IsNullOrEmpty(manager.config.permission) ? permission.UserHasPermission(playerId.ToString(), manager.config.permission) : true;
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], !hasPermission ? msg("donatoronly", playerId) : msg("viewevent", playerId), 15, new UI4(xPos + 0.03f, yPos - 0.00505f, xPos + 0.17f, yPos + 0.03495f), !hasPermission ? "aui.donator.popup" : $"aui.player.controls view {manager.eventName.Replace(" ", "<><>")}");
}
private void ShowEventDetails(BasePlayer player, Arena.EventManager manager, Arena.Team team = Arena.Team.A) {
CuiElementContainer container = UI.ElementContainer(UIPanel.Menu, uiColors[ColorType.BG_Main_Solid], new UI4(0, 0, 1, 1), true);
AddMenuHeader(ref container, player.userID, manager.config.eventType);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Main_Solid], new UI4(0.01f, 0.01f, 0.99f, 0.79f));
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], Arena.configData.ServerSettings.EventOnly ? msg("returntolobby", player.userID) : msg("returntogame", player.userID), 16, new UI4(0.01f, 0.94f, 0.13f, 0.98f), "aui.change.element destroy");
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("returntoevents", player.userID), 16, new UI4(0.01f, 0.8985f, 0.13f, 0.9385f), $"aui.change.element {manager.config.eventType.Replace(" ", "<><>")} 0");
UI.Label(ref container, UIPanel.Menu, manager.eventName, 18, new UI4(0.02f, 0.73f, 0.5f, 0.78f), TextAnchor.MiddleLeft);
int i = 0;
AddInformationEntry(ref container, msg("gamestatus", player.userID), manager.status == Arena.EventStatus.Finished || manager.status == Arena.EventStatus.Pending ? msg("waitforplayers", player.userID) : msg("inprogress", player.userID), i);
i++;
AddInformationEntry(ref container, msg("players", player.userID), $"{manager.eventPlayers.Count} / {manager.config.maximumPlayers}", i);
i++;
if (!Arena.Events.IgnoreKillLimit(manager.config.eventType)) {
AddInformationEntry(ref container, msg("scorelimit", player.userID), manager.config.killLimit == 0 ? msg("unlimited", player.userID) : manager.config.killLimit.ToString(), i);
i++;
}
if (manager.config.timeLimit > 0) {
AddInformationEntry(ref container, msg("timelimit", player.userID), $"{manager.config.timeLimit} {msg("minutes", player.userID)}", i);
i++;
}
AddInformationEntry(ref container, msg("gear", player.userID), manager.config.useClassSelector ? msg("classselect", player.userID) : msg("eventspec", player.userID), i);
i++;
foreach (var addition in manager.GetAdditionalInformation()) {
AddInformationEntry(ref container, addition.Key, addition.Value, i);
i++;
}
if (!string.IsNullOrEmpty(manager.config.description)) AddDescriptionEntry(ref container, msg("description", player.userID), manager.config.description, i);
CreateScoreboard(ref container, manager);
CreateScoreList(ref container, manager);
AddTeamSelection(ref container, manager, team, player.userID);
DestroyUI(player, UIPanel.Menu);
AddUI(player, UIPanel.Menu, container);
}
private void AddInformationEntry(ref CuiElementContainer container, string key, string value, int number) {
float yMin = 0.68f - (number * 0.045f);
float yMax = yMin + 0.04f;
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(0.02f, yMin, 0.3f, yMax));
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Button_Selected], new UI4(0.3005f, yMin, 0.4f, yMax));
UI.Label(ref container, UIPanel.Menu, key, 15, new UI4(0.025f, yMin, 0.3f, yMax), TextAnchor.MiddleLeft);
UI.Label(ref container, UIPanel.Menu, value, 15, new UI4(0.3005f, yMin, 0.395f, yMax), TextAnchor.MiddleRight);
}
private void AddDescriptionEntry(ref CuiElementContainer container, string key, string description, int number) {
float yMin = 0.68f - (number * 0.045f);
float yMax = yMin + 0.04f;
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(0.02f, yMin, 0.3f, yMax));
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Button_Selected], new UI4(0.3005f, yMin, 0.4f, yMax));
UI.Label(ref container, UIPanel.Menu, key, 15, new UI4(0.025f, yMin, 0.3f, yMax), TextAnchor.MiddleLeft);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Button_Selected], new UI4(0.02f, yMin - 0.005f, 0.4f, yMin - 0.0005f));
yMin = 0.68f - ((description.Length > 60 ? number + 2 : number + 1) * 0.045f);
yMax = yMin + (description.Length > 60 ? 0.085f : 0.04f);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(0.02f, yMin, 0.4f, yMax));
UI.Label(ref container, UIPanel.Menu, description, 15, new UI4(0.025f, yMin, 0.4f, yMax - 0.003f), TextAnchor.UpperLeft);
}
private void CreateScoreboard(ref CuiElementContainer container, Arena.EventManager manager, float xMin = 0.517f, string color = "") {
if (string.IsNullOrEmpty(color)) color = uiColors[ColorType.Button_Selected];
UI.Panel(ref container, UIPanel.Menu, color, new UI4(xMin, 0.725f, xMin + 0.03f, 0.765f));
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], new UI4(xMin + 0.033f, 0.725f, xMin + 0.327f, 0.765f));
UI.Label(ref container, UIPanel.Menu, msg("player"), 15, new UI4(xMin + 0.043f, 0.725f, xMin + 317f, 0.765f), TextAnchor.MiddleLeft);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], new UI4(xMin + 0.33f, 0.725f, xMin + 0.38f, 0.765f));
UI.Label(ref container, UIPanel.Menu, manager.GetScoreName(true), 15, new UI4(xMin + 0.33f, 0.725f, xMin + 0.38f, 0.765f));
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], new UI4(xMin + 0.383f, 0.725f, xMin + 0.433f, 0.765f));
UI.Label(ref container, UIPanel.Menu, manager.GetScoreName(false), 15, new UI4(xMin + 0.383f, 0.725f, xMin + 0.433f, 0.765f));
UI.Panel(ref container, UIPanel.Menu, color, new UI4(xMin, 0.7225f, xMin + 0.433f, 0.7245f));
}
private void CreateScoreList(ref CuiElementContainer container, Arena.EventManager manager) {
if (Arena.Events.IsTeamEvent(manager.config.eventType)) {
int count = AddScoreboardEntries(ref container, manager.GetGameScores(Arena.Team.A), 1, true, $"{(!string.IsNullOrEmpty(manager.config.teamA.name) ? manager.config.teamA.GetFormattedName() : msg("Team A"))} - ");
AddScoreboardEntries(ref container, manager.GetGameScores(Arena.Team.B), count, true, $"{(!string.IsNullOrEmpty(manager.config.teamB.name) ? manager.config.teamB.GetFormattedName() : msg("Team B"))} - ");
}
else AddScoreboardEntries(ref container, manager.GetGameScores());
}
private int AddScoreboardEntries(ref CuiElementContainer container, List<Arena.ScoreEntry> data, int i = 1, bool limit = false, string prefix = "", float xMin = 0.517f) {
foreach (var eventPlayer in limit ? data.Take(7) : data.Take(15)) {
float yMin = 0.725f - (i * 0.045f);
float yMax = yMin + 0.04f;
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(xMin, yMin, xMin + 0.03f, yMax));
UI.Label(ref container, UIPanel.Menu, eventPlayer.position.ToString(), 15, new UI4(xMin, yMin, xMin + 0.03f, yMax));
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(xMin + 0.033f, yMin, xMin + 0.327f, yMax));
UI.Label(ref container, UIPanel.Menu, $"{prefix}{StripTags(eventPlayer.displayName)}", 15, new UI4(xMin + 0.043f, yMin, xMin + 317f, yMax), TextAnchor.MiddleLeft);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(xMin + 0.33f, yMin, xMin + 0.38f, yMax));
UI.Label(ref container, UIPanel.Menu, eventPlayer.value1.ToString(), 15, new UI4(xMin + 0.34f, yMin, xMin + 0.37f, yMax), TextAnchor.MiddleRight);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(xMin + 0.383f, yMin, xMin + 0.433f, yMax));
UI.Label(ref container, UIPanel.Menu, eventPlayer.value2.ToString(), 15, new UI4(xMin + 0.393f, yMin, xMin + 0.423f, yMax), TextAnchor.MiddleRight);
i++;
}
return i;
}
private void AddTeamSelection(ref CuiElementContainer container, Arena.EventManager manager, Arena.Team team, ulong playerId) {
bool isGameFull = manager.eventPlayers.Count >= manager.config.maximumPlayers;
if (Arena.Events.IsTeamEvent(manager.config.eventType)) {
string nameA = string.IsNullOrEmpty(manager.config.teamA.name) ? msg("Team A", playerId) : manager.config.teamA.name;
string nameB = string.IsNullOrEmpty(manager.config.teamB.name) ? msg("Team B", playerId) : manager.config.teamB.name;
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(0.0295f, 0.091f, 0.3905f, 0.131f));
UI.Label(ref container, UIPanel.Menu, isGameFull ? msg("maxcapacity", playerId) : !manager.CanJoinEvent() ? msg("cantjoinstarted", playerId) : msg("selectteam", playerId), 15, new UI4(0.0295f, 0.091f, 0.3905f, 0.131f));
UI.StyledButton(ref container, UIPanel.Menu, team == Arena.Team.A ? uiColors[ColorType.Button_Selected] : uiColors[ColorType.Button_Deselected], nameA, 15, new UI4(0.0295f, 0.05f, 0.1495f, 0.09f), team == Arena.Team.A ? "" : $"aui.change.team a {manager.eventName.Replace(" ", "<><>")}");
UI.StyledButton(ref container, UIPanel.Menu, team == Arena.Team.B ? uiColors[ColorType.Button_Selected] : uiColors[ColorType.Button_Deselected], nameB, 15, new UI4(0.15f, 0.05f, 0.27f, 0.09f), team == Arena.Team.B ? "" : $"aui.change.team b {manager.eventName.Replace(" ", "<><>")}");
UI.StyledButton(ref container, UIPanel.Menu, isGameFull ? uiColors[ColorType.Panel_Alt_Solid] : uiColors[ColorType.Button_Deselected], msg("enterevent", playerId), 15, new UI4(0.2705f, 0.05f, 0.3905f, 0.09f), isGameFull || !manager.CanJoinEvent() ? "" : $"aui.event.enter {team} {manager.eventName.Replace(" ", "<><>")}");
}
else {
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Alt_Solid], new UI4(0.02f, 0.05f, 0.3f, 0.09f));
UI.Label(ref container, UIPanel.Menu, isGameFull ? msg("maxcapacity", playerId) : !manager.CanJoinEvent() ? msg("cantjoinstarted", playerId) : msg("canjoinevent", playerId), 15, new UI4(0.025f, 0.05f, 0.3f, 0.09f), TextAnchor.MiddleLeft);
UI.StyledButton(ref container, UIPanel.Menu, isGameFull || !manager.CanJoinEvent() ? uiColors[ColorType.Panel_Alt_Solid] : uiColors[ColorType.Button_Deselected], msg("enter", playerId), 15, new UI4(0.3005f, 0.05f, 0.4f, 0.09f), isGameFull || !manager.CanJoinEvent() ? "" : $"aui.event.enter {team} {manager.eventName.Replace(" ", "<><>")}");
}
}
#endregion
#region Respawn Screen
public void ShowDeathScreen(BasePlayer player, string message, int time) {
Arena.EventPlayer eventPlayer = Arena.GetUser(player);
Arena.EventManager manager = Arena.GetEvent(eventPlayer.currentEvent);
CuiElementContainer container = UI.ElementContainer(UIPanel.Death, uiColors[ColorType.BG_Main_PartialTransparent], new UI4(0, 0, 1, 1), true);
UI.Label(ref container, UIPanel.Death, message, 22, new UI4(0.2f, 0.7f, 0.8f, 0.85f));
UI.Image(ref container, UIPanel.Death, GetImage("skullicon"), new UI4(0.475f, 0.46f, 0.525f, 0.54f));
if (manager.config.useClassSelector && !eventPlayer.isEliminated) UI.StyledButton(ref container, UIPanel.Death, uiColors[ColorType.Button_Deselected], msg("changeclass", player.userID), 15, new UI4(0.44f, 0.21f, 0.56f, 0.25f), "aui.player.class");
DestroyAllUI(player);
AddUI(player, UIPanel.Death, container);
if (!eventPlayer.isEliminated) AddRespawnButton(eventPlayer, time + 1);
else timer.In(3, () => DestroyUI(player, UIPanel.Death));
}
public void ShowSpectateScreen(BasePlayer player, string message) {
Arena.EventPlayer eventPlayer = Arena.GetUser(player);
Arena.EventManager manager = Arena.GetEvent(eventPlayer.currentEvent);
CuiElementContainer container = UI.ElementContainer(UIPanel.Death, uiColors[ColorType.BG_Main_PartialTransparent], new UI4(0, 0, 1, 1), true);
UI.Label(ref container, UIPanel.Death, message, 20, new UI4(0.2f, 0.7f, 0.8f, 0.85f));
UI.Image(ref container, UIPanel.Death, GetImage("skullicon"), new UI4(0.475f, 0.46f, 0.525f, 0.54f));
UI.StyledButton(ref container, UIPanel.Death, uiColors[ColorType.Button_Deselected], msg("leaveevent", eventPlayer.player.userID), 15, new UI4(0.44f, 0.26f, 0.56f, 0.3f), "aui.player.controls leave");
DestroyAllUI(player);
AddUI(player, UIPanel.Death, container);
}
private void AddRespawnButton(Arena.EventPlayer eventPlayer, int elapsed) {
--elapsed;
CuiElementContainer container = UI.ElementContainer(UIPanel.Respawn, "0 0 0 0", new UI4(0.44f, 0.26f, 0.56f, 0.3f));
UI.Panel(ref container, UIPanel.Respawn, uiColors[ColorType.Button_Selected], new UI4(0, 1, 1, 1.05f));
UI.Button(ref container, UIPanel.Respawn, uiColors[ColorType.Button_Deselected], elapsed == 0 ? msg("respawn", eventPlayer.player.userID) : $"{msg("respawn", eventPlayer.player.userID)} ({elapsed})", 15, new UI4(0, 0, 1, 1), elapsed == 0 ? "aui.player.respawn" : "");
DestroyUI(eventPlayer.player, UIPanel.Respawn);
if (!eventPlayer.isDead || eventPlayer.isEliminated) return;
AddUI(eventPlayer.player, UIPanel.Respawn, container);
if (elapsed > 0) timer.In(1, () => AddRespawnButton(eventPlayer, elapsed));
}
#endregion
#region Class Selector
public void ShowSpawnScreen(BasePlayer player) {
Arena.EventPlayer eventPlayer = Arena.GetUser(player);
Arena.EventManager manager = Arena.GetEvent(eventPlayer.currentEvent);
CuiElementContainer container = UI.ElementContainer(UIPanel.Death, uiColors[ColorType.BG_Main_PartialTransparent], new UI4(0, 0, 1, 1), true);
UI.Label(ref container, UIPanel.Death, msg("selectclass", player.userID), 22, new UI4(0.2f, 0.7f, 0.8f, 0.85f));
UI.Image(ref container, UIPanel.Death, GetImage("skullicon"), new UI4(0.475f, 0.46f, 0.525f, 0.54f));
UI.StyledButton(ref container, UIPanel.Death, uiColors[ColorType.Button_Deselected], msg("spawn", eventPlayer.player.userID), 15, new UI4(0.44f, 0.26f, 0.56f, 0.3f), "aui.player.classchosen");
DestroyAllUI(player);
AddUI(player, UIPanel.Death, container);
AddClassSelector(eventPlayer, manager);
}
private void AddClassSelector(Arena.EventPlayer eventPlayer, Arena.EventManager manager) {
if (manager.config.useClassSelector) {
CuiElementContainer container = UI.ElementContainer(UIPanel.Class, "0 0 0 0", new UI4(0.02f, 0, 0.14f, 1));
int i = 0;
foreach (var kit in manager.config.eventKits) {
float yMin = 0.03f + (i * 0.05f);
float yMax = yMin + 0.04f;
UI.StyledButton(ref container, UIPanel.Class, i == eventPlayer.currentKit ? uiColors[ColorType.Button_Selected] : uiColors[ColorType.Button_Deselected], kit, 15, new UI4(0, yMin, 1, yMax), i == eventPlayer.currentKit ? "" : $"aui.player.class {i}");
i++;
}
DestroyUI(eventPlayer.player, UIPanel.Class);
AddUI(eventPlayer.player, UIPanel.Class, container);
}
}
#endregion
#region Game Menu
public void ShowHelpText(BasePlayer player) {
CuiElementContainer container = UI.ElementContainer(UIPanel.Help, uiColors[ColorType.BG_Main_Transparent], new UI4(0.343f, 0, 0.641f, 0.015f));
UI.Label(ref container, UIPanel.Help, string.Format(msg("menuhelp", player.userID), $"/{Arena.configData.ServerSettings.ChatCommand}"), 10, new UI4(0, 0, 1, 1));
DestroyUI(player, UIPanel.Help);
AddUI(player, UIPanel.Help, container);
}
public void OpenPlayerMenu(BasePlayer player) {
Arena.EventPlayer eventPlayer = Arena.GetUser(player);
Arena.EventManager manager = Arena.GetEvent(eventPlayer.currentEvent);
CuiElementContainer container = null;
if (Arena.Events.IsTeamEvent(manager.config.eventType)) {
container = UI.ElementContainer(UIPanel.Menu, uiColors[ColorType.BG_Main_Transparent], new UI4(0.01f, 0.75f, 0.12f, 0.99f), true);
UI.Image(ref container, UIPanel.Menu, GetImage("logosmall"), new UI4(0, 0.5f, 1, 1));
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("leaveevent", player.userID), 15, new UI4(0, 0.3334f, 1, 0.5f), "aui.player.controls leave");
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("switchteam", player.userID), 15, new UI4(0, 0.1666f, 1, 0.3334f), $"aui.change.team {eventPlayer.team} {manager.config.eventName.Replace(" ", "<><>")}");
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("cancel", player.userID), 15, new UI4(0, 0, 1, 0.1666f), "aui.player.controls cancel");
}
else {
container = UI.ElementContainer(UIPanel.Menu, uiColors[ColorType.BG_Main_Transparent], new UI4(0.01f, 0.79f, 0.12f, 0.99f), true);
UI.Image(ref container, UIPanel.Menu, GetImage("logosmall"), new UI4(0, 0.4f, 1, 1));
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("leaveevent", player.userID), 15, new UI4(0, 0.2f, 1, 0.4f), "aui.player.controls leave");
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("cancel", player.userID), 15, new UI4(0, 0, 1, 0.2f), "aui.player.controls cancel");
}
DestroyUI(player, UIPanel.Menu);
AddUI(player, UIPanel.Menu, container);
}
#endregion
#region Scoreboards
public void ShowEventResults(Arena.EventManager manager) {
CuiElementContainer container = UI.ElementContainer(UIPanel.Menu, uiColors[ColorType.BG_Main_PartialTransparent], new UI4(0, 0, 1, 1), true);
UI.Panel(ref container, UIPanel.Menu, uiColors[ColorType.Panel_Main_Transparent], new UI4(0.4f, 0.94f, 0.6f, 1));
UI.Label(ref container, UIPanel.Menu, $"{manager.eventName} ({manager.config.eventType})", 15, new UI4(0.4f, 0.94f, 0.6f, 1));
UI.Panel(ref container, UIPanel.Menu, UI.Color("#ffffff", 0.98f), new UI4(0.4f, 0.9385f, 0.6f, 0.9395f));
UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], Arena.configData.ServerSettings.EventOnly ? msg("returntolobby") : msg("returntogame"), 16, new UI4(0.01f, 0.94f, 0.13f, 0.98f), "aui.player.controls leave");
if (manager.isContinual) UI.StyledButton(ref container, UIPanel.Menu, uiColors[ColorType.Button_Deselected], msg("continueplaying"), 16, new UI4(0.135f, 0.94f, 0.265f, 0.98f), "aui.player.controls continue");
if (Arena.Events.IsTeamEvent(manager.config.eventType)) AddTeamScoreboard(ref container, manager);
else AddSingleScoreboard(ref container, manager);
foreach(var eventPlayer in manager.eventPlayers) {
DestroyAllUI(eventPlayer.player);
AddUI(eventPlayer.player, UIPanel.Menu, container);
}
}
private void AddSingleScoreboard(ref CuiElementContainer container, Arena.EventManager manager) {
CreateScoreboard(ref container, manager, 0.2835f);
AddScoreboardEntries(ref container, manager.GetGameScores(), 1, false, "", 0.2835f);
}
private void AddTeamScoreboard(ref CuiElementContainer container, Arena.EventManager manager) {
string aColor = string.IsNullOrEmpty(manager.config.teamA.color) ? uiColors[ColorType.Button_Selected] : UI.Color(manager.config.teamA.color, 1);
string bColor = string.IsNullOrEmpty(manager.config.teamB.color) ? uiColors[ColorType.Button_Selected] : UI.Color(manager.config.teamB.color, 1);
UI.Panel(ref container, UIPanel.Menu, aColor, new UI4(0.362f, 0.77f, 0.4665f, 0.83f));
UI.Label(ref container, UIPanel.Menu, $"{(string.IsNullOrEmpty(manager.config.teamA.name) ? msg("Team A") : manager.config.teamA.name)} - {manager.GetTeamScore(Arena.Team.A)}", 16, new UI4(0.362f, 0.77f, 0.455f, 0.83f), TextAnchor.MiddleRight);
CreateScoreboard(ref container, manager, 0.0335f, aColor);
AddScoreboardEntries(ref container, manager.GetGameScores(Arena.Team.A), 1, false, "", 0.0335f);
UI.Panel(ref container, UIPanel.Menu, bColor, new UI4(0.5335f, 0.77f, 0.64f, 0.83f));
UI.Label(ref container, UIPanel.Menu, $"{manager.GetTeamScore(Arena.Team.B)} - {(string.IsNullOrEmpty(manager.config.teamB.name) ? msg("Team B") : manager.config.teamB.name)}", 16, new UI4(0.545f, 0.77f, 0.64f, 0.83f), TextAnchor.MiddleLeft);
CreateScoreboard(ref container, manager, 0.5335f, bColor);
AddScoreboardEntries(ref container, manager.GetGameScores(Arena.Team.B), 1, false, "", 0.5335f);
}
public CuiElementContainer ShowGameScores(Arena.EventManager manager) {
CuiElementContainer container = null;
string[] scoreTypes = manager.GetScoreType();
int count = 0;
float size = 0.0992f;
if (Arena.Events.IsTeamEvent(manager.config.eventType)) {
container = UI.ElementContainer(UIPanel.Scores, "0 0 0 0", new UI4(0.87f, 0.655f, 0.997f, 0.85f));
UI.Panel(ref container, UIPanel.Scores, uiColors[ColorType.Button_Selected], new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
UI.Label(ref container, UIPanel.Scores, $"{manager.eventName} ({msg(manager.config.eventType)})", 10, new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
count++;
UI.Panel(ref container, UIPanel.Scores, uiColors[ColorType.Panel_Main_Transparent], new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
UI.Label(ref container, UIPanel.Scores, manager.GetScoreString(), 10, new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
count++;
string additionalScore = manager.GetAdditionalScoreString();
if (!string.IsNullOrEmpty(additionalScore)) {
UI.Panel(ref container, UIPanel.Scores, uiColors[ColorType.Panel_Main_Transparent], new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
UI.Label(ref container, UIPanel.Scores, additionalScore, 10, new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
count++;
}
UI.Panel(ref container, UIPanel.Scores, string.IsNullOrEmpty(manager.config.teamA.color) ? uiColors[ColorType.Panel_Main_Transparent] : UI.Color(manager.config.teamA.color, 1f), new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
UI.Label(ref container, UIPanel.Scores, $"{manager.config.teamA.GetFormattedName() ?? msg("Team A")} ({manager.GetTeamScore(Arena.Team.A)})", 10, new UI4(0.05f, 1 - (0.1f * count), 0.6f, 1 - (0.1f * count) + size), TextAnchor.MiddleLeft);
UI.Label(ref container, UIPanel.Scores, scoreTypes[0], 10, new UI4(0.6f, 1 - (0.1f * count), 0.8f, 1 - (0.1f * count) + size));
UI.Label(ref container, UIPanel.Scores, scoreTypes[1], 10, new UI4(0.8f, 1 - (0.1f * count), 1, 1 - (0.1f * count) + size));
count++;
var scoresA = manager.GetGameScores(Arena.Team.A);
for (int i = 0; i < scoresA.Count; i++) {
if (i >= 5) break;
float yMin = 1 - (0.1f * count);
float yMax = yMin + size;
UI.Panel(ref container, UIPanel.Scores, uiColors[ColorType.Panel_Main_Transparent], new UI4(0, yMin, 1, yMax));
UI.Label(ref container, UIPanel.Scores, TrimToSize(scoresA[i].displayName, 20), 10, new UI4(0.05f, yMin, 0.6f, yMax), TextAnchor.MiddleLeft);
UI.Label(ref container, UIPanel.Scores, scoresA[i].value1.ToString(), 10, new UI4(0.6f, yMin, 0.8f, yMax));
UI.Label(ref container, UIPanel.Scores, scoresA[i].value2.ToString(), 10, new UI4(0.8f, yMin, 1, yMax));
count++;
}
UI.Panel(ref container, UIPanel.Scores, string.IsNullOrEmpty(manager.config.teamB.color) ? uiColors[ColorType.Panel_Main_Transparent] : UI.Color(manager.config.teamB.color, 1f), new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
UI.Label(ref container, UIPanel.Scores, $"{manager.config.teamB.GetFormattedName() ?? msg("Team B")} ({manager.GetTeamScore(Arena.Team.B)})", 10, new UI4(0.05f, 1 - (0.1f * count), 0.6f, 1 - (0.1f * count) + size), TextAnchor.MiddleLeft);
UI.Label(ref container, UIPanel.Scores, scoreTypes[0], 10, new UI4(0.6f, 1 - (0.1f * count), 0.8f, 1 - (0.1f * count) + size));
UI.Label(ref container, UIPanel.Scores, scoreTypes[1], 10, new UI4(0.8f, 1 - (0.1f * count), 1, 1 - (0.1f * count) + size));
count++;
var scoresB = manager.GetGameScores(Arena.Team.B);
for (int i = 0; i < scoresB.Count; i++) {
if (i >= 5) break;
float yMin = 1 - (0.1f * count);
float yMax = yMin + size;
UI.Panel(ref container, UIPanel.Scores, uiColors[ColorType.Panel_Main_Transparent], new UI4(0, yMin, 1, yMax));
UI.Label(ref container, UIPanel.Scores, TrimToSize(scoresB[i].displayName, 20), 10, new UI4(0.05f, yMin, 0.6f, yMax), TextAnchor.MiddleLeft);
UI.Label(ref container, UIPanel.Scores, scoresB[i].value1.ToString(), 10, new UI4(0.6f, yMin, 0.8f, yMax));
UI.Label(ref container, UIPanel.Scores, scoresB[i].value2.ToString(), 10, new UI4(0.8f, yMin, 1, yMax));
count++;
}
}
else {
var scores = manager.GetGameScores();
container = UI.ElementContainer(UIPanel.Scores, "0 0 0 0", new UI4(0.87f, 0.655f, 0.997f, 0.85f));
UI.Panel(ref container, UIPanel.Scores, uiColors[ColorType.Button_Selected], new UI4(0, (1 - (0.1f * count)) + 0.002f , 1, (1 - (0.1f * count) + size) - 0.002f));
UI.Label(ref container, UIPanel.Scores, $"{manager.eventName} ({msg(manager.config.eventType)})", 10, new UI4(0, (1 - (0.1f * count)) + 0.
// ... [Code preview truncated due to length. Full source in attached file] ...