mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 01:39:23 +01:00
allow a lot of mem classes to have custom data added to them
This commit is contained in:
parent
9f43924e47
commit
26264bf576
13 changed files with 56 additions and 16 deletions
|
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Extensions;
|
||||
using MonoGame.Extended;
|
||||
using MLEM.Misc;
|
||||
using MonoGame.Extended.Tiled;
|
||||
using RectangleF = MonoGame.Extended.RectangleF;
|
||||
|
||||
namespace MLEM.Extended.Tiled {
|
||||
public class IndividualTiledMapRenderer {
|
||||
|
@ -84,7 +85,7 @@ namespace MLEM.Extended.Tiled {
|
|||
|
||||
public delegate float GetDepth(TiledMapTile tile, TiledMapTileLayer layer, int layerIndex, Point position);
|
||||
|
||||
private class TileDrawInfo {
|
||||
private class TileDrawInfo : GenericDataHolder {
|
||||
|
||||
private readonly IndividualTiledMapRenderer renderer;
|
||||
private readonly TiledMapTileset tileset;
|
||||
|
|
|
@ -4,8 +4,9 @@ using System.Collections.ObjectModel;
|
|||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Extensions;
|
||||
using MonoGame.Extended;
|
||||
using MLEM.Misc;
|
||||
using MonoGame.Extended.Tiled;
|
||||
using RectangleF = MonoGame.Extended.RectangleF;
|
||||
|
||||
namespace MLEM.Extended.Tiled {
|
||||
public class TiledMapCollisions {
|
||||
|
@ -79,7 +80,7 @@ namespace MLEM.Extended.Tiled {
|
|||
|
||||
public delegate void CollectCollisions(List<RectangleF> collisions, TileCollisionInfo tile);
|
||||
|
||||
public class TileCollisionInfo {
|
||||
public class TileCollisionInfo : GenericDataHolder {
|
||||
|
||||
public readonly TiledMap Map;
|
||||
public readonly Vector2 Position;
|
||||
|
|
|
@ -13,7 +13,7 @@ using MLEM.Textures;
|
|||
using MLEM.Ui.Style;
|
||||
|
||||
namespace MLEM.Ui.Elements {
|
||||
public abstract class Element {
|
||||
public abstract class Element : GenericDataHolder {
|
||||
|
||||
protected readonly List<Element> Children = new List<Element>();
|
||||
private readonly List<Element> sortedChildren = new List<Element>();
|
||||
|
|
|
@ -2,10 +2,11 @@ using Microsoft.Xna.Framework;
|
|||
using Microsoft.Xna.Framework.Audio;
|
||||
using MLEM.Font;
|
||||
using MLEM.Formatting;
|
||||
using MLEM.Misc;
|
||||
using MLEM.Textures;
|
||||
|
||||
namespace MLEM.Ui.Style {
|
||||
public class UiStyle {
|
||||
public class UiStyle : GenericDataHolder {
|
||||
|
||||
public NinePatch SelectionIndicator;
|
||||
public NinePatch ButtonTexture;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Misc;
|
||||
using MLEM.Textures;
|
||||
|
||||
namespace MLEM.Animations {
|
||||
public class SpriteAnimation {
|
||||
public class SpriteAnimation : GenericDataHolder {
|
||||
|
||||
private AnimationFrame[] frames;
|
||||
public AnimationFrame this[int index] => this.frames[index];
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Misc;
|
||||
using MLEM.Textures;
|
||||
|
||||
namespace MLEM.Animations {
|
||||
public class SpriteAnimationGroup {
|
||||
public class SpriteAnimationGroup : GenericDataHolder{
|
||||
|
||||
private readonly List<ConditionedAnimation> animations = new List<ConditionedAnimation>();
|
||||
private ConditionedAnimation currAnimation;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Formatting {
|
||||
public class FormatSettings {
|
||||
public class FormatSettings : GenericDataHolder {
|
||||
|
||||
public static readonly FormatSettings Default = new FormatSettings();
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Formatting {
|
||||
public class FormattingCodeCollection : Dictionary<int, List<FormattingCodeData>> {
|
||||
|
||||
}
|
||||
|
||||
public class FormattingCodeData {
|
||||
public class FormattingCodeData : GenericDataHolder {
|
||||
|
||||
public readonly FormattingCode Code;
|
||||
public readonly Match Match;
|
||||
|
|
29
MLEM/Misc/GenericDataHolder.cs
Normal file
29
MLEM/Misc/GenericDataHolder.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace MLEM.Misc {
|
||||
public class GenericDataHolder {
|
||||
|
||||
private Dictionary<string, object> data;
|
||||
|
||||
public void SetData(string key, object data) {
|
||||
if (this.data == null)
|
||||
this.data = new Dictionary<string, object>();
|
||||
if (data == default) {
|
||||
this.data.Remove(key);
|
||||
} else {
|
||||
this.data[key] = data;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetData<T>(string key) {
|
||||
if (this.data != null && this.data.TryGetValue(key, out var val) && val is T t)
|
||||
return t;
|
||||
return default;
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<string> GetDataKeys() {
|
||||
return this.data.Keys;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ using MLEM.Extensions;
|
|||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Textures {
|
||||
public class NinePatch {
|
||||
public class NinePatch : GenericDataHolder {
|
||||
|
||||
public readonly TextureRegion Region;
|
||||
public readonly Padding Padding;
|
||||
|
|
|
@ -4,7 +4,7 @@ using MLEM.Extensions;
|
|||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Textures {
|
||||
public class TextureRegion {
|
||||
public class TextureRegion : GenericDataHolder {
|
||||
|
||||
public readonly Texture2D Texture;
|
||||
public readonly Rectangle Area;
|
||||
|
|
|
@ -2,9 +2,10 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Textures {
|
||||
public class UniformTextureAtlas {
|
||||
public class UniformTextureAtlas : GenericDataHolder {
|
||||
|
||||
public readonly Texture2D Texture;
|
||||
public readonly int RegionAmountX;
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace Sandbox {
|
|||
MaxScale = 4
|
||||
};
|
||||
|
||||
/*var tex = LoadContent<Texture2D>("Textures/Test");
|
||||
var tex = LoadContent<Texture2D>("Textures/Test");
|
||||
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
|
||||
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
|
||||
TextScale = 0.1F,
|
||||
|
@ -64,9 +64,12 @@ namespace Sandbox {
|
|||
var panel = new Panel(Anchor.Center, new Vector2(0, 100), Vector2.Zero) {SetWidthBasedOnChildren = true};
|
||||
panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(100, 10)));
|
||||
panel.AddChild(new Button(Anchor.AutoCenter, new Vector2(80, 10)));
|
||||
this.UiSystem.Add("Panel", panel);*/
|
||||
this.UiSystem.Add("Panel", panel);
|
||||
|
||||
var obj = new Test{
|
||||
panel.SetData("TestKey", new Vector2(10, 2));
|
||||
Console.WriteLine(panel.GetData<Vector2>("TestKey"));
|
||||
|
||||
var obj = new Test {
|
||||
Vec = new Vector2(10, 20),
|
||||
Point = new Point(20, 30),
|
||||
Rectangle = new Rectangle(1, 2, 3, 4),
|
||||
|
|
Loading…
Reference in a new issue