2016-03-04 08:10:56 +00:00
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Drawing ;
using System.IO ;
using CodeImp.DoomBuilder.Geometry ;
using CodeImp.DoomBuilder.IO ;
#endregion
namespace CodeImp.DoomBuilder.Data
{
2016-03-23 21:26:26 +00:00
public sealed class HiResImage : ImageData
2016-03-04 08:10:56 +00:00
{
#region = = = = = = = = = = = = = = = = = = Variables
private Vector2D sourcescale ;
private Size sourcesize ;
private bool overridesettingsapplied ;
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
public override int Width { get { return sourcesize . Width ; } }
public override int Height { get { return sourcesize . Height ; } }
public override float ScaledWidth { get { return ( float ) Math . Round ( sourcesize . Width * sourcescale . x ) ; } }
public override float ScaledHeight { get { return ( float ) Math . Round ( sourcesize . Height * sourcescale . y ) ; } }
public override Vector2D Scale { get { return sourcescale ; } }
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
public HiResImage ( string name )
{
// Initialize
this . scale . x = General . Map . Config . DefaultTextureScale ;
this . scale . y = General . Map . Config . DefaultTextureScale ;
this . sourcescale = scale ;
this . sourcesize = Size . Empty ;
Changed, Select Similar Sectors action: when "Effect" option is enabled, all sectors with at least one matching generalized/predefined effect will be selected.
Added, Tag Explorer plugin: a separate category for each generalized/predefined effect is now created when "Sort by action special" sort mode is used.
Added, Edit Effect window: normal and generalized effects can now be set at the same time.
Fixed, Edit Action window: in some cases Generalized actions were incorrectly processed.
Fixed, Edit Effect window: in some cases Generalized effects were incorrectly processed.
Fixed, Select Similar window: Tab control was incorrectly anchored.
Fixed, Nodes Viewer mode, cosmetic: segs angles were calculated incorrectly when showing nodes in classic format.
Fixed: HiRes textures, which didn't override any texture or flat were not loaded.
Fixed, Tag Explorer plugin: linedef action categories were missing title when "Sort by action special" sort mode was used.
Cosmetic: renamed "Grid Setup" action to "Grid and Backdrop Setup".
2016-03-21 15:19:14 +00:00
SetName ( name ) ;
2020-07-05 07:20:08 +00:00
// biwa. HiRes replacements always seem to use worldpanning. There is no documentation about it, but not
// setting it can cause issues (see https://github.com/jewalky/UltimateDoomBuilder/issues/432)
worldpanning = true ;
2016-03-04 08:10:56 +00:00
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
// Copy constructor
public HiResImage ( HiResImage other )
{
// Initialize
this . scale = other . scale ;
this . sourcescale = other . sourcescale ;
this . sourcesize = other . sourcesize ;
2020-07-05 07:20:08 +00:00
// biwa. HiRes replacements always seem to use worldpanning. There is no documentation about it, but not
// setting it can cause issues (see https://github.com/jewalky/UltimateDoomBuilder/issues/432)
worldpanning = true ;
Changed, Select Similar Sectors action: when "Effect" option is enabled, all sectors with at least one matching generalized/predefined effect will be selected.
Added, Tag Explorer plugin: a separate category for each generalized/predefined effect is now created when "Sort by action special" sort mode is used.
Added, Edit Effect window: normal and generalized effects can now be set at the same time.
Fixed, Edit Action window: in some cases Generalized actions were incorrectly processed.
Fixed, Edit Effect window: in some cases Generalized effects were incorrectly processed.
Fixed, Select Similar window: Tab control was incorrectly anchored.
Fixed, Nodes Viewer mode, cosmetic: segs angles were calculated incorrectly when showing nodes in classic format.
Fixed: HiRes textures, which didn't override any texture or flat were not loaded.
Fixed, Tag Explorer plugin: linedef action categories were missing title when "Sort by action special" sort mode was used.
Cosmetic: renamed "Grid Setup" action to "Grid and Backdrop Setup".
2016-03-21 15:19:14 +00:00
// Copy names
this . name = other . name ;
this . filepathname = other . filepathname ;
this . virtualname = other . virtualname ;
this . displayname = other . displayname ;
this . shortname = other . shortname ;
this . longname = other . longname ;
2016-03-04 08:10:56 +00:00
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
Changed, Select Similar Sectors action: when "Effect" option is enabled, all sectors with at least one matching generalized/predefined effect will be selected.
Added, Tag Explorer plugin: a separate category for each generalized/predefined effect is now created when "Sort by action special" sort mode is used.
Added, Edit Effect window: normal and generalized effects can now be set at the same time.
Fixed, Edit Action window: in some cases Generalized actions were incorrectly processed.
Fixed, Edit Effect window: in some cases Generalized effects were incorrectly processed.
Fixed, Select Similar window: Tab control was incorrectly anchored.
Fixed, Nodes Viewer mode, cosmetic: segs angles were calculated incorrectly when showing nodes in classic format.
Fixed: HiRes textures, which didn't override any texture or flat were not loaded.
Fixed, Tag Explorer plugin: linedef action categories were missing title when "Sort by action special" sort mode was used.
Cosmetic: renamed "Grid Setup" action to "Grid and Backdrop Setup".
2016-03-21 15:19:14 +00:00
protected override void SetName ( string name )
{
name = name . Replace ( Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar ) ;
this . filepathname = name ;
this . name = Path . GetFileNameWithoutExtension ( name . ToUpperInvariant ( ) ) ;
if ( this . name . Length > DataManager . CLASIC_IMAGE_NAME_LENGTH )
{
this . name = this . name . Substring ( 0 , DataManager . CLASIC_IMAGE_NAME_LENGTH ) ;
}
this . virtualname = this . name ;
this . displayname = this . name ;
this . shortname = this . name ;
this . longname = Lump . MakeLongName ( this . name ) ;
2019-05-30 22:20:12 +00:00
ComputeNamesWidth ( ) ; // biwa
Changed, Select Similar Sectors action: when "Effect" option is enabled, all sectors with at least one matching generalized/predefined effect will be selected.
Added, Tag Explorer plugin: a separate category for each generalized/predefined effect is now created when "Sort by action special" sort mode is used.
Added, Edit Effect window: normal and generalized effects can now be set at the same time.
Fixed, Edit Action window: in some cases Generalized actions were incorrectly processed.
Fixed, Edit Effect window: in some cases Generalized effects were incorrectly processed.
Fixed, Select Similar window: Tab control was incorrectly anchored.
Fixed, Nodes Viewer mode, cosmetic: segs angles were calculated incorrectly when showing nodes in classic format.
Fixed: HiRes textures, which didn't override any texture or flat were not loaded.
Fixed, Tag Explorer plugin: linedef action categories were missing title when "Sort by action special" sort mode was used.
Cosmetic: renamed "Grid Setup" action to "Grid and Backdrop Setup".
2016-03-21 15:19:14 +00:00
}
2016-03-04 08:10:56 +00:00
internal void ApplySettings ( ImageData overridden )
{
2016-03-23 14:52:33 +00:00
// Copy relevant names...
2016-03-22 22:24:33 +00:00
name = overridden . Name ;
2016-03-04 08:10:56 +00:00
virtualname = overridden . VirtualName ;
2016-03-22 22:24:33 +00:00
displayname = overridden . DisplayName ;
2022-03-05 15:57:23 +00:00
texturenamespace = overridden . TextureNamespace ;
2016-03-23 14:52:33 +00:00
hasLongName = overridden . HasLongName ;
2016-03-04 08:10:56 +00:00
overridesettingsapplied = true ;
2020-01-12 22:10:57 +00:00
overridden . LoadImageNow ( ) ;
2016-03-04 08:10:56 +00:00
if ( overridden . ImageState = = ImageLoadState . Ready )
{
// Store source properteis
sourcesize = new Size ( overridden . Width , overridden . Height ) ;
sourcescale = overridden . Scale ;
}
}
// This loads the image
2019-12-29 02:54:12 +00:00
protected override LocalLoadResult LocalLoadImage ( )
2016-03-04 08:10:56 +00:00
{
2019-12-29 02:54:12 +00:00
// Get the patch data stream
Bitmap bitmap = null ;
string error = null ;
string sourcelocation = string . Empty ;
Stream data = General . Map . Data . GetHiResTextureData ( shortname , ref sourcelocation ) ;
if ( data ! = null )
{
// Copy patch data to memory
byte [ ] membytes = new byte [ ( int ) data . Length ] ;
2016-08-29 10:06:16 +00:00
2019-12-29 02:54:12 +00:00
lock ( data ) //mxd
{
data . Seek ( 0 , SeekOrigin . Begin ) ;
data . Read ( membytes , 0 , ( int ) data . Length ) ;
}
2016-08-29 10:06:16 +00:00
2019-12-29 02:54:12 +00:00
MemoryStream mem = new MemoryStream ( membytes ) ;
mem . Seek ( 0 , SeekOrigin . Begin ) ;
2016-03-04 08:10:56 +00:00
2022-03-05 15:57:23 +00:00
bitmap = ImageDataFormat . TryLoadImage ( mem , ( texturenamespace = = TextureNamespace . FLAT ) ? ImageDataFormat . DOOMFLAT : ImageDataFormat . DOOMPICTURE , General . Map . Data . Palette ) ;
2019-12-29 02:54:12 +00:00
// Not loaded?
if ( bitmap = = null )
2016-03-04 08:10:56 +00:00
{
2019-12-29 02:54:12 +00:00
error = "Image lump \"" + Path . Combine ( sourcelocation , filepathname . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ) + "\" data format could not be read, while loading HiRes texture \"" + this . Name + "\". Does this lump contain valid picture data at all?" ;
2016-03-04 08:10:56 +00:00
}
2019-12-29 02:54:12 +00:00
// Done
mem . Dispose ( ) ;
2016-03-04 08:10:56 +00:00
}
2019-12-29 02:54:12 +00:00
else
{
error = "Image lump \"" + shortname + "\" could not be found, while loading HiRes texture \"" + this . Name + "\". Did you forget to include required resources?" ;
}
return new LocalLoadResult ( bitmap , error , ( ) = >
{
// Apply source overrides?
if ( ! sourcesize . IsEmpty )
{
scale = new Vector2D ( ScaledWidth / width , ScaledHeight / height ) ;
}
else
{
if ( overridesettingsapplied )
General . ErrorLogger . Add ( ErrorType . Warning , "Unable to get source texture dimensions while loading HiRes texture \"" + this . Name + "\"." ) ;
// Use our own size...
sourcesize = new Size ( width , height ) ;
}
} ) ;
}
#endregion
}
2016-03-04 08:10:56 +00:00
}