Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic gui names #2

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.