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

FREE WipeSchedule : 1.0.2 1.0.2

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("WipeSchedule", "Mevent", "1.0.2")]
    public class WipeSchedule : RustPlugin
    {
        #region Fields
        private string Layer = "UI_WipeSchedule";
        public enum Types
        {
            None,
            GLOBAL_WIPE,
            WIPE
        }

        private Dictionary<int, string> DaysOfWeek = new Dictionary<int, string>()
        {
            [1] = "Понедельник",
            [2] = "Вторник",
            [3] = "Среда",
            [4] = "Четверг",
            [5] = "Пятница",
            [6] = "Суббота",
            [7] = "Воскресенье",
        };

        public List<DayClass> DaysList = new List<DayClass>();
        public class DayClass
        {
            public int day;
            public string color;
            public Types types;
            public string description;
        }
        #endregion

        #region Config
        private static ConfigData config;
        private class ConfigData
        {
            [JsonProperty("Список чат-команд для открытия календаря")]
            public List<string> Commands;
            [JsonProperty("Раз во сколько секунд обновлять календарь?")]
            public int Delay;
            [JsonProperty("Цвет дней в нынешнем месяце")]
            public string ActiveColor;
            [JsonProperty("Цвет дней в предыдущем и следующем месяце")]
            public string DisactiveColor;
            [JsonProperty("Настройка")]
            public Dictionary<int, WipeClass> wipe;
        }
        private class WipeClass
        {
            [JsonProperty("Тип")]
            public Types type;
            [JsonProperty("Цвет кнопки")]
            public string color;
            [JsonProperty("Описание")]
            public string description;
        }

        private ConfigData GetDefaultConfig()
        {
            return new ConfigData
            {
                Commands = new List<string>
                {
                    "wipe", "schedule", "wipedate"
                },
				Delay = 7200,
                ActiveColor = "0.67 0.67 0.67 0.8",
                DisactiveColor = "0 0 0 0.6",
                wipe = new Dictionary<int, WipeClass>
                {
                    {
                        1, new WipeClass
                        {
                            color = "0.78 0.30 0.26 0.8",
                            type = Types.GLOBAL_WIPE,
                            description = "ГЛОБАЛЬНЫЙ ВАЙП"
                        }
                    },
                    {
                        9, new WipeClass
                        {
                            color = "0.45 0.64 0.45 0.8",
                            type = Types.WIPE,
                            description = "ВАЙП КАРТЫ"
                        }
                    },
                    {
                        16, new WipeClass
                        {
                            color = "0.78 0.30 0.26 0.8",
                            type = Types.GLOBAL_WIPE,
                            description = "ГЛОБАЛЬНЫЙ ВАЙП"
                        }
                    },
                    {
                        23, new WipeClass
                        {
                            color = "0.45 0.64 0.45 0.8",
                            type = Types.WIPE,
                            description = "ВАЙП КАРТЫ"
                        }
                    },
                    {
                        30, new WipeClass
                        {
                            color = "0.45 0.64 0.45 0.8",
                            type = Types.WIPE,
                            description = "ВАЙП КАРТЫ"
                        }
                    }
                }
            };
        }
        protected override void LoadConfig()
        {
            base.LoadConfig();

            try
            {
                config = Config.ReadObject<ConfigData>();
                if (config == null)
                {
                    LoadDefaultConfig();
                }
            }
            catch
            {
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        protected override void LoadDefaultConfig()
        {
            PrintError("Configuration file is corrupt(or not exists), creating new one!");
            config = GetDefaultConfig();
        }
        protected override void SaveConfig() => Config.WriteObject(config);
        #endregion

        #region Hooks
        void OnServerInitialized()
        {
            PrintWarning("  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            PrintWarning($"     {Name} v{Version} loading");
            PrintWarning($"        Plugin loaded - OK");
            PrintWarning("  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

            for (int i = 0; i < config.Commands.Count; i++)
                cmd.AddChatCommand(config.Commands[i], this, nameof(CmdChatSchedule));

            cmd.AddConsoleCommand("UI_Schedule", this, nameof(CmdConsoleSchedule));
            
            CalculateTable();

            timer.Every(config.Delay, () => CalculateTable());
        }
        void CmdChatSchedule(BasePlayer player, string command, string[] args)
        {
            BuildUI(player);
        }
        void CmdConsoleSchedule(ConsoleSystem.Arg args)
        {
            var player = args.Player();

            int index = 0;
            if (!args.HasArgs(1) || !int.TryParse(args.Args[0], out index)) return;

            var check = DaysList[index];
            if (check.types != Types.None)
            {
                var container = new CuiElementContainer();
                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Text = { Text = $"{check.description}", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf" }
                }, Layer + $".Day.Of.{index}", Layer + $".Day.Of.{index}.Text");
                CuiHelper.DestroyUi(player, Layer + $".Day.Of.{index}.Text");
                CuiHelper.AddUi(player, container);
            }
        }
        #endregion

        #region Interface
        void BuildUI(BasePlayer player)
        {
            var container = new CuiElementContainer();
            var monthName = FirstUpper(DateTime.Now.ToString("MMMM", CultureInfo.GetCultureInfo("ru-RU")));

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                Button = { Color = "0 0 0 0.3", Close = Layer + ".BG", Material = "assets/content/ui/uibackgroundblur.mat" },
                Text = { Text = "" }
            }, "Overlay", Layer + ".BG");
            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-350 -180", OffsetMax = "350 200" },
                Image = { Color = "0.3 0.3 0.3 0.5" },
                CursorEnabled = true
            }, Layer + ".BG", Layer);
            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 0", OffsetMax = "0 150" },
                Text = { Text = $"<b>{monthName}</b>", FontSize = 32, Align = TextAnchor.MiddleCenter }
            }, Layer);

            #region for
            var xDaysSwitch = 2.5f;
            for (int i = 1; i <= 7; i++)
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{xDaysSwitch} 5", OffsetMax = $"{xDaysSwitch + 95} 30" },
                    Button = { Command = "", Color = "0.37 0.37 0.37 0.8" },
                    Text = { Text = DaysOfWeek[i], Align = TextAnchor.MiddleCenter, FontSize = 13, Color = "1 1 1 0.8", Font = "robotocondensed-regular.ttf" }
                }, Layer);
                xDaysSwitch += 100;
            }

            var ySwitch = -5;
            var xSwitch = 2.5f;
            for (int i = 0; i < DaysList.Count; i++)
            {
                var check = DaysList[i];

                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{xSwitch} {ySwitch - 70}", OffsetMax = $"{xSwitch + 95} {ySwitch}" },
                    Button = { Color = check.color, Command = $"UI_Schedule {i}", FadeIn = 1f },
                    Text = { Text = "" }
                }, Layer, Layer + $".Day.Of.{i}");
                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Text = { Text = $"{check.day}", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 16 }
                }, Layer + $".Day.Of.{i}", Layer + $".Day.Of.{i}.Text");

                xSwitch += 100;

                if ((i + 1) % 7 == 0)
                {
                    xSwitch = 2.5f;
                    ySwitch -= 75;
                }
            }
            #endregion

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "5 -25", OffsetMax = "25 -5" },
                Image = { Color = "0.78 0.30 0.26 0.8" }
            }, Layer, Layer + ".GlobalWipe");
            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "1 0", AnchorMax = "1 1", OffsetMin = "5 0", OffsetMax = "300 0" },
                Text = { Text = "- Глобальный вайп с удалением чертежей", Align = TextAnchor.MiddleLeft, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, Layer + ".GlobalWipe");
            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "400 -25", OffsetMax = "420 -5" },
                Image = { Color = "0.45 0.64 0.45 0.8", }
            }, Layer, Layer + ".Wipe");
            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "1 0", AnchorMax = "1 1", OffsetMin = "5 0", OffsetMax = "300 0" },
                Text = { Text = "- Вайп без удаления чертежей", Align = TextAnchor.MiddleLeft, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, Layer + ".Wipe");

            CuiHelper.DestroyUi(player, Layer);
            CuiHelper.AddUi(player, container);
        }
        #endregion

        #region Utils
        void CalculateTable()
        {
            DaysList.Clear();

            Calendar myCal = CultureInfo.InvariantCulture.Calendar;
            DateTime myDT = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, myCal);

            var PreviousMonth = myDT.AddMonths(-1);
            var DaysInPreviousMonth = (int) DateTime.DaysInMonth(PreviousMonth.Year, PreviousMonth.Month);

            int j = Convert.ToInt32(myCal.GetDayOfWeek(myDT)) - 1;
            for (int m = 0; m < j; m++) 
            {
                DaysList.Add(new DayClass
                {
                    day = DaysInPreviousMonth + m - 1,
                    color = config.DisactiveColor,
                    description = string.Empty,
                    types = Types.None
                });
            }
            
            int month = myCal.GetMonth(myDT);
            while (myCal.GetMonth(myDT) == month)
            {
                var check = config.wipe.Where(x => x.Key == myDT.Day).FirstOrDefault().Value != null;
                
                DaysList.Add(new DayClass
                {
                    day = myDT.Day,
                    color = check ? config.wipe[myDT.Day].color : config.ActiveColor,
                    description = check ? config.wipe[myDT.Day].description : string.Empty,
                    types = check ? config.wipe[myDT.Day].type : Types.None
                });

                myDT = myDT.AddDays(1);
                j--;
            }

            if (DaysList.Count < 36)
            {
                var DaysToEndTable = 35 - DaysList.Count;

                for (int i = 1; i <= DaysToEndTable; i++)
                {
                    DaysList.Add(new DayClass
                    {
                        day = i,
                        color = config.DisactiveColor,
                        description = string.Empty,
                        types = Types.None
                    });
                }
            }
        }

        public string FirstUpper(string str)
        {
            str = str.ToLower();
            string[] s = str.Split(' ');
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].Length > 1)
                    s[i] = s[i].Substring(0, 1).ToUpper() + s[i].Substring(1, s[i].Length - 1);
                else s[i] = s[i].ToUpper();
            }
            return string.Join(" ", s);
        }
        #endregion
    }
}

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