Power switchable refactor (#20419)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-10-25 13:57:23 +01:00
committed by GitHub
parent 9025ccaa9d
commit b6a8f5e780
11 changed files with 332 additions and 230 deletions

View File

@@ -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;
}