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

Shipyard #19

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update
  • Loading branch information
Cheackraze committed Feb 14, 2023
commit cd9ee47fdf7e05c977edda834cf217edc3ea9415
95 changes: 46 additions & 49 deletions Content.Client/Shipyard/BUI/ShipyardConsoleBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -4,69 +4,66 @@
using Robust.Client.GameObjects;
using static Robust.Client.UserInterface.Controls.BaseButton;

namespace Content.Client.Shipyard.BUI
namespace Content.Client.Shipyard.BUI;

public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface
{
public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private ShipyardConsoleMenu? _menu;
private ShipyardConsoleMenu? _menu;

[ViewVariables]
public int Balance { get; private set; }
public int Balance { get; private set; }

public ShipyardConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
}
public ShipyardConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();
_menu = new ShipyardConsoleMenu(this);
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnOrderApproved += ApproveOrder;
}
protected override void Open()
{
base.Open();
_menu = new ShipyardConsoleMenu(this);
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnOrderApproved += ApproveOrder;
}

private void Populate()
{
if (_menu == null)
return;
private void Populate()
{
if (_menu == null)
return;

_menu.PopulateProducts();
_menu.PopulateCategories();
}
_menu.PopulateProducts();
_menu.PopulateCategories();
}

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

if (state is not ShipyardConsoleInterfaceState cState)
return;
if (state is not ShipyardConsoleInterfaceState cState)
return;

Balance = cState.Balance;
var castState = (ShipyardConsoleInterfaceState) state;
Populate();
_menu?.UpdateState(castState);
}
Balance = cState.Balance;
var castState = (ShipyardConsoleInterfaceState) state;
Populate();
_menu?.UpdateState(castState);
}

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

if (!disposing) return;
if (!disposing) return;

_menu?.Dispose();
}
_menu?.Dispose();
}

private void ApproveOrder(ButtonEventArgs args)
private void ApproveOrder(ButtonEventArgs args)
{
if (args.Button.Parent?.Parent is not VesselRow row || row.Vessel == null)
{
if (args.Button.Parent?.Parent is not VesselRow row || row.Vessel == null)
{
return;
}

var vesselId = row.Vessel.ID;
SendMessage(new ShipyardConsolePurchaseMessage(vesselId));
return;
}

var vesselId = row.Vessel.ID;
SendMessage(new ShipyardConsolePurchaseMessage(vesselId));
}
}

This file was deleted.

169 changes: 86 additions & 83 deletions Content.Client/Shipyard/UI/ShipyardConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -10,110 +10,113 @@
using Robust.Shared.Prototypes;
using static Robust.Client.UserInterface.Controls.BaseButton;

namespace Content.Client.Shipyard.UI
namespace Content.Client.Shipyard.UI;

[GenerateTypedNameReferences]
public sealed partial class ShipyardConsoleMenu : FancyWindow
{
[GenerateTypedNameReferences]
public sealed partial class ShipyardConsoleMenu : FancyWindow
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;

public event Action<ButtonEventArgs>? OnOrderApproved;
private readonly ShipyardConsoleBoundUserInterface _menu;
private readonly List<string> _categoryStrings = new();
private string? _category;
public event Action<ButtonEventArgs>? OnOrderApproved;
private readonly ShipyardConsoleBoundUserInterface _menu;
private readonly List<string> _categoryStrings = new();
private string? _category;

public ShipyardConsoleMenu(ShipyardConsoleBoundUserInterface owner)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_menu = owner;
Title = Loc.GetString("shipyard-console-menu-title");
SearchBar.OnTextChanged += OnSearchBarTextChanged;
Categories.OnItemSelected += OnCategoryItemSelected;
}
public ShipyardConsoleMenu(ShipyardConsoleBoundUserInterface owner)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_menu = owner;
Title = Loc.GetString("shipyard-console-menu-title");
SearchBar.OnTextChanged += OnSearchBarTextChanged;
Categories.OnItemSelected += OnCategoryItemSelected;
}

private void OnCategoryItemSelected(OptionButton.ItemSelectedEventArgs args)
{
SetCategoryText(args.Id);
PopulateProducts();
}
private void OnCategoryItemSelected(OptionButton.ItemSelectedEventArgs args)
{
SetCategoryText(args.Id);
PopulateProducts();
}

private void OnSearchBarTextChanged(LineEdit.LineEditEventArgs args)
{
PopulateProducts();
}
private void OnSearchBarTextChanged(LineEdit.LineEditEventArgs args)
{
PopulateProducts();
}

private void SetCategoryText(int id)
{
_category = id == 0 ? null : _categoryStrings[id];
Categories.SelectId(id);
}
private void SetCategoryText(int id)
{
_category = id == 0 ? null : _categoryStrings[id];
Categories.SelectId(id);
}

public IEnumerable<VesselPrototype> VesselPrototypes => _protoManager.EnumeratePrototypes<VesselPrototype>();
private void GetPrototypes(out IEnumerable<VesselPrototype> vessels)
{
vessels = _protoManager.EnumeratePrototypes<VesselPrototype>();
}

