Skip to content

Commit

Permalink
Upstream merge 09/17/24 (Grimbly-Station#81)
Browse files Browse the repository at this point in the history
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Upstream merge as of 09/17/24
  • Loading branch information
SsalamethVersaach authored Sep 17, 2024
2 parents 6bc06b1 + 588d02d commit c054267
Show file tree
Hide file tree
Showing 142 changed files with 4,871 additions and 837 deletions.
40 changes: 40 additions & 0 deletions Content.Client/Flight/Components/FlightVisualsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Robust.Client.Graphics;
using Robust.Shared.GameStates;

namespace Content.Client.Flight.Components;

[RegisterComponent]
public sealed partial class FlightVisualsComponent : Component
{
/// <summary>
/// How long does the animation last
/// </summary>
[DataField]
public float Speed;

/// <summary>
/// How far it goes in any direction.
/// </summary>
[DataField]
public float Multiplier;

/// <summary>
/// How much the limbs (if there are any) rotate.
/// </summary>
[DataField]
public float Offset;

/// <summary>
/// Are we animating layers or the entire sprite?
/// </summary>
public bool AnimateLayer = false;
public int? TargetLayer;

[DataField]
public string AnimationKey = "default";

[ViewVariables(VVAccess.ReadWrite)]
public ShaderInstance Shader = default!;


}
67 changes: 67 additions & 0 deletions Content.Client/Flight/FlightSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Robust.Client.GameObjects;
using Content.Shared.Flight;
using Content.Shared.Flight.Events;
using Content.Client.Flight.Components;

namespace Content.Client.Flight;
public sealed class FlightSystem : SharedFlightSystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<FlightEvent>(OnFlight);

}

private void OnFlight(FlightEvent args)
{
var uid = GetEntity(args.Uid);
if (!_entityManager.TryGetComponent(uid, out SpriteComponent? sprite)
|| !args.IsAnimated
|| !_entityManager.TryGetComponent(uid, out FlightComponent? flight))
return;


int? targetLayer = null;
if (flight.IsLayerAnimated && flight.Layer is not null)
{
targetLayer = GetAnimatedLayer(uid, flight.Layer, sprite);
if (targetLayer == null)
return;
}

if (args.IsFlying && args.IsAnimated && flight.AnimationKey != "default")
{
var comp = new FlightVisualsComponent
{
AnimateLayer = flight.IsLayerAnimated,
AnimationKey = flight.AnimationKey,
Multiplier = flight.ShaderMultiplier,
Offset = flight.ShaderOffset,
Speed = flight.ShaderSpeed,
TargetLayer = targetLayer,
};
AddComp(uid, comp);
}
if (!args.IsFlying)
RemComp<FlightVisualsComponent>(uid);
}

public int? GetAnimatedLayer(EntityUid uid, string targetLayer, SpriteComponent? sprite = null)
{
if (!Resolve(uid, ref sprite))
return null;

int index = 0;
foreach (var layer in sprite.AllLayers)
{
// This feels like absolute shitcode, isn't there a better way to check for it?
if (layer.Rsi?.Path.ToString() == targetLayer)
return index;
index++;
}
return null;
}
}
64 changes: 64 additions & 0 deletions Content.Client/Flight/FlyingVisualizerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Content.Client.Flight.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;

namespace Content.Client.Flight;

/// <summary>
/// Handles offsetting an entity while flying
/// </summary>
public sealed class FlyingVisualizerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly SpriteSystem _spriteSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FlightVisualsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FlightVisualsComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FlightVisualsComponent, BeforePostShaderRenderEvent>(OnBeforeShaderPost);
}

private void OnStartup(EntityUid uid, FlightVisualsComponent comp, ComponentStartup args)
{
comp.Shader = _protoMan.Index<ShaderPrototype>(comp.AnimationKey).InstanceUnique();
AddShader(uid, comp.Shader, comp.AnimateLayer, comp.TargetLayer);
SetValues(comp, comp.Speed, comp.Offset, comp.Multiplier);
}

private void OnShutdown(EntityUid uid, FlightVisualsComponent comp, ComponentShutdown args)
{
AddShader(uid, null, comp.AnimateLayer, comp.TargetLayer);
}

