1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

generify the demos to make them work on android and desktop

This commit is contained in:
Ellpeck 2019-09-01 11:55:41 +02:00
parent 3603de78d0
commit b1ce3dc933
23 changed files with 170 additions and 522 deletions

View file

@ -1,25 +0,0 @@
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views;
namespace AndroidTests {
[Activity(Label = "AndroidTests"
, MainLauncher = true
, Icon = "@drawable/icon"
, Theme = "@style/Theme.Splash"
, AlwaysRetainTaskState = true
, LaunchMode = LaunchMode.SingleInstance
, ScreenOrientation = ScreenOrientation.UserLandscape
, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]
public class Activity1 : Microsoft.Xna.Framework.AndroidGameActivity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
var g = new GameImpl();
this.SetContentView((View) g.Services.GetService(typeof(View)));
g.Run();
}
}
}

View file

@ -1,113 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{410C0262-131C-4D0E-910D-D01B4F7143E0}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<AndroidApplication>true</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidSupportedAbis>armeabi-v7a;x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions>.m4a</AndroidStoreUncompressedFileExtensions>
<MandroidI18n />
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<MonoGamePlatform>Android</MonoGamePlatform>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<RootNamespace>AndroidTests</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE;ANDROID</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>TRACE;ANDROID</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
</PropertyGroup>
<ItemGroup>
<Reference Include="Coroutine, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Coroutine.1.0.1\lib\netstandard2.0\Coroutine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="MonoGame.Extended, Version=3.7.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\MonoGame.Extended.3.7.0\lib\netstandard2.0\MonoGame.Extended.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="MonoGame.Framework">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Android\MonoGame.Framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="GameImpl.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Values\Strings.xml" />
<AndroidResource Include="Resources\Drawable\Icon.png" />
<AndroidResource Include="Resources\Drawable\Splash.png" />
<AndroidResource Include="Resources\Values\Styles.xml" />
</ItemGroup>
<ItemGroup>
<MonoGameContentReference Include="Content\Content.mgcb" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MLEM.Extended\MLEM.Extended.csproj">
<Project>{232a6513-a28c-4d7f-ba5a-89281bfc1538}</Project>
<Name>MLEM.Extended</Name>
</ProjectReference>
<ProjectReference Include="..\MLEM.Startup\MLEM.Startup.csproj">
<Project>{997f4739-7bec-4621-b9ca-68deb2d74412}</Project>
<Name>MLEM.Startup</Name>
</ProjectReference>
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj">
<Project>{6f00629a-8b87-4264-8896-19983285e32f}</Project>
<Name>MLEM.Ui</Name>
</ProjectReference>
<ProjectReference Include="..\MLEM\MLEM.csproj">
<Project>{1d6ab762-43c4-4775-8924-707c7ec3f142}</Project>
<Name>MLEM</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Content\Fonts\TestFont.spritefont" />
<None Include="Content\Textures\Test.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
</Project>

View file

@ -1,34 +0,0 @@
#----------------------------- Global Properties ----------------------------#
/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:Android
/config:
/profile:Reach
/compress:False
#-------------------------------- References --------------------------------#
#---------------------------------- Content ---------------------------------#
#begin Textures/Test.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/Test.png
#begin Fonts/TestFont.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Fonts/TestFont.spritefont

View file

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>Arial</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>32</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>
<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>
<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<DefaultCharacter>*</DefaultCharacter>
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#591;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 896 B

View file

