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

Centcom rework #624

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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,60 @@
using Content.Client._Sunrise.CentCom.UI;
using Content.Shared._Sunrise.CentCom;
using Content.Shared._Sunrise.CentCom.BUIStates;
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using JetBrains.Annotations;

namespace Content.Client._Sunrise.CentCom.BUI;

[UsedImplicitly]
public sealed class CentComCargoConsoleBoundUserInterface : BoundUserInterface
{
private CentComCargoConsoleWindow? _window;
private EntityUid? _owner;

public CentComCargoConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_owner = owner;
}

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

_window = this.CreateWindow<CentComCargoConsoleWindow>();

_window.OnSendGifts += WindowOnOnSendGifts;

_window.OpenCentered();

if (!EntMan.TryGetComponent(_owner, out CentComCargoConsoleComponent? component))
return;

foreach (var i in component.Gifts)
{
_window.AddElement(i.Title, i.Description, i.Contents, i.Event);
}
}

private void WindowOnOnSendGifts(string? obj)
{
if (obj == null)
{
return;
}

SendMessage(new CentComCargoSendGiftMessage(obj));
}

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

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Content.Client._Sunrise.CentCom.UI;
using Content.Shared._Sunrise.CentCom;
using Content.Shared._Sunrise.CentCom.BUIStates;
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using static Content.Shared._Sunrise.CentCom.CentComConsoleComponent;

namespace Content.Client._Sunrise.CentCom.BUI;

[UsedImplicitly]
public sealed class CentComConsoleBoundUserInterface : BoundUserInterface
{
private static readonly string MinuteString = "минут";

private CentComConsoleWindow? _window;
private EntityUid? _owner;

public CentComConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_owner = owner;
}

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

_window = this.CreateWindow<CentComConsoleWindow>();

_window.IdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(IdCardSlotId));

_window.OnEmergencyShuttle += args => EmergencyShuttleButtonOnOnPressed(args);

_window.OnClose += Close;
_window.OnAnnounce += s => SendMessage(new CentComConsoleAnnounceMessage(s));
_window.OnAlertLevel += s => SendMessage(new CentComConsoleAlertLevelChangeMessage(s));
_window.OpenCentered();
}

private void EmergencyShuttleButtonOnOnPressed(object? args)
{
if (args == null)
return;
var arg = (ShuttleDelay)args;
// TODO: Check if arg is valid
if (_window?.LastTime == null)
{
SendMessage(new CentComConsoleCallEmergencyShuttleMessage(arg.Time));
}
else
{
SendMessage(new CentComConsoleRecallEmergencyShuttleMessage());
}
}

private TimeSpan ConvertHumanReadableToTimeSpan(string time)
{
var minutesString = time.Replace(MinuteString, "");
if (!int.TryParse(minutesString, out var minutes))
return TimeSpan.Zero;
return TimeSpan.FromMinutes(minutes);
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
var commsState = state as CentComConsoleBoundUserInterfaceState;
if (commsState == null)
return;
if (_window == null)
return;

_window.UpdateState(commsState);
_owner = EntMan.GetEntity(commsState.Owner);
}

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

_window?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Client._Sunrise.CentCom.Systems;

/// <summary>
/// This handles...
/// </summary>
public sealed class CentComCargoConsoleSystem : EntitySystem
{
/// <inheritdoc/>
public override void Initialize()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:centcom="clr-namespace:Content.Client._Sunrise.CentCom.UI"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'centcom-gifts-console-title'}"
MinSize="600 600">
<PanelContainer VerticalExpand="True" HorizontalExpand="True" HorizontalAlignment="Stretch"
StyleClasses="PdaBackground" Margin="5 5 5 5">
<ScrollContainer Name="ScrollContainer"
VerticalExpand="True"
HorizontalAlignment="Stretch"
HorizontalExpand="True">
<BoxContainer Name="Container"
Orientation="Vertical"
HorizontalExpand="True"
HorizontalAlignment="Stretch"
Margin="10 0 10 0">

