Skip to content

Commit

Permalink
v2.5.0 : KSP 0.25 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Oct 6, 2014
1 parent 79fd3aa commit ac11324
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("2.4.5")]
[assembly: KSPAssembly("ModuleManager", 2, 4)]
[assembly: AssemblyVersion("2.5.0")]
[assembly: KSPAssembly("ModuleManager", 2, 5)]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
73 changes: 73 additions & 0 deletions Properties/Resources.Designer.cs

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

124 changes: 124 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="cat" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>cat;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
Binary file added Properties/cat
Binary file not shown.
103 changes: 83 additions & 20 deletions moduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class ModuleManager : MonoBehaviour

private string version = "";

private Texture2D tex;
private Texture2D tex2;
private int activePos = 0;

#endregion state

#region Top Level - Update
Expand Down Expand Up @@ -76,10 +80,7 @@ internal void Awake()
log("Can't find LoadingScreen type. Aborting ModuleManager execution");
return;
}
Type lsType = typeof (LoadingScreen);
List<LoadingSystem> list = (from fld in lsType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
where fld.FieldType == typeof (List<LoadingSystem>)
select (List<LoadingSystem>) fld.GetValue(screen)).FirstOrDefault();
List<LoadingSystem> list = LoadingScreen.Instance.loaders;

if (list != null)
{
Expand All @@ -97,6 +98,13 @@ internal void Awake()
else
Debug.LogWarning("Can't find the LoadingSystem list. Aborting ModuleManager execution");

tex = new Texture2D(33, 20, TextureFormat.ARGB32, false);
tex.LoadImage(Properties.Resources.cat);
Color[] pix = tex.GetPixels(0, 0, 1, tex.height);
tex2 = new Texture2D(1, 20, TextureFormat.ARGB32, false);
tex2.SetPixels(pix);
tex2.Apply();

loadedInScene = true;
}

Expand Down Expand Up @@ -134,29 +142,81 @@ public void OnGUI()
{
if (HighLogic.LoadedScene == GameScenes.LOADING && MMPatchLoader.Instance != null)
{
float offsetY = Mathf.FloorToInt(0.8f * Screen.height);

if (IsWin64())
{
var centeredWarningStyle = new GUIStyle(GUI.skin.GetStyle("Label"))
{
alignment = TextAnchor.UpperCenter,
fontSize = 16,
normal = { textColor = Color.yellow }
};
const string warning = "You are using 64-bit KSP on Windows. This version of KSP is known to cause crashes unrelated to mods.";
Vector2 sizeOfWarningLabel = centeredWarningStyle.CalcSize(new GUIContent(warning));

GUI.Label(new Rect(Screen.width / 2f - (sizeOfWarningLabel.x / 2f), offsetY, sizeOfWarningLabel.x, sizeOfWarningLabel.y), warning, centeredWarningStyle);
offsetY += sizeOfWarningLabel.y;
}

var centeredStyle = new GUIStyle(GUI.skin.GetStyle("Label"))
{
alignment = TextAnchor.UpperCenter,
fontSize = 16
};
Vector2 sizeOfLabel = centeredStyle.CalcSize(new GUIContent(MMPatchLoader.Instance.status));
GUI.Label(
new Rect(Screen.width/2 - (sizeOfLabel.x/2), Mathf.FloorToInt(0.8f*Screen.height), sizeOfLabel.x,
sizeOfLabel.y), MMPatchLoader.Instance.status, centeredStyle);
GUI.Label(new Rect(Screen.width / 2f - (sizeOfLabel.x / 2f), offsetY, sizeOfLabel.x, sizeOfLabel.y), MMPatchLoader.Instance.status, centeredStyle);
offsetY += sizeOfLabel.y;

if (MMPatchLoader.Instance.errorCount > 0)
{
var errorStyle = new GUIStyle(GUI.skin.GetStyle("Label"));
errorStyle.alignment = TextAnchor.UpperLeft;
errorStyle.fontSize = 16;
var errorStyle = new GUIStyle(GUI.skin.GetStyle("Label"))
{
alignment = TextAnchor.UpperLeft,
fontSize = 16
};
Vector2 sizeOfError = errorStyle.CalcSize(new GUIContent(MMPatchLoader.Instance.errors));
GUI.Label(
new Rect(Screen.width/2 - (sizeOfLabel.x/2),
Mathf.FloorToInt(0.8f*Screen.height) + sizeOfLabel.y, sizeOfError.x, sizeOfError.y),
MMPatchLoader.Instance.errors, errorStyle);
GUI.Label(new Rect(Screen.width / 2f - (sizeOfLabel.x / 2), offsetY, sizeOfError.x, sizeOfError.y), MMPatchLoader.Instance.errors, errorStyle);
offsetY += sizeOfError.y;
}


if (IsWin64())
{
GUI.color = Color.white;
int scale = 1;
if (Screen.height >= 1080)
scale = 2;
if (Screen.height > 1440)
scale = 3;

int trailLength = 8 * tex.width * scale;
int totalLenth = trailLength + tex.width * scale;
int startPos = activePos - totalLenth;

Color guiColor = Color.white;
int currentOffset = 0;
int heightOffset = 0;
while (currentOffset <= trailLength)
{
guiColor.a = (float)currentOffset / (float)trailLength;
GUI.color = guiColor;

heightOffset = Mathf.RoundToInt(1f + Mathf.Sin(2f * Mathf.PI * (startPos + currentOffset) / (Screen.width / 6f)) * (tex.height * scale / 6f));

GUI.DrawTexture(new Rect(startPos + currentOffset, heightOffset + offsetY, tex2.width, tex2.height * scale), tex2);
currentOffset++;
}
GUI.DrawTexture(new Rect(startPos + currentOffset, heightOffset + offsetY, tex.width * scale, tex.height * scale), tex);

activePos = (activePos + 3) % (Screen.width + totalLenth);
GUI.color = Color.white;
}


}


if (showUI &&
(HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.MAINMENU) &&
!inRnDCenter)
Expand All @@ -171,6 +231,11 @@ public void OnGUI()
}
}

