Giter Club home page Giter Club logo

mlem's Introduction

The MLEM logo

MLEM Library for Extending MonoGame and FNA is a set of multipurpose libraries for the game frameworks MonoGame and FNA that provides abstractions, quality of life improvements and additional features like an extensive ui system and easy input handling.

MLEM is platform-agnostic and multi-targets .NET Standard 2.0, .NET 8.0 and .NET Framework 4.5.2, which makes it compatible with MonoGame and FNA on Desktop, mobile devices and consoles.

What next?

Packages

  • MLEM is the base package, which provides various small addons and abstractions for MonoGame and FNA, including a text formatting system and simple input handling
  • MLEM.Ui provides a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types
  • MLEM.Extended ties in with MonoGame.Extended and other MonoGame and FNA libraries
  • MLEM.Data provides simple loading and processing of textures and other data, including the ability to load non-XNB content files easily
  • MLEM.Startup combines MLEM with some other useful libraries into a quick Game startup class
  • MLEM.Templates contains cross-platform project templates

Made with MLEM

If you created a project with the help of MLEM, you can get it added to this list by submitting an issue or a pull request. If its source is public, other people will be able to use your project as an example, too!

Gallery

Here are some images that show a couple of MLEM's features.

The MLEM.Ui demo in action:

A gif showing various user interface elements from the MLEM.Ui demo

MLEM's text formatting system, which is compatible with both MLEM.Ui and regular sprite batch rendering:

An image showing text with various colors and other formatting

Friends of MLEM

There are several other libraries and tools that work well in combination with MonoGame, FNA and MLEM. Here are some of them:

  • Contentless, a tool that removes the need to add assets to the MonoGame Content Pipeline manually
  • GameBundle, a tool that packages MonoGame and other .NET applications into several distributable formats
  • Coroutine, a package that implements Unity-style coroutines for any project
  • MonoGame.Extended, a package that also provides several additional features for MonoGame

mlem's People

Contributors

ellpeck avatar luanfagu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mlem's Issues

Add TextAlignment.Justified for formatted text

Would need formatted text to know a maximum width even when not splitting or truncating, so the best way to make this happen would probably be to add an optional width param to Realign and throw if it's not passed when the text alignment is justified

Correct method for setting viewport with `BoxingViewportAdapter`.

Hello,

I'm using MLEM.Ui to make a personal game project, and so far it's been great, however I'm having a small issue with the viewport system interacting with the BoxingViewportAdapter from MonoGame.Extended. When my window resizes to a resolution that is not exactly 16:9 (which is my target aspect ratio using the BoxingViewportAdapter, which has it's virtual resolution set to 1280x720), I was initially updating the viewport of the system like so:

uiSystem.Viewport = ViewportAdapter.Viewport.Bounds;

However, this resulted in the UI being offset by (x, y) from the top left of the viewport, where the amount was equal to Viewport.Bounds.Location (image below), clipping the UI into the bottom of the screen, however at this stage the input handler was detecting hovering over the buttons at the correct locations (viewport indicated in red here, although it extends past the bottom of the clipped region).

Incorrect Viewport Offset

To fix this visual offset, I have tried both setting the viewport's Location to (0, 0), and also creating a translation matrix applied to all top level elements (eg. Matrix translate = Matrix.CreateTranslation(-newVP.X, -newVP.Y, 0)). Both of these approaches do work, however this results in the input handling for the UI being offset incorrectly by the amount of the translation.

What is the correct way to implement this viewport adjustment without either compromising the input handler or the GUI's visual location?

Allow dropdowns to have scrollable panels

Hi. I'm using MLEM in my upcoming remake of MultiMachineBuilder.
I'll want to make an inventory list, but there are no list controls.
Please add a scrollable list with customizable rendering and model types

Initializing InputHandler with handleTouch=false leads to crash on Update

Environment: MacOS Ventura / M1 (arm64)

Repro steps:

  1. Build and Run the Demo. Note that it runs just fine.
  2. In MlemGame.LoadContent(), modify the initialization of this.InputHandler to set the optional handleX parameters as follows:
this.InputHandler = new InputHandler(this, true, true, false, false); // everything true but handleTouch
  1. Build and Run again. Note the following runtime error:
