Skip to content

Commit

Permalink
Merge branch 'master-ru' into 'master-ru'
Browse files Browse the repository at this point in the history
Upstream update & Localization (Fuelable generators)

See merge request Workbench-Team/space-station-14!99
  • Loading branch information
AruMoon committed Aug 1, 2023
2 parents 589589e + d571d11 commit 0ed98e9
Show file tree
Hide file tree
Showing 264 changed files with 1,618 additions and 448 deletions.
33 changes: 10 additions & 23 deletions Content.Client/Physics/Controllers/MoverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ private void OnRelayPlayerAttached(EntityUid uid, RelayInputMoverComponent compo
{
Physics.UpdateIsPredicted(uid);
Physics.UpdateIsPredicted(component.RelayEntity);
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
if (MoverQuery.TryGetComponent(component.RelayEntity, out var inputMover))
SetMoveInput(inputMover, MoveButtons.None);
}

private void OnRelayPlayerDetached(EntityUid uid, RelayInputMoverComponent component, PlayerDetachedEvent args)
{
Physics.UpdateIsPredicted(uid);
Physics.UpdateIsPredicted(component.RelayEntity);
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
if (MoverQuery.TryGetComponent(component.RelayEntity, out var inputMover))
SetMoveInput(inputMover, MoveButtons.None);
}

Expand All @@ -87,23 +87,16 @@ public override void UpdateBeforeSolve(bool prediction, float frameTime)
if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player)
return;

if (TryComp<RelayInputMoverComponent>(player, out var relayMover))
if (RelayQuery.TryGetComponent(player, out var relayMover))
HandleClientsideMovement(relayMover.RelayEntity, frameTime);

HandleClientsideMovement(player, frameTime);
}

private void HandleClientsideMovement(EntityUid player, float frameTime)
{
var xformQuery = GetEntityQuery<TransformComponent>();
var moverQuery = GetEntityQuery<InputMoverComponent>();
var relayTargetQuery = GetEntityQuery<MovementRelayTargetComponent>();
var mobMoverQuery = GetEntityQuery<MobMoverComponent>();
var pullableQuery = GetEntityQuery<SharedPullableComponent>();
var modifierQuery = GetEntityQuery<MovementSpeedModifierComponent>();

if (!moverQuery.TryGetComponent(player, out var mover) ||
!xformQuery.TryGetComponent(player, out var xform))
if (!MoverQuery.TryGetComponent(player, out var mover) ||
!XformQuery.TryGetComponent(player, out var xform))
{
return;
}
Expand All @@ -112,17 +105,17 @@ private void HandleClientsideMovement(EntityUid player, float frameTime)
PhysicsComponent? body;
var xformMover = xform;

if (mover.ToParent && HasComp<RelayInputMoverComponent>(xform.ParentUid))
if (mover.ToParent && RelayQuery.HasComponent(xform.ParentUid))
{
if (!TryComp(xform.ParentUid, out body) ||
!TryComp(xform.ParentUid, out xformMover))
if (!PhysicsQuery.TryGetComponent(xform.ParentUid, out body) ||
!XformQuery.TryGetComponent(xform.ParentUid, out xformMover))
{
return;
}

physicsUid = xform.ParentUid;
}
else if (!TryComp(player, out body))
else if (!PhysicsQuery.TryGetComponent(player, out body))
{
return;
}
Expand All @@ -134,13 +127,7 @@ private void HandleClientsideMovement(EntityUid player, float frameTime)
physicsUid,
body,
xformMover,
frameTime,
xformQuery,
moverQuery,
mobMoverQuery,
relayTargetQuery,
pullableQuery,
modifierQuery);
frameTime);
}

