示例#1
0
    public void LoadEvent(EventMeta meta)
    {
        async UniTask LoadCover(CancellationToken token)
        {
            Assert.IsNotNull(meta.cover);

            var tasks = new List <UniTask>();

            if (coverImage.sprite != null)
            {
                coverImage.DOKill();
                coverImage.DOColor(Color.black, 0.4f);
                tasks.Add(UniTask.Delay(TimeSpan.FromSeconds(0.4f), cancellationToken: token));
            }

            Sprite sprite = null;

            tasks.Add(Context.AssetMemory.LoadAsset <Sprite>(meta.cover.OriginalUrl, AssetTag.EventCover, cancellationToken: token).ContinueWith(result => sprite = result));

            try
            {
                await tasks;
            }
            catch (OperationCanceledException)
            {
                return;
            }

            coverImage.sprite = sprite;
            coverImage.FitSpriteAspectRatio();
            coverImage.DOColor(Color.white, 2f).SetDelay(0.8f);
        }

        async UniTask LoadLogo(CancellationToken token)
        {
            Assert.IsNotNull(meta.logo);

            var tasks = new List <UniTask>();

            if (logoImage.sprite != null)
            {
                logoImage.DOKill();
                logoImage.DOFade(0, 0.4f);
                tasks.Add(UniTask.Delay(TimeSpan.FromSeconds(0.4f), cancellationToken: token));
            }

            Sprite sprite = null;

            tasks.Add(Context.AssetMemory.LoadAsset <Sprite>(meta.logo.OriginalUrl, AssetTag.EventLogo, cancellationToken: token).ContinueWith(result => sprite = result));

            try
            {
                await tasks;
            }
            catch (OperationCanceledException)
            {
                return;
            }

            logoImage.sprite = sprite;
            logoImage.DOFade(1, 0.8f).SetDelay(0.4f);
        }

        AddTask(LoadCover);
        AddTask(LoadLogo);

        Context.Player.Settings.SeenEvents.Add(meta.uid);
        Context.Player.SaveSettings();

        infoBanner.Leave(onComplete: () =>
        {
            if (!Context.Player.Settings.ReadEventDetails.Contains(meta.uid))
            {
                viewDetailsNotification.Show();
            }
            viewDetailsButton.onPointerClick.SetListener(_ =>
            {
                Context.Player.Settings.ReadEventDetails.Add(meta.uid);
                Context.Player.SaveSettings();
                viewDetailsNotification.Hide();
                if (meta.url.IsNullOrEmptyTrimmed())
                {
                    Application.OpenURL($"{Context.WebsiteUrl}/posts/{meta.uid}");
                }
                else
                {
                    WebViewOverlay.Show(meta.url,
                                        onFullyShown: () =>
                    {
                        LoopAudioPlayer.Instance.FadeOutLoopPlayer();
                    },
                                        onFullyHidden: async() =>
                    {
                        AudioSettings.Reset(AudioSettings.GetConfiguration());
                        Context.AudioManager.Dispose();
                        Context.AudioManager.Initialize();
                        await UniTask.DelayFrame(5);
                        LoopAudioPlayer.Instance.Apply(it =>
                        {
                            it.FadeInLoopPlayer();
                            it.PlayAudio(it.PlayingAudio, forceReplay: true);
                        });
                    });
                }
            });
            const string dateFormat = "yyyy/MM/dd HH:mm";
            durationText.text       = (meta.startDate.HasValue ? meta.startDate.Value.LocalDateTime.ToString(dateFormat) : "")
                                      + "~"
                                      + (meta.endDate.HasValue ? meta.endDate.Value.LocalDateTime.ToString(dateFormat) : "");
            enterButton.onPointerClick.SetListener(_ =>
            {
                if (meta.locked)
                {
                    Context.Haptic(HapticTypes.Failure, true);
                    // TODO
                    return;
                }
                Context.Haptic(HapticTypes.SoftImpact, true);
                if (meta.levelId != null)
                {
                    SpinnerOverlay.Show();

                    RestClient.Get <OnlineLevel>(new RequestHelper
                    {
                        Uri = $"{Context.ApiUrl}/levels/{meta.levelId}"
                    }).Then(level =>
                    {
                        Context.ScreenManager.ChangeScreen(
                            GamePreparationScreen.Id, ScreenTransition.In, 0.4f,
                            transitionFocus: GetComponent <RectTransform>().GetScreenSpaceCenter(),
                            payload: new GamePreparationScreen.Payload {
                            Level = level.ToLevel(LevelType.User)
                        }
                            );
                    }).CatchRequestError(error =>
                    {
                        Debug.LogError(error);
                        Dialog.PromptAlert("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());
                    }).Finally(() => SpinnerOverlay.Hide());
                }
                else if (meta.collectionId != null)
                {
                    Context.ScreenManager.ChangeScreen(
                        CollectionDetailsScreen.Id, ScreenTransition.In, 0.4f,
                        transitionFocus: GetComponent <RectTransform>().GetScreenSpaceCenter(),
                        payload: new CollectionDetailsScreen.Payload
                    {
                        CollectionId = meta.collectionId, Type = LevelType.User
                    }
                        );
                }
            });
            infoBanner.transform.RebuildLayout();
            infoBanner.Enter();
        });
    }
示例#2
0
    public override async void OnScreenBecameActive()
    {
        base.OnScreenBecameActive();

        //WebViewOverlay.Show();
        if (StartupLogger.Instance != null)
        {
            StartupLogger.Instance.Dispose();
        }

        upperLeftOverlayImage.SetAlpha(Context.CharacterManager.GetActiveCharacterAsset().mainMenuUpperLeftOverlayAlpha);
        overlayImage.SetAlpha(Context.CharacterManager.GetActiveCharacterAsset().mainMenuRightOverlayAlpha);

        var levelCount = Context.LevelManager.LoadedLocalLevels.Count(it =>
                                                                      (it.Value.Type == LevelType.User || it.Value.Type == LevelType.BuiltIn) && !BuiltInData.TrainingModeLevelIds.Contains(it.Value.Id));

        freePlayText.text = "MAIN_LEVELS_LOADED".Get(levelCount);
        freePlayText.transform.RebuildLayout();

        ProfileWidget.Instance.Enter();

        if (Context.CharacterManager.GetActiveCharacterAsset().mirrorLayout)
        {
            layout.anchorMin        = new Vector2(0, 0.5f);
            layout.anchorMax        = new Vector2(0, 0.5f);
            layout.pivot            = new Vector2(0, 0.5f);
            layout.anchoredPosition = new Vector2(96, -90);
            overlayHolder.SetLeft(280);
            overlayHolder.SetRight(840);
            overlayHolder.SetLocalScaleX(-2);
        }
        else
        {
            layout.anchorMin        = new Vector2(1, 0.5f);
            layout.anchorMax        = new Vector2(1, 0.5f);
            layout.pivot            = new Vector2(1, 0.5f);
            layout.anchoredPosition = new Vector2(-96, -90);
            overlayHolder.SetLeft(840);
            overlayHolder.SetRight(280);
            overlayHolder.SetLocalScaleX(2);
        }

        // Check new events
        if (Context.IsOnline() && Context.OnlinePlayer.IsAuthenticated)
        {
            RestClient.GetArray <EventMeta>(new RequestHelper
            {
                Uri         = $"{Context.ApiUrl}/events",
                Headers     = Context.OnlinePlayer.GetRequestHeaders(),
                EnableDebug = true
            }).AbortOnScreenBecameInactive(this).Then(events =>
            {
                var hasUnseenEvent = false;
                foreach (var meta in events)
                {
                    if (Context.Player.Settings.SeenEvents.Contains(meta.uid))
                    {
                        continue;
                    }
                    hasUnseenEvent = true;
                }
                if (hasUnseenEvent)
                {
                    eventNotification.Show();
                }
            }).CatchRequestError(Debug.LogWarning);
        }

        if (Context.InitializationState.IsAfterFirstLaunch() && !LaunchedFirstLaunchDialogue)
        {
            LaunchedFirstLaunchDialogue = true;

            var text = Resources.Load <TextAsset>("Stories/Intro");
            LevelSelectionScreen.HighlightedLevelId = BuiltInData.TutorialLevelId;
            var story = new Story(text.text);
            Resources.UnloadAsset(text);
            story.variablesState["IsBeginner"] = levelCount < 10;
            await DialogueOverlay.Show(story);

            LevelSelectionScreen.HighlightedLevelId = null;
        }
        else
        {
            if (DialogueOverlay.IsShown())
            {
                await UniTask.WaitUntil(() => !DialogueOverlay.IsShown());
            }

            if (PromptCachedCharacterDataCleared)
            {
                PromptCachedCharacterDataCleared = false;
                Dialog.PromptAlert("DIALOG_CACHED_CHARACTER_DATA_CLEARED".Get());
            }

            // Check announcement
            if (!CheckedAnnouncement && Context.IsOnline())
            {
                RestClient.Get <Announcement>(new RequestHelper
                {
                    Uri         = $"{Context.ApiUrl}/announcements",
                    Headers     = Context.OnlinePlayer.GetRequestHeaders(),
                    EnableDebug = true
                }).Then(it =>
                {
                    CheckedAnnouncement = true;
                    if (it.message != null)
                    {
                        Dialog.PromptAlert(it.message);
                    }

                    var localVersion        = new Version(Context.VersionString);
                    var currentVersion      = new Version(it.currentVersion);
                    var minSupportedVersion = new Version(it.minSupportedVersion);
                    if (localVersion < minSupportedVersion)
                    {
                        Dialog.PromptUnclosable("DIALOG_UPDATE_REQUIRED".Get(),
                                                () => Application.OpenURL(Context.StoreUrl));
                        return;
                    }

                    if (localVersion < currentVersion)
                    {
                        Dialog.Prompt("DIALOG_UPDATE_AVAILABLE_X_Y".Get(currentVersion, localVersion),
                                      () => Application.OpenURL(Context.StoreUrl));
                    }
                }).CatchRequestError(Debug.LogError);
            }
        }
    }