C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins {
[Info("Server Rewards", "k1lly0u", "0.4.73")]
[Description("UI shop to buy items, kits, and commands")]
class ServerRewards : RustPlugin {
#region Fields
[PluginReference]
Plugin Kits, Economics, EventManager, HumanNPC, LustyMap, PlaytimeTracker, ImageLibrary;
private PlayerData playerData;
private NPCData npcData;
private RewardData rewardData;
private SaleData saleData;
private CooldownData cooldownData;
private DynamicConfigFile playerdata, npcdata, rewarddata, saledata, cooldowndata;
private static ServerRewards ins;
private UIManager uiManager;
private Timer saveTimer;
private static bool uiFadeIn;
private bool isILReady;
private string color1;
private string color2;
private int blueprintId = -996920608;
private Dictionary<string, string> uiColors = new Dictionary<string, string>();
private Dictionary<ulong, int> playerRP = new Dictionary<ulong, int>();
private Hash<ulong, Timer> popupMessages = new Hash<ulong, Timer>();
private Dictionary<int, string> itemIds = new Dictionary<int, string>();
private Dictionary<string, string> itemNames = new Dictionary<string, string>();
private Dictionary<ulong, KeyValuePair<string, NPCData.NPCInfo>> npcCreator = new Dictionary<ulong, KeyValuePair<string, NPCData.NPCInfo>>();
private Dictionary<ulong, UserNPC> userNpc = new Dictionary<ulong, UserNPC>();
enum UserNPC {
Add, Edit, Remove
}
enum UIPanel {
None, Navigation, Kits, Items, Commands, Exchange, Transfer, Sell
}
enum PurchaseType {
Kit, Item, Command
}
enum Category {
None, Weapon, Construction, Items, Resources, Attire, Tool, Medical, Food, Ammunition, Traps, Misc, Component, Electrical, Fun
}
#endregion
#region UI
const string UIMain = "SR_Store";
const string UISelect = "SR_Select";
const string UIRP = "SR_RPPanel";
const string UIPopup = "SR_Popup";
private class UI {
public static CuiElementContainer CreateElementContainer(string panelName, string color, string aMin, string aMax) {
CuiElementContainer container = new CuiElementContainer() {
{
new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, CursorEnabled = true
}
, new CuiElement().Parent = "Overlay", panelName
}
}
;
return container;
}
public static void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false) {
container.Add(new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, CursorEnabled = cursor
}
, panel, CuiHelper.GetGuid());
}
public static void CreateLabel(ref CuiElementContainer container, string panel, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, string color = null, float fadein = 1.0f) {
if (uiFadeIn) fadein = 0;
container.Add(new CuiLabel {
Text = {
FontSize = size, Align = align, FadeIn = fadein, Text = text
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
}
, panel, CuiHelper.GetGuid());
}
public static void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f) {
if (uiFadeIn) fadein = 0;
container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = fadein
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, Text = {
Text = text, FontSize = size, Align = align
}
}
, panel, CuiHelper.GetGuid());
}
public static void LoadImage(ref CuiElementContainer container, string panel, string png, string aMin, string aMax) {
container.Add(new CuiElement {
Name = CuiHelper.GetGuid(), Parent = panel, Components = {
new CuiRawImageComponent {
Png = png
}
, new CuiRectTransformComponent {
AnchorMin = aMin, AnchorMax = aMax
}
}
}
);
}
public static string Color(string hexColor, float alpha) {
if (hexColor.StartsWith("#")) hexColor = hexColor.TrimStart('#');
int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
}
}
private class UIManager {
public Dictionary<UIPanel, Dictionary<Category, Dictionary<int, CuiElementContainer>>> standardElements = new Dictionary<UIPanel, Dictionary<Category, Dictionary<int, CuiElementContainer>>>();
public Dictionary<string, Dictionary<UIPanel, Dictionary<Category, Dictionary<int, CuiElementContainer>>>> npcElements = new Dictionary<string, Dictionary<UIPanel, Dictionary<Category, Dictionary<int, CuiElementContainer>>>>();
public Dictionary<ulong, PlayerUI> playerUi = new Dictionary<ulong, PlayerUI>();
public void AddUI(BasePlayer player, UIPanel type, Category subType = Category.None, int pageNumber = 0, string npcId = null) {
PlayerUI data;
if (!playerUi.TryGetValue(player.userID, out data)) {
data = new PlayerUI {
npcId = npcId
}
;
playerUi.Add(player.userID, data);
}
CuiElementContainer container = null;
if (type == UIPanel.Navigation) {
if (!string.IsNullOrEmpty(npcId)) container = npcElements[npcId][UIPanel.Navigation][Category.None][0];
else container = standardElements[UIPanel.Navigation][Category.None][0];
data.navigationIds.AddRange(container.Select(x => x.Name));
ins.DisplayPoints(player);
}
else {
if (type != UIPanel.Sell && type != UIPanel.Transfer) {
if (!string.IsNullOrEmpty(npcId)) container = npcElements[npcId][type][subType][pageNumber];
else container = standardElements[type][subType][pageNumber];
}
else {
switch (type) {
case UIPanel.Transfer : container = ins.CreateTransferElement(player, pageNumber);
break;
case UIPanel.Sell : container = ins.CreateSaleElement(player);
break;
}
}
data.elementIds.AddRange(container.Select(x => x.Name));
}
if (container != null) CuiHelper.AddUi(player, container);
playerUi[player.userID] = data;
}
public void DestroyUI(BasePlayer player, bool destroyNav = false) {
PlayerUI data;
if (playerUi.TryGetValue(player.userID, out data)) {
foreach (string elementId in data.elementIds) CuiHelper.DestroyUi(player, elementId);
if (destroyNav) {
foreach (string elementId in data.navigationIds) CuiHelper.DestroyUi(player, elementId);
CuiHelper.DestroyUi(player, UIRP);
CuiHelper.DestroyUi(player, UISelect);
playerUi.Remove(player.userID);
ins.OpenMap(player);
}
}
}
public void SwitchElement(BasePlayer player, UIPanel type, Category subType = Category.None, int pageNumber = 0, string npcId = null) {
DestroyUI(player);
AddUI(player, type, subType, pageNumber, npcId);
}
public bool IsOpen(BasePlayer player) => playerUi.ContainsKey(player.userID);
public bool NPCHasUI(string npcId) => npcElements.ContainsKey(npcId);
public void RemoveNPCUI(string npcId) {
if (NPCHasUI(npcId)) npcElements.Remove(npcId);
}
public void RenameComponents(CuiElementContainer container) {
foreach (CuiElement element in container) {
if (element.Name == "AddUI CreatedPanel") element.Name = CuiHelper.GetGuid();
}
}
public string GetNPCInUse(BasePlayer player) {
if (playerUi.ContainsKey(player.userID)) return playerUi[player.userID].npcId;
return string.Empty;
}
public class PlayerUI {
public string npcId = string.Empty;
public List<string> elementIds = new List<string>();
public List<string> navigationIds = new List<string>();
}
}
#endregion
#region UI Creation
private void CreateAllElements() {
isILReady = true;
CreateNewElement();
foreach (KeyValuePair<string, NPCData.NPCInfo> npc in npcData.npcInfo) CreateNewElement(npc.Key, npc.Value);
PrintWarning("All UI elements have been successfully generated!");
}
private void CreateNewElement(string npcId = null, NPCData.NPCInfo info = null) {
Category[] categories = Enum.GetValues(typeof(Category)) as Category[];
SetNewElement(npcId);
CreateNavUI(npcId, info);
CreateKitsUI(npcId, info);
for (int i = 0; i < categories.Length; i++) CreateItemsUI(categories[i], npcId, info);
CreateCommandsUI(npcId, info);
CreateExchangeUI(npcId);
}
private void SetNewElement(string npcId = null) {
Dictionary<UIPanel, Dictionary<Category, Dictionary<int, CuiElementContainer>>> structure = new Dictionary<UIPanel, Dictionary<Category, Dictionary<int, CuiElementContainer>>> {
{
UIPanel.Commands, new Dictionary<Category, Dictionary<int, CuiElementContainer>> {
{
Category.None, new Dictionary<int, CuiElementContainer>()
}
}
}
, {
UIPanel.Exchange, new Dictionary<Category, Dictionary<int, CuiElementContainer>> {
{
Category.None, new Dictionary<int, CuiElementContainer>()
}
}
}
, {
UIPanel.Items, new Dictionary<Category, Dictionary<int, CuiElementContainer>> {
{
Category.Ammunition, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Attire, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Component, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Construction, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Electrical, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Food, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Items, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Medical, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Misc, new Dictionary<int, CuiElementContainer>()
}
, {
Category.None, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Resources, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Tool, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Traps, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Weapon, new Dictionary<int, CuiElementContainer>()
}
, {
Category.Fun, new Dictionary<int, CuiElementContainer>()
}
,
}
}
, {
UIPanel.Kits, new Dictionary<Category, Dictionary<int, CuiElementContainer>> {
{
Category.None, new Dictionary<int, CuiElementContainer>()
}
}
}
, {
UIPanel.Navigation, new Dictionary<Category, Dictionary<int, CuiElementContainer>> {
{
Category.None, new Dictionary<int, CuiElementContainer>()
}
}
}
}
;
if (!string.IsNullOrEmpty(npcId)) uiManager.npcElements.Add(npcId, structure);
else uiManager.standardElements = structure;
}
private void CreateNavUI(string npcId = null, NPCData.NPCInfo npcInfo = null) {
CuiElementContainer container = UI.CreateElementContainer(UISelect, uiColors["dark"], "0 0.95", "1 1");
UI.CreatePanel(ref container, UISelect, uiColors["light"], "0.005 0", "0.995 1", true);
UI.CreateLabel(ref container, UISelect, $"{color1}{msg("storeTitle")}</color>", 24, "0.01 0", "0.2 1");
int i = 0;
if (string.IsNullOrEmpty(npcId)) {
if (configData.Tabs.Kits) {
CreateMenuButton(ref container, UISelect, msg("storeKits"), $"SRUI_ChangeElement Kits 0", i);
i++;
}
if (configData.Tabs.Items) {
CreateMenuButton(ref container, UISelect, msg("storeItems"), $"SRUI_ChangeElement Items 0", i);
i++;
}
if (configData.Tabs.Commands) {
CreateMenuButton(ref container, UISelect, msg("storeCommands"), $"SRUI_ChangeElement Commands 0", i);
i++;
}
if (Economics && configData.Tabs.Exchange) {
CreateMenuButton(ref container, UISelect, msg("storeExchange"), "SRUI_ChangeElement Exchange 0", i);
i++;
}
if (configData.Tabs.Transfer) {
CreateMenuButton(ref container, UISelect, msg("storeTransfer"), "SRUI_ChangeElement Transfer 0", i);
i++;
}
if (configData.Tabs.Seller) {
CreateMenuButton(ref container, UISelect, msg("sellItems"), "SRUI_ChangeElement Sell 0", i);
i++;
}
CreateMenuButton(ref container, UISelect, msg("storeClose"), "SRUI_DestroyAll", i);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Navigation][Category.None][0] = container;
}
else {
if (npcInfo != null) {
if (configData.Tabs.Kits && npcInfo.sellKits) {
CreateMenuButton(ref container, UISelect, msg("storeKits"), $"SRUI_ChangeElement Kits 0 {npcId}", i);
i++;
}
if (configData.Tabs.Items && npcInfo.sellItems) {
CreateMenuButton(ref container, UISelect, msg("storeItems"), $"SRUI_ChangeElement Items 0 {npcId}", i);
i++;
}
if (configData.Tabs.Commands && npcInfo.sellCommands) {
CreateMenuButton(ref container, UISelect, msg("storeCommands"), $"SRUI_ChangeElement Commands 0 {npcId}", i);
i++;
}
if (Economics && configData.Tabs.Exchange && npcInfo.canExchange) {
CreateMenuButton(ref container, UISelect, msg("storeExchange"), $"SRUI_ChangeElement Exchange 0 {npcId}", i);
i++;
}
if (configData.Tabs.Transfer && npcInfo.canTransfer) {
CreateMenuButton(ref container, UISelect, msg("storeTransfer"), $"SRUI_ChangeElement Transfer 0 {npcId}", i);
i++;
}
if (configData.Tabs.Seller && npcInfo.canSell) {
CreateMenuButton(ref container, UISelect, msg("sellItems"), $"SRUI_ChangeElement Sell 0 {npcId}", i);
i++;
}
CreateMenuButton(ref container, UISelect, msg("storeClose"), "SRUI_DestroyAll", i);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Navigation][Category.None][0] = container;
}
else PrintWarning($"Failed to create the navigation menu for NPC: {npcId}.Invalid data was supplied!");
}
}
private void CreateItemsUI(Category category, string npcId = null, NPCData.NPCInfo npcInfo = null) {
Category[] categories = Enum.GetValues(typeof(Category)) as Category[];
if (string.IsNullOrEmpty(npcId)) {
int maxPages = 1;
List<KeyValuePair<string, RewardData.RewardItem>> items = rewardData.items.Where(x => x.Value.category == category).ToList();
if (items.Count == 0) {
CuiElementContainer container = CreateItemsElement(new List<KeyValuePair<string, RewardData.RewardItem>>(), category, 0, false, false, null);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Items][category][0] = container;
}
else {
if (items.Count > 36) maxPages = (items.Count - 1) / 36 + 1;
for (int i = 0; i < maxPages; i++) {
int min = i * 36;
int max = items.Count < 36 ? items.Count : min + 36 > items.Count ? (items.Count - min) : 36;
List<KeyValuePair<string, RewardData.RewardItem>> range = items.OrderBy(x => x.Value.displayName).ToList().GetRange(min, max);
CuiElementContainer container = CreateItemsElement(range, category, i, i < maxPages - 1, i > 0, null);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Items][category][i] = container;
}
}
}
else {
if (npcInfo != null) {
int maxPages = 1;
List<KeyValuePair<string, RewardData.RewardItem>> items = new List<KeyValuePair<string, RewardData.RewardItem>>();
if (npcInfo.useCustom) items = rewardData.items.Where(y => npcInfo.items.Contains(y.Key)).Where(x => x.Value.category == category).ToList();
else items = rewardData.items.Where(x => x.Value.category == category).ToList();
if (items.Count == 0) {
CuiElementContainer container = CreateItemsElement(new List<KeyValuePair<string, RewardData.RewardItem>>(), category, 0, false, false, npcId);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Items][category][0] = container;
}
else {
if (items.Count > 36) maxPages = (items.Count - 1) / 36 + 1;
for (int i = 0; i < maxPages; i++) {
int min = i * 36;
int max = items.Count < 36 ? items.Count : min + 36 > items.Count ? (items.Count - min) : 36;
List<KeyValuePair<string, RewardData.RewardItem>> range = items.OrderBy(x => x.Value.displayName).ToList().GetRange(min, max);
CuiElementContainer container = CreateItemsElement(range, category, i, i < maxPages - 1, i > 0, npcId);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Items][category][i] = container;
}
}
}
else PrintWarning($"Failed to create items menu for NPC: {npcId} Category: {category}.Invalid data was supplied!");
}
}
private void CreateKitsUI(string npcId = null, NPCData.NPCInfo npcInfo = null) {
if (string.IsNullOrEmpty(npcId)) {
int maxPages = 1;
SortedDictionary<string, RewardData.RewardKit> kits = rewardData.kits;
if (kits.Count == 0) {
CuiElementContainer container = CreateKitsElement(new List<KeyValuePair<string, RewardData.RewardKit>>(), 0, false, false);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Kits][Category.None][0] = container;
}
else {
if (kits.Count > 10) maxPages = (kits.Count - 1) / 10 + 1;
for (int i = 0; i < maxPages; i++) {
int min = i * 10;
int max = kits.Count < 10 ? kits.Count : min + 10 > kits.Count ? (kits.Count - min) : 10;
List<KeyValuePair<string, RewardData.RewardKit>> range = kits.OrderBy(x => x.Value.displayName).ToList().GetRange(min, max);
CuiElementContainer container = CreateKitsElement(range, i, i < maxPages - 1, i > 0);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Kits][Category.None][i] = container;
}
}
}
else {
if (npcInfo != null) {
int maxPages = 1;
Dictionary<string, RewardData.RewardKit> kits = rewardData.kits.Where(x => npcInfo.kits.Contains(x.Key)).ToDictionary(v => v.Key, y => y.Value);
if (kits.Count == 0) {
CuiElementContainer container = CreateKitsElement(new List<KeyValuePair<string, RewardData.RewardKit>>(), 0, false, false, npcId);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Kits][Category.None][0] = container;
}
else {
if (kits.Count > 10) maxPages = (kits.Count - 1) / 10 + 1;
for (int i = 0; i < maxPages; i++) {
int min = i * 10;
int max = kits.Count < 10 ? kits.Count : min + 10 > kits.Count ? (kits.Count - min) : 10;
List<KeyValuePair<string, RewardData.RewardKit>> range = kits.OrderBy(x => x.Value.displayName).ToList().GetRange(min, max);
CuiElementContainer container = CreateKitsElement(range, i, i < maxPages - 1, i > 0, npcId);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Kits][Category.None][i] = container;
}
}
}
else PrintWarning($"Failed to create kits menu for NPC: {npcId}.Invalid data was supplied!");
}
}
private void CreateCommandsUI(string npcId = null, NPCData.NPCInfo npcInfo = null) {
if (string.IsNullOrEmpty(npcId)) {
int maxPages = 1;
SortedDictionary<string, RewardData.RewardCommand> commands = rewardData.commands;
if (commands.Count == 0) {
CuiElementContainer container = CreateCommandsElement(new List<KeyValuePair<string, RewardData.RewardCommand>>(), 0, false, false);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Commands][Category.None][0] = container;
}
else {
if (commands.Count > 10) maxPages = (commands.Count - 1) / 10 + 1;
for (int i = 0; i < maxPages; i++) {
int min = i * 10;
int max = commands.Count < 10 ? commands.Count : min + 10 > commands.Count ? (commands.Count - min) : 10;
List<KeyValuePair<string, RewardData.RewardCommand>> range = commands.OrderBy(x => x.Value.displayName).ToList().GetRange(min, max);
CuiElementContainer container = CreateCommandsElement(range, i, i < maxPages - 1, i > 0);
uiManager.RenameComponents(container);
uiManager.standardElements[UIPanel.Commands][Category.None][i] = container;
}
}
}
else {
if (npcInfo != null) {
int maxPages = 1;
Dictionary<string, RewardData.RewardCommand> commands = rewardData.commands.Where(x => npcInfo.commands.Contains(x.Key)).ToDictionary(v => v.Key, y => y.Value);
if (commands.Count == 0) {
CuiElementContainer container = CreateCommandsElement(new List<KeyValuePair<string, RewardData.RewardCommand>>(), 0, false, false, npcId);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Commands][Category.None][0] = container;
}
else {
if (commands.Count > 10) maxPages = (commands.Count - 1) / 10 + 1;
for (int i = 0; i < maxPages; i++) {
int min = i * 10;
int max = commands.Count < 10 ? commands.Count : min + 10 > commands.Count ? (commands.Count - min) : 10;
List<KeyValuePair<string, RewardData.RewardCommand>> range = commands.OrderBy(x => x.Value.displayName).ToList().GetRange(min, max);
CuiElementContainer container = CreateCommandsElement(range, i, i < maxPages - 1, i > 0, npcId);
uiManager.RenameComponents(container);
uiManager.npcElements[npcId][UIPanel.Commands][Category.None][i] = container;
}
}
}
else PrintWarning($"Failed to create commands menu for NPC: {npcId}.Invalid data was supplied!");
}
}
private void CreateExchangeUI(string npcId = null) {
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeExchange")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("exchange1")}</color>", 24, "0 0.82", "1 0.9");
UI.CreateLabel(ref container, UIMain, $"{color2}{msg("exchange2")}</color>{color1}{configData.Exchange.RP} {msg("storeRP")}</color> -> {color1}{configData.Exchange.Economics} {msg("storeCoins")}</color>", 20, "0 0.6", "1 0.7");
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("storeRP")} => {msg("storeEcon")}</color>", 20, "0.25 0.35", "0.4 0.4");
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("storeEcon")} => {msg("storeRP")}</color>", 20, "0.6 0.35", "0.75 0.4");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], msg("storeExchange"), 20, "0.25 0.3", "0.4 0.35", "SRUI_Exchange 1");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], msg("storeExchange"), 20, "0.6 0.3", "0.75 0.35", "SRUI_Exchange 2");
uiManager.RenameComponents(container);
if (!string.IsNullOrEmpty(npcId)) uiManager.npcElements[npcId][UIPanel.Exchange][Category.None][0] = container;
else uiManager.standardElements[UIPanel.Exchange][Category.None][0] = container;
}
private CuiElementContainer CreateItemsElement(List<KeyValuePair<string, RewardData.RewardItem>> items, Category category, int page, bool pageUp, bool pageDown, string npcId) {
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg(category.ToString())}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.949", "0.995 0.99", true);
CreateSubMenu(ref container, UIMain, npcId);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.94", true);
if (pageUp) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], ">>>", 16, "0.87 0.03", "0.955 0.07", $"SRUI_ChangeElement Items {page + 1} {npcId ?? "null"} {category}");
if (pageDown) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "<<<", 16, "0.045 0.03", "0.13 0.07", $"SRUI_ChangeElement Items {page - 1} {npcId ?? "null"} {category}");
for (int i = 0; i < items.Count; i++) {
CreateItemEntry(ref container, UIMain, items[i].Key, items[i].Value, i);
}
return container;
}
private CuiElementContainer CreateKitsElement(List<KeyValuePair<string, RewardData.RewardKit>> kits, int page, bool pageUp, bool pageDown, string npcId = null) {
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeKits")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
if (kits.Count == 0) UI.CreateLabel(ref container, UIMain, $"{color1}{msg("noKits")}</color>", 24, "0 0.82", "1 0.9");
else {
if (pageUp) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], ">>>", 16, "0.87 0.03", "0.955 0.07", $"SRUI_ChangeElement Kits {page + 1} {npcId}");
if (pageDown) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "<<<", 16, "0.045 0.03", "0.13 0.07", $"SRUI_ChangeElement Kits {page - 1} {npcId}");
for (int i = 0; i < kits.Count; i++) {
RewardData.RewardKit kit = kits[i].Value;
string description = string.Empty;
if (configData.UIOptions.KitContents) description = GetKitContents(kit.kitName);
else description = kit.description;
CreateKitCommandEntry(ref container, UIMain, kit.displayName, kits[i].Key, description, kit.cost, i, true, kit.iconName);
}
}
return container;
}
private CuiElementContainer CreateCommandsElement(List<KeyValuePair<string, RewardData.RewardCommand>> commands, int page, bool pageUp, bool pageDown, string npcId = null) {
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeCommands")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
if (commands.Count == 0) UI.CreateLabel(ref container, UIMain, $"{color1}{msg("noCommands")}</color>", 24, "0 0.82", "1 0.9");
else {
if (pageUp) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], ">>>", 16, "0.87 0.03", "0.955 0.07", $"SRUI_ChangeElement Commands {page + 1} {npcId}");
if (pageDown) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "<<<", 16, "0.045 0.03", "0.13 0.07", $"SRUI_ChangeElement Commands {page - 1} {npcId}");
for (int i = 0; i < commands.Count; i++) {
RewardData.RewardCommand command = commands[i].Value;
CreateKitCommandEntry(ref container, UIMain, command.displayName, commands[i].Key, command.description, command.cost, i, false, command.iconName);
}
}
return container;
}
private void PopupMessage(BasePlayer player, string msg) {
CuiElementContainer element = UI.CreateElementContainer(UIPopup, uiColors["dark"], "0.33 0.45", "0.67 0.6");
UI.CreatePanel(ref element, UIPopup, uiColors["light"], "0.01 0.04", "0.99 0.96");
UI.CreateLabel(ref element, UIPopup, $"{color1}{msg}</color>", 20, "0.05 0.05", "0.95 0.95");
if (popupMessages.ContainsKey(player.userID)) {
CuiHelper.DestroyUi(player, UIPopup);
popupMessages[player.userID].Destroy();
popupMessages.Remove(player.userID);
}
CuiHelper.AddUi(player, element);
popupMessages.Add(player.userID, timer.In(3.5f, () => {
CuiHelper.DestroyUi(player, UIPopup);
popupMessages.Remove(player.userID);
}
));
}
private void DisplayPoints(BasePlayer player) {
if (player == null) return;
CuiHelper.DestroyUi(player, UIRP);
if (!uiManager.IsOpen(player)) return;
int playerPoints = CheckPoints(player.userID);
CuiElementContainer element = UI.CreateElementContainer(UIRP, "0 0 0 0", "0.3 0", "0.7 0.1");
string message = $"{color1}{msg("storeRP", player.UserIDString)}: {playerPoints}</color>";
if (Economics && configData.Tabs.Exchange) {
object amount = Economics?.Call("Balance", player.UserIDString);
message = message + $" {color2}||</color> {color1}Economics: {amount}</color>";
}
if (configData.UIOptions.ShowPlaytime) {
object time = Interface.CallHook("GetPlayTime", player.UserIDString);
if (time is double) {
string playTime = FormatTime((double)time);
if (!string.IsNullOrEmpty(playTime)) message = $"{color1}{msg("storePlaytime", player.UserIDString)}: {playTime}</color> {color2}||</color> " + message;
}
}
UI.CreateLabel(ref element, UIRP, message, 20, "0 0", "1 1", TextAnchor.MiddleCenter, null, 0f);
CuiHelper.AddUi(player, element);
timer.Once(1, () => DisplayPoints(player));
}
#region Sale System
private CuiElementContainer CreateSaleElement(BasePlayer player) {
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeSales")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("selectItemSell")}</color>", 20, "0 0.9", "1 1");
int i = 0;
foreach (Item item in player.inventory.containerMain.itemList) {
if (saleData.items.ContainsKey(item.info.shortname)) {
if (!saleData.items[item.info.shortname].ContainsKey(item.skin)) {
saleData.items[item.info.shortname].Add(item.skin, new SaleData.SaleItem {
displayName = item?.info?.steamItem?.displayName?.translated ?? $"{item.info.displayName.translated} {item.skin}"
}
);
SaveSales();
}
string name = saleData.items[item.info.shortname][item.skin].displayName;
CreateInventoryEntry(ref container, UIMain, item.info.shortname, item.skin, name, item.amount, i);
i++;
}
}
return container;
}
private void CreateInventoryEntry(ref CuiElementContainer container, string panelName, string shortname, ulong skinId, string name, int amount, int number) {
float[] pos = CalcPosInv(number);
UI.CreateLabel(ref container, panelName, $"{msg("Name")}: {color1}{name}</color>", 14, $"{pos[0]} {pos[1]}", $"{pos[0] + 0.22f} {pos[3]}", TextAnchor.MiddleLeft);
UI.CreateLabel(ref container, panelName, $"{msg("Amount")}: {color1}{amount}</color>", 14, $"{pos[0] + 0.22f} {pos[1]}", $"{pos[0] + 0.32f} {pos[3]}", TextAnchor.MiddleLeft);
if (saleData.items[shortname][skinId].enabled) UI.CreateButton(ref container, panelName, uiColors["buttonbg"], msg("Sell"), 12, $"{pos[0] + 0.37f} {pos[1] + 0.0015f}", $"{pos[2]} {pos[3] - 0.0015f}", $"SRUI_SellItem {shortname} {skinId} {amount}");
else UI.CreateButton(ref container, panelName, uiColors["buttonbg"], msg("CantSell"), 12, $"{pos[0] + 0.37f} {pos[1] + 0.0015f}", $"{pos[2]} {pos[3] - 0.0015f}", string.Empty);
}
private void SellItem(BasePlayer player, string shortname, ulong skinId, int amount) {
SaleData.SaleItem saleItem = saleData.items[shortname][skinId];
string name = saleItem.displayName;
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeSales")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("selectToSell")}</color>", 20, "0 0.9", "1 1");
int salePrice = (int)Math.Floor(saleItem.price * amount);
UI.CreateLabel(ref container, UIMain, string.Format(msg("sellItemF"), color1, name), 18, "0.1 0.8", "0.3 0.84", TextAnchor.MiddleLeft);
UI.CreateLabel(ref container, UIMain, string.Format(msg("sellPriceF"), color1, saleItem.price, msg("storeRP")), 18, "0.1 0.76", "0.3 0.8", TextAnchor.MiddleLeft);
UI.CreateLabel(ref container, UIMain, string.Format(msg("sellUnitF"), color1, amount), 18, "0.1 0.72", "0.3 0.76", TextAnchor.MiddleLeft);
UI.CreateLabel(ref container, UIMain, string.Format(msg("sellTotalF"), color1, salePrice, msg("storeRP")), 18, "0.1 0.68", "0.3 0.72", TextAnchor.MiddleLeft);
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "+ 10000", 16, "0.84 0.72", "0.89 0.76", $"SRUI_SellItem {shortname} {skinId} {amount + 10000}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "+ 1000", 16, "0.78 0.72", "0.83 0.76", $"SRUI_SellItem {shortname} {skinId} {amount + 1000}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "+ 100", 16, "0.72 0.72", "0.77 0.76", $"SRUI_SellItem {shortname} {skinId} {amount + 100}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "+ 10", 16, "0.66 0.72", "0.71 0.76", $"SRUI_SellItem {shortname} {skinId} {amount + 10}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "+ 1", 16, "0.6 0.72", "0.65 0.76", $"SRUI_SellItem {shortname} {skinId} {amount + 1}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "-1", 16, "0.54 0.72", "0.59 0.76", $"SRUI_SellItem {shortname} {skinId} {amount - 1}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "-10", 16, "0.48 0.72", "0.53 0.76", $"SRUI_SellItem {shortname} {skinId} {amount - 10}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "-100", 16, "0.42 0.72", "0.47 0.76", $"SRUI_SellItem {shortname} {skinId} {amount - 100}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "-1000", 16, "0.36 0.72", "0.41 0.76", $"SRUI_SellItem {shortname} {skinId} {amount - 1000}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "-10000", 16, "0.3 0.72", "0.35 0.76", $"SRUI_SellItem {shortname} {skinId} {amount - 10000}");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], msg("cancelSale"), 16, "0.75 0.34", "0.9 0.39", "SRUI_CancelSale");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], msg("confirmSale"), 16, "0.55 0.34", "0.7 0.39", $"SRUI_Sell {shortname} {skinId} {amount}");
CuiHelper.DestroyUi(player, UIMain);
CuiHelper.AddUi(player, container);
}
#endregion
#region Transfer System
private CuiElementContainer CreateTransferElement(BasePlayer player, int page = 0) {
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeTransfer")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("transfer1", player.UserIDString)}</color>", 20, "0 0.9", "1 1");
int playerCount = BasePlayer.activePlayerList.Count;
if (playerCount > 136) {
int maxpages = (playerCount - 1) / 136 + 1;
if (page < maxpages - 1) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], msg("storeNext", player.UserIDString), 14, "0.87 0.935", "0.97 0.97", $"SRUI_Transfer {page + 1}");
if (page > 0) UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], msg("storeBack", player.UserIDString), 14, "0.03 0.935", "0.13 0.97", $"SRUI_Transfer {page - 1}");
}
int maxentries = (136 * (page + 1));
if (maxentries > playerCount) maxentries = playerCount;
int rewardcount = 136 * page;
int i = 0;
for (int n = rewardcount; n < maxentries; n++) {
BasePlayer target = BasePlayer.activePlayerList[n];
if (target == null || target == player) continue;
CreatePlayerNameEntry(ref container, UIMain, target.displayName, target.UserIDString, i);
i++;
}
return container;
}
private void TransferElement(BasePlayer player, string name, string id) {
CuiHelper.DestroyUi(player, UIMain);
CuiElementContainer container = UI.CreateElementContainer(UIMain, uiColors["dark"], "0 0", "1 0.95");
UI.CreateLabel(ref container, UIMain, $"<color={configData.Colors.Background_Dark.Color}>{msg("storeTransfer")}</color>", 200, "0 0", "1 1", TextAnchor.MiddleCenter);
UI.CreatePanel(ref container, UIMain, uiColors["light"], "0.005 0.01", "0.995 0.99", true);
UI.CreateLabel(ref container, UIMain, $"{color1}{msg("transfer2", player.UserIDString)}</color>", 24, "0 0.82", "1 0.9");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "1", 20, "0.27 0.3", "0.37 0.35", $"SRUI_TransferID {id} 1");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "10", 20, "0.39 0.3", "0.49 0.35", $"SRUI_TransferID {id} 10");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "100", 20, "0.51 0.3", "0.61 0.35", $"SRUI_TransferID {id} 100");
UI.CreateButton(ref container, UIMain, uiColors["buttonbg"], "1000", 20, "0.63 0.3", "0.73 0.35", $"SRUI_TransferID {id} 1000");
CuiHelper.DestroyUi(player, UIMain);
CuiHelper.AddUi(player, container);
}
#endregion
#endregion
#region UI Functions
private void CreateMenuButton(ref CuiElementContainer container, string panelName, string buttonname, string command, int number) {
Vector2 dimensions = new Vector2(0.1f, 0.6f);
Vector2 origin = new Vector2(0.2f, 0.2f);
Vector2 offset = new Vector2((0.005f + dimensions.x) * number, 0);
Vector2 posMin = origin +
// ... [Code preview truncated due to length. Full source in attached file] ...