Beispiel #1
0
        public GameMenu(ButtonSchema buttonData)
        {
            DebugFunctions.DEBUG_output_list_of_videos("GameMenu Constructor", buttonData);

            InitializeComponent();
            // load root directory
            _scenarioPath = MainResources.GetRootDirectory();

            // holds our buttons so we can iterate and enable/disable
            gameButtons = new List <GameButton>();

            // load current path position (ie 1, 2, 3, -1)
            _storyPosition = MainResources.GetPathPosition();

            // set default video to play (first video in list)
            string videoPath = buttonData.VideoFilename[_currentlyPlayingVideo];

            // path for the current branch
            _branchPath = Path.Combine(_scenarioPath, MainResources.GetBranch() + _storyPosition.ToString());

            // if we are at -1 story position or no HP, it's game over
            if (_storyPosition == -1 || isPlayerDead())
            {
                ShowLoseScreen(buttonData);
                return;
            }
            // didn't lost the game, so save restore point
            MainResources.SaveCurrentState(buttonData);

            // callback to invoke after the video is played
            Action afterVideoPlayed = AfterChoiceVideoPlayed;

            // win conditions
            // 1. if there are no more folders along this story path
            // 2. if the button data has an ending
            if (!Directory.Exists(_branchPath) || buttonData.Endings.Count > 0)
            {
                // start by setting the ending video we will play
                string endVideoPath = videoPath;

                // determine which ending based on points
                foreach (Ending ending in buttonData.Endings)
                {
                    // the first ending that matches the condition will be set as the ending (so consider the order of endings in the list)
                    if (MainResources.GetPoints() >= ending.WhenPointsAreBetween[0] && MainResources.GetPoints() <= ending.WhenPointsAreBetween[1])
                    {
                        _hasEndingVideo = true;

                        // set this ending to play after the choice video
                        endVideoPath = Path.Combine(_scenarioPath, "endings", ending.VideoFilename);

                        // set the text to display on the ending screen depending on this ending
                        buttonData.EndScreenMessage = ending.EndScreenMessage;
                        // break on first match
                        break;
                    }
                }

                if (!_hasEndingVideo && buttonData.Endings.Count == 1)
                {
                    // only 1 ending, play it (no point condition)
                    _hasEndingVideo = true;
                    endVideoPath    = Path.Combine(_scenarioPath, "endings", buttonData.Endings[0].VideoFilename);
                }


                afterVideoPlayed = () => ShowWinScreen(buttonData, endVideoPath);
                // "just in case" there are  no matches
                if (!_hasEndingVideo || buttonData.Endings.Count == 0)
                {
                    // just show the regular win screen (no ending video)
                    ShowWinScreen(buttonData, videoPath);
                    return;
                }
            }

            // see if we have other videos to play after this one
            if (buttonData.VideoFilename.Count > 1)
            {
                // set the callback to invoke after ALL videos are played
                Action finalCallback = afterVideoPlayed;
                // set the immidiate callback to play other videos first
                afterVideoPlayed = () => PlayOtherVideosFirst(buttonData.VideoFilename, finalCallback);
            }

            _fadeInStoryboards  = new Storyboard();
            _fadeOutStoryboards = new Storyboard();

            // setting fade in animations (not running them yet)
            var fadeIn = FindResource("FadeInStoryboard") as Storyboard;

            Storyboard.SetTarget(fadeIn, GameMenuGrid);

            var fadeIn2 = FindResource("FadeInStoryboard2") as Storyboard;

            Storyboard.SetTarget(fadeIn2, ChoiceMenuBorder);

            var fadeOut = FindResource("FadeOutStoryboard") as Storyboard;

            // sets the callback when storyboard (choices) have faded out
            fadeOut.Completed += NextVideoStart;
            Storyboard.SetTarget(fadeOut, GameMenuGrid);

            var fadeOut2 = FindResource("FadeOutStoryboard2") as Storyboard;

            Storyboard.SetTarget(fadeOut2, ChoiceMenuBorder);


            _fadeInStoryboards.Children.Add(fadeIn);
            _fadeInStoryboards.Children.Add(fadeIn2);

            _fadeOutStoryboards.Children.Add(fadeOut);
            _fadeOutStoryboards.Children.Add(fadeOut2);

            if (!_hasEndingVideo)
            {
                // if we are not playing the ending video, we must be continuing the game, so add the choice buttons
                AddButtons();
            }

            // now play the video, and invoke the callback after it's played
            MainResources.MainWindow.PlayFile(videoPath, afterVideoPlayed);
        }
