using System;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("FurnaceGUI", "YourName", "1.0.0")]
class FurnaceGUI : RustPlugin
{
private Dictionary<ulong, CuiElementContainer> playerGUIs = new Dictionary<ulong, CuiElementContainer>();
private Dictionary<ulong, List<string>> playerResources = new Dictionary<ulong, List<string>>();
private void OnServerInitialized()
{
foreach (BaseOven oven in BaseEntity.saveList.OfType<BaseOven>())
{
ulong ownerID = oven.OwnerID;
playerGUIs.Add(ownerID, CreateGUIElement(ownerID));
playerResources.Add(ownerID, new List<string>{"Resource1", "Resource2", "Resource3"}); // Пример данных ресурсов
}
}
private CuiElementContainer CreateGUIElement(ulong ownerID)
{
var elements = new CuiElementContainer();
string panelName = $"FurnacePanel_{ownerID}";
var guiPanel = elements.Add(new CuiPanel
{
CursorEnabled = true,
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.1 0.1", AnchorMax = "0.3 0.3" }
}, "Hud", panelName);
var tabPanel = elements.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0 0.9", AnchorMax = "1 1" },
Image = { Color = "0.2 0.2 0.2 0.7" }
}, panelName, "TabPanel");
var tabButtonAsc = elements.Add(new CuiButton
{
Button = { Command = "sort asc", Color = "0.8 0.8 0.8 0.5" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "0.5 1" },
Text = { Text = "Sort Asc", FontSize = 16, Align = TextAnchor.MiddleCenter }
}, tabPanel);
var tabButtonDesc = elements.Add(new CuiButton
{
Button = { Command = "sort desc", Color = "0.8 0.8 0.8 0.5" },
RectTransform = { AnchorMin = "0.5 0", AnchorMax = "1 1" },
Text = { Text = "Sort Desc", FontSize = 16, Align = TextAnchor.MiddleCenter }
}, tabPanel);
var guiText = elements.Add(new CuiLabel
{
Text = { Text = "Furnace GUI Text", FontSize = 16, Align = TextAnchor.MiddleCenter },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0.9" }
}, panelName);
return elements;
}
private void OnEntityEnter(BaseNetworkable entity, BasePlayer player)
{
if (entity is BaseOven && player != null)
{
BaseOven oven = entity as BaseOven;
ulong ownerID = oven.OwnerID;
if (playerGUIs.ContainsKey(ownerID) && playerGUIs[ownerID] != null)
{
CuiHelper.AddUi(player, playerGUIs[ownerID]);
}
}
}
private void OnEntityLeave(BaseNetworkable entity, BasePlayer player)
{
if (entity is BaseOven && player != null)
{
BaseOven oven = entity as BaseOven;
ulong ownerID = oven.OwnerID;
if (playerGUIs.ContainsKey(ownerID) && playerGUIs[ownerID] != null)
{
CuiHelper.DestroyUi(player, $"FurnacePanel_{ownerID}");
}
}
}
private void OnPlayerCommand(BasePlayer player, string command, string[] args)
{
if (command == "sort" && args.Length > 0)
{
string sortOrder = args[0].ToLower();
ulong ownerID = player.userID;
if (playerResources.ContainsKey(ownerID))
{
if (sortOrder == "asc")
{
playerResources[ownerID].Sort();
}
else if (sortOrder == "desc")
{
playerResources[ownerID].Sort();
playerResources[ownerID].Reverse();
}
UpdateGUI(ownerID);
}
}
}
private void UpdateGUI(ulong ownerID)
{
CuiElementContainer elements = CreateGUIElement(ownerID);
List<string> resources = playerResources[ownerID];
string resourceText = string.Join(", ", resources);
elements.Get<CuiLabel>("FurnacePanel_" + ownerID).Text.Text = "Sorted Resources: " + resourceText;
CuiHelper.DestroyUi(BasePlayer.FindByID(ownerID), "FurnacePanel_" + ownerID);
CuiHelper.AddUi(BasePlayer.FindByID(ownerID), elements);
}
private void Unload()
{
foreach (var playerGUI in playerGUIs)
{
if (playerGUI.Value != null)
{
foreach (var element in playerGUI.Value)
{
CuiHelper.DestroyUi(BasePlayer.FindByID(playerGUI.Key), element.Name);
}
}
}
playerGUIs.Clear();
playerResources.Clear();
}
}
}