Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed Nov 19, 2021
2 parents 27c5747 + 388659f commit f24f2af
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 18 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 3, "PATCH": 0, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 4, "PATCH": 0, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 2},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 2}
Expand Down
Binary file modified GameData/KSPCommunityFixes/Plugins/0_MultipleModuleInPartAPI.dll
Binary file not shown.
Binary file modified GameData/KSPCommunityFixes/Plugins/KSPCommunityFixes.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ KSP_COMMUNITY_FIXES

// Allow tweaking the autostrut mode of wheels/landing legs
TweakableWheelsAutostrut = true

// Allow numeric input ("#" button) in "float edit" PAW items
UIFloatEditNumericInput = true
}
5 changes: 4 additions & 1 deletion KSPCommunityFixes/BugFixes/FlightSceneLoadKraken.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System;
using HarmonyLib;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -7,6 +8,8 @@ namespace KSPCommunityFixes
{
class FlightSceneLoadKraken : BasePatch
{
protected override Version VersionMin => new Version(1, 8, 0);

protected override void ApplyPatches(ref List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
Expand Down
2 changes: 2 additions & 0 deletions KSPCommunityFixes/BugFixes/PAWGroupMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace KSPCommunityFixes
{
public class PAWGroupMemory : BasePatch
{
protected override Version VersionMin => new Version(1, 8, 0);

private static Dictionary<int, Dictionary<string, bool>> collapseState;

protected override void ApplyPatches(ref List<PatchInfo> patches)
Expand Down
13 changes: 9 additions & 4 deletions KSPCommunityFixes/BugFixes/PAWItemOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace KSPCommunityFixes
{
class PAWItemsOrder : BasePatch
{
protected override Version VersionMin => new Version(1, 8, 0);

protected override void ApplyPatches(ref List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
Expand All @@ -25,10 +27,13 @@ protected override void ApplyPatches(ref List<PatchInfo> patches)
}

#if DEBUG
patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(UIPartActionWindow), nameof(UIPartActionWindow.CreatePartList)),
GetType()));
if (KSPCommunityFixes.KspVersion >= new Version(1, 12, 2))
{
patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(UIPartActionWindow), nameof(UIPartActionWindow.CreatePartList)),
GetType()));
}
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion KSPCommunityFixes/KSPCommunityFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ public void ModuleManagerPostLoad()
BasePatch.Patch<PAWGroupMemory>();
BasePatch.Patch<KerbalInventoryPersistence>();
BasePatch.Patch<PAWItemsOrder>();

// QoL :
BasePatch.Patch<AltimeterHorizontalPosition>();
BasePatch.Patch<PAWCollapsedInventories>();
BasePatch.Patch<PAWStockGroups>();
BasePatch.Patch<TweakableWheelsAutostrut>();
BasePatch.Patch<UIFloatEditNumericInput>();

Destroy(this);
}
Expand Down
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="QoL\PAWCollapsedInventories.cs" />
<Compile Include="QoL\AltimeterHorizontalPosition.cs" />
<Compile Include="QoL\PAWStockGroups.cs" />
<Compile Include="QoL\UIFloatEditNumericInput.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MultipleModuleInPartAPI\MultipleModuleInPartAPI.csproj">
Expand Down
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
16 changes: 9 additions & 7 deletions KSPCommunityFixes/QoL/PAWStockGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PAWStockGroups : BasePatch
private static string commandGroupTitle;
private static string attitudeControlGroupTitle;

protected override Version VersionMin => new Version(1, 11, 1);
protected override Version VersionMin => new Version(1, 10, 1);

