-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CriticalTemperatureGauge 1.1.3.3 Initial commit.
- Loading branch information
Showing
16 changed files
with
874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/Releases | ||
/src/.vs | ||
/src/CriticalTemperatureGauge/obj | ||
/src/CriticalTemperatureGauge/bin |
Binary file added
BIN
+22.5 KB
GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CriticalTemperatureGauge", "CriticalTemperatureGauge\CriticalTemperatureGauge.csproj", "{8FB4471E-FBBB-4538-9776-D22AD22B9B18}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8FB4471E-FBBB-4538-9776-D22AD22B9B18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8FB4471E-FBBB-4538-9776-D22AD22B9B18}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8FB4471E-FBBB-4538-9776-D22AD22B9B18}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8FB4471E-FBBB-4538-9776-D22AD22B9B18}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace CriticalTemperatureGauge | ||
{ | ||
/// <summary> | ||
/// Represents the configuration window. | ||
/// </summary> | ||
public class ConfigWindow : Window | ||
{ | ||
/// <summary>Slider resolution..</summary> | ||
const int ThresholdSteps = 20; | ||
|
||
// Layout parameters | ||
const int SeparatorHeight = 8; | ||
const int IndentWidth = 20; | ||
|
||
protected override Rect InitialWindowRectangle => | ||
new Rect( | ||
Static.Settings.ConfigWindowPosition != Vector2.zero | ||
? Static.Settings.ConfigWindowPosition | ||
: new Vector2(Screen.width - 285, (Screen.height - 410) / 2), | ||
Vector2.zero); | ||
|
||
/// <summary>Creates the configuration window.</summary> | ||
public ConfigWindow() | ||
: base(Static.Settings.BaseWindowId + 1, "Critical Temperature Gauge") { } | ||
|
||
/// <summary>Writes current window position into settings.</summary> | ||
protected override void OnWindowRectUpdated() | ||
{ | ||
Static.Settings.ConfigWindowPosition = WindowRectangle.position; | ||
} | ||
|
||
/// <summary>Draws the window contents.</summary> | ||
/// <param name="windowId">Id of the window.</param> | ||
protected override void WindowGUI(int windowId) | ||
{ | ||
// Defining styles | ||
var windowStyle = new GUIStyle(GUI.skin.window) { padding = new RectOffset(8, 8, 8, 8) }; | ||
var textEditStyle = new GUIStyle(GUI.skin.textField); | ||
var labelStyle = new GUIStyle(GUI.skin.label) | ||
{ | ||
normal = new GUIStyleState { textColor = Color.white }, | ||
focused = new GUIStyleState { textColor = Color.white }, | ||
alignment = TextAnchor.MiddleLeft, | ||
}; | ||
var sliderStyle = new GUIStyle(GUI.skin.horizontalSlider) { fixedWidth = 222 }; | ||
var sliderThumbStyle = new GUIStyle(GUI.skin.horizontalSliderThumb); | ||
|
||
// Drawing layout | ||
GUILayout.Space(SeparatorHeight); | ||
|
||
// Drawing gauge visibility settings controls | ||
GUILayout.Label($"Gauge showing threshold: {Static.Settings.GaugeShowingThreshold:G2}", labelStyle); | ||
Static.Settings.GaugeShowingThreshold = | ||
Math.Round(GUILayout.HorizontalSlider((float)Static.Settings.GaugeShowingThreshold, 1F / ThresholdSteps, 1F - 1F / ThresholdSteps, sliderStyle, sliderThumbStyle) * ThresholdSteps) / ThresholdSteps; | ||
GUILayout.Label($"Gauge hiding threshold: {Static.Settings.GaugeHidingThreshold:G2}", labelStyle); | ||
Static.Settings.GaugeHidingThreshold = Math.Min(Static.Settings.GaugeShowingThreshold, | ||
Math.Round(GUILayout.HorizontalSlider((float)Static.Settings.GaugeHidingThreshold, 1F / ThresholdSteps, 1F - 1F / ThresholdSteps, sliderStyle, sliderThumbStyle) * ThresholdSteps) / ThresholdSteps); | ||
Static.Settings.ForceShowGauge = GUILayout.Toggle(Static.Settings.ForceShowGauge, "Force show gauge"); | ||
|
||
// Drawing additional information settings controls | ||
Static.Settings.ShowTemperature = GUILayout.Toggle(Static.Settings.ShowTemperature, "Show temperature"); | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Space(IndentWidth); | ||
Static.Settings.ShowTemperatureLimit = GUILayout.Toggle(Static.Settings.ShowTemperatureLimit, "Show temperature limit"); | ||
GUILayout.EndHorizontal(); | ||
Static.Settings.ShowTemperatureRate = GUILayout.Toggle(Static.Settings.ShowTemperatureRate, "Show temperature rate"); | ||
Static.Settings.ShowCriticalPart = GUILayout.Toggle(Static.Settings.ShowCriticalPart, "Show critical part"); | ||
// (Part highlighting does not work for some reason) | ||
//Static.Settings.HighlightCriticalPart = GUILayout.Toggle(Static.Settings.HighlightCriticalPart, "Highlight critical part"); | ||
|
||
// Drawing exclusion list settings controls | ||
GUILayout.Space(SeparatorHeight); | ||
Static.Settings.UseExclusionList = GUILayout.Toggle(Static.Settings.UseExclusionList, "Ignore parts with following\nmodules (comma-separated):"); | ||
GUILayout.Space(SeparatorHeight * 2); | ||
Static.Settings.ExclusionList = GUILayout.TextField(Static.Settings.ExclusionList, 512, textEditStyle); | ||
|
||
// Drawing interface settings controls | ||
GUILayout.Space(SeparatorHeight); | ||
Static.Settings.LockGaugeWindow = GUILayout.Toggle(Static.Settings.LockGaugeWindow, "Lock gauge position"); | ||
|
||
GUI.DragWindow(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/CriticalTemperatureGauge/CriticalTemperatureGauge.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{8FB4471E-FBBB-4538-9776-D22AD22B9B18}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CriticalTemperatureGauge</RootNamespace> | ||
<AssemblyName>CriticalTemperatureGauge</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Assembly-CSharp"> | ||
<HintPath>..\..\..\_Lib\1.1.3 x64\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp-firstpass"> | ||
<HintPath>..\..\..\_Lib\1.1.3 x64\Assembly-CSharp-firstpass.dll</HintPath> | ||
</Reference> | ||
<Reference Include="KSPUtil"> | ||
<HintPath>..\..\..\_Lib\1.1.3 x64\KSPUtil.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\..\..\_Lib\1.1.3 x64\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UI"> | ||
<HintPath>..\..\..\_Lib\1.1.3 x64\UnityEngine.UI.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ConfigWindow.cs" /> | ||
<Compile Include="Flight.cs" /> | ||
<Compile Include="GaugeWindow.cs" /> | ||
<Compile Include="PartState.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Settings.cs" /> | ||
<Compile Include="Static.cs" /> | ||
<Compile Include="Toolbar.cs" /> | ||
<Compile Include="Window.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<PropertyGroup> | ||
<PostBuildEvent>copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)..\GameData\$(ProjectName)\Plugins\$(ProjectName).dll"</PostBuildEvent> | ||
</PropertyGroup> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace CriticalTemperatureGauge | ||
{ | ||
/// <summary> | ||
/// Main add-on class. | ||
/// </summary> | ||
[KSPAddon(KSPAddon.Startup.Flight, false)] | ||
public class Flight : MonoBehaviour | ||
{ | ||
Window _gaugeWindow; | ||
|
||
// KSP events: | ||
|
||
public void Start() | ||
{ | ||
Debug.Log($"CriticalTemperatureGauge: Entering scene {HighLogic.LoadedScene}."); | ||
_gaugeWindow = new GaugeWindow(); | ||
} | ||
|
||
public void OnDestroy() | ||
{ | ||
_gaugeWindow?.Hide(); | ||
Static.CriticalPartState = null; | ||
Static.Settings.Save(); | ||
Debug.Log($"CriticalTemperatureGauge: Exiting scene {HighLogic.LoadedScene}."); | ||
} | ||
|
||
public void OnGUI() | ||
{ | ||
_gaugeWindow?.DrawGUI(); | ||
} | ||
|
||
public void Update() | ||
{ | ||
var vessel = FlightGlobals.ActiveVessel; | ||
|
||
if(_gaugeWindow != null && vessel != null) | ||
{ | ||
// Updating critical part state | ||
var criticalPartState = GetCriticalPartState(vessel); | ||
criticalPartState?.UpdateTemperatureRates(Static.CriticalPartState); | ||
Static.CriticalPartState = criticalPartState; | ||
|
||
// Determining if the gauge should be shown or hidden | ||
if(!_gaugeWindow.IsVisible && | ||
criticalPartState != null && | ||
(criticalPartState.Index > Static.Settings.GaugeShowingThreshold || | ||
Static.Settings.ForceShowGauge)) | ||
{ | ||
_gaugeWindow.Show(); | ||
// (Part highlighting does not work for some reason) | ||
//if(Static.Settings.HighlightCriticalPart) | ||
// HighlightPart(vessel, criticalPartState.Id); | ||
} | ||
else if(_gaugeWindow.IsVisible && | ||
(criticalPartState == null || | ||
criticalPartState.Index < Static.Settings.GaugeHidingThreshold && | ||
!Static.Settings.ForceShowGauge)) | ||
{ | ||
_gaugeWindow.Hide(); | ||
//HighlightNone(vessel); | ||
} | ||
} | ||
} | ||
|
||
/// <summary>Finds the part with the greatest Temp/TempLimit ratio.</summary> | ||
/// <param name="vessel">Current vessel.</param> | ||
/// <returns>Critical part state.</returns> | ||
PartState GetCriticalPartState(Vessel vessel) => | ||
vessel.parts | ||
.Where(IsPartNotIgnored) | ||
.Select(GetPartState) | ||
.OrderByDescending(partState => partState.Index) | ||
.FirstOrDefault(); | ||
|
||
/// <summary>Gets parameters of a part.</summary> | ||
/// <param name="part">A vessel part.</param> | ||
/// <returns>Part state.</returns> | ||
static PartState GetPartState(Part part) => | ||
new PartState | ||
{ | ||
Time = Planetarium.GetUniversalTime(), | ||
Id = part.flightID, | ||
Name = GetPartTitle(part), | ||
CoreTemperatureLimit = part.maxTemp, | ||
SkinTemperatureLimit = part.skinMaxTemp, | ||
CoreTemperature = part.temperature, | ||
SkinTemperature = part.skinTemperature, | ||
}; | ||
|
||
/// <summary>Determines if the part has a module containing in the exclusion list.</summary> | ||
/// <param name="part">A vessel part.</param> | ||
/// <returns><c>false</c> if the part is ignored; <c>true</c> otherwise.</returns> | ||
bool IsPartNotIgnored(Part part) => | ||
!(Static.Settings.UseExclusionList && Static.Settings.ExclusionListItems.Any(moduleName => part.Modules.Contains(moduleName))); | ||
|
||
// Currently, not used | ||
static void HighlightNone(Vessel craft) => HighlightPart(craft, 0); | ||
|
||
// Currently, not used | ||
static void HighlightPart(Vessel craft, uint partId) | ||
{ | ||
foreach(var part in craft.parts) | ||
{ | ||
if(part.flightID == partId) | ||
part.highlighter.FlashingOn(Color.red, Color.yellow, 0.5F); | ||
else | ||
part.highlighter.FlashingOff(); | ||
} | ||
} | ||
|
||
/// <summary>Gets the title (long name) of a part.</summary> | ||
/// <param name="part">A vessel part.</param> | ||
/// <returns>Part title.</returns> | ||
static string GetPartTitle(Part part) | ||
{ | ||
// Removing vessel name from part name | ||
int indexOfWhitespace = part.name.IndexOf(' '); | ||
var name = indexOfWhitespace >= 0 | ||
? part.name.Substring(0, indexOfWhitespace) | ||
: part.name; | ||
|
||
// Trying to get part title; using part name if failed | ||
string title; | ||
try | ||
{ | ||
title = PartLoader.getPartInfoByName(name).title; | ||
if(string.IsNullOrEmpty(title)) | ||
title = name; | ||
} | ||
catch | ||
{ | ||
title = name; | ||
} | ||
return title; | ||
} | ||
} | ||
} |
Oops, something went wrong.