Skip to content

Commit

Permalink
Merge pull request #5 from Corvax-Frontier/Fixes
Browse files Browse the repository at this point in the history
Фиксы локализаций + Автопилот
  • Loading branch information
Vonsant authored Aug 7, 2024
2 parents a5efb8a + a11f14f commit 54b34a8
Show file tree
Hide file tree
Showing 82 changed files with 584 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Content.Client.Shuttles.BUI;

[UsedImplicitly]
public sealed class ShuttleConsoleBoundUserInterface : BoundUserInterface
public sealed partial class ShuttleConsoleBoundUserInterface : BoundUserInterface // Frontier: added partial
{
[ViewVariables]
private ShuttleConsoleWindow? _window;
Expand All @@ -27,6 +27,7 @@ protected override void Open()
_window.RequestBeaconFTL += OnFTLBeaconRequest;
_window.DockRequest += OnDockRequest;
_window.UndockRequest += OnUndockRequest;
NfOpen(); // Frontier
}

private void OnUndockRequest(NetEntity entity)
Expand Down
46 changes: 36 additions & 10 deletions Content.Client/Shuttles/UI/NavScreen.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,48 @@
Text="{controls:Loc 'shuttle-console-dock-toggle'}"
TextAlign="Center"
ToggleMode="True"/>

<!-- Frontier - Inertia dampener controls-->
<controls:BoxContainer Name="DampenerModeButtons"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
Margin="5">
<controls:Button Name="DampenerOff"
Text="{controls:Loc 'shuttle-console-inertia-dampener-off'}"
TextAlign="Center"
ToggleMode="True"
MinWidth="82"
MaxWidth="82"/>
<controls:Button Name="DampenerOn"
Text="{controls:Loc 'shuttle-console-inertia-dampener-dampen'}"
TextAlign="Center"
ToggleMode="True"
MinWidth="82"
MaxWidth="82"/>
<controls:Button Name="AnchorOn"
Text="{controls:Loc 'shuttle-console-inertia-dampener-anchor'}"
TextAlign="Center"
ToggleMode="True"
MinWidth="82"
MaxWidth="82"/>
</controls:BoxContainer>
<!-- End Frontier - Inertia dampener controls-->
<!-- Frontier - IFF search -->
<controls:BoxContainer Orientation="Vertical" HorizontalExpand="True" Name="IffSearchBox">
<controls:Label Text="{controls:Loc 'shuttle-console-iff-search'}"></controls:Label>
<controls:LineEdit Name="IffSearchCriteria" Access="Public" HorizontalExpand="True"></controls:LineEdit>
<controls:Label Text="{controls:Loc 'shuttle-console-iff-search'}"/>
<controls:LineEdit Name="IffSearchCriteria" Access="Public" HorizontalExpand="True"/>
</controls:BoxContainer>

<!-- End Frontier - IFF search -->

<!-- Frontier - Maximum IFF Distance -->
<controls:BoxContainer Orientation="Vertical" HorizontalExpand="True" Name="MaximumIFFDistanceBox">
<controls:Label Text="{controls:Loc 'shuttle-console-maximum-iff-distance'}"/>
<controls:SliderIntInput Name="MaximumIFFDistanceValue"
Access="Public"
MinValue="0"
MaxValue="3000"
Value="3000"
HorizontalExpand="True"/>
Access="Public"
MinValue="0"
MaxValue="3000"
Value="3000"
HorizontalExpand="True"/>
</controls:BoxContainer>
<!-- End Frontier - Maximum IFF Distance -->
</controls:BoxContainer>
</controls:BoxContainer>
</controls:BoxContainer>
29 changes: 3 additions & 26 deletions Content.Client/Shuttles/UI/NavScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public NavScreen()
DockToggle.OnToggled += OnDockTogglePressed;
DockToggle.Pressed = NavRadar.ShowDocks;

// Frontier - IFF search
IffSearchCriteria.OnTextChanged += args => OnIffSearchChanged(args.Text);

// Frontier - Maximum IFF Distance
MaximumIFFDistanceValue.GetChild(0).GetChild(1).Margin = new Thickness(8,0,0,0);
MaximumIFFDistanceValue.OnValueChanged += args => OnRangeFilterChanged(args);
NfInitialize(); // Frontier Initialization for the NavScreen
}