private void AddShader(Entity<SpriteComponent?> entity, ShaderInstance? shader, bool animateLayer, int? layer)
{
if (!Resolve(entity, ref entity.Comp, false))
return;

if (!animateLayer)
entity.Comp.PostShader = shader;

if (animateLayer && layer is not null)
entity.Comp.LayerSetShader(layer.Value, shader);

entity.Comp.GetScreenTexture = shader is not null;
entity.Comp.RaiseShaderEvent = shader is not null;
}

/// <summary>
/// This function can be used to modify the shader's values while its running.
/// </summary>
private void OnBeforeShaderPost(EntityUid uid, FlightVisualsComponent comp, ref BeforePostShaderRenderEvent args)
{
SetValues(comp, comp.Speed, comp.Offset, comp.Multiplier);
}

private void SetValues(FlightVisualsComponent comp, float speed, float offset, float multiplier)
{
comp.Shader.SetParameter("Speed", speed);
comp.Shader.SetParameter("Offset", offset);
comp.Shader.SetParameter("Multiplier", multiplier);
}
}
21 changes: 21 additions & 0 deletions Content.Client/Guidebook/Controls/GuideFoodComposition.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<BoxContainer xmlns="https://spacestation14.io"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
HorizontalExpand="True"
Margin="0 0 0 5">
<BoxContainer Name="ReactantsContainer" Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<Label Name="ReagentLabel"
HorizontalExpand="True"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Access="Public"
Margin="2 0 0 0"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalAlignment="Center">
<Label Name="AmountLabel"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Access="Public"
Margin="2 0 0 0"/>
</BoxContainer>
</BoxContainer>
31 changes: 31 additions & 0 deletions Content.Client/Guidebook/Controls/GuideFoodComposition.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Client.UserInterface.ControlExtensions;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Guidebook.Controls;

[UsedImplicitly, GenerateTypedNameReferences]
public sealed partial class GuideFoodComposition : BoxContainer, ISearchableControl
{
public GuideFoodComposition(ReagentPrototype proto, FixedPoint2 quantity)
{
RobustXamlLoader.Load(this);

ReagentLabel.Text = proto.LocalizedName;
AmountLabel.Text = quantity.ToString();
}

public bool CheckMatchesSearch(string query)
{
return this.ChildrenContainText(query);
}

public void SetHiddenState(bool state, string query)
{
Visible = CheckMatchesSearch(query) ? state : !state;
}
}
43 changes: 43 additions & 0 deletions Content.Client/Guidebook/Controls/GuideFoodEmbed.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<BoxContainer xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Orientation="Vertical"
Margin="5 5 5 5">
<PanelContainer HorizontalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BorderThickness="1" BorderColor="#777777"/>
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical">
<PanelContainer Name="NameBackground" HorizontalExpand="True" VerticalExpand="False">
<RichTextLabel Name="FoodName" HorizontalAlignment="Center"/>
</PanelContainer>
<BoxContainer Name="SourcesContainer" HorizontalExpand="True">
<Collapsible HorizontalExpand="True">
<CollapsibleHeading Title="{Loc 'guidebook-food-sources-header'}"/>
<CollapsibleBody>
<GridContainer Name="SourcesDescriptionContainer"
Margin="10 0 10 0"
Columns="1"
HSeparationOverride="5"
HorizontalAlignment="Stretch"
HorizontalExpand="True"/>
</CollapsibleBody>
</Collapsible>
</BoxContainer>
<BoxContainer Name="CompositionContainer" HorizontalExpand="True">
<Collapsible>
<CollapsibleHeading Title="{Loc 'guidebook-food-reagents-header'}"/>
<CollapsibleBody>
<BoxContainer Name="CompositionDescriptionContainer"
Orientation="Vertical"
Margin="10 0 10 0"
HorizontalExpand="True"/>
</CollapsibleBody>
</Collapsible>
</BoxContainer>
<BoxContainer Margin="10 5 10 10" HorizontalExpand="True">
<!-- The troublemaker !-->
<RichTextLabel Name="FoodDescription" HorizontalAlignment="Left"/>
</BoxContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
Loading

0 comments on commit c054267

Please sign in to comment.