Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions Core/Loaders/UILoading/UILoader.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -62,14 +65,14 @@ public override void Unload()
/// <param name="index">Where this layer should be inserted</param>
/// <param name="visible">The logic dictating the visibility of this layer</param>
/// <param name="scale">The scale settings this layer should scale with</param>
public static void AddLayer(List<GameInterfaceLayer> layers, UIState state, int index, bool visible, InterfaceScaleType scale)
public static void AddLayer(List<GameInterfaceLayer> layers, UserInterface ui, int index, Func<bool> 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));
Expand All @@ -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)
Expand All @@ -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;
}

}
}

Expand Down Expand Up @@ -139,7 +146,13 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> 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<UserInterface, int>(inter, index));
}

Expand Down
53 changes: 40 additions & 13 deletions Core/Systems/PermissionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,30 @@ public static bool LooksLikeAdmin(Player player)
/// <param name="player">The player to add. They must not already be an admin.</param>
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<PermissionPlayer>().currentServerID);
visualAdmins.Add(player.whoAmI);
string id = player.GetModPlayer<PermissionPlayer>().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();
}
Expand All @@ -98,17 +112,30 @@ public static void AddAdmin(Player player)
/// <param name="player">The player to remove. They must be an admin.</param>
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<PermissionPlayer>().currentServerID);
string id = player.GetModPlayer<PermissionPlayer>().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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
displayName = DragonLens
author = ScalarVector & Tomat & HeartPlusUp & QuestionMark
version = 1.11.1
version = 2.0
dllReferences = StructureHelper
Loading