// Frontier - IFF search
Expand All @@ -55,30 +50,11 @@ private void OnIffSearchChanged(string text)
};
}

// Frontier - Maximum IFF Distance
private void OnRangeFilterChanged(int value)
{
NavRadar.MaximumIFFDistance = (float) value;
}

public void SetShuttle(EntityUid? shuttle)
{
_shuttleEntity = shuttle;

// Frontier - PR #1284 Add Shuttle Designation
if (_entManager.TryGetComponent<MetaDataComponent>(shuttle, out var metadata))
{
var shipNameParts = metadata.EntityName.Split(' ');
var designation = shipNameParts[^1];
if (designation.Length > 2 && designation[2] == '-')
{
NavDisplayLabel.Text = string.Join(' ', shipNameParts[..^1]);
ShuttleDesignation.Text = designation;
}
else
NavDisplayLabel.Text = metadata.EntityName;
}
// End Frontier - PR #1284
NfAddShuttleDesignation(shuttle); // Frontier - PR #1284 Add Shuttle Designation
}

private void OnIFFTogglePressed(BaseButton.ButtonEventArgs args)
Expand All @@ -102,6 +78,7 @@ private void OnDockTogglePressed(BaseButton.ButtonEventArgs args)
public void UpdateState(NavInterfaceState scc)
{
NavRadar.UpdateState(scc);
NfUpdateState(); // Frontier Update State
}

public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public ShuttleConsoleWindow()
{
UndockRequest?.Invoke(entity);
};

NfInitialize(); // Frontier Initialization for the ShuttleConsoleWindow
}

private void ClearModes(ShuttleConsoleMode mode)
Expand Down
107 changes: 9 additions & 98 deletions Content.Client/Shuttles/UI/ShuttleNavControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Client.Station; // Frontier
using Content.Shared.Shuttles.BUIStates;
using Content.Shared.Shuttles.Components;
using Content.Shared.Shuttles.Systems;
Expand All @@ -7,13 +8,11 @@
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Collections;
using Robust.Shared.Input;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;

namespace Content.Client.Shuttles.UI;

Expand All @@ -22,6 +21,7 @@ public sealed partial class ShuttleNavControl : BaseShuttleControl
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
private readonly StationSystem _station; // Frontier
private readonly SharedShuttleSystem _shuttles;
private readonly SharedTransformSystem _transform;

Expand Down Expand Up @@ -57,6 +57,7 @@ public ShuttleNavControl() : base(64f, 256f, 256f)
RobustXamlLoader.Load(this);
_shuttles = EntManager.System<SharedShuttleSystem>();
_transform = EntManager.System<SharedTransformSystem>();
_station = EntManager.System<StationSystem>(); // Frontier
}

public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
Expand Down Expand Up @@ -117,6 +118,8 @@ public void UpdateState(NavInterfaceState state)
ActualRadarRange = Math.Clamp(ActualRadarRange, WorldMinRange, WorldMaxRange);

_docks = state.Docks;

NfUpdateState(state); // Frontier Update State
}

protected override void Draw(DrawingHandleScreen handle)
Expand Down Expand Up @@ -226,19 +229,7 @@ protected override void Draw(DrawingHandleScreen handle)
shouldDrawIFF &= ShowIFFShuttles;
}

// New Frontiers - Maximum IFF Distance - checks distance to object, draws if closer than max range
// This code is licensed under AGPLv3. See AGPLv3.txt
if (shouldDrawIFF && MaximumIFFDistance >= 0.0f)
{
var gridCentre = Vector2.Transform(gridBody.LocalCenter, matty);
var distance = gridCentre.Length();

if (distance > MaximumIFFDistance)
{
shouldDrawIFF = false;
}
}
// End of modified code
shouldDrawIFF = NfCheckShouldDrawIffRangeCondition(shouldDrawIFF, gridBody, matty); // Frontier code

if (shouldDrawIFF)
{
Expand Down Expand Up @@ -298,17 +289,11 @@ protected override void Draw(DrawingHandleScreen handle)
handle.DrawString(Font, (uiPosition + labelOffset) * UIScale, labelText, UIScale, color);
}

