Fix vote popup (#14940)

This commit is contained in:
metalgearsloth
2023-03-29 19:36:30 +11:00
committed by GitHub
parent 5314c85de8
commit 4cbd5ef1ca
6 changed files with 63 additions and 8 deletions

View File

@@ -15,7 +15,14 @@
<LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True"> <LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True">
<controls:MainViewport Name="MainViewport"/> <controls:MainViewport Name="MainViewport"/>
</LayoutContainer> </LayoutContainer>
<menuBar:GameTopMenuBar Name="TopBar" Access="Protected" /> <BoxContainer Name="TopLeft" Access="Protected" Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<menuBar:GameTopMenuBar Name="TopBar" Access="Protected" />
<!-- Buffer so big votes don't skew it -->
<Control/>
</BoxContainer>
<Control Name="VoteMenu" Access="Public" Margin="0 10 0 10"/>
</BoxContainer>
<widgets:GhostGui Name="Ghost" Access="Protected" /> <widgets:GhostGui Name="Ghost" Access="Protected" />
<hotbar:HotbarGui Name="Hotbar" Access="Protected" /> <hotbar:HotbarGui Name="Hotbar" Access="Protected" />
<actions:ActionsBar Name="Actions" Access="Protected" /> <actions:ActionsBar Name="Actions" Access="Protected" />

View File

@@ -1,7 +1,5 @@
using Content.Client.UserInterface.Systems.Chat.Widgets; using Content.Client.UserInterface.Systems.Chat.Widgets;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
namespace Content.Client.UserInterface.Screens; namespace Content.Client.UserInterface.Screens;
@@ -17,7 +15,7 @@ public sealed partial class DefaultGameScreen : InGameScreen
SetAnchorPreset(MainViewport, LayoutPreset.Wide); SetAnchorPreset(MainViewport, LayoutPreset.Wide);
SetAnchorPreset(ViewportContainer, LayoutPreset.Wide); SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
SetAnchorAndMarginPreset(TopBar, LayoutPreset.TopLeft, margin: 10); SetAnchorAndMarginPreset(TopLeft, LayoutPreset.TopLeft, margin: 10);
SetAnchorAndMarginPreset(Actions, LayoutPreset.BottomLeft, margin: 10); SetAnchorAndMarginPreset(Actions, LayoutPreset.BottomLeft, margin: 10);
SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80); SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5); SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);

View File

@@ -16,6 +16,7 @@
<controls:RecordedSplitContainer Name="ScreenContainer" HorizontalExpand="True" VerticalExpand="True" SplitWidth="0" StretchDirection="TopLeft"> <controls:RecordedSplitContainer Name="ScreenContainer" HorizontalExpand="True" VerticalExpand="True" SplitWidth="0" StretchDirection="TopLeft">
<LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True"> <LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True">
<controls:MainViewport Name="MainViewport"/> <controls:MainViewport Name="MainViewport"/>
<Control Name="VoteMenu" Access="Public"/>
<widgets:GhostGui Name="Ghost" Access="Protected" /> <widgets:GhostGui Name="Ghost" Access="Protected" />
<hotbar:HotbarGui Name="Hotbar" Access="Protected" /> <hotbar:HotbarGui Name="Hotbar" Access="Protected" />
<actions:ActionsBar Name="Actions" Access="Protected" /> <actions:ActionsBar Name="Actions" Access="Protected" />

View File

@@ -1,6 +1,5 @@
using Content.Client.UserInterface.Systems.Chat.Widgets; using Content.Client.UserInterface.Systems.Chat.Widgets;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -18,6 +17,7 @@ public sealed partial class SeparatedChatGameScreen : InGameScreen
SetAnchorPreset(ScreenContainer, LayoutPreset.Wide); SetAnchorPreset(ScreenContainer, LayoutPreset.Wide);
SetAnchorPreset(ViewportContainer, LayoutPreset.Wide); SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
SetAnchorPreset(MainViewport, LayoutPreset.Wide); SetAnchorPreset(MainViewport, LayoutPreset.Wide);
SetAnchorAndMarginPreset(VoteMenu, LayoutPreset.TopLeft, margin: 10);
SetAnchorAndMarginPreset(Actions, LayoutPreset.BottomLeft, margin: 10); SetAnchorAndMarginPreset(Actions, LayoutPreset.BottomLeft, margin: 10);
SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80); SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5); SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);

View File

@@ -0,0 +1,37 @@
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.Voting;
using Robust.Client.UserInterface.Controllers;
namespace Content.Client.UserInterface.Systems.Vote;
public sealed class VoteUIController : UIController
{
[Dependency] private readonly IVoteManager _votes = default!;
public override void Initialize()
{
base.Initialize();
var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
gameplayStateLoad.OnScreenUnload += OnScreenUnload;
}
private void OnScreenLoad()
{
switch (UIManager.ActiveScreen)
{
case DefaultGameScreen game:
_votes.SetPopupContainer(game.VoteMenu);
break;
case SeparatedChatGameScreen separated:
_votes.SetPopupContainer(separated.VoteMenu);
break;
}
}
private void OnScreenUnload()
{
_votes.ClearPopupContainer();
}
}

View File

@@ -95,6 +95,13 @@ namespace Content.Client.Voting
} }
_popupContainer = container; _popupContainer = container;
SetVoteData();
}
private void SetVoteData()
{
if (_popupContainer == null)
return;
foreach (var (vId, vote) in _votes) foreach (var (vId, vote) in _votes)
{ {
@@ -121,9 +128,13 @@ namespace Content.Client.Voting
@new = true; @new = true;
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>() IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>()
.PlayGlobal("/Audio/Effects/voteding.ogg", Filter.Local(), false); .PlayGlobal("/Audio/Effects/voteding.ogg", Filter.Local(), false);
// TODO: It would be better if this used a per-state container, i.e. a container
// for the lobby and each HUD layout. // Refresh
SetPopupContainer(_userInterfaceManager.WindowRoot); var container = _popupContainer;
ClearPopupContainer();
if (container != null)
SetPopupContainer(container);
// New vote from the server. // New vote from the server.
var vote = new ActiveVote(voteId) var vote = new ActiveVote(voteId)
@@ -142,6 +153,7 @@ namespace Content.Client.Voting
_votes.Remove(voteId); _votes.Remove(voteId);
if (_votePopups.TryGetValue(voteId, out var toRemove)) if (_votePopups.TryGetValue(voteId, out var toRemove))
{ {
toRemove.Orphan(); toRemove.Orphan();
_votePopups.Remove(voteId); _votePopups.Remove(voteId);
} }