Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planetside and space elevator #4

Merged
merged 4 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Content.Shared._Emberfall.Planetside.Systems;

namespace Content.Client._Emberfall.Planetside.Systems;

public sealed class SpaceElevatorConsoleSystem : SharedSpaceElevatorConsoleSystem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Content.Shared._Emberfall.Planetside.Systems;

namespace Content.Client._Emberfall.Planetside.Systems;

public sealed class SpaceElevatorSystem : SharedSpaceElevatorSystem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Content.Shared._Emberfall.Planetside;

namespace Content.Client._Emberfall.Planetside.UI;

public sealed class SpaceElevatorBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
{
[ViewVariables]
private SpaceElevatorConsoleWindow? _window;

protected override void Open()
{
base.Open();

_window = new SpaceElevatorConsoleWindow(Owner);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnFTL += index => SendMessage(new DockingConsoleFTLMessage(index));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not SpaceElevatorConsoleState cast)
return;

_window?.UpdateState(cast);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
_window?.Orphan();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'space-elevator-console-title'}"
MinSize="400 500">
<BoxContainer Orientation="Vertical" Margin="5 5 5 5">
<!-- Status header -->
<controls:StripeBack MinSize="48 48">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="8 0">
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<Label Text="{Loc 'space-elevator-status-label'}" StyleClasses="LabelHeading"/>
<Label Name="MapFTLState" StyleClasses="LabelSubText"/>
</BoxContainer>
<PanelContainer StyleClasses="Inset" VerticalAlignment="Center">
<ProgressBar Name="FTLBar"
MinValue="0.0"
MaxValue="1.0"
Value="1.0"
MinSize="100 20"/>
</PanelContainer>
</BoxContainer>
</controls:StripeBack>

<!-- Destinations panel -->
<PanelContainer StyleClasses="AngleRect" VerticalExpand="True" Margin="0 5 0 5">
<BoxContainer Orientation="Vertical">
<controls:StripeBack>
<Label Text="{Loc 'space-elevator-destinations-label'}"
StyleClasses="LabelHeading"
Margin="8 0"/>
</controls:StripeBack>
<ScrollContainer VerticalExpand="True" HorizontalExpand="True" Margin="1">
<PanelContainer VerticalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E"/>
</PanelContainer.PanelOverride>
<ItemList Name="Destinations"
VerticalExpand="True"
HorizontalExpand="True"
SelectMode="Single"
Margin="2"/>
</PanelContainer>
</ScrollContainer>
</BoxContainer>
</PanelContainer>

<!-- Control panel -->
<PanelContainer StyleClasses="AngleRect">
<BoxContainer Orientation="Vertical">
<controls:StripeBack>
<Label Text="{Loc 'space-elevator-controls-label'}"
StyleClasses="LabelHeading"
Margin="8 0"/>
</controls:StripeBack>
<BoxContainer Orientation="Horizontal"
HorizontalAlignment="Center"
Margin="8">
<Button Name="FTLButton"
Text="{Loc 'space-elevator-ftl'}"
TextAlign="Center"
MinSize="200 38"
Disabled="True"/>
</BoxContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using Content.Client.UserInterface.Controls;
using Content.Shared._Emberfall.Planetside;
using Content.Shared._Emberfall.Planetside.Components;
using Content.Shared.Shuttles.Systems;
using Content.Shared.Timing;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;

namespace Content.Client._Emberfall.Planetside.UI;

[GenerateTypedNameReferences]
public sealed partial class SpaceElevatorConsoleWindow : FancyWindow
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IGameTiming _timing = default!;

public event Action<int>? OnFTL;

private readonly Dictionary<FTLState, (string Color, string Loc)> _stateData = new()
{
{ FTLState.Available, ("#80C71F", "shuttle-console-ftl-state-Available") },
{ FTLState.Starting, ("#169C9C", "shuttle-console-ftl-state-Starting") },
{ FTLState.Travelling, ("#8932B8", "shuttle-console-ftl-state-Travelling") },
{ FTLState.Arriving, ("#F9801D", "shuttle-console-ftl-state-Arriving") },
};

private readonly StyleBoxFlat _ftlStyle;
private FTLState _state;
private int? _selected;
private StartEndTime _ftlTime;

public SpaceElevatorConsoleWindow(EntityUid owner)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_ftlStyle = new StyleBoxFlat()
{
BackgroundColor = Color.FromHex("#80C71F"),
ContentMarginLeftOverride = 4,
ContentMarginRightOverride = 4
};
FTLBar.ForegroundStyleBoxOverride = _ftlStyle;

