Skip to content

Commit

Permalink
Merge pull request #122 from new-frontiers-14/manifest_destiny
Browse files Browse the repository at this point in the history
Station Records Job Customization
  • Loading branch information
Cheackraze authored Jul 31, 2023
2 parents 9d7edff + 073fe10 commit a1a0a2d
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Content.Shared.StationRecords;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using static Robust.Client.UserInterface.Controls.BaseButton;

namespace Content.Client.StationRecords;

Expand All @@ -19,6 +21,8 @@ protected override void Open()
_window = new();
_window.OnKeySelected += OnKeySelected;
_window.OnFiltersChanged += OnFiltersChanged;
_window.OnJobAdd += OnJobsAdd;
_window.OnJobSubtract += OnJobsSubtract;
_window.OnClose += Close;

_window.OpenCentered();
Expand All @@ -36,6 +40,25 @@ private void OnFiltersChanged(
SendMessage(msg);
}

private void OnJobsAdd(ButtonEventArgs args)
{
if (args.Button.Parent?.Parent is not JobRow row || row.Job == null)
{
return;
}

AdjustStationJobMsg msg = new(row.Job, 1);
SendMessage(msg);
}
private void OnJobsSubtract(ButtonEventArgs args)
{
if (args.Button.Parent?.Parent is not JobRow row || row.Job == null)
{
return;
}
AdjustStationJobMsg msg = new(row.Job, -1);
SendMessage(msg);
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Title="{Loc 'general-station-record-console-window-title'}"
MinSize="750 500">
<BoxContainer Orientation="Vertical">
<BoxContainer Margin="5 5 5 10" HorizontalExpand="true" VerticalAlignment="Center">
<BoxContainer Margin="5 5 5 10" HorizontalExpand="True">
<OptionButton Name="StationRecordsFilterType" MinWidth="200" Margin="0 0 10 0"/>
<LineEdit Name="StationRecordsFiltersValue"
PlaceHolder="{Loc 'general-station-record-for-filter-line-placeholder'}" HorizontalExpand="True"/>
Expand All @@ -11,11 +11,18 @@
</BoxContainer>
<BoxContainer VerticalExpand="True">
<!-- Record listing -->
<BoxContainer Orientation="Vertical" Margin="5" MinWidth="250" MaxWidth="250">
<BoxContainer Orientation="Vertical" Margin="5" MinWidth="328" MaxWidth="360">
<Label Name="RecordListingStatus" Visible="False" />
<ScrollContainer VerticalExpand="True">
<ItemList Name="RecordListing" />
</ScrollContainer>
<ScrollContainer VerticalExpand="True">
<BoxContainer Name="JobListing"
Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True">
</BoxContainer>
</ScrollContainer>
</BoxContainer>
<BoxContainer Orientation="Vertical" Margin="5">
<Label Name="RecordContainerStatus" Visible="False" Text="{Loc 'general-station-record-console-select-record-info'}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using Content.Client.Station;
using static Robust.Client.UserInterface.Controls.BaseButton;
using Content.Shared.StationRecords;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
Expand All @@ -15,6 +17,9 @@ public sealed partial class GeneralStationRecordConsoleWindow : DefaultWindow

public Action<GeneralStationRecordFilterType, string>? OnFiltersChanged;

public event Action<ButtonEventArgs>? OnJobAdd;
public event Action<ButtonEventArgs>? OnJobSubtract;

private bool _isPopulating;

private GeneralStationRecordFilterType _currentFilterType;
Expand All @@ -27,7 +32,7 @@ public GeneralStationRecordConsoleWindow()

foreach (var item in Enum.GetValues<GeneralStationRecordFilterType>())
{
StationRecordsFilterType.AddItem(GetTypeFilterLocals(item), (int)item);
StationRecordsFilterType.AddItem(GetTypeFilterLocals(item), (int) item);
}

RecordListing.OnItemSelected += args =>
Expand All @@ -48,7 +53,7 @@ public GeneralStationRecordConsoleWindow()

StationRecordsFilterType.OnItemSelected += eventArgs =>
{
var type = (GeneralStationRecordFilterType)eventArgs.Id;
var type = (GeneralStationRecordFilterType) eventArgs.Id;
if (_currentFilterType != type)
{
Expand Down Expand Up @@ -89,7 +94,7 @@ public void UpdateState(GeneralStationRecordConsoleState state)
}
}

StationRecordsFilterType.SelectId((int)_currentFilterType);
StationRecordsFilterType.SelectId((int) _currentFilterType);

if (state.RecordListing == null)
{
Expand All @@ -104,9 +109,12 @@ public void UpdateState(GeneralStationRecordConsoleState state)
RecordListingStatus.Visible = false;
RecordListing.Visible = true;
RecordContainer.Visible = true;

PopulateRecordListing(state.RecordListing!, state.SelectedKey);

if (state.JobList != null)
{
JobListing.Visible = true;
PopulateJobsContainer(state.JobList);
}
RecordContainerStatus.Visible = state.Record == null;

if (state.Record != null)
Expand All @@ -123,6 +131,7 @@ public void UpdateState(GeneralStationRecordConsoleState state)
RecordContainer.RemoveAllChildren();
}
}

