I am become Death, the Code Destroyer

This commit is contained in:
Deserty0
2025-10-05 16:48:09 +10:00
parent 636b2a5514
commit 88575e2286
9 changed files with 226 additions and 255 deletions

View File

@@ -1,42 +1,29 @@
using System.Numerics;
using Content.Client.Hands.Systems;
using Content.Client.Resources;
using Content.Client.UserInterface.Screens;
using Content.Shared._CP14.Fishing;
using Content.Shared._CP14.Fishing.Components;
using Content.Shared._CP14.Input;
using Content.Shared.CombatMode;
using Content.Shared.Interaction;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client._CP14.Fishing;
public sealed class CP14FishingSystem : CP14SharedFishingSystem
{
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly InputSystem _input = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly HandsSystem _hands = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private Popup? _fishingPopup;
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FishingUIStatus>(OnFishingStatusChanged);
SubscribeLocalEvent<CP14FishingRodComponent, AfterAutoHandleStateEvent>(OnFishingRodState);
}
public override void Update(float dt)
{
base.Update(dt);
@@ -53,7 +40,14 @@ public sealed class CP14FishingSystem : CP14SharedFishingSystem
return;
UpdatePressedButtons(fishingRodComponent, player);
UpdateUserInterface(fishingRodComponent);
}
private void OnFishingRodState(Entity<CP14FishingRodComponent> entity, ref AfterAutoHandleStateEvent args)
{
if (_userInterface.TryGetOpenUi(entity.Owner, CP14FishingUiKey.Key, out var bui))
{
bui.Update();
}
}
private void UpdatePressedButtons(CP14FishingRodComponent fishingRodComponent, EntityUid player)
@@ -67,180 +61,6 @@ public sealed class CP14FishingSystem : CP14SharedFishingSystem
return;
fishingRodComponent.Reeling = reelKey;
RaiseNetworkEvent(new FishingReelKeyMessage(reelKey));
}
private void UpdateUserInterface(CP14FishingRodComponent fishingRodComponent)
{
if (_fishingPopup is null)
return;
if (_fishingPopup.Visible == false)
return;
var fish = fishingRodComponent.CaughtFish;
if (fish is null)
return;
TryComp(fish, out CP14FishComponent? fishComponent);
if (fishComponent is null)
return;
if (!_prototypeManager.Resolve(fishingRodComponent.FishingMinigame, out var minigameStyle))
return;
var floatUI = minigameStyle.Float;
var progressbar = minigameStyle.Progressbar;
var fishIcon = minigameStyle.FishIcon;
var firstLayer = _fishingPopup!.GetChild(0);
var secondLayer = _fishingPopup!.GetChild(1);
var progressbarContainer = firstLayer.GetChild(0);
var floatContainer = firstLayer.GetChild(1);
var fishContainer = secondLayer.GetChild(0);
floatContainer.Margin = new Thickness(floatUI.Offset.X, 0, floatUI.Offset.Y + fishingRodComponent.FloatPosition, 0);
fishContainer.Margin = new Thickness(fishIcon.Offset.X, 0, fishIcon.Offset.Y + fishComponent.FishPosAndDestination.X, 0);
}
private void OnFishingStatusChanged(FishingUIStatus status)
{
if (status.UIStatus)
{
OpenFishingPopup(status.Component);
}
else
{
CloseFishingPopup();
}
}
private void OpenFishingPopup(CP14FishingRodComponent component)
{
// 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;
// Generating popup
_fishingPopup = new Popup
{
CloseOnClick = false,
CloseOnEscape = false,
MinSize = new Vector2(background.Size.X, background.Size.Y),
MaxSize = new Vector2(background.Size.X, background.Size.Y),
};
var screenCenter = new Vector2();
switch (_userInterfaceManager.ActiveScreen)
{
case DefaultGameScreen gameScreen:
gameScreen.AddChild(_fishingPopup);
screenCenter = gameScreen.Size / 2;
break;
case SeparatedChatGameScreen gameScreen:
gameScreen.AddChild(_fishingPopup);
screenCenter = gameScreen.Size / 2;
break;
}
// Generating layers
var backgroundTexture = _resourceCache.GetTexture(background.Texture);
var firstLayer = new PanelContainer
{
PanelOverride = new StyleBoxTexture
{
Texture = backgroundTexture,
},
MinSize = new Vector2(background.Size.X, background.Size.Y),
MaxSize = new Vector2(background.Size.X, background.Size.Y),
};
_fishingPopup.AddChild(firstLayer);
var secondLayer = new PanelContainer
{
MinSize = new Vector2(background.Size.X, background.Size.Y),
MaxSize = new Vector2(background.Size.X, background.Size.Y),
};
_fishingPopup.AddChild(secondLayer);
// Filling first layer
var progressbarTexture = _resourceCache.GetTexture(progressbar.Texture);
var progressbarContainer = new PanelContainer
{
PanelOverride = new StyleBoxTexture
{
Texture = progressbarTexture,
},
MinSize = new Vector2(progressbar.Size.X, 0),
SetSize = new Vector2(progressbar.Size.X, 0),
MaxSize = new Vector2(progressbar.Size.X, progressbar.Size.Y),
Margin = new Thickness(progressbar.Offset.X, 0, 0, progressbar.Offset.Y),
HorizontalAlignment = Control.HAlignment.Left,
VerticalAlignment = Control.VAlignment.Bottom,
};
firstLayer.AddChild(progressbarContainer);
var floatTexture = _resourceCache.GetTexture(floatUI.Texture);
var floatContainer = new PanelContainer
{
PanelOverride = new StyleBoxTexture
{
Texture = floatTexture,
},
MinSize = new Vector2(floatUI.Size.X, floatUI.Size.Y),
MaxSize = new Vector2(floatUI.Size.X, floatUI.Size.Y),
Margin = new Thickness(floatUI.Offset.X, 0, 0, floatUI.Offset.Y),
HorizontalAlignment = Control.HAlignment.Left,
VerticalAlignment = Control.VAlignment.Bottom,
};
firstLayer.AddChild(floatContainer);
// Filling second layer
var fishTexture = _resourceCache.GetTexture(fishIcon.Texture);
var fishIconContainer = new PanelContainer
{
PanelOverride = new StyleBoxTexture
{
Texture = fishTexture,
},
MinSize = new Vector2(fishIcon.Size.X, fishIcon.Size.Y),
MaxSize = new Vector2(fishIcon.Size.X, fishIcon.Size.Y),
Margin = new Thickness(fishIcon.Offset.X, 0, 0, fishIcon.Offset.Y),
HorizontalAlignment = Control.HAlignment.Left,
VerticalAlignment = Control.VAlignment.Bottom,
};
secondLayer.AddChild(fishIconContainer);
_fishingPopup.Open(UIBox2.FromDimensions(new Vector2(screenCenter.X - background.Size.X,
screenCenter.Y - background.Size.Y),
background.Size));
}
private void CloseFishingPopup()
{
if (_fishingPopup is null)
return;
switch (_userInterfaceManager.ActiveScreen)
{
case DefaultGameScreen gameScreen:
gameScreen.RemoveChild(_fishingPopup);
break;
case SeparatedChatGameScreen gameScreen:
gameScreen.RemoveChild(_fishingPopup);
break;
}
_fishingPopup = null;
RaiseNetworkEvent(new CP14FishingReelKeyMessage(reelKey));
}
}

