This commit is contained in:
Deserty0
2025-10-17 14:28:03 +10:00
parent 2fdd3923f5
commit f31e82f7b3
6 changed files with 97 additions and 88 deletions

View File

@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Content.Client.Hands.Systems;
using Content.Shared._CP14.Fishing;
using Content.Shared._CP14.Fishing.Components;
@@ -63,4 +64,23 @@ public sealed class CP14FishingSystem : CP14SharedFishingSystem
fishingRodComponent.Reeling = reelKey;
RaiseNetworkEvent(new CP14FishingReelKeyMessage(reelKey));
}
public bool GetInfo([NotNullWhen(true)] out CP14FishingRodComponent? rodComponent,
[NotNullWhen(true)] out CP14FishComponent? fishComponent)
{
rodComponent = null;
fishComponent = null;
var heldUid = _hands.GetActiveHandEntity();
if (!TryComp<CP14FishingRodComponent>(heldUid, out var posRodComponent))
return false;
if (!TryComp<CP14FishComponent>(posRodComponent.CaughtFish, out var posFishComponent))
return false;
rodComponent = posRodComponent;
fishComponent = posFishComponent;
return true;
}
}

View File

@@ -1,12 +1,15 @@
using Content.Shared._CP14.Fishing.Components;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.Fishing.UI;
[UsedImplicitly]
public sealed class CP14FishingBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables]
private CP14FishingWindow? _fishingWindow;
@@ -21,39 +24,17 @@ public sealed class CP14FishingBoundUserInterface : BoundUserInterface
if (!EntMan.TryGetComponent<CP14FishingRodComponent>(Owner, out var rodComponent))
return;
if (!_prototypeManager.Resolve(rodComponent.FishingMinigame, out var fishingMinigame))
return;
_fishingWindow = this.CreateWindow<CP14FishingWindow>();
_fishingWindow.InitVisuals(rodComponent);
_fishingWindow.InitVisuals(fishingMinigame);
}
public override void Update()
{
base.Update();
if (_fishingWindow is null || !EntMan.TryGetComponent<CP14FishingRodComponent>(Owner, out var rodComponent))
return;
var fish = rodComponent.CaughtFish;
if (fish is null)
return;
if (!EntMan.TryGetComponent<CP14FishComponent>(fish, out var fishComponent))
return;
var backgroundContainer = _fishingWindow.GetChild(0);
var progressbar = backgroundContainer.GetChild(0);
var floatContainer = backgroundContainer.GetChild(1);
var fishContainer = backgroundContainer.GetChild(2);
floatContainer.Margin = new Thickness(floatContainer.Margin.Left,
0,
floatContainer.Margin.Right + rodComponent.FloatPosition,
0);
fishContainer.Margin = new Thickness(fishContainer.Margin.Left,
0,
fishContainer.Margin.Right + fishComponent.FishPosAndDestination.X,
0);
_fishingWindow?.UpdateDraw();
}
}

View File

@@ -2,10 +2,6 @@
<fishingWindow:CP14FishingWindow
xmlns="https://spacestation14.io"
xmlns:fishingWindow="clr-namespace:Content.Client._CP14.Fishing.UI"
Name="FishingWindow">
<PanelContainer Name="FishingBackground">
<PanelContainer Name="Progressbar" HorizontalAlignment="Left" VerticalAlignment="Bottom"></PanelContainer>
<PanelContainer Name="Float" HorizontalAlignment="Left" VerticalAlignment="Bottom"></PanelContainer>
<PanelContainer Name="FishIcon" HorizontalAlignment="Left" VerticalAlignment="Bottom"></PanelContainer>
</PanelContainer>
Name="FishingWindow" MaxSize="0 0">
<PanelContainer Name="FishingBackground"></PanelContainer>
</fishingWindow:CP14FishingWindow>

View File

