From 89634be9afb1e7886af06659d733b60f365b9309 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Klou=C4=8Dek?= Date: Fri, 8 Aug 2008 19:19:53 +0000 Subject: [PATCH] Updated tilemanager to make it working with current libraries, by now works only for older tileset files without new disk-inexpensive way of describing "more tiles in a picture" No cave hiding... SVN-Revision: 5723 --- tools/tilemanager/Application.cs | 133 ++++++++++++++++++++++++--------------- tools/tilemanager/Makefile | 2 +- tools/tilemanager/TileSet.cs | 20 +++++- tools/tilemanager/tiler.glade | 6 +- 4 files changed, 105 insertions(+), 56 deletions(-) diff --git a/tools/tilemanager/Application.cs b/tools/tilemanager/Application.cs index 3f2f36186..dfc1bed04 100644 --- a/tools/tilemanager/Application.cs +++ b/tools/tilemanager/Application.cs @@ -89,25 +89,30 @@ public class Application { MainLayout.PackStart(AppBar, false, false, 0); AppBar.Show(); - TileGroupComboBox.Entry.Activated - += new EventHandler (OnTileGroupComboBoxEntryActivated); - MainWindow.Show(); } - private void OnOpen(object o, EventArgs e) { - FileSelection selection = new FileSelection("Select TileSet"); - selection.OkButton.Clicked += new EventHandler(OnSelectTileSetOk); - selection.CancelButton.Clicked += new EventHandler(OnSelectImageCancel); - selection.Show(); - } - - private void OnSelectTileSetOk(object o, EventArgs e) { - FileSelection selection = ((FileSelection.FSButton) o).FileSelection; - string file = selection.Filename; - selection.Destroy(); - - LoadTileSet(file); + protected void OnOpen(object o, EventArgs e) { + FileChooserDialog fileChooser = new FileChooserDialog("Select TileSet", MainWindow, FileChooserAction.Open, new object[] {}); + + 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(); + filter.Name = "Supertux tilesets"; + filter.AddPattern("*.strf"); + fileChooser.AddFilter( filter ); + Gtk.FileFilter all = new Gtk.FileFilter(); + all.Name = "All Files"; + all.AddPattern("*"); + fileChooser.AddFilter( all ); + int result = fileChooser.Run(); + fileChooser.Hide(); + + if(result != (int) ResponseType.Ok) + return; + + LoadTileSet(fileChooser.Filename); } private void LoadTileSet(string file) { @@ -126,24 +131,32 @@ public class Application { FillTileList(); } - private void OnImportImage(object o, EventArgs e) { - FileSelection selection = new FileSelection("Select ImageFile"); - selection.OkButton.Clicked += new EventHandler(OnSelectImageOk); - selection.CancelButton.Clicked += new EventHandler(OnSelectImageCancel); - selection.Show(); - } + protected void OnImportImage(object o, EventArgs e) { + FileChooserDialog fileChooser = new FileChooserDialog("Select ImageFile", MainWindow, FileChooserAction.Open, new object[] {}); - private void OnSelectImageCancel(object o, EventArgs args) { - FileSelection selection = ((FileSelection.FSButton) o).FileSelection; - selection.Destroy(); - } + fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); + fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok); + fileChooser.DefaultResponse = Gtk.ResponseType.Ok; + Gtk.FileFilter all = new Gtk.FileFilter(); + all.Name = "All Files"; + all.AddPattern("*"); + fileChooser.AddFilter( all ); + int result = fileChooser.Run(); + fileChooser.Hide(); - private void OnSelectImageOk(object o, EventArgs args) { - FileSelection selection = ((FileSelection.FSButton) o).FileSelection; - string file = selection.Filename; - selection.Destroy(); + if(result != (int) ResponseType.Ok) + return; - ChangeImage(new FileInfo(file).Name); + string file = fileChooser.Filename; + string trim = tilesetdir + "/"; + + if (!file.StartsWith(trim)){ + Console.WriteLine( + "Imported file must be located inside tileset directory"); + return; + } + + ChangeImage(file.TrimStart(trim.ToCharArray())); int startid = tileset.Tiles.Count; for(int y = 0; y < TilesY; ++y) { @@ -219,28 +232,38 @@ public class Application { DrawingArea.QueueResize(); } - private void OnSave(object o, EventArgs e) { - tileset.Write(tilesetfile); + 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 + tileset.Write(tilesetfile); + } + + protected void OnQuit(object o, EventArgs e) { + Gtk.Application.Quit(); } - private void OnQuit(object o, EventArgs e) { + protected void OnDeleteQuit(object o, DeleteEventArgs e) { Gtk.Application.Quit(); } - private void OnAbout(object o, EventArgs e) { + protected void OnAbout(object o, EventArgs e) { + Console.WriteLine( + "There is no about dialog yet..."); } - private void OnRemapTiles(object o, EventArgs e) { + protected void OnRemapTiles(object o, EventArgs e) { AppBar.SetPrompt("Start-ID:", true); } - private void OnCreateTileGroup(object o, EventArgs e) { + protected void OnCreateTileGroup(object o, EventArgs e) { } - private void OnRenameTileGroup(object o, EventArgs e) { + protected void OnRenameTileGroup(object o, EventArgs e) { } - private void OnAppBarUserResponse(object o, EventArgs e) { + protected void OnAppBarUserResponse(object o, EventArgs e) { try { if(AppBar.Response == null || AppBar.Response == "" || Tiles == null) @@ -275,7 +298,7 @@ public class Application { } } - private void OnDrawingAreaExpose(object o, ExposeEventArgs e) { + protected void OnDrawingAreaExpose(object o, ExposeEventArgs e) { if(pixbuf == null) return; @@ -295,7 +318,7 @@ public class Application { e.RetVal = false; } - private void OnDrawingAreaButtonPress(object o, ButtonPressEventArgs e) { + protected void OnDrawingAreaButtonPress(object o, ButtonPressEventArgs e) { if(SelectionArray == null) return; @@ -315,17 +338,17 @@ public class Application { SelectionArrayChanged(); } - private void OnDrawingAreaMotionNotify(object i, MotionNotifyEventArgs e) { + protected void OnDrawingAreaMotionNotify(object i, MotionNotifyEventArgs e) { if(!selecting) return; select((int) e.Event.X, (int) e.Event.Y); } - private void OnDrawingAreaButtonRelease(object o, ButtonPressEventArgs e) { + protected void OnDrawingAreaButtonRelease(object o, ButtonPressEventArgs e) { selecting = false; } - private void OnCheckButtonToggled(object sender, EventArgs e) { + protected void OnCheckButtonToggled(object sender, EventArgs e) { if(toggling) return; foreach(Tile tile in Selection) { @@ -346,7 +369,7 @@ public class Application { } } - private void OnEntryChanged(object sender, EventArgs e) { + protected void OnEntryChanged(object sender, EventArgs e) { if(toggling) return; foreach(Tile tile in Selection) { @@ -357,7 +380,7 @@ public class Application { tile.Data = Int32.Parse(DataEntry.Text); if(sender == AnimFpsEntry) tile.AnimFps = Single.Parse(AnimFpsEntry.Text); - } catch(Exception exception) { + } catch(Exception) { // ignore parse errors for now... } } @@ -396,7 +419,7 @@ public class Application { DataEntry.Text = tile.Data.ToString(); AnimFpsEntry.Text = tile.AnimFps.ToString(); IDEntry.Text = tile.ID.ToString(); - IDEntry.Editable = true; + IDEntry.IsEditable = true; first = false; if(tile.Images.Count > 0) { @@ -404,7 +427,7 @@ public class Application { } } else { IDEntry.Text += "," + tile.ID.ToString(); - IDEntry.Editable = false; + IDEntry.IsEditable = false; if(tile.Images.Count > 0 && ((ImageRegion) tile.Images[0]).ImageFile != nextimage) { nextimage = ""; @@ -433,7 +456,13 @@ public class Application { } } else { foreach(int id in selectedgroup.Tiles) { - Tile tile = (Tile) tileset.Tiles[id]; + Tile tile; + if (id >= tileset.Tiles.Count){ + Console.WriteLine("Tile ID is above Tiles.Count: " + id.ToString()); + continue; + } else { + tile = (Tile) tileset.Tiles[id]; + } if(tile == null) { Console.WriteLine("tilegroup contains deleted tile"); continue; @@ -457,12 +486,12 @@ public class Application { //submenu.Add(new MenuItem(tilegroup)); } TileGroupComboBox.PopdownStrings = groups; - TileGroupComboBox.Entry.Editable = false; + TileGroupComboBox.Entry.IsEditable = false; //AddTileGroupMenu.Submenu = submenu; } - private void OnTileGroupComboBoxEntryActivated(object o, EventArgs args) { + protected void OnTileGroupComboBoxEntryActivated(object o, EventArgs args) { if(TileGroupComboBox.Entry.Text == "All") { selectedgroup = null; } else { @@ -476,7 +505,7 @@ public class Application { FillTileList(); } - private void OnTileListCursorChanged(object sender, EventArgs e) { + protected void OnTileListCursorChanged(object sender, EventArgs e) { TreeModel model; TreePath[] selectpaths = TileList.Selection.GetSelectedRows(out model); diff --git a/tools/tilemanager/Makefile b/tools/tilemanager/Makefile index 948bebae3..642e9c8da 100644 --- a/tools/tilemanager/Makefile +++ b/tools/tilemanager/Makefile @@ -1,6 +1,6 @@ GOAL=tilemanager.exe SOURCES=$(wildcard *.cs) -CSFLAGS=-debug -pkg:gtk-sharp -pkg:glade-sharp -pkg:gnome-sharp -r:System.Drawing +CSFLAGS=-debug -pkg:gtk-sharp-2.0 -pkg:glade-sharp-2.0 -pkg:gnome-sharp-2.0 -r:System.Drawing RESOURCES=tiler.glade CSFLAGS+=$(foreach file,$(RESOURCES),-resource:$(file) ) diff --git a/tools/tilemanager/TileSet.cs b/tools/tilemanager/TileSet.cs index 831ee96d3..071876098 100644 --- a/tools/tilemanager/TileSet.cs +++ b/tools/tilemanager/TileSet.cs @@ -44,6 +44,15 @@ public class TileGroup { } public class TileSet { + private bool tooNew = false; + + /// Whether version of tileset file is too new + public bool TooNew { + get { + return tooNew; + } + } + public ArrayList Tiles = new ArrayList(); public ArrayList TileGroups = new ArrayList(); @@ -90,6 +99,7 @@ public class TileSet { } public void ParseTiles(Lisp.Parser parser) { + tooNew = false; int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d && parser.Type != Parser.LispType.START_LIST) { @@ -118,7 +128,15 @@ public class TileSet { Tiles.Add(null); Tiles[tile.ID] = tile; break; - default: + case "tiles": + SkipList(parser); + tooNew = true; + Console.WriteLine( + "Warning: new syntax of \"More tiles in one image\" file isn't currently supported"); + Console.WriteLine( + "And this means: YOU WON'T BE ABLE TO SAVE YOUR CHANGES !!!"); + break; + default: throw new Exception("Unexpected listentry: " + parser.SymbolValue); } diff --git a/tools/tilemanager/tiler.glade b/tools/tilemanager/tiler.glade index 94eead6d6..e25e4b1e0 100644 --- a/tools/tilemanager/tiler.glade +++ b/tools/tilemanager/tiler.glade @@ -19,7 +19,7 @@ False GDK_WINDOW_TYPE_HINT_NORMAL GDK_GRAVITY_NORTH_WEST - + @@ -202,7 +202,7 @@ False False True - + @@ -233,6 +233,8 @@ True * False + + -- 2.11.0