Skip to content

Commit

Permalink
sm qol fixes (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alwayswannahunt authored Dec 25, 2024
1 parent 705d930 commit f615e66
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
using Robust.Client.UserInterface;
using Content.Shared.SS220.SuperMatter.Ui;
using Content.Shared.SS220.SuperMatter.Emitter;
using Content.Shared.Singularity.Components;

namespace Content.Client.SS220.SuperMatter.Emitter.Ui;

public sealed class SuperMatterEmitterExtensionBUI : BoundUserInterface
{
[ViewVariables]
private SuperMatterEmitterExtensionMenu? _menu;

private int? _power;
private int? _ratio;

private bool _emitterActivated = false;

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

protected override void Open()
{
base.Open();
Expand All @@ -21,11 +27,40 @@ protected override void Open()
_ratio = superMatterEmitter.EnergyToMatterRatio;
}

if (EntMan.TryGetComponent<EmitterComponent>(Owner, out var emitterComponent))
{
_emitterActivated = emitterComponent.IsOn;
}

_menu = this.CreateWindow<SuperMatterEmitterExtensionMenu>();
_menu.SetEmitterParams(_ratio, _power);

var state = _emitterActivated ? ActivationStateEnum.EmitterActivated : ActivationStateEnum.EmitterDeactivated;
_menu.ChangeActivationState(state);

_menu.OnSubmitButtonPressed += (_, powerConsumption, ratio) =>
{
SendMessage(new SuperMatterEmitterExtensionValueMessage(powerConsumption, ratio));
};
_menu.OnEmitterActivatePressed += (_) =>
{
SendMessage(new SuperMatterEmitterExtensionEmitterActivateMessage());

var state = _emitterActivated ? ActivationStateEnum.EmitterDeactivated : ActivationStateEnum.EmitterActivated;
_emitterActivated = !_emitterActivated;
_menu.ChangeActivationState(state);
};
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

switch (state)
{
case SuperMatterEmitterExtensionUpdate update:
_menu?.SetEmitterParams(update.EnergyToMatterRatio, update.PowerConsumption);
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<PanelContainer StyleClasses="LowDivider" Margin="4 4 4 2"/>
<BoxContainer MaxHeight="30">
<Label Name="SubmitDescription" Margin="4 0 0 1" HorizontalExpand="True" HorizontalAlignment="Left"/>
<Button Name="EmitterActivationButton" Text="{Loc 'supermatter-emitter-extension-deactivated-emitter'}" HorizontalExpand="True" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
<Button Name="SubmitButton" Text="{Loc 'supermatter-emitter-extension-submit'}" HorizontalExpand="True" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
</BoxContainer>
</BoxContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace Content.Client.SS220.SuperMatter.Emitter.Ui;
public sealed partial class SuperMatterEmitterExtensionMenu : FancyWindow
{
[Dependency] ILocalizationManager _localization = default!;

public event Action<BaseButton.ButtonEventArgs, int, int>? OnSubmitButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnEmitterActivatePressed;

public SuperMatterEmitterExtensionMenu()
{
IoCManager.InjectDependencies(this);
Expand All @@ -25,6 +28,11 @@ public SuperMatterEmitterExtensionMenu()
OnSubmitButtonPressed?.Invoke(args, PowerConsumptionSpinBox.Value, MatterToEnergyRatioSlider.Value);
ChangeApplyState(ApplyButtonStateEnum.ChangesSaved);
};
EmitterActivationButton.OnPressed += args =>
{
OnEmitterActivatePressed?.Invoke(args);

};
}
public void SetEmitterParams(int? ratio, int? power)
{
Expand All @@ -34,6 +42,20 @@ public void SetEmitterParams(int? ratio, int? power)
PowerConsumptionSpinBox.Value = power.Value;
ChangeApplyState(ApplyButtonStateEnum.ChangesSaved);
}
public void ChangeActivationState(ActivationStateEnum state)
{
switch (state)
{
case ActivationStateEnum.EmitterActivated:
ChangeButtonLabelColor(EmitterActivationButton, Color.LimeGreen);
EmitterActivationButton.Text = _localization.GetString("supermatter-emitter-extension-activated-emitter");
break;
case ActivationStateEnum.EmitterDeactivated:
ChangeButtonLabelColor(EmitterActivationButton, Color.OrangeRed);
EmitterActivationButton.Text = _localization.GetString("supermatter-emitter-extension-deactivated-emitter");
break;
}
}

private void InitPowerConsumptionSpinBox()
{
Expand Down Expand Up @@ -76,20 +98,20 @@ private void ChangeApplyState(ApplyButtonStateEnum state)
switch (state)
{
case ApplyButtonStateEnum.ChangesSaved:
ChangeButtonLabelColor(Color.LightGreen);
ChangeButtonLabelColor(SubmitButton, Color.LightGreen);
SubmitDescription.Text = _localization.GetString("supermatter-emitter-extension-changes-saved");
SubmitDescription.FontColorOverride = Color.LightGreen;
break;
case ApplyButtonStateEnum.ChangesNotSaved:
ChangeButtonLabelColor(Color.Orange);
ChangeButtonLabelColor(SubmitButton, Color.Orange);
SubmitDescription.Text = _localization.GetString("supermatter-emitter-extension-changes-unsaved");
SubmitDescription.FontColorOverride = Color.Orange;
break;
}
}
private void ChangeButtonLabelColor(Color color)
private void ChangeButtonLabelColor(Button button, Color color)
{
SubmitButton.Label.FontColorOverride = color;
button.Label.FontColorOverride = color;
}
private void ChangeSliderLabels()
{
Expand All @@ -105,3 +127,9 @@ private enum ApplyButtonStateEnum
ChangesNotSaved
}
}

public enum ActivationStateEnum
{
EmitterActivated,
EmitterDeactivated
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public void BroadcastData(Entity<SuperMatterComponent> crystal)
var pressure = comp.PressureAccumulator / comp.UpdatesBetweenBroadcast;
comp.Name ??= MetaData(crystal.Owner).EntityName;
Dictionary<Gas, float> gasRatios = new();

if (!comp.AccumulatedGasesMoles.TryGetValue(Gas.Oxygen, out _))
InitGasMolesAccumulator(crystal.Comp);

foreach (var gas in Enum.GetValues<Gas>())
{
gasRatios.Add(gas, comp.AccumulatedGasesMoles[gas] / comp.AccumulatedGasesMoles.Values.Sum());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Content.Shared.Destructible;
using Content.Shared.SS220.SuperMatter.Ui;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Content.Shared.Humanoid;

namespace Content.Server.SS220.SuperMatterCrystal;

Expand Down Expand Up @@ -77,7 +78,7 @@ private void OnCollide(Entity<SuperMatterComponent> entity, ref StartCollideEven
return;
}

ConsumeObject(args.OtherEntity, entity);
ConsumeObject(args.OtherEntity, entity, HasComp<HumanoidAppearanceComponent>(args.OtherEntity));
}
private void OnActivation(Entity<SuperMatterComponent> entity, ref SuperMatterActivationEvent args)
{
Expand Down
7 changes: 5 additions & 2 deletions Content.Server/SS220/SuperMatter/Crystal/SuperMatterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public sealed partial class SuperMatterSystem : EntitySystem
private const float RadiationPerEnergy = 70f;

private const float IntegrityDamageICAnnounceDelay = 12f;
private const float IntegrityDamageStationAnnouncementDelay = 6f;
private const float IntegrityDamageStationAnnouncementDelay = 8f;

private const float ReleasedEnergyToGasHeat = 60f;

private const float MaxRadiationIntensity = 16f;

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -88,6 +90,7 @@ private void SuperMatterUpdate(Entity<SuperMatterComponent> crystal, float frame

EjectGases(decayedMatter, crystalTemperature, smState, gasMixture);
crystal.Comp.Matter -= decayedMatter;
crystal.Comp.Temperature += releasedEnergyPerFrame / GetHeatCapacity(crystalTemperature, prevMatter) - decayedMatter / crystal.Comp.Matter * crystalTemperature;

_atmosphere.AddHeat(gasMixture, ReleasedEnergyToGasHeat * releasedEnergyPerFrame);
AddIntegrityDamage(crystal.Comp, GetIntegrityDamage(crystal.Comp) * frameTime);
Expand Down Expand Up @@ -157,7 +160,7 @@ private void ReleaseEnergy(Entity<SuperMatterComponent> crystal)
arcShooterComponent.ShootMaxInterval = MaxTimeBetweenArcs - timeDecreaseBetweenArcs;
}

var radiationIntensity = smComp.AccumulatedRadiationEnergy / RadiationPerEnergy;
var radiationIntensity = MathF.Min(MaxRadiationIntensity, smComp.AccumulatedRadiationEnergy / RadiationPerEnergy);
radiationSource.Intensity = radiationIntensity;
}
private void EjectGases(float decayedMatter, float crystalTemperature, SuperMatterPhaseState smState, GasMixture gasMixture)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using System.Diagnostics;
using System.Linq;
using Content.Server.Singularity.EntitySystems;
using Content.Shared.Singularity.Components;
using Content.Shared.SS220.SuperMatter.Emitter;
using Content.Shared.SS220.SuperMatter.Ui;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;

namespace Content.Server.SS220.SuperMatter.Emitter;


public sealed class SuperMatterEmitterExtensionSystem : EntitySystem
{
[Dependency] EmitterSystem _emitter = default!;
[Dependency] IPrototypeManager _prototypeManager = default!;
[Dependency] UserInterfaceSystem _userInterface = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SuperMatterEmitterExtensionComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<SuperMatterEmitterExtensionComponent, SuperMatterEmitterExtensionValueMessage>(OnApplyMessage);
SubscribeLocalEvent<SuperMatterEmitterExtensionComponent, SuperMatterEmitterExtensionEmitterActivateMessage>(OnEmitterActivateMessage);
}

private void OnComponentInit(Entity<SuperMatterEmitterExtensionComponent> entity, ref ComponentInit args)
Expand All @@ -29,19 +37,51 @@ private void OnComponentInit(Entity<SuperMatterEmitterExtensionComponent> entity
}
private void OnApplyMessage(Entity<SuperMatterEmitterExtensionComponent> entity, ref SuperMatterEmitterExtensionValueMessage args)
{
entity.Comp.PowerConsumption = args.PowerConsumption;
entity.Comp.EnergyToMatterRatio = args.EnergyToMatterRatio;
entity.Comp.PowerConsumption = Math.Min(16384, args.PowerConsumption);
entity.Comp.EnergyToMatterRatio = Math.Clamp(args.EnergyToMatterRatio, 0, 100);

UpdateCorrespondingComponents(entity.Owner, entity.Comp, out var emitterComponent);

UpdateCorrespondingComponents(entity.Owner, entity.Comp);
Dirty(entity);
if (emitterComponent != null)
Dirty(entity.Owner, emitterComponent);

UpdateBUI(entity);
}
private void UpdateCorrespondingComponents(EntityUid uid, SuperMatterEmitterExtensionComponent comp)

/// <summary>
/// Updates entities BUI with current parameters
/// </summary>
/// <param name="entity"></param>
public void UpdateBUI(Entity<SuperMatterEmitterExtensionComponent> entity)
{
if (!TryComp<EmitterComponent>(uid, out var emitterComponent))
var state = new SuperMatterEmitterExtensionUpdate(entity.Comp.PowerConsumption, entity.Comp.EnergyToMatterRatio);

_userInterface.SetUiState(entity.Owner, SuperMatterEmitterExtensionUiKey.Key, state);
}

private void UpdateCorrespondingComponents(EntityUid uid, SuperMatterEmitterExtensionComponent comp, out EmitterComponent? emitterComponent)
{
if (!TryComp<EmitterComponent>(uid, out emitterComponent))
{
Log.Debug($"SM Emitter Extension exist in entity, but it doesnt have {nameof(EmitterComponent)}");
return;
}
emitterComponent.PowerUseActive = comp.PowerConsumption;
}

private void OnEmitterActivateMessage(Entity<SuperMatterEmitterExtensionComponent> entity, ref SuperMatterEmitterExtensionEmitterActivateMessage args)
{
if (!TryComp<EmitterComponent>(entity, out var emitterComponent))
{
Log.Debug($"SM Emitter Extension exist in entity, but it doesnt have {nameof(EmitterComponent)}");
return;
}

var users = _userInterface.GetActors(entity.Owner, SuperMatterEmitterExtensionUiKey.Key);
Debug.Assert(users.Count() == 1);

_emitter.TryActivate((entity.Owner, emitterComponent), users.First());
Dirty<EmitterComponent>((entity.Owner, emitterComponent));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public sealed partial class RadiationCollectorComponent : Component
[ViewVariables]
public bool Enabled;

// SS220-SM-fix-begin
/// <summary>
/// This bool ensure less usage of plasmas near SM crystal
/// </summary>
public bool NearSM = false;

[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public float ReactionRateModifierNearSM = 0.2f;

[DataField]
public float LookupSMRange = 5f;
// SS220-SM-fix-end

/// <summary>
/// List of gases that will react to the radiation passing through the collector
/// </summary>
Expand Down
12 changes: 10 additions & 2 deletions Content.Server/Singularity/EntitySystems/EmitterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ private void OnActivate(EntityUid uid, EmitterComponent component, ActivateInWor
{
if (args.Handled)
return;

// SS220-SM-smEmitter-fix
args.Handled = TryActivate((uid, component), args.User);
}
public bool TryActivate(Entity<EmitterComponent> entity, EntityUid user)
{
(EntityUid User, bool Handled) args = (user, false);
var (uid, component) = entity;
// SS220-SM-smEmitter-fix
if (TryComp(uid, out LockComponent? lockComp) && lockComp.Locked)
{
_popup.PopupEntity(Loc.GetString("comp-emitter-access-locked",
("target", uid)), uid, args.User);
return;
return args.Handled; // SS220-SM-smEmitter-fix
}

if (TryComp(uid, out PhysicsComponent? phys) && phys.BodyType == BodyType.Static)
Expand Down Expand Up @@ -97,6 +104,7 @@ private void OnActivate(EntityUid uid, EmitterComponent component, ActivateInWor
_popup.PopupEntity(Loc.GetString("comp-emitter-not-anchored",
("target", uid)), uid, args.User);
}
return args.Handled; // SS220-SM-smEmitter-fix
}

private void OnGetVerb(EntityUid uid, EmitterComponent component, GetVerbsEvent<Verb> args)
Expand Down
Loading

0 comments on commit f615e66

Please sign in to comment.