C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Oxide.Plugins
{
[Info("MBPromoCode", "Barry_Allenn", "1.3.0")]
[Description("Plugin for promo codes with an interface for entering and activating promo codes")]
public class MBPromoCode : RustPlugin
{
[PluginReference]
private Plugin ImageLibrary;
private PluginConfig config;
private Dictionary<string, int> promoCodeActivations = new Dictionary<string, int>();
private Dictionary<string, List<string>> usedPromoCodesByPlayer = new Dictionary<string, List<string>>();
private class PluginConfig
{
[JsonProperty("PromoCodes")]
public Dictionary<string, PromoCodeData> PromoCodes { get; set; }
[JsonProperty("QR code to join your Discord server")]
public string QRDISCORD_BA = "https://i.ibb.co/Zd1XKwh/Untitled-3.png";
[JsonProperty("Text in the first column")] public string textFPDEText = "Discord";
[JsonProperty("Text in the second column")] public string texttkFPDEText = "TikTok";
[JsonProperty("Link to the first column")] public string DSFPDEText = "https://discord.gg/qXkHDGPkmn";
[JsonProperty("Link to the second column")] public string TKFPDEText = "https://www.tiktok.com/@freedom.ua.rust";
[JsonProperty("QR code of your TikTok profile")]
public string QRTITTTOK_BA = "https://i.ibb.co/K7pH2jH/Untitled-2.png";
[JsonProperty("MessagePrefix")]
public string MessagePrefix { get; set; } = "<color=#0057b8>[Your Prefix]</color> ";
[JsonProperty("Webhook to send to discord")]
public string DiscordWebhookUrl { get; set; } = "Enter_your_webhook_URL_here";
[JsonProperty("true or false sending promo code messages to the global chat")]
public bool EnablePromoCodeBroadcast { get; set; } = true;
}
private class PromoCodeData
{
public string RewardCommand { get; set; }
public string ExpiryDate { get; set; }
public int MaxActivations { get; set; } = 50;
}
protected override void LoadDefaultConfig()
{
Config.WriteObject(new PluginConfig
{
EnablePromoCodeBroadcast = true,
DiscordWebhookUrl = "Enter_your_webhook_URL_here",
PromoCodes = new Dictionary<string, PromoCodeData>
{
{ "WELCOME", new PromoCodeData { RewardCommand = "give {player} wood 1000", ExpiryDate = "2025-12-31", MaxActivations = 50 } },
{ "BONUS", new PromoCodeData { RewardCommand = "give {player} stone 500", ExpiryDate = "2025-12-31", MaxActivations = 50 } }
},
MessagePrefix = "<color=#0057b8>[Your Prefix]</color> ",
}, true);
}
private void SendPluginMessage(BasePlayer player, string messageKey, params object[] args)
{
string prefix = config.MessagePrefix;
string message = string.Format(Msg(messageKey, player.UserIDString), args);
SendReply(player, $"{prefix}{message}");
}
private Dictionary<string, string> tempPromoCodeNames = new Dictionary<string, string>();
private Dictionary<string, string> tempPromoCodeCommands = new Dictionary<string, string>();
private Dictionary<string, int> tempPromoCodeLimits = new Dictionary<string, int>();
private Dictionary<string, string> tempPromoCodeDates = new Dictionary<string, string>();
private void Init()
{
PrintWarning("\n-----------------------------\n" +
" Author - Barry_Allenn\n" +
" Discord - https://discord.gg/qXkHDGPkmn\n" +
"-----------------------------");
permission.RegisterPermission("promocode.adminpanel", this);
config = Config.ReadObject<PluginConfig>();
LoadData();
}
private void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, "PromoCodeMenu");
CuiHelper.DestroyUi(player, "PromoCodeMenuUI");
}
SaveData();
}
private void LoadData()
{
usedPromoCodesByPlayer = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, List<string>>>(Name) ?? new Dictionary<string, List<string>>();
promoCodeActivations = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, int>>(Name + "_Activations") ?? new Dictionary<string, int>();
}
private void SaveData()
{
Interface.Oxide.DataFileSystem.WriteObject(Name, usedPromoCodesByPlayer);
Interface.Oxide.DataFileSystem.WriteObject(Name + "_Activations", promoCodeActivations);
}
void OnServerInitialized()
{
ImageLibrary.Call("AddImage", "https://i.ibb.co/rGQ8Q8TQ/MBPromo-Code-Os.png", "fonpromocode");
ImageLibrary.Call("AddImage", "https://i.ibb.co/V79HkcG/MBPromo-Code-Os-admin.png", "fonadminpanel");
ImageLibrary.Call("AddImage", "https://i.ibb.co/rRpQYDTk/1.png", "promo_bg");
ImageLibrary.Call("AddImage", "https://i.ibb.co/zHrZGwX3/promoadmin.png", "admin_button");
ImageLibrary.Call("AddImage", config.QRTITTTOK_BA, "QRTITTTOK_BA");
ImageLibrary.Call("AddImage", config.QRDISCORD_BA, "QRDISCORD_BA");
}
[ChatCommand("promo")]
private void ShowPromoCodeMenu(BasePlayer player, string command, string[] args)
{
ShowPromoCodeUI_V1(player);
}
[ChatCommand("open_ui2")]
private void OpenUI2ChatCommand(BasePlayer player, string command, string[] args)
{
CuiHelper.DestroyUi(player, "PromoCodeMenuUI");
ShowPromoCodeUI_V2(player);
}
private void ShowPromoCodeUI_V1(BasePlayer player)
{
CuiHelper.DestroyUi(player, "PromoCodeMenu");
var container = new CuiElementContainer();
string root = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
CursorEnabled = true
}, "Overlay", "PromoCodeMenu");
string backgroundPanel = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.7", Material = "assets/content/ui/uibackgroundblur.mat" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
CursorEnabled = true
}, root);
container.Add(new CuiElement
{
Parent = root,
Components = {
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "QRDISCORD_BA") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-159 -105", OffsetMax = "-35 19" }
}
});
container.Add(new CuiElement
{
Parent = root,
Components = {
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "QRTITTTOK_BA") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-14.5 -105", OffsetMax = "109 19" }
}
});
container.Add(new CuiElement
{
Parent = "PromoCodeMenu",
Components = {
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "fonpromocode") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-558 -314", OffsetMax = "558 315" }
}
});
container.Add(new CuiButton
{
Button = { Color = "0 0 0 0", Close = "PromoCodeMenu" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
Text = { Text = "", FontSize = 0 }
}, root);
string centerPanel = container.Add(new CuiPanel
{
Image = { Color = "0.1 0.1 0.1 0" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-438 -265", OffsetMax = "440 265" },
CursorEnabled = true
}, root);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.33 0.7", AnchorMax = "0.506 0.741" },
Text = { Text = Msg("EnterPromoCode", player.UserIDString), Color = "1.00 1.00 1.00 0.5", FontSize = 12, Align = TextAnchor.MiddleLeft }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.705 0.7", AnchorMax = "0.918 0.748" },
Text = { Text = Msg("S_info", player.userID.ToString()), Color = "1.00 1.00 1.00 0.6", Align = TextAnchor.MiddleCenter, FontSize = 15 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.675 0.62", AnchorMax = "0.918 0.66" },
Text = { Text = Msg("S_infotllo_line_1", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.675 0.56", AnchorMax = "0.918 0.6" },
Text = { Text = Msg("S_infotllo_line_2", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.675 0.5", AnchorMax = "0.918 0.54" },
Text = { Text = Msg("S_infotllo_line_3", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.675 0.44", AnchorMax = "0.918 0.48" },
Text = { Text = Msg("S_infotllo_line_4", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.675 0.38", AnchorMax = "0.918 0.42" },
Text = { Text = Msg("S_infotllo_line_5", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.339 0.232", AnchorMax = "0.436 0.261" },
Text = { Text = config.textFPDEText, Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleCenter, FontSize = 10 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.503 0.232", AnchorMax = "0.601 0.261" },
Text = { Text = config.texttkFPDEText, Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleCenter, FontSize = 10 }
}, centerPanel);
container.Add(new CuiElement
{
Parent = centerPanel,
Components = {
new CuiInputFieldComponent { Text = Msg("EnterPromoCodePlaceholder", player.UserIDString), Color = "1.00 1.00 1.00 0.6",
FontSize = 13, Align = TextAnchor.MiddleLeft, Command = "promocode.submit", NeedsKeyboard = true },
new CuiRectTransformComponent { AnchorMin = "0.33 0.63", AnchorMax = "0.53 0.671" }
}
});
container.Add(new CuiButton
{
Button = { Color = "0.2 0.8 0.2 0", Command = "promocode.submit", FadeIn = 0.5f },
RectTransform = { AnchorMin = "0.541 0.628", AnchorMax = "0.61 0.674" },
Text = { Text = Msg("Activate", player.UserIDString), Color = "1.00 1.00 1.00 0.9", FontSize = 11, Align = TextAnchor.MiddleCenter }
}, centerPanel);
if (permission.UserHasPermission(player.UserIDString, "promocode.adminpanel"))
{
container.Add(new CuiElement
{
Parent = centerPanel,
Components =
{
new CuiRawImageComponent
{
Png = (string)ImageLibrary.Call("GetImage", "admin_button"),
Color = "1 1 1 1"
},
new CuiRectTransformComponent
{
AnchorMin = "0.7915 0.908", AnchorMax = "0.974 0.9885"
}
}
});
container.Add(new CuiButton
{
Button = { Color = "0 0 0 0", Command = "open_secondary_ui", FadeIn = 0.5f },
RectTransform = { AnchorMin = "0.796 0.925", AnchorMax = "0.97 0.973" },
Text = { Text = Msg("S_adminpanel", player.UserIDString), Color = "1.00 1.00 1.00 0.9", FontSize = 11, Align = TextAnchor.MiddleCenter }
}, centerPanel);
}
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.325 0.201", AnchorMax = "0.451 0.225" },
Image = { Color = "1 1 1 0" }
}, centerPanel, "DSFPDEText");
container.Add(new CuiElement
{
Parent = "DSFPDEText",
Components =
{
new CuiInputFieldComponent { Text = config.DSFPDEText, Color = "1 1 1 0.3", Align = TextAnchor.MiddleLeft, FontSize = 9, Font = "robotocondensed-bold.ttf"},
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
}
});
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.489 0.201", AnchorMax = "0.615 0.225" },
Image = { Color = "1 1 1 0" }
}, centerPanel, "TKFPDEText");
container.Add(new CuiElement
{
Parent = "TKFPDEText",
Components =
{
new CuiInputFieldComponent { Text = config.TKFPDEText, Color = "1 1 1 0.3", Align = TextAnchor.MiddleLeft, FontSize = 9, Font = "robotocondensed-bold.ttf"},
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
}
});
// Панель-фон
// container.Add(new CuiPanel
// {
// Image = { Color = "0.67 0.87 0.80 0.2" }, // Темно-сірий прозорий фон
// RectTransform = { AnchorMin = "0.487 0.201", AnchorMax = "0.617 0.225" }
// }, centerPanel);
CuiHelper.AddUi(player, container);
}
// private void ShowPromoCodeUI_V1(BasePlayer player)
// {
// CuiHelper.DestroyUi(player, "PromoCodeMenu");
// var elements = new CuiElementContainer();
// elements.Add(new CuiPanel
// {
// Image = { Color = "0.1 0.1 0.1 0" },
// RectTransform = { AnchorMin = "0.23 0.19", AnchorMax = "0.77 0.75" },
// CursorEnabled = true
// }, "Overlay", "PromoCodeMenu");
// elements.Add(new CuiElement
// {
// Parent = "PromoCodeMenu",
// Components = {
// new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "fonpromocode") },
// new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" }
// }
// });
// elements.Add(new CuiElement
// {
// Parent = "PromoCodeMenu",
// Components = {
// new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "QRTITTTOK_BA") },
// new CuiRectTransformComponent { AnchorMin = "0.363 0.2555", AnchorMax = "0.514 0.533", OffsetMax = "0 0" }
// }
// });
// elements.Add(new CuiElement
// {
// Parent = "PromoCodeMenu",
// Components = {
// new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "QRDISCORD_BA") },
// new CuiRectTransformComponent { AnchorMin = "0.1034 0.2555", AnchorMax = "0.253 0.533", OffsetMax = "0 0" }
// }
// });
// elements.Add(new CuiElement
// {
// Parent = "PromoCodeMenu",
// Components = {
// new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "Ojdwnfwf") },
// new CuiRectTransformComponent { AnchorMin = "0.0954 0.247", AnchorMax = "0.261 0.5417", OffsetMax = "0 0" }
// }
// });
// elements.Add(new CuiElement
// {
// Parent = "PromoCodeMenu",
// Components = {
// new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "Ojdwnfwf") },
// new CuiRectTransformComponent { AnchorMin = "0.3555 0.247", AnchorMax = "0.5215 0.5417", OffsetMax = "0 0" }
// }
// });
// elements.Add(new CuiLabel
// {
// Text = { Text = Msg("EnterPromoCode", player.UserIDString), Color = "1.00 1.00 1.00 0.6", FontSize = 12, Align = TextAnchor.MiddleLeft },
// RectTransform = { AnchorMin = "0.117 0.745", AnchorMax = "0.354 0.81" }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.605 0.77", AnchorMax = "0.85 0.83" },
// Text = { Text = Msg("S_info", player.userID.ToString()), Color = "1.00 1.00 1.00 0.6", Align = TextAnchor.MiddleCenter, FontSize = 15 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.595 0.65", AnchorMax = "0.91 0.7" },
// Text = { Text = Msg("S_infotllo_line_1", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.595 0.58", AnchorMax = "0.91 0.63" },
// Text = { Text = Msg("S_infotllo_line_2", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.595 0.5", AnchorMax = "0.91 0.55" },
// Text = { Text = Msg("S_infotllo_line_3", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.595 0.43", AnchorMax = "0.91 0.48" },
// Text = { Text = Msg("S_infotllo_line_4", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.595 0.36", AnchorMax = "0.91 0.41" },
// Text = { Text = Msg("S_infotllo_line_5", player.userID.ToString()), Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleLeft, FontSize = 14 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.125 0.185", AnchorMax = "0.23 0.225" },
// Text = { Text = config.textFPDEText, Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleCenter, FontSize = 10 }
// }, "PromoCodeMenu");
// elements.Add(new CuiLabel
// {
// RectTransform = { AnchorMin = "0.385 0.185", AnchorMax = "0.49 0.225" },
// Text = { Text = config.texttkFPDEText, Color = "1.00 1.00 1.00 0.5", Align = TextAnchor.MiddleCenter, FontSize = 10 }
// }, "PromoCodeMenu");
// elements.Add(new CuiElement
// {
// Name = "PromoCodeInput",
// Parent = "PromoCodeMenu",
// Components = {
// new CuiInputFieldComponent { Text = Msg("EnterPromoCodePlaceholder", player.UserIDString), Color = "1.00 1.00 1.00 0.6",
// FontSize = 13, Align = TextAnchor.MiddleLeft, Command = "promocode.submit", NeedsKeyboard = true },
// new CuiRectTransformComponent { AnchorMin = "0.117 0.645", AnchorMax = "0.39 0.71" }
// }
// });
// elements.Add(new CuiPanel
// {
// RectTransform = { AnchorMin = "0.109 0.147", AnchorMax = "0.25 0.18", OffsetMax = "0 0" },
// Image = { Color = "1 1 1 0" }
// }, "PromoCodeMenu", "DSFPDEText");
// elements.Add(new CuiElement
// {
// Parent = "DSFPDEText",
// Components =
// {
// new CuiInputFieldComponent { Text = config.DSFPDEText, Color = "1 1 1 0.3", Align = TextAnchor.MiddleLeft, FontSize = 9, Font = "robotocondensed-bold.ttf"},
// new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
// }
// });
// elements.Add(new CuiPanel
// {
// RectTransform = { AnchorMin = "0.3685 0.147", AnchorMax = "0.509 0.18", OffsetMax = "0 0" },
// Image = { Color = "1 1 1 0" }
// }, "PromoCodeMenu", "TKFPDEText");
// elements.Add(new CuiElement
// {
// Parent = "TKFPDEText",
// Components =
// {
// new CuiInputFieldComponent { Text = config.TKFPDEText, Color = "1 1 1 0.3", Align = TextAnchor.MiddleLeft, FontSize = 9, Font = "robotocondensed-bold.ttf"},
// new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
// }
// });
// if (permission.UserHasPermission(player.UserIDString, "promocode.adminpanel"))
// {
// elements.Add(new CuiElement
// {
// Parent = "PromoCodeMenu",
// Components =
// {
// new CuiRawImageComponent
// {
// Png = (string)ImageLibrary.Call("GetImage", "admin_button"),
// Color = "1 1 1 1"
// },
// new CuiRectTransformComponent
// {
// AnchorMin = "0.575 0.17", AnchorMax = "0.878 0.24"
// }
// }
// });
// elements.Add(new CuiButton
// {
// Button = { Color = "0 0 0 0", Command = "open_secondary_ui", FadeIn = 0.5f },
// RectTransform = { AnchorMin = "0.575 0.17", AnchorMax = "0.878 0.24" },
// Text = { Text = Msg("S_adminpanel", player.UserIDString), Color = "1.00 1.00 1.00 0.9", FontSize = 11, Align = TextAnchor.MiddleCenter }
// }, "PromoCodeMenu");
// }
// elements.Add(new CuiButton
// {
// Button = { Color = "0.2 0.8 0.2 0", Command = "promocode.submit", FadeIn = 0.5f },
// RectTransform = { AnchorMin = "0.405 0.645", AnchorMax = "0.4985 0.713" },
// Text = { Text = Msg("Activate", player.UserIDString), Color = "1.00 1.00 1.00 0.9", FontSize = 11, Align = TextAnchor.MiddleCenter }
// }, "PromoCodeMenu");
// elements.Add(new CuiButton
// {
// Button = { Color = "0.8 0.2 0.2 0", Command = "promocode.close", FadeIn = 0.5f },
// RectTransform = { AnchorMin = "0.97 0.952", AnchorMax = "0.995 0.99" },
// Text = { Text = Msg("Close", player.UserIDString), FontSize = 20, Align = TextAnchor.MiddleCenter }
// }, "PromoCodeMenu");
// CuiHelper.AddUi(player, elements);
// }
private void ShowPromoCodeUI_V2(BasePlayer player, int page = 1)
{
CuiHelper.DestroyUi(player, "PromoCodeMenu");
const int itemsPerPage = 5;
var container = new CuiElementContainer();
string root = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
CursorEnabled = true
}, "Overlay", "PromoCodeMenuUI");
string backgroundPanel = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.7", Material = "assets/content/ui/uibackgroundblur.mat" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
CursorEnabled = true
}, root);
container.Add(new CuiElement
{
Parent = "PromoCodeMenuUI",
Components = {
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "fonadminpanel") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-558 -314", OffsetMax = "558 315" }
}
});
container.Add(new CuiButton
{
Button = { Color = "0 0 0 0", Close = "PromoCodeMenuUI" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
Text = { Text = "", FontSize = 0 }
}, root);
string centerPanel = container.Add(new CuiPanel
{
Image = { Color = "0.1 0.1 0.1 0" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-438 -265", OffsetMax = "440 265" },
CursorEnabled = true
}, root);
container.Add(new CuiPanel
{
Image = { Color = "0.2 0.2 0.2 0" },
RectTransform = { AnchorMin = "0.5 0.2", AnchorMax = "0.95 0.8" }
}, centerPanel);
container.Add(new CuiButton
{
Button = { Color = "0.8 0.2 0.2 0", Command = "ui_close_secondary", Close = "PromoCodeMenuUI" },
RectTransform = { AnchorMin = "0.95 0.95", AnchorMax = "0.98 0.989" },
Text = { Text = "", FontSize = 16, Align = TextAnchor.MiddleCenter }
}, centerPanel);
container.Add(new CuiLabel
{
Text = {
Text = Msg("S_panelpromo", player.userID.ToString()),
Color = "1 1 1 0.6",
FontSize = 11,
Align = TextAnchor.MiddleCenter
},
RectTransform = { AnchorMin = "0.61 0.785", AnchorMax = "0.87 0.85" }
}, centerPanel);
// var promoCodes = new List<KeyValuePair<string, PromoCodeData>>(config.PromoCodes);
// int totalPages = Mathf.CeilToInt((float)promoCodes.Count / itemsPerPage);
// int start = (page - 1) * itemsPerPage;
// float y = 0.7f;
// for (int i = start; i < start + itemsPerPage && i < promoCodes.Count; i++)
// {
// var promoCode = promoCodes[i];
// string code = promoCode.Key;
// var data = promoCode.Value;
// int activations = promoCodeActivations.TryGetValue(code, out int count) ? count : 0;
// container.Add(new CuiLabel
// {
// Text = {
// Text = $"{code} ({string.Format(lang.GetMessage("Activations", this, player.UserIDString), activations, data.MaxActivations)})",
// Color = "1 1 1 0.6",
// FontSize = 8,
// Align = TextAnchor.MiddleLeft
// },
// RectTransform = { AnchorMin = $"0.58 {y}", AnchorMax = $"0.9 {y + 0.05}" }
// }, centerPanel);
// if (!string.IsNullOrEmpty(data.ExpiryDate))
// {
// container.Add(new CuiLabel
// {
// Text = {
// Text = string.Format(lang.GetMessage("ExpiryDate", this, player.UserIDString), data.ExpiryDate),
// Color = "1 1 1 0.6",
// FontSize = 8,
// Align = TextAnchor.MiddleLeft
// },
// RectTransform = { AnchorMin = $"0.58 {y - 0.04}", AnchorMax = $"0.9 {y + 0.01}" }
// }, centerPanel);
// }
// if (permission.UserHasPermission(player.UserIDString, "promocode.adminpanel"))
// {
// container.Add(new CuiButton
// {
// Button = {
// Color = "0.8 0.2 0.2 0",
// Command = $"promocode.remove {code}",
// FadeIn = 0.5f
// },
// RectTransform = { AnchorMin = $"0.82 {y - 0.02}", AnchorMax = $"0.9 {y + 0.03}" },
// Text = { Text = Msg("S_delete", player.UserIDString), Color = "1 1 1 0.6", FontSize = 10, Align = TextAnchor.MiddleCenter }
// }, centerPanel);
// }
// y -= 0.1f;
// }
// if (page < totalPages)
// {
// container.Add(new CuiElement
// {
// Parent = centerPanel,
// Components =
// {
// new CuiRawImageComponent
// {
// Png = (string)ImageLibrary.Call("GetImage", "S_before"),
// Color = "1 1 1 1"
// },
// new CuiRectTransformComponent
// {
// AnchorMin = "0.82 0.14",
// AnchorMax = "0.875 0.2"
// }
// }
// });
// container.Add(new CuiButton
// {
// Button = { Color = "0 0 0 0", Command = $"ui_promo_page {page + 1}", FadeIn = 0.5f },
// RectTransform = { AnchorMin = "0.82 0.14", AnchorMax = "0.875 0.2" },
// Text = { Text = "", FontSize = 9, Align = TextAnchor.MiddleCenter }
// }, centerPanel);
// }
// if (page > 1)
// {
// container.Add(new CuiElement
// {
// Parent = centerPanel,
// Components =
// {
// new CuiRawImageComponent
// {
// Png = (string)ImageLibrary.Call("GetImage", "S_back"),
// Color = "1 1 1 1"
// },
// new CuiRectTransformComponent
// {
// AnchorMin = "0.61 0.14",
// AnchorMax = "0.665 0.2"
// }
// }
// });
// container.Add(new CuiButton
// {
// Button = { Color = "0 0 0 0", Command = $"ui_promo_page {page - 1}", FadeIn = 0.5f },
// RectTransform = { AnchorMin = "0.61 0.14", AnchorMax = "0.665 0.2" },
// Text = { Text = "", FontSize = 8, Align = TextAnchor.MiddleCenter }
// }, centerPanel);
// }
float blockHeight = 47f;
float blockMargin = 5.2f;
float verticalShift = 1f;
var promoList = config.PromoCodes.ToList();
int totalItems = promoList.Count;
float totalHeight = totalItems * (blockHeight + blockMargin);
float minVisibleHeight = 300f;
float scrollContentHeight = Mathf.Max(totalHeight, minVisibleHeight);
// ScrollView контейнер
container.Add(new CuiElement
{
Name = "MBScrollablePromoArea",
Parent = centerPanel,
Components =
{
new CuiScrollViewComponent
{
Vertical = true,
Horizontal = false,
Inertia = true,
Elasticity = 0.2f,
DecelerationRate = 0.2f,
ScrollSensitivity = 30f,
ContentTransform = new CuiRectTransform
{
AnchorMin = "0 1",
AnchorMax = "1 1",
OffsetMin = $"0 -{scrollContentHeight}",
OffsetMax = "0 0"
},
VerticalScrollbar = new CuiScrollbar
{
Size = 5f,
AutoHide = false,
HandleColor = "0.00 0.00 1.00 0.2",
TrackColor = "0 0 0 0"
}
},
new CuiRectTransformComponent
{
AnchorMin = "0.68 0.206",
AnchorMax = "0.9675 0.793"
},
new CuiNeedsCursorComponent()
}
});
// Внутрішній вміст
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform =
{
AnchorMin = "0 1",
AnchorMax = "0.93 1",
OffsetMin = $"0 -{scrollContentHeight}",
OffsetMax = "0 0"
}
}, "MBScrollablePromoArea", "MBPromoContent");
int columns = 1;
float columnWidth = 1f / columns;
for (int i = 0; i < promoList.Count; i++)
{
int row = i / columns;
int col = i % columns;
float topOffset = -(row * (blockHeight + blockMargin)) - verticalShift;
float bottomOffset = topOffset - blockHeight;
float left = col * columnWidth;
float right = left + columnWidth;
string containerName = $"PromoCodeContainer_{i}";
var promo = promoList[i];
var code = promo.Key;
var data = promo.Value;
int activations = promoCodeActivations.TryGetValue(code, out int count) ? count : 0;
// Контейнер блоку
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform =
{
AnchorMin = $"{left} 1",
AnchorMax = $"{right} 1",
OffsetMin = $"0 {bottomOffset}",
OffsetMax = $"0 {topOffset}"
}
}, "MBPromoContent", containerName);
string background = (string)ImageLibrary.Call("GetImage", "promo_bg");
if (!string.IsNullOrEmpty(background))
{
container.Add(new CuiElement
{
Name = $"PromoBG_{i}",
Parent = containerName,
Components =
{
new CuiRawImageComponent
{
Png = background,
Sprite = "assets/content/textures/generic/fulltransparent.tga",
Color = "1 1 1 1"
},
new CuiRectTransformComponent
{
AnchorMin = "0 0",
AnchorMax = "1 1"
}
}
});
}
// Назва промокоду
container.Add(new CuiLabel
{
Text =
{
Text = $"{code} [{activations}/{data.MaxActivations}]",
FontSize = 13,
Align = TextAnchor.MiddleLeft,
Color = "1 1 1 0.8"
},
RectTransform =
{
AnchorMin = "0.03 0.5",
AnchorMax = "0.7 0.9"
}
}, containerName);
// Дата окончания (если есть)
if (!string.IsNullOrEmpty(data.ExpiryDate))
{
container.Add(new CuiLabel
{
Text =
{
Text = string.Format(lang.GetMessage("ExpiryDate", this, player.UserIDString), data.ExpiryDate),
FontSize = 11,
Align = TextAnchor.UpperLeft,
Color = "1 1 1 0.5"
},
RectTransform =
{
AnchorMin = "0.03 0.1",
AnchorMax = "0.7 0.45"
}
}, containerName);
}
// Кнопка удаления (только если админ)
if (permission.UserHasPermission(player.UserIDString, "promocode.adminpanel"))
{
container.Add(new CuiButton
{
Button =
{
Color = "0.8 0.2 0.2 0",
Command = $"promocode.remove {code}"
},
RectTransform =
{
AnchorMin = "0.75 0.25",
AnchorMax = "0.95 0.75"
},
Text =
{
Text = Msg("S_delete", player.UserIDString),
FontSize = 12,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
}
}, containerName);
}
}
container.Add(new CuiElement
{
Parent = centerPanel,
Components = {
new CuiInputFieldComponent
{
Text = "",
Color = "1 1 1 0.6",
FontSize = 12,
Align = TextAnchor.MiddleLeft,
Command = "promocode.setname",
NeedsKeyboard = true
},
new CuiRectTransformComponent
{
AnchorMin = "0.349 0.65", AnchorMax = "0.544 0.698"
}
}
});
container.Add(new CuiButton
{
Button = {
Command = "mbpromo.back", // кастомная команда
Color = "0.2 0.5 0.8 0"
},
RectTransform = { AnchorMin = "0.865 0.04", AnchorMax = "0.947 0.12" },
Text = {
Text = Msg("MB_Back", player.UserIDString),
FontSize = 15,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
}
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.348 0.7365", AnchorMax = "0.545 0.77" },
Text = { Text = Msg("S_VDR", player.userID.ToString()), Color = "1.00 1.00 1.00 0.4", Align = TextAnchor.MiddleLeft, FontSize = 11 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.348 0.705", AnchorMax = "0.545 0.74" },
Text = { Text = Msg("S_VDRPR", player.userID.ToString()), Color = "1.00 1.00 1.00 0.2", Align = TextAnchor.MiddleLeft, FontSize = 9 }
}, centerPanel);
container.Add(new CuiElement
{
Name = "PromoCodeCommandInput",
Parent = centerPanel,
Components = {
new CuiInputFieldComponent
{
Text = "",
Color = "1 1 1 0.6",
FontSize = 12,
Align = TextAnchor.MiddleLeft,
Command = "promocode.setcommand",
NeedsKeyboard = true
},
new CuiRectTransformComponent
{
AnchorMin = "0.349 0.443", AnchorMax = "0.567 0.491"
}
}
});
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.348 0.5295", AnchorMax = "0.567 0.563" },
Text = { Text = Msg("S_CODR", player.userID.ToString()), Color = "1.00 1.00 1.00 0.4", Align = TextAnchor.MiddleLeft, FontSize = 11 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.348 0.497", AnchorMax = "0.567 0.533" },
Text = { Text = Msg("S_CODRPR", player.userID.ToString()), Color = "1.00 1.00 1.00 0.2", Align = TextAnchor.MiddleLeft, FontSize = 9 }
}, centerPanel);
container.Add(new CuiElement
{
Name = "PromoCodeLimitInput",
Parent = centerPanel,
Components = {
new CuiInputFieldComponent
{
Text = "",
Color = "1 1 1 1",
FontSize = 12,
Align = TextAnchor.MiddleCenter,
Command = "promocode.setlimit",
NeedsKeyboard = true
},
new CuiRectTransformComponent
{
AnchorMin = "0.47 0.237", AnchorMax = "0.517 0.284"
}
}
});
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.47 0.33", AnchorMax = "0.6 0.36" },
Text = { Text = Msg("S_CODRLIMIT", player.userID.ToString()), Color = "1.00 1.00 1.00 0.4", Align = TextAnchor.MiddleLeft, FontSize = 11 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.47 0.291", AnchorMax = "0.55 0.326" },
Text = { Text = Msg("S_CODRLIMFFIT", player.userID.ToString()), Color = "1.00 1.00 1.00 0.2", Align = TextAnchor.MiddleLeft, FontSize = 9 }
}, centerPanel);
container.Add(new CuiElement
{
Name = "PromoCodeExpiryDateInput",
Parent = centerPanel,
Components = {
new CuiInputFieldComponent
{
Text = "",
Color = "1 1 1 0.6",
FontSize = 12,
Align = TextAnchor.MiddleLeft,
Command = "promocode.setdate",
NeedsKeyboard = true
},
new CuiRectTransformComponent
{
AnchorMin = "0.349 0.237", AnchorMax = "0.458 0.284"
}
}
});
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.349 0.33", AnchorMax = "0.458 0.36" },
Text = { Text = Msg("S_CODRdata", player.userID.ToString()), Color = "1.00 1.00 1.00 0.4", Align = TextAnchor.MiddleLeft, FontSize = 11 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.349 0.291", AnchorMax = "0.458 0.326" },
Text = { Text = Msg("S_CODRFFdata", player.userID.ToString()), Color = "1.00 1.00 1.00 0.2", Align = TextAnchor.MiddleLeft, FontSize = 9 }
}, centerPanel);
container.Add(new CuiButton
{
Button = {
Color = "0.2 0.8 0.2 0",
Command = "promocode.create",
FadeIn = 0.5f
},
RectTransform = {
AnchorMin = "0.5285 0.237", AnchorMax = "0.611 0.284"
},
Text = {
Text = Msg("S_Create", player.UserIDString),
// ... [Code preview truncated due to length. Full source in attached file] ...