Skip to content

Commit 4d4f4d0

Browse files
committed
Added Enter hotkey for chat auto-focus, snap chat to bottom by default
1 parent 89a2c5b commit 4d4f4d0

File tree

5 files changed

+56
-17
lines changed

5 files changed

+56
-17
lines changed

Assets/Prefabs/UI/Panels/Battle Hud/Chat Frame.prefab

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ MonoBehaviour:
792792
type: 3}
793793
inputField: {fileID: 8124448700723823767}
794794
messageContainer: {fileID: 8966246736871185839}
795+
chatFocusHotkey: {fileID: 11400000, guid: 412f7345114c7a24bac24d0397c6f7de, type: 2}
795796
maxMessageCount: 100
796797
--- !u!1 &4434901819018536284
797798
GameObject:
@@ -1144,14 +1145,14 @@ RectTransform:
11441145
m_LocalPosition: {x: 0, y: 0, z: 0}
11451146
m_LocalScale: {x: 1, y: 1, z: 1}
11461147
m_Children:
1147-
- {fileID: 6277869051170347521}
1148-
- {fileID: 927985667396716179}
1149-
- {fileID: 2487816022636992502}
1150-
- {fileID: 8645664843004911884}
1151-
- {fileID: 6455393061946713254}
1152-
- {fileID: 8020618027106429412}
1153-
- {fileID: 4185472310781771014}
1154-
- {fileID: 1160691107835938544}
1148+
- {fileID: 537756131432457551}
1149+
- {fileID: 6668099274328865245}
1150+
- {fileID: 8281971847993567416}
1151+
- {fileID: 2851504963200785986}
1152+
- {fileID: 720346350325488616}
1153+
- {fileID: 4550873542131537578}
1154+
- {fileID: 7673234492804153928}
1155+
- {fileID: 4643946310078609854}
11551156
m_Father: {fileID: 1477925438819891376}
11561157
m_RootOrder: 0
11571158
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -1983,7 +1984,7 @@ PrefabInstance:
19831984
objectReference: {fileID: 0}
19841985
m_RemovedComponents: []
19851986
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
1986-
--- !u!224 &927985667396716179 stripped
1987+
--- !u!224 &6668099274328865245 stripped
19871988
RectTransform:
19881989
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
19891990
type: 3}
@@ -2176,7 +2177,7 @@ PrefabInstance:
21762177
objectReference: {fileID: 0}
21772178
m_RemovedComponents: []
21782179
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
2179-
--- !u!224 &1160691107835938544 stripped
2180+
--- !u!224 &4643946310078609854 stripped
21802181
RectTransform:
21812182
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
21822183
type: 3}
@@ -2359,7 +2360,7 @@ PrefabInstance:
23592360
objectReference: {fileID: 0}
23602361
m_RemovedComponents: []
23612362
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
2362-
--- !u!224 &2487816022636992502 stripped
2363+
--- !u!224 &8281971847993567416 stripped
23632364
RectTransform:
23642365
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
23652366
type: 3}
@@ -2552,7 +2553,7 @@ PrefabInstance:
25522553
objectReference: {fileID: 0}
25532554
m_RemovedComponents: []
25542555
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
2555-
--- !u!224 &4185472310781771014 stripped
2556+
--- !u!224 &7673234492804153928 stripped
25562557
RectTransform:
25572558
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
25582559
type: 3}
@@ -2743,7 +2744,7 @@ PrefabInstance:
27432744
objectReference: {fileID: 0}
27442745
m_RemovedComponents: []
27452746
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
2746-
--- !u!224 &6277869051170347521 stripped
2747+
--- !u!224 &537756131432457551 stripped
27472748
RectTransform:
27482749
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
27492750
type: 3}
@@ -2936,7 +2937,7 @@ PrefabInstance:
29362937
objectReference: {fileID: 0}
29372938
m_RemovedComponents: []
29382939
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
2939-
--- !u!224 &6455393061946713254 stripped
2940+
--- !u!224 &720346350325488616 stripped
29402941
RectTransform:
29412942
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
29422943
type: 3}
@@ -3129,7 +3130,7 @@ PrefabInstance:
31293130
objectReference: {fileID: 0}
31303131
m_RemovedComponents: []
31313132
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
3132-
--- !u!224 &8020618027106429412 stripped
3133+
--- !u!224 &4550873542131537578 stripped
31333134
RectTransform:
31343135
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
31353136
type: 3}
@@ -3317,7 +3318,7 @@ PrefabInstance:
33173318
objectReference: {fileID: 0}
33183319
m_RemovedComponents: []
33193320
m_SourcePrefab: {fileID: 100100000, guid: 14aef5c8a7943ff42b18259651c0069c, type: 3}
3320-
--- !u!224 &8645664843004911884 stripped
3321+
--- !u!224 &2851504963200785986 stripped
33213322
RectTransform:
33223323
m_CorrespondingSourceObject: {fileID: 5794170065339070002, guid: 14aef5c8a7943ff42b18259651c0069c,
33233324
type: 3}

