Skip to content

Commit

Permalink
Dynamic gui names
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerFailure committed Aug 6, 2024
1 parent 632c5a1 commit 634ca85
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 6 deletions.
9 changes: 7 additions & 2 deletions BeamedPowerReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class WirelessReceiver : PartModule
// UI-right click menu in flight
static string ManagedResource;
static int ResourceHash;
string GUIResourceName;
[KSPField(guiName = "Power Receiver", isPersistant = true, guiActive = true, guiActiveEditor = false), UI_Toggle(scene = UI_Scene.Flight)]
public bool Listening;

Expand Down Expand Up @@ -60,8 +61,8 @@ public void Start()
string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg";
ConfigNode MainNode;
MainNode = ConfigNode.Load(ConfigFilePath);
ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource");
ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id;
ManagedResource = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("ManagedResource");
GUIResourceName = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("GUIUnitName"); ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id;
initFrames = 0;
receiver = new ReceivedPower();
Fields["CoreTemp"].guiUnits = "K/" + maxCoreTemp.ToString() + "K";
Expand Down Expand Up @@ -111,6 +112,10 @@ private void SetLocalization()
Fields["PowerReceived"].guiName = Localizer.Format("#LOC_BeamedPower_CalcResult");
Fields["CalcWavelength"].guiName = Localizer.Format("#LOC_BeamedPower_CalcWavelength");
Events["ToggleWavelength"].guiName = Localizer.Format("#LOC_BeamedPower_CalcToggleWavelength");

Fields["PowerBeamed"].guiUnits = GUIResourceName;
Fields["Excess"].guiUnits = GUIResourceName;
Fields["PowerReceived"].guiUnits = GUIResourceName;
}

[KSPEvent(guiName = "Cycle through vessels", guiActive = true, isPersistent = false, requireFullControl = true)]
Expand Down
4 changes: 3 additions & 1 deletion BeamedPowerReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BeamedPowerStandalone
{
public class WirelessReflector : PartModule
{
string GUIResourceName;
// parameters set in part.cfg file

static string ManagedResource;
Expand Down Expand Up @@ -106,7 +107,8 @@ public void Start()
{
string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg";
ConfigNode MainNode = ConfigNode.Load(ConfigFilePath);
ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource");
GUIResourceName = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("GUIUnitName"); ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id;
ManagedResource = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("ManagedResource");
ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id;
initFrames = 0; frames = 0;
Fields["CoreTemp"].guiUnits = "K/" + maxCoreTemp.ToString() + "K";
Expand Down
9 changes: 7 additions & 2 deletions BeamedPowerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public class WirelessSource : PartModule
string operational = Localizer.Format("#LOC_BeamedPower_status_Operational");
string ExceedTempLimit = Localizer.Format("#LOC_BeamedPower_status_ExceededTempLimit");
string VesselNone = Localizer.Format("#LOC_BeamedPower_Vessel_None");

string GUIResourceName;
public void Start()
{
string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg";
ConfigNode MainNode = ConfigNode.Load(ConfigFilePath);
ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource");
ManagedResource = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("ManagedResource");
GUIResourceName = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("GUIUnitName");
ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id;
Debug.Log(Time.realtimeSinceStartup + ManagedResource);
frames = 20; initFrames = 0;
Expand Down Expand Up @@ -97,6 +98,10 @@ private void SetLocalization()
Fields["RecvEfficiency"].guiName = Localizer.Format("#LOC_BeamedPower_CalcRecvEfficiency");
Fields["PowerBeamed"].guiName = Localizer.Format("#LOC_BeamedPower_CalcPowerBeamed");
Fields["PowerReceived"].guiName = Localizer.Format("#LOC_BeamedPower_CalcResult");

Fields["PowerBeamed"].guiUnits = GUIResourceName;
Fields["Excess"].guiUnits = GUIResourceName;
Fields["PowerReceived"].guiUnits = GUIResourceName;
}

private void SetHeatParams()
Expand Down
2 changes: 1 addition & 1 deletion VesselModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void OnLoadVessel()
string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg";
ConfigNode MainNode;
MainNode = ConfigNode.Load(ConfigFilePath);
ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource");
ManagedResource = MainNode.GetNode("BPSettings").GetNode("ResourceSettings").GetValue("ManagedResource");
ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id;
}

Expand Down
Binary file modified bin/Debug/BeamedPowerStandalone.dll
Binary file not shown.
Binary file modified bin/Debug/BeamedPowerStandalone.pdb
Binary file not shown.
Binary file modified obj/Debug/BeamedPowerStandalone.dll
Binary file not shown.
Binary file modified obj/Debug/BeamedPowerStandalone.pdb
Binary file not shown.
Binary file modified obj/Release/BeamedPowerStandalone.dll
Binary file not shown.
Binary file modified obj/Release/BeamedPowerStandalone.pdb
Binary file not shown.

0 comments on commit 634ca85

Please sign in to comment.