Skip to content

Commit

Permalink
fix: allow to set specific number of logs to be used from changelog. …
Browse files Browse the repository at this point in the history
…Need to change it atm through code.

Signed-off-by: dragonslaya <dragonslaya.ss@gmail.com>
  • Loading branch information
dragonslaya84 committed Sep 3, 2021
1 parent 6868453 commit d8d28f9
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 81 deletions.
6 changes: 6 additions & 0 deletions Assets/Mirage/Editor/WelcomeWindow/Resources/Changelog.uxml
@@ -0,0 +1,6 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="Header">
<ui:Label text="Version" display-tooltip-when-elided="true" name="ChangeLogVersion" style="font-size: 20px; -unity-font-style: bold;" />
<ui:Label display-tooltip-when-elided="true" name="ChangeLogText" style="-unity-font-style: normal; font-size: 12px;" />
</ui:VisualElement>
</ui:UXML>
10 changes: 10 additions & 0 deletions Assets/Mirage/Editor/WelcomeWindow/Resources/Changelog.uxml.meta

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

145 changes: 72 additions & 73 deletions Assets/Mirage/Editor/WelcomeWindow/Resources/WelcomeWindow.uxml
@@ -1,79 +1,78 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="WelcomeWindow.uss" />
<ui:VisualElement>
<Style src="WelcomeWindow.uss" />
<ui:VisualElement name="Banner">
<ui:Label name="VersionText" text="Placeholder" />
<ui:Image name="Icon" style="background-image: resource('MirageIcon');" />
</ui:VisualElement>
<ui:Label name="Title" text="Welcome to Mirage!" />
<ui:Box name="ColumnContainer" style="flex-grow: 1;">
<ui:VisualElement name="LeftColumnBox">
<ui:Button name="WelcomeButton" text="Welcome" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="QuickStartButton" text="Quick Start Guide" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="PackagesButton" text="Packages" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="FaqButton" text="FAQ" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="BestPracticesButton" text="Best Practices" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="ChangeLogButton" text="Change Log" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="DiscordButton" text="Discord" class="light-selected-tab dark-selected-tab navButton" />
<ui:VisualElement name="Banner">
<ui:Label name="VersionText" text="Placeholder" />
<ui:Image name="Icon" style="background-image: resource(&apos;MirageIcon&apos;);" />
</ui:VisualElement>
<ui:VisualElement name="Spacer" style="display: none;" />
<ui:VisualElement name="RightColumnBox">
<ui:VisualElement name="Welcome" class="screen">
<ui:Label name="Header" text="Welcome" />
<ui:Label name="Description" text="Hello! Thank you for installing Mirage. Please visit all the pages on this window. Clicking the button at the bottom of the pages will redirect you to a webpage. Additionally, there are example projects that you can import from the Unity Package Manager. &#10;&#10;Have fun using Mirage!" style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open Documentation" class="redirect" />
</ui:VisualElement>
<ui:ScrollView name="ChangeLog" class="screen" style="display: none;">
<ui:Label name="Header" text="Change Log" />
<ui:Label text="Version 00.0.0" name="ChangeLogVersion" style="padding-left: 10px; padding-right: 10px; padding-bottom: 5px; font-size: 15px; -unity-text-align: upper-left; -unity-font-style: bold;" />
<ui:Label name="ChangeLogText" style="padding-left: 10px; padding-right: 10px; padding-bottom: 15px;" />
</ui:ScrollView>
<ui:VisualElement name="QuickStart" class="screen" style="display: none;">
<ui:Label name="Header" text="Quick Start Guide" />
<ui:Label name="Description" text="The Quick Start Guide is meant for people who just started using Mirage. The Quick Start Guide will help new users learn how to accomplish important tasks. It is highly recommended that you complete the guide." style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open Quick Start Guide" class="redirect" />
</ui:VisualElement>
<ui:VisualElement name="BestPractices" class="screen" style="display: none;">
<ui:Label name="Header" text="Best Practices" />
<ui:Label name="Description" text="This page describes the best practices that you should use during development. Currently a work in progress." style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open Best Practices Page" class="redirect" />
</ui:VisualElement>
<ui:VisualElement name="Faq" class="screen" style="display: none;">
<ui:Label name="Header" text="FAQ" />
<ui:Label name="Description" text="The FAQ page holds commonly asked questions. Currently, the FAQ page contains answers to: &#10;&#10; 1. Syncing custom data types &#10; 2. How to connect &#10; 3. Host migration &#10; 4. Server lists and matchmaking" style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open FAQ" class="redirect" />
<ui:Label name="Title" text="Welcome to Mirage!" />
<ui:Box name="ColumnContainer" style="flex-grow: 1;">
<ui:VisualElement name="LeftColumnBox">
<ui:Button name="WelcomeButton" text="Welcome" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="QuickStartButton" text="Quick Start Guide" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="PackagesButton" text="Packages" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="FaqButton" text="FAQ" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="BestPracticesButton" text="Best Practices" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="ChangeLogButton" text="Change Log" class="light-selected-tab dark-selected-tab navButton" />
<ui:Button name="DiscordButton" text="Discord" class="light-selected-tab dark-selected-tab navButton" />
</ui:VisualElement>
<ui:VisualElement name="Discord" class="screen" style="display: none;">
<ui:Label name="Header" text="Discord" />
<ui:Label name="Description" text="Mirage has an official Discord channel that you can join. Discord is the best way to contact the developers and request help with your code." style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Join Discord" class="redirect" />
</ui:VisualElement>
<ui:ScrollView name="Packages" class="screen" style="display: none;">
<ui:Label name="Header" text="Packages" />
<ui:Label name="Description" text="Mirage is a modular networking library. It ships with the foundation that you can build upon by installing packages." style="flex-basis: auto; flex-grow: 0; flex-shrink: 0;" />
<ui:Label text="Available Packages" display-tooltip-when-elided="True" style="padding-left: 10px; -unity-font-style: bold;" />
<ui:VisualElement name="ModulesList" style="flex-grow: 1; padding-left: 10px; padding-right: 10px;">
<ui:VisualElement name="Module" tooltip="Automatically find games within the same network.">
<ui:Label text="LAN Discovery" name="Name" />
<ui:Button text="Install" name="InstallButton" class="installButton" />
</ui:VisualElement>
<ui:VisualElement name="Module" tooltip="A transport that uses Facepunch&apos;s Steam SDK.">
<ui:Label text="Steam (Facepunch)" name="Name" />
<ui:Button text="Install" name="InstallButton" class="installButton" />
</ui:VisualElement>
<ui:VisualElement name="Module" tooltip="A transport that uses Steamworks.NET.">
<ui:Label text="Steam (Steamworks.NET)" name="Name" />
<ui:Button text="Install" name="InstallButton" class="installButton" />
</ui:VisualElement>
<ui:VisualElement name="Spacer" style="display: none;" />
<ui:VisualElement name="RightColumnBox">
<ui:VisualElement name="Welcome" class="screen">
<ui:Label name="Header" text="Welcome" />
<ui:Label name="Description" text="Hello! Thank you for installing Mirage. Please visit all the pages on this window. Clicking the button at the bottom of the pages will redirect you to a webpage. Additionally, there are example projects that you can import from the Unity Package Manager. &#10;&#10;Have fun using Mirage!" style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open Documentation" class="redirect" />
</ui:VisualElement>
<ui:VisualElement name="Spacer" />
</ui:ScrollView>
</ui:VisualElement>
</ui:Box>
<ui:ScrollView name="ChangeLog" class="screen" style="display: none;">
<ui:Label name="Header" text="Change Log" />
<ui:VisualElement name="ChangelogData" />
</ui:ScrollView>
<ui:VisualElement name="QuickStart" class="screen" style="display: none;">
<ui:Label name="Header" text="Quick Start Guide" />
<ui:Label name="Description" text="The Quick Start Guide is meant for people who just started using Mirage. The Quick Start Guide will help new users learn how to accomplish important tasks. It is highly recommended that you complete the guide." style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open Quick Start Guide" class="redirect" />
</ui:VisualElement>
<ui:VisualElement name="BestPractices" class="screen" style="display: none;">
<ui:Label name="Header" text="Best Practices" />
<ui:Label name="Description" text="This page describes the best practices that you should use during development. Currently a work in progress." style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open Best Practices Page" class="redirect" />
</ui:VisualElement>
<ui:VisualElement name="Faq" class="screen" style="display: none;">
<ui:Label name="Header" text="FAQ" />
<ui:Label name="Description" text="The FAQ page holds commonly asked questions. Currently, the FAQ page contains answers to: &#10;&#10; 1. Syncing custom data types &#10; 2. How to connect &#10; 3. Host migration &#10; 4. Server lists and matchmaking" style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Open FAQ" class="redirect" />
</ui:VisualElement>
<ui:VisualElement name="Discord" class="screen" style="display: none;">
<ui:Label name="Header" text="Discord" />
<ui:Label name="Description" text="Mirage has an official Discord channel that you can join. Discord is the best way to contact the developers and request help with your code." style="-unity-text-align: upper-left;" />
<ui:VisualElement name="Spacer" />
<ui:Button name="Redirect" text="Join Discord" class="redirect" />
</ui:VisualElement>
<ui:ScrollView name="Packages" class="screen" style="display: none;">
<ui:Label name="Header" text="Packages" />
<ui:Label name="Description" text="Mirage is a modular networking library. It ships with the foundation that you can build upon by installing packages." style="flex-basis: auto; flex-grow: 0; flex-shrink: 0;" />
<ui:Label text="Available Packages" display-tooltip-when-elided="True" style="padding-left: 10px; -unity-font-style: bold;" />
<ui:VisualElement name="ModulesList" style="flex-grow: 1; padding-left: 10px; padding-right: 10px;">
<ui:VisualElement name="Module" tooltip="Automatically find games within the same network.">
<ui:Label text="LAN Discovery" name="Name" />
<ui:Button text="Install" name="InstallButton" class="installButton" />
</ui:VisualElement>
<ui:VisualElement name="Module" tooltip="A transport that uses Facepunch&apos;s Steam SDK.">
<ui:Label text="Steam (Facepunch)" name="Name" />
<ui:Button text="Install" name="InstallButton" class="installButton" />
</ui:VisualElement>
<ui:VisualElement name="Module" tooltip="A transport that uses Steamworks.NET.">
<ui:Label text="Steam (Steamworks.NET)" name="Name" />
<ui:Button text="Install" name="InstallButton" class="installButton" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="Spacer" />
</ui:ScrollView>
</ui:VisualElement>
</ui:Box>
</ui:VisualElement>
</ui:UXML>
32 changes: 24 additions & 8 deletions Assets/Mirage/Editor/WelcomeWindow/WelcomeWindow.cs
Expand Up @@ -55,6 +55,7 @@ public class WelcomeWindow : EditorWindow
private static ListRequest listRequest;

