public static readonly HashSet<BasePlayer> plrsWithPopUp = new();
#region Initialization
private void Init()
{
Ui.DestroyAll();
}
#endregion
#region Commands
[ChatCommand("ui")]
private void CmdOpenUi(BasePlayer player)
{
Ui.Destroy(player);
Ui.Create(player, ImageLibrary);
}
[ConsoleCommand("quarrycompui.close")]
private void CmdClose(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
Ui.Destroy(plr);
PrintToChat(plr, "Close button clicked.");
}
}
[ConsoleCommand("quarrycompui.remove")]
private void CmdRemQuarry(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null && !plrsWithPopUp.Contains(plr))
{
plrsWithPopUp.Add(plr);
Ui.ShowPopup(plr, "Remove the Quarry?", "quarrycompui.confirmremove", "quarrycompui.cancelremove");
}
}
[ConsoleCommand("quarrycompui.confirmremove")]
private void CmdConfRem(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
Ui.ClosePopup(plr);
PrintToChat(plr, "Quarry removed.");
}
}
[ConsoleCommand("quarrycompui.cancelremove")]
private void CmdCancelRem(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
Ui.ClosePopup(plr);
PrintToChat(plr, "Removal cancelled.");
}
}
[ConsoleCommand("quarrycompui.upgrade")]
private void CmdUpgQuarry(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null && !plrsWithPopUp.Contains(plr))
{
plrsWithPopUp.Add(plr);
Ui.ShowPopup(plr, "Upgrade the Quarry?", "quarrycompui.confirmupgrade", "quarrycompui.cancelupgrade");
}
}
[ConsoleCommand("quarrycompui.confirmupgrade")]
private void CmdConfUpg(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
Ui.ClosePopup(plr);
PrintToChat(plr, "Quarry upgraded.");
}
}
[ConsoleCommand("quarrycompui.cancelupgrade")]
private void CmdCancelUpg(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
Ui.ClosePopup(plr);
PrintToChat(plr, "Upgrade cancelled.");
}
}
#endregion
#region UI Configuration
public static class Ui
{
#region Configuration Dictionaries
public static class Cfg
{
public static readonly Dictionary<string, string> Comps =
new()
{
{ "Bg", "QuarryCompUi_Background" },
{ "MainPanel", "QuarryCompUi_MainPanel" },
{ "OvrlBlk", "Overlay_Block" },
{ "PopShd", "Popup_Shadow" },
{ "PopBdr", "Popup_Border" },
{ "PopBg", "Popup_Background" },
{ "ClsBtn", "QuarryCompUi_Close" },
{ "QryPanel", "QuarryCompUi_Full_Left" },
{ "UpgPanel", "QuarryCompUi_Full_Right" },
};
public static readonly Dictionary<string, string> Colors =
new()
{
{ "Gray", "0.5 0.5 0.5 0.9" },
{ "LightGray", "0.60 0.60 0.60 0.95" },
{ "DarkGray", "0.25 0.25 0.25 0.95" },
{ "Red", "1 0 0 1" },
{ "DarkRed", "0.55 0 0 1" },
{ "FireBrick", "0.7 0.13 0.13 1" },
{ "Crimson", "0.86 0.08 0.24 1" },
{ "Maroon", "0.5 0 0 1" },
{ "Burgundy", "0.5 0 0.13 1" },
{ "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.41 0.71 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" },
};
}
#endregion
#region UI Methods
public static void Create(BasePlayer plr, Plugin ImageLibrary)
{
var cont = new CuiElementContainer();
AddPanel(cont, "0 0", "1 1", Cfg.Comps["Bg"], clr: "0 0 0 0", isCurEnb: true);
AddMain(cont);
AddCloseBtn(cont, Cfg.Comps["MainPanel"]);
AddImg(cont, Cfg.Comps["Bg"], "crude.oil", "0.1 0.1", "0.2 0.2", "ResImg", ImageLibrary);
CuiHelper.AddUi(plr, cont);
}
public static void Destroy(BasePlayer plr)
{
if (plr == null)
return;
foreach (var elem in Cfg.Comps)
CuiHelper.DestroyUi(plr, elem.Value);
plrsWithPopUp.Remove(plr);
}
public static void DestroyAll()
{
foreach (var plr in BasePlayer.activePlayerList)
Destroy(plr);
}
public static void ShowPopup(BasePlayer plr, string msg, string cmdConfirm, string cmdCancel)
{
var cont = new CuiElementContainer();
AddPanel(cont, "0 0", "1 1", Cfg.Comps["OvrlBlk"], "Overlay", "0 0 0 0.9", isCurEnb: true);
AddPanel(cont, "0.4 0.4", "0.6 0.6", Cfg.Comps["PopShd"], Cfg.Comps["OvrlBlk"], "0 0 0 0.85");
AddPanel(cont, "0.0 0.09", "0.95 1.0", Cfg.Comps["PopBdr"], Cfg.Comps["PopShd"], Cfg.Colors["White"]);
AddPanel(cont, "0.01 0.01", "0.991 0.985", Cfg.Comps["PopBg"], Cfg.Comps["PopBdr"], Cfg.Colors["Black"]);
AddTxt(cont, Cfg.Comps["PopBg"], "0.1 0.6", "0.9 0.9", msg, 16, TextAnchor.MiddleCenter);
AddBtn(cont, Cfg.Comps["PopBg"], "Yes", cmdConfirm, "0.25", "0.05", "0.45", "0.15", Cfg.Colors["LightGray"], Cfg.Colors["Green"]);
AddBtn(cont, Cfg.Comps["PopBg"], "No", cmdCancel, "0.55", "0.05", "0.75", "0.15", Cfg.Colors["LightGray"], Cfg.Colors["Red"]);
CuiHelper.AddUi(plr, cont);
}
public static void ClosePopup(BasePlayer plr)
{
foreach (var elem in Cfg.Comps)
if (elem.Key.StartsWith("Popup") || elem.Value == Cfg.Comps["OvrlBlk"])
CuiHelper.DestroyUi(plr, elem.Value);
plrsWithPopUp.Remove(plr);
}
#endregion
#region Helper Methods
private static void AddMain(CuiElementContainer cont)
{
AddPanel(cont, "0.235 0.26", "0.765 0.724", Cfg.Comps["MainPanel"], Cfg.Comps["Bg"], Cfg.Colors["LightGray"], true);
AddQuarryPanel(cont);
AddUpgradePanel(cont);
}
private static void AddQuarryPanel(CuiElementContainer cont)
{
AddPanel(cont, "0.0 0", "0.5 1", Cfg.Comps["QryPanel"], Cfg.Comps["MainPanel"], "0 0 0 0");
AddInnerSquare(cont, Cfg.Comps["QryPanel"], "0.10 0.05", "0.95 0.90", "0 0 0 0.97");
AddInnerSquare(cont, Cfg.Comps["QryPanel"], "0.054 0.1033", "0.895 0.945", "0.8 0.8 0.8 1");
AddInnerSquare(cont, Cfg.Comps["QryPanel"], "0.06 0.108", "0.89 0.94", Cfg.Colors["DarkRed"]);
AddInnerSquare(cont, Cfg.Comps["QryPanel"], "0.06 0.865", "0.89 0.870", "0.8 0.8 0.8 1");
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.84", "0.9 0.98", $"Quarry Level", 15, TextAnchor.MiddleCenter); // Removed level
AddSep(cont, Cfg.Comps["QryPanel"], "0.06 0.82", "0.89 0.825");
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.78", "0.9 0.82", "Extraction Settings:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.74", "0.9 0.78", "Extraction Interval: 1 sec", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.7", "0.9 0.74", "Fuel/extraction: 1 LG Fuel", 10, TextAnchor.MiddleLeft);
AddSep(cont, Cfg.Comps["QryPanel"], "0.06 0.65", "0.89 0.655");
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.6", "0.9 0.65", "Storage:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.56", "0.9 0.6", "Fuel Storage: 3 slots", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.52", "0.9 0.56", "Resource Storage: 6 slots", 10, TextAnchor.MiddleLeft);
AddSep(cont, Cfg.Comps["QryPanel"], "0.06 0.47", "0.89 0.475");
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.42", "0.9 0.47", "Resources/Extraction:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.38", "0.9 0.42", "Crude Oil: 10", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.34", "0.9 0.38", "HQM Ore: 60", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.3", "0.9 0.34", "Metal Ore: 100", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.26", "0.9 0.3", "Stones: 250", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["QryPanel"], "0.1 0.22", "0.9 0.26", "Sulfur Ore: 160", 10, TextAnchor.MiddleLeft);
AddBtn(cont, Cfg.Comps["QryPanel"], "Remove Quarry", "quarrycompui.remove", "0.35", "0.11", "0.65", "0.16", Cfg.Colors["LightGray"], Cfg.Colors["Red"]);
}
private static void AddUpgradePanel(CuiElementContainer cont)
{
AddPanel(cont, "0.5 0", "1 1", Cfg.Comps["UpgPanel"], Cfg.Comps["MainPanel"], "0 0 0 0");
AddInnerSquare(cont, Cfg.Comps["UpgPanel"], "0.10 0.05", "0.95 0.90", "0 0 0 0.97");
AddInnerSquare(cont, Cfg.Comps["UpgPanel"], "0.054 0.1033", "0.895 0.945", "0.8 0.8 0.8 1");
AddInnerSquare(cont, Cfg.Comps["UpgPanel"], "0.06 0.108", "0.89 0.94", "0 0 1 1");
AddInnerSquare(cont, Cfg.Comps["UpgPanel"], "0.06 0.865", "0.89 0.870", "0.8 0.8 0.8 1");
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.84", "0.9 0.98", $"Upgrade to Next Level", 15, TextAnchor.MiddleCenter);
AddSep(cont, Cfg.Comps["UpgPanel"], "0.06 0.82", "0.89 0.825");
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.78", "0.9 0.82", "Requirements:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.74", "0.9 0.78", "Scrap: 5000", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.7", "0.9 0.74", "Bone Fragments: 10000", 10, TextAnchor.MiddleLeft);
AddSep(cont, Cfg.Comps["UpgPanel"], "0.06 0.65", "0.89 0.655");
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.6", "0.9 0.65", "Upgrade Effects:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.56", "0.9 0.6", "Fuel Storage: 6 slots", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.52", "0.9 0.56", "Resource Storage: 12 slots", 10, TextAnchor.MiddleLeft);
AddSep(cont, Cfg.Comps["UpgPanel"], "0.06 0.47", "0.89 0.475");
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.42", "0.9 0.47", "Crude Oil: 20", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.38", "0.9 0.42", "HQM Ore: 120", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.34", "0.9 0.38", "Metal Ore: 150", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.3", "0.9 0.34", "Stones: 350", 10, TextAnchor.MiddleLeft);
AddTxt(cont, Cfg.Comps["UpgPanel"], "0.1 0.26", "0.9 0.3", "Sulfur Ore: 200", 10, TextAnchor.MiddleLeft);
AddBtn(cont, Cfg.Comps["UpgPanel"], "Upgrade", "quarrycompui.upgrade", "0.35", "0.11", "0.65", "0.16", Cfg.Colors["LightGray"], Cfg.Colors["Green"]);
}
private static void AddSep(CuiElementContainer cont, string prnt, string acrMin, string acrMax)
{
AddInnerSquare(cont, prnt, acrMin, acrMax, "0.8 0.8 0.8 1");
}
#endregion
#region Add UI Components
private static void AddPanel(
CuiElementContainer cont,
string acrMin,
string acrMax,
string pName,
string prnt = "Overlay",
string clr = "0 0 0 1",
bool isCurEnb = false,
bool isBg = false
)
{
var panel = new CuiPanel
{
Image = { Color = clr },
RectTransform = { AnchorMin = acrMin, AnchorMax = acrMax },
CursorEnabled = isCurEnb,
};
if (isBg)
{
panel.Image.Material = "assets/content/ui/uibackgroundblur.mat";
panel.Image.Sprite = "assets/content/ui/ui.background.transparent.radial.psd";
}
cont.Add(panel, prnt, pName);
}
private static void AddInnerSquare(CuiElementContainer cont, string prnt, string acrMin, string acrMax, string clr)
{
cont.Add(new CuiPanel { Image = { Color = clr }, RectTransform = { AnchorMin = acrMin, AnchorMax = acrMax } }, prnt);
}
private static void AddTxt(CuiElementContainer cont, string prnt, string acrMin, string acrMax, string txt, int fSize, TextAnchor align)
{
cont.Add(
new CuiLabel
{
Text =
{
Text = txt,
FontSize = fSize,
Font = "DroidSansMono.ttf",
Align = align,
Color = Cfg.Colors["White"],
},
RectTransform = { AnchorMin = acrMin, AnchorMax = acrMax },
},
prnt
);
}
private static void AddBtn(CuiElementContainer cont, string prnt, string txt, string cmd, string acrMinX, string acrMinY, string acrMaxX, string acrMaxY, string bgClr, string txtClr)
{
cont.Add(
new CuiButton
{
Button =
{
Color = bgClr,
Command = cmd,
Close = "",
},
RectTransform = { AnchorMin = $"{acrMinX} {acrMinY}", AnchorMax = $"{acrMaxX} {acrMaxY}" },
Text =
{
Text = txt,
FontSize = 14,
Align = TextAnchor.MiddleCenter,
Color = txtClr,
},
},
prnt
);
}
private static void AddImg(CuiElementContainer cont, string prnt, string resName, string acrMin, string acrMax, string imgName, Plugin ImageLibrary)
{
string imgUrl = (string)ImageLibrary?.Call("GetImage", resName);
if (imgUrl == null)
{
Debug.LogError($"Failed to get image for item: {resName}");
return;
}
cont.Add(
new CuiElement
{
Name = imgName,
Parent = prnt,
Components =
{
new CuiRawImageComponent { Png = imgUrl },
new CuiRectTransformComponent { AnchorMin = acrMin, AnchorMax = acrMax },
},
}
);
}
private static void AddCloseBtn(CuiElementContainer cont, string prnt)
{
cont.Add(
new CuiButton
{
Button =
{
Color = "1 0 0 1",
Command = "quarrycompui.close",
Close = Cfg.Comps["Bg"],
},
RectTransform = { AnchorMin = "0.95 0.95", AnchorMax = "1 1" },
Text =
{
Text = "✖",
FontSize = 13,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.5",
},
},
prnt,
Cfg.Comps["ClsBtn"]
);
}
#endregion
}
#endregion
}