Rewritten tile properties code to store tile attributes in same way as the game or...
authorMiloš Klouček <m.kloucek.m@atlas.cz>
Sun, 26 Oct 2008 17:53:00 +0000 (17:53 +0000)
committerMiloš Klouček <m.kloucek.m@atlas.cz>
Sun, 26 Oct 2008 17:53:00 +0000 (17:53 +0000)
SVN-Revision: 5808

tools/tilemanager/Application.cs
tools/tilemanager/Tile.cs
tools/tilemanager/tiler.glade

index a8fe0a9..2b0c5ae 100644 (file)
@@ -396,15 +396,15 @@ 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 == SlopeCheckButton)
-                tile.Slope = SlopeCheckButton.Active;
+                tile.SetAttribute(Attribute.SLOPE, SlopeCheckButton.Active);
             if(sender == HiddenCheckButton)
                 tile.Hidden = HiddenCheckButton.Active;
             if(sender == DontUseCheckButton)
@@ -452,11 +452,11 @@ 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);
+                SlopeCheckButton.Active = tile.HasAttribute(Attribute.SLOPE);
                 HiddenCheckButton.Active = tile.Hidden;
                 DontUseCheckButton.Active = tile.ID == -1;
                 DataEntry.Text = tile.Data.ToString();
index d85d9ed..d03a34b 100644 (file)
@@ -9,30 +9,74 @@ public class ImageRegion {
     public Rectangle Region;
 }
 
