2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
2019-12-29 02:54:12 +00:00
|
|
|
using System.Drawing;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.IO;
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2016-07-11 22:13:43 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Data
|
|
|
|
{
|
2016-07-11 22:13:43 +00:00
|
|
|
public interface ISpriteImage //mxd
|
|
|
|
{
|
|
|
|
int OffsetX { get; }
|
|
|
|
int OffsetY { get; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public sealed class SpriteImage : ImageData, ISpriteImage
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
2016-01-11 13:00:52 +00:00
|
|
|
private int offsetx;
|
|
|
|
private int offsety;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public int OffsetX { get { return offsetx; } }
|
|
|
|
public int OffsetY { get { return offsety; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
internal SpriteImage(string name)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
SetName(name);
|
|
|
|
|
2019-12-29 17:59:52 +00:00
|
|
|
AllowUnload = false;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This loads the image
|
2019-12-29 02:54:12 +00:00
|
|
|
protected override LocalLoadResult LocalLoadImage()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
// Get the lump data stream
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
string error = null;
|
|
|
|
string spritelocation = string.Empty; //mxd
|
|
|
|
Stream lumpdata = General.Map.Data.GetSpriteData(Name, ref spritelocation);
|
|
|
|
if(lumpdata != null)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
// Get a reader for the data
|
2020-01-14 16:25:35 +00:00
|
|
|
bitmap = ImageDataFormat.TryLoadImage(lumpdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette, out offsetx, out offsety);
|
|
|
|
if(bitmap == null)
|
2019-12-29 02:54:12 +00:00
|
|
|
{
|
|
|
|
// Data is in an unknown format!
|
|
|
|
error = "Sprite lump \"" + Path.Combine(spritelocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?";
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2019-12-29 02:54:12 +00:00
|
|
|
|
|
|
|
// Done
|
2019-12-29 14:38:53 +00:00
|
|
|
lumpdata.Close();
|
2019-12-29 02:54:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Missing a patch lump!
|
|
|
|
error = "Missing sprite lump \"" + Name + "\". Forgot to include required resources?";
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
return new LocalLoadResult(bitmap, error, () =>
|
|
|
|
{
|
|
|
|
scale.x = 1.0f;
|
|
|
|
scale.y = 1.0f;
|
|
|
|
|
2020-10-11 11:18:08 +00:00
|
|
|
// Set the offset if the offset was not given
|
2019-12-29 02:54:12 +00:00
|
|
|
if ((offsetx == int.MinValue) || (offsety == int.MinValue))
|
|
|
|
{
|
2020-10-11 11:18:08 +00:00
|
|
|
offsetx = offsety = 0;
|
2019-12-29 02:54:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|