protected override bool CanSound()
Expand Down
26 changes: 26 additions & 0 deletions Content.Client/Power/Generator/GeneratorWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
MinSize="350 130"
SetSize="360 180"
Title="{Loc 'generator-ui-title'}">
<BoxContainer Margin="4 0" Orientation="Horizontal">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="2" VerticalAlignment="Center" Margin="5">
<GridContainer Margin="2 0 0 0" Columns="2" HorizontalExpand="True">
<!-- Power -->
<Label Text="{Loc 'generator-ui-target-power-label'}"/>
<SpinBox Name="TargetPower" HorizontalExpand="True"/>
<Label Text="{Loc 'generator-ui-efficiency-label'}"/>
<Label Name="Efficiency" Text="???%" HorizontalExpand="True"/>
<Label Text="{Loc 'generator-ui-fuel-use-label'}"/>
<ProgressBar Name="FuelFraction" MinValue="0" MaxValue="1" HorizontalExpand="True"/>
<Label Text="{Loc 'generator-ui-fuel-left-label'}"/>
<Label Name="FuelLeft" Text="0" HorizontalExpand="True"/>
</GridContainer>
</BoxContainer>
<cc:VSeparator StyleClasses="LowDivider"/>
<PanelContainer Margin="12 0 0 0" StyleClasses="Inset" VerticalAlignment="Center">
<SpriteView Name="EntityView" SetSize="64 64" Scale="2 2" OverrideDirection="South" Margin="15"/>
</PanelContainer>
</BoxContainer>
</controls:FancyWindow>
57 changes: 57 additions & 0 deletions Content.Client/Power/Generator/GeneratorWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Power.Generator;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Power.Generator;

[GenerateTypedNameReferences]
public sealed partial class GeneratorWindow : FancyWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;

private readonly FuelGeneratorComponent? _component;
private SolidFuelGeneratorComponentBuiState? _lastState;

public GeneratorWindow(SolidFuelGeneratorBoundUserInterface bui, EntityUid vis)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_entityManager.TryGetComponent(vis, out _component);

EntityView.SetEntity(vis);
TargetPower.IsValid += IsValid;
TargetPower.ValueChanged += (args) =>
{
bui.SetTargetPower(args.Value);
};
}

private bool IsValid(int arg)
{
if (arg < 0)
return false;

if (arg > (_lastState?.MaximumPower / 1000.0f ?? 0))
return false;

return true;
}

