Skip to content

Commit

Permalink
v245.0.0 (and Storage UI V2) (#1799)
Browse files Browse the repository at this point in the history
Contains:

- Storage UI v2, required for removing DeferredClose.
- Stock market refactor (mostly some basic changes to stock market,
didn't want to make a whole other PR for it)
- Make guidebook remember where you left off
- Any other PRs are purely for fixing issues related to the above PRs or
the engine update.

:cl:
- add: Ported Storage UI v2.
- tweak: The guidebook will now remember where you left off.

---------

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: 12rabbits <53499656+12rabbits@users.noreply.github.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
Co-authored-by: gluesniffler <159397573+gluesniffler@users.noreply.github.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
  • Loading branch information
9 people authored Feb 15, 2025
1 parent 21567ac commit 3c37ff1
Show file tree
Hide file tree
Showing 34 changed files with 960 additions and 615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void UpdateState(BoundUserInterfaceState state)
}
}

private static void SendStockTradingUiMessage(StockTradingUiAction action, int company, float amount, BoundUserInterface userInterface)
private static void SendStockTradingUiMessage(StockTradingUiAction action, int company, int amount, BoundUserInterface userInterface)
{
var newsMessage = new StockTradingUiMessageEvent(action, company, amount);
var message = new CartridgeUiMessage(newsMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public sealed partial class StockTradingUiFragment : BoxContainer
private readonly Dictionary<int, CompanyEntry> _companyEntries = new();

// Event handlers for the parent UI
public event Action<int, float>? OnBuyButtonPressed;
public event Action<int, float>? OnSellButtonPressed;
public event Action<int, int>? OnBuyButtonPressed;
public event Action<int, int>? OnSellButtonPressed;

// Define colors
public static readonly Color PositiveColor = Color.FromHex("#00ff00"); // Green
Expand Down Expand Up @@ -70,8 +70,8 @@ private sealed class CompanyEntry

public CompanyEntry(int companyIndex,
string displayName,
Action<int, float>? onBuyPressed,
Action<int, float>? onSellPressed)
Action<int, int>? onBuyPressed,
Action<int, int>? onSellPressed)
{
Container = new BoxContainer
{
Expand Down Expand Up @@ -216,13 +216,13 @@ public CompanyEntry(int companyIndex,
// Button click events
_buyButton.OnPressed += _ =>
{
if (float.TryParse(_amountEdit.Text, out var amount) && amount > 0)
if (int.TryParse(_amountEdit.Text, out var amount) && amount > 0)
onBuyPressed?.Invoke(companyIndex, amount);
};

_sellButton.OnPressed += _ =>
{
if (float.TryParse(_amountEdit.Text, out var amount) && amount > 0)
if (int.TryParse(_amountEdit.Text, out var amount) && amount > 0)
onSellPressed?.Invoke(companyIndex, amount);
};

Expand All @@ -235,7 +235,7 @@ public CompanyEntry(int companyIndex,
};
}

public void Update(StockCompanyStruct company, int ownedStocks)
public void Update(StockCompany company, int ownedStocks)
{
_nameLabel.Text = company.LocalizedDisplayName;
_priceLabel.Text = $"${company.CurrentPrice:F2}";
Expand Down
8 changes: 6 additions & 2 deletions Content.Client/Guidebook/Controls/GuidebookWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:fancyTree="clr-namespace:Content.Client.UserInterface.Controls.FancyTree"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
SetSize="750 700"
SetSize="850 700"
MinSize="100 200"
Resizable="True"
Title="{Loc 'guidebook-window-title'}">
Expand All @@ -21,9 +21,13 @@
Margin="0 5 10 5">
</LineEdit>
</BoxContainer>
<BoxContainer Access="Internal" Name="ReturnContainer" Orientation="Horizontal" HorizontalAlignment="Right" Visible="False">
<Button Name="HomeButton" Text="{Loc 'ui-rules-button-home'}" Margin="0 0 10 0"/>
</BoxContainer>
<ScrollContainer Name="Scroll" HScrollEnabled="False" HorizontalExpand="True" VerticalExpand="True">
<Control>
<BoxContainer Orientation="Vertical" Name="EntryContainer" Margin="5 5 5 5" Visible="False"/>
<BoxContainer Orientation="Vertical" Name="EntryContainer" Margin="5 5 5 5" Visible="False">
</BoxContainer>
<BoxContainer Orientation="Vertical" Name="Placeholder" Margin="5 5 5 5">
<Label HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Loc 'guidebook-placeholder-text'}"/>
<Label HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Loc 'guidebook-placeholder-text-2'}"/>
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Controls.FancyTree;
using JetBrains.Annotations;
using Content.Client.UserInterface.Systems.Info;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.ContentPack;
using Robust.Shared.Prototypes;

namespace Content.Client.Guidebook.Controls;

Expand All @@ -21,6 +23,8 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler

private Dictionary<string, GuideEntry> _entries = new();

public ProtoId<GuideEntryPrototype> LastEntry;

public GuidebookWindow()
{
RobustXamlLoader.Load(this);
Expand All @@ -37,7 +41,13 @@ public GuidebookWindow()
private void OnSelectionChanged(TreeItem? item)
{
if (item != null && item.Metadata is GuideEntry entry)
{
ShowGuide(entry);

var isRulesEntry = entry.RuleEntry;
ReturnContainer.Visible = isRulesEntry;
HomeButton.OnPressed += _ => ShowGuide(entry);
}
else
ClearSelectedGuide();
}
Expand Down Expand Up @@ -66,6 +76,8 @@ private void ShowGuide(GuideEntry entry)
EntryContainer.AddChild(new Label() { Text = "ERROR: Failed to parse document." });
Logger.Error($"Failed to parse contents of guide document {entry.Id}.");
}

LastEntry = entry.Id;
}

public void UpdateGuides(
Expand Down Expand Up @@ -152,6 +164,10 @@ private void RepopulateTree(List<string>? roots = null, string? forcedRoot = nul
return null;
}

var rulesProto = UserInterfaceManager.GetUIController<InfoUIController>().GetCoreRuleEntry();
if (entry.RuleEntry && entry.Id != rulesProto.Id)
return null;

var item = Tree.AddItem(parent);
item.Metadata = entry;
var name = Loc.GetString(entry.Name);
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Guidebook/GuideEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class GuideEntry
/// </summary>
[DataField("filterEnabled")] public bool FilterEnabled = default!;

[DataField] public bool RuleEntry;

/// <summary>
/// Priority for sorting top-level guides when shown in a tree / table of contents.
/// If the guide is the child of some other guide, the order simply determined by the order of children in <see cref="Children"/>.
Expand Down
64 changes: 53 additions & 11 deletions Content.Client/Storage/StorageBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,80 @@
using Content.Client.Storage.Systems;
using Content.Client.UserInterface.Systems.Storage;
using Content.Client.UserInterface.Systems.Storage.Controls;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Client.UserInterface;

namespace Content.Client.Storage;

[UsedImplicitly]
public sealed class StorageBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entManager = default!;

[Obsolete] public override bool DeferredClose => false;
private readonly StorageSystem _storage;
private StorageWindow? _window;

public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
_storage = _entManager.System<StorageSystem>();
}

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

if (_entManager.TryGetComponent<StorageComponent>(Owner, out var comp))
_storage.OpenStorageWindow((Owner, comp));
_window = IoCManager.Resolve<IUserInterfaceManager>()
.GetUIController<StorageUIController>()
.CreateStorageWindow(Owner);

if (EntMan.TryGetComponent(Owner, out StorageComponent? storage))
{
_window.UpdateContainer((Owner, storage));
}

_window.OnClose += Close;
_window.FlagDirty();
}

public void Refresh()
{
_window?.FlagDirty();
}

public void Reclaim()
{
if (_window == null)
return;

_window.OnClose -= Close;
_window.Orphan();
_window = null;
}

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

Reclaim();
}

public void Hide()
{
if (_window == null)
return;

_storage.CloseStorageWindow(Owner);
_window.Visible = false;
}

public void Show()
{
if (_window == null)
return;

_window.Visible = true;
}

public void ReOpen()
{
_window?.Orphan();
_window = null;
Open();
}
}

Loading

0 comments on commit 3c37ff1

Please sign in to comment.