/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); //_font = new FontBuddyPlus(); _font = new FontBuddyPlusStroked(); _font.LoadContent(Content, @"Roboto-Regular", true, 24); clock.Start(); GC.Collect(); }
public override async Task LoadContent() { try { await base.LoadContent(); if (null == FontSmall) { FontSmall = new FontBuddyPlus(); FontSmall.LoadContent(Content, StyleSheet.SmallFontResource, StyleSheet.UseFontPlus, StyleSheet.SmallFontSize); } if (null == FontMedium) { FontMedium = new FontBuddyPlus(); FontMedium.LoadContent(Content, StyleSheet.MediumFontResource, StyleSheet.UseFontPlus, StyleSheet.MediumFontSize); } //create the stack layout to hold the question and words var questionStack = new StackLayout(StackAlignment.Top) { Vertical = VerticalAlignment.Bottom, Horizontal = HorizontalAlignment.Center, Highlightable = false, TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop), }; //Add the text asking a question questionStack.AddItem(new Label($"What is the", FontSmall) { Vertical = VerticalAlignment.Center, Horizontal = HorizontalAlignment.Center, Highlightable = false, TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop), }); questionStack.AddItem(new Shim(0, 8)); questionStack.AddItem(new Label($"{correctAnswer.Language} for:", FontSmall) { Vertical = VerticalAlignment.Center, Horizontal = HorizontalAlignment.Center, Highlightable = false, TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop), }); questionStack.AddItem(new Shim(0, 8)); //Add all the translations foreach (var translation in correctQuestion.Translations) { if (translation.Language != correctAnswer.Language) { CreateTranslationLabel(FontMedium, questionStack, translation); } } questionStack.Position = new Point(Resolution.ScreenArea.Center.X, (int)((Resolution.TitleSafeArea.Height * 0.2f) - (questionStack.Rect.Height * 0.4f))); AddItem(questionStack); //create the correct menu entry CorrectAnswerEntry = CreateQuestionMenuEntry(correctAnswer.Word, correctQuestion, true, FontMedium); CorrectAnswerEntry.OnClick += CorrectAnswerSelected; Entries.Add(CorrectAnswerEntry); //Add exactly three wrong answers for (int i = 0; i < 3; i++) { //get a random wrong answer int index = _rand.Next(wrongAnswers.Count); //create a menu entry for that answer var wrongMenuEntry = CreateQuestionMenuEntry(wrongAnswers[index].Word, wrongQuestions[index], false, FontMedium); wrongMenuEntry.OnClick += WrongAnswerSelected; Entries.Add(wrongMenuEntry); //remove the wrong answer from the list so it wont be added again wrongAnswers.RemoveAt(index); wrongQuestions.RemoveAt(index); } //shuffle the answers Entries.Shuffle(_rand); //create the stack layout to hold the possible answers var answersStack = new StackLayout(StackAlignment.Top) { Name = "AnswerStack", Vertical = VerticalAlignment.Center, Horizontal = HorizontalAlignment.Center, Highlightable = false, TransitionObject = new WipeTransitionObject(TransitionWipeType.PopBottom), Position = new Point(Resolution.ScreenArea.Center.X, (int)(Resolution.TitleSafeArea.Height * 0.5f)) }; //add all the question entries to the menu foreach (var entry in Entries) { answersStack.AddItem(entry); } AddItem(answersStack); //load the sound effect to play when time runs out on a question WrongAnswerSound = Content.Load <SoundEffect>("WrongAnswer"); AutoQuit.Stop(); } catch (Exception ex) { await ScreenManager.ErrorScreen(ex); } //Try to load the sound effects soundContent = new ContentManager(ScreenManager.Game.Services, "Content"); try { QuestionSoundEffect = soundContent.Load <SoundEffect>($"TTS/{correctAnswer.Language}Question"); } catch (Exception ex) { //ignore for now } //load the correct answer sound effect try { QuestionWordSoundEffect = CorrectQuestion.LoadSoundEffect(correctQuestion.OtherLanguage(correctAnswer.Language), soundContent); } catch (Exception ex) { //ignore for now } //load the sound effect for each question for (int i = 0; i < Entries.Count; i++) { try { Entries[i].LoadSoundEffect(correctAnswer.Language, soundContent); } catch (Exception ex) { //ignore for now } } QuestionStateMachine = new QuestionStateMachine(); QuestionStateMachine.StartTimer(Transition.OnTime + 0.1f); QuestionStateMachine.StateChangedEvent += QuestionStateMachine_StateChangedEvent; }