@@ -1,48 +1,50 @@
using Content.Client.Resources;
using Content.Shared._CP14.Fishing.Components;
using Content.Shared._CP14.Fishing;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.Fishing.UI;
[GenerateTypedNameReferences]
public sealed partial class CP14FishingWindow : BaseWindow
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IEntityManager _entity = default!;
private readonly CP14FishingSystem _fishing;
private CP14FishingMinigamePrototype? _fishingMinigame;
private Texture? _floatTexture;
private Texture? _fishTexture;
public CP14FishingWindow()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
_fishing = _entity.System<CP14FishingSystem>();
}
public void InitVisuals(CP14FishingRodComponent component)
public void InitVisuals(CP14FishingMinigamePrototype fishingMinigame)
{
FishingWindow.Visible = false;
// Hashing
_fishingMinigame = fishingMinigame;
// Getting data
if (!_prototypeManager.Resolve(component.FishingMinigame, out var minigameStyle))
return;
var background = minigameStyle.Background;
var floatUI = minigameStyle.Float;
var progressbar = minigameStyle.Progressbar;
var fishIcon = minigameStyle.FishIcon;
var background = _fishingMinigame.Background;
var fish = _fishingMinigame.FishIcon;
var floater = _fishingMinigame.Float;
FishingWindow.MaxSize = background.Size;
FishingWindow.SetSize = background.Size;
Progressbar.MaxSize = progressbar.Size;
Progressbar.Margin = new Thickness(progressbar.Offset.X, 0, 0, progressbar.Offset.Y);
Float.SetSize = floatUI.Size;
Float.Margin = new Thickness(floatUI.Offset.X, 0, 0, floatUI.Offset.Y);
FishIcon.SetSize = fishIcon.Size;
FishIcon.Margin = new Thickness(fishIcon.Offset.X, 0, 0, fishIcon.Offset.Y);
FishingBackground.SetSize = background.Size;
var backgroundTexture = _resourceCache.GetTexture(background.Texture);
FishingBackground.PanelOverride = new StyleBoxTexture
@@ -50,25 +52,35 @@ public sealed partial class CP14FishingWindow : BaseWindow
Texture = backgroundTexture,
};
var progressbarTexture = _resourceCache.GetTexture(progressbar.Texture);
Progressbar.PanelOverride = new StyleBoxTexture
{
Texture = progressbarTexture,
};
_floatTexture = _resourceCache.GetTexture(floater.Texture);
_fishTexture = _resourceCache.GetTexture(fish.Texture);
}
var floatTexture = _resourceCache.GetTexture(floatUI.Texture);
Float.PanelOverride = new StyleBoxTexture
{
Texture = floatTexture,
};
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
var fishTexture = _resourceCache.GetTexture(fishIcon.Texture);
FishIcon.PanelOverride = new StyleBoxTexture
{
Texture = fishTexture,
};
if (_fishingMinigame is null || _floatTexture is null || _fishTexture is null)
return;
FishingWindow.Visible = true;
if (!_fishing.GetInfo(out var rodComponent, out var fishComponent))
return;
var floatBox = CalculateUIBox(_fishingMinigame.Float, rodComponent.FloatPosition);
var fishBox = CalculateUIBox(_fishingMinigame.FishIcon, fishComponent.FishPosAndDestination.X);
handle.DrawTextureRect(_floatTexture, floatBox);
handle.DrawTextureRect(_fishTexture, fishBox);
}
private static UIBox2 CalculateUIBox(FishingMinigameElementData data, float verticalOffset)
{
var left = data.Offset.X;
var top = data.Offset.Y + verticalOffset + data.Size.Y;
var right = data.Offset.X + data.Size.X;
var bottom = data.Offset.Y + verticalOffset;
return new UIBox2(left, top, right, bottom);
}
}

View File

@@ -8,7 +8,7 @@ namespace Content.Shared._CP14.Fishing;
/// Prototype of fishing minigame stylesheet.
/// </summary>
[Prototype("CP14FishingMinigameStyle")]
public sealed partial class CP14FishingMinigamePrototype : IPrototype
public sealed class CP14FishingMinigamePrototype : IPrototype
{
[IdDataField]
public string ID { get; } = default!;
@@ -27,23 +27,23 @@ public sealed partial class CP14FishingMinigamePrototype : IPrototype
[DataField(required: true)]
public float FishingMinigameSize;
[DataDefinition]
public partial struct FishingMinigameElementData
{
/// <summary>
/// Texture path.
/// </summary>
[DataField(required: true)] public ResPath Texture;
/// <summary>
/// Size of a texture.
/// </summary>
[DataField(required: true)] public Vector2 Size;
/// <summary>
/// Offset from bottom left corner. Starter position in the bottom.
/// </summary>
[DataField(required: true)] public Vector2 Offset;
}
}
[DataDefinition]
public partial struct FishingMinigameElementData
{
/// <summary>
/// Texture path.
/// </summary>
[DataField(required: true)] public ResPath Texture;
/// <summary>
/// Size of a texture.
/// </summary>
[DataField(required: true)] public Vector2 Size;
/// <summary>
/// Offset from bottom left corner. Starter position in the bottom.
/// </summary>
[DataField(required: true)] public Vector2 Offset;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 B

After

Width:  |  Height:  |  Size: 320 B