Power switchable refactor (#20419)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -14,6 +14,7 @@ public sealed partial class GeneratorWindow : FancyWindow
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly ILocalizationManager _loc = default!;
|
||||
|
||||
private readonly SharedPowerSwitchableSystem _switchable;
|
||||
private readonly FuelGeneratorComponent? _component;
|
||||
private PortableGeneratorComponentBuiState? _lastState;
|
||||
|
||||
@@ -24,6 +25,7 @@ public sealed partial class GeneratorWindow : FancyWindow
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_entityManager.TryGetComponent(entity, out _component);
|
||||
_switchable = _entityManager.System<SharedPowerSwitchableSystem>();
|
||||
|
||||
EntityView.SetEntity(entity);
|
||||
TargetPower.IsValid += IsValid;
|
||||
@@ -99,17 +101,16 @@ public sealed partial class GeneratorWindow : FancyWindow
|
||||
StatusLabel.SetOnlyStyleClass("Danger");
|
||||
}
|
||||
|
||||
var canSwitch = _entityManager.TryGetComponent(_entity, out PowerSwitchableGeneratorComponent? switchable);
|
||||
var canSwitch = _entityManager.TryGetComponent(_entity, out PowerSwitchableComponent? switchable);
|
||||
OutputSwitchLabel.Visible = canSwitch;
|
||||
OutputSwitchButton.Visible = canSwitch;
|
||||
|
||||
if (canSwitch)
|
||||
if (switchable != null)
|
||||
{
|
||||
var isHV = switchable!.ActiveOutput == PowerSwitchableGeneratorOutput.HV;
|
||||
OutputSwitchLabel.Text =
|
||||
Loc.GetString(isHV ? "portable-generator-ui-switch-hv" : "portable-generator-ui-switch-mv");
|
||||
OutputSwitchButton.Text =
|
||||
Loc.GetString(isHV ? "portable-generator-ui-switch-to-mv" : "portable-generator-ui-switch-to-hv");
|
||||
var voltage = _switchable.VoltageString(_switchable.GetVoltage(_entity, switchable));
|
||||
OutputSwitchLabel.Text = Loc.GetString("portable-generator-ui-current-output", ("voltage", voltage));
|
||||
var nextVoltage = _switchable.VoltageString(_switchable.GetNextVoltage(_entity, switchable));
|
||||
OutputSwitchButton.Text = Loc.GetString("power-switchable-switch-voltage", ("voltage", nextVoltage));
|
||||
OutputSwitchButton.Disabled = state.On;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user