private readonly Dictionary<string, string> colorOptions = new Dictionary<string, string>
{
{ "Gray", "0.5 0.5 0.5 0.9" },
{ "LightGray", "0.60 0.60 0.60 1" },
{ "DarkGray", "0.25 0.25 0.25 1" },
{ "Red", "1 0 0 1" },
{ "DarkRed", "0.55 0 0 1" }, // Vermelho escuro
{ "FireBrick", "0.7 0.13 0.13 1" }, // Encarnado profundo
{ "Crimson", "0.86 0.08 0.24 1" },
{ "Maroon", "0.5 0 0 1" }, // Marrom avermelhado
{ "Burgundy", "0.5 0 0.13 1" }, // Vinho intenso
{ "DeepPink", "1 0.08 0.58 1" },
{ "Fuchsia", "1 0 1 1" },
{ "Magenta", "1 0 1 1" },
{ "Brown", "0.6 0.3 0 1" },
{ "DarkMagenta", "0.55 0 0.55 1" },
{ "IndianRed", "0.8 0.36 0.36 1" },
{ "RosyBrown", "0.74 0.56 0.56 1" },
{ "MediumVioletRed", "0.78 0.08 0.52 1" },
{ "Purple", "0.5 0 0.5 1" },
{ "Blue", "0 0 1 1" },
{ "Green", "0 1 0 1" },
{ "Yellow", "1 1 0 1" },
{ "Cyan", "0 1 1 1" },
{ "Orange", "1 0.5 0 1" },
{ "Pink", "1 0.75 0.8 1" },
{ "Lime", "0.75 1 0 1" },
{ "Teal", "0 0.5 0.5 1" },
{ "Lavender", "0.9 0.9 0.98 1" },
{ "White", "1 1 1 1" },
{ "Black", "0 0 0 1" },
{ "SkyBlue", "0.53 0.81 0.98 1" },
{ "Ivory", "1 1 0.94 1" },
{ "Goldenrod", "0.85 0.65 0.13 1" },
{ "Coral", "1 0.5 0.31 1" },
{ "Salmon", "0.98 0.5 0.45 1" },
{ "Navy", "0 0 0.5 1" },
{ "Turquoise", "0.25 0.88 0.82 1" },
{ "Chartreuse", "0.5 1 0 1" },
{ "SlateGray", "0.44 0.5 0.56 1" },
{ "ForestGreen", "0.13 0.55 0.13 1" },
{ "Khaki", "0.94 0.9 0.55 1" },
};
private void Init() => RemoveUiFromAllPlayers();
[ChatCommand("ui")]
private void OpenUiCommand(BasePlayer player)
{
RemoveUiFromPlayer(player);
BuildAndSendUI(player, 1);
}
[ConsoleCommand(CommandPrefix + ".close")]
private void CloseUiCommand(ConsoleSystem.Arg args)
{
var player = args?.Player();
if (player != null)
{
RemoveUiFromPlayer(player);
PrintToChat(player, "Close button was clicked.");
}
}
[ConsoleCommand(CommandPrefix + ".remove")]
private void RemoveQuarryCommand(ConsoleSystem.Arg args)
{
var player = args?.Player();
if (player != null)
{
PrintToChat(player, "Remove Quarry button was clicked.");
}
}
[ConsoleCommand(CommandPrefix + ".upgrade")]
private void UpgradeQuarryCommand(ConsoleSystem.Arg args)
{
var player = args?.Player();
if (player != null)
{
PrintToChat(player, "Upgrade button was clicked.");
}
}
private void RemoveUiFromPlayer(BasePlayer player)
{
if (player == null)
return;
foreach (var element in UiElements)
{
CuiHelper.DestroyUi(player, element);
}
player.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, false);
player.UpdateActiveItem(default);
}
private void RemoveUiFromAllPlayers()
{
foreach (var player in BasePlayer.activePlayerList)
{
RemoveUiFromPlayer(player);
BuildAndSendUI(player, 1);
}
}
private void BuildAndSendUI(BasePlayer player, int level)
{
var container = new CuiElementContainer();
string parentPanel = "QuarryUi_Background";
AddPanel(container, "0 0", "1 1", parentPanel, color: "0 0 0 0", cursorEnabled: true);
AddQuarryLevelPanel(container, level, parentPanel);
AddUpgradePanel(container, level, parentPanel);
AddCloseButton(container, "QuarryUi_Full_Right");
CuiHelper.AddUi(player, container);
player.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, true);
}
private void AddQuarryLevelPanel(CuiElementContainer container, int level, string parent)
{
var panelName = "QuarryUi_Full_Left";
AddPanel(container, "0.235 0.26", "0.499 0.724", panelName, parent, color: colorOptions["LightGray"], isBackground: true);
AddInnerSquare(container, panelName, "0.10 0.05", "0.95 0.90", "0 0 0 0.97");
AddInnerSquare(container, panelName, "0.054 0.1033", "0.895 0.945", "0.8 0.8 0.8 1");
AddInnerSquare(container, panelName, "0.06 0.108", "0.89 0.94", colorOptions["DarkRed"]);
AddInnerSquare(container, panelName, "0.06 0.865", "0.89 0.870", "0.8 0.8 0.8 1");
AddText(container, panelName, "0.1 0.84", "0.9 0.98", $"Quarry Level {level}", 15, TextAnchor.MiddleCenter);
AddText(container, panelName, "0.1 0.78", "0.9 0.82", "Extraction Settings:", 12, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.74", "0.9 0.78", "Extraction Interval: 1 second", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.7", "0.9 0.74", "Fuel per extraction: 1 Low Grade Fuel", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.6", "0.9 0.65", "Storage:", 12, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.56", "0.9 0.6", "Fuel Storage: 3 slots", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.52", "0.9 0.56", "Resource Storage: 6 slots", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.42", "0.9 0.47", "Resources Output Per Extraction:", 12, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.38", "0.9 0.42", "Crude Oil: 10", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.34", "0.9 0.38", "HQM Ore: 60", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.3", "0.9 0.34", "Metal Ore: 100", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.26", "0.9 0.3", "Stones: 250", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.22", "0.9 0.26", "Sulfur Ore: 160", 10, TextAnchor.MiddleLeft);
AddButton(container, panelName, "Remove Quarry", CommandPrefix + ".remove", "0.35", "0.01", "0.65", "0.07");
}
private void AddUpgradePanel(CuiElementContainer container, int level, string parent)
{
var panelName = "QuarryUi_Full_Right";
AddPanel(container, "0.4995 0.26", "0.765 0.724", panelName, parent, color: colorOptions["LightGray"], isBackground: true);
AddInnerSquare(container, panelName, "0.10 0.05", "0.95 0.90", "0 0 0 0.97");
AddInnerSquare(container, panelName, "0.054 0.1033", "0.895 0.945", "0.8 0.8 0.8 1");
AddInnerSquare(container, panelName, "0.06 0.108", "0.89 0.94", "0 0 1 1");
AddInnerSquare(container, panelName, "0.06 0.865", "0.89 0.870", "0.8 0.8 0.8 1");
AddText(container, panelName, "0.1 0.84", "0.9 0.98", $"Upgrade to Level {level + 1}", 15, TextAnchor.MiddleCenter);
AddText(container, panelName, "0.1 0.78", "0.9 0.82", "Requirements:", 12, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.74", "0.9 0.78", "Scrap: 5000", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.7", "0.9 0.74", "Bone Fragments: 10000", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.6", "0.9 0.65", "Upgrade Effects:", 12, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.56", "0.9 0.6", "Fuel Storage: 6 slots", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.52", "0.9 0.56", "Resource Storage: 12 slots", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.48", "0.9 0.52", "Crude Oil: 20", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.44", "0.9 0.48", "HQM Ore: 120", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.4", "0.9 0.44", "Metal Ore: 150", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.36", "0.9 0.4", "Stones: 350", 10, TextAnchor.MiddleLeft);
AddText(container, panelName, "0.1 0.32", "0.9 0.36", "Sulfur Ore: 200", 10, TextAnchor.MiddleLeft);
AddButton(container, panelName, "Upgrade", CommandPrefix + ".upgrade", "0.35", "0.05", "0.65", "0.1");
}
private void AddPanel(CuiElementContainer container, string anchorMin, string anchorMax, string panelName, string parent = "Overlay", string color = "0 0 0 1", bool cursorEnabled = false, bool isBackground = false)
{
var panel = new CuiPanel
{
Image = { Color = color },
RectTransform = { AnchorMin = anchorMin, AnchorMax = anchorMax },
CursorEnabled = cursorEnabled,
};
if (isBackground)
{
//panel.Image.Material = "assets/content/ui/uibackgroundblur.mat";
//panel.Image.Sprite = "assets/content/ui/ui.background.transparent.radial.psd";
}
container.Add(panel, parent, panelName);
}
private void AddInnerSquare(CuiElementContainer container, string parent, string anchorMin, string anchorMax, string color)
{
container.Add(new CuiPanel { Image = { Color = color }, RectTransform = { AnchorMin = anchorMin, AnchorMax = anchorMax } }, parent);
}
private void AddText(CuiElementContainer container, string parent, string anchorMin, string anchorMax, string text, int fontSize, TextAnchor align)
{
container.Add(
new CuiLabel
{
Text =
{
Text = text,
FontSize = fontSize,
Font = "DroidSansMono.ttf",
//Font = "Robotocondensed-Bold.ttf",
//Font = "Robotocondensed-Regular.ttf",
//Font = "PermanentMarker.ttf",
Align = align,
Color = colorOptions["White"],
},
RectTransform = { AnchorMin = anchorMin, AnchorMax = anchorMax },
},
parent
);
}
private void AddButton(CuiElementContainer container, string parent, string text, string command, string anchorMinX, string anchorMinY, string anchorMaxX, string anchorMaxY)
{
container.Add(
new CuiButton
{
Button =
{
Color = "0 0 1 1",
Command = command,
Close = "",
},
RectTransform = { AnchorMin = $"{anchorMinX} {anchorMinY}", AnchorMax = $"{anchorMaxX} {anchorMaxY}" },
Text =
{
Text = text,
FontSize = 14,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1",
},
},
parent
);
}
private void AddCloseButton(CuiElementContainer container, string parent)
{
container.Add(
new CuiButton
{
Button =
{
Color = "1 0 0 1",
Command = CommandPrefix + ".close",
Close = "QuarryUi_Background",
},
RectTransform = { AnchorMin = "0.95 0.95", AnchorMax = "1 1" },
Text =
{
Text = "✖",
FontSize = 13,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.5",
},
},
parent,
"QuarryUi_CloseButton"
);
}
}