View File

@@ -0,0 +1,59 @@
using Content.Shared._CP14.Fishing.Components;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client._CP14.Fishing.UI;
[UsedImplicitly]
public sealed class CP14FishingBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private CP14FishingWindow? _fishingWindow;
public CP14FishingBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
if (!EntMan.TryGetComponent<CP14FishingRodComponent>(Owner, out var rodComponent))
return;
_fishingWindow = this.CreateWindow<CP14FishingWindow>();
_fishingWindow.InitVisuals(rodComponent);
}
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);
}
}

View File

@@ -0,0 +1,11 @@
<!-- Empty fishing popup -->
<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>
</fishingWindow:CP14FishingWindow>

View File

@@ -0,0 +1,70 @@
using Content.Client.Resources;
using Content.Shared._CP14.Fishing.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
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!;
public CP14FishingWindow()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
}
public void InitVisuals(CP14FishingRodComponent component)
{
// 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;
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);
var backgroundTexture = _resourceCache.GetTexture(background.Texture);
FishingBackground.PanelOverride = new StyleBoxTexture
{
Texture = backgroundTexture,
};
var progressbarTexture = _resourceCache.GetTexture(progressbar.Texture);
Progressbar.PanelOverride = new StyleBoxTexture
{
Texture = progressbarTexture,
};
var floatTexture = _resourceCache.GetTexture(floatUI.Texture);
Float.PanelOverride = new StyleBoxTexture
{
Texture = floatTexture,
};
var fishTexture = _resourceCache.GetTexture(fishIcon.Texture);
FishIcon.PanelOverride = new StyleBoxTexture
{
Texture = fishTexture,
};
}
}

View File

@@ -0,0 +1,21 @@
using Robust.Shared.Serialization;
namespace Content.Shared._CP14.Fishing
{
[Serializable, NetSerializable]
public enum CP14FishingUiKey : byte
{
Key,
}
[Serializable, NetSerializable]
public sealed class CP14FishingReelKeyMessage : EntityEventArgs
{
public bool Reeling { get; }
public CP14FishingReelKeyMessage(bool reeling)
{
Reeling = reeling;
}
}
}

