Skip to content

Commit 7987399

Browse files
author
Safarte
committed
Docking tangent offset and velocity set to linear scale and add setting
1 parent 5517f11 commit 7987399

11 files changed

Lines changed: 65 additions & 56 deletions

File tree

.gitignore

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,7 @@ _UpgradeReport_Files/
1616

1717
# Rider
1818

19-
# User specific
20-
**/.idea/**/workspace.xml
21-
**/.idea/**/tasks.xml
22-
**/.idea/shelf/*
23-
**/.idea/dictionaries
24-
**/.idea/httpRequests/
25-
26-
# Sensitive or high-churn files
27-
**/.idea/**/dataSources/
28-
**/.idea/**/dataSources.ids
29-
**/.idea/**/dataSources.xml
30-
**/.idea/**/dataSources.local.xml
31-
**/.idea/**/sqlDataSources.xml
32-
**/.idea/**/dynamic.xml
33-
34-
# Rider auto-generates .iml files, and contentModel.xml
35-
**/.idea/**/*.iml
36-
**/.idea/**/contentModel.xml
37-
**/.idea/**/modules.xml
19+
.idea/*
3820

3921
# VS Code files
4022
.vscode/*

DAD_UI/Assets/DockingAlignmentDisplay.uss.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DAD_UI/Assets/DockingAlignmentDisplay.uxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
2-
<Style src="DockingAlignmentDisplay.uss" />
2+
<Style src="project://database/Assets/DockingAlignmentDisplay.uss?fileID=7433441132597879392&amp;guid=57166329bf8e7cb4a8f9489e73e66b56&amp;type=3#DockingAlignmentDisplay" />
33
<ui:VisualElement name="root" class="root">
44
<ui:Label text="DOCKING-ALIGNMENT" display-tooltip-when-elided="true" name="title" class="title" />
55
<ui:Button display-tooltip-when-elided="true" text="×" name="close-button" enable-rich-text="true" class="close-button" />
@@ -14,7 +14,7 @@
1414
<ui:Label text="0" display-tooltip-when-elided="true" name="tangent0" class="tangent-text" style="position: absolute; left: 57%; flex-direction: column; top: 51%;" />
1515
<ui:Label text="1" display-tooltip-when-elided="true" name="tangent1" class="tangent-text" style="position: absolute; left: 70%; top: 51%;" />
1616
<ui:Label text="2" display-tooltip-when-elided="true" name="tangent2" class="tangent-text" style="position: absolute; left: 83%; top: 51%;" />
17-
<ui:Label text="3" display-tooltip-when-elided="true" name="tangent3" class="tangent-text" style="position: absolute; left: 96%; top: 51%;" />
17+
<ui:Label text="3" display-tooltip-when-elided="true" name="tangent3" class="tangent-text" style="position: absolute; top: 51%; right: 1%;" />
1818
<ui:Label text="10°" display-tooltip-when-elided="true" name="angle-10" class="angle-text" style="position: absolute; left: 52%; flex-direction: column; top: 32%;" />
1919
<ui:Label text="20°" display-tooltip-when-elided="true" name="angle-20" class="angle-text" style="position: absolute; left: 52%; top: 20%;" />
2020
<ui:Label text="30°" display-tooltip-when-elided="true" name="angle-30" class="angle-text" style="position: absolute; left: 52%; top: 8%;" />

Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<PropertyGroup Label="Game folder configuration">
1111
<!-- Set this to the path to your KSP 2 folder if you don't have the KSP2DIR environmental variable set -->
12-
<KSP2DIR Condition="'$(KSP2DIR)' == ''">C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program 2</KSP2DIR>
12+
<KSP2DIR Condition="'$(KSP2DIR)' == ''">D:/SteamLibrary/steamapps/common/Kerbal Space Program 2</KSP2DIR>
1313
</PropertyGroup>
1414

1515
<PropertyGroup Label="Build and namespace configuration">
@@ -35,10 +35,10 @@
3535

3636
<!-- Define the main target -->
3737
<Target Label="Reading properties from swinfo.json" Name="ReadPropertiesFromJson" BeforeTargets="PreBuildEvent">
38-
<JsonPeek ContentPath="$(SolutionDir)/docking_alignment_display/swinfo.json" Query="$">
38+
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$">
3939
<Output TaskParameter="Result" ItemName="Swinfo"/>
4040
</JsonPeek>
41-
<JsonPeek ContentPath="$(SolutionDir)/docking_alignment_display/swinfo.json" Query="$.dependencies">
41+
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$.dependencies">
4242
<Output TaskParameter="Result" ItemName="Dependencies"/>
4343
</JsonPeek>
4444

-37.7 KB
Binary file not shown.
38.3 KB
Binary file not shown.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Docking Alignment Display",
66
"description": "Adds a new instrument providing necessary information to dock with precision.",
77
"source": "https://github.com/Safarte/DockingAlignmentDisplay",
8-
"version": "0.3.2",
8+
"version": "0.4.0",
99
"version_check": "https://raw.githubusercontent.com/Safarte/DockingAlignmentDisplay/main/docking_alignment_display/swinfo.json",
1010
"ksp2_version": {
1111
"min": "0.1.5",

src/DockingAlignmentDisplay/DadUiController.cs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ internal class DadUiController : KerbalMonoBehaviour
5252
private VisualElement _rotationMarker;
5353
private VisualElement _rotationMarkerSprite;
5454

55-
56-
// Flight Controls Mode
57-
//Label CtrlLabel;
58-
5955
// Main display
6056
private VisualElement _screen;
6157
private float _screenHeight;
@@ -65,6 +61,10 @@ internal class DadUiController : KerbalMonoBehaviour
6561
private VisualElement _tangentCrosshairHori;
6662
private VisualElement _tangentCrosshairVert;
6763

64+
// Tangent scale
65+
private Label _tangentScale;
66+
private Label[] _tangentTicks;
67+
6868
// Tangent Offset
6969
private Label _tofsLabel;
7070

@@ -102,12 +102,19 @@ private void Update()
102102
// Update target data
103103
_target.Update();
104104

105-
// Update flight controls mode indicator
106-
//if (Game?.ViewController?.GetActiveSimVessel(true) != null)
107-
//{
108-
// Vehicle.ActiveVesselVehicle.OnFlightControlsModeChange -= OnFlightControlsModeChanged;
109-
// Vehicle.ActiveVesselVehicle.OnFlightControlsModeChange += OnFlightControlsModeChanged;
110-
//}
105+
// Update tangent scale
106+
if (DockingAlignmentDisplayPlugin.Instance.DockingTangentOffsetScale.Value == "Linear")
107+
{
108+
_tangentScale.text = "m";
109+
for (var i = 0; i < 4; i++)
110+
_tangentTicks[i].text = (10 * (1 + i)).ToString();
111+
}
112+
else
113+
{
114+
_tangentScale.text = "10^x m";
115+
for (var i = 0; i < 4; i++)
116+
_tangentTicks[i].text = i.ToString();
117+
}
111118

112119
if (_target.IsValid)
113120
{
@@ -185,6 +192,12 @@ private void InitElements()
185192
_angleHori = _container.Q<VisualElement>("angle-hori");
186193
_angleVert = _container.Q<VisualElement>("angle-vert");
187194

195+
// Tangent scale
196+
_tangentScale = _container.Q<Label>("tangent-scale");
197+
_tangentTicks = new Label[4];
198+
for (var i = 0; i < 4; i++)
199+
_tangentTicks[i] = _container.Q<Label>($"tangent{i}");
200+
188201
// Rotate Angle crosshair
189202
_angleCrosshair.transform.rotation = Quaternion.AngleAxis(45, Vector3.forward);
190203

@@ -233,7 +246,6 @@ private static string ToDisplay(double value)
233246
/// Set the crosshair's color to red if positionError.z &lt; 0 (the craft is behind the target docking port).
234247
/// </summary>
235248
/// <param name="relativePos">Relative position in the target parallel frame</param>
236-
/// <param name="validTarget">Is the target valid</param>
237249
private void UpdateTangentCrosshair(Vector3 relativePos)
238250
{
239251
// Display crosshair
@@ -246,11 +258,20 @@ private void UpdateTangentCrosshair(Vector3 relativePos)
246258
_tangentCrosshairHori.EnableInClassList(Red, relativePos.z <= 0);
247259
_tangentCrosshairVert.EnableInClassList(Red, relativePos.z <= 0);
248260

261+
float screenX, screenY;
249262
// Convert xy error to screen coordinates with log scale
250-
var screenX = Mathf.Sign(relativePos.x) * _screenWidth *
251-
(Mathf.Log10(Mathf.Clamp(Mathf.Abs(relativePos.x), 0.1f, 990f)) + 1) / 8;
252-
var screenY = Mathf.Sign(relativePos.y) * _screenHeight *
253-
(Mathf.Log10(Mathf.Clamp(Mathf.Abs(relativePos.y), 0.1f, 990f)) + 1) / 8;
263+
if (DockingAlignmentDisplayPlugin.Instance.DockingTangentOffsetScale.Value == "Linear")
264+
{
265+
screenX = Mathf.Clamp(relativePos.x, -39f, 39f) / 40f * (_screenWidth / 2);
266+
screenY = Mathf.Clamp(relativePos.y, -39f, 39f) / 40f * (_screenHeight / 2);
267+
}
268+
else
269+
{
270+
screenX = Mathf.Sign(relativePos.x) *
271+
(Mathf.Log10(Mathf.Clamp(Mathf.Abs(relativePos.x), 0.1f, 990f)) + 1) / 4 * (_screenWidth / 2);
272+
screenY = Mathf.Sign(relativePos.y) *
273+
(Mathf.Log10(Mathf.Clamp(Mathf.Abs(relativePos.y), 0.1f, 990f)) + 1) / 4 * (_screenHeight / 2);
274+
}
254275

255276
// Move crosshair to desired position
256277
_tangentCrosshairHori.transform.position = new Vector3(0, -screenY);
@@ -263,7 +284,6 @@ private void UpdateTangentCrosshair(Vector3 relativePos)
263284
/// Set the crosshair's color to red if the docking port is pointed away from the target.
264285
/// </summary>
265286
/// <param name="relativeOrientation">Relative orientation (docking port's "up" in the parallel frame)</param>
266-
/// <param name="validTarget"></param>
267287
private void UpdateAngleCrosshair(Vector3 relativeOrientation)
268288
{
269289
// Display crosshair
@@ -292,7 +312,6 @@ private void UpdateAngleCrosshair(Vector3 relativeOrientation)
292312
/// and the target docking port. The arrow is green is the angle is less that 5° and red otherwise.
293313
/// </summary>
294314
/// <param name="relativeRoll">Relative roll between the two docking ports</param>
295-
/// <param name="validTarget"></param>
296315
private void UpdateRollIndicator(float relativeRoll)
297316
{
298317
// Display indicator
@@ -319,7 +338,6 @@ private void UpdateRollIndicator(float relativeRoll)
319338
/// docking port parallel frame.
320339
/// </summary>
321340
/// <param name="relativeVel">Relative velocity in the target parallel frame</param>
322-
/// <param name="validTarget"></param>
323341
private void UpdateTvelIndicator(Vector3 relativeVel)
324342
{
325343
// Display indicator
@@ -342,7 +360,13 @@ private void UpdateTvelIndicator(Vector3 relativeVel)
342360
_tvelMarker.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
343361

344362
// Arrow length
345-
var screenMag = (Mathf.Log10(Mathf.Clamp(mag, 0.1f, 990f)) + 1) / 8 * (_screenHeight / 2);
363+
float screenMag;
364+
// Convert xy error to screen coordinates with log scale
365+
if (DockingAlignmentDisplayPlugin.Instance.DockingTangentOffsetScale.Value == "Linear")
366+
screenMag = Mathf.Clamp(mag, -39f, 39f) / 40f * (_screenHeight / 2);
367+
else
368+
screenMag = (Mathf.Log10(Mathf.Clamp(mag, 0.1f, 990f)) + 1) / 4 * (_screenHeight / 2);
369+
346370
_tvelLine.style.height = screenMag;
347371
_tvelArrow.style.bottom = screenMag - 5;
348372
}

src/DockingAlignmentDisplay/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<MakeDir Directories="$(SolutionDir)/dist/$(ConfigurationName)/BepInEx/plugins/$(ProjectName)"/>
77

88
<ItemGroup Label="Plugin template folder to be copied">
9-
<PluginTemplate Include="$(SolutionDir)/docking_alignment_display/**/*.*"/>
9+
<PluginTemplate Include="$(SolutionDir)/plugin_template/**/*.*"/>
1010
</ItemGroup>
1111
<Message Text="Copying plugin folder to build directory"/>
1212
<Copy SourceFiles="@(PluginTemplate)"

0 commit comments

Comments
 (0)