Assets/Scripts/Client/UI/Chat/ChatFrame.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ public class ChatFrame : MonoBehaviour
1515
[SerializeField, UsedImplicitly] private ChatFrameMessage messagePrototype;
1616
[SerializeField, UsedImplicitly] private TMP_InputField inputField;
1717
[SerializeField, UsedImplicitly] private Transform messageContainer;
18+
[SerializeField, UsedImplicitly] private HotkeyInputItem chatFocusHotkey;
1819
[SerializeField, UsedImplicitly] private int maxMessageCount = 100;
1920

2021
private readonly List<ChatFrameMessage> chatMessages = new List<ChatFrameMessage>();
2122
private const float BottomSnapThreshold = 0.001f;
2223

2324
[UsedImplicitly]
24-
public bool SnapToBottom { get; set; }
25+
public bool SnapToBottom { get; set; } = true;
2526

2627
[UsedImplicitly]
2728
private void Awake()
2829
{
2930
EventHandler.RegisterEvent<Unit, string>(EventHandler.GlobalDispatcher, GameEvents.UnitChat, OnUnitChat);
31+
EventHandler.RegisterEvent<HotkeyState>(chatFocusHotkey, GameEvents.HotkeyStateChanged, OnHotkeyStateChanged);
3032
inputField.onSubmit.AddListener(OnSubmit);
3133
inputField.onDeselect.AddListener(OnDeselect);
34+
3235
GameObjectPool.PreInstantiate(messagePrototype, maxMessageCount);
3336
}
3437

@@ -42,6 +45,7 @@ private void OnDestroy()
4245
inputField.onSubmit.RemoveListener(OnSubmit);
4346
inputField.onDeselect.RemoveListener(OnDeselect);
4447
EventHandler.UnregisterEvent<Unit, string>(EventHandler.GlobalDispatcher, GameEvents.UnitChat, OnUnitChat);
48+
EventHandler.UnregisterEvent<HotkeyState>(chatFocusHotkey, GameEvents.HotkeyStateChanged, OnHotkeyStateChanged);
4549
}
4650

4751
[UsedImplicitly]
@@ -88,4 +92,11 @@ private void OnUnitChat(Unit unit, string text)
8892
if (scrollRect.verticalNormalizedPosition < BottomSnapThreshold)
8993
SnapToBottom = true;
9094
}
95+
96+
private void OnHotkeyStateChanged(HotkeyState state)
97+
{
98+
if (enabled && state == HotkeyState.Pressed)
99+
if (EventSystem.current.currentSelectedGameObject != inputField.gameObject)
100+
EventSystem.current.SetSelectedGameObject(inputField.gameObject);
101+
}
91102
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 693374c076b9a4144ac7666774b98408, type: 3}
13+
m_Name: Hotkey Item - Chat
14+
m_EditorClassIdentifier:
15+
input: {fileID: 11400000, guid: 899dff3e7662461489d8d3e369ab42b3, type: 2}
16+
id: Chat
17+
key: 13
18+
modifier: 0

Assets/Settings/Input/Hotkeys/Hotkey Item - Chat.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Settings/References/Input Reference.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ MonoBehaviour:
4646
- {fileID: 11400000, guid: d7029a586e5687440a208820189b7a3a, type: 2}
4747
- {fileID: 11400000, guid: c0bb9a66c02cfdd4b8d83cf8991f31ac, type: 2}
4848
- {fileID: 11400000, guid: a6cd36790a3049c4091e8fa84d6fec40, type: 2}
49+
- {fileID: 11400000, guid: 412f7345114c7a24bac24d0397c6f7de, type: 2}
4950
- {fileID: 11400000, guid: ff5d98c2d16456041af98fc9b4d7fe53, type: 2}
5051
- {fileID: 11400000, guid: 9abae26f4faad9744a592b4c0e0d6507, type: 2}
5152
- {fileID: 11400000, guid: 9039a6be9ba381c4b90e3d0f02624b6a, type: 2}

0 commit comments

Comments
 (0)