Improve LocalizationSettings editor

This commit is contained in:
Wojtek Figat
2021-04-22 16:10:20 +02:00
parent b5e19d95bd
commit c23d2ad2c4
3 changed files with 100 additions and 6 deletions

View File

@@ -139,7 +139,7 @@ namespace FlaxEditor.CustomEditors
/// <inheritdoc /> /// <inheritdoc />
protected override void OnModified() protected override void OnModified()
{ {
Presenter.Modified?.Invoke(); Presenter.OnModified();
base.OnModified(); base.OnModified();
} }
@@ -354,6 +354,14 @@ namespace FlaxEditor.CustomEditors
ExpandGroups(this, false); ExpandGroups(this, false);
} }
/// <summary>
/// Invokes <see cref="Modified"/> event.
/// </summary>
public void OnModified()
{
Modified?.Invoke();
}
/// <summary> /// <summary>
/// Called when selection gets changed. /// Called when selection gets changed.
/// </summary> /// </summary>

View File

@@ -0,0 +1,81 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using FlaxEditor.Content.Settings;
using FlaxEditor.CustomEditors.Editors;
using FlaxEditor.Scripting;
using FlaxEngine;
using FlaxEngine.Utilities;
namespace FlaxEditor.CustomEditors.Dedicated
{
[CustomEditor(typeof(LocalizationSettings))]
sealed class LocalizationSettingsEditor : GenericEditor
{
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
var settings = (LocalizationSettings)Values[0];
var tablesLength = settings.LocalizedStringTables?.Length ?? 0;
var tables = new List<LocalizedStringTable>(tablesLength);
for (int i = 0; i < tablesLength; i++)
{
var table = settings.LocalizedStringTables[i];
if (table && !table.WaitForLoaded())
tables.Add(table);
}
var locales = tables.GroupBy(x => x.Locale);
var tableEntries = new Dictionary<LocalizedStringTable, Dictionary<string, string[]>>();
var allKeys = new HashSet<string>();
foreach (var e in locales)
{
foreach (var table in e)
{
var entries = table.Entries;
tableEntries[table] = entries;
allKeys.AddRange(entries.Keys);
}
}
{
var group = layout.Group("Preview");
// Current language and culture preview management
group.Object("Current Language", new CustomValueContainer(new ScriptType(typeof(CultureInfo)), Localization.CurrentLanguage, (instance, index) => Localization.CurrentLanguage, (instance, index, value) => Localization.CurrentLanguage = value as CultureInfo), null, "Current UI display language for the game preview.");
group.Object("Current Culture", new CustomValueContainer(new ScriptType(typeof(CultureInfo)), Localization.CurrentCulture, (instance, index) => Localization.CurrentCulture, (instance, index, value) => Localization.CurrentCulture = value as CultureInfo), null, "Current values formatting culture for the game preview.");
}
{
var group = layout.Group("Locales");
// Show all existing locales
foreach (var e in locales)
{
var culture = new CultureInfo(e.Key);
var prop = group.AddPropertyItem(CultureInfoEditor.GetName(culture), culture.NativeName);
int count = e.Sum(x => tableEntries[x].Values.Count(y => y != null && y.Length != 0 && !string.IsNullOrEmpty(y[0])));
prop.Label(string.Format("Progress: {0}% ({1}/{2})", (int)(((float)count / allKeys.Count * 100.0f)), count, allKeys.Count));
prop.Label("Tables:");
foreach (var table in e)
{
var namePath = table.Path;
if (namePath.StartsWith(Globals.ProjectFolder))
namePath = namePath.Substring(Globals.ProjectFolder.Length + 1);
var tableLabel = prop.ClickableLabel(namePath).CustomControl;
tableLabel.TextColorHighlighted = Color.Wheat;
tableLabel.DoubleClick += delegate { Editor.Instance.Windows.ContentWin.Select(table); };
}
group.Space(10);
}
}
{
// Raw asset data editing
var group = layout.Group("Data");
base.Initialize(group);
}
}
}
}

View File

@@ -81,7 +81,7 @@ namespace FlaxEditor.CustomEditors.Editors
} }
} }
public static void UpdateFilter(TreeNode node, string filterText) private static void UpdateFilter(TreeNode node, string filterText)
{ {
// Update children // Update children
bool isAnyChildVisible = false; bool isAnyChildVisible = false;
@@ -106,6 +106,12 @@ namespace FlaxEditor.CustomEditors.Editors
} }
private void ShowPicker() private void ShowPicker()
{
var menu = CreatePicker(Culture, value => { Culture = value; });
menu.Show(_label, new Vector2(0, _label.Height));
}
internal static ContextMenuBase CreatePicker(CultureInfo value, Action<CultureInfo> changed)
{ {
var menu = new ContextMenuBase var menu = new ContextMenuBase
{ {
@@ -150,7 +156,6 @@ namespace FlaxEditor.CustomEditors.Editors
node.Parent = parent; node.Parent = parent;
lcidToNode[culture.LCID] = node; lcidToNode[culture.LCID] = node;
} }
var value = Culture;
if (value != null) if (value != null)
tree.Select((TreeNode)lcidToNode[value.LCID]); tree.Select((TreeNode)lcidToNode[value.LCID]);
tree.SelectedChanged += delegate(List<TreeNode> before, List<TreeNode> after) tree.SelectedChanged += delegate(List<TreeNode> before, List<TreeNode> after)
@@ -158,7 +163,7 @@ namespace FlaxEditor.CustomEditors.Editors
if (after.Count == 1) if (after.Count == 1)
{ {
menu.Hide(); menu.Hide();
Culture = (CultureInfo)after[0].Tag; changed((CultureInfo)after[0].Tag);
} }
}; };
searchBox.TextChanged += delegate searchBox.TextChanged += delegate
@@ -172,10 +177,10 @@ namespace FlaxEditor.CustomEditors.Editors
menu.PerformLayout(); menu.PerformLayout();
}; };
root.ExpandAll(true); root.ExpandAll(true);
menu.Show(_label, new Vector2(0, _label.Height)); return menu;
} }
private static string GetName(CultureInfo value) internal static string GetName(CultureInfo value)
{ {
return value != null ? string.Format("{0} - {1}", value.Name, value.EnglishName) : null; return value != null ? string.Format("{0} - {1}", value.Name, value.EnglishName) : null;
} }