private static WelcomeWindow currentWindow;
private static VisualTreeAsset _changeLogTemplate;

//window size of the welcome screen
private static Vector2 windowSize = new Vector2(500, 415);
Expand All @@ -64,6 +65,7 @@ public class WelcomeWindow : EditorWindow
private static string firstStartUpKey = string.Empty;
private const string firstTimeMirageKey = "MirageWelcome";
private const string miragePackageName = "com.miragenet.mirage";
private const int _numberOfChangeLogs = 3;

/// <summary>
/// Hard coded for source code version. If package version is found, this will
Expand Down Expand Up @@ -148,6 +150,8 @@ private void OnEnable()
VisualTreeAsset uxml = Resources.Load<VisualTreeAsset>("WelcomeWindow");
StyleSheet uss = Resources.Load<StyleSheet>("WelcomeWindow");

_changeLogTemplate = Resources.Load<VisualTreeAsset>("Changelog");

root.styleSheets.Add(uss);
uxml.CloneTree(root);

Expand Down Expand Up @@ -257,6 +261,8 @@ private List<string> ParseChangeLog()
{
var content = new List<string>();

int currentChangeLogs = 0;

using (var reader = new StreamReader(changeLogPath))
{
string line;
Expand All @@ -276,7 +282,12 @@ private List<string> ParseChangeLog()

//if we havent reached the next version yet
if (line.Contains("https://github.com/MirageNet/Mirage/compare/"))
break;
{
if (currentChangeLogs == _numberOfChangeLogs)
break;

currentChangeLogs++;
}

content.Add(line);
}
Expand All @@ -288,7 +299,7 @@ private List<string> ParseChangeLog()
//draw the parsed information
private void DrawChangeLog(List<string> content)
{
Label changeLogText = rootVisualElement.Q<Label>("ChangeLogText");
int currentVersionCount = -1;

for (int i = 0; i < content.Count; i++)
{
Expand All @@ -297,23 +308,28 @@ private void DrawChangeLog(List<string> content)
//if the item is a version
if (item.Contains("# [") || item.Contains("## ["))
{
string version = GetVersion();
rootVisualElement.Q<Label>("ChangeLogVersion").text = "Version " + version.Substring(0, version.Length - 2);
currentVersionCount++;

TemplateContainer newLog = _changeLogTemplate.CloneTree();
newLog.Q<Label>("ChangeLogVersion").text =
$"Version {item.Split(new[] {"["}, StringSplitOptions.RemoveEmptyEntries)[1].Split(new[] {"]"}, StringSplitOptions.RemoveEmptyEntries)[0]}";

rootVisualElement.Q<VisualElement>("ChangelogData").Add(newLog);
}
//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) { changeLogText.text += "\n"; }
if (i > 2) { rootVisualElement.Q<VisualElement>("ChangelogData").ElementAt(currentVersionCount).Q<Label>("ChangeLogText").text += "\n"; }

changeLogText.text += item.Substring(4) + "\n";
rootVisualElement.Q<VisualElement>("ChangelogData").ElementAt(currentVersionCount).Q<Label>("ChangeLogText").text += item.Substring(4) + "\n";
}
//if the item is a change
else
{
string change = item.Split(new string[] { "([" }, StringSplitOptions.None)[0];
string change = item.Split(new[] { "([" }, StringSplitOptions.None)[0];
change = change.Replace("*", "-");
changeLogText.text += change + "\n";
rootVisualElement.Q<VisualElement>("ChangelogData").ElementAt(currentVersionCount).Q<Label>("ChangeLogText").text += change + "\n";
}
}
}
Expand Down

0 comments on commit d8d28f9

Please sign in to comment.