Skip to content

Commit 611ec94

Browse files
committed
initial solution commit
1 parent 3be3c7f commit 611ec94

4 files changed

Lines changed: 196 additions & 0 deletions

File tree

ForScience.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
7+
8+
namespace ForScience
9+
{
10+
[KSPAddon(KSPAddon.Startup.Flight, false)]
11+
public class ForScience : MonoBehaviour
12+
{
13+
//GUI
14+
private GUIStyle windowStyle, labelStyle, toggleStyle;
15+
private Rect windowPosition = new Rect();
16+
private bool initStyle = false;
17+
18+
// functionality
19+
private ModuleScienceContainer container = null;
20+
private bool autoTransfer = false;
21+
22+
private void Start()
23+
{
24+
if (!initStyle) InitStyle();
25+
RenderingManager.AddToPostDrawQueue(0, OnDraw);
26+
}
27+
28+
void Update()
29+
{
30+
if (autoTransfer & !FlightGlobals.ActiveVessel.isEVA) TransferScience();
31+
}
32+
33+
void OnDraw()
34+
{
35+
if (HighLogic.LoadedScene == GameScenes.FLIGHT)
36+
{
37+
windowPosition = GUILayout.Window(104234, windowPosition, MainWindow, "For Science", windowStyle);
38+
}
39+
}
40+
41+
public void TransferScience()
42+
{
43+
var containerList = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceContainer>();
44+
var experimentList = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceExperiment>().Cast<IScienceDataContainer>().ToList();
45+
if (container = null) container = containerList[0];
46+
containerList[0].StoreData(experimentList, true);
47+
}
48+
49+
private void InitStyle()
50+
{
51+
labelStyle = new GUIStyle(HighLogic.Skin.label);
52+
labelStyle.stretchWidth = true;
53+
54+
windowStyle = new GUIStyle(HighLogic.Skin.window);
55+
windowStyle.fixedWidth = 250f;
56+
57+
toggleStyle = new GUIStyle(HighLogic.Skin.toggle);
58+
59+
initStyle = true;
60+
}
61+
62+
private void MainWindow(int windowID)
63+
{
64+
GUILayout.BeginHorizontal();
65+
if (GUILayout.Toggle(autoTransfer, "Automatic data collection", toggleStyle))
66+
{
67+
autoTransfer = true;
68+
}
69+
else autoTransfer = false;
70+
GUILayout.EndHorizontal();
71+
72+
73+
GUI.DragWindow();
74+
}
75+
}
76+
}
77+
78+
79+
80+
81+
82+

ForScience.csproj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F701425A-3C04-4592-A84D-7B5D3DECB7A5}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ForScience</RootNamespace>
11+
<AssemblyName>ForScience</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>false</DebugSymbols>
18+
<DebugType>none</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>..\..\..\..\..\Desktop\KSPTest\GameData\ForScience\Plugins\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>none</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>..\Plugins\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="Assembly-CSharp">
35+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
36+
<Private>False</Private>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="UnityEngine">
40+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
41+
<Private>False</Private>
42+
</Reference>
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="ForScience.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
50+
Other similar extension points exist, see Microsoft.Common.targets.
51+
<Target Name="BeforeBuild">
52+
</Target>
53+
<Target Name="AfterBuild">
54+
</Target>
55+
-->
56+
</Project>

ForScience.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Express 2013 for Windows Desktop
4+
VisualStudioVersion = 12.0.30110.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ForScience", "ForScience.csproj", "{F701425A-3C04-4592-A84D-7B5D3DECB7A5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F701425A-3C04-4592-A84D-7B5D3DECB7A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F701425A-3C04-4592-A84D-7B5D3DECB7A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F701425A-3C04-4592-A84D-7B5D3DECB7A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F701425A-3C04-4592-A84D-7B5D3DECB7A5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ForScience")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("ForScience")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("bf0c4a9d-d61c-4cbb-999c-51f9a2d58380")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)