Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 20th, 2012  |  syntax: C#  |  size: 41.79 KB  |  hits: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Xml;
  9.  
  10. namespace CellChunkGenerator
  11. {
  12.     public enum WallStyle
  13.     {
  14.         None,
  15.         WestWall,
  16.         WestWallTrans,
  17.         WestWindow,
  18.         WestDoorFrame,
  19.         NorthWall,
  20.         NorthWallTrans,
  21.         NorthWindow,
  22.         NorthDoorFrame,
  23.         NorthWestCorner,
  24.         NorthWestCornerTrans,
  25.         SouthEastCorner,
  26.     }
  27.     public enum RoofStyle
  28.     {
  29.         None,
  30.         WestRoofB,
  31.         WestRoofM,
  32.         WestRoofT,
  33.     }
  34.     public enum TileBlockStyle
  35.     {
  36.         None,
  37.         Solid,
  38.         SolidTransparent,
  39.     }
  40.  
  41.     public enum Direction
  42.     {
  43.         None,
  44.         N,
  45.         NE,
  46.         E,
  47.         SE,
  48.         S,
  49.         SW,
  50.         W,
  51.         NW,
  52.     }
  53.  
  54.     public enum StairStyle
  55.     {
  56.         None,
  57.         BottomW,
  58.         MiddleW,
  59.         TopW,
  60.         BottomN,
  61.         MiddleN,
  62.         TopN,
  63.     }
  64.  
  65.     public enum DoorStyle
  66.     {
  67.         None,
  68.         North,
  69.         West,
  70.     }
  71.  
  72.     public enum LightPolyStyle
  73.     {
  74.         None,
  75.         WallW,
  76.         WallN,
  77.     }
  78.    
  79.     public class UIProperties
  80.     {
  81.  
  82.         [DescriptionAttribute("Light style"),
  83.             CategoryAttribute("Light Settings"),
  84.             DefaultValueAttribute(LightPolyStyle.None)]
  85.         public LightPolyStyle LightPolyStyle { get; set; }
  86.         [DescriptionAttribute("Climb Sheet North"),
  87.               CategoryAttribute("Sheet Settings"),
  88.               DefaultValueAttribute(false)]
  89.         public bool ClimbSheetN { get; set; }
  90.         [DescriptionAttribute("Climb Sheet West"),
  91.               CategoryAttribute("Sheet Settings"),
  92.               DefaultValueAttribute(false)]
  93.         public bool ClimbSheetW { get; set; }
  94.         [DescriptionAttribute("Is tile collidable from the north?"),
  95.             CategoryAttribute("Collision Settings"),
  96.             DefaultValueAttribute(false)]
  97.         public bool CollideNorth { get; set; }
  98.         [DescriptionAttribute("Is tile collidable from the west?"),
  99.             CategoryAttribute("Collision Settings"),
  100.             DefaultValueAttribute(false)]
  101.         public bool CollideWest { get; set; }
  102.         [DescriptionAttribute("Is tile pre-'seen' on the map (aka not starting out black)"),
  103.              CategoryAttribute("Visibility Functions"),
  104.              DefaultValueAttribute(false)]
  105.         public bool PreSeen { get; set; }
  106.         [DescriptionAttribute("Force square tile is on to ambient lighting (useful to get rid of uneven lighting on roofs, for e.g."),
  107.               CategoryAttribute("Lighting Functions"),
  108.               DefaultValueAttribute(false)]
  109.         public bool ForceAmbient { get; set; }
  110.         [DescriptionAttribute("If it is a door what direction is it facing?"),
  111.             CategoryAttribute("Door Functions"),
  112.             DefaultValueAttribute(DoorStyle.None)]
  113.         public DoorStyle Door { get; set; }
  114.         [DescriptionAttribute("If it is a window what direction is it facing?"),
  115.            CategoryAttribute("Window Functions"),
  116.            DefaultValueAttribute(DoorStyle.None)]
  117.         public DoorStyle Window { get; set; }
  118.         [DescriptionAttribute("Smashed Tile Offset (0 == this tile)"),
  119.            CategoryAttribute("Window Functions"),
  120.            DefaultValueAttribute(0)]
  121.         public int SmashedTileOffset { get; set; }
  122.         [DescriptionAttribute("Is window openable?"),
  123.           CategoryAttribute("Window Functions"),
  124.           DefaultValueAttribute(false)]
  125.         public bool WindowLocked { get; set; }
  126.       [DescriptionAttribute("Open Tile Offset (0 == this tile)"),
  127.            CategoryAttribute("Window Functions"),
  128.            DefaultValueAttribute(0)]
  129.         public int OpenTileOffset { get; set; }
  130.         [DescriptionAttribute("If it is a door frame what direction is it facing?"),
  131.             CategoryAttribute("Door Functions"),
  132.        DefaultValueAttribute(DoorStyle.None)]
  133.         public DoorStyle DoorFrame { get; set; }
  134.         [DescriptionAttribute("Is it a water source piped?"),
  135.        CategoryAttribute("Water Functions"),
  136.           DefaultValueAttribute(false)]
  137.         public bool WaterPiped { get; set; }
  138.         [DescriptionAttribute("How many units worth of water is in here? (10 = one bottle)"),
  139.             CategoryAttribute("Water Functions"),
  140.             DefaultValueAttribute(0)]
  141.         public int WaterAmount { get; set; }
  142.         [DescriptionAttribute("How many max units worth of water is in here when filled? (10 = one bottle)"),
  143.             CategoryAttribute("Water Functions"),
  144.             DefaultValueAttribute(0)]
  145.         public int WaterMaxAmount { get; set; }
  146.         [DescriptionAttribute("Can the player / NPCs sleep on the object?"),
  147.             CategoryAttribute("Extra Functions"),
  148.             DefaultValueAttribute(false)]
  149.         public bool IsBed { get; set; }
  150.         [DescriptionAttribute("Hoppable North"),
  151.              CategoryAttribute("Wall Settings"),
  152.              DefaultValueAttribute(false)]
  153.         public bool HoppableN { get; set; }
  154.         [DescriptionAttribute("Hoppable West"),
  155.               CategoryAttribute("Wall Settings"),
  156.               DefaultValueAttribute(false)]
  157.         public bool HoppableW { get; set; }
  158.         [DescriptionAttribute("If it is a wall piece, the type of wall."),
  159.               CategoryAttribute("Wall Settings"),
  160.               DefaultValueAttribute(WallStyle.None)]
  161.         public WallStyle WallStyle { get; set; }
  162.         [DescriptionAttribute("If it is a stair piece, the type of stair."),
  163.             CategoryAttribute("Stair Settings"),
  164.             DefaultValueAttribute(StairStyle.None)]
  165.         public StairStyle StairStyle { get; set; }
  166.         [DescriptionAttribute("If it is a roof piece, the type of roof piece."),
  167.             CategoryAttribute("Roof Settings"),
  168.             DefaultValueAttribute(RoofStyle.None)]
  169.         public RoofStyle RoofStyle { get; set; }
  170.         [DescriptionAttribute("Is there a floor on the tile characters can walk on?"),
  171.             CategoryAttribute("Floor Settings"),
  172.             DefaultValueAttribute(false)]
  173.         public bool IsFloor { get; set; }
  174.         [DescriptionAttribute("Is the tilepiece an indoor tile? (Cuts higher floors if stood on) Only indoor floor tiles need this."),
  175.             CategoryAttribute("Floor Settings"),
  176.             DefaultValueAttribute(true)]
  177.         public bool IsIndoor { get; set; }
  178.         [DescriptionAttribute("Is tile an overlay for a floor piece? (i.e. smooth lit decal)"),
  179.             CategoryAttribute("Floor Settings"),
  180.             DefaultValueAttribute(false)]
  181.         public bool FloorOverlay { get; set; }
  182.         [DescriptionAttribute("If it is an in-tile object, is it collidable / transparent?"),
  183.             CategoryAttribute("Global Settings"),
  184.             DefaultValueAttribute(TileBlockStyle.None)]
  185.         public TileBlockStyle TileBlockStyle { get; set; }
  186.  
  187.         [DescriptionAttribute("Is tile an overlay for a wall piece? (i.e. smooth lit decal)"),
  188.             CategoryAttribute("Wall Settings"),
  189.             DefaultValueAttribute(false)]
  190.         public bool WallOverlay { get; set; }
  191.         [DescriptionAttribute("Orientation of floor height item shelves (None = no shelves)"),
  192.             CategoryAttribute("Shelf Settings"),
  193.             DefaultValueAttribute(Direction.None)]
  194.         public Direction FloorItemShelf { get; set; }
  195.         [DescriptionAttribute("Orientation of floor height item shelves (None = no shelves)"),
  196.             CategoryAttribute("Shelf Settings"),
  197.             DefaultValueAttribute(Direction.None)]
  198.         public Direction TableItemShelf { get; set; }
  199.         [DescriptionAttribute("Orientation of head height item shelves (None = no shelves)"),
  200.             CategoryAttribute("Shelf Settings"),
  201.             DefaultValueAttribute(Direction.None)]
  202.         public Direction HighItemShelf { get; set; }
  203.         [DescriptionAttribute("Name, if any, of the container the tile can store items in."),
  204.             CategoryAttribute("Object Settings"),
  205.             DefaultValueAttribute("")]
  206.         public String ContainerType { get; set; }
  207.         [DescriptionAttribute("Is it a wheeliebin?"),
  208.               CategoryAttribute("Object Settings"),
  209.               DefaultValueAttribute(false)]
  210.         public bool WheelieBin { get; set; }
  211.         public void FromProperties(Dictionary<string, string> properties)
  212.         {
  213.  
  214.  
  215.             if (properties.ContainsKey("WheelieBin"))
  216.             {
  217.                 WheelieBin = true;
  218.             }
  219.  
  220.  
  221.             if (properties.ContainsKey("collideW"))
  222.             {
  223.                 CollideWest = true;
  224.             }
  225.             if (properties.ContainsKey("collideN"))
  226.             {
  227.                 CollideNorth = true;
  228.             }
  229.             if (properties.ContainsKey("climbSheetN"))
  230.             {
  231.                 ClimbSheetN = true;
  232.             }
  233.  
  234.             if (properties.ContainsKey("climbSheetW"))
  235.             {
  236.                 ClimbSheetW = true;
  237.             }
  238.  
  239.             if (properties.ContainsKey("HoppableN"))
  240.             {
  241.                 HoppableN = true;
  242.             }
  243.             if (properties.ContainsKey("HoppableW"))
  244.             {
  245.                 HoppableW = true;
  246.             }
  247.             if (properties.ContainsKey("ForceAmbient"))
  248.             {
  249.                 ForceAmbient = true;
  250.             }
  251.             if (properties.ContainsKey("bed"))
  252.             {
  253.                 IsBed = true;
  254.             }
  255.             if (properties.ContainsKey("PreSeen"))
  256.             {
  257.                 PreSeen = true;
  258.             }
  259.             if (properties.ContainsKey("WindowLocked"))
  260.             {
  261.                 WindowLocked = true;
  262.             }
  263.             if (properties.ContainsKey("SmashedTileOffset"))
  264.             {
  265.                 SmashedTileOffset = Convert.ToInt32(properties["SmashedTileOffset"]);
  266.             }
  267.             if (properties.ContainsKey("OpenTileOffset"))
  268.             {
  269.                 SmashedTileOffset = Convert.ToInt32(properties["OpenTileOffset"]);
  270.             }
  271.             if (properties.ContainsKey("LightPolyStyle"))
  272.             {
  273.                 LightPolyStyle = (LightPolyStyle)Enum.Parse(LightPolyStyle.GetType(), properties["LightPolyStyle"]);
  274.             }
  275.            
  276.             if (properties.ContainsKey("doorN"))
  277.             {
  278.                 Door = DoorStyle.North;
  279.             }
  280.             if (properties.ContainsKey("doorW"))
  281.             {
  282.                 Door = DoorStyle.West;
  283.             }
  284.             if (properties.ContainsKey("windowN"))
  285.             {
  286.                 Window = DoorStyle.North;
  287.             }
  288.             if (properties.ContainsKey("windowW"))
  289.             {
  290.                 Window = DoorStyle.West;
  291.             }
  292.             if (properties.ContainsKey("doorFrN"))
  293.             {
  294.                 DoorFrame = DoorStyle.North;
  295.             }
  296.             if (properties.ContainsKey("doorFrW"))
  297.             {
  298.                 DoorFrame = DoorStyle.West;
  299.             }
  300.            
  301.             if (properties.ContainsKey("waterAmount"))
  302.             {
  303.                 WaterAmount = Convert.ToInt32(properties["waterAmount"]);
  304.             }
  305.             if (properties.ContainsKey("waterMaxAmount"))
  306.             {
  307.                 WaterMaxAmount = Convert.ToInt32(properties["waterMaxAmount"]);
  308.             }
  309.             if (properties.ContainsKey("waterPiped"))
  310.             {
  311.                 WaterPiped = true;
  312.             }
  313.             if (properties.ContainsKey("WestRoofB"))
  314.             {
  315.                 RoofStyle = RoofStyle.WestRoofB;
  316.             }
  317.             else if (properties.ContainsKey("WestRoofM"))
  318.             {
  319.                 RoofStyle = RoofStyle.WestRoofM;
  320.             }
  321.             else if (properties.ContainsKey("WestRoofT"))
  322.             {
  323.                 RoofStyle = RoofStyle.WestRoofT;
  324.             }
  325.             if (properties.ContainsKey("WallOverlay"))
  326.             {
  327.                 WallOverlay = true;
  328.             }
  329.             if (properties.ContainsKey("FloorOverlay"))
  330.             {
  331.                 FloorOverlay = true;
  332.             }
  333.             if (properties.ContainsKey("stairsBW"))
  334.             {
  335.                 StairStyle = StairStyle.BottomW;
  336.             }
  337.             else if (properties.ContainsKey("stairsMW"))
  338.             {
  339.                 StairStyle = StairStyle.MiddleW;
  340.             }
  341.             else if (properties.ContainsKey("stairsTW"))
  342.             {
  343.                 StairStyle = StairStyle.TopW;
  344.             }
  345.             else if (properties.ContainsKey("stairsBN"))
  346.             {
  347.                 StairStyle = StairStyle.BottomN;
  348.             }
  349.             else if (properties.ContainsKey("stairsMN"))
  350.             {
  351.                 StairStyle = StairStyle.MiddleN;
  352.             }
  353.             else if (properties.ContainsKey("stairsTN"))
  354.             {
  355.                 StairStyle = StairStyle.TopN;
  356.             }
  357.             IsIndoor = true;
  358.             if (properties.ContainsKey("windowFW"))
  359.             {
  360.                 WallStyle = WallStyle.WestWindow;
  361.                 properties.Remove("collideW");
  362.             }
  363.             else if (properties.ContainsKey("windowFN"))
  364.             {
  365.                 WallStyle = WallStyle.NorthWindow;
  366.                 properties.Remove("collideN");
  367.             }
  368.             else if (properties.ContainsKey("collideW") && properties.ContainsKey("cutW") && !properties.ContainsKey("collideN") && !properties.ContainsKey("windowFW"))
  369.             {
  370.                 WallStyle = WallStyle.WestWall;
  371.  
  372.             }
  373.             else if (properties.ContainsKey("collideW") && properties.ContainsKey("cutW") && properties.ContainsKey("collideN"))
  374.             {
  375.                 WallStyle = WallStyle.NorthWestCorner;
  376.  
  377.             }
  378.             else if (properties.ContainsKey("cutN") && properties.ContainsKey("cutW") && !properties.ContainsKey("collideN") && !properties.ContainsKey("collideW"))
  379.             {
  380.                 WallStyle = WallStyle.SouthEastCorner;
  381.             }
  382.             else if (properties.ContainsKey("cutN"))
  383.             {
  384.                 WallStyle = WallStyle.NorthDoorFrame;    
  385.             }
  386.             else if (properties.ContainsKey("cutW"))
  387.             {
  388.                 WallStyle = WallStyle.WestDoorFrame;    
  389.             }
  390.  
  391.             if (properties.ContainsKey("WallW"))
  392.             {
  393.                 WallStyle = WallStyle.WestWall;
  394.             }
  395.             else if (properties.ContainsKey("WallN"))
  396.             {
  397.                 WallStyle = WallStyle.NorthWall;
  398.             }
  399.             else if (properties.ContainsKey("WallNW"))
  400.             {
  401.                 WallStyle = WallStyle.NorthWestCorner;
  402.             }
  403.             else if (properties.ContainsKey("WallWTrans"))
  404.             {
  405.                 WallStyle = WallStyle.WestWallTrans;
  406.             }
  407.             else if (properties.ContainsKey("WallNTrans"))
  408.             {
  409.                 WallStyle = WallStyle.NorthWallTrans;
  410.             }
  411.             else if (properties.ContainsKey("WallNWTrans"))
  412.             {
  413.                 WallStyle = WallStyle.NorthWestCornerTrans;
  414.             }
  415.             else if (properties.ContainsKey("WallSE"))
  416.             {
  417.                 WallStyle = WallStyle.SouthEastCorner;
  418.             }
  419.             else if (properties.ContainsKey("WindowW"))
  420.             {
  421.                 WallStyle = WallStyle.WestWindow;
  422.             }
  423.             else if (properties.ContainsKey("WindowN"))
  424.             {
  425.                 WallStyle = WallStyle.NorthWindow;
  426.             }
  427.             else if (properties.ContainsKey("DoorWallW"))
  428.             {
  429.                 WallStyle = WallStyle.WestDoorFrame;
  430.             }
  431.             else if (properties.ContainsKey("DoorWallN"))
  432.             {
  433.                 WallStyle = WallStyle.NorthDoorFrame;
  434.             }
  435.  
  436.  
  437.  
  438.             if (properties.ContainsKey("solid"))
  439.             {
  440.                 TileBlockStyle = TileBlockStyle.Solid;
  441.             }
  442.             if (properties.ContainsKey("solidtrans"))
  443.             {
  444.                 TileBlockStyle = TileBlockStyle.SolidTransparent;
  445.             }
  446.  
  447.             if(properties.ContainsKey("container"))
  448.             {
  449.                 ContainerType = properties["container"];
  450.             }
  451.  
  452.             if (properties.ContainsKey("solidfloor"))
  453.             {
  454.                 IsFloor = true;
  455.             }
  456.  
  457.             properties.Remove("interior");
  458.            
  459.             if (properties.ContainsKey("exterior"))
  460.             {
  461.                 IsIndoor = false;
  462.             }
  463.             if (properties.ContainsKey("floorS") && properties.ContainsKey("floorW"))
  464.             {
  465.                 FloorItemShelf = Direction.SW;
  466.             }
  467.             else if (properties.ContainsKey("floorN") && properties.ContainsKey("floorW"))
  468.             {
  469.                 FloorItemShelf = Direction.NW;
  470.             }
  471.             else if (properties.ContainsKey("floorS") && properties.ContainsKey("floorE"))
  472.             {
  473.                 FloorItemShelf = Direction.SE;
  474.             }
  475.             else if (properties.ContainsKey("floorN") && properties.ContainsKey("floorE"))
  476.             {
  477.                 FloorItemShelf = Direction.NE;
  478.             }
  479.             else if (properties.ContainsKey("floorE"))
  480.             {
  481.                 FloorItemShelf = Direction.E;
  482.  
  483.             }
  484.             else if (properties.ContainsKey("floorN"))
  485.             {
  486.                 FloorItemShelf = Direction.N;
  487.  
  488.             }
  489.             else if (properties.ContainsKey("floorS"))
  490.             {
  491.                 FloorItemShelf = Direction.S;
  492.  
  493.             }
  494.             else if (properties.ContainsKey("floorW"))
  495.             {
  496.                 FloorItemShelf = Direction.W;
  497.  
  498.             }
  499.             if (properties.ContainsKey("tableS") && properties.ContainsKey("tableW"))
  500.             {
  501.                 HighItemShelf = Direction.SW;
  502.             }
  503.             else if (properties.ContainsKey("tableN") && properties.ContainsKey("tableW"))
  504.             {
  505.                 HighItemShelf = Direction.NW;
  506.             }
  507.             else if (properties.ContainsKey("tableS") && properties.ContainsKey("tableE"))
  508.             {
  509.                 TableItemShelf = Direction.SE;
  510.             }
  511.             else if (properties.ContainsKey("tableN") && properties.ContainsKey("tableE"))
  512.             {
  513.                 TableItemShelf = Direction.NE;
  514.             }
  515.             else if (properties.ContainsKey("tableE"))
  516.             {
  517.                 TableItemShelf = Direction.E;
  518.  
  519.             }
  520.             else if (properties.ContainsKey("tableN"))
  521.             {
  522.                 TableItemShelf = Direction.N;
  523.  
  524.             }
  525.             else if (properties.ContainsKey("tableS"))
  526.             {
  527.                 TableItemShelf = Direction.S;
  528.  
  529.             }
  530.             else if (properties.ContainsKey("tableW"))
  531.             {
  532.                 TableItemShelf = Direction.W;
  533.  
  534.             }
  535.          
  536.  
  537.             if (properties.ContainsKey("shelfS") && properties.ContainsKey("shelfW"))
  538.             {
  539.                 HighItemShelf = Direction.SW;
  540.             }
  541.             else if (properties.ContainsKey("shelfN") && properties.ContainsKey("shelfW"))
  542.             {
  543.                 HighItemShelf = Direction.NW;
  544.             }
  545.             else if (properties.ContainsKey("shelfS") && properties.ContainsKey("shelfE"))
  546.             {
  547.                 HighItemShelf = Direction.SE;
  548.             }
  549.             else if (properties.ContainsKey("shelfN") && properties.ContainsKey("shelfE"))
  550.             {
  551.                 HighItemShelf = Direction.NE;
  552.             }
  553.             else if (properties.ContainsKey("shelfE"))
  554.             {
  555.                 HighItemShelf = Direction.E;
  556.  
  557.             }
  558.             else if (properties.ContainsKey("shelfN"))
  559.             {
  560.                 HighItemShelf = Direction.N;
  561.  
  562.             }
  563.             else if (properties.ContainsKey("shelfS"))
  564.             {
  565.                 HighItemShelf = Direction.S;
  566.  
  567.             }
  568.             else if (properties.ContainsKey("shelfW"))
  569.             {
  570.                 HighItemShelf = Direction.W;
  571.  
  572.             }
  573.      
  574.  
  575.         }
  576.  
  577.     }
  578.     public class Tile
  579.     {
  580.         public Dictionary<String, String> Properties = new Dictionary<string, string>();
  581.         public UIProperties propertyUI = new UIProperties();
  582.  
  583.         public void ChangeProperties(string label, object oldValue, object value)
  584.         {          
  585.             /*
  586.               if (properties.ContainsKey("WaterAmount"))
  587.             {
  588.                 WaterAmount = Convert.ToInt32(properties["WaterAmount"]);
  589.             }
  590.             if (properties.ContainsKey("WaterPiped"))
  591.             {
  592.                 WaterPiped = true;
  593.             }
  594.              */
  595.  
  596.             if (label == "LightPolyStyle")
  597.             {
  598.                 Properties.Remove("LightPolyStyle");
  599.                 if ((LightPolyStyle)value != LightPolyStyle.None)
  600.                 {
  601.                     Properties["LightPolyStyle"] = ((LightPolyStyle)value).ToString();
  602.                 }
  603.  
  604.             }
  605.             if (label == "ClimbSheetN")
  606.             {
  607.                 Properties.Remove("climbSheetN");
  608.                 if ((bool)value == true)
  609.                 {
  610.                     Properties["climbSheetN"] = "";
  611.                 }
  612.  
  613.             }
  614.             if (label == "ClimbSheetW")
  615.             {
  616.                 Properties.Remove("climbSheetW");
  617.                 if ((bool)value == true)
  618.                 {
  619.                     Properties["climbSheetW"] = "";
  620.                 }
  621.  
  622.             }
  623.             if (label == "WheelieBin")
  624.             {
  625.                 Properties.Remove("WheelieBin");
  626.                 if ((bool)value == true)
  627.                 {
  628.                     Properties["WheelieBin"] = "";
  629.                 }
  630.  
  631.             }
  632.             if (label == "CollideWest")
  633.             {
  634.                 Properties.Remove("collideW");
  635.                 if ((bool)value == true)
  636.                 {
  637.                     Properties["collideW"] = "";
  638.                 }
  639.  
  640.             }
  641.             if (label == "CollideNorth")
  642.             {
  643.                 Properties.Remove("collideN");
  644.                 if ((bool)value == true)
  645.                 {
  646.                     Properties["collideN"] = "";
  647.                 }
  648.  
  649.             }
  650.             if (label == "PreSeen")
  651.             {
  652.                 Properties.Remove("PreSeen");
  653.                 if ((bool)value == true)
  654.                 {
  655.                     Properties["PreSeen"] = "";
  656.                 }
  657.  
  658.             }
  659.             if (label == "HoppableW")
  660.             {
  661.                 Properties.Remove("HoppableW");
  662.                 if ((bool)value == true)
  663.                 {
  664.                     Properties["HoppableW"] = "";
  665.                 }
  666.  
  667.             }
  668.             if (label == "HoppableN")
  669.             {
  670.                 Properties.Remove("HoppableN");
  671.                 if ((bool)value == true)
  672.                 {
  673.                     Properties["HoppableN"] = "";
  674.                 }
  675.  
  676.             }
  677.             if (label == "IsBed")
  678.             {
  679.                 Properties.Remove("bed");
  680.                 if ((bool)value == true)
  681.                 {
  682.                     Properties["bed"] = "";
  683.                 }
  684.  
  685.             }
  686.             if (label == "ForceAmbient")
  687.             {
  688.                 Properties.Remove("ForceAmbient");
  689.                 if ((bool)value == true)
  690.                 {
  691.                     Properties["ForceAmbient"] = "";
  692.                 }
  693.  
  694.             }
  695.             if (label == "WindowLocked")
  696.             {
  697.                 Properties.Remove("WindowLocked");
  698.                 if ((bool)value == true)
  699.                 {
  700.                     Properties["WindowLocked"] = "";
  701.                 }
  702.  
  703.             }
  704.            
  705.             if (label == "SmashedTileOffset")
  706.             {
  707.                 Properties["SmashedTileOffset"] = ((int)value).ToString();
  708.  
  709.             }
  710.             if (label == "OpenTileOffset")
  711.             {
  712.                 Properties["OpenTileOffset"] = ((int)value).ToString();
  713.             }
  714.            
  715.  
  716.             if (label == "Door")
  717.             {
  718.                 Properties.Remove("doorN");
  719.                 Properties.Remove("doorW");
  720.  
  721.                 switch ((DoorStyle)value)
  722.                 {
  723.                     case DoorStyle.North:
  724.                         Properties["doorN"] = "";
  725.                         break;
  726.                     case DoorStyle.West:
  727.                         Properties["doorW"] = "";
  728.                         break;
  729.                 }
  730.             }
  731.             if (label == "Window")
  732.             {
  733.                 Properties.Remove("windowN");
  734.                 Properties.Remove("windowW");
  735.  
  736.                 switch ((DoorStyle)value)
  737.                 {
  738.                     case DoorStyle.North:
  739.                         Properties["windowN"] = "";
  740.                         break;
  741.                     case DoorStyle.West:
  742.                         Properties["windowW"] = "";
  743.                         break;
  744.                 }
  745.             }
  746.             if (label == "DoorFrame")
  747.             {
  748.                 Properties.Remove("doorFrN");
  749.                 Properties.Remove("doorFrW");
  750.  
  751.                 switch ((DoorStyle)value)
  752.                 {
  753.                     case DoorStyle.North:
  754.                         Properties["doorFrN"] = "";
  755.                         break;
  756.                     case DoorStyle.West:
  757.                         Properties["doorFrW"] = "";
  758.                         break;
  759.                 }
  760.             }
  761.          
  762.  
  763.             if (label == "WaterAmount")
  764.             {
  765.                 Properties.Remove("waterAmount");
  766.                 if ((int)value != 0)
  767.                 {
  768.                     Properties["waterAmount"] = ((int)value).ToString();
  769.                 }
  770.  
  771.             }
  772.             if (label == "WaterMaxAmount")
  773.             {
  774.                 Properties.Remove("waterMaxAmount");
  775.                 if ((int)value != 0)
  776.                 {
  777.                     Properties["waterMaxAmount"] = ((int)value).ToString();
  778.                 }
  779.  
  780.             }
  781.             else if (label == "WaterPiped")
  782.             {
  783.                 Properties.Remove("waterPiped");
  784.                 if((bool)value == true)
  785.                 {
  786.                     Properties["waterPiped"] = "";
  787.                 }
  788.             }
  789.  
  790.             if (label == "RoofStyle")
  791.             {
  792.                 Properties.Remove("WestRoofB");
  793.                 Properties.Remove("WestRoofM");
  794.                 Properties.Remove("WestRoofT");
  795.  
  796.                 switch ((RoofStyle)value)
  797.                 {
  798.                     case RoofStyle.WestRoofB:
  799.                         Properties["WestRoofB"] = "";
  800.                         break;
  801.                     case RoofStyle.WestRoofM:
  802.                         Properties["WestRoofM"] = "";
  803.                         break;
  804.                     case RoofStyle.WestRoofT:
  805.                         Properties["WestRoofT"] = "";
  806.                         break;
  807.                  
  808.                 }
  809.             }
  810.             if (label == "TileBlockStyle")
  811.             {
  812.                 Properties.Remove("solid");
  813.                 Properties.Remove("solidtrans");
  814.  
  815.                 switch ((TileBlockStyle)value)
  816.                 {
  817.                     case TileBlockStyle.Solid:
  818.                         Properties["solid"] = "";
  819.                         break;
  820.                     case TileBlockStyle.SolidTransparent:
  821.                         Properties["solidtrans"] = "";
  822.                         break;
  823.                 }
  824.             }
  825.             if (label == "IsIndoor")
  826.            {
  827.                Properties.Remove("interior");
  828.                Properties.Remove("exterior");
  829.                if (((bool)(value)) == false)
  830.                {
  831.                    Properties["exterior"] = "";
  832.                }
  833.            }
  834.            if (label == "FloorOverlay")
  835.            {
  836.                Properties.Remove("FloorOverlay");
  837.  
  838.                if (((bool)(value)) == true)
  839.                {
  840.                    Properties["FloorOverlay"] = "";
  841.                }
  842.            }
  843.            if (label == "WallOverlay")
  844.            {
  845.                Properties.Remove("WallOverlay");
  846.  
  847.                if (((bool)(value)) == true)
  848.                {
  849.                    Properties["WallOverlay"] = "";
  850.                }
  851.            }
  852.            if (label == "IsFloor")
  853.            {
  854.                Properties.Remove("solidfloor");
  855.                if(((bool)(value)) == true)
  856.                {
  857.                    Properties["solidfloor"] = "";                    
  858.                }
  859.            }
  860.                
  861.            else if(label=="WallStyle")
  862.            {
  863.                Properties.Remove("wall");
  864.                Properties.Remove("WallN");
  865.                Properties.Remove("WallW");
  866.                Properties.Remove("WallNTrans");
  867.                Properties.Remove("WallWTrans");
  868.                Properties.Remove("DoorWallN");
  869.                Properties.Remove("DoorWallW");
  870.                Properties.Remove("WallNW");
  871.                Properties.Remove("WallNWTrans");
  872.                Properties.Remove("doorFrW");
  873.                Properties.Remove("doorFrN");
  874.                Properties.Remove("WallSE");
  875.                Properties.Remove("WindowW");
  876.                Properties.Remove("WindowN");
  877.                Properties.Remove("collideW");
  878.                Properties.Remove("collideN");
  879.                Properties.Remove("cutW");
  880.                Properties.Remove("cutN");
  881.                Properties.Remove("transparentW");
  882.                Properties.Remove("transparentN");
  883.                Properties.Remove("windowFW");
  884.                Properties.Remove("windowFN");
  885.                Properties["wall"] = "";
  886.                switch ((WallStyle)value)
  887.                {
  888.                    case WallStyle.None:
  889.                        Properties.Remove("wall");
  890.                        break;
  891.                    case WallStyle.NorthWall:
  892.                        Properties["WallN"] = "";
  893.                        break;
  894.                    case WallStyle.WestWall:
  895.                        Properties["WallW"] = "";
  896.                        break;
  897.                    case WallStyle.NorthWallTrans:
  898.                        Properties["WallNTrans"] = "";
  899.                        break;
  900.                    case WallStyle.WestWallTrans:
  901.                        Properties["WallWTrans"] = "";
  902.                        break;
  903.                    case WallStyle.NorthDoorFrame:
  904.                        Properties["DoorWallN"] = "";
  905.                        break;
  906.                    case WallStyle.WestDoorFrame:
  907.                        Properties["DoorWallW"] = "";
  908.                        break;
  909.                    case WallStyle.NorthWestCorner:
  910.                        Properties["WallNW"] = "";
  911.                        break;
  912.                    case WallStyle.NorthWestCornerTrans:
  913.                        Properties["WallNWTrans"] = "";
  914.                        break;
  915.                    case WallStyle.SouthEastCorner:
  916.                        Properties["WallSE"] = "";
  917.                        break;
  918.                    case WallStyle.WestWindow:
  919.                        Properties["WindowW"] = "";
  920.                        break;
  921.                    case WallStyle.NorthWindow:
  922.                        Properties["WindowN"] = "";
  923.                        break;
  924.  
  925.                }
  926.  
  927.            }
  928.            else if (label == "ContainerType")
  929.            {
  930.                Properties.Remove("container");
  931.  
  932.                if (((string)value).Trim().Length > 0)
  933.                 Properties["container"] = ((string)value).Trim();
  934.  
  935.            }
  936.            else if (label == "StairStyle")
  937.            {
  938.                Properties.Remove("stairsBW");
  939.                Properties.Remove("stairsMW");
  940.                Properties.Remove("stairsTW");
  941.                Properties.Remove("stairsBN");
  942.                Properties.Remove("stairsMN");
  943.                Properties.Remove("stairsTN");
  944.                switch ((StairStyle)value)
  945.                {
  946.                    case StairStyle.BottomW:
  947.                        Properties["stairsBW"] = "";
  948.                        break;
  949.                    case StairStyle.MiddleW:
  950.                        Properties["stairsMW"] = "";
  951.                        break;
  952.                    case StairStyle.TopW:
  953.                        Properties["stairsTW"] = "";
  954.                        break;
  955.                    case StairStyle.BottomN:
  956.                        Properties["stairsBN"] = "";
  957.                        break;
  958.                    case StairStyle.MiddleN:
  959.                        Properties["stairsMN"] = "";
  960.                        break;
  961.                    case StairStyle.TopN:
  962.                        Properties["stairsTN"] = "";
  963.                        break;
  964.  
  965.                }
  966.            }
  967.         }
  968.     }
  969.     public class Tileset
  970.     {
  971.         public String name;
  972.         public int widthTiles;
  973.         public int heightTiles;
  974.         public List<Tile> Tiles = new List<Tile>();
  975.         public string source;
  976.  
  977.         public void ChangeProperties(List<int> selectionList, string label, object oldValue, object value)
  978.         {
  979.             int n = 0;
  980.             foreach (var tile in Tiles)
  981.             {
  982.                 if(selectionList.Contains(n))
  983.                 {
  984.                     tile.ChangeProperties(label, oldValue, value);
  985.                 }
  986.                 n++;
  987.             }
  988.         }
  989.     }
  990.     public class TileSetSystem
  991.     {
  992.         public static TileSetSystem instance = new TileSetSystem();
  993.         //public List<Tileset> Tilesets = new List<Tileset>();
  994.         public Dictionary<String, Tileset> Tilesets = new Dictionary<String, Tileset>();
  995.  
  996.         public void Add(String filename)
  997.         {
  998.             String ofilename = filename;
  999.             if (filename.Contains("/"))
  1000.             {
  1001.                 filename = filename.Substring(filename.LastIndexOf("/") + 1);
  1002.             }
  1003.             if (filename.Contains("\\"))
  1004.             {
  1005.                 filename = filename.Substring(filename.LastIndexOf("\\") + 1);
  1006.             }
  1007.             Tileset set = null;
  1008.             if (Tilesets.ContainsKey(filename.Replace(".png", "")))
  1009.                 set = Tilesets[filename.Replace(".png", "")];
  1010.             else
  1011.             {
  1012.                 set = new Tileset();
  1013.                 set.source = filename;
  1014.                 if (set.source.Contains("/"))
  1015.                 {
  1016.                     set.source = set.source.Substring(set.source.LastIndexOf("/") + 1);
  1017.                 }
  1018.                 if (set.source.Contains("\\"))
  1019.                 {
  1020.                     set.source = set.source.Substring(set.source.LastIndexOf("\\") + 1);
  1021.                 }
  1022.                 set.name = set.source.Replace(".png", "");
  1023.                 Image bmp = Image.FromFile(ofilename);
  1024.                 set.widthTiles = bmp.Width / 64;
  1025.                 set.heightTiles = bmp.Height / 128;
  1026.                 Tilesets[set.name] = set;
  1027.                 for (int m = 0; m < set.widthTiles * set.heightTiles; m++)
  1028.                 {
  1029.                     Tile t = new Tile();
  1030.                     set.Tiles.Add(t);
  1031.                 }
  1032.             }
  1033.         }
  1034.  
  1035.         public void Import(String filename)
  1036.         {
  1037.             XmlDocument doc = new XmlDocument();
  1038.             doc.Load(filename);
  1039.  
  1040.             XmlNode n = doc.FirstChild.NextSibling.FirstChild;
  1041.  
  1042.             while(n != null)
  1043.             {
  1044.                 if(n.Name == "tileset")
  1045.                 {
  1046.                     XmlNode image = n.FirstChild;
  1047.                     XmlNode tile = n.FirstChild.NextSibling;
  1048.  
  1049.                     Tileset set = null;
  1050.  
  1051.                     if (Tilesets.ContainsKey(image.Attributes["source"].Value.Replace(".png", "")))
  1052.                         set = Tilesets[image.Attributes["source"].Value.Replace(".png", "")];
  1053.                     else
  1054.                     {
  1055.                         set = new Tileset();
  1056.                         set.source = image.Attributes["source"].Value;
  1057.                         if (set.source.Contains("/"))
  1058.                         {
  1059.                             set.source = set.source.Substring(set.source.LastIndexOf("/") + 1);
  1060.                         }
  1061.                         set.name = set.source.Replace(".png", "");
  1062.                         Image bmp = Image.FromFile(set.source);
  1063.                         set.widthTiles = bmp.Width/64;
  1064.                         set.heightTiles = bmp.Height / 128;
  1065.                         Tilesets[set.name] = set;
  1066.                         for (int m = 0; m < set.widthTiles * set.heightTiles; m++)
  1067.                         {
  1068.                             Tile t = new Tile();
  1069.                             set.Tiles.Add(t);
  1070.                         }
  1071.                     }
  1072.                     while (tile != null)
  1073.                     {
  1074.                         XmlNode properties = tile.FirstChild;
  1075.                         int id = Convert.ToInt32(tile.Attributes["id"].Value);
  1076.                         Tile t = set.Tiles[id];
  1077.                         if (properties != null)
  1078.                         {
  1079.                             XmlNode property = properties.FirstChild;
  1080.                             while (property != null)
  1081.                             {
  1082.  
  1083.                                 if (property.Attributes["name"].Value == "interior")
  1084.                                 {
  1085.                                     t.Properties["exterior"] = "";
  1086.                                 }
  1087.                                 else
  1088.                                 {
  1089.                                     t.Properties[property.Attributes["name"].Value] = property.Attributes["value"].Value;    
  1090.                                 }
  1091.                                
  1092.  
  1093.                                 property = property.NextSibling;
  1094.                             }
  1095.                             t.propertyUI.FromProperties(t.Properties);
  1096.                         }
  1097.                         tile = tile.NextSibling;
  1098.                     }
  1099.                 }
  1100.                 n = n.NextSibling;
  1101.             }
  1102.         }
  1103.  
  1104.         public void SaveString(BinaryWriter binWriter, String str)
  1105.         {
  1106.             foreach (var c in str)
  1107.             {
  1108.                 binWriter.Write(c);
  1109.             }
  1110.             binWriter.Write('\n');
  1111.         }
  1112.  
  1113.         private string ReadString(BinaryReader binReader)
  1114.         {
  1115.             String str = "";
  1116.  
  1117.             char c = ' ';
  1118.             while(c!='\n')
  1119.             {
  1120.                 c = binReader.ReadChar();
  1121.                 if( c!='\n')
  1122.                     str += c;
  1123.             }
  1124.             return str;
  1125.         }
  1126.         public void Save(string fileName)
  1127.         {
  1128.             ASCIIEncoding utf8 = new ASCIIEncoding();
  1129.             using (BinaryWriter binWriter =
  1130.                 new BinaryWriter(File.Open(fileName, FileMode.Create), utf8))
  1131.             {
  1132.                 binWriter.Write(this.Tilesets.Count);
  1133.                 foreach (var tileset in Tilesets.Values)
  1134.                 {
  1135.                     SaveString(binWriter, tileset.name);
  1136.                     SaveString(binWriter, tileset.source);
  1137.                     binWriter.Write(tileset.widthTiles);
  1138.                     binWriter.Write(tileset.heightTiles);
  1139.                     binWriter.Write(tileset.Tiles.Count);
  1140.                     foreach (var tile in tileset.Tiles)
  1141.                     {
  1142.                         if (tile.propertyUI.WallStyle != WallStyle.None)
  1143.                             tile.Properties["wall"] = "";
  1144.  
  1145.                         binWriter.Write(tile.Properties.Count);
  1146.                         foreach (var property in tile.Properties)
  1147.                         {
  1148.                             SaveString(binWriter,property.Key);
  1149.                             SaveString(binWriter,property.Value);
  1150.                         }
  1151.                     }
  1152.                 }
  1153.  
  1154.                 binWriter.Close();
  1155.             }
  1156.  
  1157.         }
  1158.  
  1159.  
  1160.         public void Load(String filename)
  1161.         {
  1162.             ASCIIEncoding utf8 = new ASCIIEncoding();
  1163.             using (BinaryReader binReader =
  1164.                 new BinaryReader(File.Open(filename, FileMode.Open), utf8))
  1165.             {
  1166.                 filename = filename.Substring(0, filename.LastIndexOf("\\"));
  1167.                 int c = binReader.ReadInt32();
  1168.                 for(int n=0;n<c;n++)
  1169.                 {
  1170.                    Tileset t = new Tileset();
  1171.                     t.name = ReadString(binReader);
  1172.                     t.source = ReadString(binReader);
  1173.                     t.widthTiles = binReader.ReadInt32();
  1174.                     t.heightTiles = binReader.ReadInt32();
  1175.                     Image bmp = Image.FromFile(filename+"\\"+t.source);
  1176.                     t.widthTiles = bmp.Width / 64;
  1177.                     t.heightTiles = bmp.Height / 128;
  1178.                     int c2 = binReader.ReadInt32();
  1179.                    
  1180.                     for(int m=0;m<c2;m++)
  1181.                     {
  1182.                         Tile tile = new Tile();
  1183.                         t.Tiles.Add(tile);
  1184.                         int np = binReader.ReadInt32();
  1185.                        
  1186.                         for(int q=0;q<np;q++)
  1187.                         {
  1188.                             String p = ReadString(binReader);
  1189.                             String v = ReadString(binReader);
  1190.  
  1191.                             tile.Properties[p] = v;
  1192.  
  1193.                         }
  1194.                         tile.propertyUI.FromProperties(tile.Properties);
  1195.                     }
  1196.  
  1197.                     int c3 = t.widthTiles * t.heightTiles;
  1198.  
  1199.  
  1200.                     for (int m = c2; m < c3;m++ )
  1201.                     {
  1202.                          Tile tile = new Tile();
  1203.                         t.Tiles.Add(tile);
  1204.                     }
  1205.                        
  1206.                     Tilesets[t.name] = t;
  1207.                    
  1208.                    
  1209.                 }
  1210.             }
  1211.         }
  1212.  
  1213.     }
  1214. }