blipDataList.Add(new BlipData
{
IsOutsideRadarCircle = isOutsideRadarCircle,
UiPosition = uiPosition,
VectorToPosition = uiPosition - new Vector2(uiXCentre, uiYCentre),
Color = color
});
NfAddBlipToList(blipDataList, isOutsideRadarCircle, uiPosition, uiXCentre, uiYCentre, color); // Frontier code
}

// Don't skip drawing blips if they're out of range.
DrawBlips(handle, blipDataList);
// Frontier Don't skip drawing blips if they're out of range.
NfDrawBlips(handle, blipDataList);

// Detailed view
var gridAABB = gridMatrix.TransformBox(grid.Comp.LocalAABB);
Expand Down Expand Up @@ -379,78 +364,4 @@ public class BlipData
private const int RadarBlipSize = 15;
private const int RadarFontSize = 10;

/**
* Frontier - Adds blip style triangles that are on ships or pointing towards ships on the edges of the radar.
* Draws blips at the BlipData's uiPosition and uses VectorToPosition to rotate to point towards ships.
*/
private void DrawBlips(
DrawingHandleBase handle,
List<BlipData> blipDataList
)
{
var blipValueList = new Dictionary<Color, ValueList<Vector2>>();

foreach (var blipData in blipDataList)
{
var triangleShapeVectorPoints = new[]
{
new Vector2(0, 0),
new Vector2(RadarBlipSize, 0),
new Vector2(RadarBlipSize * 0.5f, RadarBlipSize)
};

if (blipData.IsOutsideRadarCircle)
{
// Calculate the angle of rotation
var angle = (float) Math.Atan2(blipData.VectorToPosition.Y, blipData.VectorToPosition.X) + -1.6f;

// Manually create a rotation matrix
var cos = (float) Math.Cos(angle);
var sin = (float) Math.Sin(angle);
float[,] rotationMatrix = { { cos, -sin }, { sin, cos } };

// Rotate each vertex
for (var i = 0; i < triangleShapeVectorPoints.Length; i++)
{
var vertex = triangleShapeVectorPoints[i];
var x = vertex.X * rotationMatrix[0, 0] + vertex.Y * rotationMatrix[0, 1];
var y = vertex.X * rotationMatrix[1, 0] + vertex.Y * rotationMatrix[1, 1];
triangleShapeVectorPoints[i] = new Vector2(x, y);
}
}

var triangleCenterVector =
(triangleShapeVectorPoints[0] + triangleShapeVectorPoints[1] + triangleShapeVectorPoints[2]) / 3;

// Calculate the vectors from the center to each vertex
var vectorsFromCenter = new Vector2[3];
for (int i = 0; i < 3; i++)
{
vectorsFromCenter[i] = (triangleShapeVectorPoints[i] - triangleCenterVector) * UIScale;
}

// Calculate the vertices of the new triangle
var newVerts = new Vector2[3];
for (var i = 0; i < 3; i++)
{
newVerts[i] = (blipData.UiPosition * UIScale) + vectorsFromCenter[i];
}

if (!blipValueList.TryGetValue(blipData.Color, out var valueList))
{
valueList = new ValueList<Vector2>();

}
valueList.Add(newVerts[0]);
valueList.Add(newVerts[1]);
valueList.Add(newVerts[2]);
blipValueList[blipData.Color] = valueList;
}

// One draw call for every color we have
foreach (var color in blipValueList)
{
handle.DrawPrimitives(DrawPrimitiveTopology.TriangleList, color.Value.Span, color.Key);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// New Frontiers - This file is licensed under AGPLv3
// Copyright (c) 2024 New Frontiers Contributors
// See AGPLv3.txt for details.
using Content.Client.Shuttles.UI;
using Content.Shared._NF.Shuttles.Events;

namespace Content.Client.Shuttles.BUI
{
public sealed partial class ShuttleConsoleBoundUserInterface
{
private void NfOpen()
{
_window ??= new ShuttleConsoleWindow();
_window.OnInertiaDampeningModeChanged += OnInertiaDampeningModeChanged;
}
private void OnInertiaDampeningModeChanged(NetEntity? entityUid, InertiaDampeningMode mode)
{
SendMessage(new SetInertiaDampeningRequest
{
ShuttleEntityUid = entityUid,
Mode = mode,
});
}

}
}
Loading

0 comments on commit 54b34a8

Please sign in to comment.