Re-organize all projects (#4166)
This commit is contained in:
40
Content.Client/Voting/UI/VoteCallMenu.xaml
Normal file
40
Content.Client/Voting/UI/VoteCallMenu.xaml
Normal file
@@ -0,0 +1,40 @@
|
||||
<ui:VoteCallMenu xmlns="https://spacestation14.io"
|
||||
xmlns:v="clr-namespace:Content.Client.Voting"
|
||||
xmlns:ui="clr-namespace:Content.Client.Voting.UI"
|
||||
xmlns:ui1="clr-namespace:Content.Client.HUD.UI"
|
||||
MouseFilter="Stop" MinSize="350 150">
|
||||
<PanelContainer StyleClasses="AngleRect" />
|
||||
<VBoxContainer>
|
||||
<HBoxContainer>
|
||||
<MarginContainer MarginLeftOverride="8" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'ui-vote-create-title'}" VAlign="Center" StyleClasses="LabelHeading" />
|
||||
</MarginContainer>
|
||||
<MarginContainer MarginRightOverride="8">
|
||||
<TextureButton Name="CloseButton" StyleClasses="windowCloseButton"
|
||||
SizeFlagsVertical="ShrinkCenter" />
|
||||
</MarginContainer>
|
||||
</HBoxContainer>
|
||||
<ui1:HighDivider />
|
||||
|
||||
<MarginContainer SizeFlagsHorizontal="Fill" SizeFlagsVertical="Expand"
|
||||
MarginLeftOverride="8" MarginRightOverride="8" MarginTopOverride="2">
|
||||
<HBoxContainer>
|
||||
<OptionButton Name="VoteTypeButton" HorizontalExpand="True" />
|
||||
<Control HorizontalExpand="True">
|
||||
<OptionButton Name="VoteSecondButton" Visible="False" />
|
||||
</Control>
|
||||
</HBoxContainer>
|
||||
</MarginContainer>
|
||||
|
||||
<MarginContainer SizeFlagsHorizontal="Fill"
|
||||
MarginLeftOverride="8" MarginRightOverride="8" MarginBottomOverride="2">
|
||||
<Button Name="CreateButton" Text="{Loc 'ui-vote-create-button'}" />
|
||||
</MarginContainer>
|
||||
|
||||
<PanelContainer StyleClasses="LowDivider" />
|
||||
<MarginContainer MarginLeftOverride="12">
|
||||
<Label StyleClasses="LabelSubText" Text="{Loc 'ui-vote-fluff'}" />
|
||||
</MarginContainer>
|
||||
|
||||
</VBoxContainer>
|
||||
</ui:VoteCallMenu>
|
||||
111
Content.Client/Voting/UI/VoteCallMenu.xaml.cs
Normal file
111
Content.Client/Voting/UI/VoteCallMenu.xaml.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
#nullable enable
|
||||
using Content.Client.Stylesheets;
|
||||
using JetBrains.Annotations;
|
||||
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.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.Voting.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class VoteCallMenu : BaseWindow
|
||||
{
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
|
||||
public static readonly (string name, string id, (string name, string id)[]? secondaries)[] AvailableVoteTypes =
|
||||
{
|
||||
("ui-vote-type-restart", "restart", null),
|
||||
("ui-vote-type-gamemode", "preset", null)
|
||||
};
|
||||
|
||||
public VoteCallMenu()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Stylesheet = IoCManager.Resolve<IStylesheetManager>().SheetSpace;
|
||||
CloseButton.OnPressed += _ => Close();
|
||||
|
||||
for (var i = 0; i < AvailableVoteTypes.Length; i++)
|
||||
{
|
||||
var (text, _, _) = AvailableVoteTypes[i];
|
||||
VoteTypeButton.AddItem(Loc.GetString(text), i);
|
||||
}
|
||||
|
||||
VoteTypeButton.OnItemSelected += VoteTypeSelected;
|
||||
VoteSecondButton.OnItemSelected += VoteSecondSelected;
|
||||
CreateButton.OnPressed += CreatePressed;
|
||||
}
|
||||
|
||||
private void CreatePressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var typeId = VoteTypeButton.SelectedId;
|
||||
var (_, typeKey, secondaries) = AvailableVoteTypes[typeId];
|
||||
|
||||
if (secondaries != null)
|
||||
{
|
||||
var secondaryId = VoteSecondButton.SelectedId;
|
||||
var (_, secondKey) = secondaries[secondaryId];
|
||||
|
||||
_consoleHost.LocalShell.RemoteExecuteCommand($"createvote {typeKey} {secondKey}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_consoleHost.LocalShell.RemoteExecuteCommand($"createvote {typeKey}");
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private static void VoteSecondSelected(OptionButton.ItemSelectedEventArgs obj)
|
||||
{
|
||||
obj.Button.SelectId(obj.Id);
|
||||
}
|
||||
|
||||
private void VoteTypeSelected(OptionButton.ItemSelectedEventArgs obj)
|
||||
{
|
||||
VoteTypeButton.SelectId(obj.Id);
|
||||
|
||||
var (_, _, options) = AvailableVoteTypes[obj.Id];
|
||||
if (options == null)
|
||||
{
|
||||
VoteSecondButton.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
VoteSecondButton.Visible = true;
|
||||
VoteSecondButton.Clear();
|
||||
|
||||
for (var i = 0; i < options.Length; i++)
|
||||
{
|
||||
var (text, _) = options[i];
|
||||
VoteSecondButton.AddItem(Loc.GetString(text), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
|
||||
{
|
||||
return DragMode.Move;
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class VoteMenuCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "votemenu";
|
||||
public string Description => "Opens the voting menu";
|
||||
public string Help => "Usage: votemenu";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
new VoteCallMenu().OpenCentered();
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Content.Client/Voting/UI/VoteCallMenuButton.cs
Normal file
49
Content.Client/Voting/UI/VoteCallMenuButton.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Voting.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// LITERALLY just a button that opens the vote call menu.
|
||||
/// Automatically disables itself if the client cannot call votes.
|
||||
/// </summary>
|
||||
public sealed class VoteCallMenuButton : Button
|
||||
{
|
||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||
|
||||
public VoteCallMenuButton()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Text = Loc.GetString("ui-vote-menu-button");
|
||||
OnPressed += OnOnPressed;
|
||||
}
|
||||
|
||||
private void OnOnPressed(ButtonEventArgs obj)
|
||||
{
|
||||
var menu = new VoteCallMenu();
|
||||
menu.OpenCentered();
|
||||
}
|
||||
|
||||
protected override void EnteredTree()
|
||||
{
|
||||
base.EnteredTree();
|
||||
|
||||
UpdateCanCall(_voteManager.CanCallVote);
|
||||
_voteManager.CanCallVoteChanged += UpdateCanCall;
|
||||
}
|
||||
|
||||
protected override void ExitedTree()
|
||||
{
|
||||
base.ExitedTree();
|
||||
|
||||
_voteManager.CanCallVoteChanged += UpdateCanCall;
|
||||
}
|
||||
|
||||
private void UpdateCanCall(bool canCall)
|
||||
{
|
||||
Disabled = !canCall;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Content.Client/Voting/UI/VotePopup.xaml
Normal file
18
Content.Client/Voting/UI/VotePopup.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<Control xmlns="https://spacestation14.io">
|
||||
<PanelContainer StyleClasses="AngleRect" />
|
||||
<MarginContainer MarginLeftOverride="4" MarginRightOverride="4" MarginTopOverride="4" MarginBottomOverride="4">
|
||||
<VBoxContainer>
|
||||
<Label Name="VoteCaller" />
|
||||
<Label Name="VoteTitle" />
|
||||
|
||||
<GridContainer Columns="3" Name="VoteOptionsContainer" />
|
||||
<HBoxContainer>
|
||||
<MarginContainer HorizontalExpand="True" MarginLeftOverride="2" MarginRightOverride="2"
|
||||
MarginTopOverride="2" MarginBottomOverride="2">
|
||||
<ProgressBar Name="TimeLeftBar" MinValue="0" MaxValue="1" />
|
||||
</MarginContainer>
|
||||
<Label Name="TimeLeftText" />
|
||||
</HBoxContainer>
|
||||
</VBoxContainer>
|
||||
</MarginContainer>
|
||||
</Control>
|
||||
82
Content.Client/Voting/UI/VotePopup.xaml.cs
Normal file
82
Content.Client/Voting/UI/VotePopup.xaml.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using Content.Client.Stylesheets;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Voting.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class VotePopup : Control
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||
|
||||
private readonly VoteManager.ActiveVote _vote;
|
||||
private readonly Button[] _voteButtons;
|
||||
|
||||
public VotePopup(VoteManager.ActiveVote vote)
|
||||
{
|
||||
_vote = vote;
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Stylesheet = IoCManager.Resolve<IStylesheetManager>().SheetSpace;
|
||||
|
||||
Modulate = Color.White.WithAlpha(0.75f);
|
||||
_voteButtons = new Button[vote.Entries.Length];
|
||||
var group = new ButtonGroup();
|
||||
|
||||
for (var i = 0; i < _voteButtons.Length; i++)
|
||||
{
|
||||
var button = new Button
|
||||
{
|
||||
ToggleMode = true,
|
||||
Group = group
|
||||
};
|
||||
_voteButtons[i] = button;
|
||||
VoteOptionsContainer.AddChild(button);
|
||||
var i1 = i;
|
||||
button.OnPressed += _ => _voteManager.SendCastVote(vote.Id, i1);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData()
|
||||
{
|
||||
VoteTitle.Text = _vote.Title;
|
||||
VoteCaller.Text = Loc.GetString("ui-vote-created", ("initiator", _vote.Initiator));
|
||||
|
||||
for (var i = 0; i < _voteButtons.Length; i++)
|
||||
{
|
||||
var entry = _vote.Entries[i];
|
||||
_voteButtons[i].Text = Loc.GetString("ui-vote-button", ("text", entry.Text), ("votes", entry.Votes));
|
||||
|
||||
if (_vote.OurVote == i)
|
||||
_voteButtons[i].Pressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
// Logger.Debug($"{_gameTiming.ServerTime}, {_vote.StartTime}, {_vote.EndTime}");
|
||||
|
||||
var curTime = _gameTiming.RealTime;
|
||||
var timeLeft = _vote.EndTime - curTime;
|
||||
if (timeLeft < TimeSpan.Zero)
|
||||
timeLeft = TimeSpan.Zero;
|
||||
|
||||
// Round up a second.
|
||||
timeLeft = TimeSpan.FromSeconds(Math.Ceiling(timeLeft.TotalSeconds));
|
||||
|
||||
TimeLeftBar.Value = Math.Min(1, (float) ((curTime.TotalSeconds - _vote.StartTime.TotalSeconds) /
|
||||
(_vote.EndTime.TotalSeconds - _vote.StartTime.TotalSeconds)));
|
||||
|
||||
TimeLeftText.Text = $"{timeLeft:m\\:ss}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user