Skip to content

Commit

Permalink
added mod version to title bar of window
Browse files Browse the repository at this point in the history
  • Loading branch information
AmberCronin committed Oct 27, 2018
1 parent a0feaa1 commit 345d404
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 9 deletions.
99 changes: 95 additions & 4 deletions Changelog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using UnityEngine;
using System.Linq;
using System.Text.RegularExpressions;

namespace KerbalChangelog
{
Expand Down Expand Up @@ -46,7 +47,7 @@ private Changelog()
Vector2 changelogScrollPos = new Vector2();
Vector2 quickSelectionScrollPos = new Vector2();
//Dictionary<string, string> modChangelogs = new Dictionary<string, string>();
List<Tuple<string, string>> modChangelogs= new List<Tuple<string, string>>();
List<Tuple<string, string, string>> modChangelogs= new List<Tuple<string, string, string>>();
int index = 0;
bool changesLoaded = false;
float widthMultiplier = Screen.width / 1920f;
Expand All @@ -66,7 +67,7 @@ private void OnGUI()
{
if (showChangelog && changesLoaded && modChangelogs.Count > 0 && !changelogSelection)
{
changelogRect = GUILayout.Window(89156, changelogRect, DrawChangelogWindow, modChangelogs[index].item1, GUILayout.Width(windowWidth), GUILayout.Height(windowHeight));
changelogRect = GUILayout.Window(89156, changelogRect, DrawChangelogWindow, modChangelogs[index].item1 + " " + modChangelogs[index].item3, GUILayout.Width(windowWidth), GUILayout.Height(windowHeight));
}
else if (showChangelog && changesLoaded && modChangelogs.Count > 0 && changelogSelection)
{
Expand All @@ -84,7 +85,7 @@ private void DrawChangelogSelectionWindow(int id)
}
GUILayout.EndHorizontal();
quickSelectionScrollPos = GUILayout.BeginScrollView(quickSelectionScrollPos);
foreach(Tuple<string, string> modChange in modChangelogs)
foreach(Tuple<string, string, string> modChange in modChangelogs)
{
if(GUILayout.Button(modChange.item1))
{
Expand Down Expand Up @@ -156,21 +157,23 @@ private void LoadChangelogs()
string mod = cln.GetValue("modName");
Debug.Log($"[KCL] {mod}'s changelog is being displayed: {show}");
string modChangelog = "";
List<string> version = new List<string>();
foreach(ConfigNode vn in cln.GetNodes("VERSION"))
{
if(!firstVersionNumber)
{
modChangelog += "\n";
}
firstVersionNumber = false;
version.Add(vn.GetValue("version"));
modChangelog += (vn.GetValue("version") + ":\n");
foreach(string change in vn.GetValues("change"))
{
modChangelog += ("* " + change + "\n");
}
}
Debug.Log($"[KCL] Adding changelog\n{modChangelog} for mod {mod}");
modChangelogs.Add(new Tuple<string, string>(mod, modChangelog));
modChangelogs.Add(new Tuple<string, string, string>(mod, modChangelog, HighestVersion(version)));
if (!cln.SetValue("showChangelog", false))
{
Debug.Log("[KCL] Unable to set value 'showChangelog'.");
Expand All @@ -185,5 +188,93 @@ private void LoadChangelogs()
}
changesLoaded = true;
}
private string HighestVersion(List<string> versions)
{
Debug.Log("[KCL] Getting highest version...");
int numOfMajMinRevs = 0;
Debug.Log("[KCL] Finding the maximum version length");
for (int i = 0; i < versions.Count; i++)
{
if(NumberOfVersionSeperators(versions[i]) > numOfMajMinRevs)
{
numOfMajMinRevs = NumberOfVersionSeperators(versions[i]) + 1; //because this only returns the number of periods in the version string
}
}
Debug.Log($"[KCL] Filling version array: int[{versions.Count}, {numOfMajMinRevs}]");
int[,] versionArray = new int[versions.Count, numOfMajMinRevs];
FillArray(ref versionArray, -1);
Debug.Log("[KCL] Populating version array (string parsing)");
for(int i = 0; i < versions.Count; i++)
{
for(int j = 0; j < NumberOfVersionSeperators(versions[i]) + 1; j++)
{
Debug.Log($"[KCL] i={i}, j={j} in string parsing");
if(int.TryParse(versions[i].Split('.')[j], out _))
{
versionArray[i, j] = int.Parse(versions[i].Split('.')[j]);
Debug.Log($"[KCL] Filled versionArray[{i}, {j}] with value {versionArray[i, j]}");
}
else
{
Debug.Log($"[KCL] Could not parse parital version {j} of {versions[i]} as it is not an integer value");
versionArray[i, j] = -1;
}
}
}
int[] largestVersion = new int[numOfMajMinRevs];
FillArray(ref largestVersion, -1);
Debug.Log("[KCL] Deterniming largest version");
for(int i = 0; i < numOfMajMinRevs; i++)
{
for(int j = 0; j < versionArray.GetLength(0); j++)
{
if (versionArray[j, i] > largestVersion[i])
{
Debug.Log($"[KCL] Filling largestVersion[{i}] with {versionArray[j, i]}");
largestVersion[i] = versionArray[j, i];
}
}
}
string version = "v";
for(int i = 0; i < largestVersion.Length; i++)
{
if(largestVersion[i] != -1)
{
version += ("." + largestVersion[i].ToString());
}
}
Debug.Log("[KCL] Largest version is " + version);
return version;
}
private void FillArray(ref int[] array, int num)
{
for(int i = 0; i < array.Length; i++)
{
array[i] = num;
}
}
private void FillArray(ref int[,] array, int num)
{
for (int i = 0; i < array.GetLength(0); i++)
{
for(int j = 0; j < array.GetLength(1); j++)
{
array[i, j] = num;
}
}
}
private int NumberOfVersionSeperators(string version)
{
int periods = 0;
char[] charVersion = version.ToCharArray();
foreach(char c in charVersion)
{
if(c == '.')
{
periods++;
}
}
return periods;
}
}
}
10 changes: 5 additions & 5 deletions KerbalChangelog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<OutputType>Library</OutputType>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>KerbalChangelog</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -32,11 +32,11 @@
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.4.3 dependencies\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.5.1 Dependencies\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.4.3 dependencies\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.5.1 Dependencies\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
Expand All @@ -47,11 +47,11 @@
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.4.3 dependencies\UnityEngine.dll</HintPath>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.5.1 Dependencies\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.4.3 dependencies\UnityEngine.UI.dll</HintPath>
<HintPath>..\..\..\Desktop\KSP Mod stuff\KSP 1.5.1 Dependencies\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 345d404

Please sign in to comment.