I am become Death, the Code Destroyer
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
11
Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml
Normal file
11
Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml
Normal 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>
|
||||
70
Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml.cs
Normal file
70
Content.Client/_CP14/Fishing/UI/CP14FishingWindow.xaml.cs
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user