Skip to content

Commit 11f7615

Browse files
author
Jannify
authored
> Added fade out if input field text is "" > Switched from resetting position if out of bounds to "border" (SubnauticaNitrox#1056)
1 parent 8ec8989 commit 11f7615

5 files changed

Lines changed: 32 additions & 22 deletions

File tree

AssetBundles/chatlog

6 Bytes
Binary file not shown.

NitroxClient/MonoBehaviours/Gui/Chat/PlayerChat.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class PlayerChat : uGUI_InputGroup
1313
private const int LINE_CHAR_LIMIT = 255;
1414
private const int MESSAGES_LIMIT = 64;
1515
private const float TOGGLED_TRANSPARENCY = 0.4f;
16-
public const float CHAT_VISIBILITY_TIME_LENGTH = 10f;
16+
public const float CHAT_VISIBILITY_TIME_LENGTH = 6f;
1717

1818
private static readonly Queue<ChatLogEntry> entries = new Queue<ChatLogEntry>();
1919
private Image[] backgroundImages;
@@ -37,7 +37,6 @@ public IEnumerator SetupChatComponents()
3737
playerChatManager = NitroxServiceLocator.LocateService<PlayerChatManager>();
3838

3939
canvasGroup = GetComponent<CanvasGroup>();
40-
GetComponentsInChildren<HorizontalOrVerticalLayoutGroup>();
4140

4241
logEntryPrefab = GameObject.Find("ChatLogEntryPrefab");
4342
logEntryPrefab.AddComponent<PlayerChatLogItem>();

NitroxClient/MonoBehaviours/Gui/Chat/PlayerChatInputField.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ private void Update()
4545
return;
4646
}
4747

