Skip to content

Commit

Permalink
Merge https://github.com/ekrixi-14/ekrixi into morelowpop
Browse files Browse the repository at this point in the history
  • Loading branch information
Afrokada committed Jan 6, 2024
2 parents e66c51a + d1ea8c8 commit 01ff454
Show file tree
Hide file tree
Showing 43 changed files with 1,110 additions and 528 deletions.
52 changes: 27 additions & 25 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,33 @@ private void UpdateFTL(List<(NetEntity Entity, string Destination, bool Enabled)
HyperspaceDestinations.DisposeAllChildren();
_destinations.Clear();

if (destinations.Count == 0)
{
HyperspaceDestinations.AddChild(new Label()
{
Text = Loc.GetString("shuttle-console-hyperspace-none"),
HorizontalAlignment = HAlignment.Center,
});
}
else
{
destinations.Sort((x, y) => string.Compare(x.Destination, y.Destination, StringComparison.Ordinal));

foreach (var destination in destinations)
{
var button = new Button()
{
Disabled = !destination.Enabled,
Text = destination.Destination,
};

_destinations[button] = destination.Entity;
button.OnPressed += OnHyperspacePressed;
HyperspaceDestinations.AddChild(button);
}
}
// BEGIN EKRIXI MODIFICATION
// if (destinations.Count == 0)
// {
// HyperspaceDestinations.AddChild(new Label()
// {
// Text = Loc.GetString("shuttle-console-hyperspace-none"),
// HorizontalAlignment = HAlignment.Center,
// });
// }
// else
// {
// destinations.Sort((x, y) => string.Compare(x.Destination, y.Destination, StringComparison.Ordinal));
//
// foreach (var destination in destinations)
// {
// var button = new Button()
// {
// Disabled = !destination.Enabled,
// Text = destination.Destination,
// };
//
// _destinations[button] = destination.Entity;
// button.OnPressed += OnHyperspacePressed;
// HyperspaceDestinations.AddChild(button);
// }
// }
// END EKRIXI MODIFICATION

string stateText;

Expand Down
65 changes: 65 additions & 0 deletions Content.Client/_FTL/FtlPoints/StarmapConsole.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:ftlPoints="clr-namespace:Content.Client._FTL.FtlPoints"
Resizable="False"
Name="StarmapComputer"
SetSize="1000 725"
MinSize="1000 725">
<GridContainer Columns="2" Margin="5 0 5 0">
<BoxContainer Margin="0 0 5 0" Orientation="Vertical" HorizontalAlignment="Left">
<ftlPoints:StarmapControl Name="Stars"
HorizontalExpand="True"
VerticalExpand="True"
MinSize="700 700"
MaxSize="700 700"
Margin="5 0 0 0">
</ftlPoints:StarmapControl>
</BoxContainer>
<BoxContainer Orientation="Vertical"
HorizontalAlignment="Right"
MinWidth="256"
MaxWidth="256">
<controls:StripeBack>
<Label Name="GeneralDetailsLabel" Text="{Loc 'starmap-details-display-label'}" HorizontalAlignment="Center"/>
</controls:StripeBack>
<BoxContainer Name="GDReadonlyDisplay">
<GridContainer Columns="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<Label Text="{Loc 'starmap-star-details-current-star'}"/>
<Label Name="CurrentStarName"
Text="0.0"
HorizontalAlignment="Right"/>
<Label Text="{Loc 'starmap-star-details-spin-range'}"/>
<Label Name="MaxSpinRange"
Text="0.0"
HorizontalAlignment="Right"/>
<Label Text="{Loc 'starmap-star-details-crystal-integrity'}"/>
<Label Name="CrystalIntegrity"
Text="0.0"
HorizontalAlignment="Right"/>
</GridContainer>
</BoxContainer>

<controls:StripeBack>
<Label Name="StarDetailsLabel" Text="{Loc 'starmap-star-details-display-label'}" HorizontalAlignment="Center"/>
</controls:StripeBack>
<BoxContainer Name="SDReadonlyDisplay">
<GridContainer Columns="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<Label Text="{Loc 'starmap-star-details-name'}"/>
<Label Name="StarName"
Text="0.0"
HorizontalAlignment="Right"/>
<Label Text="{Loc 'starmap-star-details-coordinates'}"/>
<Label Name="StarCoordinates"
Text="0.0"
HorizontalAlignment="Right"/>
<Button Name="StarWarpButton" Text="{Loc 'starmap-star-details-button-warp'}" Disabled="True"/>
</GridContainer>
</BoxContainer>
</BoxContainer>
</GridContainer>
</controls:FancyWindow>
55 changes: 55 additions & 0 deletions Content.Client/_FTL/FtlPoints/StarmapConsole.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Numerics;
using Content.Client.UserInterface.Controls;
using Content.Shared._FTL.FtlPoints;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client._FTL.FtlPoints;

[GenerateTypedNameReferences]
public sealed partial class StarmapConsole : FancyWindow
{
private readonly StarmapConsoleBoundUserInterface _owner;
private Star? _hoveredStar = null;

public StarmapConsole(StarmapConsoleBoundUserInterface owner, IPrototypeManager protoManager)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_owner = owner;

Title = Loc.GetString("starmap-computer-title");
Stars.OnStarSelect += StarsOnOnStarSelect;
StarWarpButton.OnPressed += args =>
{
if (_hoveredStar.HasValue)
{
_owner.StarWarpButtonOnOnPressed(_hoveredStar.Value);
}
};
}

private void StarsOnOnStarSelect(Star obj)
{
StarName.Text = obj.Name;
StarCoordinates.Text = Loc.GetString("starmap-star-details-position", ("x", MathF.Round(obj.GlobalPosition.X, 1)), ("y", MathF.Round(obj.GlobalPosition.Y, 1)));
StarWarpButton.Disabled = false;
_hoveredStar = obj;
}

public void UpdateState(StarmapConsoleBoundUserInterfaceState state)
{
UpdateStars(state.Stars);
Stars.Range = state.Range;
var currentStar = state.Stars.Find(star => star.Position == Vector2.Zero);
CurrentStarName.Text = currentStar.Name;
}

private void UpdateStars(List<Star> stars)
{
Stars.SetStars(stars);
}
}
50 changes: 50 additions & 0 deletions Content.Client/_FTL/FtlPoints/StarmapConsoleBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Shared._FTL.FtlPoints;
using Robust.Shared.Prototypes;
using JetBrains.Annotations;
using Robust.Client.UserInterface.Controls;

