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 15 commits into
base: master
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions NitroxClient/Debuggers/Drawer/NitroxGUILayout.cs
Original file line number Diff line number Diff line change
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
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
7 changes: 4 additions & 3 deletions NitroxClient/MonoBehaviours/Discord/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using DiscordGameSDKWrapper;
using NitroxClient.Communication.Abstract;
using NitroxClient.MonoBehaviours.Gui.MainMenu;
using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList;
using NitroxModel;
using NitroxModel.Core;
using NitroxModel.Packets;
Expand Down Expand Up @@ -99,7 +99,7 @@ private void ActivityJoin(string secret)
{
Log.Info("[Discord] Joining Server");

if (SceneManager.GetActiveScene().name != "StartScreen" || !MainMenuMultiplayerPanel.Main)
if (SceneManager.GetActiveScene().name != "StartScreen" || !MainMenuServerListPanel.Main)
{
Log.InGame(Language.main.Get("Nitrox_DiscordMultiplayerMenu"));
Log.Warn("[Discord] Can't join a server outside of the main-menu.");
Expand All @@ -109,7 +109,8 @@ private void ActivityJoin(string secret)
string[] splitSecret = secret.Split(':');
string ip = string.Join(":", splitSecret.Take(splitSecret.Length - 1));
string port = splitSecret.Last();
MainMenuMultiplayerPanel.OpenJoinServerMenuAsync(ip, port).ContinueWithHandleError();
int portInt = int.Parse(port);
MainMenuServerButton.OpenJoinServerMenuAsync(ip, portInt).ContinueWithHandleError();
}

private void ActivityJoinRequest(ref User user)
Expand Down
Loading