adds bantime buttons to ban panel (#5856)
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
<Label Text="{Loc Minutes}" MinWidth="100" />
|
||||
<Control MinWidth="50" />
|
||||
<LineEdit Name="MinutesLine" MinWidth="100" HorizontalExpand="True" PlaceHolder="{Loc 0 minutes for a permanent ban}" />
|
||||
<Button Name="HourButton" Text="+1h (0)"/>
|
||||
<Button Name="DayButton" Text="+1d (0)"/>
|
||||
<Button Name="WeekButton" Text="+1w (0)"/>
|
||||
<Button Name="MonthButton" Text="+1M (0)"/>
|
||||
</BoxContainer>
|
||||
<cc:PlayerListControl Name="PlayerList" VerticalExpand="True" />
|
||||
<Control MinWidth="50" />
|
||||
|
||||
@@ -4,6 +4,7 @@ using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.UserInterface.Controls.LineEdit;
|
||||
@@ -14,11 +15,72 @@ namespace Content.Client.Administration.UI.Tabs.AdminTab
|
||||
[UsedImplicitly]
|
||||
public partial class BanWindow : SS14Window
|
||||
{
|
||||
protected override void EnteredTree()
|
||||
public BanWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
PlayerNameLine.OnTextChanged += PlayerNameLineOnOnTextChanged;
|
||||
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
||||
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
|
||||
MinutesLine.OnTextChanged += UpdateButtonsText;
|
||||
HourButton.OnPressed += OnHourButtonPressed;
|
||||
DayButton.OnPressed += OnDayButtonPressed;
|
||||
WeekButton.OnPressed += OnWeekButtonPressed;
|
||||
MonthButton.OnPressed += OnMonthButtonPressed;
|
||||
}
|
||||
|
||||
private bool TryGetMinutes(string str, out uint minutes)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
minutes = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return uint.TryParse(str, out minutes);
|
||||
}
|
||||
|
||||
private void OnHourButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
AddMinutes(60);
|
||||
}
|
||||
|
||||
private void OnDayButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
AddMinutes(1440);
|
||||
}
|
||||
|
||||
private void OnWeekButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
AddMinutes(10080);
|
||||
}
|
||||
|
||||
private void OnMonthButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
AddMinutes(43200);
|
||||
}
|
||||
|
||||
private void AddMinutes(uint add)
|
||||
{
|
||||
if (!TryGetMinutes(MinutesLine.Text, out var minutes))
|
||||
return;
|
||||
|
||||
MinutesLine.Text = $"{minutes + add}";
|
||||
UpdateButtons(minutes+add);
|
||||
}
|
||||
|
||||
private void UpdateButtonsText(LineEditEventArgs obj)
|
||||
{
|
||||
if (!TryGetMinutes(obj.Text, out var minutes))
|
||||
return;
|
||||
UpdateButtons(minutes);
|
||||
}
|
||||
|
||||
private void UpdateButtons(uint minutes)
|
||||
{
|
||||
HourButton.Text = $"+1h ({minutes / 60})";
|
||||
DayButton.Text = $"+1d ({minutes / 1440})";
|
||||
WeekButton.Text = $"+1w ({minutes / 10080})";
|
||||
MonthButton.Text = $"+1M ({minutes / 43200})";
|
||||
}
|
||||
|
||||
private void OnPlayerNameChanged()
|
||||
|
||||
Reference in New Issue
Block a user