From f31e82f7b3173b86c758f83f0cd1f069db06d570 Mon Sep 17 00:00:00 2001 From: Deserty0 Date: Fri, 17 Oct 2025 14:28:03 +1000 Subject: [PATCH] 123 --- .../_CP14/Fishing/CP14FishingSystem.cs | 20 +++++ .../UI/CP14FishingBoundUserInterface.cs | 35 ++------ .../_CP14/Fishing/UI/CP14FishingWindow.xaml | 8 +- .../Fishing/UI/CP14FishingWindow.xaml.cs | 82 ++++++++++-------- .../Fishing/CP14FishingMinigamePrototype.cs | 40 ++++----- .../Interface/Fishing/Default/fish_icon.png | Bin 250 -> 320 bytes 6 files changed, 97 insertions(+), 88 deletions(-) diff --git a/Content.Client/_CP14/Fishing/CP14FishingSystem.cs b/Content.Client/_CP14/Fishing/CP14FishingSystem.cs index baa90fb8d9..4efce7301c 100644 --- a/Content.Client/_CP14/Fishing/CP14FishingSystem.cs +++ b/Content.Client/_CP14/Fishing/CP14FishingSystem.cs @@ -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(heldUid, out var posRodComponent)) + return false; + + if (!TryComp(posRodComponent.CaughtFish, out var posFishComponent)) + return false; + + rodComponent = posRodComponent; + fishComponent = posFishComponent; + return true; + } } diff --git a/Content.Client/_CP14/Fishing/UI/CP14FishingBoundUserInterface.cs b/Content.Client/_CP14/Fishing/UI/CP14FishingBoundUserInterface.cs index ddb9773065..35a846a682 100644 --- a/Content.Client/_CP14/Fishing/UI/CP14FishingBoundUserInterface.cs +++ b/Content.Client/_CP14/Fishing/UI/CP14FishingBoundUserInterface.cs @@ -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(Owner, out var rodComponent)) return; + if (!_prototypeManager.Resolve(rodComponent.FishingMinigame, out var fishingMinigame)) + return; + _fishingWindow = this.CreateWindow(); - _fishingWindow.InitVisuals(rodComponent); + _fishingWindow.InitVisuals(fishingMinigame); } public override void Update() { base.Update(); - if (_fishingWindow is null || !EntMan.TryGetComponent(Owner, out var rodComponent)) - return; - - var fish = rodComponent.CaughtFish; - - if (fish is null) - return; - - if (!EntMan.TryGetComponent(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(); } } diff --git a/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml b/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml index bbfacdc27b..35960204b6 100644 --- a/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml +++ b/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml @@ -2,10 +2,6 @@ - - - - - + Name="FishingWindow" MaxSize="0 0"> + diff --git a/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml.cs b/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml.cs index f560ad0f55..40c2f3fd4f 100644 --- a/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml.cs +++ b/Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml.cs @@ -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(); } - 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); } } diff --git a/Content.Shared/_CP14/Fishing/CP14FishingMinigamePrototype.cs b/Content.Shared/_CP14/Fishing/CP14FishingMinigamePrototype.cs index 4642d9f7df..492814aeec 100644 --- a/Content.Shared/_CP14/Fishing/CP14FishingMinigamePrototype.cs +++ b/Content.Shared/_CP14/Fishing/CP14FishingMinigamePrototype.cs @@ -8,7 +8,7 @@ namespace Content.Shared._CP14.Fishing; /// Prototype of fishing minigame stylesheet. /// [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 - { - /// - /// Texture path. - /// - [DataField(required: true)] public ResPath Texture; - - /// - /// Size of a texture. - /// - [DataField(required: true)] public Vector2 Size; - - /// - /// Offset from bottom left corner. Starter position in the bottom. - /// - [DataField(required: true)] public Vector2 Offset; - } +} + +[DataDefinition] +public partial struct FishingMinigameElementData +{ + /// + /// Texture path. + /// + [DataField(required: true)] public ResPath Texture; + + /// + /// Size of a texture. + /// + [DataField(required: true)] public Vector2 Size; + + /// + /// Offset from bottom left corner. Starter position in the bottom. + /// + [DataField(required: true)] public Vector2 Offset; } diff --git a/Resources/Textures/_CP14/Interface/Fishing/Default/fish_icon.png b/Resources/Textures/_CP14/Interface/Fishing/Default/fish_icon.png index 538dce88043ce345c5c4511df523cb7cf06e4433..4d1912cb7c443ac7f7550f7952b5f37678ea3365 100644 GIT binary patch literal 320 zcmV-G0l)rPx#`bk7VR5*>jk+Et*F%*WsBVFv^a2FSGX$9BPt@CwoRZ&#BxVDAjQs^ulMR0O) zP_D(It`6Q;5EtK|tKcKpK?AuV=ygcHDG4WkzH0|8$fPC%_fX#9Yz(eu*Y=HR(3U|gLQs6k_6`FbS{t1B0dJ909N?HSg zQb&(6|@k(l`#j*+m?j8UF!gX;H=& SdKM7?0000Px#v`IukR2Y?Yj;#)YP#A{a!z>i9z~~*&%owQ5!O%tpr?W84j;02a27{YPyFuq2 z*t`O%Oq%sIog;_Ao4#+)^Zft~A;~7DNhEoW=OoF%a}_fHAn;rzB~FO-Xj*$k$R^$$ z6)dt`)u-hQm+=CFZ3=@VEk8n$<#_Bjng{@i6XN~(0svY