Viewport improvements (#3765)
This commit is contained in:
committed by
GitHub
parent
8e2fc49357
commit
147a54c642
@@ -6,6 +6,7 @@ using Content.Client.UserInterface;
|
||||
using Content.Client.Voting;
|
||||
using Content.Shared;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -13,12 +14,16 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.State
|
||||
{
|
||||
public class GameScreen : GameScreenBase
|
||||
public class GameScreen : GameScreenBase, IMainViewportState
|
||||
{
|
||||
public static readonly Vector2i ViewportSize = (EyeManager.PixelsPerMeter * 21, EyeManager.PixelsPerMeter * 15);
|
||||
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
@@ -26,6 +31,8 @@ namespace Content.Client.State
|
||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
|
||||
[ViewVariables] private ChatBox? _gameChat;
|
||||
private ConstructionMenuPresenter? _constructionMenu;
|
||||
@@ -33,15 +40,27 @@ namespace Content.Client.State
|
||||
private bool _oocEnabled;
|
||||
private bool _adminOocEnabled;
|
||||
|
||||
public MainViewport Viewport { get; private set; } = default!;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
_gameChat = new ChatBox();
|
||||
Viewport = new MainViewport
|
||||
{
|
||||
Viewport =
|
||||
{
|
||||
ViewportSize = ViewportSize
|
||||
}
|
||||
};
|
||||
|
||||
_userInterfaceManager.StateRoot.AddChild(Viewport);
|
||||
LayoutContainer.SetAnchorPreset(Viewport, LayoutContainer.LayoutPreset.Wide);
|
||||
Viewport.SetPositionFirst();
|
||||
|
||||
_userInterfaceManager.StateRoot.AddChild(_gameChat);
|
||||
LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
|
||||
LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
|
||||
LayoutContainer.SetMarginLeft(_gameChat, -475);
|
||||
LayoutContainer.SetMarginBottom(_gameChat, 235);
|
||||
|
||||
@@ -65,6 +84,8 @@ namespace Content.Client.State
|
||||
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
|
||||
|
||||
SetupPresenters();
|
||||
|
||||
_eyeManager.MainViewport = Viewport.Viewport;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -74,7 +95,10 @@ namespace Content.Client.State
|
||||
base.Shutdown();
|
||||
|
||||
_gameChat?.Dispose();
|
||||
Viewport.Dispose();
|
||||
_gameHud.RootControl.Orphan();
|
||||
// Clear viewport to some fallback, whatever.
|
||||
_eyeManager.MainViewport = _userInterfaceManager.MainViewport;
|
||||
|
||||
}
|
||||
|
||||
@@ -168,5 +192,12 @@ namespace Content.Client.State
|
||||
chat.Input.GrabKeyboardFocus();
|
||||
chat.Input.InsertAtCursor("]");
|
||||
}
|
||||
|
||||
public override void FrameUpdate(FrameEventArgs e)
|
||||
{
|
||||
base.FrameUpdate(e);
|
||||
|
||||
Viewport.Viewport.Eye = _eyeManager.CurrentEye;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.Components;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.State;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
@@ -28,7 +29,6 @@ namespace Content.Client.State
|
||||
[Dependency] protected readonly IClientEntityManager EntityManager = default!;
|
||||
[Dependency] protected readonly IInputManager InputManager = default!;
|
||||
[Dependency] protected readonly IPlayerManager PlayerManager = default!;
|
||||
[Dependency] protected readonly IEyeManager EyeManager = default!;
|
||||
[Dependency] protected readonly IEntitySystemManager EntitySystemManager = default!;
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] protected readonly IMapManager MapManager = default!;
|
||||
@@ -68,10 +68,18 @@ namespace Content.Client.State
|
||||
if (localPlayer == null)
|
||||
return;
|
||||
|
||||
var mousePosWorld = EyeManager.ScreenToMap(InputManager.MouseScreenPosition);
|
||||
var entityToClick = UserInterfaceManager.CurrentlyHovered != null
|
||||
? null
|
||||
: GetEntityUnderPosition(mousePosWorld);
|
||||
IEntity? entityToClick = null;
|
||||
var renderScale = 1;
|
||||
if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp)
|
||||
{
|
||||
var mousePosWorld = vp.ScreenToMap(InputManager.MouseScreenPosition);
|
||||
entityToClick = GetEntityUnderPosition(mousePosWorld);
|
||||
|
||||
if (vp is ScalingViewport svp)
|
||||
{
|
||||
renderScale = svp.CurrentRenderScale;
|
||||
}
|
||||
}
|
||||
|
||||
var inRange = false;
|
||||
if (localPlayer.ControlledEntity != null && entityToClick != null)
|
||||
@@ -93,7 +101,7 @@ namespace Content.Client.State
|
||||
{
|
||||
if (entityToClick != null && entityToClick.TryGetComponent(out outline))
|
||||
{
|
||||
outline.UpdateInRange(inRange);
|
||||
outline.UpdateInRange(inRange, renderScale);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -109,7 +117,7 @@ namespace Content.Client.State
|
||||
|
||||
if (_lastHoveredEntity != null && _lastHoveredEntity.TryGetComponent(out outline))
|
||||
{
|
||||
outline.OnMouseEnter(inRange);
|
||||
outline.OnMouseEnter(inRange, renderScale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,30 +214,36 @@ namespace Content.Client.State
|
||||
/// Converts a state change event from outside the simulation to inside the simulation.
|
||||
/// </summary>
|
||||
/// <param name="args">Event data values for a bound key state change.</param>
|
||||
private void OnKeyBindStateChanged(BoundKeyEventArgs args)
|
||||
private void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
|
||||
{
|
||||
// If there is no InputSystem, then there is nothing to forward to, and nothing to do here.
|
||||
if(!EntitySystemManager.TryGetEntitySystem(out InputSystem inputSys))
|
||||
return;
|
||||
|
||||
var func = args.Function;
|
||||
var kArgs = args.KeyEventArgs;
|
||||
var func = kArgs.Function;
|
||||
var funcId = InputManager.NetworkBindMap.KeyFunctionID(func);
|
||||
|
||||
var mousePosWorld = EyeManager.ScreenToMap(args.PointerLocation);
|
||||
var entityToClick = GetEntityUnderPosition(mousePosWorld);
|
||||
EntityCoordinates coordinates = default;
|
||||
EntityUid entityToClick = default;
|
||||
if (args.Viewport is IViewportControl vp)
|
||||
{
|
||||
var mousePosWorld = vp.ScreenToMap(kArgs.PointerLocation.Position);
|
||||
entityToClick = GetEntityUnderPosition(mousePosWorld)?.Uid ?? EntityUid.Invalid;
|
||||
|
||||
var coordinates = MapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) :
|
||||
EntityCoordinates.FromMap(EntityManager, MapManager, mousePosWorld);
|
||||
coordinates = MapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) :
|
||||
EntityCoordinates.FromMap(EntityManager, MapManager, mousePosWorld);
|
||||
}
|
||||
|
||||
var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, args.State,
|
||||
coordinates , args.PointerLocation,
|
||||
entityToClick?.Uid ?? EntityUid.Invalid);
|
||||
var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, kArgs.State,
|
||||
coordinates , kArgs.PointerLocation,
|
||||
entityToClick);
|
||||
|
||||
// client side command handlers will always be sent the local player session.
|
||||
var session = PlayerManager.LocalPlayer?.Session;
|
||||
if (inputSys.HandleInputCommand(session, func, message))
|
||||
{
|
||||
args.Handle();
|
||||
kArgs.Handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
Content.Client/State/IMainViewport.cs
Normal file
15
Content.Client/State/IMainViewport.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Content.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.State
|
||||
{
|
||||
/// <summary>
|
||||
/// Client state that has a main viewport.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used for taking no-UI screenshots (including things like flash overlay).
|
||||
/// </remarks>
|
||||
public interface IMainViewportState
|
||||
{
|
||||
public MainViewport Viewport { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,251 +1,81 @@
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Client.Utility;
|
||||
using System;
|
||||
using Content.Client.UserInterface;
|
||||
using Robust.Client;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using static Content.Client.StaticIoC;
|
||||
|
||||
namespace Content.Client.State
|
||||
{
|
||||
public class LauncherConnecting : Robust.Client.State.State
|
||||
{
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IStylesheetManager _stylesheetManager = default!;
|
||||
[Dependency] private readonly IClientNetManager _clientNetManager = default!;
|
||||
[Dependency] private readonly IGameController _gameController = default!;
|
||||
[Dependency] private readonly IBaseClient _baseClient = default!;
|
||||
|
||||
private Control? _control;
|
||||
private Label? _connectStatus;
|
||||
private LauncherConnectingGui? _control;
|
||||
|
||||
private Control? _connectingStatus;
|
||||
private Control? _connectFail;
|
||||
private Label? _connectFailReason;
|
||||
private Control? _disconnected;
|
||||
private Page _currentPage;
|
||||
private string? _connectFailReason;
|
||||
|
||||
public string? Address => _gameController.LaunchState.Ss14Address ?? _gameController.LaunchState.ConnectAddress;
|
||||
|
||||
public string? ConnectFailReason
|
||||
{
|
||||
get => _connectFailReason;
|
||||
private set
|
||||
{
|
||||
_connectFailReason = value;
|
||||
ConnectFailReasonChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Page CurrentPage
|
||||
{
|
||||
get => _currentPage;
|
||||
private set
|
||||
{
|
||||
_currentPage = value;
|
||||
PageChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public ClientConnectionState ConnectionState => _clientNetManager.ClientConnectState;
|
||||
|
||||
public event Action<Page>? PageChanged;
|
||||
public event Action<string?>? ConnectFailReasonChanged;
|
||||
public event Action<ClientConnectionState>? ConnectionStateChanged;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
Button exitButton;
|
||||
Button reconnectButton;
|
||||
Button retryButton;
|
||||
|
||||
var address = _gameController.LaunchState.Ss14Address ?? _gameController.LaunchState.ConnectAddress;
|
||||
|
||||
_control = new Control
|
||||
{
|
||||
Stylesheet = _stylesheetManager.SheetSpace,
|
||||
Children =
|
||||
{
|
||||
new PanelContainer {StyleClasses = {StyleBase.ClassAngleRect}},
|
||||
new VBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
MinSize = (300, 200),
|
||||
Children =
|
||||
{
|
||||
new HBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Label
|
||||
{
|
||||
Margin = new Thickness(8, 0, 0, 0),
|
||||
Text = Loc.GetString("Space Station 14"),
|
||||
StyleClasses = {StyleBase.StyleClassLabelHeading},
|
||||
VAlign = Label.VAlignMode.Center
|
||||
},
|
||||
|
||||
(exitButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("Exit"),
|
||||
HorizontalAlignment = Control.HAlignment.Right,
|
||||
HorizontalExpand = true,
|
||||
}),
|
||||
}
|
||||
},
|
||||
|
||||
// Line
|
||||
new HighDivider(),
|
||||
|
||||
new VBoxContainer
|
||||
{
|
||||
VerticalExpand = true,
|
||||
Margin = new Thickness(4, 4, 4, 0),
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
new Control
|
||||
{
|
||||
VerticalExpand = true,
|
||||
Children =
|
||||
{
|
||||
(_connectingStatus = new VBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
new Label
|
||||
{
|
||||
Text = Loc.GetString("Connecting to server..."),
|
||||
Align = Label.AlignMode.Center,
|
||||
},
|
||||
|
||||
(_connectStatus = new Label
|
||||
{
|
||||
StyleClasses = {StyleBase.StyleClassLabelSubText},
|
||||
Align = Label.AlignMode.Center,
|
||||
}),
|
||||
}
|
||||
}),
|
||||
(_connectFail = new VBoxContainer
|
||||
{
|
||||
Visible = false,
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
(_connectFailReason = new Label
|
||||
{
|
||||
Align = Label.AlignMode.Center
|
||||
}),
|
||||
|
||||
(retryButton = new Button
|
||||
{
|
||||
Text = "Retry",
|
||||
HorizontalAlignment = Control.HAlignment.Center,
|
||||
VerticalExpand = true,
|
||||
VerticalAlignment = Control.VAlignment.Bottom,
|
||||
})
|
||||
}
|
||||
}),
|
||||
|
||||
(_disconnected = new VBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
new Label
|
||||
{
|
||||
Text = "Disconnected from server:",
|
||||
Align = Label.AlignMode.Center
|
||||
},
|
||||
new Label
|
||||
{
|
||||
Text = _baseClient.LastDisconnectReason,
|
||||
Align = Label.AlignMode.Center
|
||||
},
|
||||
(reconnectButton = new Button
|
||||
{
|
||||
Text = "Reconnect",
|
||||
HorizontalAlignment = Control.HAlignment.Center,
|
||||
VerticalExpand = true,
|
||||
VerticalAlignment = Control.VAlignment.Bottom,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// Padding.
|
||||
new Control {MinSize = (0, 8)},
|
||||
|
||||
new Label
|
||||
{
|
||||
Text = address,
|
||||
StyleClasses = {StyleBase.StyleClassLabelSubText},
|
||||
HorizontalAlignment = Control.HAlignment.Center
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Line
|
||||
new PanelContainer
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat
|
||||
{
|
||||
BackgroundColor = Color.FromHex("#444"),
|
||||
ContentMarginTopOverride = 2
|
||||
},
|
||||
},
|
||||
new HBoxContainer
|
||||
{
|
||||
Margin = new Thickness(12, 0, 4, 0),
|
||||
VerticalAlignment = Control.VAlignment.Bottom,
|
||||
Children =
|
||||
{
|
||||
new Label
|
||||
{
|
||||
Text = Loc.GetString("Don't die!"),
|
||||
StyleClasses = {StyleBase.StyleClassLabelSubText}
|
||||
},
|
||||
new Label
|
||||
{
|
||||
Text = "ver 0.1",
|
||||
HorizontalExpand = true,
|
||||
HorizontalAlignment = Control.HAlignment.Right,
|
||||
StyleClasses = {StyleBase.StyleClassLabelSubText}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
_control = new LauncherConnectingGui(this);
|
||||
|
||||
_userInterfaceManager.StateRoot.AddChild(_control);
|
||||
|
||||
LayoutContainer.SetAnchorPreset(_control, LayoutContainer.LayoutPreset.Center);
|
||||
LayoutContainer.SetGrowHorizontal(_control, LayoutContainer.GrowDirection.Both);
|
||||
LayoutContainer.SetGrowVertical(_control, LayoutContainer.GrowDirection.Both);
|
||||
|
||||
exitButton.OnPressed += _ =>
|
||||
{
|
||||
_gameController.Shutdown("Exit button pressed");
|
||||
};
|
||||
|
||||
void Retry(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
if (_gameController.LaunchState.ConnectEndpoint != null)
|
||||
{
|
||||
_baseClient.ConnectToServer(_gameController.LaunchState.ConnectEndpoint);
|
||||
SetActivePage(Page.Connecting);
|
||||
}
|
||||
}
|
||||
|
||||
reconnectButton.OnPressed += Retry;
|
||||
retryButton.OnPressed += Retry;
|
||||
|
||||
_clientNetManager.ConnectFailed += (_, args) =>
|
||||
{
|
||||
_connectFailReason.Text = Loc.GetString("Failed to connect to server:\n{0}", args.Reason);
|
||||
SetActivePage(Page.ConnectFailed);
|
||||
ConnectFailReason = args.Reason;
|
||||
CurrentPage = Page.ConnectFailed;
|
||||
};
|
||||
|
||||
_clientNetManager.ClientConnectStateChanged += ConnectStateChanged;
|
||||
_clientNetManager.ClientConnectStateChanged += state => ConnectionStateChanged?.Invoke(state);
|
||||
|
||||
SetActivePage(Page.Connecting);
|
||||
|
||||
ConnectStateChanged(_clientNetManager.ClientConnectState);
|
||||
CurrentPage = Page.Connecting;
|
||||
}
|
||||
|
||||
private void ConnectStateChanged(ClientConnectionState state)
|
||||
public void RetryConnect()
|
||||
{
|
||||
if (_connectStatus == null) return;
|
||||
|
||||
_connectStatus.Text = Loc.GetString(state switch
|
||||
if (_gameController.LaunchState.ConnectEndpoint != null)
|
||||
{
|
||||
ClientConnectionState.NotConnecting => "You should not be seeing this",
|
||||
ClientConnectionState.ResolvingHost => "Resolving server address...",
|
||||
ClientConnectionState.EstablishingConnection => "Establishing initial connection...",
|
||||
ClientConnectionState.Handshake => "Doing handshake...",
|
||||
ClientConnectionState.Connected => "Synchronizing game state...",
|
||||
_ => state.ToString()
|
||||
});
|
||||
_baseClient.ConnectToServer(_gameController.LaunchState.ConnectEndpoint);
|
||||
CurrentPage = Page.Connecting;
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
_gameController.Shutdown("Exit button pressed");
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -255,17 +85,10 @@ namespace Content.Client.State
|
||||
|
||||
public void SetDisconnected()
|
||||
{
|
||||
SetActivePage(Page.Disconnected);
|
||||
CurrentPage = Page.Disconnected;
|
||||
}
|
||||
|
||||
private void SetActivePage(Page page)
|
||||
{
|
||||
if (_connectingStatus != null) _connectingStatus.Visible = page == Page.Connecting;
|
||||
if (_connectFail != null) _connectFail.Visible = page == Page.ConnectFailed;
|
||||
if (_disconnected != null) _disconnected.Visible = page == Page.Disconnected;
|
||||
}
|
||||
|
||||
private enum Page : byte
|
||||
public enum Page : byte
|
||||
{
|
||||
Connecting,
|
||||
ConnectFailed,
|
||||
|
||||
@@ -215,6 +215,8 @@ namespace Content.Client.State
|
||||
|
||||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
AddChild(new ParallaxControl());
|
||||
|
||||
var layout = new LayoutContainer();
|
||||
AddChild(layout);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user