Skip to content

Commit 5e48919

Browse files
committed
feat: Use Enum flag field for editor window
1 parent 403926d commit 5e48919

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace PlayEveryWare.EpicOnlineServices.Editor.Windows
2626
{
2727
using Epic.OnlineServices.UI;
28+
using PlayEveryWare.EpicOnlineServices.Extensions;
2829
using System;
2930
using System.Collections.Generic;
3031
using System.IO;
@@ -349,9 +350,11 @@ private void OnDefaultGUI()
349350
ref mainEOSConfigFile.alwaysSendInputToOverlay, 190,
350351
"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.");
351352

352-
GUIEditorUtility.AssigningFlagTextField("Default Activate Overlay Button",
353-
ref mainEOSConfigFile.toggleFriendsButtonCombination, 190,
353+
InputStateButtonFlags toggleFriendsButtonCombinationEnum = mainEOSConfigFile.GetToggleFriendsButtonCombinationFlags();
354+
GUIEditorUtility.AssigningEnumField<InputStateButtonFlags>("Default Activate Overlay Button",
355+
ref toggleFriendsButtonCombinationEnum, 190,
354356
"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.");
357+
mainEOSConfigFile.toggleFriendsButtonCombination = toggleFriendsButtonCombinationEnum.FlagsToStrings();
355358
}
356359

357360
protected override void RenderWindow()

com.playeveryware.eos/Runtime/Core/EOS_SDK_Additions/Extensions/InputStateButtonFlagsExtensions.cs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
namespace PlayEveryWare.EpicOnlineServices.Extensions
2626
{
27-
using Epic.OnlineServices.Auth;
2827
using Utility;
2928
using System;
3029
using System.Collections.Generic;
@@ -61,11 +60,11 @@ public static class InputStateButtonFlagsExtensions
6160

6261
/// <summary>
6362
/// Tries to parse the given list of strings representing individual
64-
/// AuthScopeFlags enum values, and performing a
63+
/// InputStateButtonFlags enum values, and performing a
6564
/// bitwise OR operation on those values.
6665
/// </summary>
6766
/// <param name="stringFlags">
68-
/// List of strings representing individual AuthScopeFlags enum values.
67+
/// List of strings representing individual InputStateButtonFlags enum values.
6968
/// </param>
7069
/// <param name="result">
7170
/// The result of performing a bitwise OR operation on the values that
@@ -79,6 +78,53 @@ public static bool TryParse(IList<string> stringFlags, out InputStateButtonFlags
7978
{
8079
return EnumUtility<InputStateButtonFlags>.TryParse(stringFlags, CustomMappings, out result);
8180
}
81+
82+
/// <summary>
83+
/// Parses an InputStateButtonFlags value in to its component strings.
84+
/// These strings can then be safely stored in a configuration value.
85+
/// </summary>
86+
/// <param name="flags">Enum to separate into parts.</param>
87+
/// <returns>A list of strings representing these flags.</returns>
88+
public static List<string> FlagsToStrings(this InputStateButtonFlags flags)
89+
{
90+
List<string> flagStrings = new List<string>();
91+
92+
// Iterate over all possible flag values
93+
foreach (InputStateButtonFlags flagOption in Enum.GetValues(typeof(InputStateButtonFlags)))
94+
{
95+
// If the passed in Enum doesn't have this flag, skip it
96+
if (!flags.HasFlag(flagOption))
97+
{
98+
continue;
99+
}
100+
101+
// Look up this flag's name in the custom mappings dictionary
102+
// The dictionary is keyed by string value and valued by enum,
103+
// so it must be entirely traversed to find its matching string
104+
bool foundMapping = false;
105+
foreach (KeyValuePair<string, InputStateButtonFlags> mapping in CustomMappings)
106+
{
107+
// Continue if this isn't the flag that matches the current option
108+
if (mapping.Value != flagOption)
109+
{
110+
continue;
111+
}
112+
113+
// This is the value needed, so use it
114+
flagStrings.Add(mapping.Key);
115+
foundMapping = true;
116+
continue;
117+
}
118+
119+
// If no custom mapping was found, use ToString instead
120+
if (!foundMapping)
121+
{
122+
flagStrings.Add(flagOption.ToString());
123+
}
124+
}
125+
126+
return flagStrings;
127+
}
82128
}
83129
}
84130

0 commit comments

Comments
 (0)