48-
if (selected)
48+
if (selected && InputField.text != "")
4949
{
50+
ResetTimer();
5051
if (UnityEngine.Input.GetKey(KeyCode.Return))
5152
{
5253
if (UnityEngine.Input.GetKey(KeyCode.LeftShift))

NitroxClient/MonoBehaviours/Gui/Chat/PlayerChatPinButton.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ public class PlayerChatPinButton : MonoBehaviour, IPointerDownHandler, IPointerU
99
{
1010
private static PlayerChatManager playerChatManager;
1111

12-
private Vector2 screenRes = new Vector2(1920, 1200);
12+
private readonly Camera mainCamera = Camera.main;
13+
private Vector2 screenRes = new Vector2(1920f, 1200f);
14+
private Vector2 chatSize;
15+
private Vector4 screenBorder;
1316
private Vector2 offset;
1417
private bool drag;
1518

1619
private void Awake()
1720
{
1821
playerChatManager = NitroxServiceLocator.LocateService<PlayerChatManager>();
22+
chatSize = transform.parent.parent.GetComponent<RectTransform>().sizeDelta;
1923
}
2024

2125
public void OnPointerDown(PointerEventData eventData)
2226
{
2327
screenRes.y = (screenRes.x / Screen.width) * Screen.height;
24-
offset = GetMouseWorldPostion() - (Vector2)playerChatManager.PlayerChaTransform.localPosition;
28+
offset = GetMouseWorldPosition() - (Vector2)playerChatManager.PlayerChaTransform.localPosition;
29+
screenBorder = new Vector4(-(screenRes.x - chatSize.x) / 2f, (screenRes.x - chatSize.x) / 2f, -(screenRes.y - chatSize.y) / 2f, (screenRes.y - chatSize.y) / 2f);
2530

2631
drag = true;
2732
PlayerChatInputField.FreezeTime = true;
@@ -32,25 +37,30 @@ public void OnPointerUp(PointerEventData eventData)
3237
drag = false;
3338
PlayerChatInputField.FreezeTime = false;
3439
PlayerChatInputField.ResetTimer();
35-
36-
if (Mathf.Abs(playerChatManager.PlayerChaTransform.localPosition.x * 2) >= screenRes.x || Mathf.Abs(playerChatManager.PlayerChaTransform.localPosition.y * 2) >= screenRes.y)
37-
{
38-
playerChatManager.PlayerChaTransform.localPosition = new Vector3(-500, 125, 0);
39-
}
4040
}
4141

42-
private void FixedUpdate()
42+
private void Update()
4343
{
4444
if (drag)
4545
{
46-
playerChatManager.PlayerChaTransform.localPosition = GetMouseWorldPostion() - offset;
46+
playerChatManager.PlayerChaTransform.localPosition = GetChatPosition();
4747
}
4848
}
4949

50-
private Vector2 GetMouseWorldPostion()
50+
private Vector2 GetMouseWorldPosition()
51+
{
52+
Vector3 position = mainCamera.ScreenToViewportPoint(UnityEngine.Input.mousePosition);
53+
position.x = (position.x - 0.5f) * screenRes.x;
54+
position.y = (position.y - 0.5f) * screenRes.y;
55+
return position;
56+
}
57+
58+
private Vector2 GetChatPosition()
5159
{
52-
Vector3 viewport = Camera.main.ScreenToViewportPoint(UnityEngine.Input.mousePosition);
53-
return new Vector2((viewport.x - 0.5f) * screenRes.x, (viewport.y - 0.5f) * screenRes.y);
60+
Vector2 position = GetMouseWorldPosition() - offset;
61+
position.x = Mathf.Clamp(position.x, screenBorder.x, screenBorder.y);
62+
position.y = Mathf.Clamp(position.y, screenBorder.z, screenBorder.w);
63+
return position;
5464
}
5565
}
5666
}

NitroxUnity/Assets/chatlog/chatlog.unity

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ RectTransform:
281281
m_AnchorMin: {x: 0, y: 0}
282282
m_AnchorMax: {x: 1, y: 1}
283283
m_AnchoredPosition: {x: 0, y: 65}
284-
m_SizeDelta: {x: 0, y: -65}
284+
m_SizeDelta: {x: 0, y: -90}
285285
m_Pivot: {x: 0, y: 0}
286286
--- !u!222 &123268637
287287
CanvasRenderer:
@@ -887,8 +887,8 @@ RectTransform:
887887
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
888888
m_AnchorMin: {x: 0, y: 0}
889889
m_AnchorMax: {x: 1, y: 1}
890-
m_AnchoredPosition: {x: 0, y: 0}
891-
m_SizeDelta: {x: 0, y: 0}
890+
m_AnchoredPosition: {x: 0, y: -12.5}
891+
m_SizeDelta: {x: 0, y: -25}
892892
m_Pivot: {x: 0.5, y: 0.5}
893893
--- !u!114 &585940677
894894
MonoBehaviour:
@@ -963,8 +963,8 @@ RectTransform:
963963
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
964964
m_AnchorMin: {x: 0.5, y: 0.5}
965965
m_AnchorMax: {x: 0.5, y: 0.5}
966-
m_AnchoredPosition: {x: -700, y: -75}
967-
m_SizeDelta: {x: 450, y: 375}
966+
m_AnchoredPosition: {x: -700, y: -50}
967+
m_SizeDelta: {x: 450, y: 400}
968968
m_Pivot: {x: 0.5, y: 0.5}
969969
--- !u!225 &695062224
970970
CanvasGroup:
@@ -1448,8 +1448,8 @@ RectTransform:
14481448
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
14491449
m_AnchorMin: {x: 0, y: 0}
14501450
m_AnchorMax: {x: 1, y: 1}
1451-
m_AnchoredPosition: {x: 0, y: 12.499939}
1452-
m_SizeDelta: {x: 0, y: 25}
1451+
m_AnchoredPosition: {x: 0, y: 0}
1452+
m_SizeDelta: {x: 0, y: 0}
14531453
m_Pivot: {x: 0.5, y: 0.5}
14541454
--- !u!114 &1496498126
14551455
MonoBehaviour:

0 commit comments

Comments
 (0)