@ -1,57 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
using MLEM.Startup;
using MLEM.Textures;
using MLEM.Ui;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
namespace AndroidTests {
public class GameImpl : MlemGame {
protected override void LoadContent() {
base.LoadContent();
var tex = LoadContent<Texture2D>("Textures/Test");
var style = new UntexturedStyle(this.SpriteBatch) {
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
TextScale = 0.1F,
PanelTexture = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8),
ButtonTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
TextFieldTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
ScrollBarBackground = new NinePatch(new TextureRegion(tex, 12, 0, 4, 8), 1, 1, 2, 2),
ScrollBarScrollerTexture = new NinePatch(new TextureRegion(tex, 8, 0, 4, 8), 1, 1, 2, 2),
CheckboxTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
CheckboxCheckmark = new TextureRegion(tex, 24, 0, 8, 8),
RadioTexture = new NinePatch(new TextureRegion(tex, 16, 0, 8, 8), 3),
RadioCheckmark = new TextureRegion(tex, 32, 0, 8, 8)
};
this.UiSystem.Style = style;
this.UiSystem.GlobalScale = 15;
this.UiSystem.AutoScaleWithScreen = true;
var panel = new Panel(Anchor.Center, new Vector2(100, 50), Vector2.Zero, false, true, new Point(5, 10));
this.UiSystem.Add("Panel", panel);
panel.AddChild(new Paragraph(Anchor.AutoLeft, 1, "I am Android"));
var image = new Image(Anchor.AutoCenter, new Vector2(50, 50), new TextureRegion(tex, 0, 0, 8, 8)) {IsHidden = true};
panel.AddChild(image);
panel.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Toggle Image") {
OnPressed = element => image.IsHidden = !image.IsHidden
});
panel.AddChild(new TextField(Anchor.AutoLeft, new Vector2(1, 10)) {PlaceholderText = "Tap to type"});
panel.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Here is some text that makes it so that the panel is actually long enough for me to try out the scroll behavior."));
panel.AddChild(new Slider(Anchor.AutoLeft, new Vector2(1, 10), 5, 100));
panel.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sapien elit, congue sit amet condimentum in, hendrerit iaculis leo. Phasellus mollis turpis felis, ac finibus elit tincidunt quis. Vestibulum maximus, velit non consequat porttitor, quam diam consequat eros, in cursus nunc mi id dui. Vivamus semper neque at feugiat semper. Nunc ultrices egestas placerat. Proin lectus felis, rutrum quis porta vel, eleifend eget eros. Morbi porttitor massa finibus felis vestibulum, quis faucibus dui volutpat. Nam enim mi, euismod a pharetra vel, suscipit eu tortor. Integer vehicula ligula at consectetur dictum. Etiam fringilla volutpat est, id egestas nunc. Maecenas turpis felis, eleifend non felis a, fringilla lobortis nibh. Morbi rhoncus vestibulum dignissim. Ut posuere nulla ipsum, non condimentum dui posuere sit amet."));
}
protected override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.CornflowerBlue);
base.DoDraw(gameTime);
}
}
}

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AndroidTests" android:versionCode="1" android:versionName="1.0">
<uses-sdk />
<application android:label="AndroidTests"></application>
</manifest>

View file

@ -1,41 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AndroidTests")]
[assembly: AssemblyProduct("AndroidTests")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6f377592-2266-4c47-855e-6260ff75e1f4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

View file

@ -1,99 +0,0 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: global::Android.Runtime.ResourceDesignerAttribute("AndroidTests.Resource", IsApplication=true)]
namespace AndroidTests
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int Icon = 2130837504;
// aapt resource value: 0x7f020001
public const int Splash = 2130837505;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class String
{
// aapt resource value: 0x7f030001
public const int ApplicationName = 2130903041;
// aapt resource value: 0x7f030000
public const int Hello = 2130903040;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
public partial class Style
{
// aapt resource value: 0x7f040000
public const int Theme_Splash = 2130968576;
static Style()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Style()
{
}
}
}
}
#pragma warning restore 1591

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Hello">Hello World, Click Me!</string>
<string name="ApplicationName">AndroidTests</string>
</resources>

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Coroutine" version="1.0.1" targetFramework="monoandroid90" />
<package id="MonoGame.Extended" version="3.7.0" targetFramework="monoandroid90" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="monoandroid90" />
</packages>

View file

