Skip to content

Commit

Permalink
Fix broken UI
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraRozier committed May 19, 2019
1 parent 85a0e3b commit ee91368
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
39 changes: 25 additions & 14 deletions PlayerAdministration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

namespace Oxide.Plugins
{
[Info("PlayerAdministration", "ThibmoRozier", "1.4.0")]
[Info("PlayerAdministration", "ThibmoRozier", "1.4.1")]
[Description("Allows server admins to moderate users using a GUI from within the game.")]
public class PlayerAdministration : RustPlugin
{
Expand Down Expand Up @@ -2033,14 +2033,15 @@ private class ConfigData
#region Predefined UI elements
private static readonly CuiPanel CBasePanel = new CuiPanel() {
RectTransform = {
AnchorMin = "1 1",
AnchorMin = "0 0",
AnchorMax = "1 1",
OffsetMin = "0 0",
OffsetMax = "0 0"
},
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.None.ToString() }
};

private static readonly CuiPanel CMainPanel = new CuiPanel() {
RectTransform = {
AnchorMin = CMainLbAnchor.ToString(),
Expand All @@ -2051,6 +2052,7 @@ private class ConfigData
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.BackgroundDark.ToString() }
};

private static readonly CuiPanel CTabHeaderPanel = new CuiPanel() {
RectTransform = {
AnchorMin = CMainMenuHeaderContainerLbAnchor.ToString(),
Expand All @@ -2061,6 +2063,7 @@ private class ConfigData
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.None.ToString() }
};

private static readonly CuiPanel CTabTabBtnPanel = new CuiPanel() {
RectTransform = {
AnchorMin = CMainMenuTabBtnContainerLbAnchor.ToString(),
Expand All @@ -2071,6 +2074,7 @@ private class ConfigData
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.Background.ToString() }
};

private static readonly CuiPanel CMainPagePanel = new CuiPanel() {
RectTransform = {
AnchorMin = CMainPanelLbAnchor.ToString(),
Expand All @@ -2081,6 +2085,7 @@ private class ConfigData
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.Background.ToString() }
};

private static readonly CuiPanel CBanByIdGroupPanel = new CuiPanel() {
RectTransform = {
AnchorMin = CMainPagePanelBanByIdLbAnchor.ToString(),
Expand All @@ -2091,6 +2096,7 @@ private class ConfigData
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.BackgroundDark.ToString() }
};

private static readonly CuiPanel CUserBtnPageSearchInputPanel = new CuiPanel() {
RectTransform = {
AnchorMin = CUserBtnPagePanelSearchInputLbAnchor.ToString(),
Expand All @@ -2101,6 +2107,7 @@ private class ConfigData
CursorEnabled = true,
Image = new CuiImageComponent() { Color = CuiDefaultColors.BackgroundDark.ToString() }
};

private static readonly CuiLabel CTabMenuHeaderLbl = new CuiLabel() {
Text = {
Text = "Player Administration by ThibmoRozier",
Expand All @@ -2115,6 +2122,7 @@ private class ConfigData
OffsetMax = "0 0"
}
};

private static readonly CuiLabel CMainPageTitleLbl = new CuiLabel() {
Text = {
Text = "Main",
Expand All @@ -2129,6 +2137,7 @@ private class ConfigData
OffsetMax = "0 0"
}
};

private static readonly CuiButton CTabMenuCloseBtn = new CuiButton() {
Button = {
Command = CCloseUiCmd,
Expand All @@ -2148,6 +2157,7 @@ private class ConfigData
Color = CuiDefaultColors.TextAlt.ToString()
}
};

private static readonly CuiButton CBanByIdActiveBtn = new CuiButton() {
Button = {
Command = CMainPageBanByIdCmd,
Expand All @@ -2167,6 +2177,7 @@ private class ConfigData
Color = CuiDefaultColors.TextAlt.ToString()
}
};

private static readonly CuiButton CBanByIdInactiveBtn = new CuiButton() {
Button = {
Command = string.Empty,
Expand All @@ -2186,6 +2197,7 @@ private class ConfigData
Color = CuiDefaultColors.TextAlt.ToString()
}
};

private static readonly CuiButton CUserBtnPagePreviousInactiveBtn = new CuiButton() {
Button = {
Command = string.Empty,
Expand All @@ -2205,6 +2217,7 @@ private class ConfigData
Color = CuiDefaultColors.TextAlt.ToString()
}
};

private static readonly CuiButton CUserBtnPageNextInactiveBtn = new CuiButton() {
Button = {
Command = string.Empty,
Expand All @@ -2224,6 +2237,7 @@ private class ConfigData
Color = CuiDefaultColors.TextAlt.ToString()
}
};

private static readonly CuiInputField CBanByIdEdt = new CuiInputField()
{
InputField = {
Expand Down Expand Up @@ -2279,7 +2293,7 @@ void Loaded()
void Unload()
{
foreach (BasePlayer player in Player.Players) {
CuiHelper.DestroyUi(player, CMainPanelName);
CuiHelper.DestroyUi(player, CBasePanelName);

if (FMainPageBanIdInputText.ContainsKey(player.userID))
FMainPageBanIdInputText.Remove(player.userID);
Expand Down Expand Up @@ -2448,20 +2462,18 @@ protected override void LoadDefaultMessages()
private void PlayerAdministrationUICallback(BasePlayer aPlayer, string aCommand, string[] aArgs)
{
LogDebug("PlayerAdministrationUICallback was called");
CuiHelper.DestroyUi(aPlayer, CBasePanelName);

if (!VerifyPermission(ref aPlayer, string.Empty, true))
return;

LogInfo($"{aPlayer.displayName}: Opened the menu");
CuiHelper.AddUi(
aPlayer,
CuiHelper.ToJson(
new CuiElementContainer {
{ CBasePanel, Cui.ParentOverlay, CBasePanelName }
},
false
)
);
CuiHelper.AddUi(aPlayer, CuiHelper.ToJson(
new CuiElementContainer {
{ CBasePanel, Cui.ParentOverlay, CBasePanelName }
},
false
));
BuildUI(aPlayer, UiPage.Main);
}

Expand All @@ -2470,8 +2482,7 @@ private void PlayerAdministrationCloseUICallback(ConsoleSystem.Arg aArg)
{
LogDebug("PlayerAdministrationCloseUICallback was called");
BasePlayer player = aArg.Player();
// CuiHelper.DestroyUi(aArg.Player(), CMainPanelName);
CuiHelper.DestroyUi(aArg.Player(), CBasePanelName);
CuiHelper.DestroyUi(player, CBasePanelName);

if (FMainPageBanIdInputText.ContainsKey(player.userID))
FMainPageBanIdInputText.Remove(player.userID);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ The default messages are in the `PlayerAdministration.json` file under the `oxid
"Heal 100 Button Text": "Heal 100",
"Heal Wounds Button Text": "Heal Wounds"
}
```
```

0 comments on commit ee91368

Please sign in to comment.