Skip to content

Commit

Permalink
Version 4.20.0
Browse files Browse the repository at this point in the history
 * FEATURE - Added TMP_Overflow and TMP_Alignment resize commands
  • Loading branch information
randoman committed Sep 10, 2021
1 parent adbef16 commit d9b60cb
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 32 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### 4.19.0
### 4.20.0
* FEATURE - Added TMP_Overflow and TMP_Alignment resize commands

### 4.19.0
* FEATURE - Added RegexPostProcessing configuration option
* BUG FIX - Fixed bug related to reload translations after changing screen size

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ The following types of commands exists:
* `UGUI_HorizontalOverflow(string mode)` - possible values: [wrap, overflow]
* Commands that control vertical overflow (UGUI only):
* `UGUI_VerticalOverflow(string mode)` - possible values: [truncate, overflow]
* Commands to control overflow (TMP only):
* `TMP_Overflow(string mode)` - [possible values](https://docs.unity3d.com/Packages/[email protected]/api/TMPro.TextOverflowModes.html)
* Commands to control text alignment (TMP only):
* `TMP_Alignment(string mode)` - [possible values](https://docs.unity3d.com/Packages/[email protected]/api/TMPro.TextAlignmentOptions.html)

But stop you say! How would I determine the path to use? This plugin provides no way to easily determine this, but there are other plugins that will allow you to do this.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void CreateClientAndHandler()
_handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

_client = new HttpClient( _handler, true );
_client.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue( "XUnity", "4.19.0" ) );
_client.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue( "XUnity", "4.20.0" ) );
_client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "*/*" ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/XUnity.AutoTranslator.Patcher/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string Version
{
get
{
return "4.19.0";
return "4.20.0";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.19.0</Version>
<Version>4.20.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public static class PluginData
/// <summary>
/// Gets the version of the plugin.
/// </summary>
public const string Version = "4.19.0";
public const string Version = "4.20.0";
}
}
88 changes: 67 additions & 21 deletions src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static bool GetSupportsStabilization( this TextTranslationInfo info )
internal class TextTranslationInfo
{
private Action<object> _unresizeFont;
private Action<object> _unresize;
private Action<object> _unfont;
private HashSet<string> _redirectedTranslations;

Expand Down Expand Up @@ -437,9 +436,9 @@ public void ResizeUI( object ui, UIResizeCache cache )
ClrTypes.UILabel_Properties.MultiLine?.Set( ui, true );
ClrTypes.UILabel_Properties.OverflowMethod?.Set( ui, 0 );

if( _unresize == null )
if( _unresizeFont == null )
{
_unresize = g =>
_unresizeFont = g =>
{
ClrTypes.UILabel_Properties.UseFloatSpacing?.Set( g, useFloatSpacingPropertyValue );
ClrTypes.UILabel_Properties.SpacingX?.Set( g, spacingXPropertyValue );
Expand All @@ -452,30 +451,61 @@ public void ResizeUI( object ui, UIResizeCache cache )
{
var overflowModeProperty = type.CachedProperty( "overflowMode" );
var originalOverflowMode = overflowModeProperty?.Get( ui );

// ellipsis (1) works
// masking (2) has a tendency to break in some versions of TMP
// truncate (3) works
if( originalOverflowMode != null && (int)originalOverflowMode == 2 )
{
overflowModeProperty.Set( ui, 3 );

_unresize = g =>
{
overflowModeProperty.Set( g, 2 );
};
}
bool changedOverflow = false;
bool isUntouched = _unresizeFont == null;

if( cache.HasAnyResizeCommands )
{
bool isUntouched = _unresizeFont == null;

var text = (Component)ui;

var segments = text.gameObject.GetPathSegments();
var scope = TranslationScopeProvider.GetScope( ui );
if( cache.TryGetUIResize( segments, scope, out var result ) )
{
if( result.OverflowCommand != null )
{
changedOverflow = true;
if( overflowModeProperty != null )
{
var newOverflowMode = result.OverflowCommand.GetMode();
if( newOverflowMode.HasValue )
{
overflowModeProperty.Set( ui, newOverflowMode );

if( isUntouched )
{
_unresizeFont = g =>
{
overflowModeProperty.Set( g, originalOverflowMode );
};
}
}
}
}

if( result.AlignmentCommand != null )
{
var alignmentProperty = type.CachedProperty( "alignment" );
if( alignmentProperty != null )
{
var alignmentValue = alignmentProperty.Get( ui );
var newAlignmentValue = result.AlignmentCommand.GetMode();

if( newAlignmentValue.HasValue )
{
alignmentProperty.Set( ui, newAlignmentValue.Value );

if( isUntouched )
{
_unresizeFont += g =>
{
alignmentProperty.Set( g, alignmentValue );
};
}
}
}
}

if( result.AutoResizeCommand != null )
{
var enableAutoSizingProperty = type.CachedProperty( "enableAutoSizing" );
Expand Down Expand Up @@ -560,16 +590,32 @@ public void ResizeUI( object ui, UIResizeCache cache )
}
}
}

if( !changedOverflow )
{
// ellipsis (1) works
// masking (2) has a tendency to break in some versions of TMP
// truncate (3) works
if( originalOverflowMode != null && (int)originalOverflowMode == 2 )
{
overflowModeProperty.Set( ui, 3 );

if( isUntouched )
{
_unresizeFont = g =>
{
overflowModeProperty.Set( g, 2 );
};
}
}
}
}
}

public void UnresizeUI( object graphic )
{
if( graphic == null ) return;

_unresize?.Invoke( graphic );
_unresize = null;

_unresizeFont?.Invoke( graphic );
_unresizeFont = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace XUnity.AutoTranslator.Plugin.Core.UIResize
{
interface ITMP_Alignment
{
int? GetMode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace XUnity.AutoTranslator.Plugin.Core.UIResize
{
interface ITMP_OverflowMode
{
int? GetMode();
}
}
23 changes: 23 additions & 0 deletions src/XUnity.AutoTranslator.Plugin.Core/UIResize/TMP_Alignment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using XUnity.AutoTranslator.Plugin.Core.Utilities;
using XUnity.Common.Constants;

namespace XUnity.AutoTranslator.Plugin.Core.UIResize
{
class TMP_Alignment : ITMP_Alignment
{
private int? _mode;

public TMP_Alignment( string[] args )
{
if( args.Length != 1 ) throw new ArgumentException( "TMP_Alignment requires one argument." );

_mode = (int)EnumHelper.GetValues( ClrTypes.TextAlignmentOptions, args[ 0 ] );
}

public int? GetMode()
{
return _mode;
}
}
}
23 changes: 23 additions & 0 deletions src/XUnity.AutoTranslator.Plugin.Core/UIResize/TMP_Overflow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using XUnity.AutoTranslator.Plugin.Core.Utilities;
using XUnity.Common.Constants;

namespace XUnity.AutoTranslator.Plugin.Core.UIResize
{
class TMP_Overflow : ITMP_OverflowMode
{
private int? _mode;

public TMP_Overflow( string[] args )
{
if( args.Length != 1 ) throw new ArgumentException( "TMP_Overflow requires one argument." );

_mode = (int)EnumHelper.GetValues( ClrTypes.TextOverflowModes, args[ 0 ] );
}

public int? GetMode()
{
return _mode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ static UIResizeAttachment()
typeof(UGUI_ChangeLineSpacing),
typeof(UGUI_ChangeLineSpacingByPercentage),
typeof(UGUI_HorizontalOverflow),
typeof(UGUI_VerticalOverflow)
typeof(UGUI_VerticalOverflow),
typeof(TMP_Overflow),
typeof(TMP_Alignment),
};

//var commands = typeof( AutoTranslationPlugin ).Assembly.GetTypes()
Expand Down Expand Up @@ -120,6 +122,18 @@ public bool AddResizeCommand( string path, string commands, int scope )
result.VerticalOverflowCommand = verticalOverflowCommand;
result.IsVerticalOverflowCommandScoped = scope != TranslationScopes.None;
}

if( resizeCommand is ITMP_OverflowMode overflowCommand )
{
result.OverflowCommand = overflowCommand;
result.IsOverflowCommandScoped = scope != TranslationScopes.None;
}

if( resizeCommand is ITMP_Alignment alignmentCommand )
{
result.AlignmentCommand = alignmentCommand;
result.IsAlignmentCommandScoped = scope != TranslationScopes.None;
}
}
else
{
Expand Down
22 changes: 21 additions & 1 deletion src/XUnity.AutoTranslator.Plugin.Core/UIResize/UIResizeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ class UIResizeResult
public IUGUI_VerticalOverflow VerticalOverflowCommand { get; set; }
public bool IsVerticalOverflowCommandScoped { get; set; }

public ITMP_OverflowMode OverflowCommand { get; set; }
public bool IsOverflowCommandScoped { get; set; }

public ITMP_Alignment AlignmentCommand { get; set; }
public bool IsAlignmentCommandScoped { get; set; }

public bool IsEmpty()
{
return ResizeCommand == null
&& AutoResizeCommand == null
&& LineSpacingCommand == null
&& HorizontalOverflowCommand == null
&& VerticalOverflowCommand == null;
&& VerticalOverflowCommand == null
&& OverflowCommand == null
&& AlignmentCommand == null;
}

public UIResizeResult Copy()
Expand Down Expand Up @@ -64,6 +72,18 @@ public void MergeInto( UIResizeResult otherResult )
VerticalOverflowCommand = otherResult.VerticalOverflowCommand;
IsVerticalOverflowCommandScoped = otherResult.IsVerticalOverflowCommandScoped;
}

if( otherResult.OverflowCommand != null && ( otherResult.IsOverflowCommandScoped || ( !otherResult.IsOverflowCommandScoped && !IsOverflowCommandScoped ) ) )
{
OverflowCommand = otherResult.OverflowCommand;
IsOverflowCommandScoped = otherResult.IsOverflowCommandScoped;
}

if( otherResult.AlignmentCommand != null && ( otherResult.IsAlignmentCommandScoped || ( !otherResult.IsAlignmentCommandScoped && !IsAlignmentCommandScoped ) ) )
{
AlignmentCommand = otherResult.AlignmentCommand;
IsAlignmentCommandScoped = otherResult.IsAlignmentCommandScoped;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<DevelopmentDependency>True</DevelopmentDependency>
<TargetFramework>net35</TargetFramework>
<Version>4.19.0</Version>
<Version>4.20.0</Version>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.19.0</Version>
<Version>4.20.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.19.0</Version>
<Version>4.20.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net40</TargetFramework>
<AssemblyName>SetupReiPatcherAndAutoTranslator</AssemblyName>
<Version>4.19.0</Version>
<Version>4.20.0</Version>
<ApplicationIcon>icon.ico</ApplicationIcon>
<Win32Resource />
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/XUnity.Common/Constants/ClrTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static class ClrTypes
public static readonly Type UnityEventBase = FindType( "UnityEngine.Events.UnityEventBase" );
public static readonly Type BaseInvokableCall = FindType( "UnityEngine.Events.BaseInvokableCall" );
public static readonly Type HorizontalWrapMode = FindType( "UnityEngine.HorizontalWrapMode" );
public static readonly Type TextOverflowModes = FindType( "TMPro.TextOverflowModes" );
public static readonly Type TextAlignmentOptions = FindType( "TMPro.TextAlignmentOptions" );
public static readonly Type VerticalWrapMode = FindType( "UnityEngine.VerticalWrapMode" );
public static readonly Type Font = FindType( "UnityEngine.Font" );
public static readonly Type WaitForSecondsRealtime = FindType( "UnityEngine.WaitForSecondsRealtime" );
Expand Down

0 comments on commit d9b60cb

Please sign in to comment.