Пример #1
0
    public UiPlayerListItem AddPlayer(PlayerData player)
    {
        var instance = UiUtility.AddChild(List, Prototype, true);

        instance.Tick.SetActive(false);
        instance.Name.text = player.Name;
        return(instance);
    }
Пример #2
0
    public void ShowChoices(PlayerData creator, List <AnswerData> choices)
    {
        if (Client.IsPlayer(creator))
        {
            InfoBox.Show(Strings.PlayersOwnDrawing);
        }

        for (int i = 0; i < choices.Count; i++)
        {
            Debug.LogFormat("Show choice: {0}", choices[i].Answer);

            var instance = UiUtility.AddChild(List.gameObject, ChoicePrototype, true);

            // Show different UI depending of if this is the player's answer
            // If it is, the player won't be able to select their own answer
            bool isPlayer  = choices[i].Author.ID == Client.PlayerData.ID;
            bool isCreator = Client.IsPlayer(creator);

            instance.YourAnswer.SetActive(isPlayer);
            instance.OtherPlayersAnswer.SetActive(!isPlayer);
            instance.Text.ForEach(x => x.text = choices[i].Answer);

            // Don't allow button presses if the drawing creator is the player
            instance.Button.interactable = !isPlayer && !isCreator;
            instance.Like.gameObject.SetActive(!isPlayer);

            var tempChoice = choices[i];

            if (!isPlayer && !isCreator)
            {
                instance.Button.onClick.AddListener(() =>
                {
                    if (OnChoiceSelected != null)
                    {
                        OnChoiceSelected(tempChoice);
                    }

                    DisableButtons();

                    InfoBox.Show(Strings.ChoiceSubmitted);
                });
            }

            // Likes
            instance.Like.onClick.AddListener(() =>
            {
                if (OnLike != null)
                {
                    OnLike(tempChoice);
                }

                instance.Like.gameObject.SetActive(false);
            });

            Views.Add(instance);
        }
    }
Пример #3
0
    void MakeInstance()
    {
        GameInstance = UiUtility.AddChild(GameContainer, GamePrototype, true);
        var rect = (RectTransform)GameInstance.transform;

        rect.sizeDelta = Vector2.zero;

        GameInstance.Initialise(Client);
        GameInstance.OnGameEnd += OnGameEnd;
    }
Пример #4
0
    T MakePopup <T>(T prototype) where T : UiPopupBase
    {
        var instance = UiUtility.AddChild(gameObject, prototype);

        var rect = (RectTransform)instance.transform;

        rect.sizeDelta = Vector2.one;

        // Bring to front
        instance.transform.SetAsLastSibling();

        return(instance);
    }
Пример #5
0
    void AddMessage(string message, params object[] args)
    {
        var instance = UiUtility.AddChild <Text>(MessagesContainer.gameObject, MessagePrototype);

        instance.text    = string.Format(message, args);
        instance.enabled = true;

        if (gameObject.activeInHierarchy)
        {
            StopAllCoroutines();
            StartCoroutine(Hack());
        }
    }
Пример #6
0
    public TView AddItem <TData, TView>(TData data, TView view, Action <TData, TView> onAdd = null) where TView : MonoBehaviour
    {
        var instance = UiUtility.AddChild <TView>(gameObject, view, true);

        if (onAdd != null)
        {
            onAdd((TData)data, (TView)instance);
        }

        Items.Add(data, instance);

        return(instance);
    }
Пример #7
0
    public void Show(GameFinalScores scores, GameFinalScores likes)
    {
        var animController = gameObject.GetOrAddComponent <UiAnimationController>();

        var views = new List <UiFinalScoreRow>();

        // Add rows
        foreach (var score in scores.Values.Take(3).ToList())
        {
            var instance = UiUtility.AddChild(RowContainer, RowProtoype, true);

            instance.PlayerName.text = string.Join(", ", scores.GetPlayerNames(score.Key));
            instance.Points.text     = score.Key.ToString();

            views.Add(instance);
        }

        // Reverse order so it plays out from 3rd to 1st
        views.Reverse();

        // Show rows
        for (int i = 0; i < views.Count; i++)
        {
            views[i].Position.text = (views.Count - i).ToString();

            var delay = i == (views.Count - 1) ? TimeBeforeFirst : TimeBetweenPlayers;

            animController.AddDelay(delay);

            animController.AddAnim(new UiAnimationFade(views[i].gameObject, 0.2f, UiAnimationFade.FadeType.In), false);

            // If showing final player...
            if (i == (views.Count - 1))
            {
                views[i].Position.text = Strings.Winner;
                animController.AddAnim(new UiAnimationScale(views[i].gameObject, Vector3.one * 5, Vector3.one, 0.5f));
            }
        }

        // Show likes if any were made
        if (likes.Values.Any(x => x.Key != 0))
        {
            animController.AddDelay(TimeBeforeMostLikes);
            animController.AddAction("Show Most Likes", () => MostLikes.Show(likes));
        }

        animController.AddDelay(TimeBeforeShowButton);
        animController.AddAnim(new UiAnimationFade(StartNewGame.gameObject, 0.2f, UiAnimationFade.FadeType.In));

        animController.PlayAnimations();
    }
