Update copyright header. Normalize line endings to LF.

This commit is contained in:
Paul Chote
2011-02-13 10:38:57 +13:00
parent ea5e2c0588
commit 094907c1a9
489 changed files with 43614 additions and 43613 deletions

View File

@@ -1,36 +1,36 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Windows.Forms;
namespace SequenceEditor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Text += " - " + Program.UnitName;
}
void toolStripButton1_Click(object sender, EventArgs e)
{
var shp = GetTextForm.GetString( "Add SHP...", "" );
if (shp == null) return;
Program.LoadAndResolve(shp);
}
void toolStripButton2_Click(object sender, EventArgs e)
{
Program.Save();
}
}
}
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Windows.Forms;
namespace SequenceEditor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Text += " - " + Program.UnitName;
}
void toolStripButton1_Click(object sender, EventArgs e)
{
var shp = GetTextForm.GetString( "Add SHP...", "" );
if (shp == null) return;
Program.LoadAndResolve(shp);
}
void toolStripButton2_Click(object sender, EventArgs e)
{
Program.Save();
}
}
}

View File

@@ -1,34 +1,34 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System.Windows.Forms;
namespace SequenceEditor
{
public partial class GetTextForm : Form
{
public GetTextForm()
{
InitializeComponent();
}
public static string GetString(string title, string defaultValue)
{
using (var f = new GetTextForm())
{
f.textBox1.Text = defaultValue;
f.Text = title;
if (DialogResult.OK != f.ShowDialog())
return null;
return f.textBox1.Text;
}
}
}
}
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Windows.Forms;
namespace SequenceEditor
{
public partial class GetTextForm : Form
{
public GetTextForm()
{
InitializeComponent();
}
public static string GetString(string title, string defaultValue)
{
using (var f = new GetTextForm())
{
f.textBox1.Text = defaultValue;
f.Text = title;
if (DialogResult.OK != f.ShowDialog())
return null;
return f.textBox1.Text;
}
}
}
}

View File

