Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wage terminal #504

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Backmen.Economy.WageConsole;
using Content.Shared.Backmen.Reinforcement;
using Content.Shared.FixedPoint;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Backmen.Economy.WageConsole.UI;

[GenerateTypedNameReferences]
public sealed partial class BonusWageWindow : FancyWindow
{
public event Action<uint, FixedPoint2> OnBonusWageRow = (u, point2) => { };
public UpdateWageRow State { get; set; }

public BonusWageWindow(OpenBonusWageConsoleUi state)
{
RobustXamlLoader.Load(this);
if (state.Row is null)
{
Close();
State = default!;
return;
}
State = state.Row;

ToName.Text = Loc.GetString("wageconsole-row", ("name", State.ToName), ("account", State.ToAccount));
Wage.Text = State.Wage.ToString();
DoneBtn.OnPressed += BonusBtnOnOnPressed;

OpenCentered();
}

private void BonusBtnOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (Double.TryParse(Wage.Text, out var wage))
{
OnBonusWageRow.Invoke(State.Id, wage);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:ui="clr-namespace:Content.Client.Backmen.Reinforcement.UI"
MinWidth="450" MinHeight="200" Title="{Loc wageconsole-bonus-title}">
<BoxContainer Orientation="Vertical">
<!-- Data -->
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<Label Name="ToName"
Access="Public"
HorizontalExpand="True" />
<LineEdit Name="Wage"
Access="Public"
HorizontalExpand="True" />
<Button Name="DoneBtn"
Access="Public"
ToolTip=""
Text="{Loc wageconsole-done}"
StyleClasses="LabelSubText"/>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Backmen.Economy.WageConsole;
using Content.Shared.Backmen.Reinforcement;
using Content.Shared.FixedPoint;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Backmen.Economy.WageConsole.UI;

[GenerateTypedNameReferences]
public sealed partial class EditWageRowWindow : FancyWindow
{
public event Action<uint, FixedPoint2> OnSaveEditedWageRow = (u, point2) => { };
public UpdateWageRow State { get; set; }

public EditWageRowWindow(OpenEditWageConsoleUi state)
{
RobustXamlLoader.Load(this);
if (state.Row is null)
{
Close();
State = default!;
return;
}
State = state.Row;

FromName.Text = Loc.GetString("wageconsole-row", ("name", State.FromName), ("account", State.FromAccount));
ToName.Text = Loc.GetString("wageconsole-row", ("name", State.ToName), ("account", State.ToAccount));
Wage.Text = State.Wage.ToString();
SaveBtn.OnPressed += SaveBtnOnOnPressed;

OpenCentered();
}

private void SaveBtnOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (Double.TryParse(Wage.Text, out var wage))
{
OnSaveEditedWageRow.Invoke(State.Id, wage);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:ui="clr-namespace:Content.Client.Backmen.Reinforcement.UI"
MinWidth="450" MinHeight="200" Title="{Loc wageconsole-edit-title}">
<BoxContainer Orientation="Vertical">
<!-- Main display -->
<BoxContainer Orientation="Horizontal" VerticalExpand="True" HorizontalExpand="True">
<!-- Station name -->
<controls:StripeBack>
<PanelContainer>
<RichTextLabel Name="StationName" HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0 5 0 3" />
</PanelContainer>
</controls:StripeBack>
</BoxContainer>
<!-- Data -->
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<Label Name="FromName"
Access="Public"
MinSize="32 32"/>
<Label Name="ToName"
Access="Public"
HorizontalExpand="True" />
<LineEdit Name="Wage"
Access="Public"
HorizontalExpand="True" />
<Button Name="SaveBtn"
Access="Public"
ToolTip=""
Text="{Loc wageconsole-save}"
StyleClasses="LabelSubText"/>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Content.Shared.Backmen.Economy.WageConsole;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;

namespace Content.Client.Backmen.Economy.WageConsole.UI;

[UsedImplicitly]
public sealed class WageConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _proto = default!;

private WageConsoleWindow? _window;
private EditWageRowWindow? _editWindow;
private BonusWageWindow? _bonusWageWindow;

public WageConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

var comp = EntMan.GetComponent<WageConsoleComponent>(Owner);

var stationName = "";
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform) && xform.GridUid != null &&
EntMan.TryGetComponent<MetaDataComponent>(xform.GridUid, out var stationData))
{
stationName = stationData.EntityName;
}

_window = new(Owner, comp, _proto, stationName);
// _window.OnKeySelected += (key, count) => SendMessage(new ChangeReinforcementMsg(key, count));
// _window.OnBriefChange += (brief) =>
// SendMessage(new WageUpdate(brief[..Math.Min(brief.Length, comp.MaxStringLength)]));
// _window.OnStartCall += () => SendMessage(new CallReinforcementStart());

_window.OnWageRowEdit += (u) => { SendMessage(new OpenWageRowMsg(u)); };
_window.OnBonusWage += (u) => { SendMessage(new OpenBonusWageMsg(u)); };

_window.OnClose += Close;
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is UpdateWageConsoleUi s)
{
if (_editWindow != null || _bonusWageWindow != null)
{
_editWindow?.Close();
_editWindow = null;
_bonusWageWindow?.Close();
_bonusWageWindow = null;
}

_window?.Update(s);
}

if (state is OpenEditWageConsoleUi e)
{
if (_editWindow != null)
{
_editWindow.Close();
_bonusWageWindow?.Close();
}

_editWindow = new EditWageRowWindow(e);
_editWindow.OnSaveEditedWageRow += (u, point2) => { SendMessage(new SaveEditedWageRowMsg(u, point2)); };
}

if (state is OpenBonusWageConsoleUi b)
{
if (_bonusWageWindow != null)
{
_editWindow?.Close();
_bonusWageWindow.Close();
_bonusWageWindow = null;
}

_bonusWageWindow = new BonusWageWindow(b);
_bonusWageWindow.OnBonusWageRow += (u, point2) =>
{
SendMessage(new BonusWageRowMsg(u, point2));
_bonusWageWindow.Close();
};
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

_window?.Close();
_editWindow?.Close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Backmen.Economy.WageConsole;
using Content.Shared.FixedPoint;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Client.Backmen.Economy.WageConsole.UI;

[GenerateTypedNameReferences]
public sealed partial class WageConsoleWindow : FancyWindow
{
private readonly EntityUid _owner;
private readonly WageConsoleComponent _comp;
private readonly IPrototypeManager _proto;
private readonly string _stationName;

public event Action<uint> OnWageRowEdit = u => { };
public event Action<uint> OnBonusWage = u => { };

public void Update(UpdateWageConsoleUi updateWageConsoleUi)
{
SourcesList.RemoveAllChildren();
foreach (var row in updateWageConsoleUi.Records)
{
var wageRow = new WageRow()
{
Id = row.Id
};
wageRow.FromName.Text = Loc.GetString("wageconsole-row", ("name", row.FromName), ("account", row.FromAccount));
wageRow.ToName.Text = Loc.GetString("wageconsole-row", ("name", row.ToName), ("account", row.ToAccount));
wageRow.Wage.Text = row.Wage.ToString();
wageRow.EditBtn.OnPressed += EditBtnOnOnPressed;
wageRow.BonusBtn.OnPressed += BonusBtnOnOnPressed;

SourcesList.Children.Add(wageRow);
}
}

private void BonusBtnOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (obj.Button.Parent?.Parent?.Parent is not WageRow row)
{
return;
}

OnBonusWage.Invoke(row.Id);
}

private void EditBtnOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (obj.Button.Parent?.Parent?.Parent is not WageRow row)
{
return;
}

OnWageRowEdit.Invoke(row.Id);
}

public WageConsoleWindow(EntityUid owner, WageConsoleComponent comp, IPrototypeManager proto, string stationName)
{
_owner = owner;
_comp = comp;
_proto = proto;
_stationName = stationName;

RobustXamlLoader.Load(this);

var msg = new FormattedMessage();
msg.AddText(stationName);
StationName.SetMessage(msg);

OpenCentered();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:ui="clr-namespace:Content.Client.Backmen.Reinforcement.UI"
MinWidth="600" MinHeight="350" Title="{Loc wageconsole-title}">
<BoxContainer Orientation="Vertical" HorizontalAlignment="Stretch">
<!-- Station name -->
<controls:StripeBack HorizontalAlignment="Stretch">
<PanelContainer>
<RichTextLabel Name="StationName" HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0 5 0 3" />
</PanelContainer>
</controls:StripeBack>
<!-- Main display -->
<BoxContainer Orientation="Horizontal" VerticalExpand="True" HorizontalExpand="True">

</BoxContainer>
<!-- Data -->
<ScrollContainer HorizontalExpand="True" VerticalExpand="True" SizeFlagsStretchRatio="6">
<BoxContainer Name="SourcesList" Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True" />
</ScrollContainer>
</BoxContainer>
</controls:FancyWindow>
17 changes: 17 additions & 0 deletions Content.Client/Backmen/Economy/WageConsole/UI/WageRow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Backmen.Reinforcement;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Backmen.Economy.WageConsole.UI;

[GenerateTypedNameReferences]
public sealed partial class WageRow : PanelContainer
{
public uint Id { get; set; }

public WageRow()
{
RobustXamlLoader.Load(this);
}
}
Loading
Loading