Skip to content
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
19 changes: 19 additions & 0 deletions Assets/JSPlugin/JSBridge.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ mergeInto(LibraryManager.library, {
'*'
)
},
OnAvatarCustomizationStep: function (step) {
const targetWindow = (() => {
try {
return window.self !== window.top ? window : window.parent
} catch (e) {
return window.parent
}
})()
targetWindow.postMessage(
{
type: 'unity-renderer',
payload: {
type: 'avatar-customization-step',
payload: step,
},
},
'*'
)
},
PreloadURLs: function(strPtr) {
const csv = UTF8ToString(strPtr);
const urls = csv.split(',');
Expand Down
9 changes: 0 additions & 9 deletions Assets/Scripts/AangConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,6 @@ public void SetEyeColor(string value)
/// </summary>
public bool UninterruptedDeferAgent { get; set; } = !Application.isMobilePlatform;

/// <summary>
/// Shows the enter name stage at the start of avatar customization.
/// </summary>
public bool ShowEnterName { get; set; }

public static void RecreateFrom(string url)
{
Instance = new AangConfiguration();
Expand Down Expand Up @@ -317,9 +312,6 @@ public static void RecreateFrom(string url)
case "uninterruptedDeferAgent":
Instance.UninterruptedDeferAgent = bool.Parse(value);
break;
case "showEnterName":
Instance.ShowEnterName = bool.Parse(value);
break;
default:
Debug.LogWarning($"Unknown parameter in URL: {key}");
break;
Expand Down Expand Up @@ -362,7 +354,6 @@ public override string ToString()
sb.AppendFormat("&showFPS={0}", ShowFPS);
sb.AppendFormat("&sequentialLoad={0}", ConcurrentLoad);
sb.AppendFormat("&useUninterruptedDeferAgent={0}", UninterruptedDeferAgent);
sb.AppendFormat("&showEnterName={0}", ShowEnterName);

return sb.ToString();
}
Expand Down
11 changes: 9 additions & 2 deletions Assets/Scripts/Configurator/ConfiguratorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private void Start()
uiPresenter.CharacterAreaDrag += dragRotator.OnDrag;
uiPresenter.Confirmed += OnConfirmed;
uiPresenter.JumpIn += OnJumpIn;
uiPresenter.AvatarCustomizationStepChanged += OnAvatarCustomizationStepChanged;

StartCoroutine(InitialLoad());
}
Expand Down Expand Up @@ -90,7 +91,12 @@ private void OnConfirmed(bool open)
platform.SetActive(!open);
}

private void OnJumpIn()
private static void OnAvatarCustomizationStepChanged(int step)
{
JSBridge.NativeCalls.OnAvatarCustomizationStep(step);
}

private void OnJumpIn(bool skipped)
{
JSBridge.NativeCalls.OnCustomizationDone(JsonUtility.ToJson(new AvatarCustomizationConfig(
_bodyShape == BodyShape.Male
Expand All @@ -99,7 +105,8 @@ private void OnJumpIn()
_eyeColor,
_skinColor,
_hairColor,
_selectedItems.Values.Select(ed => ed.URN).ToList()
_selectedItems.Values.Select(ed => ed.URN).ToList(),
skipped
)));
}

