public void Initialize(int state)
        {
            Deinitialize();
            var activeMinigame = NetworkManager.Instance.ActiveMinigame3;
            var isOwner        = NetworkManager.Instance.PlayerData.GUID == activeMinigame.Owner;
            var backgroundPath = "data/sprites/minigames/3/background";

            backgroundPath += (isOwner ? "_owner" : "") + ".png";
            var topOffset = isOwner ? 0f : 50;

            rootElement.AddChild(new Image(0, 0, bounds.width, bounds.height, new game.Sprite(backgroundPath, true, false)));

            //title

            // question
            questionLabel = new Label(0, 100, bounds.width, 60, activeMinigame.ActiveQuestion, questionStyle);
            rootElement.AddChild(questionLabel);
            if (state == 0)
            {
                yesChoiceButton = new Button(57, 170 + topOffset, 420, 160, "s1", choiceButtonStyle, () => { OnVoteClicked("yes"); });
                noChoiceButton  = new Button(620, 170 + topOffset, 420, 160, "s2", choiceButtonStyle, () => { OnVoteClicked("no"); });
                yesChoiceLabel  = new Label(57, 170 + topOffset, 420, 160, "I have", choiceLabelStyle);
                noChoiceLabel   = new Label(620, 170 + topOffset, 420, 160, "I have never", choiceLabelStyle);
                rootElement.AddChild(yesChoiceButton);
                rootElement.AddChild(noChoiceButton);
                rootElement.AddChild(yesChoiceLabel);
                rootElement.AddChild(noChoiceLabel);
            }
            else if (state == 1)
            {
                var votedSituation = activeMinigame.ActiveQuestionVotes[NetworkManager.Instance.PlayerData.GUID];
                if (votedSituation == "yes")
                {
                    yesChoiceButton = new Button(57, 170 + topOffset, 420, 160, "s1", choiceButtonStyle, () => { OnVoteClicked("yes"); });
                    yesChoiceLabel  = new Label(57, 170 + topOffset, 420, 160, "I have", choiceLabelStyle);
                    rootElement.AddChild(yesChoiceButton);
                    rootElement.AddChild(yesChoiceLabel);
                }
                else
                {
                    noChoiceButton = new Button(57, 170 + topOffset, 420, 160, "s2", choiceButtonStyle, () => { OnVoteClicked("no"); });
                    noChoiceLabel  = new Label(57, 170 + topOffset, 420, 160, "I have never", choiceLabelStyle);
                    rootElement.AddChild(noChoiceButton);
                    rootElement.AddChild(noChoiceLabel);
                }

                var totalVotes     = NetworkManager.Instance.ActiveRoom.Players.Count;
                var remainingVotes = activeMinigame.RemainingVotes;
                var totalVoted     = totalVotes - remainingVotes;
                remainingVotesLabel = new Label(bounds.width / 2f, bounds.height / 2f + topOffset, bounds.width / 2f, 170, $"Voted: {totalVoted}/{totalVotes} ({remainingVotes} remaining)", remainingVotesStyle);
                rootElement.AddChild(remainingVotesLabel);
            }
            else
            {
                var results    = activeMinigame.Result();
                var players    = NetworkManager.Instance.ActiveRoom.Players;
                var index      = 0;
                var spriteSize = 64f;
                var spacing    = 8f;
                if (players.Count <= 8)
                {
                    spriteSize = 128f;
                    spacing    = 11f;
                }

                foreach (var playerGUID in players.Keys.ToList().Sorted())
                {
                    var player       = players[playerGUID];
                    var x            = index * spriteSize + (index == 0 ? 0 : spacing);
                    var playerAvatar = new PlayerAvatarElement(x, bounds.height / 2f - spriteSize / 2f + topOffset, player.Username, player.AvatarIndex, playerNameStyle, () => { }, spriteSize);
                    index++;
                    rootElement.AddChild(playerAvatar);
                    if (!string.IsNullOrEmpty(results[playerGUID]))
                    {
                        var sprite = new game.Sprite($"data/sprites/{results[playerGUID]}Icon.png", true, false);
                        rootElement.AddChild(new Image(x + spriteSize - 64f, bounds.height / 2f + spriteSize / 2f + topOffset - 64f, 64f, 64f, sprite));
                    }
                }
            }

            if (!isOwner)
            {
                return;
            }
            nextQuestionButton = new Button(0, 350, bounds.width / 2f, 100, "NEXT QUESTION", buttonStyle, OnNextQuestionClicked);
            stopPlayingButton  = new Button(bounds.width / 2f, 350, bounds.width / 2f, 100, "STOP PLAYING", buttonStyle, OnStopPlayingClicked);
            rootElement.AddChild(nextQuestionButton);
            rootElement.AddChild(stopPlayingButton);
        }
