Beispiel #1
0
        public void LabelStack_Scale()
        {
            _stack = new StackLayout()
            {
                Alignment  = StackAlignment.Right,
                Horizontal = HorizontalAlignment.Left,
                Vertical   = VerticalAlignment.Bottom,
                Position   = new Point(10, 20)
            };

            var label1 = new Label("butt", _mediumFont)
            {
                Scale = 0.5f
            };

            _stack.AddItem(label1);

            var label2 = new Label("nuts", _mediumFont)
            {
                Scale = 0.25f
            };

            _stack.AddItem(label2);

            label1.Scale = .5f;
            label2.Scale = .25f;

            Assert.AreEqual(.5f, label1.Scale);
            Assert.AreEqual(.25f, label2.Scale);
        }
Beispiel #2
0
        public void LabelStack_TwoItems_LeftAlignment_Stack()
        {
            _stack = new StackLayout()
            {
                Alignment  = StackAlignment.Left,
                Horizontal = HorizontalAlignment.Left,
                Vertical   = VerticalAlignment.Bottom,
                Position   = new Point(10, 20)
            };

            var label1 = new Label("butt", _mediumFont);

            _stack.AddItem(label1);

            var label2 = new Label("nuts", _mediumFont);

            _stack.AddItem(label2);

            Assert.AreEqual(10f, _stack.Position.X);
            Assert.AreEqual(20f, _stack.Position.Y);
            Assert.AreEqual(10f, _stack.Rect.Left);
            Assert.AreEqual(70f, _stack.Rect.Right);
            Assert.AreEqual(20f, _stack.Rect.Bottom);
            Assert.AreEqual(60f, _stack.Rect.Width);
            Assert.AreEqual(40f, _stack.Rect.Height);
            Assert.AreEqual(StackAlignment.Left, _stack.Alignment);
            Assert.AreEqual(HorizontalAlignment.Left, _stack.Horizontal);
            Assert.AreEqual(VerticalAlignment.Bottom, _stack.Vertical);
            Assert.AreEqual(2, _stack.Items.Count);
        }
Beispiel #3
0
        public void LabelStack_TwoItems_RightAlignment_Label2()
        {
            _stack = new StackLayout()
            {
                Alignment  = StackAlignment.Right,
                Horizontal = HorizontalAlignment.Left,
                Vertical   = VerticalAlignment.Bottom,
                Position   = new Point(10, 20)
            };

            var label1 = new Label("butt", _mediumFont);

            _stack.AddItem(label1);

            var label2 = new Label("nuts", _mediumFont);

            _stack.AddItem(label2);

            Assert.AreEqual(-20f, label2.Position.X);
            Assert.AreEqual(20f, label2.Position.Y);
            Assert.AreEqual(-50f, label2.Rect.Left);
            Assert.AreEqual(20f, label2.Rect.Bottom);
            Assert.AreEqual(30f, label2.Rect.Width);
            Assert.AreEqual(40f, label2.Rect.Height);
            Assert.AreEqual(HorizontalAlignment.Right, label1.Horizontal);
            Assert.AreEqual(VerticalAlignment.Bottom, label1.Vertical);
        }
Beispiel #4
0
        public override async Task LoadContent()
        {
            await base.LoadContent();

            AddCancelButton();

            //create the stack layout
            var stack = new StackLayout();

            stack.Position = new Point(Resolution.ScreenArea.Center.X, Resolution.TitleSafeArea.Top);

            //add the label
            _label = new Label("", Content);
            stack.AddItem(_label);

            //add the slider
            _slider = new Slider()
            {
                Min            = 100,
                Max            = 200,
                SliderPosition = 150,
                HandleSize     = new Vector2(64, 64),
                Size           = new Vector2(512, 128)
            };
            stack.AddItem(_slider);

            _label.Text = _slider.SliderPosition.ToString();

            _slider.OnDrag += ((obj, e) => {
                _label.Text = _slider.SliderPosition.ToString();
            });

            AddItem(stack);
        }