public static bool IsWin64()
{
return (IntPtr.Size == 8) && (Environment.OSVersion.Platform == PlatformID.Win32NT);
}

protected void WindowGUI(int windowID)
{
GUILayout.BeginVertical();
Expand Down Expand Up @@ -343,7 +408,8 @@ public class MMPatchLoader : LoadingSystem

private static ConfigNode topNode;

private static List<ModuleManagerPostPatchCallback> postPatchCallbacks = new List<ModuleManagerPostPatchCallback>();
private static List<ModuleManagerPostPatchCallback> postPatchCallbacks =
new List<ModuleManagerPostPatchCallback>();

public static MMPatchLoader Instance { get; private set; }

Expand Down Expand Up @@ -600,13 +666,11 @@ private IEnumerator ProcessPatch(List<String> excludePaths)
yield return null;

ready = true;

}

private void StatusUpdate()
{
status = "ModuleManager: " + patchedNodeCount + " patch" + (patchedNodeCount != 1 ? "es" : "") + " applied" +
", " + needsUnsatisfiedCount + " hidden item" + (needsUnsatisfiedCount != 1 ? "s" : "");
status = "ModuleManager: " + patchedNodeCount + " patch" + (patchedNodeCount != 1 ? "es" : "") + " applied";

if (errorCount > 0)
status += ", found " + errorCount + " error" + (errorCount != 1 ? "s" : "");
Expand Down Expand Up @@ -1069,7 +1133,7 @@ public ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
break;

case Command.Rename:
if ( nodeStack.Count == 1)
if (nodeStack.Count == 1)
{
log("Renaming nodes does not work on top nodes");
errorCount++;
Expand Down Expand Up @@ -1264,7 +1328,6 @@ private static string RecurseVariableSearch(string path, ConfigNode currentNode)
//log("path:" + path);
if (path[0] == '/')
return RecurseVariableSearch(path.Substring(1), topNode);

int nextSep = path.IndexOf('/');

// make sure we don't stop on a ",/" which would be a value separator
Expand Down

0 comments on commit ac11324

Please sign in to comment.