예제 #2
0
        public void Initialize(int state)
        {
            Deinitialize();
            var isOwner        = NetworkManager.Instance.PlayerData.GUID == NetworkManager.Instance.ActiveMinigame1.Owner;
            var backgroundPath = "data/sprites/minigames/1/background";

            backgroundPath += (isOwner ? "_owner" : "") + ".png";
            var topOffset = isOwner ? 0f : 50;

            rootElement.AddChild(new Image(0, 0, bounds.width, bounds.height, new game.Sprite(backgroundPath, true, false)));

            //title

            // question
            questionLabel = new Label(0, 100, bounds.width, 60, NetworkManager.Instance.ActiveMinigame1.ActiveQuestion, questionStyle);
            rootElement.AddChild(questionLabel);
            if (state == 0)
            {
                playerAvatars = new List <PlayerAvatarElement>();
                var players    = NetworkManager.Instance.ActiveRoom.Players;
                var index      = 0;
                var spriteSize = 64f;
                var spacing    = 8f;
                if (players.Count <= 8)
                {
                    spriteSize = 128f;
                    spacing    = 11f;
                }

                foreach (var playerGUID in players.Keys.ToList().Sorted())
                {
                    var player       = players[playerGUID];
                    var x            = index * spriteSize + (index == 0 ? 0 : spacing);
                    var playerAvatar = new PlayerAvatarElement(x, bounds.height / 2f - spriteSize / 2f + topOffset, player.Username, player.AvatarIndex, playerNameStyle, () => { OnVoteClicked(player.GUID); }, spriteSize);
                    index++;
                    playerAvatars.Add(playerAvatar);
                }

                playerAvatars.ForEach(avatar => rootElement.AddChild(avatar));
            }
            else if (state == 1)
            {
                var votedGUID = NetworkManager.Instance.ActiveMinigame1.ActiveQuestionVotes[NetworkManager.Instance.PlayerData.GUID];
                var voted     = NetworkManager.Instance.ActiveRoom.Players[votedGUID];
                votedPlayer = new PlayerAvatarElement(bounds.width / 4f - 64f, bounds.height / 2f - 64f + topOffset, voted.Username, voted.AvatarIndex, playerNameStyle);
                rootElement.AddChild(votedPlayer);
                var totalVotes     = NetworkManager.Instance.ActiveRoom.Players.Count;
                var remainingVotes = NetworkManager.Instance.ActiveMinigame1.RemainingVotes;
                var totalVoted     = totalVotes - remainingVotes;
                remainingVotesLabel = new Label(bounds.width / 2f, bounds.height / 2f + topOffset, bounds.width / 2f, 170, $"Voted: {totalVoted}/{totalVotes} ({remainingVotes} remaining)", remainingVotesStyle);
                rootElement.AddChild(remainingVotesLabel);
            }
            else
            {
                var totalVotes = NetworkManager.Instance.ActiveRoom.Players.Count;
                var(winnerGuid, winnerVotes) = NetworkManager.Instance.ActiveMinigame1.Result();
                var winner = NetworkManager.Instance.ActiveRoom.Players[winnerGuid];
                resultPlayer = new PlayerAvatarElement(20, bounds.height / 2f - 64f + topOffset, winner.Username, winner.AvatarIndex, playerNameStyle);
                rootElement.AddChild(resultPlayer);
                resultLabel = new Label(168f, 100 + topOffset, bounds.width / 2f, 250, $"WINNER\nWith {winnerVotes}/{totalVotes} votes", resultStyle);
                rootElement.AddChild(resultLabel);
                if (!isOwner)
                {
                    rootElement.AddChild(new Label(bounds.width / 2f, 100 + topOffset, bounds.width / 2f, 250, "WAITING FOR CREATOR TO MOVE ON TO THE NEXT QUESTION", alertStyle));
                }
            }

            if (!isOwner)
            {
                return;
            }
            nextQuestionButton = new Button(0, 350, bounds.width / 2f, 100, "NEXT QUESTION", buttonStyle, OnNextQuestionClicked);
            stopPlayingButton  = new Button(bounds.width / 2f, 350, bounds.width / 2f, 100, "STOP PLAYING", buttonStyle, OnStopPlayingClicked);
            rootElement.AddChild(nextQuestionButton);
            rootElement.AddChild(stopPlayingButton);
        }