Expand Down
103 changes: 54 additions & 49 deletions Assets/Scripts/Configurator/ConfiguratorUIPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using Configurator.Views;
using Data;
using JetBrains.Annotations;
using Runtime.Wearables;
using UI.Elements;
using UI.Manipulators;
Expand All @@ -15,20 +14,17 @@ namespace Configurator
public class ConfiguratorUIPresenter : MonoBehaviour
{
private const string USS_CUSTOMIZE_CONTAINER_HIDDEN = "customize-container--hidden";
private const string USS_ENTER_NAME_HIDDEN = "enter-name-container--hidden";
private const string USS_CONFIRMATION_CONTAINER_HIDDEN = "confirmation-container--hidden";

[SerializeField] private UIDocument uiDocument;

private VisualElement _customizeContainer;
private VisualElement _loader;
private VisualElement _loaderIcon;

private VisualElement _enterNameContainer;

private DCLButtonElement _backButton;
private DCLButtonElement _skipButton;
private DCLButtonElement _confirmButton;
private DCLButtonElement _secondaryButton;
private DCLButtonElement _primaryButton;

private Label _stageTitle;
private Label _stageNumber;
Expand All @@ -41,11 +37,9 @@ public class ConfiguratorUIPresenter : MonoBehaviour
private string _username;

// Views
private EnterNameView _enterNameView;
private WearablesView _headWearablesView;
private WearablesView _bodyWearablesView;
private PresetsView _presetsView;
private ConfirmPopupView _confirmPopupView;
private BodyShapePopupView _bodyShapePopupView;
private ColorPopupView _skinColorPopupView;
private ColorPopupView _hairColorPopupView;
Expand All @@ -65,7 +59,8 @@ public class ConfiguratorUIPresenter : MonoBehaviour
public event Action<string, EntityDefinition> WearableSelected;
public event Action<PresetDefinition> PresetSelected;
public event Action<bool> Confirmed;
public event Action JumpIn;
public event Action<bool> JumpIn;
public event Action<int> AvatarCustomizationStepChanged;

private bool _confirmationOpen;
private bool _usingMobile;
Expand All @@ -81,12 +76,6 @@ private void OnEnable()
_customizeContainer = root.Q("CustomizeContainer");
var characterArea = _customizeContainer.Q("CharacterArea");

// Enter name
_enterNameContainer = root.Q("EnterNameContainer");
_enterNameView = new EnterNameView(_enterNameContainer);
_enterNameView.Confirmed += OnNameConfirmed;
ShowEnterName(AangConfiguration.Instance.ShowEnterName);

characterArea.RegisterCallback<GeometryChangedEvent, VisualElement>((_, area) =>
{
if (_confirmationOpen) return;
Expand All @@ -113,23 +102,24 @@ private void OnEnable()
_stageNumber = root.Q<Label>("StageNumber");

_backButton = root.Q<DCLButtonElement>("BackButton");
_skipButton = root.Q<DCLButtonElement>("SkipButton");
_confirmButton = root.Q<DCLButtonElement>("ConfirmButton");
_secondaryButton = root.Q<DCLButtonElement>("SecondaryButton");
_primaryButton = root.Q<DCLButtonElement>("PrimaryButton");

_backButton.Clicked += OnBackClicked;
_confirmButton.Clicked += OnNextClicked;
_skipButton.Clicked += () => OpenConfirm(true);
_primaryButton.Clicked += OnPrimaryClicked;
_secondaryButton.Clicked += OnSecondaryClicked;

_loader = root.Q("Loader");
_loaderIcon = _loader.Q("Icon");

var presetsContainer = root.Q("Presets");
_presetsView = new PresetsView(presetsContainer,
"Choose {0}'s starting look",
"START CUSTOMIZING",
"CUSTOMIZE LATER",
221,
"START",
true);
"CUSTOMIZE LATER",
"START CUSTOMIZATION",
"START");
_presetsView.PresetSelected += preset => PresetSelected!(preset);

// Dropdowns
Expand All @@ -148,8 +138,7 @@ private void OnEnable()
"Customize {0}'s face",
"CUSTOMIZE OUTFIT",
209,
"OUTFIT",
true);
"OUTFIT");
_headWearablesView.WearableSelected += (c, ae) => WearableSelected!(c, ae);
_headWearablesView.CategoryChanged += c => CategoryChanged!(c);
_headWearablesView.ColorSelected += c =>
Expand All @@ -170,8 +159,7 @@ private void OnEnable()
"Customize {0}'s outfit",
"FINISH",
123,
"FINISH",
false);
"FINISH");
_bodyWearablesView.WearableSelected += (c, ae) => WearableSelected!(c, ae);
_bodyWearablesView.CategoryChanged += c => CategoryChanged!(c);

Expand All @@ -186,7 +174,7 @@ private void OnEnable()
_confirmContainer = root.Q("ConfirmationContainer");
_confirmTitle = _confirmContainer.Q<Label>("Title");
_confirmContainer.Q<DCLButtonElement>("ConfirmationBackButton").Clicked += () => OpenConfirm(false);
_confirmContainer.Q<DCLButtonElement>("JumpInButton").Clicked += () => JumpIn!();
_confirmContainer.Q<DCLButtonElement>("JumpInButton").Clicked += () => JumpIn!(false);

