diff --git a/Core/Loaders/UILoading/UILoader.cs b/Core/Loaders/UILoading/UILoader.cs
index 6e7ecd4..4863a74 100644
--- a/Core/Loaders/UILoading/UILoader.cs
+++ b/Core/Loaders/UILoading/UILoader.cs
@@ -1,7 +1,10 @@
-using System;
+using DragonLens.Core.Systems;
+using System;
using System.Collections.Generic;
using System.Linq;
+using Terraria.ID;
using Terraria.UI;
+using static ReLogic.Peripherals.RGB.Corsair.CorsairDeviceGroup;
namespace DragonLens.Core.Loaders.UILoading
{
@@ -62,14 +65,14 @@ public override void Unload()
/// Where this layer should be inserted
/// The logic dictating the visibility of this layer
/// The scale settings this layer should scale with
- public static void AddLayer(List layers, UIState state, int index, bool visible, InterfaceScaleType scale)
+ public static void AddLayer(List layers, UserInterface ui, int index, Func visible, InterfaceScaleType scale)
{
- string name = state == null ? "Unknown" : state.ToString();
+ string name = ui?.CurrentState?.ToString() ?? "Unknown";
layers.Insert(index, new LegacyGameInterfaceLayer("DragonLens: " + name,
delegate
{
- if (visible)
- state.Draw(Main.spriteBatch);
+ if (visible())
+ ui.Draw(Main.spriteBatch, Main._drawInterfaceGameTime);
return true;
}, scale));
@@ -86,8 +89,11 @@ public override void UpdateUI(GameTime gameTime)
foreach (UserInterface eachState in SortedUserInterfaces)
{
- if (eachState?.CurrentState != null && ((SmartUIState)eachState.CurrentState).Visible)
+ if (eachState?.CurrentState is SmartUIState s && s.Visible)
{
+ if (Main.netMode != NetmodeID.SinglePlayer && !PermissionHandler.CanUseTools(Main.LocalPlayer))
+ continue;
+
eachState.Update(gameTime);
if (eachState.LeftMouse.WasDown && eachState.LeftMouse.LastDown is not null && eachState.LeftMouse.LastDown is not UIState)
@@ -96,6 +102,7 @@ public override void UpdateUI(GameTime gameTime)
if (eachState.RightMouse.WasDown && eachState.RightMouse.LastDown is not null && eachState.RightMouse.LastDown is not UIState)
Main.mouseRight = false;
}
+
}
}
@@ -139,7 +146,13 @@ public override void ModifyInterfaceLayers(List layers)
SmartUIState state = inter.CurrentState as SmartUIState;
int index = state.InsertionIndex(layers);
- AddLayer(layers, state, index, state.Visible, state.Scale);
+ AddLayer(layers, inter, index, () =>
+ {
+ if (Main.dedServ || Main.netMode == NetmodeID.SinglePlayer)
+ return state.Visible;
+
+ return state.Visible && PermissionHandler.CanUseTools(Main.LocalPlayer);
+ }, state.Scale);
orderedInterfaces.Add(new Tuple(inter, index));
}
diff --git a/Core/Systems/PermissionHandler.cs b/Core/Systems/PermissionHandler.cs
index 693e767..7567021 100644
--- a/Core/Systems/PermissionHandler.cs
+++ b/Core/Systems/PermissionHandler.cs
@@ -77,16 +77,30 @@ public static bool LooksLikeAdmin(Player player)
/// The player to add. They must not already be an admin.
public static void AddAdmin(Player player)
{
- ModPacket packet = ModLoader.GetMod("DragonLens").GetPacket();
- packet.Write("AdminUpdate");
- packet.Write(0);
- packet.Write(player.whoAmI);
- packet.Send();
+ if (Main.netMode == NetmodeID.MultiplayerClient)
+ {
+ ModPacket packet = ModLoader.GetMod("DragonLens").GetPacket();
+ packet.Write("AdminUpdate");
+ packet.Write(0);
+ packet.Write(player.whoAmI);
+ packet.Send();
+ return;
+ }
if (Main.netMode == NetmodeID.Server)
{
- admins.Add(player.GetModPlayer().currentServerID);
- visualAdmins.Add(player.whoAmI);
+ string id = player.GetModPlayer().currentServerID;
+
+ if (!string.IsNullOrEmpty(id) && !admins.Contains(id))
+ admins.Add(id);
+
+ if (!visualAdmins.Contains(player.whoAmI))
+ visualAdmins.Add(player.whoAmI);
+
+ ModPacket packet = ModLoader.GetMod("DragonLens").GetPacket();
+ packet.Write("AdminUpdate");
+ packet.Write(0);
+ packet.Send(player.whoAmI);
SendVisualAdmins();
}
@@ -98,17 +112,30 @@ public static void AddAdmin(Player player)
/// The player to remove. They must be an admin.
public static void RemoveAdmin(Player player)
{
- ModPacket packet = ModLoader.GetMod("DragonLens").GetPacket();
- packet.Write("AdminUpdate");
- packet.Write(1);
- packet.Write(player.whoAmI);
- packet.Send();
+ if (Main.netMode == NetmodeID.MultiplayerClient)
+ {
+ ModPacket packet = ModLoader.GetMod("DragonLens").GetPacket();
+ packet.Write("AdminUpdate");
+ packet.Write(1);
+ packet.Write(player.whoAmI);
+ packet.Send();
+ return;
+ }
if (Main.netMode == NetmodeID.Server)
{
- admins.Remove(player.GetModPlayer().currentServerID);
+ string id = player.GetModPlayer().currentServerID;
+
+ if (!string.IsNullOrEmpty(id))
+ admins.RemoveAll(n => n == id);
+
visualAdmins.Remove(player.whoAmI);
+ ModPacket packet = ModLoader.GetMod("DragonLens").GetPacket();
+ packet.Write("AdminUpdate");
+ packet.Write(1);
+ packet.Send(player.whoAmI);
+
SendVisualAdmins();
}
}
diff --git a/build.txt b/build.txt
index 17fcf77..2926072 100644
--- a/build.txt
+++ b/build.txt
@@ -1,4 +1,4 @@
displayName = DragonLens
author = ScalarVector & Tomat & HeartPlusUp & QuestionMark
-version = 1.11.1
+version = 2.0
dllReferences = StructureHelper
\ No newline at end of file