Skip to content

Commit 9940ab8

Browse files
authored
Toast Overlay Type Implemented (#1256)
* Remember me behaviour fixed - do you remember, the firs night of ...september * toast added as gui overlay * connection modal not prompting issue fixed
1 parent 15d6486 commit 9940ab8

File tree

10 files changed

+811
-93
lines changed

10 files changed

+811
-93
lines changed

Packages/io.chainsafe.web3-unity/Runtime/GUI/GuiInfoOverlay.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ namespace ChainSafe.Gaming.GUI
88
public class GuiInfoOverlay : MonoBehaviour
99
{
1010
public TMP_Text Message;
11+
public TMP_Text ToastMessage;
1112
public GameObject ErrorIcon;
1213
public GameObject LoadingIcon;
1314
public Button CloseButton;
1415

16+
public Transform Container;
17+
public Transform ToastContainer;
18+
1519
private bool closeOnClick;
1620
private Action onClose;
1721
private Action<GuiInfoOverlay> onRelease;
18-
22+
1923
public int Id { get; private set; }
2024

2125
private void Awake()
@@ -30,9 +34,20 @@ public void Initialize(int id, GuiOverlayType type, string message, bool closeOn
3034
this.closeOnClick = closeOnClick;
3135
onRelease = release;
3236

37+
Container.gameObject.SetActive(type != GuiOverlayType.Toast);
38+
ToastContainer.gameObject.SetActive(type == GuiOverlayType.Toast);
39+
3340
ErrorIcon.SetActive(type == GuiOverlayType.Error);
3441
LoadingIcon.SetActive(type == GuiOverlayType.Loading);
35-
Message.text = message;
42+
43+
if (type != GuiOverlayType.Toast)
44+
{
45+
Message.text = message;
46+
}
47+
else
48+
{
49+
ToastMessage.text = message;
50+
}
3651
}
3752

3853
public void UpdateMessage(string message)
@@ -52,6 +67,13 @@ private void OnScreenClick()
5267

5368
internal void Hide()
5469
{
70+
// Already hidden,
71+
// this happens when the close button and the OnScreenClick button references are the same (tries to hide twice)
72+
if (!gameObject.activeSelf)
73+
{
74+
return;
75+
}
76+
5577
gameObject.SetActive(false); // replace with animation
5678
onClose?.Invoke();
5779
onRelease(this);

Packages/io.chainsafe.web3-unity/Runtime/GUI/GuiOverlayManager.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45
using UnityEngine.Pool;
@@ -14,21 +15,34 @@ public class GuiOverlayManager : MonoBehaviour
1415

1516
private ObjectPool<GuiInfoOverlay> pool;
1617

17-
private int overlayCounter = 1000; // offset to detect when default integer value is sent to one of the methods
18+
private int _overlayCounter = 1000; // offset to detect when default integer value is sent to one of the methods
1819

20+
private Coroutine _hideCoroutine;
21+
1922
private void Awake()
2023
{
2124
pool = new ObjectPool<GuiInfoOverlay>(CreateOverlay, InitOverlay, ReleaseOverlay, defaultCapacity: 2);
2225
}
2326

24-
public int Show(GuiOverlayType type, string message, bool deactivateOnClick, Action onClose = null)
27+
public int Show(GuiOverlayType type, string message, bool deactivateOnClick, Action onClose = null, float timeOut = 0)
2528
{
2629
var overlay = pool.Get();
2730
activeOverlays.Add(overlay);
28-
overlay.Initialize(overlayCounter++, type, message, deactivateOnClick, onClose, OnReleaseRequested);
31+
overlay.Initialize(_overlayCounter++, type, message, deactivateOnClick, onClose, OnReleaseRequested);
32+
if (timeOut > 0)
33+
{
34+
_hideCoroutine = StartCoroutine(Hide(overlay.Id, timeOut));
35+
}
2936
return overlay.Id;
3037
}
3138

39+
private IEnumerator Hide(int overlayId, float timeout)
40+
{
41+
yield return new WaitForSeconds(timeout);
42+
43+
Hide(overlayId);
44+
}
45+
3246
public void Hide(int overlayId)
3347
{
3448
var overlay = activeOverlays.Find(o => o.Id == overlayId);
@@ -68,13 +82,21 @@ private void ReleaseOverlay(GuiInfoOverlay overlay)
6882

6983
private void OnReleaseRequested(GuiInfoOverlay overlay)
7084
{
85+
if (_hideCoroutine != null)
86+
{
87+
StopCoroutine(_hideCoroutine);
88+
89+
_hideCoroutine = null;
90+
}
91+
7192
pool.Release(overlay);
7293
}
7394
}
7495

7596
public enum GuiOverlayType
7697
{
7798
Error,
78-
Loading
99+
Loading,
100+
Toast
79101
}
80102
}

0 commit comments

Comments
 (0)