"/path/to/mlem/clone/MLEM/Demos.DesktopGL/bin/Debug/net7.0/MLEM Desktop Demos"
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at MLEM.Ui.UiControls.Update() in /path/to/mlem/clone/MLEM/MLEM.Ui/UiControls.cs:line 226
   at MLEM.Ui.UiSystem.Update(GameTime time) in /path/to/mlem/clone/MLEM/MLEM.Ui/UiSystem.cs:line 274
   at Microsoft.Xna.Framework.Game.<>c.<.cctor>b__116_1(IUpdateable updateable, GameTime gameTime)
   at Microsoft.Xna.Framework.Game.SortingFilteringCollection`1.ForEachFilteredItem[TUserData](Action`2 action, TUserData userData)
   at Microsoft.Xna.Framework.Game.Update(GameTime gameTime)
   at MLEM.Startup.MlemGame.DoUpdate(GameTime gameTime) in /path/to/mlem/clone/MLEM/MLEM.Startup/MlemGame.cs:line 144
   at Demos.GameImpl.DoUpdate(GameTime gameTime) in /path/to/mlem/clone/MLEM/Demos/GameImpl.cs:line 117
   at MLEM.Startup.MlemGame.Update(GameTime gameTime) in /path/to/mlem/clone/MLEM/MLEM.Startup/MlemGame.cs:line 102
   at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime)
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
   at Microsoft.Xna.Framework.Game.Run()
   at Demos.DesktopGL.Program.Main() in /path/to/mlem/clone/MLEM/Demos.DesktopGL/Program.cs:line 19

UiSystem.Draw throws System.MissingMethodException in FontStashSharp

UiSystem.Draw throws

System.MissingMethodException: 'Method not found: 'Single FontStashSharp.SpriteFontBase.DrawText(Microsoft.Xna.Framework.Graphics.SpriteBatch, System.String, Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Color, System.Nullable`1<Microsoft.Xna.Framework.Vector2>, Single, Microsoft.Xna.Framework.Vector2, Single, Single, Single, FontStashSharp.TextStyle, FontStashSharp.FontSystemEffect, Int32)'.'

What I did:

  • Create a new Monogame 3.8.1 WindowsDX project
  • Add the following nuget packages:
    • MLEM (6.2.0)
    • MLEM.UI (6.2.0)
    • MLEM.Extended (6.2.0)
    • FontStashSharp.MonoGame (1.3.6)
  • Add a ttf font file
  • Add the following code to LoadContent (mostly from https://mlem.ellpeck.de/articles/ui.html#adding-elements):
_fontSystem = new FontSystem();
_fontSystem.AddFont(File.ReadAllBytes(@"Content/Fonts/12-post-antiqua-roman-05554.ttf"));

var style = new UntexturedStyle(_spriteBatch)
{
    Font = new GenericStashFont(_fontSystem.GetFont(18))
};
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
_uiSystem = new UiSystem(this, style);
var box = new Panel(Anchor.Center, new Vector2(100, 1), Vector2.Zero, setHeightBasedOnChildren: true);
box.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This is some example text!"));
box.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 20), "Okay")
{
    OnPressed = element => _uiSystem.Remove("InfoBox"),
    PositionOffset = new Vector2(0, 1)
});
_uiSystem.Add("InfoBox", box);

The following code to Update:

_uiSystem.Update(gameTime);

And the following to Draw:

_uiSystem.Draw(gameTime, _spriteBatch);

FontStashSharp seems to be working on its own, I can do .DrawText and it works.

Calculating real index within `Code.DrawCharacter`

Currently, the DrawCharacter function in Code has the following function signature:

bool DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth)

I'm trying to implement a system which slowly reveals text over time, and since the token index provided as a parameter here (indexInToken) resets at the start of every new token, which can be caused by any number of other codes, there doesn't seem to be a way to discern what index within the entire scope that the Code applies to the character is at, and I need this information to determine whether enough time has passed to reveal this character or not.

For example; if I have the following text passed into the formatter:

<reveal 0.5>This is some text <u>that's being revealed!</u></reveal>

There doesn't seem to be a way for me to discern the first "T" character from "This" (real index 0) and the lowercase "t" from "that's" (real index 19) within the DrawCharacter function, as they both have a token index of 0, since the underline starts a new token. If the class had access to the raw index/index of the token that was being rendered at the time this would be fine, but I don't see any way to access that information.

Am I misjudging how the system works here? Is there a way for me to calculate the literal index of the character being drawn?
Apologies for the long issue.

DisplayArea has incorrect value in some case

Hi!

You have written that coder can use DisplayArea for mouse input handle.

I don't set size vector for image exactly, and have got this:
image

Red rectangle - DisplayArea
Blue rectangle - what I mean real DisplayArea.

So, if i try to check mouse events I can't see real image area. If I will use scaleToImage, it makes image too big, because asset is hi-res.

Add a UI debug mode that displays information about elements

It should outline all UI elements in a unique color (based on path or hash code?) and display their width and height in pixels (as well as potentially their anchor position) in the corner. This should use the default font and default font size from the UI style.

MonoGame freezes when passing non square region to NinePatch

This will run fine:
PaperBorderPatch = new NinePatch(new TextureRegion(UITextureAtlas, 128, 0, 64, 64), 16, NinePatchMode.Tile);
Where the region is 64x64

But when this is passed
PaperBorderPatch = new NinePatch(new TextureRegion(UITextureAtlas, 128, 0, 64, 32), 16, NinePatchMode.Tile);
Where the region is 64x32, MG freezes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.