View File

@@ -6,6 +6,8 @@ using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Throwing;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Network;
@@ -26,6 +28,7 @@ public abstract class CP14SharedFishingSystem : EntitySystem
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
@@ -41,7 +44,7 @@ public abstract class CP14SharedFishingSystem : EntitySystem
SubscribeLocalEvent<CP14FishingRodComponent, AfterInteractEvent>(OnInteract);
SubscribeLocalEvent<CP14FishingRodComponent, DroppedEvent>(OnDropEvent);
SubscribeNetworkEvent<FishingReelKeyMessage>(OnReelingMessage);
SubscribeNetworkEvent<CP14FishingReelKeyMessage>(OnReelingMessage);
}
public override void Update(float frameTime)
@@ -65,6 +68,9 @@ public abstract class CP14SharedFishingSystem : EntitySystem
private void UpdatePositions(EntityUid fishingRod, CP14FishingRodComponent fishingRodComponent, TimeSpan curTime)
{
if (_netManager.IsClient && _gameTiming.IsFirstTimePredicted)
return;
if (fishingRodComponent.CaughtFish is null)
return;
@@ -158,8 +164,7 @@ public abstract class CP14SharedFishingSystem : EntitySystem
{
fishingRodComponent.FishHooked = true;
var user = fishingRodComponent.User;
RaiseLocalEvent(user!.Value, new FishingUIStatus(true, fishingRodComponent));
_userInterface.OpenUi(fishingRod, CP14FishingUiKey.Key);
DirtyField(fishingRod, fishingRodComponent, nameof(CP14FishingRodComponent.FishHooked));
return;
@@ -178,6 +183,9 @@ public abstract class CP14SharedFishingSystem : EntitySystem
if (!_netManager.IsServer)
return;
if (fishingRodComponent.CaughtFish is not null)
return;
if (curTime < fishingRodComponent.FishingTime)
return;
@@ -226,29 +234,33 @@ public abstract class CP14SharedFishingSystem : EntitySystem
DirtyField(fish, fishComponent, nameof(CP14FishComponent.FishGetAwayTime));
}
private void RevalidateFishing(EntityUid fishingRod, CP14FishingRodComponent component)
private void RevalidateFishing(EntityUid fishingRod, CP14FishingRodComponent fishingRodComponent)
{
if (component.FishingFloat is null)
if (fishingRodComponent.FishingFloat is null)
return;
if (_transform.InRange(fishingRod, component.FishingFloat.Value, component.MaxFishingDistance * 1.5f))
if (_transform.InRange(fishingRod, fishingRodComponent.FishingFloat.Value, fishingRodComponent.MaxFishingDistance * 1.5f))
return;
PredictedDel(component.FishingFloat);
PredictedDel(fishingRodComponent.FishingFloat);
component.FishingFloat = null;
component.Target = null;
component.User = null;
fishingRodComponent.FishHooked = false;
fishingRodComponent.CaughtFish = null;
fishingRodComponent.FishingFloat = null;
fishingRodComponent.Target = null;
fishingRodComponent.User = null;
DirtyFields(fishingRod,
component,
fishingRodComponent,
null,
nameof(CP14FishingRodComponent.FishingFloat),
nameof(CP14FishingRodComponent.Target),
nameof(CP14FishingRodComponent.User));
nameof(CP14FishingRodComponent.User),
nameof(CP14FishingRodComponent.CaughtFish),
nameof(CP14FishingRodComponent.FishHooked));
}
private void OnReelingMessage(FishingReelKeyMessage msg, EntitySessionEventArgs args)
private void OnReelingMessage(CP14FishingReelKeyMessage msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not { } player)
return;
@@ -261,7 +273,7 @@ public abstract class CP14SharedFishingSystem : EntitySystem
DirtyField(activeItem.Value, fishingRodComponent, nameof(CP14FishingRodComponent.Reeling));
}
private void OnInteract(EntityUid uid, CP14FishingRodComponent component, AfterInteractEvent args)
private void OnInteract(EntityUid fishingRod, CP14FishingRodComponent fishingRodComponent, AfterInteractEvent args)
{
if (args.Handled)
return;
@@ -269,50 +281,48 @@ public abstract class CP14SharedFishingSystem : EntitySystem
if (args.Target is not { Valid: true })
return;
if (component.FishingFloat is not null)
if (fishingRodComponent.FishingFloat is not null)
return;
if (!TryComp<CP14FishingPondComponent>(args.Target, out _))
return;
if (!_interaction.InRangeUnobstructed(uid, args.Target.Value, component.MaxFishingDistance))
if (!_interaction.InRangeUnobstructed(fishingRod, args.Target.Value, fishingRodComponent.MaxFishingDistance))
return;
args.Handled = true;
component.FishingTime = _gameTiming.CurTime;
component.FishingTime += TimeSpan.FromSeconds(_random.NextDouble(component.MinAwaitTime, component.MaxAwaitTime));
component.User = args.User;
fishingRodComponent.FishingTime = _gameTiming.CurTime;
fishingRodComponent.FishingTime += TimeSpan.FromSeconds(_random.NextDouble(fishingRodComponent.MinAwaitTime, fishingRodComponent.MaxAwaitTime));
fishingRodComponent.User = args.User;
DirtyFields(uid, component, null, nameof(CP14FishingRodComponent.FishingTime), nameof(CP14FishingRodComponent.User));
DirtyFields(fishingRod, fishingRodComponent, null, nameof(CP14FishingRodComponent.FishingTime), nameof(CP14FishingRodComponent.User));
CastFloat(args.Used, component, args.Target.Value);
CastFloat(fishingRod, fishingRodComponent, args.Target.Value);
}
private void OnDropEvent(EntityUid entity, CP14FishingRodComponent component, DroppedEvent ev)
private void OnDropEvent(EntityUid fishingRod, CP14FishingRodComponent fishingRodComponent, DroppedEvent ev)
{
component.User = null;
DirtyField(entity, component, nameof(CP14FishingRodComponent.User));
fishingRodComponent.User = null;
DirtyField(fishingRod, fishingRodComponent, nameof(CP14FishingRodComponent.User));
}
private void CastFloat(EntityUid uid, CP14FishingRodComponent component, EntityUid target)
private void CastFloat(EntityUid fishingRod, CP14FishingRodComponent fishingRodComponent, EntityUid fishingPond)
{
var rodCoords = Transform(uid).Coordinates;
var targetCoords = Transform(target).Coordinates;
var rodCoords = Transform(fishingRod).Coordinates;
var targetCoords = Transform(fishingPond).Coordinates;
var fishingFloat = PredictedSpawnAtPosition(component.FloatPrototype, rodCoords);
var fishingFloat = PredictedSpawnAtPosition(fishingRodComponent.FloatPrototype, rodCoords);
component.FishingFloat = fishingFloat;
component.Target = target;
component.User = uid;
DirtyFields(uid,
component,
fishingRodComponent.FishingFloat = fishingFloat;
fishingRodComponent.Target = fishingPond;
DirtyFields(fishingRod,
fishingRodComponent,
null,
nameof(CP14FishingRodComponent.FishingFloat),
nameof(CP14FishingRodComponent.Target),
nameof(CP14FishingRodComponent.User));
nameof(CP14FishingRodComponent.Target));
_throwing.TryThrow(fishingFloat, targetCoords, component.ThrowPower, recoil: false, doSpin: false);
_throwing.TryThrow(fishingFloat, targetCoords, fishingRodComponent.ThrowPower, recoil: false, doSpin: false);
}
private void EnsurePausedMap()
@@ -328,28 +338,4 @@ public abstract class CP14SharedFishingSystem : EntitySystem
_mapId = newMapId;
_map.SetPaused(mapUid, true);
}
[Serializable, NetSerializable]
public sealed class FishingReelKeyMessage : EntityEventArgs
{
public bool Reeling { get; }
public FishingReelKeyMessage(bool reeling)
{
Reeling = reeling;
}
}
public sealed class FishingUIStatus : EntityEventArgs
{
public bool UIStatus { get; }
public CP14FishingRodComponent Component { get; }
public FishingUIStatus(bool uiStatus, CP14FishingRodComponent component)
{
UIStatus = uiStatus;
Component = component;
}
}
}

View File

@@ -20,8 +20,8 @@ public sealed partial class CP14FishComponent : Component
public Vector2 FishPosAndDestination;
[DataField]
public double MinAwaitTime = 1;
public double MinAwaitTime = 5;
[DataField]
public double MaxAwaitTime = 4;
public double MaxAwaitTime = 10;
}

View File

@@ -6,7 +6,7 @@ namespace Content.Shared._CP14.Fishing.Components;
/// <summary>
/// Allows to fish with this item
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true), AutoGenerateComponentPause]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true, true), AutoGenerateComponentPause]
public sealed partial class CP14FishingRodComponent : Component
{
// Vars

View File

@@ -44,6 +44,10 @@
slots:
- neck
- type: CP14FishingRod
- type: UserInterface
interfaces:
enum.CP14FishingUiKey.Key:
type: CP14FishingBoundUserInterface
- type: entity
parent: BaseItem