public static readonly HashSet<BasePlayer> plrsWithPopUp = new();
private void Init()
{
ComputerUi.DestroyAll();
}
[ChatCommand("ui")]
private void CmdOpenUi(BasePlayer player)
{
ComputerUi.Destroy(player);
ComputerUi.Create(player, 1, ImageLibrary);
}
[ConsoleCommand("quarrycompui.close")]
private void CmdClose(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
ComputerUi.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);
ComputerUi.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)
{
ComputerUi.ClosePopup(plr);
PrintToChat(plr, "Quarry removed.");
}
}
[ConsoleCommand("quarrycompui.cancelremove")]
private void CmdCancelRem(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
ComputerUi.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);
ComputerUi.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)
{
ComputerUi.ClosePopup(plr);
PrintToChat(plr, "Quarry upgraded.");
}
}
[ConsoleCommand("quarrycompui.cancelupgrade")]
private void CmdCancelUpg(ConsoleSystem.Arg arg)
{
var plr = arg.Player();
if (plr != null)
{
ComputerUi.ClosePopup(plr);
PrintToChat(plr, "Upgrade cancelled.");
}
}
public static class UiCfg
{
public static readonly string[] Elems = { "QuarryCompUi_Background", "QuarryCompUi_Close", "Overlay_Block", "Popup_Shadow", "Popup_Border", "Popup_Background" };
public static readonly Dictionary<string, string> Clrs =
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" },
{ "SlatGray", "0.44 0.5 0.56 1" },
{ "ForestGreen", "0.13 0.55 0.13 1" },
{ "Khaki", "0.94 0.9 0.55 1" },
};
}
public static class UiComp
{
public const string BgName = "QuarryCompUi_Background";
public const string MainCombName = "QuarryCompUi_MainCombined";
public const string OvrlBlkName = "Overlay_Block";
public const string PopShdName = "Popup_Shadow";
public const string PopBdrName = "Popup_Border";
public const string PopBgName = "Popup_Background";
public const string ClsBtnName = "QuarryCompUi_Close";
public const string QryPanelName = "QuarryCompUi_Full_Left";
public const string UpgPanelName = "QuarryCompUi_Full_Right";
}
public static class ComputerUi
{
public static void Create(BasePlayer plr, int lvl, Plugin ImageLibrary)
{
var cont = new CuiElementContainer();
AddPanel(cont, "0 0", "1 1", UiComp.BgName, clr: "0 0 0 0", isCurEnb: true);
AddMainCombined(cont, lvl);
AddCloseBtn(cont, UiComp.MainCombName);
AddImg(cont, UiComp.BgName, "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 UiCfg.Elems)
CuiHelper.DestroyUi(plr, elem);
QuarryComputerUi.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", UiComp.OvrlBlkName, "Overlay", "0 0 0 0.9", isCurEnb: true);
AddPanel(cont, "0.4 0.4", "0.6 0.6", UiComp.PopShdName, UiComp.OvrlBlkName, "0 0 0 0.85");
AddPanel(cont, "0.0 0.09", "0.95 1.0", UiComp.PopBdrName, UiComp.PopShdName, UiCfg.Clrs["White"]);
AddPanel(cont, "0.01 0.01", "0.991 0.985", UiComp.PopBgName, UiComp.PopBdrName, UiCfg.Clrs["Black"]);
AddTxt(cont, UiComp.PopBgName, "0.1 0.6", "0.9 0.9", msg, 16, TextAnchor.MiddleCenter);
AddBtn(cont, UiComp.PopBgName, "Yes", cmdConfirm, "0.25", "0.05", "0.45", "0.15", UiCfg.Clrs["LightGray"], UiCfg.Clrs["Green"]);
AddBtn(cont, UiComp.PopBgName, "No", cmdCancel, "0.55", "0.05", "0.75", "0.15", UiCfg.Clrs["LightGray"], UiCfg.Clrs["Red"]);
CuiHelper.AddUi(plr, cont);
}
public static void ClosePopup(BasePlayer plr)
{
foreach (var elem in UiCfg.Elems)
if (elem.StartsWith("Popup_") || elem == UiComp.OvrlBlkName)
CuiHelper.DestroyUi(plr, elem);
QuarryComputerUi.plrsWithPopUp.Remove(plr);
}
private static void AddMainCombined(CuiElementContainer cont, int lvl)
{
AddPanel(cont, "0.235 0.26", "0.765 0.724", UiComp.MainCombName, UiComp.BgName, UiCfg.Clrs["LightGray"], true);
AddQuarryPanel(cont, lvl);
AddUpgradePanel(cont, lvl);
}
private static void AddQuarryPanel(CuiElementContainer cont, int lvl)
{
AddPanel(cont, "0.0 0", "0.5 1", UiComp.QryPanelName, UiComp.MainCombName, "0 0 0 0");
AddInnerSquare(cont, UiComp.QryPanelName, "0.10 0.05", "0.95 0.90", "0 0 0 0.97");
AddInnerSquare(cont, UiComp.QryPanelName, "0.054 0.1033", "0.895 0.945", "0.8 0.8 0.8 1");
AddInnerSquare(cont, UiComp.QryPanelName, "0.06 0.108", "0.89 0.94", UiCfg.Clrs["DarkRed"]);
AddInnerSquare(cont, UiComp.QryPanelName, "0.06 0.865", "0.89 0.870", "0.8 0.8 0.8 1");
AddTxt(cont, UiComp.QryPanelName, "0.1 0.84", "0.9 0.98", $"Quarry Level {lvl}", 15, TextAnchor.MiddleCenter);
AddSep(cont, UiComp.QryPanelName, "0.06 0.82", "0.89 0.825");
AddTxt(cont, UiComp.QryPanelName, "0.1 0.78", "0.9 0.82", "Extraction Settings:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.74", "0.9 0.78", "Extraction Interval: 1 sec", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.7", "0.9 0.74", "Fuel/extraction: 1 LG Fuel", 10, TextAnchor.MiddleLeft);
AddSep(cont, UiComp.QryPanelName, "0.06 0.65", "0.89 0.655");
AddTxt(cont, UiComp.QryPanelName, "0.1 0.6", "0.9 0.65", "Storage:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.56", "0.9 0.6", "Fuel Storage: 3 slots", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.52", "0.9 0.56", "Resource Storage: 6 slots", 10, TextAnchor.MiddleLeft);
AddSep(cont, UiComp.QryPanelName, "0.06 0.47", "0.89 0.475");
AddTxt(cont, UiComp.QryPanelName, "0.1 0.42", "0.9 0.47", "Resources/Extraction:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.38", "0.9 0.42", "Crude Oil: 10", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.34", "0.9 0.38", "HQM Ore: 60", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.3", "0.9 0.34", "Metal Ore: 100", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.26", "0.9 0.3", "Stones: 250", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.QryPanelName, "0.1 0.22", "0.9 0.26", "Sulfur Ore: 160", 10, TextAnchor.MiddleLeft);
AddBtn(cont, UiComp.QryPanelName, "Remove Quarry", "quarrycompui.remove", "0.35", "0.11", "0.65", "0.16", UiCfg.Clrs["LightGray"], UiCfg.Clrs["Red"]);
}
private static void AddUpgradePanel(CuiElementContainer cont, int lvl)
{
AddPanel(cont, "0.5 0", "1 1", UiComp.UpgPanelName, UiComp.MainCombName, "0 0 0 0");
AddInnerSquare(cont, UiComp.UpgPanelName, "0.10 0.05", "0.95 0.90", "0 0 0 0.97");
AddInnerSquare(cont, UiComp.UpgPanelName, "0.054 0.1033", "0.895 0.945", "0.8 0.8 0.8 1");
AddInnerSquare(cont, UiComp.UpgPanelName, "0.06 0.108", "0.89 0.94", "0 0 1 1");
AddInnerSquare(cont, UiComp.UpgPanelName, "0.06 0.865", "0.89 0.870", "0.8 0.8 0.8 1");
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.84", "0.9 0.98", $"Upgrade to Level {lvl + 1}", 15, TextAnchor.MiddleCenter);
AddSep(cont, UiComp.UpgPanelName, "0.06 0.82", "0.89 0.825");
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.78", "0.9 0.82", "Requirements:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.74", "0.9 0.78", "Scrap: 5000", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.7", "0.9 0.74", "Bone Fragments: 10000", 10, TextAnchor.MiddleLeft);
AddSep(cont, UiComp.UpgPanelName, "0.06 0.65", "0.89 0.655");
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.6", "0.9 0.65", "Upgrade Effects:", 12, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.56", "0.9 0.6", "Fuel Storage: 6 slots", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.52", "0.9 0.56", "Resource Storage: 12 slots", 10, TextAnchor.MiddleLeft);
AddSep(cont, UiComp.UpgPanelName, "0.06 0.47", "0.89 0.475");
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.42", "0.9 0.47", "Crude Oil: 20", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.38", "0.9 0.42", "HQM Ore: 120", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.34", "0.9 0.38", "Metal Ore: 150", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.3", "0.9 0.34", "Stones: 350", 10, TextAnchor.MiddleLeft);
AddTxt(cont, UiComp.UpgPanelName, "0.1 0.26", "0.9 0.3", "Sulfur Ore: 200", 10, TextAnchor.MiddleLeft);
AddBtn(cont, UiComp.UpgPanelName, "Upgrade", "quarrycompui.upgrade", "0.35", "0.11", "0.65", "0.16", UiCfg.Clrs["LightGray"], UiCfg.Clrs["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");
}
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 = UiCfg.Clrs["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 = UiComp.BgName,
},
RectTransform = { AnchorMin = "0.95 0.95", AnchorMax = "1 1" },
Text =
{
Text = "✖",
FontSize = 13,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.5",
},
},
prnt,
UiComp.ClsBtnName
);
}
}
}