1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

additional documentation article improvements

This commit is contained in:
Ell 2023-03-05 20:31:09 +01:00
parent 12af816a90
commit 24a4c23be5
5 changed files with 12 additions and 10 deletions

View file

@ -4,6 +4,8 @@ The **MLEM** base package features an extended `InputHandler` class that allows
Rather than using an event-based structure, the MLEM input handler relies on the game's `Update` frames: To query input through the input handler, you have to query it every Update frame, and input information will only be available for a single update frame in most situations.
The input handler makes use of the `GenericInput` struct, which is a MLEM wrapper around the three main types of input that MonoGame and FNA provide: `Keys`, `Buttons` and `MouseButton` (the latter of which is a MLEM abstraction of mouse buttons). Values of all of these types can be converted into `GenericInput` implicitly, and a `GenericInput` can be converted back implicitly as well, so you will rarely ever have to interact with the `GenericInput` type manually.
## Setting it up
To set it up, all you have to do is create a new instance. The constructor optionally accepts parameters to enable or disable certain kinds of input.
```cs
@ -52,7 +54,7 @@ if (this.InputHandler.TryConsumePressed(Keys.Up)) {
```
## Input metrics
The input handler tracks additional data related to keyboard, gamepad, and mouse inputs, such as the amount of times that they have been down and up for, as well as the amount of time that has passed since they were last pressed. These metrics can be useful for implementing short-press and long-press behavior.
The input handler tracks additional data related to keyboard, gamepad, and mouse inputs, such as the amount of times that they have been down for. These metrics can be useful for implementing short-press and long-press behavior.
```cs
// how long has the A key been up (or down) for the last time it was up (or down)?
@ -64,7 +66,7 @@ var timeSincePress = this.InputHandler.TryGetTimeSincePress(Keys.A);
```
## Gesture handling
MonoGame's default gesture handling (which is inherited from XNA) can be a little difficult to deal with, mainly due to the fact that gestures stay in the queue until they are queried (so they might be very old), and the fact that they can't be queried without being removed from the queue, which is especially annoying if queued gesture is not the one a specific piece of code was waiting for.
MonoGame's default gesture handling (which is inherited from XNA) can be a little difficult to deal with. This is mainly due to the fact that gestures stay in the queue until they are queried (so they might be very old), and the fact that they can't be queried without being permanently removed from the queue.
Because of this, MLEM's input handler also provides a much more streamlined user experience for touch gesture input.
@ -86,7 +88,7 @@ if (this.InputHandler.GetGesture(GestureType.Tap, out var sample)) {
### External gesture handling
If your game already handles gestures through some other means, you might notice that one of the gesture handling methods stops working correctly. This is due to the fact that MonoGame's gesture querying system only supports each gesture being queried once before it is removed from the queue, which causes any additional queries for that gesture to fail.
The input handler's gesture handling does not have this problem, since gestures are kept around for an entire update frame no matter how many times they are queried, and gestures can be queried from multiple sources based on the expected gesture type. Because of this, it's generally recommended to use the input handler's gesture system instead of the default one.
The input handler's gesture handling does not have this problem, since gestures are kept around for an entire update frame no matter how many times they are queried, and gestures can be queried from multiple sources based on the expected gesture type. Because of this, it's generally recommended that you use the input handler's gesture system instead of the default one.
However, if you want to continue using your own gesture handling, but still allow the `InputHandler` to have access to gestures (for [MLEM.Ui](ui.md), for example), you can set `ExternalGestureHandling` to true in your `InputHandler`. Then, you can use `AddExternalGesture` to make the input handler aware of a gesture for the duration of the update frame that you added it on. As an example, you could modify your game's existing gesture handling like this:
```cs

View file

@ -61,13 +61,13 @@ As `RawContentManager` automatically collects all raw content readers in the loa
## Environments without reflection or with trimming
By default, the `RawContentManager` finds all types that extend `RawContentReader` in all loaded assemblies, so they don't have to be added manually. This won't work in environments like NativeAOT, where reflection isn't as readily available, or in assemblies that get trimmed.
If you're in an environment with this restriction, you can manually collect all of the content readers that you plan on using and call the constructor that accepts a list of content readers instead:
If you're in an environment with this restriction, you can manually collect all the content readers that you plan on using and call the constructor that accepts a list of content readers instead:
```csharp
protected override void LoadContent() {
var neededReaders = new List<RawContentReader> {
new Texture2DReader(), new JsonReader() // ...
};
this.rawContent = new RawContentManager(this.Services);
this.rawContent = new RawContentManager(this.Services, neededReaders);
this.Components.Add(this.rawContent);
}
```

View file

@ -44,7 +44,7 @@ To draw your tokenized text, all you have to do is call its `Draw` method like s
```cs
tokenizedString.Draw(gameTime, spriteBatch, position, font, color, scale, depth);
```
Note that, if your tokenized text contains any animations, you have to updated the tokenized string every `Update` call like so:
Note that, if your tokenized text contains any animations, you have to update the tokenized string every `Update` call like so:
```cs
tokenizedString.Update(gameTime);
```

View file

@ -32,7 +32,7 @@ This means that, to check if the tile at tile coordinate `6, 10` contains any co
```cs
var tiles = collisions.GetCollidingTiles(new RectangleF(6, 10, 1, 1));
```
If the tile at that location is `16x16` pixels big and it has a single collision box at pixels `4, 4` that is `8x8` pixels big, then the following code prints out its percentaged coordinates: `X: 0.25, Y: 0.25, Width: 0.5, Height: 0.5`.
If the tile at that location is `16x16` pixels big, and it has a single collision box at pixels `4, 4` that is `8x8` pixels big, then the following code prints out its percentaged coordinates: `X: 0.25, Y: 0.25, Width: 0.5, Height: 0.5`.
```cs
foreach (var tile in tiles)
Console.WriteLine(tile.Collisions[0]);

View file

@ -92,7 +92,7 @@ this.UiSystem.Add("InfoBox", box);
### About sizing
Note that, when setting the width and height of any element, there are some things to note:
- Each element has a `SetWidthBasedOnChildren` and a `SetHeightBasedOnChildren` property, which allow them to change their size automatically based on their content
- When specifying a width or height *lower than or equal to 1*, it is seen as a percentage based on the parent's size instead. For example, a paragraph with a width of `0.5F` inside of a panel width a width of `200` will be `100` units wide.
- When specifying a width or height *lower than or equal to 1*, it is seen as a percentage based on the parent's size instead. For example, a paragraph with a width of `0.5F` inside a panel width a width of `200` will be `100` units wide.
- When specifying a width *lower than 0*, it is seen as a percentage based on the element's height, and vice versa. For example, a panel with a width of `200` and a height of `-2` will be `400` units tall.
A lot of other ways to modify the size of an object are available as well, including `TreatSizeAsMaximum`, `TreatSizeAsMinimum`, `PreventParentSpill` and more. For more information, the `Element` [documentation](xref:MLEM.Ui.Elements.Element) contains descriptions of all fields, properties and methods.
A lot of other ways to modify the size of an object are available as well, including `TreatSizeAsMaximum`, `TreatSizeAsMinimum`, `PreventParentSpill` and more. For more information, the `Element` [documentation](xref:MLEM.Ui.Elements.Element) contains descriptions of all fields, properties, and methods.