Skip to content

Commit

Permalink
Docking to altimeter fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
formicant committed Apr 26, 2022
1 parent 99d88f8 commit 264ea19
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
39 changes: 39 additions & 0 deletions CriticalTemperatureGauge/Altimeter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KSP.UI.Screens.Flight;
using UnityEngine;

namespace CriticalTemperatureGauge
{
public class Altimeter
{
public Altimeter()
{
var altitudeTumbler = GameObject.FindObjectOfType<KSP.UI.Screens.Flight.AltitudeTumbler>();
_altimeterPanel = altitudeTumbler.gameObject.transform.parent.parent.gameObject;
_screenCenter = Screen.width / 2f;
}

public float Scale => _altimeterPanel.transform.lossyScale.y;

public Vector2 DockPosition
{
get
{
var position = _altimeterPanel.transform.position;
var x = ShiftX + position.x;
var y = ShiftY - position.y + (Height - Margin) * Scale;
return new Vector2(x, y);
}
}

readonly GameObject _altimeterPanel;
readonly float _screenCenter;

const float ShiftX = 840;
const float ShiftY = 525;
const float Height = 82.5f;
const float Margin = 8.5f;
}
}
1 change: 1 addition & 0 deletions CriticalTemperatureGauge/CriticalTemperatureGauge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Altimeter.cs" />
<Compile Include="Wrappers\ClickThroughBlocker.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Flight.cs" />
Expand Down
13 changes: 6 additions & 7 deletions CriticalTemperatureGauge/GaugeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@ public class GaugeWindow : Window

const float FontSize = 14;

protected override GUISkin Skin => GUI.skin;
readonly Altimeter _altimeter = new Altimeter();

float AltimeterScale => GameSettings.UI_SCALE * GameSettings.UI_SCALE_ALTIMETER;
float Scale => AltimeterScale * Static.Settings.GaugeWindowScale;
protected override GUISkin Skin => GUI.skin;

Vector2 DockPosition => new Vector2(Screen.width / 2, AltimeterScale * 83);
float Scale => _altimeter.Scale * Static.Settings.GaugeWindowScale;

protected override Vector2? ConstWindowPosition =>
Static.Settings.DockGaugeWindow || Static.Settings.LockGaugeWindow
? (Static.Settings.DockGaugeWindow ? DockPosition : Static.Settings.GaugeWindowPosition) +
? (Static.Settings.DockGaugeWindow ? _altimeter.DockPosition : Static.Settings.GaugeWindowPosition) +
Scale * WindowSize.x / 2 * Vector2.left
: (Vector2?)null;

protected override Vector2? ConstWindowSize => Scale * WindowSize;

protected override Rect InitialWindowRectangle =>
new Rect(
DockPosition - new Vector2(Scale * 120, 0),
_altimeter.DockPosition - new Vector2(Scale * 120, 0),
ConstWindowSize.Value);

/// <summary>Creates the temperature gauge window.</summary>
Expand All @@ -59,7 +58,7 @@ public GaugeWindow()
protected override void OnWindowRectUpdated()
{
Static.Settings.GaugeWindowPosition = Static.Settings.DockGaugeWindow
? DockPosition
? _altimeter.DockPosition
: WindowRectangle.position + Scale * WindowSize.x / 2 * Vector2.right;
}

Expand Down
2 changes: 1 addition & 1 deletion CriticalTemperatureGauge/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.12.0.0")]
[assembly: AssemblyVersion("1.12.3.0")]

// Use KSPAssembly to allow other DLLs to make this DLL a dependency in a
// non-hacky way in KSP. Format is (AssemblyProduct, major, minor), and it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
{
"MAJOR": 1,
"MINOR": 12,
"PATCH": 0,
"PATCH": 3,
"BUILD": 0
},
"KSP_VERSION":
{
"MAJOR": 1,
"MINOR": 12,
"PATCH": 0
"PATCH": 3
},
"KSP_VERSION_MIN":
{
Expand Down
Binary file not shown.

0 comments on commit 264ea19

Please sign in to comment.