+public class Attribute {
+       /// <summary>solid tile that is indestructible by Tux</summary>
+       public const int SOLID     = 0x0001;
+       /// <summary>uni-directional solid tile</summary>
+       public const int UNISOLID  = 0x0002;
+       /// <summary>a brick that can be destroyed by jumping under it</summary>
+       public const int BRICK     = 0x0004;
+       /// <summary>the level should be finished when touching a goaltile.</summary>
+       /// <remarks>
+       /// if <see cref="Data">data</see> is 0 then the endsequence should be
+       /// triggered, if <see cref="Data">data</see> is 1 then we can finish
+       /// the level instantly.
+       /// </remarks>
+       public const int GOAL      = 0x0008;
+       /// <summary>slope tile</summary>
+       public const int SLOPE     = 0x0010;
+       /// <summary>Bonusbox, content is stored in <see cref="Data">data</see></summary>
+       public const int FULLBOX   = 0x0020;
+       /// <summary>Tile is a coin</summary>
+       public const int COIN      = 0x0040;
+       /// <summary>an ice brick that makes tux sliding more than usual</summary>
+       public const int ICE       = 0x0100;
+       /// <summary>a water tile in which tux starts to swim</summary>
+       public const int WATER     = 0x0200;
+       /// <summary>a tile that hurts the player if he touches it</summary>
+       public const int HURTS     = 0x0400;
+       /// <summary>for lava: WATER, HURTS, FIRE</summary>
+       public const int FIRE      = 0x0800;
+
+
+       // TODO: Find out why are worldmap tile attributes stored in data(s)
+       // worldmap flags
+       public const int WORLDMAP_NORTH = 0x0001;
+       public const int WORLDMAP_SOUTH = 0x0002;
+       public const int WORLDMAP_EAST  = 0x0004;
+       public const int WORLDMAP_WEST  = 0x0008;
+
+       public const int WORLDMAP_STOP  = 0x0010;
+}
+
 public class Tile {
-    public int ID;
-    public bool Solid;
-    public bool UniSolid;
-    public bool Ice;
-    public bool Water;
-    public bool Slope;
-    public bool Hidden;
-    public bool Hurts;
-    public bool FullBox;
-    public bool Brick;
-    public bool Coin;
-    public bool Goal;
-    public int NextTile;
-    public int Data;
-    public float AnimFps;
-    public string EditorImage;
-    public ArrayList Images = new ArrayList();
-
-    public Tile() {
-        ID = -1;
-        NextTile = -1;
-        AnimFps = 1;
-    }
+       public int ID;
+       public bool Hidden;
+       public int NextTile;
+       public int Attributes;
+       public int Data;
+       public float AnimFps;
+       public string EditorImage;
+       public ArrayList Images = new ArrayList();
+
+       public Tile() {
+               ID = -1;
+               NextTile = -1;
+               AnimFps = 1;
+       }
+
+       public bool HasAttribute (int Attrib)
+       {
+               return (Attributes & Attrib) != 0;
+       }
+
+       public void SetAttribute (int Attrib, bool Value)
+       {
+               if (Value)
+                       Attributes |= Attrib;
+               else
+                       Attributes &= (~Attrib);        //NOTE: "~" stands for bitwise negation
+       }
 
     public void Write(LispWriter writer) {
         writer.StartList("tile");
@@ -57,30 +101,31 @@ public class Tile {
             Console.WriteLine("no images on tile " + ID);
         }
 
-        if(Solid)
+        if(HasAttribute(Attribute.SOLID))
             writer.Write("solid", true);
-        if(UniSolid)
+        if(HasAttribute(Attribute.UNISOLID))
             writer.Write("unisolid", true);
-        if(Ice)
+        if(HasAttribute(Attribute.ICE))
             writer.Write("ice", true);
-        if(Water)
+        if(HasAttribute(Attribute.WATER))
             writer.Write("water", true);
-        if(Slope)
+        if(HasAttribute(Attribute.SLOPE))
             writer.Write("slope-type", Data);
-        if(Hurts)
+        if(HasAttribute(Attribute.HURTS))
             writer.Write("hurts", true);
-        if(Hidden)
-            writer.Write("hidden", true);
-        if(Coin)
+        if(HasAttribute(Attribute.COIN))
             writer.Write("coin", true);
-        if(FullBox)
+        if(HasAttribute(Attribute.FULLBOX))
             writer.Write("fullbox", true);
-        if(Brick)
+        if(HasAttribute(Attribute.BRICK))
             writer.Write("brick", true);
+        if(HasAttribute(Attribute.GOAL))
+            writer.Write("goal", true);
+
+        if(Hidden)
+            writer.Write("hidden", true);
         if(NextTile >= 0)
             writer.Write("next-tile", NextTile);
-        if(Goal)
-            writer.Write("goal", true);
         if(EditorImage != null)
             writer.Write("editor-images", EditorImage);
         if(Data != 0)
@@ -111,48 +156,48 @@ public class Tile {
                     case "editor-images":
                         EditorImage = parser.StringValue;
                         break;
+                    case "anim-fps":
+                        AnimFps = parser.FloatValue;
+                        break;
+                    case "data":
+                        Data = parser.IntegerValue;
+                        break;
+                    case "next-tile":
+                        NextTile = parser.IntegerValue;
+                        break;
+                    case "hidden":
+                        Hidden = parser.BoolValue;
+                        break;
                     case "solid":
-                        Solid = parser.BoolValue;
+                        SetAttribute(Attribute.SOLID, parser.BoolValue);
                         break;
                     case "unisolid":
-                        UniSolid = parser.BoolValue;
+                        SetAttribute(Attribute.UNISOLID, parser.BoolValue);
                         break;
                     case "ice":
-                        Ice = parser.BoolValue;
+                        SetAttribute(Attribute.ICE, parser.BoolValue);
                         break;
                     case "water":
-                        Water = parser.BoolValue;
+                        SetAttribute(Attribute.WATER, parser.BoolValue);
                         break;
                     case "slope-type":
-                        Slope = true;
+                        SetAttribute(Attribute.SLOPE, true);
                         Data = parser.IntegerValue;
                         break;
-                    case "anim-fps":
-                        AnimFps = parser.FloatValue;
-                        break;
                     case "hurts":
-                        Hurts = parser.BoolValue;
-                        break;
-                    case "hidden":
-                        Hidden = parser.BoolValue;
-                        break;
-                    case "data":
-                        Data = parser.IntegerValue;
-                        break;
-                    case "next-tile":
-                        NextTile = parser.IntegerValue;
+                        SetAttribute(Attribute.HURTS, parser.BoolValue);
                         break;
                     case "brick":
-                        Brick = parser.BoolValue;
+                        SetAttribute(Attribute.BRICK, parser.BoolValue);
                         break;
                     case "fullbox":
-                        FullBox = parser.BoolValue;
+                        SetAttribute(Attribute.FULLBOX, parser.BoolValue);
                         break;
                     case "coin":
-                        Coin = parser.BoolValue;
+                        SetAttribute(Attribute.COIN, parser.BoolValue);
                         break;
                     case "goal":
-                        Goal = parser.BoolValue;
+                        SetAttribute(Attribute.GOAL, parser.BoolValue);
                         break;
                     default:
                         Console.WriteLine("Unknown tile element " + symbol);
index 8a0b330..9fcb687 100644 (file)
                  <property name="can_focus">True</property>
                  <property name="climb_rate">1</property>
                  <property name="digits">0</property>
-                 <property name="numeric">False</property>
+                 <property name="numeric">True</property>
                  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
                  <property name="snap_to_ticks">False</property>
                  <property name="wrap">False</property>
-                 <property name="adjustment">1 0 100 1 10 10</property>
+                 <property name="adjustment">1 1 65535 1 10 10</property>
                </widget>
                <packing>
                  <property name="padding">5</property>