Project

General

Profile

Bug #27455

UIControl*.OnSymmetryFieldChanged Handler Called With Wrong Parameters

Added by DRVeyl 20 days ago.

Status:
New
Severity:
Low
Assignee:
-
Category:
Plugins/Add-Ons
Target version:
-
Start date:
03/27/2021
% Done:

0%

Version:
Platform:
Linux, OSX, Windows
Expansion:
Core Game
Language:
English (US)
Mod Related:
Yes
Votes:
Arrow u r green
Arrow d r red

Description

When calling the onFieldChanged handler of a KSPField's UIControl, the passed parameters are the BaseField and the previous value. However, when calling the onSymmetryFieldChanged handler, the parameters are the BaseField and the new value.

From a modding perspective, it would be very helpful to fix onSymmetryFieldChanged to pass the old value. Procedural parts mods want to take some action when fields change that depends on the previous value, such as moving attached parts when the length or diameter changes. Knowing the previous value is critical to that. This works well for onFieldChanged.

Mods can, and have, worked around this. However, it makes the code much more complex and difficult to maintain than a version that could use the stock-provided method if fixed, especially with new (since 1.8) PAW caching improvements.

Example handler that can be assigned to eg uiControlEditor.onFieldChanged and uiControlEditor.onSymmetryFieldChanged:

public void handler(BaseField f, object obj)
{
    var newValue = f.GetValue(this);
    UnityEngine.Debug.Log($"{part} Field: {field.name}: Old value: {obj}  New value: {newValue}");
}

Existing code should not be relying on the current behaviour of getting the new value in the obj parameter, as it is available via f.GetValue(this)

Also available in: Atom PDF