Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #210 from user424242420/time-left-pda
Browse files Browse the repository at this point in the history
Время до эвака в кпк
  • Loading branch information
Vonsant authored May 31, 2024
2 parents 66bb467 + b488d68 commit 346e1f3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Content.Client/PDA/PdaMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<ContainerButton Name="StationTimeButton">
<RichTextLabel Name="StationTimeLabel" Access="Public"/>
</ContainerButton>
<ContainerButton Name="ShuttleLeftTimeButton">
<RichTextLabel Name="ShuttleLeftTimeLabel" Access="Public"/>
</ContainerButton>
<ContainerButton Name="StationAlertLevelInstructionsButton">
<RichTextLabel Name="StationAlertLevelInstructions" Access="Public"/>
</ContainerButton>
Expand Down
28 changes: 26 additions & 2 deletions Content.Client/PDA/PdaMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public sealed partial class PdaMenu : PdaWindow
public const int SettingsView = 2;
public const int ProgramContentView = 3;

private TimeSpan shuttleEvacTimeSpan;

private string _pdaOwner = Loc.GetString("comp-pda-ui-unknown");
private string _owner = Loc.GetString("comp-pda-ui-unknown");
private string _jobTitle = Loc.GetString("comp-pda-ui-unassigned");
private string _stationName = Loc.GetString("comp-pda-ui-unknown");
private string _alertLevel = Loc.GetString("comp-pda-ui-unknown");
private string _timeLeftShuttle = Loc.GetString("comp-pda-ui-unknown");
private string _instructions = Loc.GetString("comp-pda-ui-unknown");
private string _balance = Loc.GetString("comp-pda-ui-unknown");

Expand Down Expand Up @@ -116,6 +118,11 @@ public PdaMenu()
_clipboard.SetText(_alertLevel);
};

ShuttleLeftTimeButton.OnPressed += _ =>
{
_clipboard.SetText(_timeLeftShuttle);
};

BalanceButton.OnPressed += _ =>
{
_clipboard.SetText(_balance);
Expand Down Expand Up @@ -165,14 +172,25 @@ public void UpdateState(PdaUpdateState state)
StationNameLabel.SetMarkup(Loc.GetString("comp-pda-ui-station",
("station", _stationName)));

_balance = Loc.GetString("comp-pda-ui-balance", ("balance", state.Balance));
BalanceLabel.SetMarkup(_balance);
if (state.Balance is not null)
{
_balance = Loc.GetString("comp-pda-ui-balance", ("balance", state.Balance.Value));
BalanceLabel.SetMarkup(_balance);
}

var stationTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan);

StationTimeLabel.SetMarkup(Loc.GetString("comp-pda-ui-station-time",
("time", stationTime.ToString("hh\\:mm\\:ss"))));

shuttleEvacTimeSpan = state.EvacShuttleTime ?? TimeSpan.Zero;
var shuttleEvacTime = shuttleEvacTimeSpan - _gameTiming.CurTime;
if (state.EvacShuttleTime is not null)
_timeLeftShuttle = Loc.GetString("comp-pda-ui-left-time",
("time", shuttleEvacTime.ToString("hh\\:mm\\:ss")));

ShuttleLeftTimeLabel.SetMarkup(_timeLeftShuttle);

var alertLevel = state.PdaOwnerInfo.StationAlertLevel;
var alertColor = state.PdaOwnerInfo.StationAlertColor;
var alertLevelKey = alertLevel != null ? $"alert-level-{alertLevel}" : "alert-level-unknown";
Expand Down Expand Up @@ -346,6 +364,12 @@ protected override void Draw(DrawingHandleScreen handle)

StationTimeLabel.SetMarkup(Loc.GetString("comp-pda-ui-station-time",
("time", stationTime.ToString("hh\\:mm\\:ss"))));

var shuttleEvacTime = shuttleEvacTimeSpan - _gameTiming.CurTime;
_timeLeftShuttle = Loc.GetString("comp-pda-ui-left-time",
("time", shuttleEvacTime.TotalSeconds <= 0 ? Loc.GetString("comp-pda-ui-unknown") : shuttleEvacTime.ToString("hh\\:mm\\:ss")));

ShuttleLeftTimeLabel.SetMarkup(_timeLeftShuttle);
}
}
}
31 changes: 28 additions & 3 deletions Content.Server/PDA/PdaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using Content.Server.Light.EntitySystems;
using Content.Server.PDA.Ringer;
using Content.Server.Station.Systems;
using Content.Server.RoundEnd;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Systems;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared.Access.Components;
Expand All @@ -21,20 +24,25 @@
using Robust.Shared.Containers;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;