Beispiel #5
0
 private void CreateTranslationLabel(IFontBuddy font, StackLayout questionStack, Translation translation)
 {
     try
     {
         QuestionWordLabel = new QuestionLabel(false, translation.Word, font, font)
         {
             Vertical         = VerticalAlignment.Center,
             Horizontal       = HorizontalAlignment.Center,
             Highlightable    = false,
             TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop),
             Scale            = 1.2f,
         };
         QuestionWordLabel.ShrinkToFit(Resolution.TitleSafeArea.Width);
         questionStack.AddItem(QuestionWordLabel);
         questionStack.AddItem(new Shim(0, 8));
     }
     catch (Exception ex)
     {
         ScreenManager.ErrorScreen(ex);
         throw new Exception($"Error creating menu entry for {translation.Word}", ex);
     }
 }
        private StackLayout GetStack()
        {
            //create the stack layout and add some labels
            var stack = new StackLayout()
            {
                Alignment  = StackAlignment.Top,
                Horizontal = HorizontalAlignment.Left,
                Vertical   = VerticalAlignment.Center
            };

            for (int i = 100; i < 150; i++)
            {
                var text  = i.ToString();
                var label = new Label(text, Content, FontSize.Small)
                {
                    Horizontal = HorizontalAlignment.Center,
                    Vertical   = VerticalAlignment.Center,
                };

                var button = new RelativeLayoutButton()
                {
                    Horizontal    = HorizontalAlignment.Center,
                    Vertical      = VerticalAlignment.Center,
                    HasOutline    = true,
                    HasBackground = false,
                    Layer         = i,
                    //Size = new Vector2(label.Rect.Width, label.Rect.Height)
                };
                button.Size = new Vector2(label.Rect.Width, label.Rect.Height);
                button.AddItem(label);
                button.OnClick += ((object obj, ClickEventArgs e) =>
                {
                    ScreenManager.AddScreen(new OkScreen(text));
                });

                stack.AddItem(button);
            }

            return(stack);
        }
Beispiel #7
0
 protected override void AddButtons(StackLayout stack)
 {
     //just an ok button on this screen
     stack.AddItem(AddMessageBoxOkButton());
 }
        public override async Task LoadContent()
        {
            await base.LoadContent();

            //create the meter rectangles
            var lifebarRect = new Rectangle(
                (int)Resolution.TitleSafeArea.Left,
                (int)Resolution.TitleSafeArea.Top,
                512, 128);

            var superBarRect = new Rectangle(
                (int)Resolution.TitleSafeArea.Left,
                lifebarRect.Bottom,
                512, 128);

            var manaBarRect = new Rectangle(
                (int)Resolution.TitleSafeArea.Left,
                superBarRect.Bottom,
                1024, 256);

            var timerRect = new Rectangle(600,
                                          (int)Resolution.TitleSafeArea.Top,
                                          128, 128);

            //create the lifebar
            lifeBar       = new LifeBar(maxHP, Content, "lifebarborder.png", "lifebar.png", "lifebarGradient.png", lifebarRect);
            timer         = new TimerMeter(maxTime, Content, "TimerBackground.png", "TimerMeter.png", "TimerGradient.png", timerRect);
            manaBar       = new ManaBar(maxMana, Content, "energybackground.png", "energymeter.png", "energygradient.png", manaBarRect);
            superBar      = new SuperBar(maxSuper, Content, "EnergyMeter1.png", "EnergyMeterMask1.png", "EnergyMeterGradient1.png", superBarRect);
            meterRenderer = new MeterRenderer(Content, "MeterShader.fx");

            //add a stack of buttons for interacting with stuff
            var lifeButtonStack = new StackLayout(StackAlignment.Bottom)
            {
                Position   = new Point(Resolution.TitleSafeArea.Right, Resolution.TitleSafeArea.Bottom),
                Horizontal = HorizontalAlignment.Right,
                Vertical   = VerticalAlignment.Top
            };
            var hitButton = AddButton("Add Damage");

            hitButton.OnClick += HitButton_OnClick;
            lifeButtonStack.AddItem(hitButton);

            var healButton = AddButton("Heal");

            healButton.OnClick += HealButton_OnClick;
            lifeButtonStack.AddItem(healButton);

            var addSuperButton = AddButton("Add Energy");

            addSuperButton.OnClick += AddSuperButton_OnClick;
            lifeButtonStack.AddItem(addSuperButton);

            var spendSuperButton = AddButton("Use Super");

            spendSuperButton.OnClick += SpendSuperButton_OnClick;
            lifeButtonStack.AddItem(spendSuperButton);

            var addManaButton = AddButton("Add Mana");

            addManaButton.OnClick += AddManaButton_OnClick;
            lifeButtonStack.AddItem(addManaButton);

            var spendManaButton = AddButton("Use Mana");

            spendManaButton.OnClick += SpendManaButton_OnClick;
            lifeButtonStack.AddItem(spendManaButton);

            var nopeButton = AddButton("Super Nope");

            nopeButton.OnClick += NopeButton_OnClick;
            lifeButtonStack.AddItem(nopeButton);

            var resetTime = AddButton("ResetTime");

            resetTime.OnClick += ResetTime_OnClick;
            lifeButtonStack.AddItem(resetTime);

            AddItem(lifeButtonStack);

            Reset();
        }