namespace Content.Client._FTL.FtlPoints;

[UsedImplicitly]
public sealed class StarmapConsoleBoundUserInterface : BoundUserInterface
{
private StarmapConsole? _window;

public StarmapConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) {}

protected override void Open()
{
base.Open();
var collection = IoCManager.Instance;

if (collection == null)
return;

_window = new StarmapConsole(this, IoCManager.Resolve<IPrototypeManager>());
_window.OnClose += Close;

_window.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}

public void StarWarpButtonOnOnPressed(Star star)
{
var message = new WarpToStarMessage(star);
SendMessage(message);
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
var castState = (StarmapConsoleBoundUserInterfaceState) state;
_window?.UpdateState(castState);
}
}
127 changes: 127 additions & 0 deletions Content.Client/_FTL/FtlPoints/StarmapControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System.Numerics;
using Content.Shared._FTL.FtlPoints;
using Content.Shared.Input;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Shared.Input;
using YamlDotNet.Core.Tokens;

namespace Content.Client._FTL.FtlPoints;

public sealed class StarmapControl : Control
{
[Dependency] private readonly IInputManager _inputManager = default!;

public float Range = 1f;

private List<Star> _stars = new List<Star>();
private const float Ppd = 15f;

private readonly Font _font;
private bool _mouseDown = false;

public event Action<Star>? OnStarSelect;

public StarmapControl()
{
IoCManager.InjectDependencies(this);

var cache = IoCManager.Resolve<IResourceCache>();
_font = new VectorFont(cache.GetResource<FontResource>("/Fonts/IBMPlexMono/IBMPlexMono-Regular.ttf"), 8);
}

public void SetStars(List<Star> stars)
{
_stars = stars;
}

private Vector2 CalculateOffset()
{
return Size / 2;
}

private Vector2 GetMouseCoordinates()
{
return _inputManager.MouseScreenPosition.Position;
}

private Vector2 GetPositionOfStar(Vector2 position)
{
return CalculateOffset() + (position * Ppd);
}

protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
handle.DrawRect(new UIBox2(Vector2.Zero, Size), Color.Black);

// Draw lines in a grid
var lines = 10;

for (var i = 0; i < lines; i++)
{
var xStep = Size.X / lines;
var yStep = Size.X / lines;
handle.DrawLine(new Vector2(i * xStep, 0), new Vector2(i * xStep, Size.Y), Color.DarkSlateGray);
handle.DrawLine(new Vector2(0, i * yStep), new Vector2(Size.X, i * yStep), Color.DarkSlateGray);
}

// Draw warp range
handle.DrawCircle(GetPositionOfStar(Vector2.Zero), Range * Ppd, Color.White, false);
handle.DrawCircle(GetPositionOfStar(Vector2.Zero), Range * Ppd, new Color(47, 79, 79, 127));

// Draw sensor range
handle.DrawCircle(GetPositionOfStar(Vector2.Zero), (int) (Range * 1.5) * Ppd, Color.Blue, false);

foreach (var star in _stars)
{
var uiPosition = GetPositionOfStar(star.Position);
var globalPosition = GlobalPosition + uiPosition;
var radius = 5f;

// check if distance is smaller than radius of circle then BOOm
var hovered = Vector2.Distance(GetMouseCoordinates(), globalPosition) <= radius * 1.5;

var color = Color.White;
var name = star.Name;

// out of warp range
if (Vector2.Distance(Vector2.Zero, star.Position) >= Range)
color = Color.Red;

// out of scanning range
if (Vector2.Distance(Vector2.Zero, star.Position) >= Range * 1.5)
{
color = Color.DarkRed;
name = Loc.GetString("ship-ftl-tag-oor");
}

if (star.Position == Vector2.Zero)
color = Color.Blue;

// before circle rendering so that we can change whats rendered
if (hovered)
{
radius = 10f;
}
handle.DrawCircle(uiPosition, radius, color);

// after circle rendering incase we wish to show text/etc
if (hovered)
{
handle.DrawString(_font, uiPosition + new Vector2(10, 0), name);
}

// on click
if (!hovered || !_inputManager.IsKeyDown(Keyboard.Key.MouseLeft))
continue;

if (Vector2.Distance(Vector2.Zero, star.Position) >= Range)
continue; // out of warp range

OnStarSelect?.Invoke(star);
}
}
}
1 change: 1 addition & 0 deletions Content.Client/_FTL/ShipWeapons/GunnerConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
HorizontalAlignment="Right"/>
</GridContainer>
</BoxContainer>

<controls:StripeBack>
<Label Name="GunControlLabel" Text="{Loc 'gunner-console-gun-control-label'}" HorizontalAlignment="Center"/>
</controls:StripeBack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public sealed partial class ShuttleSystem
private MapId? _hyperSpaceMap;

public const float DefaultStartupTime = 13.5f;
public const float DefaultTravelTime = 60f;
public const float DefaultTravelTime = 60;
public const float DefaultArrivalTime = 5f;
private const float FTLCooldown = 30f;
private const float FTLCooldown = 35f;
private const float ShuttleFTLRange = 100f;

/// <summary>
Expand Down
Loading

0 comments on commit 01ff454

Please sign in to comment.