This commit is contained in:
Deserty0
2025-09-06 04:14:26 +10:00
parent af2e62ff59
commit 3759f240b3
4 changed files with 36 additions and 12 deletions

View File

@@ -1,19 +1,25 @@
using System.Diagnostics;
using System.Numerics;
using Content.Shared._CP14.Fishing;
using Content.Shared._CP14.Fishing.Components;
using Content.Shared.Interaction;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Utility;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.Fishing;
public sealed class CP14FishingSystem : CP14SharedFishingSystem
{
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
private Popup? _fishingPopup;
private const int FishingMinigameSizeX = 41;
private const int FishingMinigameSizeY = 149;
public override void Initialize()
{
@@ -27,7 +33,7 @@ public sealed class CP14FishingSystem : CP14SharedFishingSystem
if (args.Handled)
return;
if (!args.CanReach || args.Target is not { Valid: true } target)
if (!args.CanReach || args.Target is not { Valid: true })
return;
if (!TryComp<CP14FishingPondComponent>(args.Target, out var pond))
@@ -36,31 +42,44 @@ public sealed class CP14FishingSystem : CP14SharedFishingSystem
if (component.FishingProcess)
return;
OpenFishingPopup();
OpenFishingPopup(component);
}
private void OpenFishingPopup()
private void OpenFishingPopup(CP14FishingRodComponent component)
{
_fishingPopup = new Popup
{
CloseOnClick = false,
CloseOnEscape = false,
MinSize = new Vector2(41, 149),
MaxSize = new Vector2(41, 149), // 41, 149 is minigame texture format
MinSize = new Vector2(FishingMinigameSizeX, FishingMinigameSizeY),
MaxSize = new Vector2(FishingMinigameSizeX, FishingMinigameSizeY),
};
_userInterfaceManager.ModalRoot.AddChild(_fishingPopup);
var backgroundTexture = RequestTexture(CP14FishingMinigameElement.Background, component);
if (backgroundTexture is null)
return;
var panel = new PanelContainer
{
PanelOverride = new StyleBoxTexture
{
Texture = SpriteSpecifier.Texture()
}
Texture = backgroundTexture,
},
};
}
private ResPath RequestTexture(FishingMinigameElement element, CP14FishingRodComponent minigamePrototype)
private TextureResource? RequestTexture(CP14FishingMinigameElement element, CP14FishingRodComponent fishingRodComponent)
{
var minigamePrototype = _prototypeManager.Index(fishingRodComponent.FishingMinigame);
if (minigamePrototype.Texture is null || !minigamePrototype.Texture.TryGetValue(element, out var data))
{
Debug.Fail($"Tried to request a fishing minigame element {element} without a texture.");
return null;
}
var texture = _resourceCache.GetResource<TextureResource>(data.Texture);
return texture;
}
}

View File

@@ -11,7 +11,7 @@ public sealed partial class CP14FishingMinigamePrototype : IPrototype
public string ID { get; } = default!;
[DataField(required: true)]
public Dictionary<FishingMinigameElement, FishingMinigameElementData>? Texture;
public Dictionary<CP14FishingMinigameElement, FishingMinigameElementData>? Texture;
[DataDefinition]
public partial struct FishingMinigameElementData
@@ -21,7 +21,7 @@ public sealed partial class CP14FishingMinigamePrototype : IPrototype
}
}
public enum FishingMinigameElement : byte
public enum CP14FishingMinigameElement : byte
{
Background,
DefaultFishIcon,

View File

@@ -1,3 +1,5 @@
using Robust.Shared.Prototypes;
namespace Content.Shared._CP14.Fishing.Components;
/// <summary>
@@ -7,4 +9,7 @@ namespace Content.Shared._CP14.Fishing.Components;
public sealed partial class CP14FishingRodComponent : Component
{
public bool FishingProcess = false;
[DataField]
public ProtoId<CP14FishingMinigamePrototype> FishingMinigame = "Default";
}

View File

@@ -1,5 +1,5 @@
- type: CP14FishingMinigameStyle
id: default
id: Default
texture:
background:
- texture: _CP14/Interface/Fishing/Default/background.png