Skip to content

Commit

Permalink
Fix #797 (Missing science transmission option and information)
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed Dec 16, 2019
1 parent 104d408 commit 3bb123b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
5 changes: 5 additions & 0 deletions GameData/RemoteTech/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ Localization
#RT_ModuleUI_Autothreshold_Off = Off
#RT_ModuleUI_DeactivateatEC = Deactivate at EC %
#RT_ModuleUI_ActivateatEC = Activate at EC %

#RT_ModuleUI_Transmit = Transmit all science
#RT_ModuleUI_SciencePacketSize = Science packet size
#RT_ModuleUI_SciencePacketInterval = Science packet interval
#RT_ModuleUI_SciencePacketCost = Science packet cost

#RT_ModuleUI_Connected = Connected
#RT_ModuleUI_NoResources = Out of power
Expand Down
5 changes: 5 additions & 0 deletions GameData/RemoteTech/Localization/zh-cn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ Localization
#RT_ModuleUI_Autothreshold_Off = 关闭
#RT_ModuleUI_DeactivateatEC = 当EC达到 %停用
#RT_ModuleUI_ActivateatEC = 当EC达到 %激活

#RT_ModuleUI_Transmit = Transmit all science
#RT_ModuleUI_SciencePacketSize = Science packet size
#RT_ModuleUI_SciencePacketInterval = Science packet interval
#RT_ModuleUI_SciencePacketCost = Science packet cost

#RT_ModuleUI_Connected = 连接
#RT_ModuleUI_NoResources = 电力耗尽
Expand Down
86 changes: 83 additions & 3 deletions src/RemoteTech/Modules/ModuleRTAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public float
RTPacketSize = 0.0f,
RTPacketResourceCost = 0.0f;

[KSPField(guiName = "#RT_ModuleUI_SciencePacketSize", guiActive = false , guiActiveEditor = true)] //Science packet size
public String GUI_SciencePacketSize;
[KSPField(guiName = "#RT_ModuleUI_SciencePacketInterval", guiActive = false , guiActiveEditor = true)] //Science packet interval
public String GUI_SciencePacketInterval;
[KSPField(guiName = "#RT_ModuleUI_SciencePacketCost", guiActive = false , guiActiveEditor = true)] //Science packet cost
public String GUI_SciencePacketCost;

public int[] mDeployFxModuleIndices, mProgressFxModuleIndices;
private List<IScalarModule> mDeployFxModules = new List<IScalarModule>();
private List<IScalarModule> mProgressFxModules = new List<IScalarModule>();
Expand Down Expand Up @@ -256,6 +263,21 @@ public virtual void SetState(bool state)
else {
AddTransmitter();
}

if (mTransmitter != null)
{
Events["EventTransmit"].guiActive = true;
Fields["GUI_SciencePacketInterval"].guiActive = true;
Fields["GUI_SciencePacketSize"].guiActive = true;
Fields["GUI_SciencePacketCost"].guiActive = true;
}
else
{
Events["EventTransmit"].guiActive = false;
Fields["GUI_SciencePacketInterval"].guiActive = false;
Fields["GUI_SciencePacketSize"].guiActive = false;
Fields["GUI_SciencePacketCost"].guiActive = false;
}
}

[KSPEvent(name = "EventToggle", guiActive = false)]
Expand Down Expand Up @@ -294,6 +316,52 @@ public virtual void SetState(bool state)
[KSPEvent(name = "OverrideClose", active = true, guiActiveUnfocused = true, unfocusedRange = 5, externalToEVAOnly = true, guiName = "#RT_ModuleUI_ForceClose", category = "skip_delay;skip_control")]//[EVA] Force Close
public void OverrideClose() { EventClose(); }

[KSPEvent(name = "EventTransmit", guiActive = false, guiActiveEditor = false, guiName = "#RT_ModuleUI_Transmit")]//Transmit all science
public void EventTransmit()
{
if (mTransmitter != null && mTransmitter.CanTransmit())
{
List<ScienceData> scienceDataList = new List<ScienceData>();
for(int i = 0; i < vessel.parts.Count; i++)
{
//get experiments
var experiments = vessel.parts[i].FindModulesImplementing<ModuleScienceExperiment>();
for (int j = 0; j < experiments.Count; j++)
{
if(experiments[j].HasExperimentData)
{
var scienceData = experiments[j].GetData();
for (int k = 0; k < scienceData.Length; k++)
{
experiments[j].DumpData(scienceData[k]);
}
scienceDataList.AddRange(scienceData);
}
}

//get containers of stored experiments
var scienceContainers = vessel.parts[i].FindModulesImplementing<ModuleScienceContainer>();
for (int j = 0; j < scienceContainers.Count; j++)
{
if(scienceContainers[j].GetStoredDataCount() > 0)
{
var scienceData = scienceContainers[j].GetData();
for (int k = 0; k < scienceData.Length; k++)
{
scienceContainers[j].DumpData(scienceData[k]);
}
scienceDataList.AddRange(scienceData);
}
}
}

if (scienceDataList.Count > 0)
{
mTransmitter.TransmitData(scienceDataList);
}
}
}

public void OnConnectionRefresh()
{
SetState(IsRTActive);
Expand Down Expand Up @@ -378,11 +446,11 @@ public override void OnAwake()
{
base.OnAwake();
if (consumedResources == null)
{
{
consumedResources = new List<PartResourceDefinition>();
}
else
{
else
{
consumedResources.Clear();
}
for (var i = 0; i < resHandler.inputResources.Count; i++)
Expand Down Expand Up @@ -475,6 +543,18 @@ private void AddTransmitter()
// Trigger onVesselWasModified after adding a new transmitter
GameEvents.onVesselWasModified.Fire(this.part.vessel);
}

if (mTransmitter != null)
{
//overwrite default parameters of ModuleRTDataTransmitter
(mTransmitter as ModuleRTDataTransmitter).PacketSize = RTPacketSize;
(mTransmitter as ModuleRTDataTransmitter).PacketInterval = RTPacketInterval;
(mTransmitter as ModuleRTDataTransmitter).PacketResourceCost = RTPacketResourceCost;
}

GUI_SciencePacketInterval = String.Format("{0} sec", RTPacketInterval);
GUI_SciencePacketSize = String.Format("{0} Mits", RTPacketSize);
GUI_SciencePacketCost = String.Format("{0} charge", RTPacketResourceCost);
}

private void RemoveTransmitter()
Expand Down
1 change: 1 addition & 0 deletions src/RemoteTech/Modules/ModuleRTDataTransmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace RemoteTech.Modules
/// <summary>Used to transmit science from a vessel with an antenna.</summary>
public sealed class ModuleRTDataTransmitter : PartModule, IScienceDataTransmitter
{
//Default parameters unless loaded from antenna configuration
[KSPField]
public float
PacketInterval = 0.5f,
Expand Down

0 comments on commit 3bb123b

Please sign in to comment.