Skip to content

Commit

Permalink
feat: use orderbook package
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 committed Oct 2, 2024
1 parent ae100c5 commit d2b1fd6
Show file tree
Hide file tree
Showing 214 changed files with 2,569 additions and 16,545 deletions.
7 changes: 3 additions & 4 deletions Assets/Core/Xsolla/Browser/IInAppBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace Xsolla.Core
{
public interface IInAppBrowser
{
bool IsOpened { get; }

bool IsFullScreen { get; }
event Action OpenEvent;

event Action<BrowserCloseInfo> CloseEvent;
Expand All @@ -14,10 +17,6 @@ public interface IInAppBrowser

event Action<string, Action, Action> ConfirmDialogEvent;

bool IsOpened { get; }

bool IsFullScreen { get; }

void Open(string url);

void Close(float delay = 0f, bool isManually = false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ internal class CloseBrowserButton : MonoBehaviour

private void Start()
{
if (CloseButton != null)
{
CloseButton.onClick.AddListener(() => Destroy(gameObject, 0.01f));
}
if (CloseButton != null) CloseButton.onClick.AddListener(() => Destroy(gameObject, 0.01f));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class SinglePageBrowser2D : MonoBehaviour
[SerializeField] private Button CloseButton;
[SerializeField] private Button FullscreenButton;
[SerializeField] private Button BackButton;
[SerializeField] private Vector2Int Viewport = new Vector2Int(1920, 1080);
[SerializeField] private Vector2Int Viewport = new(1920, 1080);
[SerializeField] private GameObject PreloaderPrefab;

#pragma warning disable CS0067
Expand Down Expand Up @@ -58,10 +58,7 @@ private void Awake()
{
xsollaBrowser.Navigate.GetUrl(currentUrl =>
{
if (string.IsNullOrEmpty(urlBeforePopup))
{
urlBeforePopup = currentUrl;
}
if (string.IsNullOrEmpty(urlBeforePopup)) urlBeforePopup = currentUrl;
});
xsollaBrowser.Navigate.To(popupUrl, newUrl => { BackButton.gameObject.SetActive(true); });
});
Expand All @@ -83,7 +80,8 @@ private IEnumerator Start()
display.RedrawFrameCompleteEvent += DestroyPreloader;
display.RedrawFrameCompleteEvent += EnableCloseButton;
display.RedrawFrameCompleteEvent += EnableFullScreenButton;
display.ViewportChangedEvent += (width, height) => XDebug.Log("Display viewport changed: " + width + "x" + height);
display.ViewportChangedEvent += (width, height) =>
XDebug.Log("Display viewport changed: " + width + "x" + height);

mouse = this.GetOrAddComponent<Mouse2DBehaviour>();
keyboard = this.GetOrAddComponent<Keyboard2DBehaviour>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ namespace Xsolla.Core.Browser
{
internal class Display2DBehaviour : MonoBehaviour
{
private IXsollaBrowserRender xsollaRender;
public RawImage renderImage;
private IXsollaBrowserRender xsollaRender;

public Vector2Int CurrentRenderSize { get; private set; }

public event Action<int, int> ViewportChangedEvent;
public event Action RedrawFrameCompleteEvent;
public event Action FirstRedrawFrameCompleteEvent;

private IEnumerator Start()
{
if (!GetComponentInParent<Canvas>())
Expand All @@ -41,6 +37,10 @@ private void OnDestroy()
StopRedraw();
}

public event Action<int, int> ViewportChangedEvent;
public event Action RedrawFrameCompleteEvent;
public event Action FirstRedrawFrameCompleteEvent;

public void StartRedraw(int width, int height)
{
if (xsollaRender == null)
Expand Down Expand Up @@ -77,7 +77,6 @@ private IEnumerator RedrawCoroutine()
{
var isFirstRedraw = true;
while (enabled)
{
yield return ActionExtensions.WaitMethod<Texture2D>(
xsollaRender.To,
texture =>
Expand All @@ -95,7 +94,6 @@ private IEnumerator RedrawCoroutine()
isFirstRedraw = false;
}
});
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,34 @@ namespace Xsolla.Core.Browser
{
internal class Keyboard2DBehaviour : MonoBehaviour
{
private IXsollaBrowserKeyboardInput keyboardInput;

public event Action EscapePressed;

private static readonly List<KeyCode> SystemKeys = new List<KeyCode> {
private static readonly List<KeyCode> SystemKeys = new()
{
KeyCode.Escape
};

// @formatter:off
private static readonly Dictionary<KeyCode, string> ModificationKeys = new Dictionary<KeyCode, string>{
{KeyCode.LeftShift, "Shift"},
{KeyCode.RightShift, "Shift"},
{KeyCode.LeftAlt, "Alt"},
{KeyCode.RightAlt, "Alt"},
{KeyCode.LeftControl, "Control"},
{KeyCode.RightControl, "Control"}
private static readonly Dictionary<KeyCode, string> ModificationKeys = new()
{
{ KeyCode.LeftShift, "Shift" },
{ KeyCode.RightShift, "Shift" },
{ KeyCode.LeftAlt, "Alt" },
{ KeyCode.RightAlt, "Alt" },
{ KeyCode.LeftControl, "Control" },
{ KeyCode.RightControl, "Control" }
};

private static readonly Dictionary<KeyCode, string> NumpadKeys = new Dictionary<KeyCode, string>{
{KeyCode.Keypad0, "Digit0"},
{KeyCode.Keypad1, "Digit1"},
{KeyCode.Keypad2, "Digit2"},
{KeyCode.Keypad3, "Digit3"},
{KeyCode.Keypad4, "Digit4"},
{KeyCode.Keypad5, "Digit5"},
{KeyCode.Keypad6, "Digit6"},
{KeyCode.Keypad7, "Digit7"},
{KeyCode.Keypad8, "Digit8"},
{KeyCode.Keypad9, "Digit9"}
private static readonly Dictionary<KeyCode, string> NumpadKeys = new()
{
{ KeyCode.Keypad0, "Digit0" },
{ KeyCode.Keypad1, "Digit1" },
{ KeyCode.Keypad2, "Digit2" },
{ KeyCode.Keypad3, "Digit3" },
{ KeyCode.Keypad4, "Digit4" },
{ KeyCode.Keypad5, "Digit5" },
{ KeyCode.Keypad6, "Digit6" },
{ KeyCode.Keypad7, "Digit7" },
{ KeyCode.Keypad8, "Digit8" },
{ KeyCode.Keypad9, "Digit9" }
};
// @formatter:on

private static readonly List<KeyCode> AllKeyCodes = Enum.GetValues(typeof(KeyCode)).OfType<KeyCode>()
.Where(key => key < KeyCode.Mouse0)
Expand All @@ -47,17 +44,16 @@ internal class Keyboard2DBehaviour : MonoBehaviour
.Except(NumpadKeys.Keys)
.ToList();

private IXsollaBrowserKeyboardInput keyboardInput;

private void Awake()
{
keyboardInput = GetComponent<XsollaBrowser>().Input.Keyboard;
}

private void Update()
{
if (InputProxy.GetKeyUp(KeyCode.Escape))
{
EscapePressed?.Invoke();
}
if (InputProxy.GetKeyUp(KeyCode.Escape)) EscapePressed?.Invoke();

foreach (var pair in ModificationKeys)
{
Expand All @@ -69,10 +65,8 @@ private void Update()
}

foreach (var pair in NumpadKeys)
{
if (InputProxy.GetKeyDown(pair.Key))
keyboardInput.PressKey(pair.Value);
}

AllKeyCodes.ForEach(code =>
{
Expand All @@ -83,6 +77,14 @@ private void Update()
}
});
}

public event Action EscapePressed;

// @formatter:off



// @formatter:on
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

namespace Xsolla.Core.Browser
{
internal class Mouse2DBehaviour : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IScrollHandler
internal class Mouse2DBehaviour : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler,
IScrollHandler
{
private Canvas canvas;
private RectTransform selfRectTransform;

private IXsollaBrowserKeyboardInput browserKeyboard;
private IXsollaBrowserMouseInput browserMouse;
private Canvas canvas;
private Display2DBehaviour displayBehaviour;

private Coroutine mouseMovementCoroutine;
private RectTransform selfRectTransform;

private void Awake()
{
Expand All @@ -34,12 +34,15 @@ private void OnDestroy()
StopAllCoroutines();
}

void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
{
var mousePosition = CalculateBrowserMousePosition(eventData.position);
browserMouse.Click(mousePosition, pos => XDebug.Log("Click handled by: " + pos));
}

void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
{
if (mouseMovementCoroutine != null)
{
StopCoroutine(mouseMovementCoroutine);
}
if (mouseMovementCoroutine != null) StopCoroutine(mouseMovementCoroutine);

mouseMovementCoroutine = StartCoroutine(MouseMovementCoroutine());
}
Expand All @@ -53,12 +56,6 @@ void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
}
}

void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
{
var mousePosition = CalculateBrowserMousePosition(eventData.position);
browserMouse.Click(mousePosition, pos => XDebug.Log("Click handled by: " + pos));
}

void IScrollHandler.OnScroll(PointerEventData eventData)
{
var key = eventData.scrollDelta.y > 0
Expand All @@ -83,31 +80,31 @@ private IEnumerator MouseMovementCoroutine()

private IEnumerator Display2DInitializationCoroutine()
{
yield return new WaitWhile(() => displayBehaviour.CurrentRenderSize.x == 0 || displayBehaviour.CurrentRenderSize.y == 0);
yield return new WaitWhile(() =>
displayBehaviour.CurrentRenderSize.x == 0 || displayBehaviour.CurrentRenderSize.y == 0);
}

private IEnumerator MouseMovementCoroutine(Vector2 lastPosition, Vector2 mousePosition, Action<Vector2> callback = null)
private IEnumerator MouseMovementCoroutine(Vector2 lastPosition, Vector2 mousePosition,
Action<Vector2> callback = null)
{
if ((mousePosition - lastPosition).sqrMagnitude > 1.0f)
{
yield return ActionExtensions.WaitMethod(
browserMouse.MoveTo,
mousePosition,
pos => callback?.Invoke(pos)
);
}
else
{
yield return null;
}
}

private Vector2 CalculateBrowserMousePosition(Vector3 inputMousePosition)
{
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(selfRectTransform, inputMousePosition, canvas.worldCamera, out var point))
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(selfRectTransform, inputMousePosition,
canvas.worldCamera, out var point))
{
point += selfRectTransform.sizeDelta * 0.5f; // Transform's anchors in the center of the rect
point.y = displayBehaviour.CurrentRenderSize.y - point.y; // Browser's axis are differs from Unity's axis
point.y = displayBehaviour.CurrentRenderSize.y -
point.y; // Browser's axis are differs from Unity's axis
return point;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Xsolla.Core.Browser
internal class Preloader2DBehaviour : MonoBehaviour
{
private int lastProgress;
private object progressLocker;
private GameObject prefab;
private GameObject preloaderObject;
private object progressLocker;
private XsollaBrowser xsollaBrowser;
private GameObject prefab;

private void Awake()
{
Expand Down Expand Up @@ -64,7 +64,7 @@ private IEnumerator PreloaderCoroutine(int progress)
yield break;

if (progress < 99)
preloaderObject.GetComponent<PreloaderScript>().SetPercent((int)progress);
preloaderObject.GetComponent<PreloaderScript>().SetPercent(progress);
else
preloaderObject.GetComponent<PreloaderScript>().SetText(string.Empty);
}
Expand Down
13 changes: 5 additions & 8 deletions Assets/Core/Xsolla/Browser/XsollaBrowser/XsollaInAppBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ internal class XsollaInAppBrowser : MonoBehaviour, IInAppBrowser
[SerializeField] private GameObject BrowserPrefab;
[SerializeField] private bool IsDontDestroyOnLoad;
private GameObject BrowserObject;
private SinglePageBrowser2D SinglePageBrowser;
private XsollaBrowser XsollaBrowser;

private CanvasScaler CanvasScaler;
private Vector2 ScalerOriginalReferenceSize;
private Display2DBehaviour Display2DBehaviour;
private Vector2Int FramedModeDisplaySize;
private Vector2Int FullscreenModeDisplaySize;
private Display2DBehaviour Display2DBehaviour;
private Vector2 ScalerOriginalReferenceSize;
private SinglePageBrowser2D SinglePageBrowser;
private XsollaBrowser XsollaBrowser;

public event Action OpenEvent;
public event Action<BrowserCloseInfo> CloseEvent;
Expand Down Expand Up @@ -92,10 +92,7 @@ public void AddInitHandler(Action callback)

public void UpdateSize(int width, int height)
{
if (!IsFullScreen)
{
FramedModeDisplaySize = new Vector2Int(width, height);
}
if (!IsFullScreen) FramedModeDisplaySize = new Vector2Int(width, height);

if (IsOpened)
SinglePageBrowser.SetViewport(new Vector2Int(width, height));
Expand Down
4 changes: 2 additions & 2 deletions Assets/Core/Xsolla/Browser/XsollaWebBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using UnityEngine;
#if UNITY_WEBGL || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
using System.Runtime.InteropServices;
#endif

namespace Xsolla.Core
Expand Down Expand Up @@ -48,7 +46,9 @@ public static void Open(string url, bool forcePlatformBrowser = false)
InAppBrowser.AddInitHandler(() => InAppBrowser.UpdateSize(450, 760));
}
else
{
Application.OpenURL(url);
}
#elif UNITY_WEBGL
#pragma warning disable 0618
Application.ExternalEval($"window.open(\"{url}\",\"_blank\")");
Expand Down
2 changes: 1 addition & 1 deletion Assets/Core/Xsolla/Entities/BrowserCloseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ public class BrowserCloseInfo
// Whether the browser is closed manually by a user.
public bool isManually;
}
}
}
Loading

0 comments on commit d2b1fd6

Please sign in to comment.