mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
allow storing additional coordinates in a DataTextureAtlas
This commit is contained in:
parent
8e06e54325
commit
c8fd2a4c17
3 changed files with 22 additions and 7 deletions
|
@ -56,23 +56,33 @@ namespace MLEM.Data {
|
||||||
text = reader.ReadToEnd();
|
text = reader.ReadToEnd();
|
||||||
var atlas = new DataTextureAtlas(texture);
|
var atlas = new DataTextureAtlas(texture);
|
||||||
|
|
||||||
// parse each texture region: "<name> loc <u> <v> <w> <h> piv <px> <py>"
|
// parse each texture region: "<name> loc <u> <v> <w> <h> piv <px> <py>" followed by extra data in the form "key <x> <y>"
|
||||||
const string regex = @"(.+)\W+loc\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+(?:piv\W+([0-9.]+)\W+([0-9.]+))?";
|
foreach (Match match in Regex.Matches(text, @"(.+)\W+loc\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)(?:\W+piv\W+([0-9.]+)\W+([0-9.]+))?(?:\W+(\w+)\W+([0-9.]+)\W+([0-9.]+))*")) {
|
||||||
foreach (Match match in Regex.Matches(text, regex)) {
|
|
||||||
var name = match.Groups[1].Value.Trim();
|
var name = match.Groups[1].Value.Trim();
|
||||||
|
// location
|
||||||
var loc = new Rectangle(
|
var loc = new Rectangle(
|
||||||
int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value),
|
int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value),
|
||||||
int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value));
|
int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value));
|
||||||
|
// pivot
|
||||||
var piv = Vector2.Zero;
|
var piv = Vector2.Zero;
|
||||||
if (match.Groups[6].Success) {
|
if (match.Groups[6].Success) {
|
||||||
piv = new Vector2(
|
piv = new Vector2(
|
||||||
float.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X),
|
float.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X),
|
||||||
float.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y));
|
float.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y));
|
||||||
}
|
}
|
||||||
atlas.regions.Add(name, new TextureRegion(texture, loc) {
|
var region = new TextureRegion(texture, loc) {
|
||||||
PivotPixels = piv,
|
PivotPixels = piv,
|
||||||
Name = name
|
Name = name
|
||||||
});
|
};
|
||||||
|
// additional data
|
||||||
|
if (match.Groups[8].Success) {
|
||||||
|
for (var i = 0; i < match.Groups[8].Captures.Count; i++) {
|
||||||
|
region.SetData(match.Groups[8].Captures[i].Value, new Vector2(
|
||||||
|
float.Parse(match.Groups[9].Captures[i].Value),
|
||||||
|
float.Parse(match.Groups[10].Captures[i].Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
atlas.regions.Add(name, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
return atlas;
|
return atlas;
|
||||||
|
|
|
@ -11,6 +11,9 @@ loc 96 0 16 32
|
||||||
LongTableUp
|
LongTableUp
|
||||||
loc 0 32 64 48
|
loc 0 32 64 48
|
||||||
piv 16 48
|
piv 16 48
|
||||||
|
extraData1 12 14
|
||||||
|
extraData2 129 4
|
||||||
|
|
||||||
LongTableRight
|
LongTableRight
|
||||||
loc 64 32 64 48
|
loc 64 32 64 48
|
||||||
piv 112 48
|
piv 112 48
|
|
@ -157,6 +157,8 @@ namespace Sandbox {
|
||||||
var atlas = this.Content.LoadTextureAtlas("Textures/Furniture");
|
var atlas = this.Content.LoadTextureAtlas("Textures/Furniture");
|
||||||
foreach (var r in atlas.Regions) {
|
foreach (var r in atlas.Regions) {
|
||||||
Console.WriteLine(r.Name + ": " + r.U + " " + r.V + " " + r.Width + " " + r.Height + " " + r.PivotPixels);
|
Console.WriteLine(r.Name + ": " + r.U + " " + r.V + " " + r.Width + " " + r.Height + " " + r.PivotPixels);
|
||||||
|
foreach (var key in r.GetDataKeys())
|
||||||
|
Console.WriteLine(key + " " + r.GetData<Vector2>(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.OnDraw += (g, time) => {
|
this.OnDraw += (g, time) => {
|
||||||
|
@ -181,7 +183,7 @@ namespace Sandbox {
|
||||||
this.tokenized.Update(time);
|
this.tokenized.Update(time);
|
||||||
};
|
};
|
||||||
|
|
||||||
var testPanel = new Panel(Anchor.Center, new Vector2(0.5F, 100), Vector2.Zero);
|
/*var testPanel = new Panel(Anchor.Center, new Vector2(0.5F, 100), Vector2.Zero);
|
||||||
testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(0.25F, -1)));
|
testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(0.25F, -1)));
|
||||||
testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(2500, 1)) {PreventParentSpill = true});
|
testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(2500, 1)) {PreventParentSpill = true});
|
||||||
this.UiSystem.Add("Test", testPanel);
|
this.UiSystem.Add("Test", testPanel);
|
||||||
|
@ -192,7 +194,7 @@ namespace Sandbox {
|
||||||
};
|
};
|
||||||
invalidPanel.AddChild(new Paragraph(Anchor.AutoRight, 1, "This is some test text!", true));
|
invalidPanel.AddChild(new Paragraph(Anchor.AutoRight, 1, "This is some test text!", true));
|
||||||
invalidPanel.AddChild(new VerticalSpace(1));
|
invalidPanel.AddChild(new VerticalSpace(1));
|
||||||
this.UiSystem.Add("Invalid", invalidPanel);
|
this.UiSystem.Add("Invalid", invalidPanel);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DoUpdate(GameTime gameTime) {
|
protected override void DoUpdate(GameTime gameTime) {
|
||||||
|
|
Loading…
Reference in a new issue