-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from redbluegames/staging
Merge Staging v1.7.0 into Master
- Loading branch information
Showing
143 changed files
with
5,900 additions
and
431 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
Assets/RedBlueGames/MulliganRenamer/Editor/ExtensionsAndUtilities/ColorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* MIT License | ||
Copyright (c) 2016 Edward Rowe, RedBlueGames | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
namespace RedBlueGames.MulliganRenamer | ||
{ | ||
using UnityEngine; | ||
|
||
/// <summary> | ||
/// Extension methods for the Color class | ||
/// </summary> | ||
public static class ColorExtensions | ||
{ | ||
/// <summary> | ||
/// Sets the alpha on the color to the specified value and returns the result | ||
/// </summary> | ||
/// <param name="color">Color to modify</param> | ||
/// <param name="alpha">New alpha value</param> | ||
/// <returns>Resulting color</returns> | ||
public static Color CreateCopyWithNewAlpha(this Color color, float alpha) | ||
{ | ||
var alphaModified = new Color( | ||
color.r, | ||
color.g, | ||
color.b, | ||
alpha); | ||
return alphaModified; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/RedBlueGames/MulliganRenamer/Editor/ExtensionsAndUtilities/ColorExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
Assets/RedBlueGames/MulliganRenamer/Editor/ExtensionsAndUtilities/EditorCoroutineUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace RedBlueGames.MulliganRenamer | ||
{ | ||
using System; | ||
using System.Collections; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
public static class EditorCoroutineUtility | ||
{ | ||
/// <summary> | ||
/// Starts a Coroutine using Unity Editor's update loop. This is useful for EditorWindows | ||
/// which aren't MonoBehaviours and therefore can't use Coroutines. | ||
/// Utility function adapted from https://forum.unity.com/threads/using-unitywebrequest-in-editor-tools.397466/#post-4485181 | ||
/// </summary> | ||
/// <param name="update"></param> | ||
/// <param name="onEnd"></param> | ||
public static void StartBackgroundTask(IEnumerator update, Action onEnd = null) | ||
{ | ||
EditorApplication.CallbackFunction closureCallback = null; | ||
|
||
closureCallback = () => | ||
{ | ||
try | ||
{ | ||
if (update.MoveNext() == false) | ||
{ | ||
if (onEnd != null) | ||
{ | ||
onEnd(); | ||
} | ||
|
||
EditorApplication.update -= closureCallback; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (onEnd != null) | ||
{ | ||
onEnd(); | ||
} | ||
|
||
Debug.LogException(ex); | ||
EditorApplication.update -= closureCallback; | ||
} | ||
}; | ||
|
||
EditorApplication.update += closureCallback; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...RedBlueGames/MulliganRenamer/Editor/ExtensionsAndUtilities/EditorCoroutineUtility.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
187 changes: 187 additions & 0 deletions
187
.../RedBlueGames/MulliganRenamer/Editor/ExtensionsAndUtilities/MulliganEditorGUIUtilities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/* MIT License | ||
Copyright (c) 2016 Edward Rowe, RedBlueGames | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
namespace RedBlueGames.MulliganRenamer | ||
{ | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
public static class MulliganEditorGUIUtilities | ||
{ | ||
/// <summary> | ||
/// Draw a DiffLabel, which draws a simple EditorGUILabel populated with the results from a rename op (diff). | ||
/// </summary> | ||
/// <param name="rect">Rect to draw in</param> | ||
/// <param name="renameResult">The result of a RenameOp, which contains the diffs to render</param> | ||
/// <param name="showBefore">Flag to show the name before the op, instead of the result</param> | ||
/// <param name="resultLabelStyle">Style of the DiffLabel</param> | ||
/// <param name="style">Style for the EditorGUILabel itself</param> | ||
public static void DrawDiffLabel(Rect rect, RenameResult renameResult, bool showBefore, DiffLabelStyle resultLabelStyle, GUIStyle style) | ||
{ | ||
var labelText = string.Empty; | ||
if (!resultLabelStyle.HideDiff) | ||
{ | ||
ApplyBackgroundColorToDiff( | ||
rect, | ||
style, | ||
renameResult, | ||
resultLabelStyle.OperationToShow, | ||
resultLabelStyle.DiffBackgroundColor); | ||
} | ||
|
||
labelText = showBefore ? renameResult.GetOriginalColored(resultLabelStyle.DiffTextColor) : | ||
renameResult.GetResultColored(resultLabelStyle.DiffTextColor); | ||
EditorGUI.LabelField(rect, labelText, style); | ||
} | ||
|
||
private static void ApplyBackgroundColorToDiff( | ||
Rect rect, | ||
GUIStyle style, | ||
RenameResult renameContent, | ||
DiffOperation operationToColor, | ||
Color backgroundColor) | ||
{ | ||
if (string.IsNullOrEmpty(renameContent.Original)) | ||
{ | ||
return; | ||
} | ||
|
||
// Blocks don't need padding or margin because it's accounted for | ||
// when we measure the total. We only want to know the size of each content block . | ||
var blockStyle = new GUIStyle(style); | ||
blockStyle.margin = new RectOffset(); | ||
blockStyle.padding = new RectOffset(); | ||
|
||
var position = rect; | ||
var allTextSoFar = string.Empty; | ||
foreach (var diff in renameContent) | ||
{ | ||
// We want to skip whatever diff we aren't rendering on this column | ||
// (Column 1 shows deletions, Column 2 shows insertions) | ||
if (diff.Operation != operationToColor && diff.Operation != DiffOperation.Equal) | ||
{ | ||
continue; | ||
} | ||
|
||
if (diff.Operation == operationToColor) | ||
{ | ||
var totalRect = style.CalcSize(new GUIContent(allTextSoFar)); | ||
var blockRect = new Rect(position.x + totalRect.x - style.padding.left, position.y, 0, totalRect.y); | ||
var spaceBlocks = GetConsecutiveBlocksOfToken(diff.Result, ' '); | ||
|
||
foreach (var block in spaceBlocks) | ||
{ | ||
var blockSize = blockStyle.CalcSize(new GUIContent(block)); | ||
|
||
blockRect.width = blockSize.x; | ||
var textureWidth = ((blockRect.x + blockRect.width) < (rect.x + rect.width)) | ||
? blockRect.width | ||
: Mathf.Max(0f, (rect.x + rect.width) - (blockRect.x)); | ||
|
||
var textureRect = new Rect( | ||
blockRect.x, | ||
blockRect.y, | ||
textureWidth, | ||
blockRect.height); | ||
|
||
var textColorTransparent = backgroundColor; | ||
|
||
var oldColor = GUI.color; | ||
GUI.color = textColorTransparent; | ||
GUI.DrawTexture(textureRect, Texture2D.whiteTexture); | ||
GUI.color = oldColor; | ||
|
||
blockRect.x += blockSize.x; | ||
} | ||
} | ||
|
||
allTextSoFar += diff.Result; | ||
} | ||
} | ||
|
||
private static List<string> GetConsecutiveBlocksOfToken(string str, char token) | ||
{ | ||
var spaceBlocks = new List<string>(); | ||
var characterStreak = new System.Text.StringBuilder(); | ||
var isTokenBlock = false; | ||
if (str.Length > 0) | ||
{ | ||
characterStreak.Append(str[0]); | ||
isTokenBlock = str[0] == token; | ||
} | ||
|
||
for (int i = 1; i < str.Length; ++i) | ||
{ | ||
if (isTokenBlock) | ||
{ | ||
if (str[i] == token) | ||
{ | ||
characterStreak.Append(str[i]); | ||
} | ||
else | ||
{ | ||
spaceBlocks.Add(characterStreak.ToString()); | ||
characterStreak = new System.Text.StringBuilder(); | ||
characterStreak.Append(str[i]); | ||
|
||
isTokenBlock = false; | ||
} | ||
} | ||
else | ||
{ | ||
if (str[i] == token) | ||
{ | ||
spaceBlocks.Add(characterStreak.ToString()); | ||
characterStreak = new System.Text.StringBuilder(); | ||
characterStreak.Append(str[i]); | ||
|
||
isTokenBlock = true; | ||
} | ||
else | ||
{ | ||
characterStreak.Append(str[i]); | ||
} | ||
} | ||
} | ||
|
||
if (characterStreak.Length > 0) | ||
{ | ||
spaceBlocks.Add(characterStreak.ToString()); | ||
} | ||
|
||
return spaceBlocks; | ||
} | ||
|
||
public class DiffLabelStyle | ||
{ | ||
public bool HideDiff { get; set; } | ||
|
||
public DiffOperation OperationToShow { get; set; } | ||
|
||
public Color DiffTextColor { get; set; } | ||
|
||
public Color DiffBackgroundColor { get; set; } | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...lueGames/MulliganRenamer/Editor/ExtensionsAndUtilities/MulliganEditorGUIUtilities.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.