Skip to content

Commit ef8f40e

Browse files
authored
New modding patch: KSPFieldEnumDesc (#243)
1 parent e1a31e7 commit ef8f40e

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

GameData/KSPCommunityFixes/Settings.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ KSP_COMMUNITY_FIXES
460460
// upgrade scripts.
461461
ModUpgradePipeline = false
462462
463+
// Adds display name and localization support for enum KSPFields.
464+
// To use add `Description` attribute to the field.
465+
KSPFieldEnumDesc = false
466+
463467
// ##########################
464468
// Localization tools
465469
// ##########################

KSPCommunityFixes/KSPCommunityFixes.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<Compile Include="Library\LocalizationUtils.cs" />
134134
<Compile Include="Library\Numerics.cs" />
135135
<Compile Include="Library\ObjectPool.cs" />
136+
<Compile Include="Modding\KSPFieldEnumDesc.cs" />
136137
<Compile Include="Modding\ModUpgradePipeline.cs" />
137138
<Compile Include="Performance\AsteroidAndCometDrillCache.cs" />
138139
<Compile Include="BugFixes\DoubleCurvePreserveTangents.cs" />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using HarmonyLib;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace KSPCommunityFixes.Modding
6+
{
7+
public class KSPFieldEnumDesc : BasePatch
8+
{
9+
protected override Version VersionMin => new Version(1, 12, 3);
10+
11+
protected override void ApplyPatches(List<PatchInfo> patches)
12+
{
13+
patches.Add(new PatchInfo(
14+
PatchMethodType.Prefix,
15+
AccessTools.Method(typeof(BaseField), "GetStringValue"),
16+
this));
17+
}
18+
19+
internal static bool BaseField_GetStringValue_Prefix(BaseField __instance, object host, bool gui, ref string __result)
20+
{
21+
if (!gui) return true;
22+
23+
Type fieldType = __instance.FieldInfo.FieldType;
24+
if (fieldType.IsEnum)
25+
{
26+
var val = (Enum)__instance.GetValue(host);
27+
__result = val.displayDescription();
28+
return false;
29+
}
30+
31+
return true;
32+
}
33+
}
34+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
151151
- `R16G16B16A16` : 4 channels (RGBA) uncompressed 64 bpp
152152
- `R16_FLOAT` / `R32_FLOAT` : single channel (R) uncompressed 16/32 bpp
153153
- `R16G16_FLOAT` / `R32G32_FLOAT` : 2 channels (RG) uncompressed 32/64 bpp
154-
- `R16G16B16A16_FLOAT` / `R32G32B32A32_FLOAT` : 4 channels (RGBA) uncompressed 64/128 bpp
154+
- `R16G16B16A16_FLOAT` / `R32G32B32A32_FLOAT` : 4 channels (RGBA) uncompressed 64/128 bpp
155+
- **KSPFieldEnumDesc** [KSP 1.12.2 - 1.12.5]<br/>Disabled by default, you can enable it with a MM patch. Adds display name and localization support for enum KSPFields. To use add `Description` attribute to the field.
155156

156157
#### Stock configs tweaks
157158
- **[ManufacturerFixes](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/62)**<br/>Fix a bunch of stock parts not having manufacturers, add icons for the stock "Stratus Corporation" and "LightYear Tire Company" and two new agents, "FreeFall Parachutes" and "Clamp-O-Tron".

0 commit comments

Comments
 (0)