Difference between revisions of "Ruminate Example"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Setup)
(Create a new screen)
Line 80: Line 80:
 
       var text = new Text(game.GreySpriteFont, Color.Black);
 
       var text = new Text(game.GreySpriteFont, Color.Black);
  
       _gui = new Gui(game, skin, text, testSkins, testTexts) {
+
       _gui = new Gui(game, skin, text);
          Widgets = new Widget[] {                                           
+
      _gui.AddWidget(
               new SingleLineTextBox(10, 550, 120, 10) { Value = "0123456789" }, //Test with default value
+
          new Panel(10,10,300,300)
               new SingleLineTextBox(10, 575, 120, 10) { Value = "0123456789", Text = "testText" } //Test with specified font
+
          {
 +
              Children = new Widget[] {                                           
 +
               new Button(10,10,"test"),  
 +
               new SingleLineTextBox(10, 50, 120, 10) { Value = "Hello World"}
 
           }
 
           }
       };
+
       });
 
  }
 
  }
  

Revision as of 10:44, 10 October 2017

Installation

Open the nuget package console (under tools) and run the command

Install-Package MonoGame.Framework.Gui -Version 1.0.1

Now you need to download the following zip file which contains the content folder for Ruminate, you need to extract this into the content folder of your project:

https://drive.google.com/file/d/0Bw-0YEA_JX9gcFEyY1F2aXVJbGs/view?usp=sharing

Setup

Click on project and create a new class, call it Screen.cs. Copy the following code:

using Microsoft.Xna.Framework;

namespace YourNameSpace {

    public abstract class Screen {

        public Color Color { get; set; }

        public abstract void Init(Game1 game);
        public abstract void OnResize();
        public abstract void Update(GameTime time);
        public abstract void Draw();
    }
}

Remember to use the original namespace from when you created the class.

Create a new screen

Create a new class from the project menu and name the class screen1. You need to add the following to the using section of the new class;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Ruminate.GUI.Content;
using Ruminate.GUI.Framework;

Edit the class declaration to make it a class of Screen:

class screen1: Screen{

}

Within the new class add the following variable:

 Gui _gui;

Now copy the following methods into the class:

 public override void OnResize() {            
     _gui.Resize();              
 }

 public override void Update() {
     _gui.Update();
 }

 public override void Draw() {
     _gui.Draw();
 }

the final method required is an Init method, create the following method:

 public override void Init(Game1 game) {

      Color = Color.White;

      var skin = new Skin(game.GreyImageMap, game.GreyMap);
      var text = new Text(game.GreySpriteFont, Color.Black);

      _gui = new Gui(game, skin, text);
      _gui.AddWidget(
          new Panel(10,10,300,300)
          {
              Children = new Widget[] {                                           
              new Button(10,10,"test"), 
              new SingleLineTextBox(10, 50, 120, 10) { Value = "Hello World"}
          }
      });
 }

Displaying a screen

Add the following variables into your Game1.cs:

Screen _currentScreen;
Screen[] _currentScreens;

public SpriteFont GreySpriteFont;
public Texture2D GreyImageMap;
public string GreyMap;

In the LoadContent method of Game1.cs add the following to load the textures and imagemap:

GreyImageMap = Content.Load<Texture2D>(@"GreySkin\ImageMap");
GreyMap = File.OpenText(@"GreySkin\Map.txt").ReadToEnd();
GreySpriteFont = Content.Load<SpriteFont>(@"GreySkin\Texture");