protected override void ApplyPatches(ref List<PatchInfo> patches)
{
Expand Down Expand Up @@ -61,17 +61,19 @@ static void Part_Start_Postfix(Part __instance)
{
BasePAWGroup pawGroup = new BasePAWGroup("CF_Part", partGroupTitle, true);

__instance.Fields[nameof(Part.sameVesselCollision)].group = pawGroup; // 1.11.1
BaseField sameVesselCollision = __instance.Fields["sameVesselCollision"]; // 1.11.1
if (sameVesselCollision != null)
sameVesselCollision.group = pawGroup;

BaseEvent setVesselNaming = __instance.Events["SetVesselNaming"]; // 1.11.0
if (setVesselNaming != null)
setVesselNaming.group = pawGroup;

__instance.Events[nameof(Part.AimCamera)].group = pawGroup;
__instance.Events[nameof(Part.ResetCamera)].group = pawGroup;
__instance.Events[nameof(Part.ToggleAutoStrut)].group = pawGroup;
__instance.Events[nameof(Part.ToggleRigidAttachment)].group = pawGroup;
__instance.Events[nameof(Part.ShowUpgradeStats)].group = pawGroup;

if (__instance.Events.Contains(nameof(Part.SetVesselNaming))) // 1.11.0
{
__instance.Events[nameof(Part.SetVesselNaming)].group = pawGroup;
}
}

static void ModuleDataTransmitter_OnStart_Postfix(ModuleDataTransmitter __instance)
Expand Down
2 changes: 2 additions & 0 deletions KSPCommunityFixes/QoL/TweakableWheelsAutostrut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace KSPCommunityFixes.BugFixes
{
class TweakableWheelsAutostrut : BasePatch
{
protected override Version VersionMin => new Version(1, 8, 0);

protected override void ApplyPatches(ref List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
Expand Down
182 changes: 182 additions & 0 deletions KSPCommunityFixes/QoL/UIFloatEditNumericInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using System;
using HarmonyLib;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

namespace KSPCommunityFixes
{
public class UIFloatEditNumericInput : BasePatch
{
protected override Version VersionMin => new Version(1, 8, 0);

private static UIPartActionNumericFloatEdit prefab;

protected override void ApplyPatches(ref List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(UIPartActionController), "Awake"),
GetType()));
}

static void UIPartActionController_Awake_Postfix(UIPartActionController __instance)
{
if (prefab == null)
{
UIPartActionFloatEdit original = null;
UIPartActionFloatRange floatRange = null;

foreach (var uiPartActionFieldItem in __instance.fieldPrefabs)
{
if (uiPartActionFieldItem is UIPartActionFloatEdit)
original = (UIPartActionFloatEdit)uiPartActionFieldItem;
else if (uiPartActionFieldItem is UIPartActionFloatRange)
floatRange = (UIPartActionFloatRange)uiPartActionFieldItem;
}

if (original != null && floatRange != null)
prefab = UIPartActionNumericFloatEdit.CreatePrefab(original, floatRange);
}

if (prefab != null)
{
for (int i = 0; i < __instance.fieldPrefabs.Count; i++)
{
if (__instance.fieldPrefabs[i] is UIPartActionFloatEdit)
{
__instance.fieldPrefabs[i] = prefab;
break;
}
}
}
}
}

[UI_FloatEdit]
public class UIPartActionNumericFloatEdit : UIPartActionFloatEdit
{
public static UIPartActionNumericFloatEdit CreatePrefab(UIPartActionFloatEdit original, UIPartActionFloatRange floatRange)
{
UIPartActionNumericFloatEdit customComponent = original.gameObject.AddComponent<UIPartActionNumericFloatEdit>();

customComponent.fieldName = original.fieldName;
customComponent.fieldValue = original.fieldValue;
customComponent.incLarge = original.incLarge;
customComponent.incSmall = original.incSmall;
customComponent.decLarge = original.decLarge;
customComponent.decSmall = original.decSmall;
customComponent.slider = original.slider;

customComponent.originalObjects = new GameObject[original.transform.childCount];
int i = 0;
foreach (Transform child in original.transform)
{
customComponent.originalObjects[i] = child.gameObject;
i++;
}

customComponent.numericContainer = Instantiate(floatRange.transform.Find("InputFieldHolder").gameObject);
customComponent.numericContainer.transform.SetParent(original.transform);
customComponent.fieldNameNumeric = customComponent.numericContainer.transform.Find("NameNumeric").GetComponent<TextMeshProUGUI>();
customComponent.inputField = customComponent.numericContainer.GetComponentInChildren<TMP_InputField>();

return customComponent;
}

public TextMeshProUGUI fieldNameNumeric;
public TMP_InputField inputField;
public GameObject numericContainer;
public GameObject[] originalObjects;

public override void Setup(UIPartActionWindow window, Part part, PartModule partModule, UI_Scene scene, UI_Control control, BaseField field)
{
base.Setup(window, part, partModule, scene, control, field);

fieldNameNumeric.text = field.guiName;
inputField.onEndEdit.AddListener(OnFieldInput);
inputField.onSelect.AddListener(AddInputFieldLock);
GameEvents.onPartActionNumericSlider.Add(ToggleNumericSlider);
ToggleNumericSlider(GameSettings.PAW_NUMERIC_SLIDERS);
window.usingNumericValue = true;
}

private void OnDestroy()
{
GameEvents.onPartActionNumericSlider.Remove(ToggleNumericSlider);
}

private void ToggleNumericSlider(bool numeric)
{
foreach (GameObject originalObject in originalObjects)
{
originalObject.SetActive(!numeric);
}

numericContainer.SetActive(numeric);
fieldNameNumeric.gameObject.SetActive(numeric);

if (numeric)
{
inputField.text = GetFieldValue().ToString($"F{floatControl.sigFigs}");
}
else
{
OnFieldInput(inputField.text);
float value = GetFieldValue();
string unit = floatControl.unit;
int sigFigs = floatControl.sigFigs;
string text = ((!floatControl.useSI) ? (KSPUtil.LocalizeNumber(value, "F" + sigFigs) + unit) : KSPUtil.PrintSI(value, unit, sigFigs));
fieldValue.text = text;

float min, max;
if (floatControl.incrementLarge == 0f)
{
min = floatControl.minValue;
max = floatControl.maxValue;
}
else if (floatControl.incrementSmall == 0f)
{
min = IntervalBase(value, floatControl.incrementLarge);
max = min + floatControl.incrementLarge;
}
else
{
min = IntervalBase(value, floatControl.incrementSmall);
max = min + floatControl.incrementSmall;
}
slider.minValue = Mathf.Max(min, floatControl.minValue);
slider.maxValue = Mathf.Min(max, floatControl.maxValue);
slider.value = value;
}
}

private float IntervalBase(float value, float increment)
{
float num = Mathf.Floor((value + floatControl.incrementSlide / 2f) / increment) * increment;
if (num > floatControl.maxValue - increment)
num = floatControl.maxValue - increment;

return num;
}

private void OnFieldInput(string input)
{
if (float.TryParse(input, out float result))
{
if (floatControl.incrementSlide > 0f)
result = Mathf.Ceil(result / floatControl.incrementSlide) * floatControl.incrementSlide;

result = Mathf.Clamp(result, floatControl.minValue, floatControl.maxValue);
SetFieldValue(result);
inputField.text = result.ToString($"F{floatControl.sigFigs}");
}
RemoveInputfieldLock();
}

private float GetFieldValue()
{
return field.GetValue<float>(field.host);
}
}
}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ Some patches will be applied only to specific KSP versions.

- **PAWCollapsedInventories** [KSP 1.11.0 - 1.12.2]<br/>Part Action Window inventory UI widgets in a collapsed group by default, group title show slots usage and cargo mass. Applied to part and kerbal inventories.<br/><img src="https://github.com/KSPModdingLibs/KSPCommunityFixes/raw/master/Screenshots/PAWCollapsedInventories.gif" width="300"/>
- **AltimeterHorizontalPosition** [KSP 1.8.0 - 1.12.2]<br/>Altimeter widget horizontal position is now tweakable in the pause menu settings.<br/><img src="https://github.com/KSPModdingLibs/KSPCommunityFixes/raw/master/Screenshots/AltimeterHorizontalPosition.gif" width="500"/>
- **PAWStockGroups** [KSP 1.11.1 - 1.12.2]<br/>Part Action Window groups for a selection of stock modules<br/><img src="https://github.com/KSPModdingLibs/KSPCommunityFixes/raw/master/Screenshots/PAWGroups.png" width="500"/>
- **TweakableWheelsAutostrut** [KSP 1.8.0 - 1.12.2]<br/>Allow tweaking the autostrut mode of wheels/landing legs. Still default to "heaviest".
- **PAWStockGroups** [KSP 1.10.1 - 1.12.2]<br/>Part Action Window groups for a selection of stock modules<br/><img src="https://github.com/KSPModdingLibs/KSPCommunityFixes/raw/master/Screenshots/PAWGroups.png" width="500"/>
- **TweakableWheelsAutostrut** [KSP 1.8.0 - 1.12.2]<br/>Allow tweaking the autostrut mode of wheels/landing legs. Still default to "heaviest".<br/><img src="https://github.com/KSPModdingLibs/KSPCommunityFixes/raw/master/Screenshots/TweakableWheelsAutostrut.gif"/>
- **UIFloatEditNumericInput** [KSP 1.8.0 - 1.12.2]<br/>Allow numeric input ("#" button) in "float edit" PAW items<br/><img src="https://github.com/KSPModdingLibs/KSPCommunityFixes/raw/master/Screenshots/UIFloatEditNumericInput.gif"/>

#### Mod API
- **MultipleModuleInPartAPI**<br/>This API allow other plugins to implement PartModules that can exist in multiple occurrence in a single part and won't suffer "module indexing mismatch" persistent data losses following part configuration changes. [See documentation on the wiki](https://github.com/KSPModdingLibs/KSPCommunityFixes/wiki/MultipleModuleInPartAPI).
Expand All @@ -52,6 +53,11 @@ MIT

### Changelog

##### 1.4.0
- New QoL patch : UIFloatEditNumericInput
- Fixed some patches not being applied in KSP versions below 1.12 : PAWItemsOrder, TweakableWheelsAutostrut, ModuleIndexingMismatch, FlightSceneLoadKraken.
- PAWStockGroups patch now applicable to KSP 1.10.1 (min version was 1.11.1 before)

##### 1.3.0
- New bugfix : PAWItemsOrder

Expand Down
Binary file added Screenshots/TweakableWheelsAutostrut.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/UIFloatEditNumericInput.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f24f2af

Please sign in to comment.