Converts the particle accelerator over to ECS + misc (#17075)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
TemporalOroboros
2023-06-07 23:25:59 -07:00
committed by GitHub
parent a3137cc0f0
commit d71b6c84e5
61 changed files with 1293 additions and 1169 deletions

View File

@@ -19,10 +19,10 @@ namespace Content.Client.ParticleAccelerator.UI
{
private readonly ShaderInstance _greyScaleShader;
private readonly ParticleAcceleratorBoundUserInterface Owner;
private readonly ParticleAcceleratorBoundUserInterface _owner;
private readonly Label _drawLabel;
private readonly NoiseGenerator _drawNoiseGenerator;
private readonly FastNoiseLite _drawNoiseGenerator;
private readonly Button _onButton;
private readonly Button _offButton;
private readonly Button _scanButton;
@@ -36,9 +36,9 @@ namespace Content.Client.ParticleAccelerator.UI
private readonly PASegmentControl _fuelChamberTexture;
private readonly PASegmentControl _controlBoxTexture;
private readonly PASegmentControl _powerBoxTexture;
private readonly PASegmentControl _emitterCenterTexture;
private readonly PASegmentControl _emitterRightTexture;
private readonly PASegmentControl _emitterLeftTexture;
private readonly PASegmentControl _emitterForeTexture;
private readonly PASegmentControl _emitterPortTexture;
private readonly PASegmentControl _emitterStarboardTexture;
private float _time;
private int _lastDraw;
@@ -47,14 +47,16 @@ namespace Content.Client.ParticleAccelerator.UI
private bool _blockSpinBox;
private bool _assembled;
private bool _shouldContinueAnimating;
private int _maxStrength = 3;
public ParticleAcceleratorControlMenu(ParticleAcceleratorBoundUserInterface owner)
{
SetSize = (400, 320);
_greyScaleShader = IoCManager.Resolve<IPrototypeManager>().Index<ShaderPrototype>("Greyscale").Instance();
Owner = owner;
_drawNoiseGenerator = new NoiseGenerator(NoiseGenerator.NoiseType.Fbm);
_owner = owner;
_drawNoiseGenerator = new();
_drawNoiseGenerator.SetFractalType(FastNoiseLite.FractalType.FBm);
_drawNoiseGenerator.SetFrequency(0.5f);
var resourceCache = IoCManager.Resolve<IResourceCache>();
@@ -98,7 +100,7 @@ namespace Content.Client.ParticleAccelerator.UI
MouseFilter = MouseFilterMode.Pass
});
_stateSpinBox = new SpinBox {Value = 0, IsValid = StrengthSpinBoxValid,};
_stateSpinBox = new SpinBox { Value = 0, IsValid = StrengthSpinBoxValid };
_stateSpinBox.InitDefaultButtons();
_stateSpinBox.ValueChanged += PowerStateChanged;
_stateSpinBox.LineEditDisabled = true;
@@ -107,7 +109,7 @@ namespace Content.Client.ParticleAccelerator.UI
{
ToggleMode = false,
Text = Loc.GetString("particle-accelerator-control-menu-off-button"),
StyleClasses = {StyleBase.ButtonOpenRight},
StyleClasses = { StyleBase.ButtonOpenRight },
};
_offButton.OnPressed += args => owner.SendEnableMessage(false);
@@ -115,13 +117,13 @@ namespace Content.Client.ParticleAccelerator.UI
{
ToggleMode = false,
Text = Loc.GetString("particle-accelerator-control-menu-on-button"),
StyleClasses = {StyleBase.ButtonOpenLeft},
StyleClasses = { StyleBase.ButtonOpenLeft },
};
_onButton.OnPressed += args => owner.SendEnableMessage(true);
var closeButton = new TextureButton
{
StyleClasses = {"windowCloseButton"},
StyleClasses = { "windowCloseButton" },
HorizontalAlignment = HAlignment.Right,
Margin = new Thickness(0, 0, 8, 0)
};
@@ -130,7 +132,7 @@ namespace Content.Client.ParticleAccelerator.UI
var serviceManual = new Label
{
HorizontalAlignment = HAlignment.Center,
StyleClasses = {StyleBase.StyleClassLabelSubText},
StyleClasses = { StyleBase.StyleClassLabelSubText },
Text = Loc.GetString("particle-accelerator-control-menu-service-manual-reference")
};
_drawLabel = new Label();
@@ -227,7 +229,8 @@ namespace Content.Client.ParticleAccelerator.UI
Align = Label.AlignMode.Center
},
serviceManual
}
},
Visible = false,
}),
}
},
@@ -267,9 +270,9 @@ namespace Content.Client.ParticleAccelerator.UI
new Control {MinSize = imgSize},
(_powerBoxTexture = Segment("power_box")),
new Control {MinSize = imgSize},
(_emitterLeftTexture = Segment("emitter_left")),
(_emitterCenterTexture = Segment("emitter_center")),
(_emitterRightTexture = Segment("emitter_right")),
(_emitterStarboardTexture = Segment("emitter_starboard")),
(_emitterForeTexture = Segment("emitter_fore")),
(_emitterPortTexture = Segment("emitter_port")),
}
}
}
@@ -312,7 +315,7 @@ namespace Content.Client.ParticleAccelerator.UI
}
});
_scanButton.OnPressed += args => Owner.SendScanPartsMessage();
_scanButton.OnPressed += args => _owner.SendScanPartsMessage();
_alarmControl.AnimationCompleted += s =>
{
@@ -336,7 +339,7 @@ namespace Content.Client.ParticleAccelerator.UI
private bool StrengthSpinBoxValid(int n)
{
return (n >= 0 && n <= 3 && !_blockSpinBox);
return n >= 0 && n <= _maxStrength && !_blockSpinBox;
}
private void PowerStateChanged(ValueChangedEventArgs e)
@@ -356,16 +359,15 @@ namespace Content.Client.ParticleAccelerator.UI
case 3:
newState = ParticleAcceleratorPowerState.Level2;
break;
// They can't reach this level anyway and I just want to fix the bugginess for now.
//case 4:
// newState = ParticleAcceleratorPowerState.Level3;
// break;
case 4:
newState = ParticleAcceleratorPowerState.Level3;
break;
default:
return;
}
_stateSpinBox.SetButtonDisabled(true);
Owner.SendPowerStateMessage(newState);
_owner.SendPowerStateMessage(newState);
}
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
@@ -402,14 +404,15 @@ namespace Content.Client.ParticleAccelerator.UI
});
_shouldContinueAnimating = false;
_alarmControl.StopAnimation("warningAnim");
_alarmControl.Visible = false;
if (maxState == ParticleAcceleratorPowerState.Level3 && enabled && assembled)
_maxStrength = maxState == ParticleAcceleratorPowerState.Level3 ? 4 : 3;
if (_maxStrength > 3 && enabled && assembled)
{
_shouldContinueAnimating = true;
_alarmControl.PlayAnimation(_alarmControlAnimation, "warningAnim");
if (!_alarmControl.Visible)
_alarmControl.PlayAnimation(_alarmControlAnimation, "warningAnim");
}
else
_shouldContinueAnimating = false;
}
private void UpdateUI(bool assembled, bool blocked, bool enabled, bool powerBlock)
@@ -430,12 +433,12 @@ namespace Content.Client.ParticleAccelerator.UI
private void UpdatePreview(ParticleAcceleratorUIState updateMessage)
{
_endCapTexture.SetPowerState(updateMessage, updateMessage.EndCapExists);
_fuelChamberTexture.SetPowerState(updateMessage, updateMessage.FuelChamberExists);
_controlBoxTexture.SetPowerState(updateMessage, true);
_fuelChamberTexture.SetPowerState(updateMessage, updateMessage.FuelChamberExists);
_powerBoxTexture.SetPowerState(updateMessage, updateMessage.PowerBoxExists);
_emitterCenterTexture.SetPowerState(updateMessage, updateMessage.EmitterCenterExists);
_emitterLeftTexture.SetPowerState(updateMessage, updateMessage.EmitterLeftExists);
_emitterRightTexture.SetPowerState(updateMessage, updateMessage.EmitterRightExists);
_emitterStarboardTexture.SetPowerState(updateMessage, updateMessage.EmitterStarboardExists);
_emitterForeTexture.SetPowerState(updateMessage, updateMessage.EmitterForeExists);
_emitterPortTexture.SetPowerState(updateMessage, updateMessage.EmitterPortExists);
}
protected override void FrameUpdate(FrameEventArgs args)
@@ -453,7 +456,7 @@ namespace Content.Client.ParticleAccelerator.UI
var watts = 0;
if (_lastDraw != 0)
{
var val = _drawNoiseGenerator.GetNoise(_time);
var val = _drawNoiseGenerator.GetNoise(_time, 0f);
watts = (int) (_lastDraw + val * 5);
}
@@ -476,7 +479,7 @@ namespace Content.Client.ParticleAccelerator.UI
_baseState = name;
_rsi = cache.GetResource<RSIResource>($"/Textures/Structures/Power/Generation/PA/{name}.rsi").RSI;
AddChild(_base = new TextureRect {Texture = _rsi[$"completed"].Frame0});
AddChild(_base = new TextureRect { Texture = _rsi[$"completed"].Frame0 });
AddChild(_unlit = new TextureRect());
MinSize = _rsi.Size;
}