namespace Content.Server.PDA
{
public sealed class PdaSystem : SharedPdaSystem
{
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly CartridgeLoaderSystem _cartridgeLoader = default!;
[Dependency] private readonly InstrumentSystem _instrument = default!;
[Dependency] private readonly RingerSystem _ringer = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly EmergencyShuttleSystem _emergencyShuttleSystem = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;

public override void Initialize()
{
Expand All @@ -51,6 +59,8 @@ public override void Initialize()
SubscribeLocalEvent<PdaComponent, PdaShowUplinkMessage>(OnUiMessage);
SubscribeLocalEvent<PdaComponent, PdaLockUplinkMessage>(OnUiMessage);

SubscribeLocalEvent<RoundEndSystemChangedEvent>(OnEmergencyChanged);

SubscribeLocalEvent<PdaComponent, CartridgeLoaderNotificationSentEvent>(OnNotification);

SubscribeLocalEvent<StationRenamedEvent>(OnStationRenamed);
Expand Down Expand Up @@ -104,6 +114,11 @@ private void OnStationRenamed(StationRenamedEvent ev)
UpdateAllPdaUisOnStation();
}

private void OnEmergencyChanged(RoundEndSystemChangedEvent ev)
{
UpdateAllPdaUisOnStation();
}

private void OnAlertLevelChanged(AlertLevelChangedEvent args)
{
UpdateAllPdaUisOnStation();
Expand Down Expand Up @@ -166,9 +181,18 @@ public void UpdatePdaUi(EntityUid uid, PdaComponent? pda = null, EntityUid? acto

var programs = _cartridgeLoader.GetAvailablePrograms(uid, loader);
var id = CompOrNull<IdCardComponent>(pda.ContainedId);
var balance = 0;
if (actor_uid != null && TryComp<BankAccountComponent>(actor_uid, out var account))
balance = account.Balance;
int? balance = null;
if (actor_uid is not null && TryComp<BankAccountComponent>(actor_uid, out var account))
balance = account.Balance;

TimeSpan shuttleTime;
var station = _station.GetOwningStation(uid);
if (!TryComp<StationEmergencyShuttleComponent>(station, out var stationEmergencyShuttleComponent) && _roundEndSystem.ExpectedCountdownEnd is not null)
shuttleTime = _roundEndSystem.ExpectedCountdownEnd.Value;

else
shuttleTime = TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.EmergencyShuttleDockTime));


var state = new PdaUpdateState(
programs,
Expand All @@ -186,6 +210,7 @@ public void UpdatePdaUi(EntityUid uid, PdaComponent? pda = null, EntityUid? acto
StationAlertColor = pda.StationAlertColor
},
balance,
shuttleTime,
pda.StationName,
showUplink,
hasInstrument,
Expand Down
7 changes: 5 additions & 2 deletions Content.Shared/PDA/PdaUpdateState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public sealed class PdaUpdateState : CartridgeLoaderUiState // WTF is this. what
public bool HasUplink;
public bool CanPlayMusic;
public string? Address;
public int Balance;
public int? Balance;
public TimeSpan? EvacShuttleTime;

public PdaUpdateState(
List<NetEntity> programs,
Expand All @@ -27,7 +28,8 @@ public PdaUpdateState(
bool hasPai,
bool hasBook,
PdaIdInfoText pdaOwnerInfo,
int balance,
int? balance,
TimeSpan? evacShuttleTime,
string? stationName,
bool hasUplink = false,
bool canPlayMusic = false,
Expand All @@ -44,6 +46,7 @@ public PdaUpdateState(
StationName = stationName;
Address = address;
Balance = balance;
EvacShuttleTime = evacShuttleTime;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Resources/Locale/ru-RU/pda/pda-component.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ comp-pda-ui-unknown = Неизвестно
comp-pda-ui-unassigned = Не назначено
pda-notification-message = [font size=12][bold]КПК[/bold] { $header }: [/font]
"{ $message }"
comp-pda-ui-balance = Баланс: [color=white]{ $balance }[/color]
comp-pda-ui-balance = Баланс: [color=white]{ $balance }$[/color]
comp-pda-ui-left-time = Время до эвакуации: [color=white]{ $time }[/color]

0 comments on commit 346e1f3

Please sign in to comment.