Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MainMenu Controller support #2055

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
822e4d0
Handle uncatched MainMenu errors from Sn Update
Jannify Sep 28, 2023
a29f63f
Add controller support for server list
Jannify Jun 24, 2023
90c4117
Revamped AddServer window to SN style and UI based
Jannify Jun 24, 2023
77fa57e
Renaming few MainMenu files to reflect behavior/SN naming conventions
Jannify Jun 24, 2023
dfaddb0
Start SN through steam instead of direct start
Jannify Feb 10, 2024
bd9bc17
Fix Selectable drawer NRE
Jannify Mar 14, 2024
665f916
Add controller support for join server input and refactor whole process
Jannify Mar 14, 2024
a64c5c6
Add basic Array and List entry in Debugger
Jannify Mar 15, 2024
acf6080
Fixed bugs where not all click events where removed
Jannify Mar 15, 2024
e685091
Add invalidation to NitroxServiceLocator.Cache when EndCurrentLifetim…
Jannify Mar 15, 2024
1947e80
Add new UI and controller support for server password input
Jannify Mar 15, 2024
52baf1b
Refactor JoinServerBackend
Jannify Mar 15, 2024
488f0bc
Investigating WIP on controllerSupport
Jannify Apr 5, 2024
c760f4c
Add drawer for EvenTrigger component
Jannify Oct 29, 2024
7c2448c
Fix scrolling in server list
Jannify Oct 29, 2024
f90d74e
Improve string building for name/ip/port on server list button
Jannify Oct 29, 2024
8e57165
Add translation string in loading panel
Jannify Oct 30, 2024
5cefed3
Added <Tab<, <Shift+Tab> and <Enter> support in server create view
Jannify Oct 30, 2024
5627dfe
Implement jumping to new server entry after creating
Jannify Oct 30, 2024
ae2f8f1
Center notification text
Jannify Nov 6, 2024
da79400
Add spacing between server list entries
Jannify Nov 6, 2024
69cd453
Add request delete screen for server entries
Jannify Nov 8, 2024
0539643
Register missed Image drawers and enhanced UnityEventDrawer
Jannify Nov 8, 2024
d62f20d
Fix delete button not being red
Jannify Nov 15, 2024
fff0ead
Fix button text staying black
Jannify Nov 15, 2024
c25991d
Increase text size for creating server entry
Jannify Nov 16, 2024
52d7ec2
Add color preview in colorPicker
Jannify Nov 16, 2024
3b8d88b
Adjust player name input field font size with length
Jannify Nov 17, 2024
b064f26
Fixing minor things
Jannify Dec 9, 2024
8b2f1dc
Fixed LAN server discovery crash when having server select menu open
Measurity Dec 13, 2024
e134821
Remove path argument from Load/Save of ServerList to prevent unsynchr…
Jannify Dec 15, 2024
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
1 change: 1 addition & 0 deletions Nitrox.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002EMemberReordering_002EMigrations_002ECSharpFileLayoutPatternRemoveIsAttributeUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
31 changes: 19 additions & 12 deletions NitroxClient/Communication/LANBroadcastClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,37 @@ namespace NitroxClient.Communication;
public static class LANBroadcastClient
{
private static event Action<IPEndPoint> serverFound;

public static event Action<IPEndPoint> ServerFound
{
add
{
serverFound += value;

// Trigger event for servers already found.
foreach (IPEndPoint server in discoveredServers)
foreach (IPEndPoint server in DiscoveredServers)
{
value?.Invoke(server);
}
}
remove => serverFound -= value;
}

private static Task<IEnumerable<IPEndPoint>> lastTask;
private static ConcurrentBag<IPEndPoint> discoveredServers = new();
public static ConcurrentQueue<IPEndPoint> DiscoveredServers = [];

public static async Task<IEnumerable<IPEndPoint>> SearchAsync(bool force = false, CancellationToken cancellationToken = default)
{
if (!force && lastTask != null)
{
return await lastTask;
DiscoveredServers = [];
foreach (IPEndPoint ipEndPoint in await lastTask)
{
DiscoveredServers.Enqueue(ipEndPoint);
}
return DiscoveredServers;
}

discoveredServers = new ConcurrentBag<IPEndPoint>();
return await (lastTask = SearchInternalAsync(cancellationToken));
}

Expand All @@ -57,20 +63,21 @@ static void ReceivedResponse(IPEndPoint remoteEndPoint, NetPacketReader reader,
}
int serverPort = reader.GetInt();
IPEndPoint serverEndPoint = new(remoteEndPoint.Address, serverPort);
if (discoveredServers.Contains(serverEndPoint))
if (DiscoveredServers.Contains(serverEndPoint))
{
return;
}
Log.Info($"Found LAN server at {serverEndPoint}.");
discoveredServers.Add(serverEndPoint);

Log.Debug($"Found LAN server at {serverEndPoint}.");
DiscoveredServers.Enqueue(serverEndPoint);
OnServerFound(serverEndPoint);
}

