2019-08-07 22:25:33 +02:00
using System ;
using Microsoft.Xna.Framework ;
2019-08-09 15:15:22 +02:00
using Microsoft.Xna.Framework.Graphics ;
2019-08-07 22:25:33 +02:00
using Microsoft.Xna.Framework.Input ;
2019-08-09 15:15:22 +02:00
using MLEM.Extended.Extensions ;
2019-08-09 19:28:48 +02:00
using MLEM.Font ;
2019-08-07 22:25:33 +02:00
using MLEM.Input ;
2019-08-07 21:26:16 +02:00
using MLEM.Startup ;
2019-08-09 15:15:22 +02:00
using MLEM.Textures ;
2019-08-09 18:26:28 +02:00
using MLEM.Ui ;
using MLEM.Ui.Elements ;
2019-08-09 15:15:22 +02:00
using MonoGame.Extended.TextureAtlases ;
2019-08-07 21:26:16 +02:00
namespace Tests {
public class GameImpl : MlemGame {
2019-08-09 15:15:22 +02:00
private Texture2D testTexture ;
private NinePatch testPatch ;
2019-08-09 18:26:28 +02:00
private UiSystem uiSystem ;
2019-08-09 22:04:26 +02:00
public GameImpl ( ) {
this . IsMouseVisible = true ;
}
2019-08-09 15:15:22 +02:00
protected override void LoadContent ( ) {
base . LoadContent ( ) ;
this . testTexture = LoadContent < Texture2D > ( "Textures/Test" ) ;
this . testPatch = new NinePatch ( new TextureRegion ( this . testTexture , 0 , 8 , 24 , 24 ) , 8 ) ;
2019-08-09 18:26:28 +02:00
// Ui system tests
2019-08-09 22:04:26 +02:00
this . uiSystem = new UiSystem ( this . Window , this . GraphicsDevice , 5 , new GenericSpriteFont ( LoadContent < SpriteFont > ( "Fonts/TestFont" ) ) , this . InputHandler ) ;
2019-08-09 18:26:28 +02:00
2019-08-09 19:28:48 +02:00
var root = new Panel ( Anchor . BottomLeft , new Vector2 ( 100 , 100 ) , new Point ( 5 , 5 ) , this . testPatch ) ;
2019-08-09 22:04:26 +02:00
root . AddChild ( new Paragraph ( Anchor . AutoLeft , 1 , "This is a test text that is hopefully long enough to cover at least a few lines, otherwise it would be very sad." , 0.2F ) ) ;
root . AddChild ( new Button ( Anchor . AutoCenter , new Vector2 ( 1 , 15 ) , new NinePatch ( new TextureRegion ( this . testTexture , 24 , 8 , 16 , 16 ) , 4 ) , "Test Button" ) {
OnClicked = ( element , pos , button ) = > {
if ( button = = MouseButton . Left )
Console . WriteLine ( "Clicked" ) ;
}
} ) ;
2019-08-09 18:26:28 +02:00
this . uiSystem . Add ( "Test" , root ) ;
2019-08-09 15:15:22 +02:00
}
2019-08-07 22:25:33 +02:00
protected override void Update ( GameTime gameTime ) {
base . Update ( gameTime ) ;
// Input tests
if ( Input . IsKeyPressed ( Keys . A ) )
Console . WriteLine ( "A was pressed" ) ;
if ( Input . IsMouseButtonPressed ( MouseButton . Left ) )
Console . WriteLine ( "Left was pressed" ) ;
if ( Input . IsGamepadButtonPressed ( 0 , Buttons . A ) )
Console . WriteLine ( "Gamepad A was pressed" ) ;
2019-08-09 18:26:28 +02:00
this . uiSystem . Update ( gameTime ) ;
2019-08-07 22:25:33 +02:00
}
2019-08-07 21:26:16 +02:00
2019-08-09 15:15:22 +02:00
protected override void Draw ( GameTime gameTime ) {
base . Draw ( gameTime ) ;
this . GraphicsDevice . Clear ( Color . Black ) ;
2019-08-09 19:28:48 +02:00
this . uiSystem . Draw ( gameTime , this . SpriteBatch , samplerState : SamplerState . PointClamp ) ;
2019-08-09 15:15:22 +02:00
}
2019-08-07 21:26:16 +02:00
}
}