Merge branches 'pseudo-classes', 'input-refactor' and '19-08-21-update-submodule'

This commit is contained in:
Pieter-Jan Briers
2019-08-21 17:25:01 +02:00
57 changed files with 301 additions and 374 deletions

View File

@@ -8,6 +8,7 @@ using Robust.Shared.Maths;
using Robust.Shared.Utility;
using Robust.Shared.Localization;
using Robust.Shared.IoC;
using Robust.Shared.Input;
namespace Content.Client.Chat
{
@@ -82,7 +83,7 @@ namespace Content.Client.Chat
vBox.AddChild(contentMargin);
Input = new LineEdit();
Input.OnKeyDown += InputKeyDown;
Input.OnKeyBindDown += InputKeyBindDown;
Input.OnTextEntered += Input_OnTextEntered;
vBox.AddChild(Input);
@@ -119,23 +120,27 @@ namespace Content.Client.Chat
AddChild(outerVBox);
}
protected override void MouseDown(GUIMouseButtonEventArgs e)
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
{
base.MouseDown(e);
base.KeyBindDown(args);
if (!args.CanFocus)
{
return;
}
Input.GrabKeyboardFocus();
}
private void InputKeyDown(GUIKeyEventArgs e)
private void InputKeyBindDown(GUIBoundKeyEventArgs args)
{
if (e.Key == Keyboard.Key.Escape)
if (args.Function == EngineKeyFunctions.TextReleaseFocus)
{
Input.ReleaseKeyboardFocus();
e.Handle();
args.Handle();
return;
}
if (e.Key == Keyboard.Key.Up)
else if (args.Function == EngineKeyFunctions.TextHistoryPrev)
{
if (_inputIndex == -1 && _inputHistory.Count != 0)
{
@@ -151,12 +156,12 @@ namespace Content.Client.Chat
{
Input.Text = _inputHistory[_inputIndex];
}
Input.CursorPos = Input.Text.Length;
e.Handle();
args.Handle();
return;
}
if (e.Key == Keyboard.Key.Down)
else if (args.Function == EngineKeyFunctions.TextHistoryNext)
{
if (_inputIndex == 0)
{
@@ -169,8 +174,9 @@ namespace Content.Client.Chat
_inputIndex--;
Input.Text = _inputHistory[_inputIndex];
}
Input.CursorPos = Input.Text.Length;
e.Handle();
args.Handle();
}
}

View File

@@ -1,4 +1,4 @@
using Content.Client.UserInterface;
using Content.Client.UserInterface;
using Robust.Client.Console;
using Robust.Client.Interfaces.Input;
using Robust.Client.Interfaces.Placement;
@@ -49,9 +49,8 @@ namespace Content.Client
_escapeMenu.OnClose += () => _gameHud.EscapeButtonDown = false;
var escapeMenuCommand = InputCmdHandler.FromDelegate(Enabled);
_inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, escapeMenuCommand);
_inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu,
InputCmdHandler.FromDelegate(s => Enabled()));
}
else if (obj.OldState is GameScreen)
{
@@ -63,7 +62,7 @@ namespace Content.Client
}
}
private void Enabled(ICommonSession session)
private void Enabled()
{
if (_escapeMenu.IsOpen)
{

View File

@@ -127,18 +127,18 @@ namespace Content.Client.GameObjects
_sprite?.LayerSetVisible(slot, false);
}
public void SendUnequipMessage(Slots slot)
{
var unequipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Unequip);
SendNetworkMessage(unequipmessage);
}
public void SendEquipMessage(Slots slot)
{
var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Equip);
SendNetworkMessage(equipmessage);
}
public void SendUseMessage(Slots slot)
{
var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Use);
SendNetworkMessage(equipmessage);
}
public void SendOpenStorageUIMessage(Slots slot)
{
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));

View File

@@ -43,7 +43,7 @@ namespace Content.Client.GameObjects
base.Initialize();
_window = new HumanInventoryWindow(_loc, _resourceCache);
_window.OnClose += () => GameHud.InventoryButtonDown = false;
foreach (var (slot, button) in _window.Buttons)
{
button.OnPressed = AddToInventory;
@@ -97,7 +97,7 @@ namespace Content.Client.GameObjects
foreach (var button in buttons)
{
button.SpriteView.Sprite = sprite;
button.OnPressed = RemoveFromInventory;
button.OnPressed = HandleInventoryKeybind;
button.StorageButton.Visible = hasInventory;
}
}

View File

@@ -27,7 +27,8 @@ namespace Content.Client.GameObjects
AddChild(Button = new TextureButton
{
TextureNormal = texture,
Scale = (2, 2)
Scale = (2, 2),
EnableAllKeybinds = true
});
Button.OnPressed += e => OnPressed?.Invoke(e);
@@ -44,7 +45,8 @@ namespace Content.Client.GameObjects
Scale = (0.75f, 0.75f),
SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
SizeFlagsVertical = SizeFlags.ShrinkEnd,
Visible = false
Visible = false,
EnableAllKeybinds = true
});
StorageButton.OnPressed += e => OnStoragePressed?.Invoke(e);

View File

@@ -1,6 +1,7 @@
using System;
using System;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.Input;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Interfaces.GameObjects;
@@ -60,24 +61,44 @@ namespace Content.Client.GameObjects
{
}
protected void RemoveFromInventory(BaseButton.ButtonEventArgs args)
protected void HandleInventoryKeybind(BaseButton.ButtonEventArgs args)
{
args.Button.Pressed = false;
var control = (InventoryButton) args.Button.Parent;
Owner.SendUnequipMessage(control.Slot);
if (args.Event.Function == ContentKeyFunctions.ActivateItemInWorld)
{
OpenStorage(args);
}
else if (args.Event.CanFocus)
{
UseItemOnInventory(args);
}
}
protected void AddToInventory(BaseButton.ButtonEventArgs args)
{
if (!args.Event.CanFocus)
{
return;
}
args.Button.Pressed = false;
var control = (InventoryButton) args.Button.Parent;
Owner.SendEquipMessage(control.Slot);
}
protected void UseItemOnInventory(BaseButton.ButtonEventArgs args)
{
args.Button.Pressed = false;
var control = (InventoryButton)args.Button.Parent;
Owner.SendUseMessage(control.Slot);
}
protected void OpenStorage(BaseButton.ButtonEventArgs args)
{
if (!args.Event.CanFocus && args.Event.Function != ContentKeyFunctions.ActivateItemInWorld)
{
return;
}
args.Button.Pressed = false;
var control = (InventoryButton)args.Button.Parent;

View File

@@ -5,6 +5,7 @@ using Robust.Client.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.Timers;
@@ -16,7 +17,9 @@ namespace Content.Client.GameObjects.Components.Sound
{
private readonly List<ScheduledSound> _schedules = new List<ScheduledSound>();
private AudioSystem _audioSystem;
private Random Random;
#pragma warning disable 649
[Dependency] private readonly IRobustRandom _random;
#pragma warning restore 649
public override void StopAllSounds()
{
@@ -46,9 +49,8 @@ namespace Content.Client.GameObjects.Components.Sound
public void Play(ScheduledSound schedule)
{
if (!schedule.Play) return;
if (Random == null) Random = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode());
Timer.Spawn((int) schedule.Delay + (Random.Next((int) schedule.RandomDelay)),() =>
Timer.Spawn((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() =>
{
if (!schedule.Play) return; // We make sure this hasn't changed.
if (_audioSystem == null) _audioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();

View File

@@ -1,4 +1,4 @@
using Content.Client.GameObjects.Components.Weapons.Ranged;
using Content.Client.GameObjects.Components.Weapons.Ranged;
using Content.Client.Interfaces.GameObjects;
using Content.Shared.Input;
using Robust.Client.GameObjects.EntitySystems;
@@ -37,7 +37,7 @@ namespace Content.Client.GameObjects.EntitySystems
base.Update(frameTime);
var canFireSemi = _isFirstShot;
var state = _inputSystem.CmdStates.GetState(ContentKeyFunctions.UseItemInHand);
var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
if (state != BoundKeyState.Down)
{
_isFirstShot = true;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Content.Client.Chat;
using Content.Client.Interfaces;
@@ -18,6 +18,7 @@ using Robust.Shared.Input;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Players;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -188,11 +189,7 @@ namespace Content.Client.GameTicking
_lobby.ServerName.Text = _baseClient.GameInfo.ServerName;
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
InputCmdHandler.FromDelegate(session =>
{
_lobby.Chat.Input.IgnoreNext = true;
_lobby.Chat.Input.GrabKeyboardFocus();
}));
InputCmdHandler.FromDelegate(s => _focusChat(_lobby.Chat)));
_updateLobbyUi();
@@ -237,19 +234,25 @@ namespace Content.Client.GameTicking
_lobby = null;
}
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
InputCmdHandler.FromDelegate(session =>
{
_gameChat.Input.IgnoreNext = true;
_gameChat.Input.GrabKeyboardFocus();
}));
_gameChat = new ChatBox();
_userInterfaceManager.StateRoot.AddChild(_gameChat);
_userInterfaceManager.StateRoot.AddChild(_gameHud.RootControl);
_chatManager.SetChatBox(_gameChat);
_gameChat.DefaultChatFormat = "say \"{0}\"";
_gameChat.Input.PlaceHolder = _localization.GetString("Say something! [ for OOC");
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
InputCmdHandler.FromDelegate(s => _focusChat(_gameChat)));
}
private void _focusChat(ChatBox chat)
{
if (_userInterfaceManager.KeyboardFocused != null)
{
return;
}
chat.Input.IgnoreNext = true;
chat.Input.GrabKeyboardFocus();
}
private enum TickerState

View File

@@ -21,12 +21,12 @@ namespace Content.Client.Input
human.AddFunction(ContentKeyFunctions.Drop);
human.AddFunction(ContentKeyFunctions.ActivateItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
human.AddFunction(ContentKeyFunctions.UseItemInHand);
human.AddFunction(ContentKeyFunctions.ActivateItemInWorld);
human.AddFunction(ContentKeyFunctions.ThrowItemInHand);
human.AddFunction(ContentKeyFunctions.OpenContextMenu);
human.AddFunction(ContentKeyFunctions.OpenCraftingMenu);
human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
human.AddFunction(ContentKeyFunctions.MouseMiddle);
// Disabled until there is feedback, so hitting tab doesn't suddenly break interaction.
// human.AddFunction(ContentKeyFunctions.ToggleCombatMode);

View File

@@ -10,6 +10,7 @@ using Robust.Client.Utility;
using Robust.Shared.Interfaces.Log;
using Robust.Shared.Maths;
using Robust.Shared.Noise;
using Robust.Shared.Random;
using SixLabors.ImageSharp.Advanced;
using BlendFactor = Robust.Shared.Maths.Color.BlendFactor;

View File

@@ -10,6 +10,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Timers;
using Robust.Shared.Utility;
namespace Content.Client.Research
{

View File

@@ -2,6 +2,7 @@
using Content.Client.GameObjects.EntitySystems;
using Content.Client.Interfaces.GameObjects;
using Content.Client.Utility;
using Content.Shared.Input;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Interfaces.GameObjects.Components;
@@ -9,6 +10,7 @@ using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
@@ -199,12 +201,17 @@ namespace Content.Client.UserInterface
return _handL.Contains((Vector2i) point) || _handR.Contains((Vector2i) point);
}
protected override void MouseDown(GUIMouseButtonEventArgs args)
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
{
base.MouseDown(args);
base.KeyBindDown(args);
var leftHandContains = _handL.Contains((Vector2i) args.RelativePosition);
var rightHandContains = _handR.Contains((Vector2i) args.RelativePosition);
if (!args.CanFocus)
{
return;
}
var leftHandContains = _handL.Contains((Vector2i)args.RelativePosition);
var rightHandContains = _handR.Contains((Vector2i)args.RelativePosition);
string handIndex;
if (leftHandContains)
@@ -220,7 +227,7 @@ namespace Content.Client.UserInterface
return;
}
if (args.Button == Mouse.Button.Left)
if (args.Function == EngineKeyFunctions.Use)
{
if (!TryGetHands(out var hands))
return;
@@ -236,12 +243,12 @@ namespace Content.Client.UserInterface
}
}
else if (args.Button == Mouse.Button.Middle)
else if (args.Function == ContentKeyFunctions.MouseMiddle)
{
SendSwitchHandTo(handIndex);
}
else if (args.Button == Mouse.Button.Right)
else if (args.Function == ContentKeyFunctions.OpenContextMenu)
{
if (!TryGetHands(out var hands))
{
@@ -255,7 +262,7 @@ namespace Content.Client.UserInterface
}
var esm = IoCManager.Resolve<IEntitySystemManager>();
esm.GetEntitySystem<VerbSystem>().OpenContextMenu(entity, new ScreenCoordinates(args.GlobalPosition));
esm.GetEntitySystem<VerbSystem>().OpenContextMenu(entity, new ScreenCoordinates(args.PointerLocation.Position));
}
}
}