cancellationToken = cancellationToken == default ? new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token : cancellationToken;
EventBasedNetListener listener = new();
NetManager client = new(listener) {
AutoRecycle = true,
NetManager client = new(listener)
{
AutoRecycle = true,
BroadcastReceiveEnabled = true,
UnconnectedMessagesEnabled = true
};
Expand All @@ -85,7 +92,7 @@ static void ReceivedResponse(IPEndPoint remoteEndPoint, NetPacketReader reader,
if (!client.IsRunning)
{
Log.Warn("Failed to start LAN discover client: none of the defined ports are available");
return Enumerable.Empty<IPEndPoint>();
return [];
}

Log.Info("Searching for LAN servers...");
Expand Down Expand Up @@ -131,7 +138,7 @@ static void ReceivedResponse(IPEndPoint remoteEndPoint, NetPacketReader reader,
listener.ClearNetworkReceiveUnconnectedEvent();
client.Stop();
listener.NetworkReceiveUnconnectedEvent -= ReceivedResponse;
return discoveredServers;
return DiscoveredServers;
}

private static void OnServerFound(IPEndPoint obj)
Expand Down
5 changes: 5 additions & 0 deletions NitroxClient/Debuggers/Drawer/DrawerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using NitroxModel.Helper;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace NitroxClient.Debuggers.Drawer;
Expand All @@ -34,6 +35,7 @@ public DrawerManager(SceneDebugger sceneDebugger)
RectDrawer rectDrawer = new();
LayoutGroupDrawer layoutGroupDrawer = new(rectDrawer);
MaterialDrawer materialDrawer = new();
ImageDrawer imageDrawer = new(colorDrawer, materialDrawer, rectDrawer);
NitroxEntityDrawer nitroxEntityDrawer = new();

AddDrawer<NitroxEntityDrawer, NitroxEntity>(nitroxEntityDrawer);
Expand All @@ -47,9 +49,12 @@ public DrawerManager(SceneDebugger sceneDebugger)
AddDrawer<CanvasScalerDrawer, CanvasScaler>(new(vectorDrawer));
AddDrawer<ContentSizeFitterDrawer, ContentSizeFitter>();
AddDrawer<DropdownDrawer, Dropdown>(new(sceneDebugger, selectableDrawer));
AddDrawer<EventTriggerDrawer, EventTrigger>(new(sceneDebugger));
AddDrawer<GraphicRaycasterDrawer, GraphicRaycaster>();
AddDrawer<GridLayoutGroupDrawer, GridLayoutGroup>(new(vectorDrawer, rectDrawer));
AddDrawer<LayoutGroupDrawer, HorizontalLayoutGroup>(layoutGroupDrawer);
AddDrawer<ImageDrawer, Image>(imageDrawer);
AddDrawer<ImageDrawer, RawImage>(imageDrawer);
AddDrawer<LayoutGroupDrawer, VerticalLayoutGroup>(layoutGroupDrawer);
AddDrawer<MaskDrawer, Mask>();
AddDrawer<RectTransformDrawer, RectTransform>(new(vectorDrawer));
Expand Down
10 changes: 5 additions & 5 deletions NitroxClient/Debuggers/Drawer/NitroxGUILayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class NitroxGUILayout

public static void Separator()
{
GUILayout.Box(GUIContent.none, separatorStyle, GUILayout.Height(1));
GUILayout.Box(GUIContent.none, separatorStyle, GUILayout.Height(5));
}

public static int IntField(int value, float valueWidth = VALUE_WIDTH) => ConvertibleField(value, valueWidth).ToInt32(CultureInfo.CurrentCulture);
Expand Down Expand Up @@ -154,7 +154,7 @@ public static float SliderField(float value, float minValue, float maxValue, flo
/// <returns>The newly selected enum value.</returns>
public static Enum EnumPopup(Enum selected, float buttonWidth = VALUE_WIDTH)
{
return EnumPopupInternal(selected, buttonWidth);
return EnumPopupInternal(selected, buttonWidth);
}

public static T EnumPopup<T>(T selected, float buttonWidth = VALUE_WIDTH) where T : Enum
Expand Down Expand Up @@ -183,7 +183,7 @@ bool IsFlagSet<T>(T value, T flag)
return (lValue & lFlag) != 0;
};

T SetFlags<T>(T value, T flags, bool toggle)
object SetFlags(Type type, object value, object flags, bool toggle)
{
long lValue = Convert.ToInt64(value);
long lFlag = Convert.ToInt64(flags);
Expand All @@ -201,7 +201,7 @@ T SetFlags<T>(T value, T flags, bool toggle)
lValue = 0;
}

return (T)Enum.ToObject(typeof(T), lValue);
return Enum.ToObject(type, lValue);
};

Enum[] enumValues = Enum.GetValues(enumType).Cast<Enum>().ToArray();
Expand All @@ -215,7 +215,7 @@ T SetFlags<T>(T value, T flags, bool toggle)

bool isFlagSet = IsFlagSet(selected, enumValue);

selected = SetFlags(selected, enumValue, GUILayout.Toggle(isFlagSet, enumName, "Button", GUILayout.Width(buttonWidth)));
selected = (Enum) SetFlags(enumType, selected, enumValue, GUILayout.Toggle(isFlagSet, enumName, "Button", GUILayout.Width(buttonWidth)));
}
}

