Пример #1
0
        private void LoadContent_Buttons(ContentManager Content)
        {
            //generating button for each available character.
            Vector2 prevDrawCoordinate = buttonGridOrigin;
            Vector2 translation;

            for (int i = 0; i < uiButtons.Length; i++)
            {
                //get the directory of respective button textures for characters from the ID;
                Type   characterReference = CharacterLinker.GetCharacterReference(i);
                string directory          = (string)characterReference.GetField("SpriteReference").GetRawConstantValue();
                //load the button texture(s)
                Texture2D tex     = Content.Load <Texture2D>(directory);
                Texture2D outline = Content.Load <Texture2D>("CharacterSelect/Buttons/Outline");

                //create mask
                bool[,] mask = UiTools.CreateBoolMask(tex);
                //generate draw position
                if ((i & 1) == 1)   //if odd number
                {
                    translation = buttonTesselateVector;
                }
                else
                {
                    translation = new Vector2(buttonTesselateVector.X, -buttonTesselateVector.Y);
                }
                //instantiate button
                uiButtons[i] = new CharSelectButton(i, prevDrawCoordinate + (buttonScale * translation), tex, outline, mask, buttonScale);
                //update the draw coordinate for tesselation.
                prevDrawCoordinate = prevDrawCoordinate + (buttonScale * translation);

                //attach event handler to button
                uiButtons[i].buttonPressed += HandleButtonPress;
            }

            //generate help button
            helpButton = new TutorialButton(graphicsDevice, this,
                                            WindowTools.PaddingToPixelCoordinate(0, 0, 10, 10),
                                            (int)(20 * buttonScale),
                                            (int)(10 * buttonScale));

            //generating confirm button
            Texture2D confirmButtonTexture = Content.Load <Texture2D>("PreparationTurn/EndTurnButton");
            Texture2D confirmButtonOutline = Content.Load <Texture2D>("PreparationTurn/EndTurnButtonHovered");

            confirmButton = new CharSelectConfirmButton(WindowTools.PaddingToPixelCoordinate(0.45f, 0.6f, 0, 0) - buttonScale / 2 * new Vector2(confirmButtonTexture.Width, 0), confirmButtonTexture, confirmButtonOutline, UiTools.CreateBoolMask(confirmButtonTexture), buttonScale * 2);
            confirmButton.buttonPressed += HandleButtonPress;
        }
Пример #2
0
        private void HandleButtonPress(object sender, CharSelectButtonEventArgs eventArgs)
        {
            if (eventArgs.type == CharSelectButton.buttonTypes.ConfirmButton)
            {
                if (p1SelectedButton != null && p2SelectedButton != null)
                {
                    BoardGame.GameArgs args = new BoardGame.GameArgs(
                        p1SelectedButton.LinkId,
                        p2SelectedButton.LinkId,
                        pColors[0],
                        pColors[1],
                        winThreshold
                        );

                    GameStateManager.Instance.ChangeState(new BoardGame(graphicsDevice, args));
                }
            }
            else if (eventArgs.type == CharSelectButton.buttonTypes.CharacterSelection)
            {
                if (eventArgs.leftClicked)
                {
                    if (p1SelectedButton == uiButtons[eventArgs.linkId])
                    {
                        p1SelectedButton = null;
                        infoBoxes[0].SetCharacterInformation(null, null);
                    }
                    else
                    {
                        p1SelectedButton = uiButtons[eventArgs.linkId];
                        infoBoxes[0].SetCharacterInformation(p1SelectedButton.ButtonTexture, CharacterLinker.GetCharacterReference(p1SelectedButton.LinkId));
                    }
                }
                else if (eventArgs.rightClicked)
                {
                    if (p2SelectedButton == uiButtons[eventArgs.linkId])
                    {
                        p2SelectedButton = null;
                        infoBoxes[1].SetCharacterInformation(null, null);
                    }
                    else
                    {
                        p2SelectedButton = uiButtons[eventArgs.linkId];
                        infoBoxes[1].SetCharacterInformation(p2SelectedButton.ButtonTexture, CharacterLinker.GetCharacterReference(p2SelectedButton.LinkId));
                    }
                }
            }
        }