Skip to content

Commit

Permalink
fix(WelcomeWindow): fixed parsing of change logs (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
phodoval committed Dec 31, 2021
1 parent cbdfbf3 commit 5da522d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirage/Editor/WelcomeWindow/Resources/Changelog.uxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="Header" style="flex-wrap: nowrap; white-space: nowrap;">
<ui:Label text="Version" display-tooltip-when-elided="true" name="ChangeLogVersion" style="font-size: 20px; -unity-font-style: bold; flex-wrap: nowrap;" />
<ui:VisualElement name="ChangeSet" style="flex-wrap: nowrap; white-space: nowrap;">
<ui:Label text="Version" display-tooltip-when-elided="true" name="ChangeLogVersion" />
<ui:Label display-tooltip-when-elided="true" name="ChangeLogText" style="-unity-font-style: normal; font-size: 12px; flex-wrap: nowrap; white-space: normal;" />
</ui:VisualElement>
</ui:UXML>
13 changes: 13 additions & 0 deletions Assets/Mirage/Editor/WelcomeWindow/Resources/WelcomeWindow.uss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
white-space: normal;
}

#ChangeSet {
padding-left: 10px;
padding-right: 10px;
margin-bottom: 15px;
}

#ChangeLogVersion {
font-size: 20px;
-unity-font-style: bold;
flex-wrap: nowrap;
margin-bottom: 5px;
}

#Description {
font-size: 14px;
-unity-text-align: upper-left;
Expand Down
26 changes: 22 additions & 4 deletions Assets/Mirage/Editor/WelcomeWindow/WelcomeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Mirage.Logging;
using UnityEditor;
using UnityEditor.PackageManager;
Expand Down Expand Up @@ -40,6 +41,12 @@ public class WelcomeWindow : EditorWindow
private const string FaqUrl = "https://miragenet.github.io/Mirage/Articles/Guides/FAQ.html";
private const string DiscordInviteUrl = "https://discord.gg/DTBPBYvexy";

#if UNITY_2021_2_OR_NEWER
private const string BoldReplace = "<b>$1</b>";
#else
private const string BoldReplace = "$1";
#endif

private readonly List<Package> Packages = new List<Package>()
{
new Package { displayName = "LAN Discovery", packageName = "com.miragenet.discovery", gitUrl = "https://github.com/MirageNet/Discovery.git?path=/Assets/Discovery"},
Expand Down Expand Up @@ -183,7 +190,7 @@ private void OnEnable()

private void OnDisable()
{
//now that we have seen the welcome window,
//now that we have seen the welcome window,
//set this this to true so we don't load the window every time we recompile (for the current version)
EditorPrefs.SetBool(firstStartUpKey, true);
EditorPrefs.SetBool(firstTimeMirageKey, true);
Expand Down Expand Up @@ -302,6 +309,9 @@ private void DrawChangeLog(List<string> content)
int currentVersionCount = -1;

var builder = new StringBuilder();
var firstTitle = true;
var regexLine = new Regex("^\\* (.*)$");
var regexBold = new Regex("\\*\\*(.*)\\*\\*");

for (int i = 0; i < content.Count; i++)
{
Expand All @@ -320,21 +330,29 @@ private void DrawChangeLog(List<string> content)
rootVisualElement.Q<VisualElement>("ChangelogData").Add(newLog);

builder = new StringBuilder();
firstTitle = true;
}
//if the item is a change title
else if (item.Contains("###"))
{
//only add a space above the title if it isn't the first title
if (i > 2) { builder.Append("\n"); }
if (!firstTitle) { builder.Append("\n"); }

builder.Append(item.Substring(4));
#if UNITY_2021_2_OR_NEWER
string subTitle = $"<b>{item.Substring(4)}</b>";
#else
string subTitle = item.Substring(4);
#endif
builder.Append(subTitle);
builder.Append("\n");
firstTitle = false;
}
//if the item is a change
else
{
string change = item.Split(new string[] { "([" }, StringSplitOptions.None)[0];
change = change.Replace("*", "-");
change = regexLine.Replace(change, "- $1\n");
change = regexBold.Replace(change, BoldReplace);

builder.Append(change);
}
Expand Down

0 comments on commit 5da522d

Please sign in to comment.