private void PopulateRecordListing(Dictionary<StationRecordKey, string> listing, StationRecordKey? selected)
{
RecordListing.Clear();
Expand All @@ -139,6 +148,7 @@ private void PopulateRecordListing(Dictionary<StationRecordKey, string> listing,
item.Selected = true;
}
}

_isPopulating = false;

RecordListing.SortItemsByText();
Expand All @@ -163,23 +173,27 @@ private void PopulateRecordContainer(GeneralStationRecord record)
},
new Label()
{
Text = Loc.GetString("general-station-record-console-record-title", ("job", Loc.GetString(record.JobTitle)))
Text = Loc.GetString("general-station-record-console-record-title",
("job", Loc.GetString(record.JobTitle)))
},
new Label()
{
Text = Loc.GetString("general-station-record-console-record-species", ("species", record.Species))
},
new Label()
{
Text = Loc.GetString("general-station-record-console-record-gender", ("gender", record.Gender.ToString()))
Text = Loc.GetString("general-station-record-console-record-gender",
("gender", record.Gender.ToString()))
},
new Label()
{
Text = Loc.GetString("general-station-record-console-record-fingerprint", ("fingerprint", record.Fingerprint ?? Loc.GetString("generic-not-available-shorthand")))
Text = Loc.GetString("general-station-record-console-record-fingerprint",
("fingerprint", record.Fingerprint ?? Loc.GetString("generic-not-available-shorthand")))
},
new Label()
{
Text = Loc.GetString("general-station-record-console-record-dna", ("dna", record.DNA ?? Loc.GetString("generic-not-available-shorthand")))
Text = Loc.GetString("general-station-record-console-record-dna",
("dna", record.DNA ?? Loc.GetString("generic-not-available-shorthand")))
}
};

Expand All @@ -201,4 +215,21 @@ private string GetTypeFilterLocals(GeneralStationRecordFilterType type)
{
return Loc.GetString($"general-station-record-{type.ToString().ToLower()}-filter");
}

private void PopulateJobsContainer(IReadOnlyDictionary<string, uint?> jobList)
{
JobListing.RemoveAllChildren();
foreach (var (job, amount) in jobList)
{
var jobEntry = new JobRow
{
Job = job,
JobName = { Text = job },
JobAmount = { Text = amount.ToString() },
};
jobEntry.DecreaseJobSlot.OnPressed += (args) => { OnJobSubtract?.Invoke(args); };
jobEntry.IncreaseJobSlot.OnPressed += (args) => { OnJobAdd?.Invoke(args); };
JobListing.AddChild(jobEntry);
}
}
}
24 changes: 24 additions & 0 deletions Content.Client/StationRecords/JobRow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<PanelContainer xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
HorizontalExpand="True">
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True">
<Label Name="JobName"
Access="Public"
MinWidth="210" />
<Button Name="DecreaseJobSlot"
Access="Public"
ToolTip=""
Text="-"
StyleClasses="OptionLeft" />
<Label Name="JobAmount"
Margin="6 0 0 0"
Access="Public"
MinWidth="22"/>
<Button Name="IncreaseJobSlot"
Access="Public"
ToolTip=""
Text="+"
StyleClasses="OptionRight" />
</BoxContainer>
</PanelContainer>
17 changes: 17 additions & 0 deletions Content.Client/StationRecords/JobRow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Shipyard;
using Content.Shared.Shipyard.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.StationRecords;