@ -7,12 +7,15 @@ using MLEM.Startup;
using MLEM.Textures; using MLEM.Textures;
namespace Demos { namespace Demos {
public class AnimationDemo : MlemGame { public class AnimationDemo : Demo {
private SpriteAnimationGroup group; private SpriteAnimationGroup group;
private int facing; private int facing;
protected override void LoadContent() { public AnimationDemo(MlemGame game) : base(game) {
}
public override void LoadContent() {
base.LoadContent(); base.LoadContent();
var tex = LoadContent<Texture2D>("Textures/Anim"); var tex = LoadContent<Texture2D>("Textures/Anim");
@ -37,7 +40,7 @@ namespace Demos {
// you can also add a priority to an animation in the group (10 in this case, which is higher than the default of 0) // you can also add a priority to an animation in the group (10 in this case, which is higher than the default of 0)
// if two animations' playing conditions are both true, then the one with the higher priority will be picked to play // if two animations' playing conditions are both true, then the one with the higher priority will be picked to play
// in this instance, a standing "animation" is displayed when we're facing down and also holding the space key // in this instance, a standing "animation" is displayed when we're facing down and also holding the space key
this.group.Add(new SpriteAnimation(1F, tex, new Rectangle(0, 0, 8, 8)) {Name = "DownStanding"}, () => this.facing == 0 && Input.IsKeyDown(Keys.Space), 10); this.group.Add(new SpriteAnimation(1F, tex, new Rectangle(0, 0, 8, 8)) {Name = "DownStanding"}, () => this.facing == 0 && this.InputHandler.IsKeyDown(Keys.Space), 10);
// you can also add a callback to see when the animation used changes // you can also add a callback to see when the animation used changes
this.group.OnAnimationChanged += (anim, newAnim) => { this.group.OnAnimationChanged += (anim, newAnim) => {
@ -45,7 +48,7 @@ namespace Demos {
}; };
} }
protected override void Update(GameTime gameTime) { public override void Update(GameTime gameTime) {
base.Update(gameTime); base.Update(gameTime);
if (this.InputHandler.IsKeyDown(Keys.Down)) if (this.InputHandler.IsKeyDown(Keys.Down))
@ -62,7 +65,7 @@ namespace Demos {
this.group.Update(gameTime); this.group.Update(gameTime);
} }
protected override void DoDraw(GameTime gameTime) { public override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black); this.GraphicsDevice.Clear(Color.Black);
this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(10)); this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(10));

View file

@ -7,12 +7,15 @@ namespace Demos {
/// <summary> /// <summary>
/// This is a demo for <see cref="AutoTiling"/>. /// This is a demo for <see cref="AutoTiling"/>.
/// </summary> /// </summary>
public class AutoTilingDemo : MlemGame { public class AutoTilingDemo : Demo {
private Texture2D texture; private Texture2D texture;
private string[] layout; private string[] layout;
protected override void LoadContent() { public AutoTilingDemo(MlemGame game) : base(game) {
}
public override void LoadContent() {
base.LoadContent(); base.LoadContent();
// The layout of the texture is important for auto tiling to work correctly. // The layout of the texture is important for auto tiling to work correctly.
// It needs to be laid out as follows: Five tiles aligned horizontally within the texture file, with the following information // It needs to be laid out as follows: Five tiles aligned horizontally within the texture file, with the following information
@ -35,7 +38,7 @@ namespace Demos {
}; };
} }
protected override void DoDraw(GameTime gameTime) { public override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black); this.GraphicsDevice.Clear(Color.Black);
// the texture region supplied to the AutoTiling method should only encompass the first filler tile's location and size // the texture region supplied to the AutoTiling method should only encompass the first filler tile's location and size

37
Demos/Demo.cs Normal file
View file

@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Input;
using MLEM.Startup;
using MLEM.Ui;
namespace Demos {
public class Demo {
public readonly MlemGame Game;
public SpriteBatch SpriteBatch => this.Game.SpriteBatch;
public GraphicsDevice GraphicsDevice => this.Game.GraphicsDevice;
public InputHandler InputHandler => this.Game.InputHandler;
public UiSystem UiSystem => this.Game.UiSystem;
public Demo(MlemGame game) {
this.Game = game;
}
public virtual void LoadContent() {
}
public virtual void Update(GameTime time) {
}
public virtual void DoDraw(GameTime time) {
}
public virtual void Clear() {
}
public static T LoadContent<T>(string name) {
return MlemGame.LoadContent<T>(name);
}
}
}

View file

@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net462</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -13,13 +12,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" /> <PackageReference Include="MonoGame.Framework.Portable" Version="3.7.1.189">
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.7.0.1708" /> <PrivateAssets>all</PrivateAssets>
</ItemGroup> </PackageReference>
<ItemGroup>
<MonoGameContentReference Include="Content\Content.mgcb" />
<Content Include="Content\*\**" />
</ItemGroup> </ItemGroup>
</Project> </Project>

89
Demos/GameImpl.cs Normal file
View file

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
using MLEM.Startup;
using MLEM.Textures;
using MLEM.Ui;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
namespace Demos {
public class GameImpl : MlemGame {
private static readonly Dictionary<string, Func<MlemGame, Demo>> Demos = new Dictionary<string, Func<MlemGame, Demo>>();
private Demo activeDemo;
static GameImpl() {
Demos.Add("Ui", game => new UiDemo(game));
Demos.Add("Animation", game => new AnimationDemo(game));
Demos.Add("AutoTiling", game => new AutoTilingDemo(game));
Demos.Add("Pathfinding", game => new PathfindingDemo(game));
}
public GameImpl() {
this.IsMouseVisible = true;
}
protected override void LoadContent() {
base.LoadContent();
var tex = LoadContent<Texture2D>("Textures/Test");
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
TextScale = 0.1F,
PanelTexture = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8),
ButtonTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
ScrollBarBackground = new NinePatch(new TextureRegion(tex, 12, 0, 4, 8), 1, 1, 2, 2),
ScrollBarScrollerTexture = new NinePatch(new TextureRegion(tex, 8, 0, 4, 8), 1, 1, 2, 2),
};
this.UiSystem.AutoScaleReferenceSize = new Point(1280, 720);
this.UiSystem.AutoScaleWithScreen = true;
this.UiSystem.GlobalScale = 5;
var selection = new Panel(Anchor.Center, new Vector2(100, 80), Vector2.Zero, false, true, new Point(5, 10));
this.UiSystem.Add("DemoSelection", selection);
var backButton = new Button(Anchor.TopRight, new Vector2(30, 10), "Back") {
OnPressed = e => {
this.activeDemo.Clear();
this.activeDemo = null;
this.UiSystem.Remove("BackButton");
this.UiSystem.Add("DemoSelection", selection);
}
};
selection.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Select the demo you want to see below. Check the demos' source code for more in-depth explanations of their functionality."));
selection.AddChild(new VerticalSpace(5));
foreach (var demo in Demos) {
selection.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 10), demo.Key) {
OnPressed = e => {
this.UiSystem.Remove("DemoSelection");
this.UiSystem.Add("BackButton", backButton);
this.activeDemo = demo.Value.Invoke(this);
this.activeDemo.LoadContent();
},
PositionOffset = new Vector2(0, 1)
});
}
}
protected override void DoDraw(GameTime gameTime) {
if (this.activeDemo != null) {
this.activeDemo.DoDraw(gameTime);
} else {
this.GraphicsDevice.Clear(Color.CornflowerBlue);
}
base.DoDraw(gameTime);
}
protected override void Update(GameTime gameTime) {
base.Update(gameTime);
if (this.activeDemo != null)
this.activeDemo.Update(gameTime);
}
}
}

View file

@ -10,12 +10,16 @@ using MLEM.Startup;
using MonoGame.Extended; using MonoGame.Extended;
namespace Demos { namespace Demos {
public class PathfindingDemo : MlemGame { public class PathfindingDemo : Demo {
private bool[,] world; private bool[,] world;
private AStar2 pathfinder; private AStar2 pathfinder;
private List<Point> path; private List<Point> path;
public PathfindingDemo(MlemGame game) : base(game) {
}
private void Init() { private void Init() {
// generate a simple random world for testing, where true is walkable area, and false is a wall // generate a simple random world for testing, where true is walkable area, and false is a wall
var random = new Random(); var random = new Random();
@ -53,21 +57,21 @@ namespace Demos {
Console.WriteLine("Couldn't find a path, press the left mouse button to try again"); Console.WriteLine("Couldn't find a path, press the left mouse button to try again");
} }
protected override void LoadContent() { public override void LoadContent() {
base.LoadContent(); base.LoadContent();
this.Init(); this.Init();
} }
protected override void Update(GameTime gameTime) { public override void Update(GameTime gameTime) {
base.Update(gameTime); base.Update(gameTime);
// when pressing the left mouse button, generate a new world and find a new path // when pressing the left mouse button, generate a new world and find a new path
if (Input.IsMouseButtonPressed(MouseButton.Left)) { if (this.InputHandler.IsMouseButtonPressed(MouseButton.Left)) {
this.Init(); this.Init();
} }
} }
protected override void DoDraw(GameTime gameTime) { public override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.White); this.GraphicsDevice.Clear(Color.White);
this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(14)); this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(14));

View file

@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
namespace Demos {
public static class Program {
private static readonly Dictionary<string, Func<Game>> Demos = new Dictionary<string, Func<Game>>();
static Program() {
Demos.Add("Ui", () => new UiDemo());
Demos.Add("AutoTiling", () => new AutoTilingDemo());
Demos.Add("Animation", () => new AnimationDemo());
Demos.Add("Pathfinding", () => new PathfindingDemo());
}
public static void Main(string[] args) {
Func<Game> demoUsed;
if (args.Length <= 0 || !Demos.ContainsKey(args[0])) {
beforeDemo:
Console.WriteLine("Please type the name of the demo you want to see and press Enter.");
Console.WriteLine("The following demos are available: " + string.Join(", ", Demos.Keys));
Console.WriteLine("(Alternatively, you can supply the name of the demo you want to see as the first argument)");
var demo = Console.ReadLine();
if (!Demos.ContainsKey(demo)) {
Console.WriteLine("Not a valid demo.");
goto beforeDemo;
} else {
demoUsed = Demos[demo];
}
} else {
demoUsed = Demos[args[0]];
}
using (var game = demoUsed.Invoke())
game.Run();
}
}
}

View file

@ -22,16 +22,15 @@ namespace Demos {
/// - Call the instance's DrawEarly method before clearing your <see cref="GraphicsDevice"/> /// - Call the instance's DrawEarly method before clearing your <see cref="GraphicsDevice"/>
/// - Call the instance's Draw method in your game's Draw method /// - Call the instance's Draw method in your game's Draw method
/// </remarks> /// </remarks>
public class UiDemo : MlemGame { public class UiDemo : Demo {
private Texture2D testTexture; private Texture2D testTexture;
private NinePatch testPatch; private NinePatch testPatch;
public UiDemo() { public UiDemo(MlemGame game) : base(game) {
this.IsMouseVisible = true;
} }
protected override void LoadContent() { public override void LoadContent() {
this.testTexture = LoadContent<Texture2D>("Textures/Test"); this.testTexture = LoadContent<Texture2D>("Textures/Test");
this.testPatch = new NinePatch(new TextureRegion(this.testTexture, 0, 8, 24, 24), 8); this.testPatch = new NinePatch(new TextureRegion(this.testTexture, 0, 8, 24, 24), 8);
base.LoadContent(); base.LoadContent();
@ -55,7 +54,7 @@ namespace Demos {
RadioTexture = new NinePatch(new TextureRegion(this.testTexture, 16, 0, 8, 8), 3), RadioTexture = new NinePatch(new TextureRegion(this.testTexture, 16, 0, 8, 8), 3),
RadioCheckmark = new TextureRegion(this.testTexture, 32, 0, 8, 8) RadioCheckmark = new TextureRegion(this.testTexture, 32, 0, 8, 8)
}; };
var untexturedStyle = this.UiSystem.Style; var untexturedStyle = new UntexturedStyle(this.SpriteBatch);
// set the defined style as the current one // set the defined style as the current one
this.UiSystem.Style = style; this.UiSystem.Style = style;
// scale every ui up by 5 // scale every ui up by 5
@ -200,7 +199,12 @@ namespace Demos {
button.AddedDisplayOffset = Vector2.Zero; button.AddedDisplayOffset = Vector2.Zero;
} }
protected override void DoDraw(GameTime gameTime) { public override void Clear() {
this.UiSystem.Remove("Test");
this.UiSystem.Remove("TestTooltip");
}
public override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.CornflowerBlue); this.GraphicsDevice.Clear(Color.CornflowerBlue);
base.DoDraw(gameTime); base.DoDraw(gameTime);
} }

View file

@ -10,7 +10,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demos", "Demos\Demos.csproj
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Ui", "MLEM.Ui\MLEM.Ui.csproj", "{6F00629A-8B87-4264-8896-19983285E32F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Ui", "MLEM.Ui\MLEM.Ui.csproj", "{6F00629A-8B87-4264-8896-19983285E32F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndroidTests", "AndroidTests\AndroidTests.csproj", "{410C0262-131C-4D0E-910D-D01B4F7143E0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demos.DesktopGL", "Demos.DesktopGL\Demos.DesktopGL.csproj", "{468A868F-FB75-4D48-BC03-6F9FCDB014C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demos.Android", "AndroidDemos\Demos.Android.csproj", "{410C0262-131C-4D0E-910D-D01B4F7143E0}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -38,6 +40,10 @@ Global
{6F00629A-8B87-4264-8896-19983285E32F}.Debug|Any CPU.Build.0 = Debug|Any CPU {6F00629A-8B87-4264-8896-19983285E32F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F00629A-8B87-4264-8896-19983285E32F}.Release|Any CPU.ActiveCfg = Release|Any CPU {6F00629A-8B87-4264-8896-19983285E32F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F00629A-8B87-4264-8896-19983285E32F}.Release|Any CPU.Build.0 = Release|Any CPU {6F00629A-8B87-4264-8896-19983285E32F}.Release|Any CPU.Build.0 = Release|Any CPU
{468A868F-FB75-4D48-BC03-6F9FCDB014C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{468A868F-FB75-4D48-BC03-6F9FCDB014C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{468A868F-FB75-4D48-BC03-6F9FCDB014C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{468A868F-FB75-4D48-BC03-6F9FCDB014C9}.Release|Any CPU.Build.0 = Release|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {410C0262-131C-4D0E-910D-D01B4F7143E0}.Release|Any CPU.ActiveCfg = Release|Any CPU