Skip to content

Commit

Permalink
Merge pull request #77 from anatawa12/internationalization
Browse files Browse the repository at this point in the history
Internationalization
  • Loading branch information
anatawa12 authored Mar 26, 2023
2 parents 362e18f + f5ab1b2 commit 3c68f7f
Show file tree
Hide file tree
Showing 33 changed files with 403 additions and 129 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Internationalization support `#77`
- This adds way to translate editor elements.
- However, no other language translation than English is not added yet.
- Please feel free to make PullRequest if you can maintain the translation.

### Changed

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Internationalization support `#77`
- This adds way to translate editor elements.
- However, no other language translation than English is not added yet.
- Please feel free to make PullRequest if you can maintain the translation.

### Changed

Expand Down
46 changes: 46 additions & 0 deletions Editor/AvatarTagComponentEditorBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using CustomLocalization4EditorExtension;
using UnityEditor;

namespace Anatawa12.AvatarOptimizer
{
abstract class AvatarTagComponentEditorBase : Editor
{
private readonly SaveVersionDrawer _saveVersion = new SaveVersionDrawer();

public sealed override void OnInspectorGUI()
{
CL4EE.DrawLanguagePicker();

var description = Description;
if (!string.IsNullOrEmpty(description))
EditorGUILayout.HelpBox(description, MessageType.None);

_saveVersion.Draw(serializedObject);

OnInspectorGUIInner();
}

protected virtual string Description => null;
protected abstract void OnInspectorGUIInner();
}

[CustomEditor(typeof(AvatarTagComponent), true)]
class DefaultAvatarTagComponentEditor : AvatarTagComponentEditorBase
{
protected override void OnInspectorGUIInner()
{
serializedObject.UpdateIfRequiredOrScript();
var iterator = serializedObject.GetIterator();

var enterChildren = true;
while (iterator.NextVisible(enterChildren))
{
if ("m_Script" != iterator.propertyPath)
EditorGUILayout.PropertyField(iterator, true);
enterChildren = false;
}

serializedObject.ApplyModifiedProperties();
}
}
}
3 changes: 3 additions & 0 deletions Editor/AvatarTagComponentEditorBase.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Anatawa12.AvatarOptimizer
{
[UsedImplicitly]
public class AvatarTagComponentEditor
public class AvatarTagComponentEditorImpl
{
[UsedImplicitly]
public static void SetCurrentSaveVersion(AvatarTagComponent component)
Expand Down
File renamed without changes.
15 changes: 6 additions & 9 deletions Editor/ClearEndpointPositionEditor.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using Anatawa12.AvatarOptimizer.Processors;
using CustomLocalization4EditorExtension;
using UnityEditor;
using UnityEngine;
using VRC.Dynamics;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(ClearEndpointPosition))]
internal class ClearEndpointPositionEditor : Editor
internal class ClearEndpointPositionEditor : AvatarTagComponentEditorBase
{
private readonly SaveVersionDrawer _saveVersion = new SaveVersionDrawer();
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("You clear Endpoint Position with _end bones.");
EditorGUILayout.LabelField("This can be useful for MergeBone component");

_saveVersion.Draw(serializedObject);
protected override string Description => CL4EE.Tr("ClearEndpointPosition:description");

if (GUILayout.Button("Apply and Remove Component"))
protected override void OnInspectorGUIInner()
{
if (GUILayout.Button(CL4EE.Tr("ClearEndpointPosition:button:Apply and Remove Component")))
{
ClearEndpointPositionProcessor.Process(((Component)target).GetComponent<VRCPhysBoneBase>());
DestroyImmediate(target);
Expand Down
18 changes: 5 additions & 13 deletions Editor/FreezeBlendShapeEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using CustomLocalization4EditorExtension;
using UnityEditor;
using UnityEngine;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(FreezeBlendShape))]
public class FreezeBlendShapeEditor : Editor
class FreezeBlendShapeEditor : AvatarTagComponentEditorBase
{
private readonly SaveVersionDrawer _saveVersion = new SaveVersionDrawer();
private PrefabSafeSet.EditorUtil<string> _shapeKeysSet;

private void OnEnable()
Expand All @@ -19,16 +19,8 @@ private void OnEnable()
(x, v) => x.stringValue = v);
}