/// <summary>
/// Populates the list of products that will actually be shown, using the current filters.
/// </summary>
public void PopulateProducts()
{
Vessels.RemoveAllChildren();
var vessels = VesselPrototypes.ToList();
vessels.Sort((x, y) =>
string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase));
/// <summary>
/// Populates the list of products that will actually be shown, using the current filters.
/// </summary>
public void PopulateProducts()
{
Vessels.RemoveAllChildren();
GetPrototypes(out var vessels);
var vesselList = vessels.ToList();
vesselList.Sort((x, y) =>
string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase));

var search = SearchBar.Text.Trim().ToLowerInvariant();
foreach (var prototype in vessels)
var search = SearchBar.Text.Trim().ToLowerInvariant();
foreach (var prototype in vesselList)
{
// if no search or category
// else if search
// else if category and not search
if (search.Length == 0 && _category == null ||
search.Length != 0 && prototype.Name.ToLowerInvariant().Contains(search) ||
search.Length == 0 && _category != null && prototype.Category.Equals(_category))
{
// if no search or category
// else if search
// else if category and not search
if (search.Length == 0 && _category == null ||
search.Length != 0 && prototype.Name.ToLowerInvariant().Contains(search) ||
search.Length == 0 && _category != null && prototype.Category.Equals(_category))
var vesselEntry = new VesselRow
{
var vesselEntry = new VesselRow
{
Vessel = prototype,
VesselName = { Text = prototype.Name },
Purchase = { ToolTip = prototype.Description },
Price = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.Price.ToString())) },
};
vesselEntry.Purchase.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
Vessels.AddChild(vesselEntry);
}
Vessel = prototype,
VesselName = { Text = prototype.Name },
Purchase = { ToolTip = prototype.Description },
Price = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.Price.ToString())) },
};
vesselEntry.Purchase.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
Vessels.AddChild(vesselEntry);
}
}
}

/// <summary>
/// Populates the list categories that will actually be shown, using the current filters.
/// </summary>
public void PopulateCategories()
/// <summary>
/// Populates the list categories that will actually be shown, using the current filters.
/// </summary>
public void PopulateCategories()
{
_categoryStrings.Clear();
Categories.Clear();
GetPrototypes(out var vessels);
foreach (var prototype in vessels)
{
_categoryStrings.Clear();
Categories.Clear();

foreach (var prototype in VesselPrototypes)
if (!_categoryStrings.Contains(prototype.Category))
{
if (!_categoryStrings.Contains(prototype.Category))
{
_categoryStrings.Add(Loc.GetString(prototype.Category));
}
_categoryStrings.Add(Loc.GetString(prototype.Category));
}
}

_categoryStrings.Sort();

// Add "All" category at the top of the list
_categoryStrings.Insert(0, Loc.GetString("cargo-console-menu-populate-categories-all-text"));
_categoryStrings.Sort();

foreach (var str in _categoryStrings)
{
Categories.AddItem(str);
}
}
// Add "All" category at the top of the list
_categoryStrings.Insert(0, Loc.GetString("cargo-console-menu-populate-categories-all-text"));

public void UpdateState(ShipyardConsoleInterfaceState state)
foreach (var str in _categoryStrings)
{
BankAccountLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", state.Balance.ToString()));
Categories.AddItem(str);
}
}

public void UpdateState(ShipyardConsoleInterfaceState state)
{
BankAccountLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", state.Balance.ToString()));
}
}
17 changes: 8 additions & 9 deletions Content.Client/Shipyard/UI/VesselRow.xaml.cs
Original file line number Diff line number Diff line change
@@ -4,17 +4,16 @@
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Shipyard.UI
namespace Content.Client.Shipyard.UI;

[GenerateTypedNameReferences]
public sealed partial class VesselRow : PanelContainer
{
[GenerateTypedNameReferences]
public sealed partial class VesselRow : PanelContainer
{
public VesselPrototype? Vessel { get; set; }
public VesselPrototype? Vessel;

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

7 changes: 3 additions & 4 deletions Content.Server/Shipyard/Commands/PurchaseShuttleCommand.cs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ public sealed class PurchaseShuttleCommand : IConsoleCommand
{
[Dependency] private readonly IEntitySystemManager _entityManager = default!;
public string Command => "purchaseshuttle";
public string Description => "Spawns and docks a specified shuttle from a grid file";
public string Description => Loc.GetString("shipyard-commands-purchase-desc");
public string Help => $"{Command} <station ID> <gridfile path>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
@@ -27,7 +27,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
var shuttlePath = args[1];
var system = _entityManager.GetEntitySystem<ShipyardSystem>();
var station = new EntityUid(stationId);
system.PurchaseShuttle(station, shuttlePath, out _);
system.TryPurchaseShuttle(station, shuttlePath, out _);
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
@@ -37,8 +37,7 @@ public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
case 1:
return CompletionResult.FromHint(Loc.GetString("station-id"));
case 2:
var opts = CompletionHelper.PrototypeIDs<GameMapPrototype>();
return CompletionResult.FromHintOptions(opts, Loc.GetString("cmd-hint-savemap-path"));
return CompletionResult.FromHint(Loc.GetString("cmd-hint-savemap-path"));
}

return CompletionResult.Empty;

This file was deleted.

Loading