Пример #8
0
    public void Show(GameFinalScores likes)
    {
        var mostLikes = likes.Values.Aggregate((current, next) => next.Key > current.Key ? next : current);

        var view = UiUtility.AddChild(Rows, RowPrototype, true);

        view.Name.text   = string.Join(", ", likes.GetPlayerNames(mostLikes.Key));
        view.Points.text = mostLikes.Key.ToString();

        var animController = gameObject.GetOrAddComponent <UiAnimationController>();

        gameObject.SetActive(true);
        animController.AddAnim(new UiAnimationFade(gameObject, 0.25f, UiAnimationFade.FadeType.In));
        animController.PlayAnimations();
    }
Пример #9
0
    void OnRecieveRoomList(ServerMessage.RoomList message)
    {
        browserItems.ForEach(x => Destroy(x.gameObject));
        browserItems.Clear();

        foreach (var room in message.Rooms)
        {
            // Make instance of view
            var view = UiUtility.AddChild <UiBrowserItem>(Browser.gameObject, BrowserItemPrototype, true);
            view.Text.text    = string.Format("{0}'s Game / Players: {1} / Started?: {2}", room.Owner.Name, room.Players.Count, room.GameStarted);
            view.Toggle.group = toggleGroup;
            view.RoomData     = room;

            // Add toggle listener
            var temp = room;
            view.Toggle.onValueChanged.AddListener((enabled) =>
            {
                if (enabled)
                {
                    Debug.LogFormat("Select room {0}", view.RoomData.ID);
                    selectedRoom = temp;
                }
            });

            view.gameObject.GetOrAddComponent <DoubleClickHandler>().OnDoubleClick += () =>
            {
                OnJoin();
            };

            browserItems.Add(view);
        }

        // Select first item
        if (browserItems.Count != 0)
        {
            browserItems[0].Toggle.isOn = true;
        }

        NoGames.SetActive(browserItems.Count == 0);
    }
Пример #10
0
    // Kill me now!
    IEnumerator Animate(AnswerData result)
    {
        Result.GetOrAddComponent <CanvasGroup>().Fade(0f, 1f, 0.5f);

        yield return(new WaitForSeconds(TimeBeforeShowAnswer));

        Answer.gameObject.SetActive(true);
        Answer.text = string.Format("{0}", result.Answer);

        yield return(new WaitForSeconds(TimeBeforeShowChosenBy));

        Divider.gameObject.SetActive(true);
        Divider.Fade(0f, 1f, 0.1f);
        ChosenBy.gameObject.SetActive(true);
        ChosenBy.gameObject.GetOrAddComponent <CanvasGroup>().Fade(0f, 1f, 0.1f);

        yield return(new WaitForSeconds(TimeBeforePlayersReveal));

        float revealTime = TimeToRevealPlayers / result.Choosers.Count;

        foreach (var player in result.Choosers)
        {
            yield return(new WaitForSeconds(revealTime));

            var instance = UiUtility.AddChild(Rows, RowPrototype, true);
            instance.PlayerName.text = player.Name;
            instance.gameObject.GetOrAddComponent <CanvasGroup>().Scale(Vector3.one * 5, Vector3.one, 0.2f);
            resultViews.Add(instance.gameObject);
        }

        if (result.Type != GameAnswerType.ActualAnswer)
        {
            yield return(new WaitForSeconds(TimeBeforeAuthorReveal));
        }
        else
        {
            yield return(new WaitForSeconds(TimeBeforeActualAnswerReveal));
        }

        Author.gameObject.SetActive(true);
        Author.gameObject.GetOrAddComponent <CanvasGroup>().Fade(0f, 1f, TimeAuthorFade);
        Author.gameObject.GetOrAddComponent <CanvasGroup>().Scale(new Vector3(5f, 5f, 1f), Vector3.one, TimeAuthorScale);

        if (result.Type == GameAnswerType.Player)
        {
            Author.text = string.Format(Strings.Result.PlayerAnswer, result.Author.Name);
            yield return(new WaitForSeconds(TimeBeforeScoreReveal));

            Points.gameObject.SetActive(true);
            Points.text = string.Format("+{0}", result.Points.ToString());
            Points.gameObject.GetOrAddComponent <CanvasGroup>().Fade(0f, 1f, TimeScoreFade);
            Points.gameObject.GetOrAddComponent <CanvasGroup>().Scale(new Vector3(5f, 5f, 1f), Vector3.one, TimeScoreScale);
        }
        else if (result.Type == GameAnswerType.Decoy)
        {
            Author.text = Strings.Result.Decoy;
            yield return(new WaitForSeconds(TimeBeforeScoreReveal));
        }
        else
        {
            Author.text = string.Format(Strings.Result.ActualAnswer);
            yield return(new WaitForSeconds(TimeBeforeScoreReveal));
        }

        if (result.Type != GameAnswerType.ActualAnswer)
        {
            yield return(new WaitForSeconds(TimeBeforeShowNextResult));
        }
        else
        {
            yield return(new WaitForSeconds(TimeAfterActualAnswerReveal));
        }

        Result.GetOrAddComponent <CanvasGroup>().Fade(1f, 0f, TimeFadeAfterResult);

        yield return(new WaitForSeconds(TimeFadeAfterResult));

        if (OnFinishedShowingResult != null)
        {
            OnFinishedShowingResult();
        }

        yield return(0);
    }