Beispiel #9
0
        public override async Task LoadContent()
        {
            await base.LoadContent();

            AddCancelButton();

            //add the scroll options
            var scroll = new MenuEntry("Scroll Up", Content);

            scroll.OnClick += ((object obj, ClickEventArgs e) =>
            {
                var scrollPos = _layout.ScrollPosition;
                scrollPos.Y -= _scrollDelta;
                _layout.ScrollPosition = scrollPos;
            });
            AddMenuEntry(scroll);

            scroll          = new MenuEntry("Scroll Down", Content);
            scroll.OnClick += ((object obj, ClickEventArgs e) =>
            {
                var scrollPos = _layout.ScrollPosition;
                scrollPos.Y += _scrollDelta;
                _layout.ScrollPosition = scrollPos;
            });
            AddMenuEntry(scroll);

            scroll          = new MenuEntry("Scroll Left", Content);
            scroll.OnClick += ((object obj, ClickEventArgs e) =>
            {
                var scrollPos = _layout.ScrollPosition;
                scrollPos.X -= _scrollDelta;
                _layout.ScrollPosition = scrollPos;
            });
            AddMenuEntry(scroll);

            scroll          = new MenuEntry("Scroll Right", Content);
            scroll.OnClick += ((object obj, ClickEventArgs e) =>
            {
                var scrollPos = _layout.ScrollPosition;
                scrollPos.X += _scrollDelta;
                _layout.ScrollPosition = scrollPos;
            });
            AddMenuEntry(scroll);

            //create the stack layout and add some labels
            var stack = new StackLayout()
            {
                Alignment  = StackAlignment.Top,
                Horizontal = HorizontalAlignment.Left,
                Vertical   = VerticalAlignment.Top
            };

            var label  = new Label("buttnuts", Content, FontSize.Small);
            var button = new RelativeLayoutButton()
            {
                HasOutline    = true,
                HasBackground = false
            };

            button.Size = new Vector2(label.Rect.Width, label.Rect.Height);
            button.AddItem(label);
            button.OnClick += ((object obj, ClickEventArgs e) =>
            {
                ExitScreen();
            });
            stack.AddItem(button);

            label  = new Label("catpants", Content, FontSize.Small);
            button = new RelativeLayoutButton()
            {
                HasOutline    = true,
                HasBackground = false
            };
            button.Size = new Vector2(label.Rect.Width, label.Rect.Height);
            button.AddItem(label);
            button.OnClick += ((object obj, ClickEventArgs e) =>
            {
                ExitScreen();
            });
            stack.AddItem(button);

            label  = new Label("foo", Content, FontSize.Small);
            button = new RelativeLayoutButton()
            {
                HasOutline    = true,
                HasBackground = false
            };
            button.Size = new Vector2(label.Rect.Width, label.Rect.Height);
            button.AddItem(label);
            button.OnClick += ((object obj, ClickEventArgs e) =>
            {
                ExitScreen();
            });
            stack.AddItem(button);

            label  = new Label("bleh", Content, FontSize.Small);
            button = new RelativeLayoutButton()
            {
                HasOutline    = true,
                HasBackground = false
            };
            button.Size = new Vector2(label.Rect.Width, label.Rect.Height);
            button.AddItem(label);
            button.OnClick += ((object obj, ClickEventArgs e) =>
            {
                ExitScreen();
            });
            stack.AddItem(button);

            //create the scroll layout and add the stack
            _layout = new ScrollLayout()
            {
                Horizontal = HorizontalAlignment.Right,
                Vertical   = VerticalAlignment.Bottom,
                Size       = new Vector2(label.Rect.Width, label.Rect.Height)
            };
            _layout.Position = new Point(ResolutionBuddy.Resolution.ScreenArea.Right, ResolutionBuddy.Resolution.ScreenArea.Bottom);

            _layout.AddItem(stack);
            AddItem(_layout);
        }
