hack hack hack mostly works
This commit is contained in:
@@ -21,5 +21,6 @@ namespace OpenRA.Editor
|
|||||||
{
|
{
|
||||||
public Bitmap Bitmap;
|
public Bitmap Bitmap;
|
||||||
public ResourceTypeInfo Info;
|
public ResourceTypeInfo Info;
|
||||||
|
public int Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ namespace OpenRA.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitmap.UnlockBits(data);
|
bitmap.UnlockBits(data);
|
||||||
return new ResourceTemplate { Bitmap = bitmap, Info = info };
|
return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.ImageCount - 1 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing.Imaging;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Thirdparty;
|
||||||
|
|
||||||
namespace OpenRA.Editor
|
namespace OpenRA.Editor
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,7 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
public BrushTemplate Brush;
|
public BrushTemplate Brush;
|
||||||
public ActorTemplate Actor;
|
public ActorTemplate Actor;
|
||||||
|
public ResourceTemplate Resource;
|
||||||
|
|
||||||
Dictionary<string, ActorTemplate> ActorTemplates = new Dictionary<string, ActorTemplate>();
|
Dictionary<string, ActorTemplate> ActorTemplates = new Dictionary<string, ActorTemplate>();
|
||||||
Dictionary<int, ResourceTemplate> ResourceTemplates = new Dictionary<int, ResourceTemplate>();
|
Dictionary<int, ResourceTemplate> ResourceTemplates = new Dictionary<int, ResourceTemplate>();
|
||||||
@@ -29,9 +31,9 @@ namespace OpenRA.Editor
|
|||||||
Chunks.Clear();
|
Chunks.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBrush(BrushTemplate brush) { Actor = null; Brush = brush; }
|
public void SetBrush(BrushTemplate brush) { Actor = null; Brush = brush; Resource = null; }
|
||||||
public void SetActor(ActorTemplate actor) { Brush = null; Actor = actor; }
|
public void SetActor(ActorTemplate actor) { Brush = null; Actor = actor; Resource = null; }
|
||||||
public void SetResource(ResourceTemplate resource) { Brush = null; Actor = null; /* todo */ }
|
public void SetResource(ResourceTemplate resource) { Brush = null; Actor = null; Resource = resource; }
|
||||||
|
|
||||||
public void BindActorTemplates(IEnumerable<ActorTemplate> templates)
|
public void BindActorTemplates(IEnumerable<ActorTemplate> templates)
|
||||||
{
|
{
|
||||||
@@ -40,7 +42,7 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
public void BindResourceTemplates(IEnumerable<ResourceTemplate> templates)
|
public void BindResourceTemplates(IEnumerable<ResourceTemplate> templates)
|
||||||
{
|
{
|
||||||
/* todo */
|
ResourceTemplates = templates.ToDictionary(a => a.Info.ResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<int2, Bitmap> Chunks = new Dictionary<int2, Bitmap>();
|
Dictionary<int2, Bitmap> Chunks = new Dictionary<int2, Bitmap>();
|
||||||
@@ -72,6 +74,9 @@ namespace OpenRA.Editor
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (e.Button == MouseButtons.Right)
|
||||||
|
Erase();
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Left && Brush != null)
|
if (e.Button == MouseButtons.Left && Brush != null)
|
||||||
DrawWithBrush();
|
DrawWithBrush();
|
||||||
if (e.Button == MouseButtons.Left && Actor != null)
|
if (e.Button == MouseButtons.Left && Actor != null)
|
||||||
@@ -108,6 +113,27 @@ namespace OpenRA.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Erase()
|
||||||
|
{
|
||||||
|
Actor = null;
|
||||||
|
Brush = null;
|
||||||
|
Resource = null;
|
||||||
|
|
||||||
|
var key = Map.Actors.FirstOrDefault(a => a.Value.Location == GetBrushLocation());
|
||||||
|
if (key.Key != null) Map.Actors.Remove(key.Key);
|
||||||
|
|
||||||
|
if (Map.MapResources[GetBrushLocation().X, GetBrushLocation().Y].type != 0)
|
||||||
|
{
|
||||||
|
Map.MapResources[GetBrushLocation().X, GetBrushLocation().Y] = new TileReference<byte, byte>();
|
||||||
|
var ch = new int2((GetBrushLocation().X) / ChunkSize, (GetBrushLocation().Y) / ChunkSize);
|
||||||
|
if (Chunks.ContainsKey(ch))
|
||||||
|
{
|
||||||
|
Chunks[ch].Dispose();
|
||||||
|
Chunks.Remove(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
string NextActorName()
|
string NextActorName()
|
||||||
{
|
{
|
||||||
@@ -127,18 +153,31 @@ namespace OpenRA.Editor
|
|||||||
Map.Actors[NextActorName()] = new ActorReference(Actor.Info.Name.ToLowerInvariant(), GetBrushLocation(), owner);
|
Map.Actors[NextActorName()] = new ActorReference(Actor.Info.Name.ToLowerInvariant(), GetBrushLocation(), owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Random r = new Random();
|
||||||
|
void DrawWithResource()
|
||||||
|
{
|
||||||
|
Map.MapResources[GetBrushLocation().X, GetBrushLocation().Y]
|
||||||
|
= new TileReference<byte, byte>
|
||||||
|
{
|
||||||
|
type = (byte)Resource.Info.ResourceType,
|
||||||
|
index = (byte)r.Next(Resource.Info.SpriteNames.Length),
|
||||||
|
image = (byte)Resource.Value
|
||||||
|
};
|
||||||
|
|
||||||
|
var ch = new int2((GetBrushLocation().X) / ChunkSize, (GetBrushLocation().Y) / ChunkSize);
|
||||||
|
if (Chunks.ContainsKey(ch))
|
||||||
|
{
|
||||||
|
Chunks[ch].Dispose();
|
||||||
|
Chunks.Remove(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseDown(e);
|
base.OnMouseDown(e);
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Right)
|
if (e.Button == MouseButtons.Right)
|
||||||
{
|
Erase();
|
||||||
Actor = null;
|
|
||||||
Brush = null;
|
|
||||||
|
|
||||||
var key = Map.Actors.FirstOrDefault(a => a.Value.Location == GetBrushLocation());
|
|
||||||
if (key.Key != null) Map.Actors.Remove(key.Key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Left && Brush != null)
|
if (e.Button == MouseButtons.Left && Brush != null)
|
||||||
DrawWithBrush();
|
DrawWithBrush();
|
||||||
@@ -174,6 +213,26 @@ namespace OpenRA.Editor
|
|||||||
for (var x = 0; x < 24; x++)
|
for (var x = 0; x < 24; x++)
|
||||||
for (var y = 0; y < 24; y++)
|
for (var y = 0; y < 24; y++)
|
||||||
p[ (j * 24 + y) * stride + i * 24 + x ] = Palette.GetColor(rawImage[x + 24 * y]).ToArgb();
|
p[ (j * 24 + y) * stride + i * 24 + x ] = Palette.GetColor(rawImage[x + 24 * y]).ToArgb();
|
||||||
|
|
||||||
|
if (Map.MapResources[u * ChunkSize + i, v * ChunkSize + j].type != 0)
|
||||||
|
{
|
||||||
|
var resourceImage = ResourceTemplates[Map.MapResources[u * ChunkSize + i, v * ChunkSize + j].type].Bitmap;
|
||||||
|
var srcdata = resourceImage.LockBits(new Rectangle(0, 0, resourceImage.Width, resourceImage.Height),
|
||||||
|
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||||
|
|
||||||
|
int* q = (int*)srcdata.Scan0.ToPointer();
|
||||||
|
var srcstride = srcdata.Stride >> 2;
|
||||||
|
|
||||||
|
for (var x = 0; x < 24; x++)
|
||||||
|
for (var y = 0; y < 24; y++)
|
||||||
|
{
|
||||||
|
var c = q[y * srcstride + x];
|
||||||
|
if ((c & 0xff000000) != 0) /* quick & dirty, i cbf doing real alpha */
|
||||||
|
p[(j * 24 + y) * stride + i * 24 + x] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceImage.UnlockBits(srcdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +292,11 @@ namespace OpenRA.Editor
|
|||||||
if (Actor != null)
|
if (Actor != null)
|
||||||
DrawActor(e.Graphics, GetBrushLocation(), Actor);
|
DrawActor(e.Graphics, GetBrushLocation(), Actor);
|
||||||
|
|
||||||
if (Brush == null && Actor == null)
|
if (Resource != null)
|
||||||
|
e.Graphics.DrawImage(Resource.Bitmap,
|
||||||
|
(24 * GetBrushLocation() + Offset).ToPoint());
|
||||||
|
|
||||||
|
if (Brush == null && Actor == null && Resource == null)
|
||||||
{
|
{
|
||||||
var x = Map.Actors.FirstOrDefault(a => a.Value.Location == GetBrushLocation());
|
var x = Map.Actors.FirstOrDefault(a => a.Value.Location == GetBrushLocation());
|
||||||
if (x.Key != null)
|
if (x.Key != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user