C#:
using System;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
[Info("MWipeDate", "Mystery", "0.0.1")]
public class MWipeDate : RustPlugin {
[PluginReference]
private Plugin ImageLibrary;
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["p1"]
= "Monday", ["v2"] = "Tuesday", ["s3"] = "Wednesday", ["h4"] = "Thursday", ["p5"] = "Friday", ["s6"] = "Saturday", ["v7"] = "Sunday", ["8"] = "WIPE WITH DELETION OF STUDIES", ["9"] = "WIPE WITHOUT DELETING STUDIES",
}
, this);
lang.RegisterMessages(new Dictionary<string, string> {
["p1"]
= "Понедельник", ["v2"] = "Вторник", ["s3"] = "Среда", ["h4"] = "Четверг", ["p5"] = "Пятница", ["s6"] = "Суббота", ["v7"] = "Воскресенье", ["8"] = "ВАЙП С УДАЛЕНИЕМ ИЗУЧЕНИЙ", ["9"] = "ВАЙП БЕЗ УДАЛЕНИЯ ИЗУЧЕНИЙ",
}
, this, "ru");
/// "ВАЙП С УДАЛЕНИЕМ ИЗУЧЕНИЙ" : "ВАЙП БЕЗ УДАЛЕНИЯ ИЗУЧЕНИЙ" Msg("8", player.UserIDString) : Msg("9", player.UserIDString),
}
private string Msg(string key, string userid = null, params object[] obj) {
return string.Format(lang.GetMessage(key, this, userid), obj);
}
#region Variables
private string Layer = "UI_WipeDateLayer";
private string ResultJSON = string.Empty;
private CuiElementContainer container = new CuiElementContainer();
private Dictionary<DayOfWeek, string> Translations = new Dictionary<DayOfWeek, string> {
[DayOfWeek.Monday]
= "p1", [DayOfWeek.Tuesday] = "v2", [DayOfWeek.Wednesday] = "s3", [DayOfWeek.Thursday] = "h4", [DayOfWeek.Friday] = "p5", [DayOfWeek.Saturday] = "s6", [DayOfWeek.Sunday] = "v7",
}
;
private class Configuration {
public int MonthID;
public Dictionary<DayOfWeek, Dictionary<int, int>> Dates = new Dictionary<DayOfWeek, Dictionary<int, int>>();
public Dictionary<DayOfWeek, Dictionary<int, int>> NextDates = new Dictionary<DayOfWeek, Dictionary<int, int>>();
public static Configuration GenerateDefault() {
return new Configuration {
MonthID = 0, NextDates = new Dictionary<DayOfWeek, Dictionary<int, int>> {
[DayOfWeek.Monday]
= new Dictionary<int, int>(), [DayOfWeek.Tuesday] = new Dictionary<int, int>(), [DayOfWeek.Wednesday] = new Dictionary<int, int>(), [DayOfWeek.Thursday] = new Dictionary<int, int>(), [DayOfWeek.Friday] = new Dictionary<int, int>(), [DayOfWeek.Saturday] = new Dictionary<int, int>(), [DayOfWeek.Sunday] = new Dictionary<int, int>(),
}
, Dates = new Dictionary<DayOfWeek, Dictionary<int, int>> {
[DayOfWeek.Monday]
= new Dictionary<int, int>(), [DayOfWeek.Tuesday] = new Dictionary<int, int>(), [DayOfWeek.Wednesday] = new Dictionary<int, int>(), [DayOfWeek.Thursday] = new Dictionary<int, int>(), [DayOfWeek.Friday] = new Dictionary<int, int>(), [DayOfWeek.Saturday] = new Dictionary<int, int>(), [DayOfWeek.Sunday] = new Dictionary<int, int>(),
}
}
;
}
}
#endregion
#region Variables
private static Configuration Settings;
#endregion
#region Interface
protected override void LoadConfig() {
base.LoadConfig();
try {
Settings = Config.ReadObject<Configuration>();
if (Settings == null) LoadDefaultConfig();
}
catch {
PrintWarning($"Ошибка чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
protected override void LoadDefaultConfig() => Settings = Configuration.GenerateDefault();
protected override void SaveConfig() => Config.WriteObject(Settings);
private void OnServerInitialized() {
DateTime now = DateTime.Now;
if (Settings.MonthID != now.Month) {
bool currentFull = true;
Settings = Configuration.GenerateDefault();
Settings.MonthID = now.Month;
for (int i = 1; i <= DateTime.DaysInMonth(now.Year, now.Month);
i++) {
var date = new DateTime(now.Year, now.Month, i);
if (!Settings.Dates.ContainsKey(date.DayOfWeek)) Settings.Dates.Add(date.DayOfWeek, new Dictionary<int, int>());
if (i == 1) {
if (date.DayOfWeek == DayOfWeek.Sunday) {
for (int t = 0; t < (int) 7;
t++) {
if (((DayOfWeek) t) != DayOfWeek.Sunday) Settings.Dates[(DayOfWeek) t].Add(-1, -1);
}
}
for (int t = 0; t < (int) date.DayOfWeek;
t++) {
if (((DayOfWeek) t) != DayOfWeek.Sunday) Settings.Dates[(DayOfWeek) t].Add(-1, -1);
}
}
int curWipe = date.DayOfWeek == DayOfWeek.Saturday ? currentFull ? 2 : 1 : 0;
Settings.Dates[date.DayOfWeek].Add(i, curWipe);
currentFull = curWipe == 0 ? currentFull : !currentFull;
}
currentFull = true;
for (int i = 1; i <= DateTime.DaysInMonth(now.Year, now.Month + 1);
i++) {
var date = new DateTime(now.Year, now.Month + 1, i);
if (!Settings.NextDates.ContainsKey(date.DayOfWeek)) Settings.NextDates.Add(date.DayOfWeek, new Dictionary<int, int>());
if (i == 1) {
if (date.DayOfWeek == DayOfWeek.Sunday) {
for (int t = 0; t < (int) 7;
t++) {
if (((DayOfWeek) t) != DayOfWeek.Sunday) Settings.NextDates[(DayOfWeek) t].Add(-1, -1);
}
}
for (int t = 0; t < (int) date.DayOfWeek;
t++) {
if (((DayOfWeek) t) != DayOfWeek.Sunday) Settings.NextDates[(DayOfWeek) t].Add(-1, -1);
}
}
int curWipe = date.DayOfWeek == DayOfWeek.Saturday ? currentFull ? 2 : 1 : 0;
Settings.NextDates[date.DayOfWeek].Add(i, curWipe);
currentFull = curWipe == 0 ? currentFull : !currentFull;
}
var max = Settings.Dates.Max(p => p.Value.Count);
foreach (var check in Settings.Dates) {
while (check.Value.Count < max) check.Value.Add(Oxide.Core.Random.Range(5, 100) * -1, -1);
}
max = Settings.NextDates.Max(p => p.Value.Count);
foreach (var check in Settings.NextDates) {
while (check.Value.Count < max) check.Value.Add(Oxide.Core.Random.Range(5, 100) * -1, -1);
}
}
PrintWarning(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
PrintWarning($" {Name} v{Version} loading");
if (!ImageLibrary) {
PrintError(" Install plugin: 'ImageLibrary'");
Core.Interface.Oxide.UnloadPlugin(Name);
return;
}
PrintWarning(" Plugin loaded - OK");
PrintWarning(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
#endregion
private void Unload() {
BasePlayer.activePlayerList.ToList().ForEach(p => {
CuiHelper.DestroyUi(p, Layer);
}
);
}
#region Commands
[ChatCommand("calendar")]
private void CmdChatWipe(BasePlayer player) {
Wipe(player);
}
void Wipe(BasePlayer player) {
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiPanel() {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Image = {
Color = "0 0 0 0"
}
}
, "Mystery", Layer);
float width = 0.1435f, height = 0.063f, startxBox = 0.0f, startyBox = 0.996f - height, xmin = startxBox, ymin = startyBox, z = 0;
foreach (var day in Settings.Dates) {
var curName = Translations[day.Key];
var firstDay = day.Value.FirstOrDefault();
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width * 0.95} {ymin + height * 0.98}"
}
, Button = {
Color = firstDay.Value <= 0 ? firstDay.Key <= -1 ? "0.89 0.81 0.70 0.3" : firstDay.Key == DateTime.Now.Day ? "0.69 0.65 0.62 1" : "0.89 0.81 0.70 0.4" : firstDay.Value == 1 ? "0.52 0.36 0.36 0.8" : "0.36 0.43 0.52 0.8"
}
, Text = {
Text = Msg($"{curName.ToLower()}", player.UserIDString), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 12, Color = "1 1 1 0.7"
}
}
, Layer, Layer + curName);
float width1 = 0.99f, height1 = 2.905f, startxBox1 = 0.0f, startyBox1 = 0.0f - height1, xmin1 = startxBox1, ymin1 = startyBox1;
foreach (var date in day.Value) {
if (date.Key == DateTime.Now.Day && date.Value >= 1) {
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 0.95}", OffsetMin = "0 0", OffsetMax = "0 0"
}
, Image = {
Color = date.Value <= 0 ? date.Key <= -1 ? "0.89 0.81 0.70 0.3" : date.Key == DateTime.Now.Day ? "0.69 0.65 0.62 1" : "0.89 0.81 0.70 0.4" : date.Value == 1 ? "0.52 0.36 0.36 0.8" : "0.36 0.43 0.52 0.8"
}
}
, Layer + curName, Layer + date.Key);
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"0 0", AnchorMax = $"1 0", OffsetMin = $"0 0", OffsetMax = $"0 3"
}
, Image = {
Color = "0.69 0.65 0.62 1"
}
}
, Layer + date.Key);
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"1 0", AnchorMax = $"1 1", OffsetMin = $"-3 0", OffsetMax = $"0 0"
}
, Image = {
Color = "0.69 0.65 0.62 1"
}
}
, Layer + date.Key);
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"0 0", AnchorMax = $"0 1", OffsetMin = $"0 0", OffsetMax = $"3 0"
}
, Image = {
Color = "0.69 0.65 0.62 1"
}
}
, Layer + date.Key);
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"0 1", AnchorMax = $"1 1", OffsetMin = $"0 -3", OffsetMax = $"0 0"
}
, Image = {
Color = "0.69 0.65 0.62 1"
}
}
, Layer + date.Key);
}
else {
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 0.95}", OffsetMin = "0 0", OffsetMax = "0 0"
}
, Image = {
Color = date.Value <= 0 ? date.Key <= -1 ? "0.89 0.81 0.70 0.3" : date.Key == DateTime.Now.Day ? "0.69 0.65 0.62 1" : "0.89 0.81 0.70 0.4" : date.Value == 1 ? "0.52 0.36 0.36 0.8" : "0.36 0.43 0.52 0.8"
}
}
, Layer + curName, Layer + date.Key);
}
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = date.Key <= -1 ? "" : date.Key.ToString(), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", FontSize = 38, Color = date.Value <= 0 && date.Key == DateTime.Now.Day ? "0.2 0.2 0.2 0.7" : "0.81 0.77 0.74 1"
}
}
, Layer + date.Key, Layer + date.Key + "T");
if (date.Value > 0) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = $"UI_WipeDate {date.Value == 2} {date.Key}"
}
, Text = {
Text = ""
}
}
, Layer + date.Key);
}
xmin1 += width1;
if (xmin1 + width1 >= 0) {
xmin1 = startxBox1;
ymin1 -= height1;
}
}
xmin += width;
if (xmin + width >= 6) {
xmin = startxBox;
ymin -= height;
}
}
CuiHelper.AddUi(player, container);
}
#endregion
[ConsoleCommand("UI_WipeDate")]
private void ConsoleHandler(ConsoleSystem.Arg args) {
var player = args.Player();
if (!player || !args.HasArgs(1)) return;
bool fullWipe = bool.Parse(args.Args[0]);
int icon = int.Parse(args.Args[1]);
string text = fullWipe ? Msg("8", player.UserIDString) : Msg("9", player.UserIDString);
CuiHelper.DestroyUi(player, Layer + icon + "T");
CuiHelper.AddUi(player, new CuiElementContainer {
{
new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = text, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14, Color = "0.81 0.77 0.74 1"
}
}
, Layer + icon
}
}
);
}
}
}