Disposals UI to XAML (#4623)
* DisposalUnitWindow to XAML * DisposalTaggerWindow to XAML * Remove unused imports * DisposalRouterWindow to XAML * Fix localization
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Disposal.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedDisposalRouterComponent"/>
|
||||
/// </summary>
|
||||
public class DisposalRouterWindow : SS14Window
|
||||
{
|
||||
public readonly LineEdit TagInput;
|
||||
public readonly Button Confirm;
|
||||
|
||||
public DisposalRouterWindow()
|
||||
{
|
||||
MinSize = SetSize = (500, 110);
|
||||
Title = Loc.GetString("disposal-router-window-title");
|
||||
|
||||
Contents.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
new Label {Text = Loc.GetString("disposal-router-window-tags-label")},
|
||||
new Control {MinSize = (0, 10)},
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
(TagInput = new LineEdit
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
MinSize = (320, 0),
|
||||
ToolTip = Loc.GetString("disposal-router-window-tag-input-tooltip"),
|
||||
IsValid = tags => TagRegex.IsMatch(tags)
|
||||
}),
|
||||
new Control {MinSize = (10, 0)},
|
||||
(Confirm = new Button {Text = Loc.GetString("disposal-router-window-tag-input-confirm-button")})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void UpdateState(DisposalRouterUserInterfaceState state)
|
||||
{
|
||||
TagInput.Text = state.Tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Content.Client/Disposal/UI/DisposalRouterWindow.xaml
Normal file
18
Content.Client/Disposal/UI/DisposalRouterWindow.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'disposal-router-window-title'}"
|
||||
MinSize="500 110"
|
||||
SetSize="500 110">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Text="{Loc 'disposal-router-window-tags-label'}" />
|
||||
<Control MinSize="0 10" />
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<LineEdit Name="TagInputProtected"
|
||||
HorizontalExpand="True"
|
||||
MinSize="320 0"
|
||||
ToolTip="{Loc 'disposal-router-window-tag-input-tooltip'}" />
|
||||
<Control MinSize="10 0" />
|
||||
<Button Name="ConfirmProtected"
|
||||
Text="{Loc 'disposal-router-window-tag-input-confirm-button'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
32
Content.Client/Disposal/UI/DisposalRouterWindow.xaml.cs
Normal file
32
Content.Client/Disposal/UI/DisposalRouterWindow.xaml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
|
||||
|
||||
namespace Content.Client.Disposal.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedDisposalRouterComponent"/>
|
||||
/// </summary>
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class DisposalRouterWindow : SS14Window
|
||||
{
|
||||
public LineEdit TagInput => TagInputProtected;
|
||||
public Button Confirm => ConfirmProtected;
|
||||
|
||||
public DisposalRouterWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
TagInput.IsValid = tags => TagRegex.IsMatch(tags);
|
||||
}
|
||||
|
||||
|
||||
public void UpdateState(DisposalRouterUserInterfaceState state)
|
||||
{
|
||||
TagInput.Text = state.Tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Disposal.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedDisposalTaggerComponent"/>
|
||||
/// </summary>
|
||||
public class DisposalTaggerWindow : SS14Window
|
||||
{
|
||||
public readonly LineEdit TagInput;
|
||||
public readonly Button Confirm;
|
||||
|
||||
public DisposalTaggerWindow()
|
||||
{
|
||||
MinSize = SetSize = (500, 110);
|
||||
Title = Loc.GetString("disposal-tagger-window-title");
|
||||
|
||||
Contents.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
new Label {Text = Loc.GetString("disposal-tagger-window-tag-input-label")},
|
||||
new Control {MinSize = (0, 10)},
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
(TagInput = new LineEdit
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
MinSize = (320, 0),
|
||||
IsValid = tag => TagRegex.IsMatch(tag)
|
||||
}),
|
||||
new Control {MinSize = (10, 0)},
|
||||
(Confirm = new Button {Text = Loc.GetString("disposal-tagger-window-tag-confirm-button")})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void UpdateState(DisposalTaggerUserInterfaceState state)
|
||||
{
|
||||
TagInput.Text = state.Tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Content.Client/Disposal/UI/DisposalTaggerWindow.xaml
Normal file
17
Content.Client/Disposal/UI/DisposalTaggerWindow.xaml
Normal file
@@ -0,0 +1,17 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'disposal-tagger-window-title'}"
|
||||
MinSize="500 110"
|
||||
SetSize="500 110">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Text="{Loc 'disposal-tagger-window-tag-input-label'}" />
|
||||
<Control MinSize="0 10" />
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<LineEdit Name="TagInputProtected"
|
||||
HorizontalExpand="True"
|
||||
MinSize="320 0" />
|
||||
<Control MinSize="10 0" />
|
||||
<Button Name="ConfirmProtected"
|
||||
Text="{Loc 'disposal-tagger-window-tag-confirm-button'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
32
Content.Client/Disposal/UI/DisposalTaggerWindow.xaml.cs
Normal file
32
Content.Client/Disposal/UI/DisposalTaggerWindow.xaml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent;
|
||||
|
||||
namespace Content.Client.Disposal.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedDisposalTaggerComponent"/>
|
||||
/// </summary>
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class DisposalTaggerWindow : SS14Window
|
||||
{
|
||||
public LineEdit TagInput => TagInputProtected;
|
||||
public Button Confirm => ConfirmProtected;
|
||||
|
||||
public DisposalTaggerWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
TagInput.IsValid = tag => TagRegex.IsMatch(tag);
|
||||
}
|
||||
|
||||
|
||||
public void UpdateState(DisposalTaggerUserInterfaceState state)
|
||||
{
|
||||
TagInput.Text = state.Tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
using System;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Disposal;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using static Content.Shared.Disposal.Components.SharedDisposalUnitComponent;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Disposal.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedDisposalUnitComponent"/>
|
||||
/// </summary>
|
||||
public class DisposalUnitWindow : SS14Window
|
||||
{
|
||||
private readonly Label _unitState;
|
||||
private readonly ProgressBar _pressureBar;
|
||||
public readonly Button Engage;
|
||||
public readonly Button Eject;
|
||||
public readonly Button Power;
|
||||
|
||||
public DisposalUnitWindow()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
MinSize = SetSize = (300, 140);
|
||||
Resizable = false;
|
||||
Contents.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 4,
|
||||
Children =
|
||||
{
|
||||
new Label {Text = Loc.GetString("ui-disposal-unit-label-state")},
|
||||
(_unitState = new Label {Text = Loc.GetString("ui-disposal-unit-label-status")})
|
||||
}
|
||||
},
|
||||
new Control {MinSize = (0, 5)},
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 4,
|
||||
Children =
|
||||
{
|
||||
new Label {Text = Loc.GetString("ui-disposal-unit-label-pressure")},
|
||||
(_pressureBar = new ProgressBar
|
||||
{
|
||||
MinSize = (190, 20),
|
||||
HorizontalAlignment = HAlignment.Right,
|
||||
MinValue = 0,
|
||||
MaxValue = 1,
|
||||
Page = 0,
|
||||
Value = 0.5f
|
||||
})
|
||||
}
|
||||
},
|
||||
new Control {MinSize = (0, 10)},
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
(Engage = new Button
|
||||
{
|
||||
Text = Loc.GetString("ui-disposal-unit-button-flush"),
|
||||
StyleClasses = {StyleBase.ButtonOpenRight},
|
||||
ToggleMode = true
|
||||
}),
|
||||
|
||||
(Eject = new Button
|
||||
{
|
||||
Text = Loc.GetString("ui-disposal-unit-button-eject"),
|
||||
StyleClasses = {StyleBase.ButtonOpenBoth}
|
||||
}),
|
||||
|
||||
(Power = new CheckButton
|
||||
{
|
||||
Text = Loc.GetString("ui-disposal-unit-button-power"),
|
||||
StyleClasses = {StyleBase.ButtonOpenLeft}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdatePressureBar(float pressure)
|
||||
{
|
||||
_pressureBar.Value = pressure;
|
||||
|
||||
var normalized = pressure / _pressureBar.MaxValue;
|
||||
|
||||
const float leftHue = 0.0f; // Red
|
||||
const float middleHue = 0.066f; // Orange
|
||||
const float rightHue = 0.33f; // Green
|
||||
const float saturation = 1.0f; // Uniform saturation
|
||||
const float value = 0.8f; // Uniform value / brightness
|
||||
const float alpha = 1.0f; // Uniform alpha
|
||||
|
||||
// These should add up to 1.0 or your transition won't be smooth
|
||||
const float leftSideSize = 0.5f; // Fraction of _chargeBar lerped from leftHue to middleHue
|
||||
const float rightSideSize = 0.5f; // Fraction of _chargeBar lerped from middleHue to rightHue
|
||||
|
||||
float finalHue;
|
||||
if (normalized <= leftSideSize)
|
||||
{
|
||||
normalized /= leftSideSize; // Adjust range to 0.0 to 1.0
|
||||
finalHue = MathHelper.Lerp(leftHue, middleHue, normalized);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalized = (normalized - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0.
|
||||
finalHue = MathHelper.Lerp(middleHue, rightHue, normalized);
|
||||
}
|
||||
|
||||
// Check if null first to avoid repeatedly creating this.
|
||||
_pressureBar.ForegroundStyleBoxOverride ??= new StyleBoxFlat();
|
||||
|
||||
var foregroundStyleBoxOverride = (StyleBoxFlat) _pressureBar.ForegroundStyleBoxOverride;
|
||||
foregroundStyleBoxOverride.BackgroundColor =
|
||||
Color.FromHsv(new Vector4(finalHue, saturation, value, alpha));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the interface state for the disposals window.
|
||||
/// </summary>
|
||||
/// <returns>true if we should stop updating every frame.</returns>
|
||||
public bool UpdateState(DisposalUnitBoundUserInterfaceState state)
|
||||
{
|
||||
var currentTime = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
var fullTime = state.FullPressureTime;
|
||||
var pressure = (float) Math.Min(1.0f, 1.0f - (fullTime.TotalSeconds - currentTime.TotalSeconds) * SharedDisposalUnitSystem.PressurePerSecond);
|
||||
|
||||
Title = state.UnitName;
|
||||
_unitState.Text = state.UnitState;
|
||||
UpdatePressureBar(pressure);
|
||||
Power.Pressed = state.Powered;
|
||||
Engage.Pressed = state.Engaged;
|
||||
|
||||
return !state.Powered || pressure >= 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Content.Client/Disposal/UI/DisposalUnitWindow.xaml
Normal file
38
Content.Client/Disposal/UI/DisposalUnitWindow.xaml
Normal file
@@ -0,0 +1,38 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
MinSize="300 140"
|
||||
SetSize="300 140"
|
||||
Resizable="False">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
SeparationOverride="4">
|
||||
<Label Text="{Loc 'ui-disposal-unit-label-state'}" />
|
||||
<Label Name="UnitState"
|
||||
Text="{Loc 'ui-disposal-unit-label-status'}" />
|
||||
</BoxContainer>
|
||||
<Control MinSize="0 5" />
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
SeparationOverride="4">
|
||||
<Label Text="{Loc 'ui-disposal-unit-label-pressure'}" />
|
||||
<ProgressBar Name="PressureBar"
|
||||
MinSize="190 20"
|
||||
HorizontalAlignment="Right"
|
||||
MinValue="0"
|
||||
MaxValue="1"
|
||||
Page="0"
|
||||
Value="0.5" />
|
||||
</BoxContainer>
|
||||
<Control MinSize="0 10" />
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Button Name="EngageProtected"
|
||||
Text="{Loc 'ui-disposal-unit-button-flush'}"
|
||||
StyleClasses="OpenRight"
|
||||
ToggleMode="True" />
|
||||
<Button Name="EjectProtected"
|
||||
Text="{Loc 'ui-disposal-unit-button-eject'}"
|
||||
StyleClasses="OpenBoth" />
|
||||
<CheckButton Name="PowerProtected"
|
||||
Text="{Loc 'ui-disposal-unit-button-power'}"
|
||||
StyleClasses="OpenLeft" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
88
Content.Client/Disposal/UI/DisposalUnitWindow.xaml.cs
Normal file
88
Content.Client/Disposal/UI/DisposalUnitWindow.xaml.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using Content.Shared.Disposal;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using static Content.Shared.Disposal.Components.SharedDisposalUnitComponent;
|
||||
|
||||
namespace Content.Client.Disposal.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side UI used to control a <see cref="SharedDisposalUnitComponent"/>
|
||||
/// </summary>
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class DisposalUnitWindow : SS14Window
|
||||
{
|
||||
public Button Engage => EngageProtected;
|
||||
public Button Eject => EjectProtected;
|
||||
public Button Power => PowerProtected;
|
||||
|
||||
public DisposalUnitWindow()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void UpdatePressureBar(float pressure)
|
||||
{
|
||||
PressureBar.Value = pressure;
|
||||
|
||||
var normalized = pressure / PressureBar.MaxValue;
|
||||
|
||||
const float leftHue = 0.0f; // Red
|
||||
const float middleHue = 0.066f; // Orange
|
||||
const float rightHue = 0.33f; // Green
|
||||
const float saturation = 1.0f; // Uniform saturation
|
||||
const float value = 0.8f; // Uniform value / brightness
|
||||
const float alpha = 1.0f; // Uniform alpha
|
||||
|
||||
// These should add up to 1.0 or your transition won't be smooth
|
||||
const float leftSideSize = 0.5f; // Fraction of _chargeBar lerped from leftHue to middleHue
|
||||
const float rightSideSize = 0.5f; // Fraction of _chargeBar lerped from middleHue to rightHue
|
||||
|
||||
float finalHue;
|
||||
if (normalized <= leftSideSize)
|
||||
{
|
||||
normalized /= leftSideSize; // Adjust range to 0.0 to 1.0
|
||||
finalHue = MathHelper.Lerp(leftHue, middleHue, normalized);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalized = (normalized - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0.
|
||||
finalHue = MathHelper.Lerp(middleHue, rightHue, normalized);
|
||||
}
|
||||
|
||||
// Check if null first to avoid repeatedly creating this.
|
||||
PressureBar.ForegroundStyleBoxOverride ??= new StyleBoxFlat();
|
||||
|
||||
var foregroundStyleBoxOverride = (StyleBoxFlat) PressureBar.ForegroundStyleBoxOverride;
|
||||
foregroundStyleBoxOverride.BackgroundColor =
|
||||
Color.FromHsv(new Vector4(finalHue, saturation, value, alpha));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the interface state for the disposals window.
|
||||
/// </summary>
|
||||
/// <returns>true if we should stop updating every frame.</returns>
|
||||
public bool UpdateState(DisposalUnitBoundUserInterfaceState state)
|
||||
{
|
||||
var currentTime = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
var fullTime = state.FullPressureTime;
|
||||
var pressure = (float) Math.Min(1.0f, 1.0f - (fullTime.TotalSeconds - currentTime.TotalSeconds) * SharedDisposalUnitSystem.PressurePerSecond);
|
||||
|
||||
Title = state.UnitName;
|
||||
UnitState.Text = state.UnitState;
|
||||
UpdatePressureBar(pressure);
|
||||
Power.Pressed = state.Powered;
|
||||
Engage.Pressed = state.Engaged;
|
||||
|
||||
return !state.Powered || pressure >= 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user