</BoxContainer>
</ScrollContainer>
</PanelContainer>
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
VerticalAlignment="Bottom" HorizontalAlignment="Right" SetSize="19 19"/>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Client.UserInterface.Controls;
using Content.Shared._Sunrise.CentCom.BUIStates;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._Sunrise.CentCom.UI;

[GenerateTypedNameReferences]
public sealed partial class CentComCargoConsoleWindow : FancyWindow
{
public event Action<string?>? OnSendGifts;

public CentComCargoConsoleWindow()
{
RobustXamlLoader.Load(this);
}

public void UpdateState(CentComCargoConsoleBoundUserInterfaceState state)
{

}

public void AddElement(string title, string description, List<string> contents, string? prototype=null)
{
var newControl = new CentComGiftsConsoleEntry(title, description, contents, prototype);
newControl.OnSendButton += s => OnSendGifts?.Invoke(s);
Container.AddChild(newControl);
}
}

41 changes: 41 additions & 0 deletions Content.Client/_Sunrise/CentCom/UI/CentComConsoleWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'centcom-console-window-title'}"
MinSize="800 200">
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<GridContainer Columns="2">
<GridContainer Columns="3" HorizontalExpand="True">
<Label Text="{Loc 'centcom-card-console-id'}"/>
<Button Name="IdButton" Access="Public" MinHeight="30"/>
<Label Name="IdLabel"/>
</GridContainer>
<BoxContainer Orientation="Vertical" HorizontalAlignment="Right">
<Label Name="StationNameLabel" Text="{Loc 'centcom-console-window-station'}"/>
</BoxContainer>
</GridContainer>
<!-- <TabContainer Name="TabContainer"> -->
<PanelContainer Name="{Loc 'centcom-console-alert-levels-control'}" StyleClasses="BackgroundDark">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="5">
<TextEdit Name="MessageInput" HorizontalExpand="True" VerticalExpand="True" Margin="0 0 0 5" MinHeight="100" />
<Button Name="AnnounceButton" Text="{Loc 'comms-console-menu-announcement-button'}" ToolTip="{Loc 'comms-console-menu-announcement-button-tooltip'}" StyleClasses="OpenLeft" Access="Public" />

<OptionButton Name="AlertLevelButton" ToolTip="{Loc 'comms-console-menu-alert-level-button-tooltip'}" StyleClasses="OpenRight" Access="Public" />

<Control MinSize="10 10" />

<RichTextLabel Name="CountdownLabel" VerticalExpand="True"/>
<GridContainer Columns="2">
<OptionButton Name="DurationButton" StyleClasses="OpenRight" Access="Public" />
<Button Name="EmergencyShuttleButton" StyleClasses="OpenLeft" Text="Placeholder Text" ToolTip="{Loc 'comms-console-menu-emergency-shuttle-button-tooltip'}" Access="Public" HorizontalExpand="True"/>
</GridContainer>
</BoxContainer>
</PanelContainer>
<!-- <PanelContainer Name="{Loc 'centcom-console-ert-control'}" StyleClasses="BackgroundDark"> -->
<!-- <GridContainer Rows="2"> -->
<!-- <Label Text="{Loc 'centcom-console-window-ert-alert'}"/> -->
<!-- <ScrollContainer Name="ErtGroups"/> -->
<!-- </GridContainer> -->
<!-- </PanelContainer> -->
<!-- </TabContainer> -->
</BoxContainer>
</controls:FancyWindow>
122 changes: 122 additions & 0 deletions Content.Client/_Sunrise/CentCom/UI/CentComConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using Content.Client.UserInterface.Controls;
using Content.Shared._Sunrise.CentCom.BUIStates;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client._Sunrise.CentCom.UI;