@@ -1,137 +1,137 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using OpenRA.FileFormats;
namespace SequenceEditor
{
static class Program
{
static string XmlFilename;
public static string UnitName;
public static XmlDocument Doc;
public static Dictionary<string, Bitmap[]> Shps = new Dictionary<string, Bitmap[]>();
public static Palette Pal;
public static Dictionary<string, Sequence> Sequences = new Dictionary<string, Sequence>();
public static void LoadAndResolve( string shp )
{
try
{
if (Shps.ContainsKey(shp)) return;
var reader = new ShpReader(FileSystem.OpenWithExts(shp, ".tem", ".sno", ".int", ".shp"));
Shps[shp] = reader.Select(ih =>
{
var bmp = new Bitmap(reader.Width, reader.Height);
for (var j = 0; j < bmp.Height; j++)
for (var i = 0; i < bmp.Width; i++)
bmp.SetPixel(i, j, Pal.GetColor(ih.Image[j * bmp.Width + i]));
return bmp;
}).ToArray();
}
catch { }
}
public static void Save()
{
var e = Doc.SelectSingleNode(string.Format("//unit[@name=\"{0}\"]", UnitName)) as XmlElement;
if (e == null)
{
e = Doc.CreateElement("unit");
e.SetAttribute( "name", UnitName );
e = Doc.SelectSingleNode("sequences").AppendChild(e) as XmlElement;
}
while (e.HasChildNodes) e.RemoveChild(e.FirstChild); /* what a fail */
foreach (var s in Sequences)
{
var seqnode = Doc.CreateElement("sequence");
seqnode.SetAttribute("name", s.Key);
seqnode.SetAttribute("start", s.Value.start.ToString());
seqnode.SetAttribute("length", s.Value.length.ToString());
if (s.Value.shp != UnitName)
seqnode.SetAttribute("src", s.Value.shp);
e.AppendChild(seqnode);
}
Doc.Save(XmlFilename);
}
[STAThread]
static void Main( string[] args )
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length != 3)
{
MessageBox.Show( "usage: SequenceEditor mod[,mod]* sequences-file.xml palette.pal");
return;
}
var mods = args[0].Split(',');
var manifest = new Manifest(mods);
FileSystem.LoadFromManifest( manifest );
XmlFilename = args[1];
Doc = new XmlDocument();
Doc.Load(XmlFilename);
var tempPal = new Palette(FileSystem.Open(args[2]), true);
Pal = tempPal;
UnitName = GetTextForm.GetString("Unit to edit?", "e1");
if (string.IsNullOrEmpty(UnitName))
return;
LoadAndResolve(UnitName);
var xpath = string.Format("//unit[@name=\"{0}\"]/sequence", UnitName);
foreach (XmlElement e in Doc.SelectNodes(xpath))
{
if (e.HasAttribute("src"))
LoadAndResolve(e.GetAttribute("src"));
Sequences[e.GetAttribute("name")] = new Sequence(e);
}
Application.Run(new Form1());
}
}
class Sequence
{
public int start;
public int length;
public string shp;
public Sequence(XmlElement e)
{
start = int.Parse(e.GetAttribute("start"));
shp = e.GetAttribute("src");
if (shp == "") shp = Program.UnitName;
var a = e.GetAttribute("length");
length = (a == "*")
? Program.Shps[shp].Length - start
: ((a == "") ? 1 : int.Parse(a));
}
public Sequence() { }
}
}
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using OpenRA.FileFormats;
namespace SequenceEditor
{
static class Program
{
static string XmlFilename;
public static string UnitName;
public static XmlDocument Doc;
public static Dictionary<string, Bitmap[]> Shps = new Dictionary<string, Bitmap[]>();
public static Palette Pal;
public static Dictionary<string, Sequence> Sequences = new Dictionary<string, Sequence>();
public static void LoadAndResolve( string shp )
{
try
{
if (Shps.ContainsKey(shp)) return;
var reader = new ShpReader(FileSystem.OpenWithExts(shp, ".tem", ".sno", ".int", ".shp"));
Shps[shp] = reader.Select(ih =>
{
var bmp = new Bitmap(reader.Width, reader.Height);
for (var j = 0; j < bmp.Height; j++)
for (var i = 0; i < bmp.Width; i++)
bmp.SetPixel(i, j, Pal.GetColor(ih.Image[j * bmp.Width + i]));
return bmp;
}).ToArray();
}
catch { }
}
public static void Save()
{
var e = Doc.SelectSingleNode(string.Format("//unit[@name=\"{0}\"]", UnitName)) as XmlElement;
if (e == null)
{
e = Doc.CreateElement("unit");
e.SetAttribute( "name", UnitName );
e = Doc.SelectSingleNode("sequences").AppendChild(e) as XmlElement;
}
while (e.HasChildNodes) e.RemoveChild(e.FirstChild); /* what a fail */
foreach (var s in Sequences)
{
var seqnode = Doc.CreateElement("sequence");
seqnode.SetAttribute("name", s.Key);
seqnode.SetAttribute("start", s.Value.start.ToString());
seqnode.SetAttribute("length", s.Value.length.ToString());
if (s.Value.shp != UnitName)
seqnode.SetAttribute("src", s.Value.shp);
e.AppendChild(seqnode);
}
Doc.Save(XmlFilename);
}
[STAThread]
static void Main( string[] args )
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length != 3)
{
MessageBox.Show( "usage: SequenceEditor mod[,mod]* sequences-file.xml palette.pal");
return;
}
var mods = args[0].Split(',');
var manifest = new Manifest(mods);
FileSystem.LoadFromManifest( manifest );
XmlFilename = args[1];
Doc = new XmlDocument();
Doc.Load(XmlFilename);
var tempPal = new Palette(FileSystem.Open(args[2]), true);
Pal = tempPal;
UnitName = GetTextForm.GetString("Unit to edit?", "e1");
if (string.IsNullOrEmpty(UnitName))
return;
LoadAndResolve(UnitName);
var xpath = string.Format("//unit[@name=\"{0}\"]/sequence", UnitName);
foreach (XmlElement e in Doc.SelectNodes(xpath))
{
if (e.HasAttribute("src"))
LoadAndResolve(e.GetAttribute("src"));
Sequences[e.GetAttribute("name")] = new Sequence(e);
}
Application.Run(new Form1());
}
}
class Sequence
{
public int start;
public int length;
public string shp;
public Sequence(XmlElement e)
{
start = int.Parse(e.GetAttribute("start"));
shp = e.GetAttribute("src");
if (shp == "") shp = Program.UnitName;
var a = e.GetAttribute("length");
length = (a == "*")
? Program.Shps[shp].Length - start
: ((a == "") ? 1 : int.Parse(a));
}
public Sequence() { }
}
}

View File

