Skip to content

Commit

Permalink
Updated to KSP 1.8.1.
Browse files Browse the repository at this point in the history
Using ToolbarController.
‘Dock to altimeter’ option added.
Scaling support added.
Textures redrawn.
Project folder tree modified.
  • Loading branch information
formicant committed Nov 23, 2019
1 parent 7baf5ff commit cdd4e7d
Show file tree
Hide file tree
Showing 41 changed files with 727 additions and 1,243 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/Releases
/src/.vs
/src/CriticalTemperatureGauge/obj
/src/CriticalTemperatureGauge/bin
/.vs
/CriticalTemperatureGauge/obj
/CriticalTemperatureGauge/bin
*.suo
*.user
18 changes: 18 additions & 0 deletions CriticalTemperatureGauge.netkan
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"spec_version" : 1,
"identifier" : "CriticalTemperatureGauge",
"$kref" : "#/ckan/github/formicant/CriticalTemperatureGauge",
"$vref" : "#/ckan/ksp-avc",
"name" : "Critical Temperature Gauge",
"author" : [ "Ravien", "Teilnehmer" ],
"abstract" : "A plugin showing a temperature gauge and which part is going to blow up first",
"license" : "GPL-3.0",
"depends" : [
{ "name": "ModuleManager" }.
{ "name": "ClickThroughBlocker" }.
{ "name": "ToolbarController" }
],
"resources" : {
"homepage" : "http://forum.kerbalspaceprogram.com/index.php?/topic/146239-113-critical-temperature-gauge-continued"
}
}
19 changes: 12 additions & 7 deletions src/CriticalTemperatureGauge.sln → CriticalTemperatureGauge.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CriticalTemperatureGauge", "CriticalTemperatureGauge\CriticalTemperatureGauge.csproj", "{8FB4471E-FBBB-4538-9776-D22AD22B9B18}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CriticalTemperatureGauge", "CriticalTemperatureGauge\CriticalTemperatureGauge.csproj", "{84D37056-6C2B-4016-AC7B-69EDC258622C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1931306C-ABAE-442B-888B-FE658B98A0C5}"
ProjectSection(SolutionItems) = preProject
GameData\CriticalTemperatureGauge\CriticalTemperatureGauge.version = GameData\CriticalTemperatureGauge\CriticalTemperatureGauge.version
EndProjectSection
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
{84D37056-6C2B-4016-AC7B-69EDC258622C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84D37056-6C2B-4016-AC7B-69EDC258622C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84D37056-6C2B-4016-AC7B-69EDC258622C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84D37056-6C2B-4016-AC7B-69EDC258622C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F1B19BB7-A0E6-461A-BEFD-3815D2F04A7A}
SolutionGuid = {57761E15-7176-423D-A7B2-0A391C3F32F1}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" 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>
<ProjectGuid>{84D37056-6C2B-4016-AC7B-69EDC258622C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CriticalTemperatureGauge</RootNamespace>
<AssemblyName>CriticalTemperatureGauge</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -20,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -28,45 +30,53 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<DebugSymbols>true</DebugSymbols>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\_Lib\1.7.0\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\_Lib\1.8.1\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="ClickThroughBlocker, Version=0.1.9.3, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\_Lib\Mods\ClickThroughBlocker.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Microsoft.CSharp" />
<Reference Include="ToolbarControl, Version=0.1.9.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\_Lib\Mods\ToolbarControl.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\_Lib\1.8.1\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\_Lib\1.7.0\UnityEngine.dll</HintPath>
<HintPath>..\..\_Lib\1.8.1\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\_Lib\1.8.1\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Format.cs" />
<Compile Include="PartTemperatureState.cs" />
<Compile Include="SettingsWindow.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Flight.cs" />
<Compile Include="Format.cs" />
<Compile Include="GaugeWindow.cs" />
<Compile Include="Highlighter.cs" />
<Compile Include="PartTemperatureState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegisterToolbar.cs" />
<Compile Include="Settings.cs" />
<Compile Include="SettingsWindow.cs" />
<Compile Include="Static.cs" />
<Compile Include="AppLauncher.cs" />
<Compile Include="BlizzysToolbar.cs" />
<Compile Include="BlizzysToolbarWrapper.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>
<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>
16 changes: 16 additions & 0 deletions CriticalTemperatureGauge/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace CriticalTemperatureGauge
{
static class Extensions
{
public static T? Then<T>(this bool condition, T thenValue) where T : struct =>
condition ? thenValue : (T?)null;

public static Rect Scale(this Rect rectangle, float scale) =>
new Rect(scale * rectangle.position, scale * rectangle.size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using KSP.UI.Screens;
using ToolbarControl_NS;

namespace CriticalTemperatureGauge
{
Expand All @@ -13,14 +15,50 @@ public class Flight : MonoBehaviour
{
readonly Window _gaugeWindow = new GaugeWindow();
readonly Highlighter _highlighter = new Highlighter();
readonly BlizzysToolbar _toolbar = new BlizzysToolbar();
readonly SettingsWindow _settingsWindow = new SettingsWindow();
ToolbarControl _toolbarControl;

// Toolbar control:

void CreateToolbarControl()
{
if(_toolbarControl == null)
{
_toolbarControl = gameObject.AddComponent<ToolbarControl>();
_toolbarControl.AddToAllToolbars(
onTrue: OnButtonToggle,
onFalse: OnButtonToggle,
visibleInScenes: ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW,
nameSpace: Static.PluginId,
toolbarId: $"{Static.PluginId}Settings",
largeToolbarIcon: $"{Static.TexturePath}ToolbarIcon-57",
smallToolbarIcon: $"{Static.TexturePath}ToolbarIcon-24",
toolTip: Static.PluginTitle);
}
}

void DestroyToolbarControl()
{
if(_toolbarControl != null)
{
_toolbarControl.OnDestroy();
Destroy(_toolbarControl);
_toolbarControl = null;
}
}

void OnButtonToggle()
{
_toolbarControl.SetFalse(makeCall: false);
_settingsWindow.Toggle();
}

// KSP events:

public void Start()
{
Debug.Log($"{nameof(CriticalTemperatureGauge)}: Entering scene {HighLogic.LoadedScene}.");
_toolbar.Start();
Debug.Log($"{Static.PluginId}: Entering scene {HighLogic.LoadedScene}.");
CreateToolbarControl();
}

public void Awake()
Expand All @@ -36,40 +74,40 @@ public void OnDestroy()
Static.Settings.Save();
GameEvents.onShowUI.Remove(OnShowUI);
GameEvents.onHideUI.Remove(OnHideUI);
_gaugeWindow?.Hide();
_gaugeWindow.Hide();
_settingsWindow.Hide();
Static.CriticalPartState = null;
_toolbar.Destroy();
if(Static.AppLauncher != null)
Static.AppLauncher.ButtonState = false;
Debug.Log($"{nameof(CriticalTemperatureGauge)}: Exiting scene {HighLogic.LoadedScene}.");
DestroyToolbarControl();
Debug.Log($"{Static.PluginId}: Exiting scene {HighLogic.LoadedScene}.");
}
catch(Exception exception)
{
Debug.Log($"{nameof(CriticalTemperatureGauge)}: Exception during exiting scene {HighLogic.LoadedScene}: {exception}");
Debug.Log($"{Static.PluginId}: Exception during exiting scene {HighLogic.LoadedScene}: {exception}");
}
}

void OnShowUI()
{
if(_gaugeWindow != null)
_gaugeWindow.CanShow = true;
_gaugeWindow.CanShow = true;
_settingsWindow.CanShow = true;
}

void OnHideUI()
{
if(_gaugeWindow != null)
_gaugeWindow.CanShow = false;
_gaugeWindow.CanShow = false;
_settingsWindow.CanShow = false;
}

public void OnGUI()
{
_gaugeWindow?.DrawGUI();
_gaugeWindow.DrawGUI();
_settingsWindow.DrawGUI();
}

public void Update()
{
var vessel = FlightGlobals.ActiveVessel;
if(_gaugeWindow != null && vessel != null)
if(vessel != null)
{
// Updating critical part state
var criticalPartState = GetCriticalPartState(vessel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CriticalTemperatureGauge
{
internal static class Format
static class Format
{
public static string Temperature(double temperature, double? temperatureLimit) =>
temperatureLimit.HasValue
Expand All @@ -25,12 +25,6 @@ internal static class Format
$" {partName} ({(isSkin ? Skin : Core)})";


public static T? Then<T>(this bool condition, T thenValue)
where T : struct
=>
condition ? thenValue : (T?)null;


static string ToUnsignedString(this double value, int intPlaces)
{
var numberString = value.ToString("F0", CultureInfo.InvariantCulture);
Expand Down
Loading

0 comments on commit cdd4e7d

Please sign in to comment.