private void LoadGame(Savegame save) { // Set required gameplay elements currentScriptIndex = save.currentScriptIndex; _scripts[currentScriptIndex].currentLine = save.currentScriptLine; _scripts[currentScriptIndex].currentPositionInLine = 0; _environment = save.currentEnvironment; _environment.currentLanguage = UILanguage.createLanguage(Settings.language); _assets.variables = save.currentVariables; // Start game StopSound(false); StopMusic(false); ClearViewport(false); NewGame(false); // Load environment from save LoadSurroundingsFromEnvironment(_environment); Settings.inGame = true; Settings.allowProgress = true; Settings.afterLoad = true; }
/* * Loads main menu elements */ private void MainMenu(bool restartBackground, bool restartMusic) { ClearViewport(true); TextBlock gameNameTextBlock = new TextBlock { Name = "gameNameTextBlock", Text = Settings.gameName, FontSize = 48, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.AliceBlue) }; ViewportContainer.Children.Add(gameNameTextBlock); Canvas.SetLeft(gameNameTextBlock, 100); Canvas.SetTop(gameNameTextBlock, 50); Panel.SetZIndex(gameNameTextBlock, 2); Savegame lastSave = FindLastSave(); if (lastSave != null) { Button continueButton = new Button { Name = "continueButton", Width = 320, Height = 48, Background = new SolidColorBrush(Color.FromArgb(192, 16, 16, 16)) }; TextBlock continueTextBlock = new TextBlock { Name = "continueTextBlock", Text = _environment.currentLanguage.UI_mainMenu_continue, FontSize = 20, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White) }; continueButton.Content = continueTextBlock; continueButton.Click += (sender, args) => { LoadGame(lastSave); }; ViewportContainer.Children.Add(continueButton); Canvas.SetLeft(continueButton, 100); Canvas.SetTop(continueButton, 200); Panel.SetZIndex(continueButton, 2); } Button newGameButton = new Button { Name = "newGameButton", Width = 320, Height = 48, Background = new SolidColorBrush(Color.FromArgb(192, 16, 16, 16)) }; TextBlock newGameTextBlock = new TextBlock { Name = "newGameTextBlock", Text = _environment.currentLanguage.UI_mainMenu_newGame, FontSize = 20, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White) }; newGameButton.Content = newGameTextBlock; newGameButton.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(NewGameButtonClick)); ViewportContainer.Children.Add(newGameButton); Canvas.SetLeft(newGameButton, 100); Canvas.SetTop(newGameButton, 280); Panel.SetZIndex(newGameButton, 2); Button loadGameButton = new Button { Name = "newGameButton", Width = 320, Height = 48, Background = new SolidColorBrush(Color.FromArgb(192, 16, 16, 16)) }; TextBlock loadGameTextBlock = new TextBlock { Name = "loadGameTextBlock", Text = _environment.currentLanguage.UI_mainMenu_loadGame, FontSize = 20, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White) }; loadGameButton.Content = loadGameTextBlock; loadGameButton.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(LoadGameButtonClick)); ViewportContainer.Children.Add(loadGameButton); Canvas.SetLeft(loadGameButton, 100); Canvas.SetTop(loadGameButton, 360); Panel.SetZIndex(loadGameButton, 2); Button optionsButton = new Button { Name = "optionsButton", Width = 320, Height = 48, Background = new SolidColorBrush(Color.FromArgb(192, 16, 16, 16)) }; TextBlock optionsTextBlock = new TextBlock { Name = "optionsTextBlock", Text = _environment.currentLanguage.UI_mainMenu_options, FontSize = 20, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White) }; optionsButton.Content = optionsTextBlock; optionsButton.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OptionsButtonClick)); ViewportContainer.Children.Add(optionsButton); Canvas.SetLeft(optionsButton, 100); Canvas.SetTop(optionsButton, 440); Panel.SetZIndex(optionsButton, 2); Button exitButton = new Button { Name = "exitButton", Width = 320, Height = 48, Background = new SolidColorBrush(Color.FromArgb(192, 16, 16, 16)) }; TextBlock exitTextBlock = new TextBlock { Name = "exitTextBlock", Text = _environment.currentLanguage.UI_mainMenu_exit, FontSize = 20, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White) }; exitButton.Content = exitTextBlock; exitButton.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(ExitButtonClick)); ViewportContainer.Children.Add(exitButton); Canvas.SetLeft(exitButton, 100); Canvas.SetTop(exitButton, 520); Panel.SetZIndex(exitButton, 2); Button languageButton = new Button { Name = "languageButton", Width = 48, Height = 48, Background = new SolidColorBrush(Color.FromArgb(192, 16, 16, 16)) }; TextBlock languageTextBlock = new TextBlock { Name = "languageTextBlock", Text = _environment.currentLanguage.initial, FontSize = 20, FontWeight = FontWeights.ExtraBold, Foreground = new SolidColorBrush(Colors.White) }; languageButton.Content = languageTextBlock; languageButton.Click += (sender, args) => { int langIndex = Settings.LanguageInitialList.FindIndex(s => s == Settings.language); Settings.language = langIndex == Settings.LanguageInitialList.Count - 1 ? Settings.LanguageInitialList[0] : Settings.LanguageInitialList[langIndex + 1]; _environment.currentLanguage = UILanguage.createLanguage(Settings.language); MainMenu(false, false); SaveSettings(); }; ViewportContainer.Children.Add(languageButton); Canvas.SetLeft(languageButton, Settings.windowWidth - 98); Canvas.SetTop(languageButton, Settings.windowHeight - 98); Panel.SetZIndex(languageButton, 2); AllowResize(true); // Menu background image and music if (restartBackground) { ShowBackground("menu_background", 10); } if (restartMusic) { _backgroundMusicPlayer.Stop(); _soundEffectPlayer.Stop(); PlaySound("menu_music", 1, true); } }