forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request space-wizards#2 from Just-a-Unity-Dev/power-contro…
…l-computer Power control computer
- Loading branch information
Showing
12 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Content.Client/_FTL/PowerControl/PowerControlBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Content.Shared._FTL.PowerControl; | ||
using Content.Shared.Gravity; | ||
using JetBrains.Annotations; | ||
using Robust.Client.GameObjects; | ||
|
||
namespace Content.Client._FTL.PowerControl | ||
{ | ||
[UsedImplicitly] | ||
public sealed class PowerControlBoundUserInterface : BoundUserInterface | ||
{ | ||
private PowerControlWindow? _window; | ||
|
||
public PowerControlBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base (owner, uiKey) {} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_window = new PowerControlWindow(this, Owner); | ||
|
||
_window.OpenCentered(); | ||
_window.OnClose += Close; | ||
} | ||
|
||
public void ToggleApc(EntityUid entity) | ||
{ | ||
SendMessage(new ToggleApcMessage(entity)); | ||
} | ||
|
||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
|
||
var castState = (PowerControlState) state; | ||
Logger.Debug(castState.Areas.Count.ToString()); | ||
_window?.UpdateState(castState); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) | ||
return; | ||
|
||
_window?.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Content.Shared._FTL.PowerControl; | ||
|
||
namespace Content.Client._FTL.PowerControl; | ||
|
||
/// <inheritdoc/> | ||
public sealed class PowerControlSystem : SharedPowerControlSystem | ||
{ | ||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<controls:FancyWindow xmlns="https://spacestation14.io" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
xmlns:style="clr-namespace:Content.Client.Stylesheets" | ||
Resizable="False" | ||
Name="PCComputer" | ||
SetSize="450 350" | ||
MinSize="450 350"> | ||
<BoxContainer Orientation="Vertical" Margin="5 0 5 0"> | ||
<BoxContainer Margin="0 5 10 10" Orientation="Vertical"> | ||
<PanelContainer StyleClasses="LowDivider" /> | ||
<ScrollContainer | ||
Name="ApcContainer" | ||
HorizontalExpand="True" | ||
VerticalExpand="False" | ||
MinSize="400 250" | ||
Margin="5 5 5 5"> | ||
<BoxContainer | ||
Name="Apcs" | ||
Orientation="Vertical" | ||
HorizontalExpand="True" | ||
VerticalExpand="True" | ||
MinSize="400 250" | ||
Margin="25 0 25 0"> | ||
<!-- Products get added here by code --> | ||
</BoxContainer> | ||
</ScrollContainer> | ||
</BoxContainer> | ||
|
||
<!-- Footer --> | ||
<BoxContainer Orientation="Vertical"> | ||
<PanelContainer StyleClasses="LowDivider" /> | ||
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom"> | ||
<Label Text="{Loc 'power-control-computer-flavor-left'}" StyleClasses="WindowFooterText" /> | ||
<Label Text="{Loc 'power-control-computer-flavor-right'}" StyleClasses="WindowFooterText" | ||
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0" /> | ||
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered" | ||
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/> | ||
</BoxContainer> | ||
</BoxContainer> | ||
</BoxContainer> | ||
</controls:FancyWindow> |
42 changes: 42 additions & 0 deletions
42
Content.Client/_FTL/PowerControl/PowerControlWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Content.Shared._FTL.PowerControl; | ||
using Content.Shared.Gravity; | ||
using Content.Shared.Lathe; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow; | ||
|
||
namespace Content.Client._FTL.PowerControl; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class PowerControlWindow : FancyWindow | ||
{ | ||
private readonly ButtonGroup _buttonGroup = new(); | ||
private readonly PowerControlBoundUserInterface _owner; | ||
|
||
public PowerControlWindow(PowerControlBoundUserInterface ui, ClientUserInterfaceComponent component) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
Title = Loc.GetString("power-control-computer-title"); | ||
_owner = ui; | ||
} | ||
|
||
public void UpdateState(PowerControlState state) | ||
{ | ||
Apcs.RemoveAllChildren(); | ||
foreach (var area in state.Areas) | ||
{ | ||
var button = new Button() | ||
{ | ||
Text = Loc.GetString("power-control-computer-button-text", ("enabled", area.Enabled), ("name", area.Name)) | ||
}; | ||
button.OnPressed += args => | ||
{ | ||
_owner.ToggleApc(area.Entity); | ||
}; | ||
Apcs.AddChild(button); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Linq; | ||
using Content.Server.Power.Components; | ||
using Content.Shared._FTL.Areas; | ||
|
||
namespace Content.Server._FTL.Areas; | ||
|
||
public sealed class AreaSystem : SharedAreasSystem | ||
{ | ||
public List<Area> GetAreasOnGrid(EntityUid? gridUid) | ||
{ | ||
var areas = new List<Area>(); | ||
|
||
foreach (var apc in EntityQuery<ApcComponent>()) | ||
{ | ||
var xform = Transform(apc.Owner); | ||
if (xform.GridUid != gridUid) | ||
continue; | ||
var meta = MetaData(apc.Owner); | ||
var area = new Area | ||
{ | ||
Entity = apc.Owner, | ||
Name = meta.EntityName, | ||
Enabled = apc.MainBreakerEnabled | ||
}; | ||
areas.Add(area); | ||
} | ||
|
||
return areas; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Content.Shared._FTL.PowerControl; | ||
|
||
namespace Content.Server._FTL.PowerControl; | ||
|
||
[RegisterComponent] | ||
public sealed class PowerControlComponent : SharedPowerControlComponent | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Content.Server._FTL.Areas; | ||
using Content.Server.Power.Components; | ||
using Content.Server.Power.EntitySystems; | ||
using Content.Server.UserInterface; | ||
using Content.Shared._FTL.PowerControl; | ||
using Robust.Server.GameObjects; | ||
|
||
namespace Content.Server._FTL.PowerControl; | ||
|
||
/// <inheritdoc/> | ||
public sealed class PowerControlSystem : SharedPowerControlSystem | ||
{ | ||
[Dependency] private readonly UserInterfaceSystem _userInterface = default!; | ||
[Dependency] private readonly AreaSystem _areas = default!; | ||
[Dependency] private readonly ApcSystem _apc = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<PowerControlComponent, AfterActivatableUIOpenEvent>(OnToggleInterface); | ||
SubscribeLocalEvent<PowerControlComponent, ToggleApcMessage>(OnApcToggleRequestMessage); | ||
base.Initialize(); | ||
} | ||
|
||
private void OnApcToggleRequestMessage(EntityUid uid, PowerControlComponent component, ToggleApcMessage message) | ||
{ | ||
var apc = message.ApcEntity; | ||
|
||
Logger.Debug(apc.ToString()); | ||
_apc.ApcToggleBreaker(apc); | ||
UpdateUserInterface(uid, component); | ||
} | ||
|
||
private void UpdateUserInterface(EntityUid uid, PowerControlComponent? component = null) | ||
{ | ||
if (!Resolve(uid, ref component)) | ||
return; | ||
|
||
var xform = Transform(uid); | ||
if (xform.GridUid == null) | ||
return; | ||
|
||
var state = new PowerControlState(_areas.GetAreasOnGrid(xform.GridUid)); | ||
_userInterface.TrySetUiState(uid, PowerControlUiKey.Key, state); | ||
} | ||
|
||
private void OnToggleInterface(EntityUid uid, PowerControlComponent component, AfterActivatableUIOpenEvent args) | ||
{ | ||
UpdateUserInterface(uid, component); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._FTL.Areas; | ||
|
||
[Serializable, NetSerializable] | ||
public struct Area | ||
{ | ||
public EntityUid Entity; | ||
public string Name; | ||
public bool Enabled; | ||
} | ||
|
||
public abstract class SharedAreasSystem : EntitySystem | ||
{ | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
Content.Shared/_FTL/PowerControl/SharedPowerControlComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._FTL.PowerControl; | ||
|
||
/// <summary> | ||
/// This is used for... | ||
/// </summary> | ||
public abstract class SharedPowerControlComponent : Component | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Contains network state for SharedPowerControlComponent. | ||
/// </summary> | ||
[Serializable, NetSerializable] | ||
public sealed class SharedPowerControlComponentState : ComponentState | ||
{ | ||
public SharedPowerControlComponentState(SharedPowerControlComponent component) | ||
{ | ||
|
||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Content.Shared/_FTL/PowerControl/SharedPowerControlSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Content.Shared._FTL.Areas; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._FTL.PowerControl; | ||
|
||
/// <summary> | ||
/// Sent to the server to set whether the generator should be on or off | ||
/// </summary> | ||
[Serializable, NetSerializable] | ||
public sealed class ToggleApcMessage : BoundUserInterfaceMessage | ||
{ | ||
public EntityUid ApcEntity; | ||
|
||
public ToggleApcMessage(EntityUid entity) | ||
{ | ||
ApcEntity = entity; | ||
} | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class PowerControlState : BoundUserInterfaceState | ||
{ | ||
public List<Area> Areas; | ||
|
||
public PowerControlState(List<Area> areas) | ||
{ | ||
Areas = areas; | ||
} | ||
} | ||
|
||
[NetSerializable, Serializable] | ||
public enum PowerControlUiKey : byte | ||
{ | ||
Key, | ||
} | ||
|
||
/// <summary> | ||
/// This handles... | ||
/// </summary> | ||
public abstract class SharedPowerControlSystem : EntitySystem | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
power-control-computer-flavor-left = Control power responsibly. | ||
power-control-computer-flavor-right = v0.1 | ||
power-control-computer-title = power control computer | ||
power-control-computer-button-text = | ||
{$name} {$enabled -> | ||
[true] (enabled) | ||
*[false] (disabled) | ||
} |
Oops, something went wrong.