public override void OnInspectorGUI()
protected override void OnInspectorGUIInner()
{
if (targets.Length != 1)
{
EditorGUILayout.LabelField("MultiTarget Editing is not supported");
return;
}

_saveVersion.Draw(serializedObject);

var component = (FreezeBlendShape)target;

var shapes = EditSkinnedMeshComponentUtil.GetBlendShapes(component.GetComponent<SkinnedMeshRenderer>(), component);
Expand All @@ -47,13 +39,13 @@ public override void OnInspectorGUI()

using (new GUILayout.HorizontalScope())
{
if (GUILayout.Button("Check All"))
if (GUILayout.Button(CL4EE.Tr("FreezeBlendShape:button:Check All")))
{
foreach (var shapeKeyName in shapes)
_shapeKeysSet.GetElementOf(shapeKeyName).EnsureAdded();
}

if (GUILayout.Button("Invert All"))
if (GUILayout.Button(CL4EE.Tr("FreezeBlendShape:button:Invert All")))
{
foreach (var shapeKeyName in shapes)
{
Expand Down
11 changes: 11 additions & 0 deletions Editor/Localizations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CustomLocalization4EditorExtension;

namespace Anatawa12.AvatarOptimizer
{
static class Localizations
{
[AssemblyCL4EELocalization]
public static Localization Localization { get; } = new Localization(
"8b53df9f2e18428bbba2165c4f2af9be", "en");
}
}
3 changes: 3 additions & 0 deletions Editor/Localizations.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Editor/MakeChildrenEditor.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using System;
using CustomLocalization4EditorExtension;
using UnityEditor;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(MakeChildren))]
[CanEditMultipleObjects]
internal class MakeChildrenEditor : Editor
internal class MakeChildrenEditor : AvatarTagComponentEditorBase
{
private readonly SaveVersionDrawer _saveVersion = new SaveVersionDrawer();
protected override string Description => CL4EE.Tr("MakeChildren:description");
private SerializedProperty _children;

private void OnEnable()
{
_children = serializedObject.FindProperty(nameof(MakeChildren.children));
}

public override void OnInspectorGUI()
protected override void OnInspectorGUIInner()
{
EditorGUILayout.HelpBox("This component will make children at build time", MessageType.Info);
_saveVersion.Draw(serializedObject);
EditorGUILayout.PropertyField(_children);
serializedObject.ApplyModifiedProperties();
}
Expand Down
10 changes: 5 additions & 5 deletions Editor/MergeBoneEditor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using CustomLocalization4EditorExtension;
using UnityEditor;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(MergeBone))]
public class MergeBoneEditor : Editor
class MergeBoneEditor : AvatarTagComponentEditorBase
{
private SaveVersionDrawer _saveVersion = new SaveVersionDrawer();
public override void OnInspectorGUI()
protected override string Description => CL4EE.Tr("MergeBone:description");

protected override void OnInspectorGUIInner()
{
EditorGUILayout.LabelField("You will remove this GameObject and merge bone to parent");
_saveVersion.Draw(serializedObject);
}
}
}
10 changes: 5 additions & 5 deletions Editor/MergePhysBoneEditor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Linq;
using CustomLocalization4EditorExtension;
using UnityEditor;
using UnityEngine;
using VRC.Dynamics;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(MergePhysBone))]
internal class MergePhysBoneEditor : Editor
internal class MergePhysBoneEditor : AvatarTagComponentEditorBase
{
private static class Style
{
Expand All @@ -24,7 +25,6 @@ private static class Style
};
}

private readonly SaveVersionDrawer _saveVersion = new SaveVersionDrawer();
private SerializedProperty _mergedComponentProp;
private SerializedProperty _rootTransformProp;
private SerializedProperty _forcesProp;
Expand Down Expand Up @@ -79,9 +79,8 @@ private void OnEnable()
(x, v) => x.objectReferenceValue = v);
}

