Skip to content

Commit 27a8ca2

Browse files
authored
Merge pull request #913 from PlayEveryWare/feature/configurable-overlay-key
feat(config): Customizable Overlay Config Button Combination
2 parents 94f3c1a + cf7db13 commit 27a8ca2

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

Assets/Plugins/Source/Editor/EditorWindows/EOSSettingsWindow.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
namespace PlayEveryWare.EpicOnlineServices.Editor.Windows
2626
{
27+
using Epic.OnlineServices.UI;
28+
using PlayEveryWare.EpicOnlineServices.Extensions;
29+
using PlayEveryWare.EpicOnlineServices.Utility;
2730
using System;
2831
using System.Collections.Generic;
2932
using System.IO;
@@ -347,6 +350,14 @@ private void OnDefaultGUI()
347350
GUIEditorUtility.AssigningBoolField("Always send Input to Overlay",
348351
ref mainEOSConfigFile.alwaysSendInputToOverlay, 190,
349352
"If true, the plugin will always send input to the overlay from the C# side to native, and handle showing the overlay. This doesn't always mean input makes it to the EOS SDK.");
353+
354+
InputStateButtonFlags toggleFriendsButtonCombinationEnum = mainEOSConfigFile.GetToggleFriendsButtonCombinationFlags();
355+
GUIEditorUtility.AssigningEnumField<InputStateButtonFlags>("Default Activate Overlay Button",
356+
ref toggleFriendsButtonCombinationEnum, 190,
357+
"Users can press the button(s) associated with this value to activate the Epic Social Overlay. Not all combinations are valid; the SDK will log an error at the start of runtime if an invalid combination is selected.");
358+
mainEOSConfigFile.toggleFriendsButtonCombination = EnumUtility<InputStateButtonFlags>.GetEnumerator(toggleFriendsButtonCombinationEnum)
359+
.Select(enumValue => enumValue.ToString())
360+
.ToList();
350361
}
351362

352363
protected override void RenderWindow()

Assets/Plugins/Source/Editor/Utility/GUIEditorUtility.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ public static void AssigningFloatToStringField(string label, ref string value, f
198198
EditorGUIUtility.labelWidth = originalLabelWidth;
199199
}
200200

201+
public static void AssigningEnumField<T>(string label, ref T value, float labelWidth = -1, string tooltip = null) where T : Enum
202+
{
203+
float originalLabelWidth = EditorGUIUtility.labelWidth;
204+
if (labelWidth >= 0)
205+
{
206+
EditorGUIUtility.labelWidth = labelWidth;
207+
}
208+
209+
var newValue = (T)EditorGUILayout.EnumFlagsField(CreateGUIContent(label, tooltip), value, GUILayout.ExpandWidth(true));
210+
value = newValue;
211+
212+
EditorGUIUtility.labelWidth = originalLabelWidth;
213+
}
214+
201215
#region New methods for rendering input fields
202216

203217
private delegate T InputRenderDelegate<T>(string label, T value, float labelWidth, string tooltip);

com.playeveryware.eos/Runtime/Core/Config/EOSConfig.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace PlayEveryWare.EpicOnlineServices
3535
using UnityEngine;
3636
using System.Text.RegularExpressions;
3737
using Extensions;
38+
using Epic.OnlineServices.UI;
39+
using PlayEveryWare.EpicOnlineServices.Utility;
3840

3941
/// <summary>
4042
/// Represents the default deployment ID to use when a given sandbox ID is
@@ -335,6 +337,15 @@ protected EOSConfig() : base("EpicOnlineServicesConfig.json")
335337
"to the SDK.", 4)]
336338
public bool hackForceSendInputDirectlyToSDK;
337339

340+
/// <summary>
341+
/// When this combination of buttons is pressed on a controller, the
342+
/// social overlay will toggle on.
343+
/// Default to <see cref="InputStateButtonFlags.SpecialLeft"/>, and will
344+
/// use that value if this configuration field is null, empty, or contains
345+
/// only <see cref="InputStateButtonFlags.None"/>.
346+
/// </summary>
347+
public List<string> toggleFriendsButtonCombination = new List<string>() { InputStateButtonFlags.SpecialLeft.ToString() };
348+
338349
#endregion
339350

340351
public static Regex InvalidEncryptionKeyRegex;
@@ -441,6 +452,19 @@ public AuthScopeFlags GetAuthScopeFlags()
441452
AuthScopeFlagsExtensions.TryParse);
442453
}
443454

455+
/// <summary>
456+
/// Returns a single InputStateButtonFlags enum value that results from a
457+
/// bitwise OR operation of all the <seealso cref="toggleFriendsButtonCombination"/> flags on this
458+
/// config.
459+
/// </summary>
460+
/// <returns>An InputStateButtonFlags enum value.</returns>
461+
public InputStateButtonFlags GetToggleFriendsButtonCombinationFlags()
462+
{
463+
return StringsToEnum<InputStateButtonFlags>(
464+
toggleFriendsButtonCombination,
465+
(IList<string> stringFlags, out InputStateButtonFlags result) => EnumUtility<InputStateButtonFlags>.TryParse(stringFlags, null, out result));
466+
}
467+
444468
/// <summary>
445469
/// Given a reference to an InitializeThreadAffinity struct, set the
446470
/// member fields contained within to match the values of this config.

com.playeveryware.eos/Runtime/Core/EOSManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,12 @@ private PlatformInterface CreatePlatformInterface()
533533
//-------------------------------------------------------------------------
534534
private void InitializeOverlay(IEOSCoroutineOwner coroutineOwner)
535535
{
536+
EOSConfig configData = Config.Get<EOSConfig>();
537+
536538
// Sets the button for the bringing up the overlay
537539
var friendToggle = new SetToggleFriendsButtonOptions
538540
{
539-
ButtonCombination = InputStateButtonFlags.SpecialLeft
541+
ButtonCombination = configData.GetToggleFriendsButtonCombinationFlags()
540542
};
541543
UIInterface uiInterface = Instance.GetEOSPlatformInterface().GetUIInterface();
542544
uiInterface.SetToggleFriendsButton(ref friendToggle);

0 commit comments

Comments
 (0)