Skip to content

Commit fb8667a

Browse files
PiezPiedPysteamport
authored and
steamport
committed
Icons fix (Kerbalism#173)
* 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)
1 parent 77afe79 commit fb8667a

File tree

9 files changed

+262
-152
lines changed

9 files changed

+262
-152
lines changed

.editorconfig

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
end_of_line = crlf
33

44
# Code files
5-
[*.cs,*.csx,*.vb,*.vbx]
6-
5+
[*.{cs,csx,vb,vbx}]
6+
insert_final_newline = true
77
indent_style = tab
88
indent_size = 4
9+
tab_width = 4
910
trim_trailing_whitespace = true
1011

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
* Fixed the icons sometimes not displaying bug (PiezPiedPy)
8+
* Fixed the icons sometimes not displaying bug and icon scaling bug (PiezPiedPy)
99
* RemoteTech support now integrates correctly with the planner and signal system (PiezPiedPy)
1010
* Improved RemoteTech support (simulate in planner buttons, reliability, antenna EC consumption) (Gordon Dry & PiezPiedPy)
1111
* RemoteTech antennas will need power even if vessel is unloaded (Sir Mortimer)

GameData/Kerbalism/Kerbalism.dll

512 Bytes
Binary file not shown.

src/.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = crlf
5+
6+
# Code files
7+
[*.{cs,csx,vb,vbx}]
8+
insert_final_newline = true
9+
indent_style = tab
10+
indent_size = 4
11+
tab_width = 4
12+
trim_trailing_whitespace = true
13+

src/Kerbalism.csproj

+70-69
Original file line numberDiff line numberDiff line change
@@ -99,75 +99,75 @@
9999
<DefineConstants>KSP13</DefineConstants>
100100
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
101101
</PropertyGroup>
102-
<Choose>
103-
<When Condition="'$(Configuration)'=='Release' Or '$(Configuration)'=='Debug'">
104-
<ItemGroup>
105-
<Reference Include="Assembly-CSharp">
106-
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
107-
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
108-
<Private>False</Private>
109-
</Reference>
110-
<Reference Include="Assembly-CSharp-firstpass">
111-
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
112-
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
113-
<Private>False</Private>
114-
</Reference>
115-
<Reference Include="Assembly-UnityScript">
116-
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
117-
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
118-
<Private>False</Private>
119-
</Reference>
120-
<Reference Include="Assembly-UnityScript-firstpass">
121-
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
122-
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
123-
<Private>False</Private>
124-
</Reference>
125-
<Reference Include="UnityEngine">
126-
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
127-
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
128-
<Private>False</Private>
129-
</Reference>
130-
<Reference Include="UnityEngine.UI">
131-
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
132-
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
133-
<Private>False</Private>
134-
</Reference>
135-
</ItemGroup>
136-
</When>
137-
<Otherwise>
138-
<ItemGroup>
139-
<Reference Include="Assembly-CSharp">
140-
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
141-
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
142-
<Private>False</Private>
143-
</Reference>
144-
<Reference Include="Assembly-CSharp-firstpass">
145-
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
146-
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
147-
<Private>False</Private>
148-
</Reference>
149-
<Reference Include="Assembly-UnityScript">
150-
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
151-
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
152-
<Private>False</Private>
153-
</Reference>
154-
<Reference Include="Assembly-UnityScript-firstpass">
155-
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
156-
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
157-
<Private>False</Private>
158-
</Reference>
159-
<Reference Include="UnityEngine">
160-
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
161-
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
162-
<Private>False</Private>
163-
</Reference>
164-
<Reference Include="UnityEngine.UI">
165-
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
166-
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
167-
<Private>False</Private>
168-
</Reference>
169-
</ItemGroup>
170-
</Otherwise>
102+
<Choose>
103+
<When Condition="'$(Configuration)'=='Release' Or '$(Configuration)'=='Debug'">
104+
<ItemGroup>
105+
<Reference Include="Assembly-CSharp">
106+
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
107+
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
108+
<Private>False</Private>
109+
</Reference>
110+
<Reference Include="Assembly-CSharp-firstpass">
111+
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
112+
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
113+
<Private>False</Private>
114+
</Reference>
115+
<Reference Include="Assembly-UnityScript">
116+
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
117+
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
118+
<Private>False</Private>
119+
</Reference>
120+
<Reference Include="Assembly-UnityScript-firstpass">
121+
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
122+
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
123+
<Private>False</Private>
124+
</Reference>
125+
<Reference Include="UnityEngine">
126+
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
127+
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
128+
<Private>False</Private>
129+
</Reference>
130+
<Reference Include="UnityEngine.UI">
131+
<HintPath Condition="Exists('$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPDEVDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
132+
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
133+
<Private>False</Private>
134+
</Reference>
135+
</ItemGroup>
136+
</When>
137+
<Otherwise>
138+
<ItemGroup>
139+
<Reference Include="Assembly-CSharp">
140+
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
141+
<HintPath Condition="Exists('.\Assembly-CSharp.dll')">.\Assembly-CSharp.dll</HintPath>
142+
<Private>False</Private>
143+
</Reference>
144+
<Reference Include="Assembly-CSharp-firstpass">
145+
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
146+
<HintPath Condition="Exists('.\Assembly-CSharp-firstpass.dll')">.\Assembly-CSharp-firstpass.dll</HintPath>
147+
<Private>False</Private>
148+
</Reference>
149+
<Reference Include="Assembly-UnityScript">
150+
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript.dll</HintPath>
151+
<HintPath Condition="Exists('.\Assembly-UnityScript.dll')">.\Assembly-UnityScript.dll</HintPath>
152+
<Private>False</Private>
153+
</Reference>
154+
<Reference Include="Assembly-UnityScript-firstpass">
155+
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\Assembly-UnityScript-firstpass.dll</HintPath>
156+
<HintPath Condition="Exists('.\Assembly-UnityScript-firstpass.dll')">.\Assembly-UnityScript-firstpass.dll</HintPath>
157+
<Private>False</Private>
158+
</Reference>
159+
<Reference Include="UnityEngine">
160+
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
161+
<HintPath Condition="Exists('.\UnityEngine.dll')">.\UnityEngine.dll</HintPath>
162+
<Private>False</Private>
163+
</Reference>
164+
<Reference Include="UnityEngine.UI">
165+
<HintPath Condition="Exists('$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll')">$(KSPBACKPORTDIR)\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
166+
<HintPath Condition="Exists('.\UnityEngine.UI.dll')">.\UnityEngine.UI.dll</HintPath>
167+
<Private>False</Private>
168+
</Reference>
169+
</ItemGroup>
170+
</Otherwise>
171171
</Choose>
172172
<ItemGroup>
173173
<Reference Include="System">
@@ -321,6 +321,7 @@
321321
<None Include="..\GameData\Kerbalism\Kerbalism.version">
322322
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
323323
</None>
324+
<None Include=".editorconfig" />
324325
</ItemGroup>
325326
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
326327
<Target Name="PostBuildMacros">

