forked from DeltaV-Station/Delta-v
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Shipyards (DeltaV-Station#1314)
# Description I needed this extremely badly. # TODO - [x] Move all of this out of the DeltaV folders. # Changelog :cl: - add: Added Shipyards. --------- Signed-off-by: deltanedas <[email protected]> Co-authored-by: deltanedas <[email protected]> Co-authored-by: Null <[email protected]> Co-authored-by: Milon <[email protected]> Co-authored-by: Plykiya <[email protected]> Co-authored-by: plykiya <[email protected]> Co-authored-by: Ed <[email protected]> Co-authored-by: Radezolid <[email protected]> Co-authored-by: sleepyyapril <[email protected]>
- Loading branch information
1 parent
01a13e3
commit d69b516
Showing
76 changed files
with
20,255 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Content.Shared.Shipyard; | ||
|
||
namespace Content.Client.Shipyard; | ||
|
||
public sealed class ShipyardConsoleSystem : SharedShipyardConsoleSystem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Content.Shared.Access.Systems; | ||
using Content.Shared.Shipyard; | ||
using Content.Shared.Whitelist; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client.Shipyard.UI; | ||
|
||
public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface | ||
{ | ||
[Dependency] private readonly IPrototypeManager _proto = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
|
||
private readonly AccessReaderSystem _access; | ||
private readonly EntityWhitelistSystem _whitelist; | ||
|
||
[ViewVariables] | ||
private ShipyardConsoleMenu? _menu; | ||
|
||
public ShipyardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
_access = EntMan.System<AccessReaderSystem>(); | ||
_whitelist = EntMan.System<EntityWhitelistSystem>(); | ||
} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_menu = new ShipyardConsoleMenu(Owner, _proto, EntMan, _player, _access, _whitelist); | ||
_menu.OpenCentered(); | ||
_menu.OnClose += Close; | ||
_menu.OnPurchased += Purchase; | ||
} | ||
|
||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
|
||
if (state is not ShipyardConsoleState cast) | ||
return; | ||
|
||
_menu?.UpdateState(cast); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
|
||
if (disposing) | ||
_menu?.Dispose(); | ||
} | ||
|
||
private void Purchase(string id) | ||
{ | ||
SendMessage(new ShipyardConsolePurchaseMessage(id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<controls:FancyWindow xmlns="https://spacestation14.io" | ||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
SetSize="500 360" | ||
MinSize="460 280" | ||
Title="{Loc 'shipyard-console-menu-title'}"> | ||
<BoxContainer Orientation="Vertical" Margin="5 0 5 0"> | ||
<Label Name="BankAccountLabel" /> | ||
<BoxContainer Orientation="Horizontal"> | ||
<OptionButton Name="Categories" | ||
Prefix="{Loc 'cargo-console-menu-categories-label'}" | ||
HorizontalExpand="True" /> | ||
<LineEdit Name="SearchBar" | ||
PlaceHolder="{Loc 'cargo-console-menu-search-bar-placeholder'}" | ||
HorizontalExpand="True" /> | ||
</BoxContainer> | ||
<ScrollContainer HorizontalExpand="True" | ||
VerticalExpand="True" | ||
SizeFlagsStretchRatio="6"> | ||
<BoxContainer Name="Vessels" | ||
Orientation="Vertical" | ||
HorizontalExpand="True" | ||
VerticalExpand="True"> | ||
<!-- Vessels get added here by code --> | ||
</BoxContainer> | ||
</ScrollContainer> | ||
<TextureButton VerticalExpand="True" /> | ||
</BoxContainer> | ||
</controls:FancyWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.Access.Systems; | ||
using Content.Shared.Shipyard; | ||
using Content.Shared.Shipyard.Prototypes; | ||
using Content.Shared.Whitelist; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.Player; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client.Shipyard.UI; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class ShipyardConsoleMenu : FancyWindow | ||
{ | ||
private readonly AccessReaderSystem _access; | ||
private readonly IPlayerManager _player; | ||
|
||
public event Action<string>? OnPurchased; | ||
|
||
private readonly List<VesselPrototype> _vessels = new(); | ||
private readonly List<string> _categories = new(); | ||
|
||
public Entity<ShipyardConsoleComponent> Console; | ||
private string? _category; | ||
|
||
public ShipyardConsoleMenu(EntityUid console, IPrototypeManager proto, IEntityManager entMan, IPlayerManager player, AccessReaderSystem access, EntityWhitelistSystem whitelist) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
|
||
Console = (console, entMan.GetComponent<ShipyardConsoleComponent>(console)); | ||
_access = access; | ||
_player = player; | ||
|
||
// don't include ships that aren't allowed by whitelist, server won't accept them anyway | ||
foreach (var vessel in proto.EnumeratePrototypes<VesselPrototype>()) | ||
{ | ||
if (whitelist.IsWhitelistPassOrNull(vessel.Whitelist, console)) | ||
_vessels.Add(vessel); | ||
} | ||
_vessels.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase)); | ||
|
||
// only list categories in said ships | ||
foreach (var vessel in _vessels) | ||
{ | ||
foreach (var category in vessel.Categories) | ||
{ | ||
if (!_categories.Contains(category)) | ||
_categories.Add(category); | ||
} | ||
} | ||
|
||
_categories.Sort(); | ||
// inserting here and not adding at the start so it doesn't get affected by sort | ||
_categories.Insert(0, Loc.GetString("cargo-console-menu-populate-categories-all-text")); | ||
PopulateCategories(); | ||
|
||
SearchBar.OnTextChanged += _ => PopulateProducts(); | ||
Categories.OnItemSelected += args => | ||
{ | ||
_category = args.Id == 0 ? null : _categories[args.Id]; | ||
Categories.SelectId(args.Id); | ||
PopulateProducts(); | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Populates the list of products that will actually be shown, using the current filters. | ||
/// </summary> | ||
private void PopulateProducts() | ||
{ | ||
Vessels.RemoveAllChildren(); | ||
|
||
var access = _player.LocalSession?.AttachedEntity is {} player | ||
&& _access.IsAllowed(player, Console); | ||
|
||
var search = SearchBar.Text.Trim().ToLowerInvariant(); | ||
foreach (var vessel in _vessels) | ||
{ | ||
if (search.Length != 0 && !vessel.Name.ToLowerInvariant().Contains(search)) | ||
continue; | ||
if (_category != null && !vessel.Categories.Contains(_category)) | ||
continue; | ||
|
||
var vesselEntry = new VesselRow(vessel, access); | ||
vesselEntry.OnPurchasePressed += () => OnPurchased?.Invoke(vessel.ID); | ||
Vessels.AddChild(vesselEntry); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Populates the list categories that will actually be shown, using the current filters. | ||
/// </summary> | ||
private void PopulateCategories() | ||
{ | ||
Categories.Clear(); | ||
foreach (var category in _categories) | ||
{ | ||
Categories.AddItem(category); | ||
} | ||
} | ||
|
||
public void UpdateState(ShipyardConsoleState state) | ||
{ | ||
BankAccountLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", state.Balance.ToString())); | ||
PopulateProducts(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<PanelContainer xmlns="https://spacestation14.io" | ||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" | ||
HorizontalExpand="True"> | ||
<BoxContainer Orientation="Horizontal" | ||
HorizontalExpand="True"> | ||
<Button Name="Purchase" Text="{Loc 'purchase'}" StyleClasses="LabelSubText" /> | ||
<Label Name="VesselName" HorizontalExpand="True" /> | ||
<PanelContainer> | ||
<PanelContainer.PanelOverride> | ||
<gfx:StyleBoxFlat BackgroundColor="#25252A" /> | ||
</PanelContainer.PanelOverride> | ||
|
||
<Label Name="Price" MinSize="52 32" Align="Right" /> | ||
</PanelContainer> | ||
</BoxContainer> | ||
</PanelContainer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Content.Shared.Shipyard.Prototypes; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.CustomControls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.Shipyard.UI; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class VesselRow : PanelContainer | ||
{ | ||
public event Action? OnPurchasePressed; | ||
|
||
public VesselRow(VesselPrototype vessel, bool access) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
|
||
VesselName.Text = vessel.Name; | ||
|
||
var tooltip = new Tooltip(); | ||
tooltip.SetMessage(FormattedMessage.FromMarkup(vessel.Description)); | ||
Purchase.TooltipSupplier = _ => tooltip; | ||
Purchase.Disabled = !access; | ||
Purchase.OnPressed += _ => OnPurchasePressed?.Invoke(); | ||
|
||
Price.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", vessel.Price)); | ||
} | ||
} |
Oops, something went wrong.