summaryrefslogtreecommitdiff
path: root/MainForm.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MainForm.cs')
-rw-r--r--MainForm.cs1046
1 files changed, 1046 insertions, 0 deletions
diff --git a/MainForm.cs b/MainForm.cs
new file mode 100644
index 0000000..b2212e2
--- /dev/null
+++ b/MainForm.cs
@@ -0,0 +1,1046 @@
+// GfxEd8
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// 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.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// $Id$
+//
+using System;
+using System.Windows.Forms;
+using System.IO;
+using System.Drawing;
+using GfxEdInterface;
+using Noddybox.GUI;
+
+namespace GfxEd8
+{
+ /// <summary>
+ /// Description of MainForm.
+ /// </summary>
+ public class MainForm : System.Windows.Forms.Form
+ {
+ private System.Windows.Forms.CheckBox m_applyAll;
+ private System.Windows.Forms.Button m_scrollLeftButton;
+ private System.Windows.Forms.Button m_rotateRightButton;
+ private System.Windows.Forms.NumericUpDown m_spriteNo;
+ private System.Windows.Forms.Button m_deleteButton;
+ private System.Windows.Forms.Button m_insertButton;
+ private System.Windows.Forms.Button m_scrollRightButton;
+ private System.Windows.Forms.Button m_clearButton;
+ private System.Windows.Forms.GroupBox m_adjustGroup;
+ private System.Windows.Forms.Button m_scrollDownButton;
+ private System.Windows.Forms.Button m_rotateLeftButton;
+ private System.Windows.Forms.Button m_mirrorHorizButton;
+ private System.Windows.Forms.GroupBox m_editorGroup;
+ private System.Windows.Forms.GroupBox m_controlGroup;
+ private System.Windows.Forms.Button m_scrollUpButton;
+ private System.Windows.Forms.Button m_revertButton;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.NumericUpDown m_duplicateCount;
+ private System.Windows.Forms.Button m_duplicateButton;
+ private System.Windows.Forms.Button m_addButton;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.TextBox m_spriteCount;
+ private System.Windows.Forms.Button m_mirrorVerticalButton;
+
+ private GfxEditor m_editor;
+ private string m_path;
+ private string m_exportPath;
+ private MenuTree m_menu;
+ private MenuItem m_editorTypeMenu;
+ private IPlugin m_plugin;
+ private SpriteList m_sprite;
+ private int m_index;
+ private bool m_blockValue;
+ private bool m_commonPal;
+
+ private const string MAGIC="@GFXED8_ISS1";
+
+ public MainForm()
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ // For some reason, this crashes the designer since I put them
+ // inside groups...
+ //
+ m_editor=new GfxEditor();
+ m_editor.Location=new Point(4,16);
+
+ m_editorGroup.Controls.Add(m_editor);
+
+ PluginControl.Initialise("gfxed8config.xml");
+
+ if (PluginControl.Names.Count==0)
+ {
+ throw new Exception("No plugins defined");
+ }
+
+ m_sprite=new SpriteList();
+
+ Menu=new MainMenu();
+
+ m_menu=new MenuTree(Menu);
+ m_editorTypeMenu=new MenuItem("Editor Type");
+
+ foreach (string s in PluginControl.Names)
+ {
+ m_editorTypeMenu.MenuItems.Add
+ (new MenuItem(s,new EventHandler(OnEditorChanged)));
+ }
+
+ m_menu.Add("/file", "File");
+ m_menu.Add("/file/new", "New", new EventHandler(OnNew));
+ m_menu.Add("/file/open", "Open...", new EventHandler(OnOpen));
+ m_menu.Add("/file/save", "Save", new EventHandler(OnSave));
+ m_menu.Add("/file/saveas", "Save as...", new EventHandler(OnSaveAs));
+ m_menu.Add("/file/quit", "Quit", new EventHandler(OnQuit));
+
+ m_menu.Add("/editor", m_editorTypeMenu);
+
+ m_menu.Add("/plugin","Plugin");
+ m_menu.Add("/plugin/export","Export...",new EventHandler(OnExport));
+ m_menu.Add("/plugin/config","Config...",new EventHandler(OnConfig));
+ m_menu.Add("/plugin/process","Process");
+ m_menu.Add("/plugin/process/one","Current Sprite...",new EventHandler(OnProcessOne));
+ m_menu.Add("/plugin/process/all","All Sprites...",new EventHandler(OnProcessAll));
+
+ m_menu.Add("/help","Help");
+ m_menu.Add("/help/about","About...", new EventHandler(OnAbout));
+
+ m_menu.Get("/file/save").Enabled=false;
+
+ m_path="";
+ m_exportPath="";
+
+ m_editorTypeMenu.MenuItems[0].Checked=true;
+
+ InitialiseEditor(m_editorTypeMenu.MenuItems[0]);
+ }
+
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ //try
+ {
+ Application.Run(new MainForm());
+ }
+ //catch (Exception e)
+ {
+ //Util.Error(e.Message);
+ }
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// This method is required for Windows Forms designer support.
+ /// Do not change the method contents inside the source code editor. The Forms designer might
+ /// not be able to load this method if it was changed manually.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_mirrorVerticalButton = new System.Windows.Forms.Button();
+ this.m_spriteCount = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.label5 = new System.Windows.Forms.Label();
+ this.m_addButton = new System.Windows.Forms.Button();
+ this.m_duplicateButton = new System.Windows.Forms.Button();
+ this.m_duplicateCount = new System.Windows.Forms.NumericUpDown();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.m_revertButton = new System.Windows.Forms.Button();
+ this.m_scrollUpButton = new System.Windows.Forms.Button();
+ this.m_controlGroup = new System.Windows.Forms.GroupBox();
+ this.m_editorGroup = new System.Windows.Forms.GroupBox();
+ this.m_mirrorHorizButton = new System.Windows.Forms.Button();
+ this.m_rotateLeftButton = new System.Windows.Forms.Button();
+ this.m_scrollDownButton = new System.Windows.Forms.Button();
+ this.m_adjustGroup = new System.Windows.Forms.GroupBox();
+ this.m_clearButton = new System.Windows.Forms.Button();
+ this.m_scrollRightButton = new System.Windows.Forms.Button();
+ this.m_insertButton = new System.Windows.Forms.Button();
+ this.m_deleteButton = new System.Windows.Forms.Button();
+ this.m_spriteNo = new System.Windows.Forms.NumericUpDown();
+ this.m_rotateRightButton = new System.Windows.Forms.Button();
+ this.m_scrollLeftButton = new System.Windows.Forms.Button();
+ this.m_applyAll = new System.Windows.Forms.CheckBox();
+ ((System.ComponentModel.ISupportInitialize)(this.m_duplicateCount)).BeginInit();
+ this.m_controlGroup.SuspendLayout();
+ this.m_adjustGroup.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.m_spriteNo)).BeginInit();
+ this.SuspendLayout();
+ //
+ // m_mirrorVerticalButton
+ //
+ this.m_mirrorVerticalButton.Location = new System.Drawing.Point(80, 96);
+ this.m_mirrorVerticalButton.Name = "m_mirrorVerticalButton";
+ this.m_mirrorVerticalButton.Size = new System.Drawing.Size(64, 24);
+ this.m_mirrorVerticalButton.TabIndex = 4;
+ this.m_mirrorVerticalButton.Text = "Vertical";
+ this.m_mirrorVerticalButton.Click += new System.EventHandler(this.OnVerticalMirror);
+ //
+ // m_spriteCount
+ //
+ this.m_spriteCount.Location = new System.Drawing.Point(88, 24);
+ this.m_spriteCount.Name = "m_spriteCount";
+ this.m_spriteCount.ReadOnly = true;
+ this.m_spriteCount.Size = new System.Drawing.Size(48, 20);
+ this.m_spriteCount.TabIndex = 10;
+ this.m_spriteCount.Text = "textBox1";
+ //
+ // label4
+ //
+ this.label4.Location = new System.Drawing.Point(8, 208);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(136, 16);
+ this.label4.TabIndex = 11;
+ this.label4.Text = "Rotate";
+ this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // label5
+ //
+ this.label5.Location = new System.Drawing.Point(272, 56);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(40, 24);
+ this.label5.TabIndex = 17;
+ this.label5.Text = "Times";
+ this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // m_addButton
+ //
+ this.m_addButton.Location = new System.Drawing.Point(144, 24);
+ this.m_addButton.Name = "m_addButton";
+ this.m_addButton.Size = new System.Drawing.Size(64, 24);
+ this.m_addButton.TabIndex = 12;
+ this.m_addButton.Text = "Add";
+ this.m_addButton.Click += new System.EventHandler(this.OnAddSprite);
+ //
+ // m_duplicateButton
+ //
+ this.m_duplicateButton.Location = new System.Drawing.Point(144, 56);
+ this.m_duplicateButton.Name = "m_duplicateButton";
+ this.m_duplicateButton.Size = new System.Drawing.Size(64, 24);
+ this.m_duplicateButton.TabIndex = 15;
+ this.m_duplicateButton.Text = "Duplicate";
+ this.m_duplicateButton.Click += new System.EventHandler(this.OnDuplicateSprite);
+ //
+ // m_duplicateCount
+ //
+ this.m_duplicateCount.Location = new System.Drawing.Point(216, 56);
+ this.m_duplicateCount.Maximum = new System.Decimal(new int[] {
+ 999,
+ 0,
+ 0,
+ 0});
+ this.m_duplicateCount.Minimum = new System.Decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.m_duplicateCount.Name = "m_duplicateCount";
+ this.m_duplicateCount.Size = new System.Drawing.Size(48, 20);
+ this.m_duplicateCount.TabIndex = 16;
+ this.m_duplicateCount.UpDownAlign = System.Windows.Forms.LeftRightAlignment.Left;
+ this.m_duplicateCount.Value = new System.Decimal(new int[] {
+ 7,
+ 0,
+ 0,
+ 0});
+ //
+ // label1
+ //
+ this.label1.Location = new System.Drawing.Point(8, 80);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(40, 16);
+ this.label1.TabIndex = 3;
+ this.label1.Text = "Mirror";
+ this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // label2
+ //
+ this.label2.Location = new System.Drawing.Point(64, 24);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(16, 24);
+ this.label2.TabIndex = 9;
+ this.label2.Text = "of";
+ this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // label3
+ //
+ this.label3.Location = new System.Drawing.Point(8, 128);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(136, 16);
+ this.label3.TabIndex = 6;
+ this.label3.Text = "Scroll";
+ this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // m_revertButton
+ //
+ this.m_revertButton.Location = new System.Drawing.Point(360, 24);
+ this.m_revertButton.Name = "m_revertButton";
+ this.m_revertButton.Size = new System.Drawing.Size(64, 24);
+ this.m_revertButton.TabIndex = 14;
+ this.m_revertButton.Text = "Revert";
+ this.m_revertButton.Click += new System.EventHandler(this.OnRevertSprite);
+ //
+ // m_scrollUpButton
+ //
+ this.m_scrollUpButton.Location = new System.Drawing.Point(8, 176);
+ this.m_scrollUpButton.Name = "m_scrollUpButton";
+ this.m_scrollUpButton.Size = new System.Drawing.Size(64, 24);
+ this.m_scrollUpButton.TabIndex = 8;
+ this.m_scrollUpButton.Text = "Up";
+ this.m_scrollUpButton.Click += new System.EventHandler(this.OnUpScroll);
+ //
+ // m_controlGroup
+ //
+ this.m_controlGroup.Controls.Add(this.label5);
+ this.m_controlGroup.Controls.Add(this.m_duplicateCount);
+ this.m_controlGroup.Controls.Add(this.m_duplicateButton);
+ this.m_controlGroup.Controls.Add(this.m_revertButton);
+ this.m_controlGroup.Controls.Add(this.m_deleteButton);
+ this.m_controlGroup.Controls.Add(this.m_addButton);
+ this.m_controlGroup.Controls.Add(this.m_insertButton);
+ this.m_controlGroup.Controls.Add(this.m_spriteNo);
+ this.m_controlGroup.Controls.Add(this.label2);
+ this.m_controlGroup.Controls.Add(this.m_spriteCount);
+ this.m_controlGroup.Location = new System.Drawing.Point(8, 344);
+ this.m_controlGroup.Name = "m_controlGroup";
+ this.m_controlGroup.Size = new System.Drawing.Size(560, 88);
+ this.m_controlGroup.TabIndex = 12;
+ this.m_controlGroup.TabStop = false;
+ this.m_controlGroup.Text = "Sprite";
+ //
+ // m_editorGroup
+ //
+ this.m_editorGroup.Location = new System.Drawing.Point(8, 0);
+ this.m_editorGroup.Name = "m_editorGroup";
+ this.m_editorGroup.Size = new System.Drawing.Size(392, 336);
+ this.m_editorGroup.TabIndex = 13;
+ this.m_editorGroup.TabStop = false;
+ this.m_editorGroup.Text = "Editor";
+ //
+ // m_mirrorHorizButton
+ //
+ this.m_mirrorHorizButton.Location = new System.Drawing.Point(8, 96);
+ this.m_mirrorHorizButton.Name = "m_mirrorHorizButton";
+ this.m_mirrorHorizButton.Size = new System.Drawing.Size(64, 24);
+ this.m_mirrorHorizButton.TabIndex = 2;
+ this.m_mirrorHorizButton.Text = "Horizontal";
+ this.m_mirrorHorizButton.Click += new System.EventHandler(this.OnHorizontalMirror);
+ //
+ // m_rotateLeftButton
+ //
+ this.m_rotateLeftButton.Location = new System.Drawing.Point(8, 224);
+ this.m_rotateLeftButton.Name = "m_rotateLeftButton";
+ this.m_rotateLeftButton.Size = new System.Drawing.Size(64, 24);
+ this.m_rotateLeftButton.TabIndex = 10;
+ this.m_rotateLeftButton.Text = "Left";
+ this.m_rotateLeftButton.Click += new System.EventHandler(this.OnRotateLeft);
+ //
+ // m_scrollDownButton
+ //
+ this.m_scrollDownButton.Location = new System.Drawing.Point(80, 176);
+ this.m_scrollDownButton.Name = "m_scrollDownButton";
+ this.m_scrollDownButton.Size = new System.Drawing.Size(64, 24);
+ this.m_scrollDownButton.TabIndex = 9;
+ this.m_scrollDownButton.Text = "Down";
+ this.m_scrollDownButton.Click += new System.EventHandler(this.OnDownScroll);
+ //
+ // m_adjustGroup
+ //
+ this.m_adjustGroup.Controls.Add(this.m_rotateRightButton);
+ this.m_adjustGroup.Controls.Add(this.label4);
+ this.m_adjustGroup.Controls.Add(this.m_rotateLeftButton);
+ this.m_adjustGroup.Controls.Add(this.m_scrollDownButton);
+ this.m_adjustGroup.Controls.Add(this.m_scrollUpButton);
+ this.m_adjustGroup.Controls.Add(this.m_scrollRightButton);
+ this.m_adjustGroup.Controls.Add(this.label3);
+ this.m_adjustGroup.Controls.Add(this.m_scrollLeftButton);
+ this.m_adjustGroup.Controls.Add(this.m_mirrorVerticalButton);
+ this.m_adjustGroup.Controls.Add(this.label1);
+ this.m_adjustGroup.Controls.Add(this.m_mirrorHorizButton);
+ this.m_adjustGroup.Controls.Add(this.m_applyAll);
+ this.m_adjustGroup.Controls.Add(this.m_clearButton);
+ this.m_adjustGroup.Location = new System.Drawing.Point(408, 0);
+ this.m_adjustGroup.Name = "m_adjustGroup";
+ this.m_adjustGroup.Size = new System.Drawing.Size(160, 336);
+ this.m_adjustGroup.TabIndex = 14;
+ this.m_adjustGroup.TabStop = false;
+ this.m_adjustGroup.Text = "Adjust";
+ //
+ // m_clearButton
+ //
+ this.m_clearButton.Location = new System.Drawing.Point(8, 48);
+ this.m_clearButton.Name = "m_clearButton";
+ this.m_clearButton.Size = new System.Drawing.Size(64, 24);
+ this.m_clearButton.TabIndex = 0;
+ this.m_clearButton.Text = "Clear";
+ this.m_clearButton.Click += new System.EventHandler(this.OnClear);
+ //
+ // m_scrollRightButton
+ //
+ this.m_scrollRightButton.Location = new System.Drawing.Point(80, 144);
+ this.m_scrollRightButton.Name = "m_scrollRightButton";
+ this.m_scrollRightButton.Size = new System.Drawing.Size(64, 24);
+ this.m_scrollRightButton.TabIndex = 7;
+ this.m_scrollRightButton.Text = "Right";
+ this.m_scrollRightButton.Click += new System.EventHandler(this.OnRightScroll);
+ //
+ // m_insertButton
+ //
+ this.m_insertButton.Location = new System.Drawing.Point(216, 24);
+ this.m_insertButton.Name = "m_insertButton";
+ this.m_insertButton.Size = new System.Drawing.Size(64, 24);
+ this.m_insertButton.TabIndex = 11;
+ this.m_insertButton.Text = "Insert";
+ this.m_insertButton.Click += new System.EventHandler(this.OnInsertSprite);
+ //
+ // m_deleteButton
+ //
+ this.m_deleteButton.Location = new System.Drawing.Point(288, 24);
+ this.m_deleteButton.Name = "m_deleteButton";
+ this.m_deleteButton.Size = new System.Drawing.Size(64, 24);
+ this.m_deleteButton.TabIndex = 13;
+ this.m_deleteButton.Text = "Delete";
+ this.m_deleteButton.Click += new System.EventHandler(this.OnDeleteSprite);
+ //
+ // m_spriteNo
+ //
+ this.m_spriteNo.Location = new System.Drawing.Point(8, 24);
+ this.m_spriteNo.Name = "m_spriteNo";
+ this.m_spriteNo.Size = new System.Drawing.Size(56, 20);
+ this.m_spriteNo.TabIndex = 6;
+ this.m_spriteNo.ValueChanged += new System.EventHandler(this.OnSprite);
+ //
+ // m_rotateRightButton
+ //
+ this.m_rotateRightButton.Location = new System.Drawing.Point(80, 224);
+ this.m_rotateRightButton.Name = "m_rotateRightButton";
+ this.m_rotateRightButton.Size = new System.Drawing.Size(64, 24);
+ this.m_rotateRightButton.TabIndex = 12;
+ this.m_rotateRightButton.Text = "Right";
+ this.m_rotateRightButton.Click += new System.EventHandler(this.OnRotateRight);
+ //
+ // m_scrollLeftButton
+ //
+ this.m_scrollLeftButton.Location = new System.Drawing.Point(8, 144);
+ this.m_scrollLeftButton.Name = "m_scrollLeftButton";
+ this.m_scrollLeftButton.Size = new System.Drawing.Size(64, 24);
+ this.m_scrollLeftButton.TabIndex = 5;
+ this.m_scrollLeftButton.Text = "Left";
+ this.m_scrollLeftButton.Click += new System.EventHandler(this.OnLeftScroll);
+ //
+ // m_applyAll
+ //
+ this.m_applyAll.Location = new System.Drawing.Point(8, 16);
+ this.m_applyAll.Name = "m_applyAll";
+ this.m_applyAll.Size = new System.Drawing.Size(120, 24);
+ this.m_applyAll.TabIndex = 1;
+ this.m_applyAll.Text = "Apply to all Sprites";
+ //
+ // MainForm
+ //
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+ this.ClientSize = new System.Drawing.Size(578, 447);
+ this.Controls.Add(this.m_adjustGroup);
+ this.Controls.Add(this.m_editorGroup);
+ this.Controls.Add(this.m_controlGroup);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+ this.MaximizeBox = false;
+ this.Name = "MainForm";
+ this.Text = "GfxEd8";
+ this.Closing += new System.ComponentModel.CancelEventHandler(this.OnFormClosing);
+ ((System.ComponentModel.ISupportInitialize)(this.m_duplicateCount)).EndInit();
+ this.m_controlGroup.ResumeLayout(false);
+ this.m_adjustGroup.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.m_spriteNo)).EndInit();
+ this.ResumeLayout(false);
+ }
+ #endregion
+
+ private void UpdateSpriteCount()
+ {
+ m_blockValue=true;
+
+ m_spriteCount.Text=m_sprite.Count.ToString();
+ m_deleteButton.Enabled=(m_sprite.Count>1);
+
+ if (m_index>=m_sprite.Count)
+ {
+ m_index=m_sprite.Count-1;
+ m_spriteNo.Value=m_sprite.Count;
+ }
+
+ m_spriteNo.Maximum=m_sprite.Count;
+
+ m_blockValue=false;
+ }
+
+ private void InitialiseEditor(MenuItem i)
+ {
+ m_blockValue=true;
+
+ m_plugin=PluginControl.Get(i.Text);
+
+ m_commonPal=false;
+
+ foreach (bool b in m_plugin.SprPalCommon)
+ {
+ m_commonPal|=b;
+ }
+
+ m_menu.Get("/plugin/config").Enabled=(m_plugin.Config!=null);
+ m_menu.Get("/plugin/process").Enabled=(m_plugin.Process!=null);
+
+ m_sprite.Clear();
+ m_sprite.Add(new Sprite("",m_plugin.AllowedSizes[0],m_plugin.MaxColours));
+ m_sprite.Changed=false;
+
+ Text="GfxEd8 - " + m_plugin.Description;
+
+ m_editor.Plugin=m_plugin;
+ m_editor.Sprite=m_sprite[0];
+
+ m_spriteNo.Value=1;
+ m_spriteNo.Minimum=1;
+ m_spriteNo.Maximum=1;
+ m_index=0;
+
+ m_blockValue=false;
+
+ UpdateSpriteCount();
+ }
+
+ private void GetEdit()
+ {
+ m_sprite[m_index]=m_editor.Sprite;
+ CheckCommonPal();
+ }
+
+ private void CheckCommonPal()
+ {
+ if (m_commonPal)
+ {
+ Sprite spr=m_sprite[m_index];
+
+ foreach (Sprite s in m_sprite)
+ {
+ uint i=0;
+
+ foreach (bool b in m_plugin.SprPalCommon)
+ {
+ if (b)
+ {
+ s.Pal(i,spr.Pal(i));
+ }
+
+ ++i;
+ }
+ }
+ }
+ }
+
+ private bool LoadSprites()
+ {
+ TextReader str=null;
+
+ try
+ {
+ IPlugin plugin;
+
+ str=File.OpenText(m_path);
+
+ string s;
+
+ s=str.ReadLine();
+
+ if (s!=MAGIC)
+ {
+ Util.Error(m_path,"Not a GfxEd8 file or incompatible version");
+ str.Close();
+ m_path="";
+ return false;
+ }
+
+ s=str.ReadLine();
+
+ plugin=PluginControl.Get(s);
+
+ if (plugin==null)
+ {
+ Util.Error(m_path,"Used an unknown plugin:\n"+s);
+ str.Close();
+ m_path="";
+ return false;
+ }
+
+ s=str.ReadLine();
+
+ if (s!=PluginControl.Version(plugin.ShortName))
+ {
+ if (!Util.YesNo
+ ("Different version of plugin used to save file.\n"+
+ "Loaded plugin version: "+
+ PluginControl.Version(plugin.ShortName)+"\n"+
+ "File saved with version: "+s+".\n\nTry and load anyway?"))
+ {
+ str.Close();
+ m_path="";
+ return false;
+ }
+ }
+
+ m_exportPath=str.ReadLine();
+
+ if (plugin.Config!=null)
+ {
+ plugin.Config.Input(str);
+ }
+
+ foreach (MenuItem i in m_editorTypeMenu.MenuItems)
+ {
+ if (i.Text==plugin.ShortName)
+ {
+ i.Checked=true;
+ InitialiseEditor(i);
+ break;
+ }
+ else
+ {
+ i.Checked=false;
+ }
+ }
+
+ m_sprite=SpriteList.Input(str);
+
+ UpdateSpriteCount();
+ m_editor.Sprite=new Sprite(m_sprite[0]);
+
+ str.Close();
+
+ return true;
+ }
+ catch (IOException ex)
+ {
+ if (str!=null)
+ {
+ str.Close();
+ }
+
+ Util.Error(m_path,"Error reading file:\n"+ex.Message);
+ m_path="";
+ return false;
+ }
+ }
+
+ private void SaveSprites()
+ {
+ GetEdit();
+
+ TextWriter str=null;
+
+ try
+ {
+ str=File.CreateText(m_path);
+
+ str.WriteLine(MAGIC);
+ str.WriteLine(m_plugin.ShortName);
+ str.WriteLine(PluginControl.Version(m_plugin.ShortName));
+ str.WriteLine(m_exportPath);
+
+ if (m_plugin.Config!=null)
+ {
+ m_plugin.Config.Output(str);
+ }
+
+ m_sprite.Output(str);
+
+ str.Close();
+
+ m_sprite.Changed=false;
+ }
+ catch (IOException ex)
+ {
+ if (str!=null)
+ {
+ str.Close();
+ }
+
+ Util.Error(m_path,"Error writing file:\n"+ex.Message);
+ m_path="";
+ return;
+ }
+ }
+
+ private void Scroll(int dx, int dy)
+ {
+ GetEdit();
+
+ if (m_applyAll.Checked)
+ {
+ foreach (Sprite s in m_sprite)
+ {
+ s.Scroll(dx,dy);
+ }
+ }
+ else
+ {
+ m_sprite[m_index].Scroll(dx,dy);
+ }
+
+ m_sprite.Changed=true;
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnEditorChanged(object sender, System.EventArgs e)
+ {
+ MenuItem i=(MenuItem)sender;
+
+ if (i.Checked)
+ {
+ return;
+ }
+
+ if (m_sprite.Changed && !Util.YesNo("Sure you want to change the editor?\n"+
+ "All edits will be lost."))
+ {
+ return;
+ }
+
+ foreach (MenuItem m in m_editorTypeMenu.MenuItems)
+ {
+ m.Checked=(m==i);
+ }
+
+ InitialiseEditor(i);
+ }
+
+ void OnNew(object sender, System.EventArgs e)
+ {
+ if (!m_sprite.Changed || Util.YesNo("Lose current edits?"))
+ {
+ m_sprite.Clear();
+ m_sprite.Add(new Sprite("",m_plugin.AllowedSizes[0],m_plugin.MaxColours));
+ m_sprite.Changed=false;
+ m_menu.Get("/file/save").Enabled=false;
+ m_path="";
+ }
+ }
+
+ void OnOpen(object sender, System.EventArgs e)
+ {
+ if (!m_sprite.Changed || Util.YesNo("Lose current edits?"))
+ {
+ OpenFileDialog fsel=new OpenFileDialog();
+
+ fsel.FileName=m_path;
+ fsel.Filter="GfxEd8 files (*.gf8)|*.gf8|All files (*.*)|*.*";
+ fsel.FilterIndex=1;
+
+ if(fsel.ShowDialog()==DialogResult.OK)
+ {
+ m_path=fsel.FileName;
+
+ if (LoadSprites())
+ {
+ m_menu.Get("/file/save").Enabled=true;
+ }
+ }
+ }
+ }
+
+ void OnSave(object sender, System.EventArgs e)
+ {
+ SaveSprites();
+ }
+
+ void OnSaveAs(object sender, System.EventArgs e)
+ {
+ SaveFileDialog fsel=new SaveFileDialog();
+
+ fsel.FileName=m_path;
+ fsel.Filter="GfxEd8 files (*.gf8)|*.gf8|All files (*.*)|*.*";
+ fsel.FilterIndex=1;
+
+ if(fsel.ShowDialog()==DialogResult.OK)
+ {
+ m_path=fsel.FileName;
+
+ SaveSprites();
+ m_menu.Get("/file/save").Enabled=true;
+ }
+ }
+
+ void OnQuit(object sender, System.EventArgs e)
+ {
+ if (!m_sprite.Changed || Util.YesNo("Lose current edits?"))
+ {
+ m_sprite.Changed=false;
+ Close();
+ }
+ }
+
+ void OnAbout(object sender, System.EventArgs e)
+ {
+ Form about=new About();
+
+ about.ShowDialog(this);
+ }
+
+ void OnExport(object sender, System.EventArgs e)
+ {
+ SaveFileDialog fsel=new SaveFileDialog();
+
+ string ext=m_plugin.ExportExtension;
+
+ fsel.FileName=m_exportPath;
+ fsel.Filter="Exported files (*."+ext+")|*."+ext+"|All files (*.*)|*.*";
+ fsel.FilterIndex=1;
+
+ if(fsel.ShowDialog()==DialogResult.OK)
+ {
+ GetEdit();
+
+ m_exportPath=fsel.FileName;
+
+ try
+ {
+ m_plugin.Export(m_exportPath,m_sprite);
+ }
+ catch (IOException ex)
+ {
+ Util.Error(m_path,"Error writing file:\n"+ex.Message);
+ return;
+ }
+ catch (Exception ex)
+ {
+ Util.Error("Problem exporting sprites:\n"+ex.Message);
+ }
+ }
+
+ }
+
+ void OnConfig(object sender, System.EventArgs e)
+ {
+ m_plugin.Config.Settings(this);
+ }
+
+ void OnProcessOne(object sender, System.EventArgs e)
+ {
+ m_plugin.Process.Single(m_editor.Sprite);
+ }
+
+ void OnProcessAll(object sender, System.EventArgs e)
+ {
+ // TODO: Get sprite
+ m_plugin.Process.All(m_sprite);
+ }
+
+ void OnFormClosing(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ if (m_sprite.Changed && !Util.YesNo("Lose current edits?"))
+ {
+ e.Cancel=true;
+ }
+ }
+
+ void OnSprite(object sender, System.EventArgs e)
+ {
+ // Cheap, I know...
+ //
+ if (m_blockValue)
+ {
+ return;
+ }
+
+ GetEdit();
+ m_index=Convert.ToInt32(m_spriteNo.Value)-1;
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnAddSprite(object sender, System.EventArgs e)
+ {
+ m_sprite.Add(new Sprite("",m_plugin.AllowedSizes[0],m_plugin.MaxColours));
+ UpdateSpriteCount();
+ CheckCommonPal();
+ }
+
+ void OnInsertSprite(object sender, System.EventArgs e)
+ {
+ GetEdit();
+ m_sprite.Insert(m_index,
+ new Sprite("",m_plugin.AllowedSizes[0],m_plugin.MaxColours));
+ UpdateSpriteCount();
+ CheckCommonPal();
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnDeleteSprite(object sender, System.EventArgs e)
+ {
+ m_sprite.RemoveAt(m_index);
+ UpdateSpriteCount();
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnRevertSprite(object sender, System.EventArgs e)
+ {
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnDuplicateSprite(object sender, System.EventArgs e)
+ {
+ GetEdit();
+
+ for(int i=m_index;i<m_index+m_duplicateCount.Value;i++)
+ {
+ if (i==m_sprite.Count-1)
+ {
+ m_sprite.Add(new Sprite(m_sprite[i]));
+ }
+ else
+ {
+ m_sprite.Insert(i+1,new Sprite(m_sprite[i]));
+ }
+
+ m_sprite[i+1].Name=Util.NextName(m_sprite[i].Name);
+ }
+
+ UpdateSpriteCount();
+ CheckCommonPal();
+ }
+
+ void OnClear(object sender, System.EventArgs e)
+ {
+ GetEdit();
+
+ if (m_applyAll.Checked)
+ {
+ foreach (Sprite s in m_sprite)
+ {
+ s.Clear();
+ }
+ }
+ else
+ {
+ m_sprite[m_index].Clear();
+ }
+
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnHorizontalMirror(object sender, System.EventArgs e)
+ {
+ GetEdit();
+
+ if (m_applyAll.Checked)
+ {
+ foreach (Sprite s in m_sprite)
+ {
+ s.MirrorHorizontal();
+ }
+ }
+ else
+ {
+ m_sprite[m_index].MirrorHorizontal();
+ }
+
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnVerticalMirror(object sender, System.EventArgs e)
+ {
+ GetEdit();
+
+ if (m_applyAll.Checked)
+ {
+ foreach (Sprite s in m_sprite)
+ {
+ s.MirrorVertical();
+ }
+ }
+ else
+ {
+ m_sprite[m_index].MirrorVertical();
+ }
+
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnLeftScroll(object sender, System.EventArgs e)
+ {
+ Scroll(-1,0);
+ }
+
+ void OnRightScroll(object sender, System.EventArgs e)
+ {
+ Scroll(1,0);
+ }
+
+ void OnUpScroll(object sender, System.EventArgs e)
+ {
+ Scroll(0,-1);
+ }
+
+ void OnDownScroll(object sender, System.EventArgs e)
+ {
+ Scroll(0,1);
+ }
+
+ void OnRotateLeft(object sender, System.EventArgs e)
+ {
+ GetEdit();
+
+ if (m_applyAll.Checked)
+ {
+ foreach (Sprite s in m_sprite)
+ {
+ s.RotateLeft();
+ }
+ }
+ else
+ {
+ m_sprite[m_index].RotateLeft();
+ }
+
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ void OnRotateRight(object sender, System.EventArgs e)
+ {
+ GetEdit();
+
+ if (m_applyAll.Checked)
+ {
+ foreach (Sprite s in m_sprite)
+ {
+ s.RotateRight();
+ }
+ }
+ else
+ {
+ m_sprite[m_index].RotateRight();
+ }
+
+ m_editor.Sprite=new Sprite(m_sprite[m_index]);
+ }
+
+ }
+}