@@ -1,230 +1,230 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using OpenRA.FileFormats;
namespace SequenceEditor
{
public class Surface : Control
{
public Surface()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
UpdateStyles();
}
Dictionary<string, Dictionary<int, Rectangle>> items
= new Dictionary<string, Dictionary<int, Rectangle>>();
Point mousePos;
Point clickPos;
bool isDragging;
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
mousePos = e.Location;
if (e.Button == MouseButtons.Left)
isDragging = true;
Invalidate();
}
Pair<string, int>? FindFrameAt(Point p)
{
if (items.Count > 0)
{
foreach (var shp in items)
{
var sel = shp.Value.FirstOrDefault(a => a.Value.Contains(p));
if (!sel.Value.IsEmpty)
return Pair.New(shp.Key, sel.Key);
}
}
return null;
}
string lastName = "";
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (isDragging && e.Button == MouseButtons.Left)
{
isDragging = false;
/* create a new sequence! */
var start = FindFrameAt(clickPos);
var end = FindFrameAt(mousePos);
if (start != null && end != null
&& start.Value.First == end.Value.First)
{
var s = new Sequence()
{
start = start.Value.Second,
length = end.Value.Second - start.Value.Second + 1,
shp = start.Value.First
};
var name = GetTextForm.GetString("Name of new sequence", lastName);
if (name == null) return;
Program.Sequences.Add(name, s);
lastName = name;
}
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
clickPos = e.Location;
if (e.Button == MouseButtons.Right)
{
var frameAtPoint = FindFrameAt(e.Location);
if (frameAtPoint == null) return;
var seq = Program.Sequences
.Where(kv => kv.Value.shp == frameAtPoint.Value.First &&
frameAtPoint.Value.Second.IsInRange( kv.Value.start, kv.Value.length )).ToArray();
foreach (var s in seq)
Program.Sequences.Remove(s.Key);
Invalidate();
}
}
Sequence tempSequence;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var x = 0;
var y = 0;
Point? toolPoint = null;
string toolText = "";
var frameAtPoint = FindFrameAt(mousePos);
if (frameAtPoint != null)
{
var rect = items[frameAtPoint.Value.First][frameAtPoint.Value.Second];
e.Graphics.FillRectangle(Brushes.Silver, rect);
toolPoint = new Point(rect.Left, rect.Bottom);
toolText = frameAtPoint.Value.Second.ToString();
}
tempSequence = null;
if (isDragging)
{
/* create a new sequence! */
var start = FindFrameAt(clickPos);
var end = FindFrameAt(mousePos);
if (start != null && end != null
&& start.Value.First == end.Value.First)
tempSequence = new Sequence() {
start = start.Value.Second,
length = end.Value.Second - start.Value.Second + 1,
shp = start.Value.First };
}
items.Clear();
foreach (var shp in Program.Shps)
{
x = 0;
e.Graphics.DrawString(shp.Key + ".shp", Font, Brushes.Black, x, y);
y += Font.Height;
var u = 0;
var i = 0;
var dict = items[shp.Key] = new Dictionary<int, Rectangle>();
foreach (var frame in shp.Value)
{
if (x + frame.Width >= ClientSize.Width)
{
x = 0;
y += u;
u = 0;
}
dict[i++] = new Rectangle(x, y, frame.Width, frame.Height);
e.Graphics.DrawImage(frame, x, y);
x += frame.Width;
u = Math.Max(u, frame.Height);
}
y += u;
x = 0;
}
var brushes = new[] { Brushes.Green, Brushes.Red, Brushes.Blue, Brushes.Magenta, Brushes.DarkOrange, Brushes.Navy };
var seqid = 0;
var seqs = Program.Sequences.Select(a => a); /* shorter than teh typename!! */
if (tempSequence != null)
seqs = seqs.Concat(new[] { new KeyValuePair<string, Sequence>("New sequence...", tempSequence) });
foreach (var seq in seqs)
{
var firstFrame = seq.Value.start;
var r = items[seq.Value.shp][firstFrame];
for (var i = 0; i < seq.Value.length; i++)
{
var q = items[seq.Value.shp][i + firstFrame];
e.Graphics.FillRectangle(brushes[seqid], q.Left, q.Top, q.Width, 2);
}
var z = e.Graphics.MeasureString(seq.Key, Font);
e.Graphics.FillRectangle(brushes[seqid], r.Left, r.Top, z.Width, z.Height);
e.Graphics.DrawString(seq.Key, Font, Brushes.White, r.Left, r.Top);
seqid = ++seqid % brushes.Length;
}
if (toolPoint.HasValue)
{
var size = e.Graphics.MeasureString(toolText, Font);
e.Graphics.FillRectangle(Brushes.Silver, toolPoint.Value.X, toolPoint.Value.Y, size.Width, size.Height);
e.Graphics.DrawString(toolText, Font, Brushes.Black, toolPoint.Value.X, toolPoint.Value.Y);
}
var newHeight = Math.Max( Parent.ClientSize.Height, y );
if (Height != newHeight)
Height = newHeight;
}
}
static class Exts
{
public static bool IsInRange(this int x, int start, int len)
{
return x >= start && x < start + len;
}
}
}
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using OpenRA.FileFormats;
namespace SequenceEditor
{
public class Surface : Control
{
public Surface()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
UpdateStyles();
}
Dictionary<string, Dictionary<int, Rectangle>> items
= new Dictionary<string, Dictionary<int, Rectangle>>();
Point mousePos;
Point clickPos;
bool isDragging;
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
mousePos = e.Location;
if (e.Button == MouseButtons.Left)
isDragging = true;
Invalidate();
}
Pair<string, int>? FindFrameAt(Point p)
{
if (items.Count > 0)
{
foreach (var shp in items)
{
var sel = shp.Value.FirstOrDefault(a => a.Value.Contains(p));
if (!sel.Value.IsEmpty)
return Pair.New(shp.Key, sel.Key);
}
}
return null;
}
string lastName = "";
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (isDragging && e.Button == MouseButtons.Left)
{
isDragging = false;
/* create a new sequence! */
var start = FindFrameAt(clickPos);
var end = FindFrameAt(mousePos);
if (start != null && end != null
&& start.Value.First == end.Value.First)
{
var s = new Sequence()
{
start = start.Value.Second,
length = end.Value.Second - start.Value.Second + 1,
shp = start.Value.First
};
var name = GetTextForm.GetString("Name of new sequence", lastName);
if (name == null) return;
Program.Sequences.Add(name, s);
lastName = name;
}
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
clickPos = e.Location;
if (e.Button == MouseButtons.Right)
{
var frameAtPoint = FindFrameAt(e.Location);
if (frameAtPoint == null) return;
var seq = Program.Sequences
.Where(kv => kv.Value.shp == frameAtPoint.Value.First &&
frameAtPoint.Value.Second.IsInRange( kv.Value.start, kv.Value.length )).ToArray();
foreach (var s in seq)
Program.Sequences.Remove(s.Key);
Invalidate();
}
}
Sequence tempSequence;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var x = 0;
var y = 0;
Point? toolPoint = null;
string toolText = "";
var frameAtPoint = FindFrameAt(mousePos);
if (frameAtPoint != null)
{
var rect = items[frameAtPoint.Value.First][frameAtPoint.Value.Second];
e.Graphics.FillRectangle(Brushes.Silver, rect);
toolPoint = new Point(rect.Left, rect.Bottom);
toolText = frameAtPoint.Value.Second.ToString();
}
tempSequence = null;
if (isDragging)
{
/* create a new sequence! */
var start = FindFrameAt(clickPos);
var end = FindFrameAt(mousePos);
if (start != null && end != null
&& start.Value.First == end.Value.First)
tempSequence = new Sequence() {
start = start.Value.Second,
length = end.Value.Second - start.Value.Second + 1,
shp = start.Value.First };
}
items.Clear();
foreach (var shp in Program.Shps)
{
x = 0;
e.Graphics.DrawString(shp.Key + ".shp", Font, Brushes.Black, x, y);
y += Font.Height;
var u = 0;
var i = 0;
var dict = items[shp.Key] = new Dictionary<int, Rectangle>();
foreach (var frame in shp.Value)
{
if (x + frame.Width >= ClientSize.Width)
{
x = 0;
y += u;
u = 0;
}
dict[i++] = new Rectangle(x, y, frame.Width, frame.Height);
e.Graphics.DrawImage(frame, x, y);
x += frame.Width;
u = Math.Max(u, frame.Height);
}
y += u;
x = 0;
}
var brushes = new[] { Brushes.Green, Brushes.Red, Brushes.Blue, Brushes.Magenta, Brushes.DarkOrange, Brushes.Navy };
var seqid = 0;
var seqs = Program.Sequences.Select(a => a); /* shorter than teh typename!! */
if (tempSequence != null)
seqs = seqs.Concat(new[] { new KeyValuePair<string, Sequence>("New sequence...", tempSequence) });
foreach (var seq in seqs)
{
var firstFrame = seq.Value.start;
var r = items[seq.Value.shp][firstFrame];
for (var i = 0; i < seq.Value.length; i++)
{
var q = items[seq.Value.shp][i + firstFrame];
e.Graphics.FillRectangle(brushes[seqid], q.Left, q.Top, q.Width, 2);
}
var z = e.Graphics.MeasureString(seq.Key, Font);
e.Graphics.FillRectangle(brushes[seqid], r.Left, r.Top, z.Width, z.Height);
e.Graphics.DrawString(seq.Key, Font, Brushes.White, r.Left, r.Top);
seqid = ++seqid % brushes.Length;
}
if (toolPoint.HasValue)
{
var size = e.Graphics.MeasureString(toolText, Font);
e.Graphics.FillRectangle(Brushes.Silver, toolPoint.Value.X, toolPoint.Value.Y, size.Width, size.Height);
e.Graphics.DrawString(toolText, Font, Brushes.Black, toolPoint.Value.X, toolPoint.Value.Y);
}
var newHeight = Math.Max( Parent.ClientSize.Height, y );
if (Height != newHeight)
Height = newHeight;
}
}
static class Exts
{
public static bool IsInRange(this int x, int start, int len)
{
return x >= start && x < start + len;
}
}
}