Skip to content

Commit a802960

Browse files
authored
Merge branch 'development' into feat/more-unit-tests
2 parents 487ac8d + c0be867 commit a802960

File tree

8 files changed

+217
-124
lines changed

8 files changed

+217
-124
lines changed

Assets/Plugins/Source/Editor/ConfigEditors/ConfigEditor.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace PlayEveryWare.EpicOnlineServices.Editor
3232
using UnityEngine.Events;
3333
using Utility;
3434
using Task = System.Threading.Tasks.Task;
35-
using Config = EpicOnlineServices.Config;
36-
3735

3836
/// <summary>
3937
/// Contains implementations of IConfigEditor that are common to all
@@ -51,6 +49,11 @@ public class ConfigEditor<T> : IConfigEditor where T :
5149
/// </summary>
5250
protected string _labelText;
5351

52+
/// <summary>
53+
/// The labels for each group.
54+
/// </summary>
55+
protected string[] _groupLabels;
56+
5457
/// <summary>
5558
/// Event that triggers when the config editor is expanded.
5659
/// </summary>
@@ -103,6 +106,7 @@ public ConfigEditor(
103106
{
104107
_collapsible = attribute.Collapsible;
105108
_labelText = attribute.Label;
109+
_groupLabels = attribute.GroupLabels;
106110
}
107111

108112
_animExpanded = new(_collapsible);
@@ -124,7 +128,7 @@ public ConfigEditor(
124128
/// </summary>
125129
public void Expand()
126130
{
127-
// Don't do anything if already expanded, or if cannot expand
131+
// Don't do anything if already expanded, or cannot expand
128132
if (_expanded || !_collapsible)
129133
{
130134
return;
@@ -162,13 +166,11 @@ protected virtual void OnExpanded(EventArgs e)
162166
/// <returns>A collection of config fields.</returns>
163167
private static IOrderedEnumerable<IGrouping<int, (FieldInfo FieldInfo, ConfigFieldAttribute FieldDetails)>> GetFieldsByGroup()
164168
{
165-
var returnValue = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Instance)
169+
return typeof(T).GetFields(BindingFlags.Public | BindingFlags.Instance)
166170
.Where(field => field.GetCustomAttribute<ConfigFieldAttribute>() != null)
167171
.Select(info => (info, info.GetCustomAttribute<ConfigFieldAttribute>()))
168172
.GroupBy(r => r.Item2.Group)
169173
.OrderBy(group => group.Key);
170-
171-
return returnValue;
172174
}
173175

174176
/// <summary>
@@ -214,11 +216,16 @@ private static float GetMaximumLabelWidth(IEnumerable<(FieldInfo, ConfigFieldAtt
214216
/// </exception>
215217
protected void RenderConfigFields()
216218
{
217-
var fieldGroups = GetFieldsByGroup();
218-
foreach (var fieldGroup in fieldGroups)
219+
foreach (var fieldGroup in GetFieldsByGroup())
219220
{
220221
float labelWidth = GetMaximumLabelWidth(fieldGroup);
221222

223+
// If there is a label for the field group, then display it.
224+
if (0 >= fieldGroup.Key && _groupLabels?.Length > fieldGroup.Key)
225+
{
226+
GUILayout.Label(_groupLabels[fieldGroup.Key], EditorStyles.boldLabel);
227+
}
228+
222229
foreach (var field in fieldGroup)
223230
{
224231
switch (field.FieldDetails.FieldType)
@@ -238,6 +245,9 @@ protected void RenderConfigFields()
238245
case ConfigFieldType.Ulong:
239246
field.FieldInfo.SetValue(config, GUIEditorUtility.RenderInputField(field.FieldDetails, (ulong)field.FieldInfo.GetValue(config), labelWidth));
240247
break;
248+
case ConfigFieldType.Double:
249+
field.FieldInfo.SetValue(config, GUIEditorUtility.RenderInputField(field.FieldDetails, (double)field.FieldInfo.GetValue(config), labelWidth));
250+
break;
241251
case ConfigFieldType.TextList:
242252
field.FieldInfo.SetValue(config, GUIEditorUtility.RenderInputField(field.FieldDetails, (List<string>)field.FieldInfo.GetValue(config), labelWidth));
243253
break;

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

Lines changed: 14 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -96,94 +96,6 @@ public static void AssigningTextField(string label, ref string value, float labe
9696
EditorGUIUtility.labelWidth = originalLabelWidth;
9797
}
9898

99-
public static void AssigningPath(string label, ref string filePath, string prompt, string directory = "", string extension = "", bool selectFolder = false, bool horizontalLayout = true, float maxButtonWidth = 100, float labelWidth = -1, string tooltip = null)
100-
{
101-
if (horizontalLayout)
102-
{
103-
EditorGUILayout.BeginHorizontal();
104-
}
105-
106-
AssigningTextField(label, ref filePath, labelWidth, tooltip);
107-
108-
bool buttonPressed = maxButtonWidth > 0 ? GUILayout.Button("Select", GUILayout.MaxWidth(maxButtonWidth)) : GUILayout.Button("Select");
109-
110-
if (buttonPressed)
111-
{
112-
var newFilePath = selectFolder ? EditorUtility.OpenFolderPanel(prompt, "", "") : EditorUtility.OpenFilePanel(prompt, directory, extension);
113-
if (!string.IsNullOrWhiteSpace(newFilePath))
114-
{
115-
filePath = newFilePath;
116-
}
117-
}
118-
119-
if (horizontalLayout)
120-
{
121-
EditorGUILayout.EndHorizontal();
122-
}
123-
}
124-
125-
private delegate T InputRenderDelegate<T>(string label, T value, float labelWidth, string tooltip);
126-
127-
public static void AssigningULongField(string label, ref ulong value, float labelWidth = -1, string tooltip = null)
128-
{
129-
float originalLabelWidth = EditorGUIUtility.labelWidth;
130-
if (labelWidth >= 0)
131-
{
132-
EditorGUIUtility.labelWidth = labelWidth;
133-
}
134-
135-
ulong newValue = value;
136-
var newValueAsString = EditorGUILayout.TextField(CreateGUIContent(label, tooltip), value.ToString(), GUILayout.ExpandWidth(true));
137-
if (string.IsNullOrWhiteSpace(newValueAsString))
138-
{
139-
newValueAsString = "0";
140-
}
141-
142-
try
143-
{
144-
newValue = ulong.Parse(newValueAsString);
145-
value = newValue;
146-
}
147-
catch (FormatException)
148-
{
149-
}
150-
catch (OverflowException)
151-
{
152-
}
153-
154-
EditorGUIUtility.labelWidth = originalLabelWidth;
155-
}
156-
157-
public static void AssigningUintField(string label, ref uint value, float labelWidth = -1, string tooltip = null)
158-
{
159-
float originalLabelWidth = EditorGUIUtility.labelWidth;
160-
if (labelWidth >= 0)
161-
{
162-
EditorGUIUtility.labelWidth = labelWidth;
163-
}
164-
165-
uint newValue = value;
166-
var newValueAsString = EditorGUILayout.TextField(CreateGUIContent(label, tooltip), value.ToString(), GUILayout.ExpandWidth(true));
167-
if (string.IsNullOrWhiteSpace(newValueAsString))
168-
{
169-
newValueAsString = "0";
170-
}
171-
172-
try
173-
{
174-
newValue = uint.Parse(newValueAsString);
175-
value = newValue;
176-
}
177-
catch (FormatException)
178-
{
179-
}
180-
catch (OverflowException)
181-
{
182-
}
183-
184-
EditorGUIUtility.labelWidth = originalLabelWidth;
185-
}
186-
18799
public static void AssigningULongToStringField(string label, ref string value, float labelWidth = -1, string tooltip = null)
188100
{
189101
float originalLabelWidth = EditorGUIUtility.labelWidth;
@@ -288,6 +200,8 @@ public static void AssigningFloatToStringField(string label, ref string value, f
288200

289201
#region New methods for rendering input fields
290202

203+
private delegate T InputRenderDelegate<T>(string label, T value, float labelWidth, string tooltip);
204+
291205
public static List<string> RenderInputField(ConfigFieldAttribute configFieldDetails, List<string> value,
292206
float labelWidth, string tooltip = null)
293207
{
@@ -391,6 +305,18 @@ public static string RenderInputField(FilePathFieldAttribute configFieldAttribut
391305
return filePath;
392306
}
393307

308+
public static double RenderInputField(ConfigFieldAttribute configFieldDetails, double value, float labelWidth, string tooltip = null)
309+
{
310+
return InputRendererWrapper(configFieldDetails.Label, value, labelWidth, tooltip,
311+
(label, value1, width, s) =>
312+
{
313+
return EditorGUILayout.DoubleField(
314+
CreateGUIContent(configFieldDetails.Label, tooltip),
315+
value,
316+
GUILayout.ExpandWidth(true));
317+
});
318+
}
319+
394320
public static string RenderInputField(ConfigFieldAttribute configFieldDetails, string value, float labelWidth,
395321
string tooltip = null)
396322
{

com.playeveryware.eos/Runtime/Core/Config/Attributes/ConfigFieldAttribute.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ public class ConfigFieldAttribute : Attribute
4343
/// </summary>
4444
public int Group { get; }
4545

46+
/// <summary>
47+
/// The type of the field - used to inform how to render input controls
48+
/// and validation.
49+
/// </summary>
4650
public ConfigFieldType FieldType { get; }
47-
51+
4852
public ConfigFieldAttribute(
4953
string label,
5054
ConfigFieldType type,

com.playeveryware.eos/Runtime/Core/Config/Attributes/ConfigFieldType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public enum ConfigFieldType
6060
/// </summary>
6161
Ulong,
6262

63+
/// <summary>
64+
/// A plain double.
65+
/// </summary>
66+
Double,
67+
6368
/// <summary>
6469
/// A list of strings.
6570
/// </summary>

com.playeveryware.eos/Runtime/Core/Config/Attributes/ConfigGroupAttribute.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,21 @@ public class ConfigGroupAttribute : Attribute
4343
/// </summary>
4444
public bool Collapsible { get; }
4545

46+
/// <summary>
47+
/// Set the
48+
/// </summary>
49+
public string[] GroupLabels { get; }
50+
4651
public ConfigGroupAttribute(string label, bool collapsible = true)
4752
{
4853
Label = label;
4954
Collapsible = collapsible;
5055
}
56+
57+
public ConfigGroupAttribute(string label, string[] groupLabels, bool collapsible = true)
58+
: this(label, collapsible)
59+
{
60+
GroupLabels = groupLabels;
61+
}
5162
}
5263
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ public static T Get<T>() where T : Config
220220
/// <returns>
221221
/// True if the parsing of flags was successful, false otherwise.
222222
/// </returns>
223-
protected delegate bool TryParseEnumDelegate<TEnum>(IList<string> stringFlags, out TEnum result) where TEnum : struct, Enum;
223+
protected delegate bool TryParseEnumDelegate<TEnum>(IList<string>
224+
stringFlags, out TEnum result) where TEnum : struct, Enum;
224225

225226
/// <summary>
226227
/// Private static wrapper to handle converting a list of strings into
@@ -240,7 +241,9 @@ public static T Get<T>() where T : Config
240241
/// operation between the enum values that result from parsing each of
241242
/// the items in a list into the indicated enum type value.
242243
/// </returns>
243-
protected static TEnum StringsToEnum<TEnum>(IList<string> stringFlags, TryParseEnumDelegate<TEnum> parseEnumFn)
244+
protected static TEnum StringsToEnum<TEnum>(
245+
IList<string> stringFlags,
246+
TryParseEnumDelegate<TEnum> parseEnumFn)
244247
where TEnum : struct, Enum
245248
{
246249
_ = parseEnumFn(stringFlags, out TEnum result);
@@ -298,10 +301,10 @@ private async Task EnsureConfigFileExistsAsync()
298301
// If the editor is not running, then the config file not
299302
// existing should throw an error.
300303
throw new FileNotFoundException(
301-
$"Config file \"{FilePath}\" does not exist.");
304+
$"Config file \"{FilePath}\" does not exist.");
302305
#endif
303306
}
304-
}
307+
}
305308

306309
// Functions declared below should only ever be utilized in the editor.
307310
// They are so divided to guarantee separation of concerns.

0 commit comments

Comments
 (0)