[GenerateTypedNameReferences]
public sealed partial class CentComConsoleWindow : FancyWindow
{
public TimeSpan? LastTime;
public event Action<string>? OnAnnounce;
public event Action<string>? OnAlertLevel;
public event Action<object?>? OnEmergencyShuttle;
private bool SelectedTimeFlag = false;

public CentComConsoleWindow()
{
RobustXamlLoader.Load(this);

// А вот так вот
Resizable = false;

AnnounceButton.OnPressed += _ => OnAnnounce?.Invoke(Rope.Collapse(MessageInput.TextRope));

AlertLevelButton.OnItemSelected += args =>
{
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
if (metadata != null && metadata is string cast)
{
OnAlertLevel?.Invoke(cast);
}
};

DurationButton.OnItemSelected += args =>
{
DurationButton.SelectId(args.Id);
SelectedTimeFlag = true;
};

EmergencyShuttleButton.OnPressed += _ =>
OnEmergencyShuttle?.Invoke(DurationButton.SelectedMetadata);
}

public void UpdateState(CentComConsoleBoundUserInterfaceState state)
{
IdButton.Text = state.IsIdPresent
? Loc.GetString("id-card-console-window-eject-button")
: Loc.GetString("id-card-console-window-insert-button");
IdLabel.Text = state.IdName != string.Empty
? state.IdName
: Loc.GetString("centcom-console-window-empty-id");
if (state.Station != null)
{
StationNameLabel.Text = state.Station.Name;

AlertLevelButton.Clear();
foreach (var alertLevel in state.Station.AlertLevels)
{
var name = alertLevel;
if (Loc.TryGetString($"alert-level-{alertLevel}", out var locName))
{
name = locName;
}
AlertLevelButton.AddItem(name);
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, alertLevel);

if (alertLevel == state.Station.CurrentAlert)
{
AlertLevelButton.Select(AlertLevelButton.ItemCount - 1);
}
}

DurationButton.Clear();
foreach (var del in state.Station.Delays)
{
var delay = del;
if (Loc.TryGetString($"centcom-console-duration-{delay.Label}", out var locDelay))
{
delay.Label = locDelay;
}
DurationButton.AddItem(delay.Label);
DurationButton.SetItemMetadata(DurationButton.ItemCount - 1, delay);

if (delay.Time == state.Station.DefaultDelay && !SelectedTimeFlag)
{
DurationButton.Select(DurationButton.ItemCount - 1);
}
}

if (!state.SentEvac)
{
EmergencyShuttleButton.Text = Loc.GetString("centcom-console-call-shuttle-label");
LastTime = null;
}
else
{
if (state.LeftBeforeEvac != null)
{
EmergencyShuttleButton.Text = $"Осталось {(int)Math.Floor(state.LeftBeforeEvac.Value.TotalSeconds)}с";
LastTime = state.LeftBeforeEvac;
}
}
}

AnnounceButton.Disabled = !(state.IsIdPresent && state.IdEnoughPermissions);
DurationButton.Disabled = !(state.IsIdPresent && state.IdEnoughPermissions);
EmergencyShuttleButton.Disabled = !(state.IsIdPresent && state.IdEnoughPermissions);
AlertLevelButton.Disabled = !(state.IsIdPresent && state.IdEnoughPermissions);
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (LastTime == null)
return;
EmergencyShuttleButton.Text = $"Осталось {(int)Math.Floor((LastTime.Value - TimeSpan.FromSeconds(args.DeltaSeconds)).TotalSeconds)}с";
LastTime = LastTime.Value - TimeSpan.FromSeconds(args.DeltaSeconds);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<PanelContainer xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
HorizontalAlignment="Stretch"
HorizontalExpand="True"
StyleClasses="AngleRect"
ModulateSelfOverride="#2b2b31"
Margin="0 5 0 5">
<BoxContainer Orientation="Vertical" Margin="5 0 5 0">
<GridContainer Columns="2">
<RichTextLabel Name="TitleLabel" Text="{Loc 'centcom-gifts-console-unknown'}" HorizontalAlignment="Stretch"
HorizontalExpand="True"/>
<Button Name="SendGiftButton" Text="{Loc 'centcom-gifts-console-send'}" HorizontalAlignment="Right"/>
</GridContainer>
<RichTextLabel Name="DescriptionLabel" Text="{Loc 'centcom-gifts-console-unknown'}"/>
<controls:HLine Color="#404040" Thickness="2" Margin="0 5 0 5"/>
<RichTextLabel Name="ContentLabel" Text="{Loc 'centcom-gifts-console-unknown'}"/>
</BoxContainer>
</PanelContainer>
Loading
Loading