Иконка ресурса

FREE KingGamesDeathmatch : 1.4.1 1.4.1

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6

using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Steamworks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Scrim Deathmatch", "Pho3niX90", "1.4.1")]
    [Description("")]
    public class KingGamesDeathmatch : RustPlugin
    {
        [PluginReference] Plugin Spawns;
        [PluginReference] Plugin Loadoutless;
        #region Vars
        private const int autoBalanceMax = 1;
        private static KingGamesDeathmatch plugin;
        static KingGamesDeathmatch _instance;
        string panelColor = "0 0 0 0.5";//"1 0.5 0 0";
        string panelColor2 = "1.0 0.8 0 0.8";//"1 0.5 0 1";
        private static List<string> teamColors = new List<string>();


        public enum MemberType
        {
            Spectator,
            Playing,
            Destroying,
            NoTeam
        }

        public class RespawnInfo
        {
            public string spawnFile;
            public string kitName;
            public string kitNameClothing;
        }

        #endregion

        #region Oxide Hooks

        private void Init() {
            plugin = this;

            //colors must be hex
            teamColors.Add("#ff0000");
            teamColors.Add("#0000ff");
            teamColors.Add("#00ff00");
            teamColors.Add("#ff00ff");
            teamColors.Add("#00ffff");
        }

        private void OnServerInitialized() {
            CreateGames();
        }

        private void Unload() {
            RemoveAllGames();
        }

        object OnPlayerDeath(BasePlayer player, HitInfo info) {
            if (info == null || info.Initiator == null) {
                Puts("Deny death");
                return "nope";
            }
            BasePlayer attacker = info?.InitiatorPlayer;
            Puts($"Player {player.displayName} has died.Killed by {attacker?.displayName} {attacker == null}");
            MarkDead(player);
            return null;
        }
        #endregion

        #region Core

        private static void RemoveAllGames() {
            foreach (var entity in UnityEngine.Object.FindObjectsOfType<GameController>()) {
                UnityEngine.Object.DestroyImmediate(entity);
            }

            foreach (var entity in UnityEngine.Object.FindObjectsOfType<GameTeam>()) {
                UnityEngine.Object.DestroyImmediate(entity);
            }

            foreach (var entity in UnityEngine.Object.FindObjectsOfType<GamePlayer>()) {
                UnityEngine.Object.DestroyImmediate(entity);
            }
        }

        private void CreateGames() {
            RemoveAllGames();

            timer.Once(1f, () => {
                foreach (var def in config.gConfigs) {
                    if (def.enabled) {
                        var obj = new GameObject().AddComponent<GameController>();
                        obj.Setup(def);
                    }
                }
            });
        }

        private void JoinGame(BasePlayer player, string name, int teamNumber) {
            Puts($"Tryint to join {name} for team {teamNumber}");
            var obj = Interface.CallHook(nameof(CanJoinGame), player);
            player.ConsoleMessage($"[Games] Can join game '{name}' : {obj == null} (Current game: {obj})");
            if (obj != null) return;

            foreach (var game in UnityEngine.Object.FindObjectsOfType<GameController>()) {
                if (string.Equals(game.gConfig.shortname, name, StringComparison.OrdinalIgnoreCase)) {
                    game.PlayerJoin(player, teamNumber);
                }
            }
        }

        private void LeaveGame(BasePlayer player) {
            var obj = plugin.GetPlayer(player);
            if (obj != null) {
                UnityEngine.Object.DestroyImmediate(obj);
            }
        }

        private static void MarkReady(BasePlayer player, bool ar = false) {
            var obj = plugin.GetPlayer(player);
            if (obj != null && !obj.isReady) {
                obj.isReady = true;
                plugin.SendAll(obj.team.controller, ar ? Message.BecameReadyAuto : Message.BecameReady, player.displayName);
            }
        }

        private static void MarkDead(BasePlayer player) {
            var obj = plugin.GetPlayer(player);
            if (obj != null) obj.Died();
        }

        private static void CleanArena(GameController gControl) {
            Vector3 t1 = plugin.GetFirstSpawnPoint(plugin.LoadSpawnpoints(gControl.gConfig.team1Spawn));
            Vector3 t2 = plugin.GetFirstSpawnPoint(plugin.LoadSpawnpoints(gControl.gConfig.team2Spawn));

            Vector3 midPoint = (t1 + t2) / 2;
            float distance = Vector3.Distance(t1, t2) + 10;

            var entities = new List<BaseEntity>();
            Vis.Entities(midPoint, distance, entities);

            foreach (var entity in entities) {
                if (entity.IsValid() && entity.OwnerID != 0) {
                    BasePlayer owner = BasePlayer.FindByID(entity.OwnerID);
                    GamePlayer player = plugin.GetPlayer(owner);
                    if (owner == null || player == null || !gControl.allPlayersIncSpec.Contains(player)) continue;
                    if (!(entity is BasePlayer)) {
                        plugin.Puts($"Killing a {entity?.GetType().Name}");
                        entity?.Kill();
                    }
                }
            }
        }

        private void SendAll(GameController controller, Message key, params object[] args) {
            foreach (var player in controller.allPlayersIncSpec) {
                RefreshTeamUIPanel(player, controller);
                SendMessage(player.original, key, args);
            }
        }

        #endregion

        #region Scores
        private object OnEntityTakeDamage(BasePlayer player, HitInfo info) {
            if (info == null) return true;
            var initiator = plugin.GetPlayer(info?.InitiatorPlayer);
            if (initiator != null) initiator.damage += Convert.ToInt32(info.damageTypes.Total());
            return null;
        }

        private void OnEntityDeath(BasePlayer player, HitInfo info) {
            if (info == null) return;

            var initiator = plugin.GetPlayer(info?.InitiatorPlayer);
            var victim = plugin.GetPlayer(player);

            if (initiator != null) initiator.kills++;
            if (victim != null) victim.death++;

            if (initiator != null && victim != null) {
                string iniColor = plugin.TeamColor(initiator.team.teamNumber);
                string vicColor = plugin.TeamColor(victim.team.teamNumber);

                foreach (GamePlayer pl in initiator.currentGameContr.allPlayersIncSpec) {
                    SendReply(pl.original, $"<color={iniColor}>{initiator.original.displayName}</color> killed <color={vicColor}>{victim.original.displayName}</color>");
                }
            }
        }

        #endregion

        #region UI 2.0 General

        private const string elemMainTop = "KingGamesDeathmatch.UI.Main.Top";
        private const string elemMainBottom = "KingGamesDeathmatch.UI.Main.Bottom";
        private const string elemMainLeft = "KingGamesDeathmatch.UI.Main.Bottom.Left";
        private const string elemMainRight = "KingGamesDeathmatch.UI.Main.Bottom.Right";
        private CuiRectTransformComponent team1Position = new CuiRectTransformComponent {
            AnchorMin = "0 0.967",
            AnchorMax = "0 0.967",
            OffsetMin = "5 -30",
            OffsetMax = "305 -5"
        };

        private CuiRectTransformComponent team2Position = new CuiRectTransformComponent {
            AnchorMin = "1 0.967",
            AnchorMax = "1 0.967",
            OffsetMin = "-310 -30",
            OffsetMax = "-5 -5"
        };

        private void RefreshTeamUIPanel(GamePlayer player, GameController controller) {
            var containerTop = new CuiElementContainer();
            var containerBottomLeft = new CuiElementContainer();
            var containerBottomRight = new CuiElementContainer();

            // Main score panel
            containerTop.Add(new CuiElement {
                Name = elemMainTop,
                Parent = "Hud",
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0 0 0 0"
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMax = "1.0 1.0",
                        AnchorMin = "0.0 0.0"
                    },
                    //new CuiNeedsCursorComponent()
                }
            });

            if (controller.gConfig.tournament) {
                AddTournamentPanel(containerTop, controller);
            } else {
                AddTeamPanel(containerTop, controller.team1);
                AddTeamPanel(containerTop, controller.team2);
            }

            // Main panel
            containerBottomLeft.Add(new CuiElement {
                Name = elemMainLeft,
                Parent = "Hud.Menu",
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0 0 0 0"
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMax = "0.293 0.07",
                        AnchorMin = "0.185 0.04"
                    },
                    //new CuiNeedsCursorComponent()
                }
            });

            // Change team button
            containerBottomLeft.Add(new CuiButton {
                Text =
                {
                    Align = TextAnchor.MiddleCenter,
                    Text = player.team.teamNumber == 0 ? "JOIN TEAM" : "CHANGE TEAM",
                    FontSize = 17,
                },
                Button =
                {
                    Command = "deathmatch.changeteam",
                    Color = "0.5 0.5 0.5 0.7"
                },
                RectTransform =
                {
                    AnchorMin = "0 0",
                    AnchorMax = "1 1"
                }
            }, elemMainLeft);


            containerBottomRight.Add(new CuiElement {
                Name = elemMainRight,
                Parent = "Hud.Menu",
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0 0 0 0"
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMax = "0.848 0.09",
                        AnchorMin = "0.632 0.02"
                    },
                    //new CuiNeedsCursorComponent()
                }
            });

            //Leave button
            containerBottomRight.Add(new CuiButton {
                Text =
                 {
                     Align = TextAnchor.MiddleCenter,
                     Text = "LEAVE",
                     FontSize = 17,
                 },
                Button =
                 {
                     Command = "chat.say /leave",
                     Color = "0.5 0.5 0.5 0.7"
                 },
                RectTransform =
                 {
                    AnchorMin = "0.15 0",
                    AnchorMax = "0.49 0.45"
                 }
            }, elemMainRight);

            if (controller.owner == player) {
                // Settings button
                containerBottomRight.Add(new CuiButton {
                    Text =
                    {
                        Align = TextAnchor.MiddleCenter,
                        Text = "SETTINGS",
                        FontSize = 17,
                    },
                    Button =
                    {
                        Command = "api.deathmatch",
                        Color = "0.5 0.5 0.5 0.7"
                    },
                    RectTransform =
                    {
                    AnchorMin = "0.51 0.00",
                    AnchorMax = "0.85 0.45"
                    }
                }, elemMainRight);
            }

            // Owner Name
            containerBottomRight.Add(new CuiElement {
                Parent = elemMainRight,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"Owner: {controller.owner?.original?.displayName ?? "No One" }",
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 15
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0 0.50",
                        AnchorMax = "1 1.00",
                    },
                }
            });

            CuiHelper.DestroyUi(player.original, elemMainTop);
            CuiHelper.DestroyUi(player.original, elemMainLeft);
            CuiHelper.DestroyUi(player.original, elemMainRight);
            CuiHelper.AddUi(player.original, containerTop);
            CuiHelper.AddUi(player.original, containerBottomLeft);
            CuiHelper.AddUi(player.original, containerBottomRight);
        }
        private void AddTournamentPanel(CuiElementContainer container, GameController controller) {
            var parent = elemMainTop + ".team.tournament";
            var leftScore = parent + ".score.left";
            var rightScore = parent + ".score.right";
            var leftIamge = parent + ".image.left";
            var rightName = parent + ".name.right";
            var leftName = parent + ".name.left";
            var rightImage = parent + ".image.right";
            var midTimer = parent + ".mid.timer";
            var midRound = parent + ".mid.round";

            var leftColor = "1 0 0 0.9";
            var rightColor = "0 0 1 0.9";

            container.Add(new CuiElement {
                Name = parent,
                Parent = elemMainTop,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0.0 0.0 0.5 0.7"
                    },
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.90",
                        AnchorMax = "0.5 0.90",
                        OffsetMin = $"-210 -20",
                        OffsetMax = $"210 20"
                    }
                }
            });
            // score panel images
            //container.Add(new CuiElement {
            //    Name = leftIamge,
            //    Parent = parent,
            //    Components =
            //    {
            //        new CuiImageComponent
            //        {
            //            Color = "0 0 0.2 0.6"
            //        },
            //        new CuiRectTransformComponent {
            //            AnchorMin = "0 0",
            //            AnchorMax = "0 0",
            //            OffsetMin = $"0 0",
            //            OffsetMax = $"40 40"
            //        }
            //    }
            //});
            //container.Add(new CuiElement {
            //    Name = rightImage,
            //    Parent = parent,
            //    Components =
            //    {
            //        new CuiImageComponent
            //        {
            //            Color = "0 0 0.2 0.6"
            //        },
            //        new CuiRectTransformComponent {
            //            AnchorMin = "1 0",
            //            AnchorMax = "1 0",
            //            OffsetMin = $"-40 0",
            //            OffsetMax = $"0 40"
            //        }
            //    }
            //});

            // score panel
            container.Add(new CuiElement {
                Name = leftScore,
                Parent = parent,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0 0 0.2 0.6"
                    },
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0",
                        AnchorMax = "0.5 0",
                        OffsetMin = $"-70 0",
                        OffsetMax = $"-30 40"
                    }
                }
            });
            container.Add(new CuiElement {
                Name = rightScore,
                Parent = parent,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0 0 0.2 0.6"
                    },
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0",
                        AnchorMax = "0.5 0",
                        OffsetMin = $"30 0",
                        OffsetMax = $"70 40"
                    }
                }
            });

            // name panels            
            container.Add(new CuiElement {
                Name = leftName,
                Parent = leftScore,
                Components =
                {
                new CuiImageComponent {
                    Color = "0 0 0.2 0.3"
                },
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0.0",
                        AnchorMax = "0 0.0",
                        OffsetMin = $"-140 0",
                        OffsetMax = $"-2 40"
                    }
                }
            });
            container.Add(new CuiElement {
                Name = rightName,
                Parent = rightScore,
                Components =
                {
               new CuiImageComponent {
                   Color = "0 0 0.2 0.3"
               },
                   new CuiRectTransformComponent {
                       AnchorMin = "1 0.0",
                       AnchorMax = "1 0.0",
                       OffsetMin = $"2 0",
                       OffsetMax = $"140 40"
                   }
               }
            });

            //scores
            container.Add(new CuiElement {
                Parent = leftScore,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"7",
                        Color = leftColor,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 30
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = $"-28 -28",
                        OffsetMax = $"28 28"
                    },
                }
            });
            container.Add(new CuiElement {
                Parent = rightScore,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"12",
                        Color = rightColor,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 30
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = $"-28 -28",
                        OffsetMax = $"28 28"
                    },
                }
            });

            //team names
            container.Add(new CuiElement {
                Parent = leftName,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"Team A",
                        Color = leftColor,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 25
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0 0",
                        AnchorMax = "0 0",
                        OffsetMin = $"2 0",
                        OffsetMax = $"138 40"
                    },
                }
            });
            container.Add(new CuiElement {
                Parent = rightName,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"Team B",
                        Color = rightColor,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 25
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0 0",
                        AnchorMax = "0 0",
                        OffsetMin = $"2 0",
                        OffsetMax = $"138 40"
                    },
                }
            });

            //mid info
            container.Add(new CuiElement {
                Name = midTimer,
                Parent = parent,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0 0 0.2 0.3"
                    },
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0",
                        AnchorMax = "0.5 0",
                        OffsetMin = $"-28 0",
                        OffsetMax = $"28 40"
                    }
                }
            });
            container.Add(new CuiElement {
                Parent = midTimer,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"13:41",
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 20
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.5 0.2",
                        AnchorMax = "0.5 0.2",
                        OffsetMin = $"-28 0",
                        OffsetMax = $"28 40"
                    },
                }
            });
            container.Add(new CuiElement {
                Parent = midTimer,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"Round 13/30",
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 8
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.5 0.05",
                        AnchorMax = "0.5 0.05",
                        OffsetMin = $"-28 0",
                        OffsetMax = $"28 15"
                    },
                }
            });

        }

        private void AddTeamPanel(CuiElementContainer container, GameTeam team) {
            var teamID = team.teamNumber;
            var values = team.getPlayers;
            var parent = elemMainTop + ".team." + teamID;
            var transform = teamID == 2 ? team2Position : team1Position;
            var teamChar = teamID == 2 ? "B" : "A";
            string teamColor = plugin.TeamColor(teamID);

            // Team panel
            container.Add(new CuiElement {
                Name = parent,
                Parent = elemMainTop,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = "0.5 0.5 0.5 0.7"
                    },
                    transform,
                }
            });

            container.Add(new CuiElement {
                Parent = parent,
                Components =
                {
                    new CuiTextComponent
                    {
                        Text = $"   <color={teamColor}>Team {teamChar}</color> ({team.getPlayers.Length:00})  Wins: {team.wins:00}       Kills     Deaths     Damage     Ready",
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleLeft,
                        FontSize = 12
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0 0",
                        AnchorMax = "1 1",
                    },
                }
            });

            var startY = -20;
            var lastY = startY;
            var sizeY = 15;
            var offsetY = 5;

            foreach (var value in values) {
                // Name
                container.Add(new CuiElement {
                    Parent = parent,
                    Components =
                    {
                        new CuiTextComponent
                        {
                            Text = value.original.displayName,
                            Color = !value.isPlaying ? "1 0 0 1" : "0 1 0 1",
                            Align = TextAnchor.MiddleLeft,
                            FontSize = 12
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "0 0",
                            OffsetMin = $"10 {lastY}",
                            OffsetMax = $"120 {lastY + sizeY}"
                        },
                    }
                });

                // Kills
                container.Add(new CuiElement {
                    Parent = parent,
                    Components =
                    {
                        new CuiTextComponent
                        {
                            Text = value.kills.ToString(),
                            Color = "1 1 1 1",
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 12
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "0 0",
                            OffsetMin = $"120 {lastY}",
                            OffsetMax = $"155 {lastY + sizeY}"
                        },
                    }
                });

                // Death
                container.Add(new CuiElement {
                    Parent = parent,
                    Components =
                    {
                        new CuiTextComponent
                        {
                            Text = value.death.ToString(),
                            Color = "1 1 1 1",
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 12
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "0 0",
                            OffsetMin = $"160 {lastY}",
                            OffsetMax = $"200 {lastY + sizeY}"
                        },
                    }
                });

                // Damage
                container.Add(new CuiElement {
                    Parent = parent,
                    Components =
                    {
                        new CuiTextComponent
                        {
                            Text = value.damage.ToString(),
                            Color = "1 1 1 1",
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 12
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "0 0",
                            OffsetMin = $"205 {lastY}",
                            OffsetMax = $"250 {lastY + sizeY}"
                        },
                    }
                });

                // Ready
                container.Add(new CuiElement {
                    Parent = parent,
                    Components =
                    {
                        new CuiTextComponent
                        {
                            Text = value.isReady.ToString(),
                            Color = "1 1 1 1",
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 12
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "0 0",
                            OffsetMin = $"255 {lastY}",
                            OffsetMax = $"290 {lastY + sizeY}"
                        },
                    }
                });

                lastY -= sizeY + offsetY;
            }
        }

        #endregion

        #region UI 2.0 Settings

        private const string elemMainSettings = "test.ui.main";
        private const string elemPanelSettings = "test.ui.subpanel";

        private class ButtonSimple
        {
            public string layer = "Name";
            public string command = "Command";
        }

        private class ButtonComplex : ButtonSimple
        {
            public string textON = "ON";
            public string textOFF = "OFF";
            public bool isOn = true;
            public string colorON = "0 0.8 0 0.8";
            public string colorOFF = "0.8 0 0 0.8";
        }

        private ButtonComplex[] buttonsSettingsGeneral =
        {
            new ButtonComplex // 0
            {
                layer = "ARENA",
                textON = "PUBLIC",
                textOFF = "PRIVATE",
                command = "api.deathmatch visibility arena"
            },
            new ButtonComplex // 1
            {
                layer = "TEAM A",
                textON = "PUBLIC",
                textOFF = "PRIVATE",
                command = "api.deathmatch visibility team1"
            },
            new ButtonComplex // 2
            {
                layer = "TEAM B",
                textON = "PUBLIC",
                textOFF = "PRIVATE",
                command = "api.deathmatch visibility team2"
            },
            new ButtonComplex // 3
            {
                layer = "SPECTATORS",
                textON = "ALLOWED",
                textOFF = "FORBIDDEN",
                command = "api.deathmatch visibility spectators"
            },
            new ButtonComplex // 4
            {
                layer = "HS ONLY",
                colorOFF = "0 0.8 0 0.8",
                colorON = "0.8 0 0 0.8",
                command = "api.deathmatch hsonly"
            },
            new ButtonComplex // 5
            {
                layer = "AUTOBALANCE",
                command = "api.deathmatch autobalance"
            },
            new ButtonComplex // 6
            {
                layer = "FRIENDLY FIRE",
                colorOFF = "0 0.8 0 0.8",
                colorON = "0.8 0 0 0.8",
                command = "api.deathmatch friendlyfire"
            },
 //           new ButtonComplex // 7
 //           {
 //               layer = "TIME LIMIT",
 //               colorOFF = "0 0.8 0 0.8",
 //               colorON = "0.8 0 0 0.8",
 //               command = "api.deathmatch timelimit"
 //           },
//            new ButtonComplex // 8
//            {
//                layer = "TIME",
//                textON = "DAY",
//                textOFF = "NIGHT",
//            },
        };

        private ButtonSimple[] buttonsSettingsAdditional =
        {
            new ButtonSimple
            {
                layer = "FORCE START",
                command = "api.deathmatch forcestart"
            },
            new ButtonSimple
            {
                layer = "RESTART ROUND",
                command = "api.deathmatch restartround"
            },
        };

        private ButtonSimple[] buttonsNavigation =
        {
            new ButtonSimple
            {
                layer = "GENERAL"
            },
            new ButtonSimple
            {
                layer = "KITS"
            },
            new ButtonSimple
            {
                layer = "PLAYERS"
            },
        };

        private void UIOpenSettings(GamePlayer player, int type) {
            var container = new CuiElementContainer
            {
                // Main panel
                new CuiElement
                {
                    Name = elemMainSettings,
                    Parent = "Overlay",
                    Components =
                    {
                        new CuiImageComponent {Color = "0 0 0 0.9"},
                        new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1"},
                        new CuiNeedsCursorComponent()
                    }
                },
                // Border
                new CuiElement
                {
                    Name = elemMainSettings + ".border",
                    Parent = elemMainSettings,
                    Components =
                    {
                        new CuiImageComponent {Color = panelColor2,},
                        new CuiRectTransformComponent {AnchorMin = "0 0.93", AnchorMax = "1 1",},
                    }
                },
                // Sub panel
                new CuiElement
                {
                    Name = elemPanelSettings,
                    Parent = elemMainSettings,
                    Components =
                    {
                        new CuiImageComponent {Color = "0.2 0.2 0.2 0"},
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0.334 0.5",
                            AnchorMax = "0.334 0.5",
                            OffsetMin = "-300 -200",
                            OffsetMax = "300 200"
                        },
                    }
                }
            };

            switch (type) {
                case 1:
                    AddGeneralPage(container, player.team.controller);
                    break;

                case 2:
                    AddKitsPage(container, player.team.controller);
                    break;

                case 3:
                    AddPlayersPage(container, player.team.controller);
                    break;
            }

            // Navigation
            var offsetX = 50;
            var sizeX = 150;
            var sizeY = 50;
            var lastY = 0;
            var lastX = -(buttonsNavigation.Length * (sizeX + offsetX)) / 2;
            var i = 0;
            foreach (var button in buttonsNavigation) {
                // Button
                container.Add(new CuiButton {
                    Text =
                        {
                            Text = button.layer,
                            Color = button.command,
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 25
                        },
                    Button =
                        {
                            Command = $"api.deathmatch {++i}",
                            Color = "1 0.5 0 0"
                        },
                    RectTransform =
                        {
                            AnchorMin = "0.5 0.5",
                            AnchorMax = "0.5 0.5",
                            OffsetMin = $"{lastX} {lastY - sizeY / 2}",
                            OffsetMax = $"{lastX + sizeX} {lastY + sizeY / 2}"
                        }
                }, elemMainSettings + ".border");

                lastX += sizeX + offsetX;
            }

            // Close button
            container.Add(new CuiButton {
                Text =
                {
                    Align = TextAnchor.MiddleCenter,
                    Text = "X",
                    FontSize = 30,
                },
                Button =
                {
                    Close = elemMainSettings,
                    Color = "1 0 0 0"
                },
                RectTransform =
                {
                    AnchorMin = "1 1",
                    AnchorMax = "1 1",
                    OffsetMin = "-45 -45",
                    OffsetMax = "-5 -5"
                }
            }, elemMainSettings);

            CuiHelper.DestroyUi(player.original, elemMainSettings);
            CuiHelper.AddUi(player.original, container);
        }

        private void AddGeneralPage(CuiElementContainer container, GameController controller) {
            var startX = 0;
            var startY = 0;
            var offsetX = 5;
            var offsetY = 5;
            var sizeX = 250;
            var sizeY = 50;
            var lastX = startX;
            var lastY = startY;

            var buttons = buttonsSettingsGeneral.ToArray();
            buttons[0].isOn = controller.gConfig.arenaPublic;
            buttons[1].isOn = controller.gConfig.team1Public;
            buttons[2].isOn = controller.gConfig.team2Public;
            buttons[3].isOn = controller.gConfig.spectatorsAllowed;
            buttons[4].isOn = controller.gConfig.headshotOnly;
            buttons[5].isOn = controller.gConfig.autoBalance;
            buttons[6].isOn = controller.gConfig.friendlyFire;
            //buttons[7].isOn = controller.gConfig.roundHasTimeLimit;

            foreach (var button in buttonsSettingsGeneral) {
                // Name
                container.Add(new CuiButton {
                    Text =
                    {
                        Text = button.layer,
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 25
                    },
                    Button =
                    {
                        Command = button.command,
                        Color = "1 0 0 0"
                    },
                    RectTransform =
                    {
                        AnchorMin = "0 1",
                        AnchorMax = "0 1",
                        OffsetMin = $"{lastX} {lastY - sizeY}",
                        OffsetMax = $"{lastX + sizeX} {lastY}"
                    }
                }, elemPanelSettings);

                lastX += sizeX + offsetX;

                // Button
                container.Add(new CuiButton {
                    Text =
                    {
                        Text = button.isOn ? button.textON : button.textOFF,
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 25
                    },
                    Button =
                    {
                        Command = button.command,
                        Color = button.isOn ? button.colorON : button.colorOFF,
                    },
                    RectTransform =
                    {
                        AnchorMin = "0 1",
                        AnchorMax = "0 1",
                        OffsetMin = $"{lastX} {lastY - sizeY}",
                        OffsetMax = $"{lastX + sizeX} {lastY}"
                    }
                }, elemPanelSettings);

                lastY -= sizeY + offsetY;
                lastX = startX;
            }

            // Border
            container.Add(new CuiElement {
                Parent = elemPanelSettings,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = panelColor2,
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0 1",
                        AnchorMax = "0 1",
                        OffsetMin = $"{sizeX * 2 + offsetX * 2} {lastY}",
                        OffsetMax = $"{sizeX * 2 + offsetX * 2 + 5} {startY + 5}"
                    }
                }
            });

            startX = sizeX * 2 + offsetX * 2 + 10;
            startY = 0;
            offsetX = 5;
            offsetY = 5;
            sizeX = 250;
            sizeY = 50;
            lastX = startX;
            lastY = startY;

            foreach (var button in buttonsSettingsAdditional) {
                // Button
                container.Add(new CuiButton {
                    Text =
                    {
                        Text = button.layer,
                        Color = button.command,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 25
                    },
                    Button =
                    {
                        Command = button.command,
                        Color = "1 0.5 0 0.5"
                    },
                    RectTransform =
                    {
                        AnchorMin = "0 1",
                        AnchorMax = "0 1",
                        OffsetMin = $"{lastX} {lastY - sizeY}",
                        OffsetMax = $"{lastX + sizeX} {lastY}"
                    }
                }, elemPanelSettings);

                lastY -= sizeY + offsetY;
                lastX = startX;
            }

            startX = 50;
            startY = 0;
            offsetX = 50;
            offsetY = 5;
            sizeX = 150;
            sizeY = 50;
            lastX = startX;
            lastY = startY;

            lastX = -(buttonsNavigation.Length * (sizeX + offsetX)) / 2;

            foreach (var button in buttonsNavigation) {
                // Button
                container.Add(new CuiButton {
                    Text =
                        {
                            Text = button.layer,
                            Color = button.command,
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 25
                        },
                    Button =
                        {
                            Command = button.command,
                            Color = "1 0.5 0 0"
                        },
                    RectTransform =
                        {
                            AnchorMin = "0.5 0.5",
                            AnchorMax = "0.5 0.5",
                            OffsetMin = $"{lastX} {lastY - sizeY / 2}",
                            OffsetMax = $"{lastX + sizeX} {lastY + sizeY / 2}"
                        }
                }, elemMainSettings + ".border");

                lastX += sizeX + offsetX;
            }
        }

        private void AddKitsPage(CuiElementContainer container, GameController controller) {
            // Border
            container.Add(new CuiElement {
                Parent = elemMainSettings,
                Components =
                {
                    new CuiImageComponent
                    {
                        Color = panelColor2,
                    },
                    new CuiRectTransformComponent
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = "-3 -300",
                        OffsetMax = "3 250"
                    }
                }
            });

            var startX = -550;
            var startY = 120;
            var offsetX = 5;
            var offsetY = 5;
            var sizeX = 100;
            var sizeY = 25;
            var lastX = startX;
            var lastY = startY;
            var i = 0;

            // Team A
            container.Add(new CuiButton {
                Text =
                    {
                        Text = $"<color={plugin.TeamColor(controller.team1.teamNumber)}>Team A:</color> {controller.team1.kitName}",
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleLeft,
                        FontSize = 25
                    },
                Button =
                    {

                        Color = "1 0.5 0 0"
                    },
                RectTransform =
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = $"{lastX} {lastY + sizeY}",
                        OffsetMax = $"{lastX + sizeX * 4} {lastY + sizeY * 3}"
                    }
            }, elemMainSettings);

            foreach (var name in config.kitsWeapons) {
                if (i >= 50) {
                    break;
                }

                // Button
                container.Add(new CuiButton {
                    Text =
                    {
                        Text = name,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 15
                    },
                    Button =
                    {

                        Command = $"api.deathmatch kit team1 {name}",
                        Color = panelColor2
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = $"{lastX} {lastY - sizeY / 2}",
                        OffsetMax = $"{lastX + sizeX} {lastY + sizeY / 2}"
                    }
                }, elemMainSettings);


                if (++i % 5 == 0) {
                    lastY -= sizeY + offsetY;
                    lastX = startX;
                } else {
                    lastX += sizeX + offsetX;
                }
            }

            startX = 200;
            startY = 120;
            offsetX = 5;
            offsetY = 5;
            sizeX = 100;
            sizeY = 25;
            lastX = startX;
            lastY = startY;
            i = 0;

            // Team B
            container.Add(new CuiButton {
                Text =
                    {
                        Text = $"<color={plugin.TeamColor(controller.team2.teamNumber)}>Team B:</color> {controller.team2.kitName}",
                        Color = "1 1 1 1",
                        Align = TextAnchor.MiddleLeft,
                        FontSize = 25
                    },
                Button =
                    {

                        Color = "1 0.5 0 0"
                    },
                RectTransform =
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = $"{lastX - sizeX} {lastY + sizeY}",
                        OffsetMax = $"{lastX + sizeX * 4} {lastY + sizeY * 3}"
                    }
            }, elemMainSettings);

            foreach (var name in config.kitsWeapons) {
                if (i >= 50) {
                    break;
                }

                // Button
                container.Add(new CuiButton {
                    Text =
                    {
                        Text = name,
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 15
                    },
                    Button =
                    {
                        Command = $"api.deathmatch kit team2 {name}",
                        Color = panelColor2
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.5 0.5",
                        AnchorMax = "0.5 0.5",
                        OffsetMin = $"{lastX - sizeX} {lastY - sizeY / 2}",
                        OffsetMax = $"{lastX} {lastY + sizeY / 2}"
                    }
                }, elemMainSettings);


                if (++i % 5 == 0) {
                    lastY -= sizeY + offsetY;
                    lastX = startX;
          
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху