Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Port fancy typing indicators #58

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions Content.Client/Chat/TypingIndicator/TypingIndicatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class TypingIndicatorSystem : SharedTypingIndicatorSystem
private readonly TimeSpan _typingTimeout = TimeSpan.FromSeconds(2);
private TimeSpan _lastTextChange;
private bool _isClientTyping;
private bool _isClientChatFocused; // Corvax-TypingIndicator

public override void Initialize()
{
Expand All @@ -31,7 +32,10 @@ public void ClientChangedChatText()
return;

// client typed something - show typing indicator
ClientUpdateTyping(true);
// Corvax-TypingIndicator-Start
_isClientTyping = true;
ClientUpdateTyping();
// Corvax-TypingIndicator-End
_lastTextChange = _time.CurTime;
}

Expand All @@ -42,9 +46,26 @@ public void ClientSubmittedChatText()
return;

// client submitted text - hide typing indicator
ClientUpdateTyping(false);
// Corvax-TypingIndicator-Start
_isClientTyping = false;
_isClientChatFocused = false;
ClientUpdateTyping();
// Corvax-TypingIndicator-End
}

// Corvax-TypingIndicator-Start
public void ClientChangedChatFocus(bool isFocused)
{
// don't update it if player don't want to show typing
if (!_cfg.GetCVar(CCVars.ChatShowTypingIndicator))
return;

// client submitted text - hide typing indicator
_isClientChatFocused = isFocused;
ClientUpdateTyping();
}
// Corvax-TypingIndicator-End

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand All @@ -56,31 +77,45 @@ public override void Update(float frameTime)
if (dif > _typingTimeout)
{
// client didn't typed anything for a long time - hide indicator
ClientUpdateTyping(false);
// Corvax-TypingIndicator-Start
_isClientTyping = false;
ClientUpdateTyping();
// Corvax-TypingIndicator-End
}
}
}

private void ClientUpdateTyping(bool isClientTyping)
private void ClientUpdateTyping() // Corvax-TypingIndicator
{
if (_isClientTyping == isClientTyping)
return;
_isClientTyping = isClientTyping;
// Corvax-TypingIndicator-Start
// if (_isClientTyping == isClientTyping)
// return;
// _isClientTyping = isClientTyping;
// Corvax-TypingIndicator-End

// check if player controls any pawn
if (_playerManager.LocalEntity == null)
return;

// Corvax-TypingIndicator-Start
var state = TypingIndicatorState.None;
if (_isClientChatFocused)
state = _isClientTyping ? TypingIndicatorState.Typing : TypingIndicatorState.Idle;
// Corvax-TypingIndicator-End

// send a networked event to server
RaiseNetworkEvent(new TypingChangedEvent(isClientTyping));
RaiseNetworkEvent(new TypingChangedEvent(state)); // Corvax-TypingIndicator
}

private void OnShowTypingChanged(bool showTyping)
{
// hide typing indicator immediately if player don't want to show it anymore
if (!showTyping)
{
ClientUpdateTyping(false);
// Corvax-TypingIndicator-Start
_isClientTyping = false;
ClientUpdateTyping();
// Corvax-TypingIndicator-End
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override void OnAppearanceChange(EntityUid uid, TypingIndicatorCompone
return;
}

AppearanceSystem.TryGetData<bool>(uid, TypingIndicatorVisuals.IsTyping, out var isTyping, args.Component);
//AppearanceSystem.TryGetData<bool>(uid, TypingIndicatorVisuals.IsTyping, out var isTyping, args.Component); // Corvax-TypingIndicator
var layerExists = args.Sprite.LayerMapTryGet(TypingIndicatorLayers.Base, out var layer);
if (!layerExists)
layer = args.Sprite.LayerMapReserveBlank(TypingIndicatorLayers.Base);
Expand All @@ -29,6 +29,19 @@ protected override void OnAppearanceChange(EntityUid uid, TypingIndicatorCompone
args.Sprite.LayerSetState(layer, proto.TypingState);
args.Sprite.LayerSetShader(layer, proto.Shader);
args.Sprite.LayerSetOffset(layer, proto.Offset);
args.Sprite.LayerSetVisible(layer, isTyping);
// args.Sprite.LayerSetVisible(layer, isTyping); // Corvax-TypingIndicator
// Corvax-TypingIndicator-Start
AppearanceSystem.TryGetData<TypingIndicatorState>(uid, TypingIndicatorVisuals.State, out var state);
args.Sprite.LayerSetVisible(layer, state != TypingIndicatorState.None);
switch (state)
{
case TypingIndicatorState.Idle:
args.Sprite.LayerSetState(layer, proto.IdleState);
break;
case TypingIndicatorState.Typing:
args.Sprite.LayerSetState(layer, proto.TypingState);
break;
}
// Corvax-TypingIndicator-End
}
}
7 changes: 7 additions & 0 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,13 @@ public void NotifyChatTextChange()
_typingIndicator?.ClientChangedChatText();
}

// Corvax-TypingIndicator-Start
public void NotifyChatFocus(bool isFocused)
{
_typingIndicator?.ClientChangedChatFocus(isFocused);
}
// Corvax-TypingIndicator-End

public void Repopulate()
{
foreach (var chat in _chats)
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public ChatBox()
ChatInput.Input.OnTextEntered += OnTextEntered;
ChatInput.Input.OnKeyBindDown += OnInputKeyBindDown;
ChatInput.Input.OnTextChanged += OnTextChanged;
ChatInput.Input.OnFocusEnter += OnFocusEnter; // Corvax-TypingIndicator
ChatInput.Input.OnFocusExit += OnFocusExit; // Corvax-TypingIndicator
ChatInput.ChannelSelector.OnChannelSelect += OnChannelSelect;
ChatInput.FilterButton.Popup.OnChannelFilter += OnChannelFilter;

Expand Down Expand Up @@ -175,6 +177,20 @@ private void OnTextChanged(LineEditEventArgs args)
_controller.NotifyChatTextChange();
}

// Corvax-TypingIndicator-Start
private void OnFocusEnter(LineEditEventArgs args)
{
// Warn typing indicator about focus
_controller.NotifyChatFocus(true);
}

private void OnFocusExit(LineEditEventArgs args)
{
// Warn typing indicator about focus
_controller.NotifyChatFocus(false);
}
// Corvax-TypingIndicator-End

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand Down
14 changes: 7 additions & 7 deletions Content.Server/Chat/TypingIndicator/TypingIndicatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void OnPlayerAttached(PlayerAttachedEvent ev)
private void OnPlayerDetached(EntityUid uid, TypingIndicatorComponent component, PlayerDetachedEvent args)
{
// player left entity body - hide typing indicator
SetTypingIndicatorEnabled(uid, false);
SetTypingIndicatorState(uid, TypingIndicatorState.None); // Corvax-TypingIndicator
}

private void OnClientTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs args)
Expand All @@ -47,18 +47,18 @@ private void OnClientTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs
if (!_actionBlocker.CanEmote(uid.Value) && !_actionBlocker.CanSpeak(uid.Value))
{
// nah, make sure that typing indicator is disabled
SetTypingIndicatorEnabled(uid.Value, false);
SetTypingIndicatorState(uid.Value, TypingIndicatorState.None); // Corvax-TypingIndicator
return;
}

SetTypingIndicatorEnabled(uid.Value, ev.IsTyping);
SetTypingIndicatorState(uid.Value, ev.State); // Corvax-TypingIndicator
}

private void SetTypingIndicatorEnabled(EntityUid uid, bool isEnabled, AppearanceComponent? appearance = null)
private void SetTypingIndicatorState(EntityUid uid, TypingIndicatorState state, AppearanceComponent? appearance = null) // Corvax-TypingIndicator
{
if (!Resolve(uid, ref appearance, false))
return;
// if (!Resolve(uid, ref appearance, false)) // Corvax-TypingIndicator
// return;

_appearance.SetData(uid, TypingIndicatorVisuals.IsTyping, isEnabled, appearance);
_appearance.SetData(uid, TypingIndicatorVisuals.State, state); // Corvax-TypingIndicator
}
}
8 changes: 5 additions & 3 deletions Content.Shared/Chat/TypingIndicator/TypingChangedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace Content.Shared.Chat.TypingIndicator;
[Serializable, NetSerializable]
public sealed class TypingChangedEvent : EntityEventArgs
{
public readonly bool IsTyping;
// Corvax-TypingIndicator-Start
public readonly TypingIndicatorState State;

public TypingChangedEvent(bool isTyping)
public TypingChangedEvent(TypingIndicatorState state)
{
IsTyping = isTyping;
State = state;
}
// Corvax-TypingIndicator-End
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public sealed partial class TypingIndicatorPrototype : IPrototype
[DataField("typingState", required: true)]
public string TypingState = default!;

// Corvax-TypingIndicator-Start
[DataField("idleState", required: true)]
public string IdleState = default!;
// Corvax-TypingIndicator-End

[DataField("offset")]
public Vector2 Offset = new(0, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Content.Shared.Chat.TypingIndicator;
[Serializable, NetSerializable]
public enum TypingIndicatorVisuals : byte
{
IsTyping
State, // Corvax-TypingIndicator
}

[Serializable]
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/Corvax/TypingIndicator/TypingIndicatorState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Robust.Shared.Serialization;

namespace Content.Shared.Chat.TypingIndicator;

[Serializable, NetSerializable]
public enum TypingIndicatorState
{
None = 0,
Idle = 1,
Typing = 2,
}
11 changes: 11 additions & 0 deletions Resources/Prototypes/typing_indicator.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,61 @@
- type: typingIndicator
id: default
typingState: default0
idleState: default3 # Corvax-TypingIndicator

- type: typingIndicator
id: robot
typingState: robot0
idleState: robot3 # Corvax-TypingIndicator

- type: typingIndicator
id: alien
typingState: alien0
idleState: alien3 # Corvax-TypingIndicator

- type: typingIndicator
id: guardian
typingState: guardian0
idleState: guardian3 # Corvax-TypingIndicator

- type: typingIndicator
id: holo
typingState: holo0
idleState: holo3 # Corvax-TypingIndicator
offset: 0, 0.0625

- type: typingIndicator
id: lawyer
typingState: lawyer0
idleState: lawyer3 # Corvax-TypingIndicator
offset: 0, 0.125

- type: typingIndicator
id: moth
typingState: moth0
idleState: moth3 # Corvax-TypingIndicator
offset: 0, 0.125

- type: typingIndicator
id: spider
typingState: spider0
idleState: spider3 # Corvax-TypingIndicator
offset: 0, 0.125

- type: typingIndicator
id: vox
typingState: vox0
idleState: vox3 # Corvax-TypingIndicator
offset: -0.125, 0.125

- type: typingIndicator
id: lizard
typingState: lizard0
idleState: lizard3 # Corvax-TypingIndicator
offset: 0, 0.0625

- type: typingIndicator
id: slime
typingState: slime0
idleState: slime3 # Corvax-TypingIndicator
offset: 0, 0.125
Loading