public override void OnInspectorGUI()
protected override void OnInspectorGUIInner()
{
_saveVersion.Draw(serializedObject);
EditorGUI.BeginDisabledGroup(_mergedComponentProp.objectReferenceValue != null);
EditorGUILayout.PropertyField(_mergedComponentProp);
EditorGUI.EndDisabledGroup();
Expand Down Expand Up @@ -116,7 +115,8 @@ public override void OnInspectorGUI()
break;
case VRCPhysBoneBase.LimitType.Angle:
case VRCPhysBoneBase.LimitType.Hinge:
EditorGUILayout.PropertyField(_maxAngleXProp, new GUIContent("Max Angle"));
EditorGUILayout.PropertyField(_maxAngleXProp,
new GUIContent(CL4EE.Tr("MergePhysBone:prop:Max Angle")));
EditorGUILayout.PropertyField(_limitRotationProp);
break;
case VRCPhysBoneBase.LimitType.Polar:
Expand Down
51 changes: 7 additions & 44 deletions Editor/MergeSkinnedMeshEditor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CustomLocalization4EditorExtension;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(MergeSkinnedMesh))]
internal class MergeSkinnedMeshEditor : Editor
internal class MergeSkinnedMeshEditor : AvatarTagComponentEditorBase
{
private static class Style
{
Expand All @@ -25,7 +24,6 @@ private static class Style
};
}

private readonly SaveVersionDrawer _saveVersion = new SaveVersionDrawer();
SerializedProperty _renderersSetProp;
SerializedProperty _staticRenderersSetProp;
SerializedProperty _removeEmptyRendererObjectProp;
Expand All @@ -44,14 +42,11 @@ private void OnEnable()
(x, v) => x.objectReferenceValue = v);
}

public override void OnInspectorGUI()
protected override void OnInspectorGUIInner()
{
_saveVersion.Draw(serializedObject);
if (((MergeSkinnedMesh)target).GetComponent<SkinnedMeshRenderer>().sharedMesh)
{
GUILayout.Label($"Mesh of SkinnedMeshRenderer is not None!", Style.WarningStyle);
GUILayout.Label($"You should add MergeSkinnedMesh onto new GameObject with new SkinnedMeshRenderer!",
Style.WarningStyle);
EditorGUILayout.HelpBox(CL4EE.Tr("MergeSkinnedMesh:warning:MeshIsNotNone"), MessageType.Warning);
}

EditorGUILayout.PropertyField(_renderersSetProp);
Expand All @@ -60,45 +55,13 @@ public override void OnInspectorGUI()

serializedObject.ApplyModifiedProperties();

EditorGUILayout.LabelField("Merge Materials:", EditorStyles.boldLabel);
EditorGUILayout.LabelField(CL4EE.Tr("MergeSkinnedMesh:label:Merge Materials"), EditorStyles.boldLabel);
if (targets.Length != 1)
EditorGUILayout.LabelField("MergeMaterial is not supported with Multi Target Editor");
else
MergeMaterials((MergeSkinnedMesh)target);
}

public void ShowRenderers<T>(string property, SerializedProperty array, Action<T> validation)
where T : Object
{
EditorGUILayout.LabelField(property, EditorStyles.boldLabel);

EditorGUI.indentLevel++;
for (var i = 0; i < array.arraySize; i++)
{
var elementProp = array.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(elementProp);

if (elementProp.objectReferenceValue == null)
{
array.DeleteArrayElementAtIndex(i);
i--;
}
else if (elementProp.objectReferenceValue is T renderer)
{
validation(renderer);
}
}

var toAdd = (T)EditorGUILayout.ObjectField($"Element {array.arraySize}", null, typeof(T), true);
if (toAdd != null)
{
array.arraySize += 1;
array.GetArrayElementAtIndex(array.arraySize - 1).objectReferenceValue = toAdd;
}

EditorGUI.indentLevel--;
}

public void MergeMaterials(MergeSkinnedMesh merge)
{
var materials = new HashSet<Material>();
Expand All @@ -123,11 +86,11 @@ public void MergeMaterials(MergeSkinnedMesh merge)
EditorGUI.indentLevel++;
var element = _doNotMergeMaterials.GetElementOf(group.Key);
var fieldPosition = EditorGUILayout.GetControlRect();
var label = new GUIContent("Merge");
var label = new GUIContent(CL4EE.Tr("MergeSkinnedMesh:label:Merge"));
using (new PrefabSafeSet.PropertyScope<Material>(element, fieldPosition, label))
element.SetExistence(!EditorGUI.ToggleLeft(fieldPosition, label, !element.Contains));

EditorGUILayout.LabelField("Renderers:");
EditorGUILayout.LabelField(CL4EE.Tr("MergeSkinnedMesh:label:Renderers"));
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(true);
foreach (var (_, rendererIndex, _) in group)
Expand Down
Loading

0 comments on commit 3c68f7f

Please sign in to comment.