src/Lib.cs

+44-9
Original file line numberDiff line numberDiff line change
@@ -1382,23 +1382,57 @@ public static int CountTech(string[] techs)
13821382

13831383
// --- ASSETS ---------------------------------------------------------------
13841384

1385-
// return path of directory containing the DLL
1385+
///<summary> Returns the path of the directory containing the DLL </summary>
13861386
public static string Directory()
13871387
{
13881388
string dll_path = Assembly.GetExecutingAssembly().Location;
13891389
return dll_path.Substring(0, dll_path.LastIndexOf(Path.DirectorySeparatorChar));
13901390
}
13911391

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

1400-
// get a material with the shader specified
1401-
static Dictionary<string, Material> shaders;
1400+
///<summary> Returns a scaled copy of the source texture </summary>
1401+
public static Texture2D ScaledTexture(Texture2D src, int width, int height, FilterMode mode = FilterMode.Trilinear)
1402+
{
1403+
ScaleWithGPU(src, width, height, mode);
1404+
1405+
Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
1406+
texture.Resize(width, height);
1407+
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
1408+
return texture;
1409+
}
1410+
1411+
///<summary> Scales the texture data of the source texture </summary>
1412+
public static void ScaleTexture(Texture2D texture, int width, int height, FilterMode mode = FilterMode.Trilinear)
1413+
{
1414+
ScaleWithGPU(texture, width, height, mode);
1415+
1416+
texture.Resize(width, height);
1417+
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
1418+
texture.Apply(true);
1419+
}
1420+
1421+
///<summary>Renders the source texture into the RTT - used by the scaling methods ScaledTexture() and ScaleTexture() </summary>
1422+
private static void ScaleWithGPU(Texture2D src, int width, int height, FilterMode fmode)
1423+
{
1424+
src.filterMode = fmode;
1425+
src.Apply(true);
1426+
1427+
RenderTexture rtt = new RenderTexture(width, height, 32);
1428+
Graphics.SetRenderTarget(rtt);
1429+
GL.LoadPixelMatrix(0, 1, 1, 0);
1430+
GL.Clear(true, true, new Color(0, 0, 0, 0));
1431+
Graphics.DrawTexture(new Rect(0, 0, 1, 1), src);
1432+
}
1433+
1434+
public static Dictionary<string, Material> shaders;
1435+
///<summary> Returns a material from the specified shader </summary>
14021436
public static Material GetShader(string name)
14031437
{
14041438
if (shaders == null)
@@ -1413,8 +1447,9 @@ public static Material GetShader(string name)
14131447
Shader[] pre_shaders = bundle.LoadAllAssets<Shader>();
14141448
foreach (Shader shader in pre_shaders)
14151449
{
1416-
var key = shader.name.Replace("Custom/", string.Empty);
1417-
if (shaders.ContainsKey(key)) shaders.Remove(key);
1450+
string key = shader.name.Replace("Custom/", string.Empty);
1451+
if (shaders.ContainsKey(key))
1452+
shaders.Remove(key);
14181453
shaders.Add(key, new Material(shader));
14191454
}
14201455
bundle.Unload(false);
@@ -1659,4 +1694,4 @@ public static String FormatSI(double value, String unit)
16591694
}
16601695

16611696

1662-
} // KERBALISM
1697+
} // KERBALISM

src/System/Kerbalism.cs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class KerbalismMain: MonoBehaviour
1414
{
1515
public void Start()
1616
{
17+
Icons.Initialize(); // set up the icon textures
1718
RemoteTech.EnableInSPC(); // allow RemoteTech Core to run in the Space Center
1819

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

0 commit comments

Comments
 (0)