Beispiel #2
0
        private void AddButtons()
        {
            gameButtons = new List <GameButton>();

            // load the buttons from json file
            string branchPath = Path.Combine(_branchPath, "options.json");

            using (StreamReader r = new StreamReader(branchPath))
            {
                string json = r.ReadToEnd();
                List <ButtonSchema> items = JsonConvert.DeserializeObject <List <ButtonSchema> >(json);
                foreach (var item in items)
                {
                    // set default path progression
                    StoryPath storyPath = new StoryPath
                    {
                        Branch        = MainResources.GetBranch(),
                        StartPosition = _storyPosition
                    };

                    // set default score adjustments
                    ScoreAdjustment scoreAdjustment = new ScoreAdjustment
                    {
                        HP     = 0,
                        Points = 0
                    };

                    // default empty ending list
                    List <Ending> endings = new List <Ending>();
                    // will hold the list of videos to play when the button is pressed
                    List <string> videoPaths = new List <string>()
                    {
                    };

                    // the video path is the CURRENT BRANCH PATH, even if the branch will be changed
                    string videoFilepath = Path.Combine(_scenarioPath, storyPath.Branch + storyPath.StartPosition);

                    // if we have conditional videos, they take priority over anything in VideoFilename
                    if (item.Videos != null)
                    {
                        // loop through our conditional options
                        foreach (ConditionalVideos cond in item.Videos)
                        {
                            // the first match will be used (so consider the order of endings in the list)
                            if (MainResources.GetPoints() >= cond.WhenPointsAreBetween[0] && MainResources.GetPoints() <= cond.WhenPointsAreBetween[1])
                            {
                                // add these videos to the list to be played
                                foreach (string vid in cond.VideoFilename)
                                {
                                    videoPaths.Add(Path.Combine(videoFilepath, vid));
                                }
                                // break on first match
                                break;
                            }
                        }
                        // if we still have no videos to play, just get the first one from the ConditionalVideos
                        if (videoPaths.Count == 0)
                        {
                            ConditionalVideos defaultVideos = item.Videos[0];
                            foreach (string video in defaultVideos.VideoFilename)
                            {
                                videoPaths.Add(Path.Combine(videoFilepath, video));
                            }
                        }
                    }
                    else
                    {
                        // no conditional videos, just play the list of VideoFilename
                        foreach (string vidPath in item.VideoFilename)
                        {
                            videoPaths.Add(Path.Combine(videoFilepath, vidPath));
                        }
                    }



                    // if item.Path is null, we stay on the same branch and advance 1 position (default behavior)
                    if (item.Path != null)
                    {
                        // if we change the path, we set the branch and the start position on that branch
                        storyPath.Branch        = item.Path.Branch;
                        storyPath.StartPosition = item.Path.StartPosition;
                    }

                    if (item.ScoreAdjustment != null)
                    {
                        scoreAdjustment.HP     = item.ScoreAdjustment.HP;
                        scoreAdjustment.Points = item.ScoreAdjustment.Points;
                    }

                    if (item.Endings != null)
                    {
                        endings = item.Endings;
                    }

                    ButtonSchema buttonData = new ButtonSchema()
                    {
                        ButtonType       = item.ButtonType,
                        VideoFilename    = videoPaths,
                        Path             = storyPath,
                        ScoreAdjustment  = scoreAdjustment,
                        Endings          = endings,
                        EndScreenMessage = item.EndScreenMessage
                    };

                    GameButton gameButton = new GameButton(item.Label, buttonData, ButtonClicked);
                    // disable the button by default
                    gameButton.IsEnabled = false;
                    // add the button to our global button container so we can re-enable them after the video is done
                    gameButtons.Add(gameButton);
                }
            }

            gameButtons.Shuffle();

            // making 2 columns with multiple rows for the buttons
            int buttonPos = 0;

            foreach (var gameButton in gameButtons)
            {
                if (buttonPos == 0 || buttonPos == 2 || buttonPos == 4)
                {
                    ButtonStackPanel.Children.Add(gameButton);
                }
                else
                {
                    ButtonStackPanel2.Children.Add(gameButton);
                }
                buttonPos += 1;
            }

            // Debug logging
            // display the current HP, points, branch and position on the choice menu
            HealthAndPositionLabel.Content = $"{MainResources.GetBranch()}{_storyPosition} | HP:{MainResources.GetHP()} Pts:{MainResources.GetPoints()}";
        }