Beispiel #10
0
        public void Stack_AddItem_default()
        {
            _stack.Position = new Point(10, 20);

            var shim = new Shim()
            {
                Position = new Point(100, 200),
                Size     = new Vector2(30, 40)
            };

            _stack.AddItem(shim);

            Assert.AreEqual(-5, _stack.Rect.X);
            Assert.AreEqual(20, _stack.Rect.Y);
            Assert.AreEqual(30, _stack.Rect.Width);
            Assert.AreEqual(40, _stack.Rect.Height);
            Assert.AreEqual(-5, shim.Rect.X);
            Assert.AreEqual(20, shim.Rect.Y);
            Assert.AreEqual(HorizontalAlignment.Center, shim.Horizontal);
            Assert.AreEqual(VerticalAlignment.Top, shim.Vertical);
        }
Beispiel #11
0
        public override async Task LoadContent()
        {
            await base.LoadContent();

            AddCancelButton();

            touches = ScreenManager.Game.Services.GetService <ITouchManager>();

            var stack = new StackLayout()
            {
                Alignment  = StackAlignment.Bottom,
                Horizontal = HorizontalAlignment.Left,
                Vertical   = VerticalAlignment.Bottom
            };

            stack.Position = new Point(ResolutionBuddy.Resolution.ScreenArea.Left, ResolutionBuddy.Resolution.ScreenArea.Bottom);

            var label = new Label("butt", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };

            stack.AddItem(label);

            label = new Label("nuts", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);
            AddItem(stack);

            stack = new StackLayout()
            {
                Alignment  = StackAlignment.Bottom,
                Horizontal = HorizontalAlignment.Center,
                Vertical   = VerticalAlignment.Bottom
            };
            stack.Position = new Point(ResolutionBuddy.Resolution.ScreenArea.Center.X, ResolutionBuddy.Resolution.ScreenArea.Bottom);

            label = new Label("butt", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);

            label = new Label("nuts", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);
            AddItem(stack);

            stack = new StackLayout()
            {
                Alignment  = StackAlignment.Bottom,
                Horizontal = HorizontalAlignment.Right,
                Vertical   = VerticalAlignment.Bottom
            };
            stack.Position = new Point(ResolutionBuddy.Resolution.ScreenArea.Right, ResolutionBuddy.Resolution.ScreenArea.Bottom);

            label = new Label("butt", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);

            label = new Label("nuts", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);
            AddItem(stack);

            stack = new StackLayout()
            {
                Alignment  = StackAlignment.Left,
                Horizontal = HorizontalAlignment.Right,
                Vertical   = VerticalAlignment.Center
            };
            stack.Position = new Point(ResolutionBuddy.Resolution.ScreenArea.Left, ResolutionBuddy.Resolution.ScreenArea.Center.Y);

            label = new Label("butt", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);

            label = new Label("nuts", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);
            AddItem(stack);

            stack = new StackLayout()
            {
                Alignment  = StackAlignment.Right,
                Horizontal = HorizontalAlignment.Right,
                Vertical   = VerticalAlignment.Center
            };
            stack.Position = new Point(ResolutionBuddy.Resolution.ScreenArea.Right, ResolutionBuddy.Resolution.ScreenArea.Center.Y);

            label = new Label("butt", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);

            label = new Label("nuts", Content, FontSize.Small)
            {
                HasOutline    = true,
                HasBackground = false
            };
            stack.AddItem(label);
            AddItem(stack);
        }
Beispiel #12
0
        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;
        }