Expand Down
6 changes: 5 additions & 1 deletion NitroxClient/Debuggers/Drawer/Unity/UnityEventDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ private static void DrawUnityEventBase(UnityEventBase unityEventBase)
using (new GUILayout.HorizontalScope())
{
NitroxGUILayout.Separator();
GUILayout.Label(unityEventBase.GetPersistentMethodName(index), NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
Object target = unityEventBase.GetPersistentTarget(index);
if(target)
GUILayout.Label($"{target.GetType().Name}.{unityEventBase.GetPersistentMethodName(index)}()", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
else
GUILayout.Label($"{unityEventBase.GetPersistentMethodName(index)}()", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions NitroxClient/Debuggers/Drawer/UnityUI/EventTriggerDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Linq;
using NitroxModel.Helper;
using UnityEngine;
using UnityEngine.EventSystems;

namespace NitroxClient.Debuggers.Drawer.UnityUI;

public class EventTriggerDrawer : IDrawer<EventTrigger>
{
private readonly SceneDebugger sceneDebugger;

public EventTriggerDrawer(SceneDebugger sceneDebugger)
{
Validate.NotNull(sceneDebugger);

this.sceneDebugger = sceneDebugger;
}

public void Draw(EventTrigger eventTrigger)
{
foreach (EventTrigger.Entry entry in eventTrigger.triggers.OrderBy(x => x.eventID))
{
using (new GUILayout.VerticalScope("box"))
{
GUILayout.Label($"EventTriggerType.{Enum.GetName(typeof(EventTriggerType), entry.eventID)}");

for (int i = 0; i < entry.callback.GetPersistentEventCount(); i++)
{
using (new GUILayout.HorizontalScope())
{
object target = entry.callback.GetPersistentTarget(i);

switch (target)
{
case Component component:
if (GUILayout.Button($"Jump to {component.name}", GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)))
{
sceneDebugger.JumpToComponent(component);
}
NitroxGUILayout.Separator();
GUILayout.TextField($"{component.GetType().Name}.{entry.callback.GetPersistentMethodName(i)}()", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(250));
break;
default:
GUILayout.TextField($"[{target.GetType().Name}]: {target}", GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
GUILayout.TextField($"{entry.callback.GetPersistentMethodName(i)}()", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(250));
break;
}
}
NitroxGUILayout.Separator();
}
}
NitroxGUILayout.Separator();
}
}
}
36 changes: 32 additions & 4 deletions NitroxClient/Debuggers/Drawer/UnityUI/SelectableDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,56 @@ private void DrawTransitionSpriteSwap(Selectable selectable)
{
GUILayout.Label("Highlighted Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
ImageDrawer.DrawTexture(selectable.spriteState.highlightedSprite.texture);
if (selectable.spriteState.highlightedSprite)
{
ImageDrawer.DrawTexture(selectable.spriteState.highlightedSprite.texture);
}
else
{
GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
}
}

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Pressed Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
ImageDrawer.DrawTexture(selectable.spriteState.pressedSprite.texture);
if (selectable.spriteState.pressedSprite)
{
ImageDrawer.DrawTexture(selectable.spriteState.pressedSprite.texture);
}
else
{
GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
}
}

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Selected Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
ImageDrawer.DrawTexture(selectable.spriteState.selectedSprite.texture);
if (selectable.spriteState.selectedSprite)
{
ImageDrawer.DrawTexture(selectable.spriteState.selectedSprite.texture);
}
else
{
GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
}
}

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Disabled Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
ImageDrawer.DrawTexture(selectable.spriteState.disabledSprite.texture);
if (selectable.spriteState.disabledSprite)
{
ImageDrawer.DrawTexture(selectable.spriteState.disabledSprite.texture);
}
else
{
GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions NitroxClient/Debuggers/SceneDebugger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down Expand Up @@ -304,6 +305,16 @@ private void DrawFields(UnityEngine.Object target)
JumpToComponent(component);
}
}
else if(fieldValue != null && (field.FieldType.IsArray || typeof(IList).IsAssignableFrom(field.FieldType)))
{
IList list = (IList)field.GetValue(target);
GUILayout.Box($"Length: {list.Count}" , GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
}
else if(fieldValue != null && (typeof(IDictionary).IsAssignableFrom(field.FieldType)))
{
IDictionary dict = (IDictionary)field.GetValue(target);
GUILayout.Box($"Length: {dict.Count}" , GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
}
else if (drawerManager.TryDrawEditor(fieldValue, out object editedValue))
{
field.SetValue(target, editedValue);
Expand Down
8 changes: 4 additions & 4 deletions NitroxClient/GameLogic/HUD/PdaTabs/uGUI_PlayerPingEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ public void UpdateButtonsPosition()

private void ClearButtonListeners()
{
GetToggle(MuteObject).onValueChanged.RemoveAllListeners();
GetToggle(KickObject).onValueChanged.RemoveAllListeners();
GetToggle(TeleportToObject).onValueChanged.RemoveAllListeners();
GetToggle(TeleportToMeObject).onValueChanged.RemoveAllListeners();
GetToggle(MuteObject).onValueChanged = new Toggle.ToggleEvent();
GetToggle(KickObject).onValueChanged = new Toggle.ToggleEvent();
GetToggle(TeleportToObject).onValueChanged = new Toggle.ToggleEvent();
GetToggle(TeleportToMeObject).onValueChanged = new Toggle.ToggleEvent();
}

private IEnumerator AssignSprites()
Expand Down
8 changes: 4 additions & 4 deletions NitroxClient/GameLogic/Settings/NitroxSettingsManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using NitroxClient.GameLogic.Bases;
using NitroxClient.MonoBehaviours.Gui.MainMenu;
using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList;
using UnityEngine.Events;

namespace NitroxClient.GameLogic.Settings;
Expand All @@ -21,9 +21,9 @@ public NitroxSettingsManager()

/// <summary>
/// Allows to create new settings
///
///
/// Available types : TOGGLE, SLIDER, LIST, BUTTON
///
///
/// <example>
/// <para>Examples :</para>
/// <code>
Expand All @@ -38,7 +38,7 @@ private void MakeSettings()
AddSetting("Nitrox_StreamerSettings", new Setting("Nitrox_HideIp", NitroxPrefs.HideIp, hide =>
{
NitroxPrefs.HideIp.Value = hide;
MainMenuMultiplayerPanel.Main.RefreshServerEntries();
MainMenuServerListPanel.Main.RefreshServerEntries();
}));

AddSetting("Nitrox_ResyncSettings", new Setting("Nitrox_ResyncBuildings", () =>
Expand Down
Loading