[GenerateTypedNameReferences]
public sealed partial class JobRow : PanelContainer
{
public string? Job;
public JobRow()
{
RobustXamlLoader.Load(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.ObjectModel;
using Content.Server.Station.Systems;
using Content.Shared.StationRecords;
using Robust.Server.GameObjects;
using System.Linq;
using Content.Shared.Roles;

namespace Content.Server.StationRecords.Systems;

Expand All @@ -10,6 +12,7 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly StationRecordsSystem _stationRecordsSystem = default!;
[Dependency] private readonly StationJobsSystem _stationJobsSystem = default!;

public override void Initialize()
{
Expand All @@ -18,6 +21,7 @@ public override void Initialize()
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, GeneralStationRecordsFilterMsg>(OnFiltersChanged);
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, RecordModifiedEvent>(UpdateUserInterface);
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, AfterGeneralRecordCreatedEvent>(UpdateUserInterface);
SubscribeLocalEvent<GeneralStationRecordConsoleComponent, AdjustStationJobMsg>(OnAdjustJob);
}

private void UpdateUserInterface<T>(EntityUid uid, GeneralStationRecordConsoleComponent component, T ev)
Expand All @@ -32,6 +36,15 @@ private void OnKeySelected(EntityUid uid, GeneralStationRecordConsoleComponent c
UpdateUserInterface(uid, component);
}

private void OnAdjustJob(EntityUid uid, GeneralStationRecordConsoleComponent component, AdjustStationJobMsg msg)
{
var stationUid = _stationSystem.GetOwningStation(uid);
if (stationUid is EntityUid station)
{
_stationJobsSystem.TryAdjustJobSlot(station, msg.JobProto, msg.Amount, false, true);
}
UpdateUserInterface(uid, component);
}
private void OnFiltersChanged(EntityUid uid,
GeneralStationRecordConsoleComponent component, GeneralStationRecordsFilterMsg msg)
{
Expand All @@ -55,7 +68,7 @@ private void UpdateUserInterface(EntityUid uid,

if (!TryComp<StationRecordsComponent>(owningStation, out var stationRecordsComponent))
{
GeneralStationRecordConsoleState state = new(null, null, null, null);
GeneralStationRecordConsoleState state = new(null, null, null, null, null);
SetStateForInterface(uid, state);
return;
}
Expand All @@ -77,7 +90,7 @@ private void UpdateUserInterface(EntityUid uid,

if (listing.Count == 0)
{
GeneralStationRecordConsoleState state = new(null, null, null, console.Filter);
GeneralStationRecordConsoleState state = new(null, null, null, console.Filter, null);
SetStateForInterface(uid, state);
return;
}
Expand All @@ -86,14 +99,16 @@ private void UpdateUserInterface(EntityUid uid,
console.ActiveKey = listing.Keys.First();
}

var jobList = _stationJobsSystem.GetJobs(owningStation.Value);

GeneralStationRecord? record = null;
if (console.ActiveKey != null)
{
_stationRecordsSystem.TryGetRecord(owningStation.Value, console.ActiveKey.Value, out record,
stationRecordsComponent);
}

GeneralStationRecordConsoleState newState = new(console.ActiveKey, record, listing, console.Filter);
GeneralStationRecordConsoleState newState = new(console.ActiveKey, record, listing, console.Filter, jobList);
SetStateForInterface(uid, newState);
}

Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/StationRecords/GeneralStationRecordsFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ public enum GeneralStationRecordFilterType : byte
Prints,
DNA,
}

[Serializable, NetSerializable]
public sealed class AdjustStationJobMsg : BoundUserInterfaceMessage
{
public string JobProto { get; }
public int Amount { get; }

public AdjustStationJobMsg(string jobProto, int amount)
{
JobProto = jobProto;
Amount = amount;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.ObjectModel;
using Robust.Shared.Serialization;

namespace Content.Shared.StationRecords;
Expand Down Expand Up @@ -37,16 +38,18 @@ public sealed class GeneralStationRecordConsoleState : BoundUserInterfaceState
public Dictionary<StationRecordKey, string>? RecordListing { get; }
public GeneralStationRecordsFilter? Filter { get; }
public GeneralStationRecordConsoleState(StationRecordKey? key, GeneralStationRecord? record,
Dictionary<StationRecordKey, string>? recordListing, GeneralStationRecordsFilter? newFilter)
Dictionary<StationRecordKey, string>? recordListing, GeneralStationRecordsFilter? newFilter, IReadOnlyDictionary<string, uint?>? jobList)
{
SelectedKey = key;
Record = record;
RecordListing = recordListing;
Filter = newFilter;
JobList = jobList;
}
public IReadOnlyDictionary<string, uint?>? JobList { get; }

public bool IsEmpty() => SelectedKey == null
&& Record == null && RecordListing == null;
&& Record == null && RecordListing == null;
}

[Serializable, NetSerializable]
Expand Down

0 comments on commit a1a0a2d

Please sign in to comment.