// Debug FPS Counter
_fpsCounter = root.Q<Label>("FPSCounter");
Expand Down Expand Up @@ -225,19 +213,6 @@ private void OnEnable()
RefreshCurrentStage();
}

private void OnNameConfirmed(string username, [CanBeNull] string email)
{
_username = username;
ShowEnterName(false);
RefreshCurrentStage();
}

private void ShowEnterName(bool show)
{
_customizeContainer.EnableInClassList(USS_CUSTOMIZE_CONTAINER_HIDDEN, show);
_enterNameContainer.EnableInClassList(USS_ENTER_NAME_HIDDEN, !show);
}

private void OnDisable()
{
if (!Application.isEditor) return;
Expand Down Expand Up @@ -265,20 +240,46 @@ private void OnBackClicked()
_stages[--_currentStageIndex].Show();

RefreshCurrentStage();
AvatarCustomizationStepChanged?.Invoke(_currentStageIndex);
}

private void OnNextClicked()
private void OnPrimaryClicked()
{
// The next button on the first stage (presets) functions as "skip"
if (_currentStageIndex == 0)
{
JumpIn!(true);
return;
}

if (_currentStageIndex == _stages.Length - 1)
{
OpenConfirm(true);
JumpIn!(false);
return;
}

AdvanceStage();
}

private void OnSecondaryClicked()
{
// The skip button on the first stage (presets) functions as "next"
if (_currentStageIndex == 0)
{
AdvanceStage();
return;
}

JumpIn!(true);
}

private void AdvanceStage()
{
_stages[_currentStageIndex].HideLeft();
_stages[++_currentStageIndex].Show();

RefreshCurrentStage();
AvatarCustomizationStepChanged?.Invoke(_currentStageIndex);
}

private void OpenConfirm(bool open)
Expand All @@ -297,27 +298,30 @@ private void RefreshCurrentStage()
var stage = _stages[_currentStageIndex];
_stageTitle.text = string.Format(stage.Title, _username);
_stageNumber.text = $"{_currentStageIndex + 1}.";
_confirmButton.Text = _usingMobile ? stage.ConfirmButtonTextMobile : stage.ConfirmButtonText;
_primaryButton.Text = _usingMobile ? stage.PrimaryButtonTextMobile : stage.PrimaryButtonText;

stage.SetUsingMobileMode(_usingMobile);

// No animations on mobile
if (_usingMobile)
{
_confirmButton.style.width = StyleKeyword.Auto;
_primaryButton.style.width = StyleKeyword.Auto;
}
else
{
_confirmButton.style.width = stage.ConfirmButtonWidth;
_primaryButton.style.width = stage.PrimaryButtonWidth;
}

_confirmButton.ButtonIcon = _currentStageIndex == _stages.Length - 1
_primaryButton.ButtonIcon = _currentStageIndex == _stages.Length - 1
? DCLButtonElement.Icon.Check
: DCLButtonElement.Icon.Forward;

_skipButton.EnableInClassList("dcl-button--hidden-down",
!stage.CanSkip || _usingMobile && _currentStageIndex != 0);
_skipButton.Text = _usingMobile ? "SKIP" : "SKIP CUSTOMIZATION";
var secondaryText = _usingMobile ? stage.SecondaryButtonTextMobile : stage.SecondaryButtonText;
var showSecondary = secondaryText != null;
_secondaryButton.EnableInClassList("dcl-button--hidden-down", !showSecondary);
if(secondaryText != null) _secondaryButton.Text = secondaryText;
_secondaryButton.pickingMode = showSecondary ? PickingMode.Position : PickingMode.Ignore;

_backButton.EnableInClassList("dcl-button--hidden-down", _currentStageIndex == 0);

// TODO: Change?
Expand All @@ -341,6 +345,7 @@ public void LoadCompleted()
RefreshCurrentStage();
_customizeContainer.SetVisibility(true);
_loader.SetDisplay(false);
AvatarCustomizationStepChanged?.Invoke(_currentStageIndex);
}

public void SetUsingMobileMode(bool usingMobile)
Expand Down
34 changes: 0 additions & 34 deletions Assets/Scripts/Configurator/Views/ConfirmPopupView.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/Scripts/Configurator/Views/ConfirmPopupView.cs.meta

This file was deleted.

Loading