public void Update(SolidFuelGeneratorComponentBuiState state)
{
if (_component == null)
return;

var oldState = _lastState;
_lastState = state;
// ReSharper disable once CompareOfFloatsByEqualityOperator
if (oldState?.TargetPower != state.TargetPower)
TargetPower.OverrideValue((int)(state.TargetPower / 1000.0f));
Efficiency.Text = SharedGeneratorSystem.CalcFuelEfficiency(state.TargetPower, state.OptimalPower, _component).ToString("P1");
FuelFraction.Value = state.RemainingFuel - (int) state.RemainingFuel;
FuelLeft.Text = ((int) MathF.Floor(state.RemainingFuel)).ToString();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Shared.Power.Generator;
using JetBrains.Annotations;
using Robust.Client.GameObjects;

namespace Content.Client.Power.Generator;

[UsedImplicitly]
public sealed class SolidFuelGeneratorBoundUserInterface : BoundUserInterface
{
private GeneratorWindow? _window;

public SolidFuelGeneratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();
_window = new GeneratorWindow(this, Owner);

_window.OpenCenteredLeft();
_window.OnClose += Close;
}

protected override void UpdateState(BoundUserInterfaceState state)
{
if (state is not SolidFuelGeneratorComponentBuiState msg)
return;

_window?.Update(msg);
}

protected override void Dispose(bool disposing)
{
_window?.Dispose();
}

public void SetTargetPower(int target)
{
SendMessage(new SetTargetPowerMessage(target));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public override void FrameUpdate(float frameTime)
if (Direction == DirectionFlag.None)
{
if (TryComp(player, out InputMoverComponent? cmp))
_mover.LerpRotation(cmp, frameTime);
_mover.LerpRotation(player, cmp, frameTime);

return;
}

Expand All @@ -64,7 +65,7 @@ public override void FrameUpdate(float frameTime)
if (!TryComp(player, out InputMoverComponent? mover))
return;

_mover.LerpRotation(mover, frameTime);
_mover.LerpRotation(player, mover, frameTime);

var effectiveDir = Direction;
if ((Direction & DirectionFlag.North) != 0)
Expand All @@ -75,7 +76,7 @@ public override void FrameUpdate(float frameTime)

var query = GetEntityQuery<TransformComponent>();
var xform = query.GetComponent(player);
var pos = _transform.GetWorldPosition(xform, query);
var pos = _transform.GetWorldPosition(xform);

if (!xform.ParentUid.IsValid())
{
Expand All @@ -93,12 +94,12 @@ public override void FrameUpdate(float frameTime)
if (xform.ParentUid.IsValid())
_transform.SetGridId(player, xform, Transform(xform.ParentUid).GridUid);

var parentRotation = _mover.GetParentGridAngle(mover, query);
var parentRotation = _mover.GetParentGridAngle(mover);
var localVec = effectiveDir.AsDir().ToAngle().ToWorldVec();
var worldVec = parentRotation.RotateVec(localVec);
var speed = CompOrNull<MovementSpeedModifierComponent>(player)?.BaseSprintSpeed ?? DefaultSpeed;
var delta = worldVec * frameTime * speed;
_transform.SetWorldPositionRotation(xform, pos + delta, delta.ToWorldAngle(), query);
_transform.SetWorldPositionRotation(xform, pos + delta, delta.ToWorldAngle());
}

private sealed class MoverHandler : InputCmdHandler
Expand Down
19 changes: 13 additions & 6 deletions Content.Server/Anomaly/AnomalySystem.Generator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Anomaly.Components;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Station.Components;
using Content.Shared.Anomaly;
using Content.Shared.CCVar;
using Content.Shared.Materials;
Expand Down Expand Up @@ -93,8 +94,7 @@ public void SpawnOnRandomGridLocation(EntityUid grid, string toSpawn)
var xform = Transform(grid);

var targetCoords = xform.Coordinates;
var gridBounds = gridComp.LocalAABB;
gridBounds.Scale(_configuration.GetCVar(CCVars.AnomalyGenerationGridBoundsScale));
var gridBounds = gridComp.LocalAABB.Scale(_configuration.GetCVar(CCVars.AnomalyGenerationGridBoundsScale));

for (var i = 0; i < 25; i++)
{
Expand Down Expand Up @@ -147,11 +147,18 @@ private void OnGeneratingUnpaused(EntityUid uid, GeneratingAnomalyGeneratorCompo

private void OnGeneratingFinished(EntityUid uid, AnomalyGeneratorComponent component)
{
var grid = Transform(uid).GridUid;
if (grid == null)
return;
var xform = Transform(uid);

if (_station.GetStationInMap(xform.MapID) is not { } station ||
!TryComp<StationDataComponent>(station, out var data) ||
_station.GetLargestGrid(data) is not { } grid)
{
if (xform.GridUid == null)
return;
grid = xform.GridUid.Value;
}

SpawnOnRandomGridLocation(grid.Value, component.SpawnerPrototype);
SpawnOnRandomGridLocation(grid, component.SpawnerPrototype);
RemComp<GeneratingAnomalyGeneratorComponent>(uid);
Appearance.SetData(uid, AnomalyGeneratorVisuals.Generating, false);
Audio.PlayPvs(component.GeneratingFinishedSound, uid);
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/Anomaly/AnomalySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.Explosion.EntitySystems;
using Content.Server.Materials;
using Content.Server.Radio.EntitySystems;
using Content.Server.Station.Systems;
using Content.Shared.Anomaly;
using Content.Shared.Anomaly.Components;
using Content.Shared.DoAfter;
Expand All @@ -28,6 +29,7 @@ public sealed partial class AnomalySystem : SharedAnomalySystem
[Dependency] private readonly ExplosionSystem _explosion = default!;
[Dependency] private readonly MaterialStorageSystem _material = default!;
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly RadioSystem _radio = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;

Expand Down
Loading

0 comments on commit 0ed98e9

Please sign in to comment.