if (!_entMan.TryGetComponent<SpaceElevatorConsoleComponent>(owner, out var comp))
return;

if (!comp.HasPlatform)
{
MapFTLState.Text = Loc.GetString("docking-console-no-shuttle");
_ftlStyle.BackgroundColor = Color.FromHex("#B02E26");
}

SetupEventHandlers();
}

private void SetupEventHandlers()
{
Destinations.OnItemSelected += args =>
{
_selected = args.ItemIndex;
UpdateButton();
};

Destinations.OnItemDeselected += _ =>
{
_selected = null;
UpdateButton();
};

FTLButton.OnPressed += _ =>
{
if (_selected is { } index)
{
OnFTL?.Invoke(index);
FTLButton.Disabled = true;
}
};
}

public void UpdateState(SpaceElevatorConsoleState state)
{
_state = state.FTLState;
_ftlTime = state.FTLTime;

var (color, locString) = _stateData.GetValueOrDefault(_state,
("#B02E26", "shuttle-console-ftl-state-Cooldown"));

MapFTLState.Text = Loc.GetString(locString);
_ftlStyle.BackgroundColor = Color.FromHex(color);

if (Destinations.Count != state.Destinations.Count)
{
UpdateDestinations(state.Destinations);
}

UpdateButton();
}

private void UpdateDestinations(List<ElevatorDestination> destinations)
{
Destinations.Clear();
foreach (var dest in destinations)
{
Destinations.AddItem(dest.Name);
}
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);

var progress = _ftlTime.ProgressAt(_timing.CurTime);
FTLBar.Value = float.IsFinite(progress) ? progress : 1;

UpdateButton();
}

private void UpdateButton()
{
FTLButton.Disabled = _selected == null || _state != FTLState.Available;
}
}
6 changes: 3 additions & 3 deletions Content.Server/Shuttles/Systems/ArrivalsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public sealed class ArrivalsSystem : EntitySystem

private readonly List<ProtoId<BiomeTemplatePrototype>> _arrivalsBiomeOptions = new()
{
"Grasslands",
"LowDesert",
// "Grasslands", // Emberfall
// "LowDesert", // Emberfall
"Snow",
};

Expand Down Expand Up @@ -534,7 +534,7 @@ private void SetupArrivalsStation()
_biomes.EnsurePlanet(mapUid, _protoManager.Index(template));
var restricted = new RestrictedRangeComponent
{
Range = 32f
Range = 64f // Emberfall, was 32
};
AddComp(mapUid, restricted);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Server._Emberfall.Planetside.Systems;
using Content.Shared._Emberfall.Planetside;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Server._Emberfall.Planetside.Components;

/// <summary>
/// This is used to load a map and then spawn a grid on it.
/// </summary>
[RegisterComponent, Access(typeof(PlanetsideTerrainSpawnerSystem))]
public sealed partial class PlanetsideTerrainSpawnerComponent : Component
{
/// <summary>
/// The terrain template to use.
/// </summary>
[DataField(required: true)]
public ProtoId<TerrainTemplatePrototype> Terrain;

/// <summary>
/// The grid to load when spawning the map.
/// </summary>
[DataField]
public ResPath? GridPath;

/// <summary>
/// The loaded map entity.
/// </summary>
[DataField]
public EntityUid? Map;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Server._Emberfall.Planetside.Components;

namespace Content.Server._Emberfall.Planetside.Systems;

/// <summary>
/// This handles spawning a new map from a TerrainTemplatePrototype.
/// <seealso cref="PlanetsideTerrainSystem"/>
/// </summary>
public sealed class PlanetsideTerrainSpawnerSystem : EntitySystem
{
[Dependency] private readonly PlanetsideTerrainSystem _planetside = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<PlanetsideTerrainSpawnerComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<PlanetsideTerrainSpawnerComponent, MapInitEvent>(OnMapInit);
}

private void OnShutdown(Entity<PlanetsideTerrainSpawnerComponent> ent, ref ComponentShutdown args)
{
QueueDel(ent.Comp.Map);
}

private void OnMapInit(Entity<PlanetsideTerrainSpawnerComponent> ent, ref MapInitEvent args)
{
// No terrain - needed for test to not fail
if (string.IsNullOrEmpty(ent.Comp.Terrain))
return;

if (ent.Comp.GridPath is { } path)
{
ent.Comp.Map = _planetside.GenerateTerrainWithStructures(ent.Comp.Terrain, path.ToString());
return;
}

ent.Comp.Map = _planetside.GenerateTerrain(ent.Comp.Terrain);
}
}
Loading
Loading