X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=tools%2Ftilemanager%2FApplication.cs;h=deaf73b967a864a1fe80c73df71c9d711c68fce0;hb=2ad3ecbc14b77d373c796ad04d6389489666cc01;hp=45922006f9c95b89bab1b3baa5c44da9db547d9b;hpb=8c92d7d5c03b857226fdd07f94b492187a12bdcb;p=supertux.git diff --git a/tools/tilemanager/Application.cs b/tools/tilemanager/Application.cs index 45922006f..deaf73b96 100644 --- a/tools/tilemanager/Application.cs +++ b/tools/tilemanager/Application.cs @@ -1,17 +1,20 @@ +// $Id$ using System; using System.IO; using System.Collections; using Gtk; using Gdk; -using Gnome; using Glade; public class Application { [Glade.Widget] private Gtk.Window MainWindow; [Glade.Widget] + private Gtk.CheckMenuItem useNewSyntax; + [Glade.Widget] private Gtk.DrawingArea DrawingArea; [Glade.Widget] + //Flags CheckButtons private Gtk.CheckButton SolidCheckButton; [Glade.Widget] private Gtk.CheckButton UniSolidCheckButton; @@ -20,28 +23,42 @@ public class Application { [Glade.Widget] private Gtk.CheckButton WaterCheckButton; [Glade.Widget] + private Gtk.CheckButton HurtsCheckButton; + [Glade.Widget] + private Gtk.CheckButton FireCheckButton; + [Glade.Widget] + private Gtk.CheckButton BrickCheckButton; + [Glade.Widget] + private Gtk.CheckButton CoinCheckButton; + [Glade.Widget] + private Gtk.CheckButton FullBoxCheckButton; + [Glade.Widget] private Gtk.CheckButton SlopeCheckButton; [Glade.Widget] + private Gtk.CheckButton GoalCheckButton; + [Glade.Widget] private Gtk.CheckButton DontUseCheckButton; [Glade.Widget] private Gtk.CheckButton HiddenCheckButton; [Glade.Widget] + private Gtk.Entry DataEntry; [Glade.Widget] private Gtk.Entry AnimFpsEntry; [Glade.Widget] private Gtk.Entry IDEntry; [Glade.Widget] - private Gnome.AppBar AppBar; - [Glade.Widget] - private Gtk.VBox MainLayout; - [Glade.Widget] private Gtk.TreeView TileList; [Glade.Widget] private Gtk.Combo TileGroupComboBox; [Glade.Widget] private Gtk.MenuItem AddTileGroupMenu; + [Glade.Widget] + private Gtk.Dialog RemapDialog; + [Glade.Widget] + private Gtk.SpinButton RD_spinButton; + private string tilesetdir; private string tilesetfile; private TileSet tileset; @@ -59,7 +76,7 @@ public class Application { private Gdk.Pixbuf pixbuf; public static int Main(string[] args) { - Program kit = new Program("tiler", "0.0.1", Modules.UI, args); + Gtk.Application.Init(); Application app = new Application(); @@ -67,7 +84,7 @@ public class Application { if(args.Length == 1) app.LoadTileSet(args[0]); - kit.Run(); + Gtk.Application.Run(); return 0; } @@ -75,20 +92,13 @@ public class Application { Glade.XML gxml = new Glade.XML(null, "tiler.glade", null, null); gxml.Autoconnect(this); - if(MainWindow == null || DrawingArea == null || AppBar == null) + if(MainWindow == null || DrawingArea == null || RemapDialog == null) throw new Exception("some widgets not found"); DrawingArea.AddEvents((int) Gdk.EventMask.ButtonPressMask); DrawingArea.AddEvents((int) Gdk.EventMask.ButtonReleaseMask); DrawingArea.AddEvents((int) Gdk.EventMask.ButtonMotionMask); - // libglade missed interactivity property :-/ - MainLayout.Remove(AppBar); - AppBar = new AppBar(true, true, PreferencesType.Always); - AppBar.UserResponse += new EventHandler(OnAppBarUserResponse); - MainLayout.PackStart(AppBar, false, false, 0); - AppBar.Show(); - MainWindow.Show(); } @@ -98,9 +108,19 @@ public class Application { fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok); fileChooser.DefaultResponse = Gtk.ResponseType.Ok; - Gtk.FileFilter filter = new Gtk.FileFilter(); + Gtk.FileFilter filter; + filter = new Gtk.FileFilter(); filter.Name = "Supertux tilesets"; filter.AddPattern("*.strf"); + filter.AddPattern("*.stgt"); + fileChooser.AddFilter( filter ); + filter = new Gtk.FileFilter(); + filter.Name = "Supertux 0.1.x tilesets"; + filter.AddPattern("*.stgt"); + fileChooser.AddFilter( filter ); + filter = new Gtk.FileFilter(); + filter.Name = "Supertux 0.3.x tilesets"; + filter.AddPattern("*.strf"); fileChooser.AddFilter( filter ); Gtk.FileFilter all = new Gtk.FileFilter(); all.Name = "All Files"; @@ -129,6 +149,11 @@ public class Application { SelectionChanged(); FillTileGroupComboBox(); FillTileList(); + + useNewSyntax.Active = tileset.IsNew; + if (tileset.IsNew) + Console.WriteLine("Warning: new syntax of 0.3.x files \"More tiles in one image\" isn't currently supported for WRITING"); + } protected void OnImportImage(object o, EventArgs e) { @@ -166,7 +191,7 @@ public class Application { tile.ID = startid + i; ImageRegion region = new ImageRegion(); region.ImageFile = currentimage; - region.Region = new System.Drawing.Rectangle(x*32, y*32, 32, 32); + region.Region = new System.Drawing.Rectangle(x*TileSet.TILE_WIDTH, y*TileSet.TILE_HEIGHT, TileSet.TILE_WIDTH, TileSet.TILE_HEIGHT); tile.Images.Add(region); if(Tiles[i] != null) { Console.WriteLine( @@ -188,15 +213,15 @@ public class Application { } try { pixbuf = new Pixbuf(tilesetdir + "/" + file); - if(pixbuf.Width % 32 != 0 || pixbuf.Height % 32 != 0) + if(pixbuf.Width % TileSet.TILE_WIDTH != 0 || pixbuf.Height % TileSet.TILE_HEIGHT != 0) Console.WriteLine("Warning: Image Width or Height is not a multiple of 32"); } catch(Exception e) { ShowException(e); return; } currentimage = new FileInfo(file).Name; - TilesX = pixbuf.Width / 32; - TilesY = pixbuf.Height / 32; + TilesX = pixbuf.Width / TileSet.TILE_WIDTH; + TilesY = pixbuf.Height / TileSet.TILE_HEIGHT; SelectionArray = new bool[TilesX * TilesY]; Tiles = new Tile[TilesX * TilesY]; @@ -208,8 +233,8 @@ public class Application { continue; ImageRegion region = (ImageRegion) tile.Images[0]; if(region.ImageFile == currentimage) { - int px = region.Region.X / 32; - int py = region.Region.Y / 32; + int px = region.Region.X / TileSet.TILE_WIDTH; + int py = region.Region.Y / TileSet.TILE_HEIGHT; int i = py*TilesX+px; if(i < 0 || i >= Tiles.Length) { Console.WriteLine("Invalid Imageregion at tile " + @@ -218,7 +243,7 @@ public class Application { } if(Tiles[i] != null) { Console.WriteLine("Multiple tiles for region " + - px*32 + " , " + py*32); + px*TileSet.TILE_WIDTH + " , " + py*TileSet.TILE_HEIGHT); continue; } Tiles[i] = tile; @@ -233,11 +258,14 @@ public class Application { } protected void OnSave(object o, EventArgs e) { - if (tileset.TooNew) - Console.WriteLine( - "Sorry, the file you are editing is too new, there will be huge data loss if you save this."); - else + if (tileset.IsNew && useNewSyntax.Active) { + MessageDialog dialog = new MessageDialog(MainWindow, DialogFlags.Modal | DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, + "Sorry, the file you are editing is too new and 0.3.x syntax is not supported yet."); + dialog.Run(); + dialog.Destroy(); + } else { tileset.Write(tilesetfile); + } } protected void OnQuit(object o, EventArgs e) { @@ -249,40 +277,71 @@ public class Application { } protected void OnAbout(object o, EventArgs e) { - Console.WriteLine( - "There is no about dialog yet..."); +// string[] authors = new string[]{ +// "", +// }; + + Gtk.AboutDialog dialog = new Gtk.AboutDialog(); +// dialog.Icon = ; + dialog.ProgramName = "SuperTux Tiler"; + dialog.Version = "0.0.3"; + dialog.Comments = "A tileset editor for SuperTux 0.1.x"; +// dialog.Authors = authors; + dialog.Copyright = "Copyright (c) 2006 SuperTux Devel Team"; + dialog.License = + "This program is free software; you can redistribute it and/or modify" + Environment.NewLine + + "it under the terms of the GNU General Public License as published by" + Environment.NewLine + + "the Free Software Foundation; either version 2 of the License, or" + Environment.NewLine + + "(at your option) any later version." + Environment.NewLine + + Environment.NewLine + + "This program is distributed in the hope that it will be useful," + Environment.NewLine + + "but WITHOUT ANY WARRANTY; without even the implied warranty of" + Environment.NewLine + + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" + Environment.NewLine + + "GNU General Public License for more details." + Environment.NewLine + + Environment.NewLine + + "You should have received a copy of the GNU General Public License" + Environment.NewLine + + "along with this program; if not, write to the Free Software Foundation, Inc.," + Environment.NewLine + + "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" + Environment.NewLine; + dialog.Website = "http://supertux.lethargik.org/"; + dialog.WebsiteLabel = "SuperTux on the Web"; + dialog.Run(); + dialog.Destroy(); } protected void OnRemapTiles(object o, EventArgs e) { - AppBar.SetPrompt("Start-ID:", true); + if(Tiles == null) + return; + RemapDialog.Show(); } - protected void OnCreateTileGroup(object o, EventArgs e) { + protected void OnRemapDialogCancel(object o, EventArgs e) { + RemapDialog.Hide(); } - protected void OnRenameTileGroup(object o, EventArgs e) { - } - - protected void OnAppBarUserResponse(object o, EventArgs e) { + protected void OnRemapDialogApply(object o, EventArgs e) { + RemapDialog.Hide(); try { - if(AppBar.Response == null || AppBar.Response == "" - || Tiles == null) - return; // remap tiles int id; try { - id = Int32.Parse(AppBar.Response); + id = RD_spinButton.ValueAsInt; } catch(Exception exception) { ShowException(exception); return; } RemapTiles(id); } finally { - AppBar.ClearPrompt(); + RD_spinButton.Value = 1; } } + protected void OnCreateTileGroup(object o, EventArgs e) { + } + + protected void OnRenameTileGroup(object o, EventArgs e) { + } + protected void RemapTiles(int startID) { if(Tiles == null) return; @@ -339,7 +398,7 @@ public class Application { } private void select(int x, int y) { - int tile = y/32 * TilesX + x/32; + int tile = y/TileSet.TILE_HEIGHT * TilesX + x/TileSet.TILE_WIDTH; if(tile < 0 || tile >= SelectionArray.Length) return; @@ -362,15 +421,27 @@ public class Application { return; foreach(Tile tile in Selection) { if(sender == SolidCheckButton) - tile.Solid = SolidCheckButton.Active; + tile.SetAttribute(Attribute.SOLID, SolidCheckButton.Active); if(sender == UniSolidCheckButton) - tile.UniSolid = UniSolidCheckButton.Active; + tile.SetAttribute(Attribute.UNISOLID, UniSolidCheckButton.Active); if(sender == IceCheckButton) - tile.Ice = IceCheckButton.Active; + tile.SetAttribute(Attribute.ICE, IceCheckButton.Active); if(sender == WaterCheckButton) - tile.Water = WaterCheckButton.Active; + tile.SetAttribute(Attribute.WATER, WaterCheckButton.Active); + if(sender == HurtsCheckButton) + tile.SetAttribute(Attribute.HURTS, HurtsCheckButton.Active); + if(sender == FireCheckButton) + tile.SetAttribute(Attribute.FIRE, FireCheckButton.Active); + if(sender == BrickCheckButton) + tile.SetAttribute(Attribute.BRICK, BrickCheckButton.Active); + if(sender == CoinCheckButton) + tile.SetAttribute(Attribute.COIN, CoinCheckButton.Active); + if(sender == FullBoxCheckButton) + tile.SetAttribute(Attribute.FULLBOX, FullBoxCheckButton.Active); if(sender == SlopeCheckButton) - tile.Slope = SlopeCheckButton.Active; + tile.SetAttribute(Attribute.SLOPE, SlopeCheckButton.Active); + if(sender == GoalCheckButton) + tile.SetAttribute(Attribute.GOAL, GoalCheckButton.Active); if(sender == HiddenCheckButton) tile.Hidden = HiddenCheckButton.Active; if(sender == DontUseCheckButton) @@ -418,11 +489,17 @@ public class Application { string nextimage = ""; foreach(Tile tile in Selection) { if(first) { - SolidCheckButton.Active = tile.Solid; - UniSolidCheckButton.Active = tile.UniSolid; - IceCheckButton.Active = tile.Ice; - WaterCheckButton.Active = tile.Water; - SlopeCheckButton.Active = tile.Slope; + SolidCheckButton.Active = tile.HasAttribute(Attribute.SOLID); + UniSolidCheckButton.Active = tile.HasAttribute(Attribute.UNISOLID); + IceCheckButton.Active = tile.HasAttribute(Attribute.ICE); + WaterCheckButton.Active = tile.HasAttribute(Attribute.WATER); + HurtsCheckButton.Active = tile.HasAttribute(Attribute.HURTS); + FireCheckButton.Active = tile.HasAttribute(Attribute.FIRE); + BrickCheckButton.Active = tile.HasAttribute(Attribute.BRICK); + CoinCheckButton.Active = tile.HasAttribute(Attribute.COIN); + FullBoxCheckButton.Active = tile.HasAttribute(Attribute.FULLBOX); + SlopeCheckButton.Active = tile.HasAttribute(Attribute.SLOPE); + GoalCheckButton.Active = tile.HasAttribute(Attribute.GOAL); HiddenCheckButton.Active = tile.Hidden; DontUseCheckButton.Active = tile.ID == -1; DataEntry.Text = tile.Data.ToString();