Skip to content

Commit aa169b6

Browse files
Fixed the Collect All so it now works with science containers which have a gui available in the PAW
Added check so that if no science containers are available, the button will be greyed out Now doesn't show the Collect All if no data is available to be collected
1 parent 0619945 commit aa169b6

File tree

7 files changed

+81
-21
lines changed

7 files changed

+81
-21
lines changed

ChangeLog.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@
7979
1.9.3
8080
Added two colors to the buttons:
8181
Yellow if the experiment needs to be reset before rerunning it
82-
Red if the experiment cannot be reset
82+
Red if the experiment cannot be reset
83+
84+
1.9.6
85+
Fixed the Collect All so it now works with science containers which have a gui available in the PAW
86+
Added check so that if no science containers are available, the button will be greyed out
87+
Now doesn't show the Collect All if no data is available to be collected

ScienceAlert.version

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"VERSION": {
1010
"MAJOR": 1,
1111
"MINOR": 9,
12-
"PATCH": 5,
13-
"BUILD": 4
12+
"PATCH": 6,
13+
"BUILD": 0
1414
},
1515
"KSP_VERSION": {
1616
"MAJOR": 1,

Source/ScienceAlert.Windows/DraggableExperimentList.cs

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Collections;
23
using System.Linq;
34
using ReeperCommon;
45
using ScienceAlert.Experiments;
@@ -8,6 +9,7 @@ namespace ScienceAlert.Windows
89
{
910
class DraggableExperimentList : DraggableWindow
1011
{
12+
internal static DraggableExperimentList Instance;
1113
private const string WindowTitle = "Available Experiments";
1214

1315
public ExperimentManager manager;
@@ -18,6 +20,7 @@ class DraggableExperimentList : DraggableWindow
1820

1921
protected override Rect Setup()
2022
{
23+
Instance = this;
2124
Title = "Available Experiments";
2225
ShrinkHeightToFit = true;
2326
Skin = Instantiate(Settings.Skin); // we'll be altering it a little bit to make sure the buttons are the right size
@@ -80,6 +83,50 @@ private string GetBiomeString()
8083
base.OnGUI();
8184
}
8285

86+
internal List<ModuleScienceContainer> msc;
87+
88+
internal void CheckForCollection()
89+
{
90+
msc = new List<ModuleScienceContainer>();
91+
{
92+
var parts = FlightGlobals.ActiveVessel.Parts.FindAll(p => p.Modules.Contains("ModuleScienceContainer"));
93+
94+
for (int i = parts.Count - 1; i > 0; i--)
95+
{
96+
Part part = parts[i];
97+
if (part.Modules["ModuleScienceContainer"].Events["CollectAllEvent"].guiActive)
98+
{
99+
var m = part.Modules["ModuleScienceContainer"] as ModuleScienceContainer;
100+
msc.Add(m);
101+
}
102+
}
103+
}
104+
}
105+
106+
public int GetActiveVesselDataCount()
107+
{
108+
int dataCnt = 0;
109+
if (FlightGlobals.ActiveVessel != null)
110+
{
111+
Vessel activeVessel = FlightGlobals.ActiveVessel;
112+
int pCount = activeVessel.parts.Count;
113+
while (pCount-- > 0)
114+
{
115+
Part part = activeVessel.parts[pCount];
116+
int mCount = part.Modules.Count;
117+
while (mCount-- > 0)
118+
{
119+
IScienceDataContainer scienceDataContainer = part.Modules[mCount] as IScienceDataContainer;
120+
if (scienceDataContainer != null)
121+
{
122+
dataCnt += scienceDataContainer.GetScienceCount();
123+
}
124+
}
125+
}
126+
}
127+
return dataCnt;
128+
}
129+
83130
bool doAll = false;
84131
bool noEva = false;
85132
protected override void DrawUI()
@@ -106,24 +153,28 @@ protected override void DrawUI()
106153
doAll = true;
107154
noEva = true;
108155
}
109-
if (GUILayout.Button("Collect All", Settings.Skin.button))
156+
157+
if (GetActiveVesselDataCount() > 0)
110158
{
111-
var parts = FlightGlobals.ActiveVessel.Parts.FindAll(p => p.Modules.Contains("ModuleScienceContainer"));
112-
113-
foreach (var part in parts)
159+
160+
if (msc != null && msc.Count > 0)
114161
{
115-
var m = part.Modules["ModuleScienceContainer"];
116-
117-
if (m.Events["CollectAllEvent"].active)
118-
{
119-
//((ModuleScienceContainer)m).CollectAllEvent();
120162

121-
ModuleScienceContainer msc = m as ModuleScienceContainer;
122-
msc.CollectAllEvent();
163+
if (GUILayout.Button("Collect All", Settings.Skin.button))
164+
{
165+
foreach (var m in msc)
166+
{
167+
m.CollectAllEvent();
168+
}
123169
}
124170
}
171+
else
172+
{
173+
GUI.enabled = false;
174+
GUILayout.Button("Collect All (no science containers available)");
175+
GUI.enabled = true;
176+
}
125177
}
126-
127178
//-----------------------------------------------------
128179
// Experiment list
129180
//-----------------------------------------------------

Source/ScienceAlert.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@
3131
</PropertyGroup>
3232
<ItemGroup>
3333
<Reference Include="Assembly-CSharp">
34-
<HintPath>R:\KSP_1.5.1_dev\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
34+
<HintPath>R:\KSP_1.6.1_dev\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
3535
<Private>False</Private>
3636
</Reference>
3737
<Reference Include="ClickThroughBlocker">
38-
<HintPath>R:\KSP_1.5.1_dev\GameData\000_ClickThroughBlocker\Plugins\ClickThroughBlocker.dll</HintPath>
38+
<HintPath>R:\KSP_1.6.1_dev\GameData\000_ClickThroughBlocker\Plugins\ClickThroughBlocker.dll</HintPath>
3939
</Reference>
4040
<Reference Include="System" />
4141
<Reference Include="System.Core" />
4242
<Reference Include="ToolbarControl">
43-
<HintPath>R:\KSP_1.5.1_dev\GameData\001_ToolbarControl\Plugins\ToolbarControl.dll</HintPath>
43+
<HintPath>R:\KSP_1.6.1_dev\GameData\001_ToolbarControl\Plugins\ToolbarControl.dll</HintPath>
4444
</Reference>
4545
<Reference Include="UnityEngine">
46-
<HintPath>R:\KSP_1.5.1_dev\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
46+
<HintPath>R:\KSP_1.6.1_dev\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
4747
<Private>False</Private>
4848
</Reference>
4949
<Reference Include="UnityEngine.UI">
50-
<HintPath>R:\KSP_1.5.1_dev\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
50+
<HintPath>R:\KSP_1.6.1_dev\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
5151
<Private>False</Private>
5252
</Reference>
5353
</ItemGroup>

Source/ScienceAlert/ScienceAlert.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ private void SliceAtlasTexture()
199199
void ButtonLeftClicked()
200200
{
201201
WindowEventLogic.experimentList.Visible = !WindowEventLogic.experimentList.Visible;
202+
DraggableExperimentList.Instance.CheckForCollection();
202203
}
204+
203205
void ButtonRightClicked()
204206
{
205207
WindowEventLogic.optionsWindow.Visible = !WindowEventLogic.optionsWindow.Visible;

Source/ScienceAlert/StorageCache.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ private IEnumerator Rebuild()
130130
IsBusy = false;
131131
Log.Debug("ALERT:Rebuilt StorageCache");
132132
}
133+
if (Windows.DraggableExperimentList.Instance != null)
134+
Windows.DraggableExperimentList.Instance.CheckForCollection();
133135
}
134136

135137
private void RemoveMagicTransmitter(bool rootOnly = true)

deploy.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rem GAMEDATA is the name of the local GameData
77
rem VERSIONFILE is the name of the version file, usually the same as GAMEDATA,
88
rem but not always
99

10-
set H=R:\KSP_1.5.1_dev
10+
set H=R:\KSP_1.6.1_dev
1111
set GAMEDIR=ScienceAlert
1212
set GAMEDATA="GameData"
1313
set VERSIONFILE=%GAMEDIR%.version

0 commit comments

Comments
 (0)