Skip to content

Commit

Permalink
Icons fix (#173)
Browse files Browse the repository at this point in the history
* Icons: Creat an Initialize method and call it in MainMenu Scene

* .editorconfig: Fix typos

* Build: Add .editorconfig to /src and .csproj so VS uses it

* Lib: Add texture scaling methods

* Icons: Dont scale app icon

* Icons: Use new scaling methods

* CHANGELOG.md: Add icon scaling bug fix info

* Build: Release dll (v.1.8.0)
  • Loading branch information
PiezPiedPy authored and steamport committed Aug 21, 2018
1 parent 77afe79 commit fb8667a
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 152 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
end_of_line = crlf

# Code files
[*.cs,*.csx,*.vb,*.vbx]

[*.{cs,csx,vb,vbx}]
insert_final_newline = true
indent_style = tab
indent_size = 4
tab_width = 4
trim_trailing_whitespace = true

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

* Kerbalism documents are now available here: https://kerbalism.readthedocs.io Note they are still a Work in Progress

* Fixed the icons sometimes not displaying bug (PiezPiedPy)
* Fixed the icons sometimes not displaying bug and icon scaling bug (PiezPiedPy)
* RemoteTech support now integrates correctly with the planner and signal system (PiezPiedPy)
* Improved RemoteTech support (simulate in planner buttons, reliability, antenna EC consumption) (Gordon Dry & PiezPiedPy)
* RemoteTech antennas will need power even if vessel is unloaded (Sir Mortimer)
Expand Down
Binary file modified GameData/Kerbalism/Kerbalism.dll
Binary file not shown.
13 changes: 13 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = crlf

# Code files
[*.{cs,csx,vb,vbx}]
insert_final_newline = true
indent_style = tab
indent_size = 4
tab_width = 4
trim_trailing_whitespace = true

139 changes: 70 additions & 69 deletions src/Kerbalism.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,75 +99,75 @@
<DefineConstants>KSP13</DefineConstants>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>
<Choose>
<When Condition="'$(Configuration)'=='Release' Or '$(Configuration)'=='Debug'">
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript-firstpass">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript-firstpass">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
<Choose>
<When Condition="'$(Configuration)'=='Release' Or '$(Configuration)'=='Debug'">
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript-firstpass">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-UnityScript-firstpass">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Reference Include="System">
Expand Down Expand Up @@ -321,6 +321,7 @@
<None Include="..\GameData\Kerbalism\Kerbalism.version">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include=".editorconfig" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="PostBuildMacros">
Expand Down
53 changes: 44 additions & 9 deletions src/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,23 +1382,57 @@ public static int CountTech(string[] techs)

// --- ASSETS ---------------------------------------------------------------

// return path of directory containing the DLL
///<summary> Returns the path of the directory containing the DLL </summary>
public static string Directory()
{
string dll_path = Assembly.GetExecutingAssembly().Location;
return dll_path.Substring(0, dll_path.LastIndexOf(Path.DirectorySeparatorChar));
}

// get a texture
public static Texture2D GetTexture(string name)
///<summary> Loads a .png texture from the folder defined in <see cref="Icons.TexturePath"/> </summary>
public static Texture2D GetTexture(string name, int width = 16, int height = 16)
{
Texture2D texture = new Texture2D(36, 36);
Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
texture.LoadImage(System.IO.File.ReadAllBytes(Icons.TexturePath + name + ".png"));
return texture;
}

// get a material with the shader specified
static Dictionary<string, Material> shaders;
///<summary> Returns a scaled copy of the source texture </summary>
public static Texture2D ScaledTexture(Texture2D src, int width, int height, FilterMode mode = FilterMode.Trilinear)
{
ScaleWithGPU(src, width, height, mode);

Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
texture.Resize(width, height);
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
return texture;
}

///<summary> Scales the texture data of the source texture </summary>
public static void ScaleTexture(Texture2D texture, int width, int height, FilterMode mode = FilterMode.Trilinear)
{
ScaleWithGPU(texture, width, height, mode);

texture.Resize(width, height);
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
texture.Apply(true);
}

///<summary>Renders the source texture into the RTT - used by the scaling methods ScaledTexture() and ScaleTexture() </summary>
private static void ScaleWithGPU(Texture2D src, int width, int height, FilterMode fmode)
{
src.filterMode = fmode;
src.Apply(true);

RenderTexture rtt = new RenderTexture(width, height, 32);
Graphics.SetRenderTarget(rtt);
GL.LoadPixelMatrix(0, 1, 1, 0);
GL.Clear(true, true, new Color(0, 0, 0, 0));
Graphics.DrawTexture(new Rect(0, 0, 1, 1), src);
}

public static Dictionary<string, Material> shaders;
///<summary> Returns a material from the specified shader </summary>
public static Material GetShader(string name)
{
if (shaders == null)
Expand All @@ -1413,8 +1447,9 @@ public static Material GetShader(string name)
Shader[] pre_shaders = bundle.LoadAllAssets<Shader>();
foreach (Shader shader in pre_shaders)
{
var key = shader.name.Replace("Custom/", string.Empty);
if (shaders.ContainsKey(key)) shaders.Remove(key);
string key = shader.name.Replace("Custom/", string.Empty);
if (shaders.ContainsKey(key))
shaders.Remove(key);
shaders.Add(key, new Material(shader));
}
bundle.Unload(false);
Expand Down Expand Up @@ -1659,4 +1694,4 @@ public static String FormatSI(double value, String unit)
}


} // KERBALISM
} // KERBALISM
1 change: 1 addition & 0 deletions src/System/Kerbalism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class KerbalismMain: MonoBehaviour
{
public void Start()
{
Icons.Initialize(); // set up the icon textures
RemoteTech.EnableInSPC(); // allow RemoteTech Core to run in the Space Center

// Set the loaded trigger to false, this we will load a new
Expand Down

0 comments on commit fb8667a

Please sign in to comment.