Skip to content

Commit

Permalink
add claim points button to oreproc
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Dec 11, 2024
1 parent 43f2809 commit 446c7e3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Content.Client/Lathe/UI/LatheBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.DeltaV.Salvage; // DeltaV
using Content.Shared.Lathe;
using Content.Shared.Research.Components;
using JetBrains.Annotations;
Expand Down Expand Up @@ -31,6 +32,8 @@ protected override void Open()
{
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
};

_menu.OnClaimMiningPoints += () => SendMessage(new LatheClaimMiningPointsMessage()); // DeltaV
}

protected override void UpdateState(BoundUserInterfaceState state)
Expand Down
7 changes: 6 additions & 1 deletion Content.Client/Lathe/UI/LatheMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@
HorizontalExpand="True">
<ui:MaterialStorageControl Name="MaterialsList" SizeFlagsStretchRatio="8"/>
</BoxContainer>
<!-- Begin DeltaV Additions: Mining points -->
<BoxContainer Orientation="Horizontal" Name="MiningPointsContainer" Visible="False">
<Label Name="MiningPointsLabel" HorizontalExpand="True"/>
<Button Name="MiningPointsClaimButton" Text="{Loc 'lathe-menu-mining-points-claim-button'}"/>
</BoxContainer>
<!-- End DeltaV Additions: Mining points -->
</BoxContainer>
</BoxContainer>

</BoxContainer>

</DefaultWindow>
41 changes: 41 additions & 0 deletions Content.Client/Lathe/UI/LatheMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
using System.Linq;
using System.Text;
using Content.Client.Materials;
using Content.Shared.DeltaV.Salvage.Components; // DeltaV
using Content.Shared.DeltaV.Salvage.Systems; // DeltaV
using Content.Shared.Lathe;
using Content.Shared.Lathe.Prototypes;
using Content.Shared.Research.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Player; // DeltaV
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing; // DeltaV

namespace Content.Client.Lathe.UI;

[GenerateTypedNameReferences]
public sealed partial class LatheMenu : DefaultWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _player = default!; // DeltaV
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

private readonly SpriteSystem _spriteSystem;
private readonly LatheSystem _lathe;
private readonly MaterialStorageSystem _materialStorage;
private readonly MiningPointsSystem _miningPoints; // DeltaV

public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<string, int>? RecipeQueueAction;
public event Action? OnClaimMiningPoints; // DeltaV

public List<ProtoId<LatheRecipePrototype>> Recipes = new();

Expand All @@ -35,6 +42,8 @@ public sealed partial class LatheMenu : DefaultWindow

public EntityUid Entity;

private uint? _lastMiningPoints; // DeltaV: used to avoid Loc.GetString every frame

public LatheMenu()
{
RobustXamlLoader.Load(this);
Expand All @@ -43,6 +52,7 @@ public LatheMenu()
_spriteSystem = _entityManager.System<SpriteSystem>();
_lathe = _entityManager.System<LatheSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>();
_miningPoints = _entityManager.System<MiningPointsSystem>(); // DeltaV

SearchBar.OnTextChanged += _ =>
{
Expand Down Expand Up @@ -70,9 +80,29 @@ public void SetEntity(EntityUid uid)
}
}

// Begin DeltaV Additions: Mining points UI
MiningPointsContainer.Visible = _entityManager.TryGetComponent<MiningPointsComponent>(Entity, out var points);
MiningPointsClaimButton.OnPressed += _ => OnClaimMiningPoints?.Invoke();
if (points != null)
UpdateMiningPoints(points.Points);
// End DeltaV Additions

MaterialsList.SetOwner(Entity);
}

/// <summary>
/// DeltaV: Updates the UI elements for mining points.
/// </summary>
private void UpdateMiningPoints(uint points)
{
MiningPointsClaimButton.Disabled = points == 0 || _player.LocalSession?.AttachedEntity is not {} player || _miningPoints.TryFindIdCard(player) == null;
if (points == _lastMiningPoints)
return;

_lastMiningPoints = points;
MiningPointsLabel.Text = Loc.GetString("lathe-menu-mining-points", ("points", points));
}

protected override void Opened()
{
base.Opened();
Expand All @@ -83,6 +113,17 @@ protected override void Opened()
}
}

/// <summary>
/// DeltaV: Update mining points UI whenever it changes.
/// </summary>
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);

if (_entityManager.TryGetComponent<MiningPointsComponent>(Entity, out var points))
UpdateMiningPoints(points.Points);
}

/// <summary>
/// Populates the list of all the recipes
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/deltav/lathe/ui/lathe-menu.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lathe-menu-mining-points = Mining Points: {$points}
lathe-menu-mining-points-claim-button = Claim Points

0 comments on commit 446c7e3

Please sign in to comment.