Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Basic editing of vanilla textures in the editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
hankmorgan committed Sep 23, 2018
1 parent f9cb7e0 commit c89f4b7
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 209 deletions.
29 changes: 21 additions & 8 deletions Editor/UnderworldEditor/UnderworldEditor/ArtLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace UnderworldEditor
{
public class ArtLoader
{
public Bitmap[] ImageCache;
public const byte BitMapHeaderSize = 28;

/// <summary>
Expand Down Expand Up @@ -73,12 +74,12 @@ public static Bitmap Image(char[] databuffer, long dataOffSet, int width, int he
/// <param name="Alpha">If set to <c>true</c> alpha.</param>
public static Bitmap Image(char[] databuffer, long dataOffSet, int width, int height, string imageName, Palette pal, bool Alpha, bool useXFER)
{
Bitmap image = new Bitmap(width, height,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Byte[] imageColors = new Byte[width * height*4];
Bitmap image = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Byte[] imageColors = new Byte[width * height * 4];

long counter = 0;
for (int iRow = 0; iRow < height; iRow++)
{
for (int iRow = 0; iRow < height; iRow++)
{
for (int j = (iRow * width); j < (iRow * width) + width; j++)
{
byte pixel = (byte)Util.getValAtAddress(databuffer, dataOffSet + (long)j, 8);
Expand All @@ -95,19 +96,19 @@ public static Bitmap Image(char[] databuffer, long dataOffSet, int width, int he
// image.SetPixels32(imageColors);
//image.Apply();
//return image;
return CopyDataToBitmap(imageColors,height,width);
return CopyDataToBitmap(imageColors, height, width);
}

/// <summary>
/// function CopyDataToBitmap
/// Purpose: Given the pixel data return a bitmap of size [352,288],PixelFormat=24RGB
/// </summary>
/// <param name="data">Byte array with pixel data</param>
public static Bitmap CopyDataToBitmap(byte[] data,int height, int width)
public static Bitmap CopyDataToBitmap(byte[] data, int height, int width)
{
//Here create the Bitmap to the know height, width and format
Bitmap bmp = new Bitmap(height, width, PixelFormat.Format32bppRgb);

//Create a BitmapData and Lock all pixels to be written
BitmapData bmpData = bmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
Expand Down Expand Up @@ -341,6 +342,18 @@ static char getActualAuxPalVal(char[] auxpal, int nibble)
}


public static Bitmap Palette(Palette pal)
{
char[] paldata = new char[256*64];
for (int j=0; j<64;j++)
{
for (int i = 0; i < 256; i++)
{
paldata[j*256 + i] = (char)i;
}
}

return Image(paldata, 0,64, 256, "name", pal, true); }

}//end class
}
39 changes: 39 additions & 0 deletions Editor/UnderworldEditor/UnderworldEditor/ArtUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace UnderworldEditor
{
class ArtUI
{

public static void setPixelAtLocation(TextureLoader artfile, int imageNo, PictureBox img, int x, int y, int newpixel)
{
if (artfile == null) { return; }
if (img.Image == null) { return; }
//(Bitmap)(img.Image).SetPixel(x, y, PaletteLoader.Palettes[0].ColorAtPixel(50, false));
artfile.ImageCache[imageNo].SetPixel(x, y, PaletteLoader.Palettes[0].ColorAtPixel((byte)newpixel, false));
switch (main.curgame)
{
case main.GAME_UW1:
if (imageNo<210)
{
artfile.texturebufferW[artfile.OffsetT[imageNo] + y * 64 + x] = (char)newpixel;
}
break;
}
img.Image = artfile.ImageCache[imageNo];
}

public static void SaveData(char[] artfile)
{
Util.WriteStreamFile("c:\\games\\uw1\\data\\W64_test.TR", artfile);
}

}//endclass
}
45 changes: 45 additions & 0 deletions Editor/UnderworldEditor/UnderworldEditor/Palette.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace UnderworldEditor
{
public class Palette
{
public byte[] red = new byte[256];
public byte[] blue = new byte[256];
public byte[] green = new byte[256];

/// <summary>
/// Returns the color for the specified palette index.
/// </summary>
/// <returns>The at pixel.</returns>
/// <param name="pixel">Pixel.</param>
/// <param name="Alpha">If set to <c>true</c> alpha.</param>
public Color ColorAtPixel(byte pixel, bool Alpha)
{
byte alpha;
if (Alpha == true)
{
if (pixel != 0) //Alpha
{
alpha = 255;
}
else
{
alpha = 0;
}
}
else
{
alpha = 0;
}
return Color.FromArgb((int)alpha, (int)red[pixel], (int)green[pixel], (int)blue[pixel]);
}


}//end class
}
45 changes: 33 additions & 12 deletions Editor/UnderworldEditor/UnderworldEditor/TextureLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class TextureLoader: ArtLoader
private string pathTex_UW2 = "DATA\\T64.TR";
private string pathTex_SS1 = "RES\\DATA\\Texture.res";

char[] texturebufferW;
char[] texturebufferF;
char[] texturebufferT;
public char[] texturebufferW;//uw1 wall file data
public char[] texturebufferF;//uw1 floor file data
public char[] texturebufferT;//uw2 file data

public long[] OffsetT = new long[261]; //file address offsets for texutres

public bool texturesWLoaded;
public bool texturesFLoaded;
Expand All @@ -28,18 +30,24 @@ public class TextureLoader: ArtLoader

public const float BumpMapStrength = 1f;


public TextureLoader()
{
ImageCache = new Bitmap[261];
}

public override Bitmap LoadImageAt(int index)
{
return LoadImageAt(index, PaletteLoader.Palettes[0]);
}

/// <summary>
/// Loads the image at index.
/// </summary>
/// <returns>The <see cref="UnityEngine.Texture2D"/>.</returns>
/// <param name="index">Index.</param>
/// <param name="palToUse">Pal to use.</param>
/// If the index is greater than 209 I return a floor texture.
/// <summary>
/// Loads the image at index.
/// </summary>
/// <returns>The <see cref="UnityEngine.Texture2D"/>.</returns>
/// <param name="index">Index.</param>
/// <param name="palToUse">Pal to use.</param>
/// If the index is greater than 209 I return a floor texture.
public Bitmap LoadImageAt(int index, Palette palToUse)
{
if (main.curgame == main.GAME_UW2)
Expand All @@ -51,6 +59,10 @@ public Bitmap LoadImageAt(int index, Palette palToUse)
{
case main.GAME_UW2:
{
if (ImageCache[index] != null)
{
return ImageCache[index];
}
if (texturesFLoaded == false)
{
if (!Util.ReadStreamFile("c:\\games\\uw2\\" + pathTex_UW2, out texturebufferT))
Expand All @@ -63,12 +75,18 @@ public Bitmap LoadImageAt(int index, Palette palToUse)
}
}
long textureOffset = Util.getValAtAddress(texturebufferT, ((index) * 4) + 4, 32);
return Image(texturebufferT, textureOffset, FloorDim, FloorDim, "name_goes_here", palToUse, false);
OffsetT[index] = textureOffset;
ImageCache[index] = Image(texturebufferT, textureOffset, FloorDim, FloorDim, "name_goes_here", palToUse, false);
return ImageCache[index];
}

case main.GAME_UW1:
default:
{
//if (ImageCache[index]!=null)
//{
// return ImageCache[index];
//}
if (index < TextureSplit)
{//Wall textures
if (texturesWLoaded == false)
Expand All @@ -83,7 +101,9 @@ public Bitmap LoadImageAt(int index, Palette palToUse)
}
}
long textureOffset = Util.getValAtAddress(texturebufferW, (index * 4) + 4, 32);
return Image(texturebufferW, textureOffset, 64, 64, "name_goes_here", palToUse, false);
OffsetT[index] = textureOffset;
ImageCache[index] = Image(texturebufferW, textureOffset, 64, 64, "name_goes_here", palToUse, false);
return ImageCache[index];
}
else
{//Floor textures (to match my list of textures)
Expand All @@ -99,6 +119,7 @@ public Bitmap LoadImageAt(int index, Palette palToUse)
}
}
long textureOffset = Util.getValAtAddress(texturebufferF, ((index - TextureSplit) * 4) + 4, 32);
OffsetT[index] = textureOffset;
return Image(texturebufferF, textureOffset, FloorDim, FloorDim, "name_goes_here", palToUse, false);
}
}//end switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ArtLoader.cs" />
<Compile Include="ArtUI.cs" />
<Compile Include="Palette.cs" />
<Compile Include="PaletteLoader.cs" />
<Compile Include="PlayerDatUI.cs" />
Expand Down
Loading

0 comments on commit c89f4b7

Please sign in to comment.