Skip to content

Commit 445e11b

Browse files
committed
feat: PR Feedback wrt to Custom Mappings
1 parent 5e48919 commit 445e11b

File tree

4 files changed

+6
-81
lines changed

4 files changed

+6
-81
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace PlayEveryWare.EpicOnlineServices.Editor.Windows
2626
{
2727
using Epic.OnlineServices.UI;
2828
using PlayEveryWare.EpicOnlineServices.Extensions;
29+
using PlayEveryWare.EpicOnlineServices.Utility;
2930
using System;
3031
using System.Collections.Generic;
3132
using System.IO;
@@ -354,7 +355,9 @@ private void OnDefaultGUI()
354355
GUIEditorUtility.AssigningEnumField<InputStateButtonFlags>("Default Activate Overlay Button",
355356
ref toggleFriendsButtonCombinationEnum, 190,
356357
"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();
358+
mainEOSConfigFile.toggleFriendsButtonCombination = EnumUtility<InputStateButtonFlags>.GetEnumerator(toggleFriendsButtonCombinationEnum)
359+
.Select(enumValue => enumValue.ToString())
360+
.ToList();
358361
}
359362

360363
protected override void RenderWindow()

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,6 @@ public static bool RenderInputField(ConfigFieldAttribute configFieldDetails, boo
388388
});
389389
}
390390

391-
public static T RenderInputField<T>(ConfigFieldAttribute configFieldDetails, T value, float labelWidth, string tooltip = null) where T : Enum
392-
{
393-
return InputRendererWrapper<T>(configFieldDetails.Label, value, labelWidth, tooltip, (s, b, arg3, arg4) =>
394-
{
395-
return (T)EditorGUILayout.EnumFlagsField(CreateGUIContent(configFieldDetails.Label, tooltip), value, GUILayout.ExpandWidth(true));
396-
});
397-
}
398-
399391
private static T InputRendererWrapper<T>(string label, T value, float labelWidth, string toolTip, InputRenderDelegate<T> renderFn)
400392
{
401393
// Store the current label width so that it can be subsequently be restored.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public AuthScopeFlags GetAuthScopeFlags()
446446

447447
/// <summary>
448448
/// Returns a single InputStateButtonFlags enum value that results from a
449-
/// bitwise OR operation of all the defaultActivateOverlayButtonCombination flags on this
449+
/// bitwise OR operation of all the <seealso cref="toggleFriendsButtonCombination"/> flags on this
450450
/// config.
451451
/// </summary>
452452
/// <returns>An InputStateButtonFlags enum value.</returns>

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

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,6 @@ namespace PlayEveryWare.EpicOnlineServices.Extensions
3535
/// </summary>
3636
public static class InputStateButtonFlagsExtensions
3737
{
38-
/// <summary>
39-
/// Returns the internal custom mappings.
40-
/// </summary>
41-
public static Dictionary<string, InputStateButtonFlags> CustomMappings { get; } = new()
42-
{
43-
{ "DPadDown", InputStateButtonFlags.DPadDown },
44-
{ "DPadLeft", InputStateButtonFlags.DPadLeft },
45-
{ "DPadRight", InputStateButtonFlags.DPadRight },
46-
{ "DPadUp", InputStateButtonFlags.DPadUp },
47-
{ "FaceButtonBottom", InputStateButtonFlags.FaceButtonBottom },
48-
{ "FaceButtonLeft", InputStateButtonFlags.FaceButtonLeft },
49-
{ "FaceButtonRight", InputStateButtonFlags.FaceButtonRight },
50-
{ "FaceButtonTop", InputStateButtonFlags.FaceButtonTop },
51-
{ "LeftShoulder", InputStateButtonFlags.LeftShoulder },
52-
{ "LeftThumbstick", InputStateButtonFlags.LeftThumbstick },
53-
{ "LeftTrigger", InputStateButtonFlags.LeftTrigger },
54-
{ "RightShoulder", InputStateButtonFlags.RightShoulder },
55-
{ "RightThumbstick", InputStateButtonFlags.RightThumbstick },
56-
{ "RightTrigger", InputStateButtonFlags.RightTrigger },
57-
{ "SpecialLeft", InputStateButtonFlags.SpecialLeft },
58-
{ "SpecialRight", InputStateButtonFlags.SpecialRight }
59-
};
60-
6138
/// <summary>
6239
/// Tries to parse the given list of strings representing individual
6340
/// InputStateButtonFlags enum values, and performing a
@@ -76,54 +53,7 @@ public static class InputStateButtonFlagsExtensions
7653
/// </returns>
7754
public static bool TryParse(IList<string> stringFlags, out InputStateButtonFlags result)
7855
{
79-
return EnumUtility<InputStateButtonFlags>.TryParse(stringFlags, CustomMappings, out result);
80-
}
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;
56+
return EnumUtility<InputStateButtonFlags>.TryParse(stringFlags, null, out result);
12757
}
12858
}
12959
}

0 commit comments

Comments
 (0)