Skip to content

Commit

Permalink
Wage terminal (#504)
Browse files Browse the repository at this point in the history
* Done

* Merge branch 'master' into Wage-Terminal

* Update wage.yml

* make it safety
  • Loading branch information
KayzelW authored Mar 6, 2024
1 parent c1cc43d commit 4264c55
Show file tree
Hide file tree
Showing 22 changed files with 810 additions and 36 deletions.
42 changes: 42 additions & 0 deletions Content.Client/Backmen/Economy/WageConsole/UI/BonusWageWindow.cs
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);
}
}
}
23 changes: 23 additions & 0 deletions Content.Client/Backmen/Economy/WageConsole/UI/BonusWageWindow.xaml
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>
43 changes: 43 additions & 0 deletions Content.Client/Backmen/Economy/WageConsole/UI/EditWageRowWindow.cs
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();
}
}
77 changes: 77 additions & 0 deletions Content.Client/Backmen/Economy/WageConsole/UI/WageConsoleWindow.cs
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

0 comments on commit 4264c55

Please sign in to comment.