// Mouse moves over display
        public override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            BlockEntry newhighlight = null;

            hx = -1;
            hy = -1;

            // Determine highlighted block
            float nhx = (mousemappos.x - blockmap.Range.Left) / (float)blockmap.BlockSize;
            float nhy = (mousemappos.y - blockmap.Range.Top) / (float)blockmap.BlockSize;

            if ((nhx < (float)blockmap.Size.Width) && (nhy < (float)blockmap.Size.Height) && (nhx >= 0.0f) && (nhy >= 0.0f))
            {
                newhighlight = blockmap.GetBlockAt(mousemappos);
                if (newhighlight != null)
                {
                    hx = (int)nhx;
                    hy = (int)nhy;
                }
            }

            if (newhighlight != highlighted)
            {
                highlighted = newhighlight;
                General.Interface.RedrawDisplay();
            }
        }
示例#2
0
        /// <summary>
        /// Cleans a single block
        /// </summary>
        /// <param name="map">
        /// The map containing the target block
        /// </param>
        /// <param name="x">
        /// The x coordinate of the target block
        /// </param>
        /// <param name="y">
        /// The y coordinate of the target block
        /// </param>
        /// <param name="depth">
        /// The depth coordinate of the target block
        /// </param>
        public static void CleanBlock(BlockMap map, int x, int y, int depth)
        {
            Block b = map.GetBlockAt(x, y, depth);

            if (b != null)
            {
                OrientedBlock ob = (OrientedBlock)b;

                if (ob == null)
                {
                    return;
                }

                BlockSet[] bs = ob.GetBlockSetsAsArray();

                BlockSet currentSet = ob.GetCurrentBlockSet();

                for (int k = 0; k < bs.Length; k++)
                {
                    if (bs[k] == currentSet)
                    {
                        continue;
                    }

                    BlockSet bSet = bs[k];

                    for (int l = 0; l < bSet.blockSet.Length; l++)
                    {
                        GameObject.Destroy(bSet.blockSet[l].gameObject);
                    }
                }
            }
        }
        // This runs the check
        public override void Run()
        {
            BlockMap <BlockEntry> blockmap = BuilderPlug.Me.ErrorCheckForm.BlockMap;
            Dictionary <Vertex, List <Vertex> > doneverts = new Dictionary <Vertex, List <Vertex> >();
            int progress     = 0;
            int stepprogress = 0;

            // Go for all the verts
            foreach (Vertex v in General.Map.Map.Vertices)
            {
                BlockEntry block = blockmap.GetBlockAt(v.Position);

                // Go for all the linedefs that our vertex could overlap
                foreach (Linedef l in block.Lines)
                {
                    if (v == l.Start || v == l.End)
                    {
                        continue;
                    }
                    if (Math.Round(l.Line.GetDistanceToLine(v.Position, true), 3) == 0)
                    {
                        SubmitResult(new ResultVertexOverlappingLine(v, l));
                    }
                }

                // Go for all the verts that our vertex could overlap
                foreach (Vertex bv in block.Vertices)
                {
                    if (bv == v || (doneverts.ContainsKey(v) && doneverts[v].Contains(bv)) || (doneverts.ContainsKey(bv) && doneverts[bv].Contains(v)))
                    {
                        continue;
                    }
                    if (bv.Position == v.Position)
                    {
                        SubmitResult(new ResultVertexOverlappingVertex(v, bv));
                    }
                    if (!doneverts.ContainsKey(v))
                    {
                        doneverts.Add(v, new List <Vertex>());
                    }
                    doneverts[v].Add(bv);
                }

                // Handle thread interruption
                try { Thread.Sleep(0); }
                catch (ThreadInterruptedException) { return; }

                // We are making progress!
                if ((++progress / PROGRESS_STEP) > stepprogress)
                {
                    stepprogress = (progress / PROGRESS_STEP);
                    AddProgress(1);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Refresh the target block - correcting the orientation of the block and the surrounding blocks
        /// </summary>
        /// <param name="map">
        /// The map housing the block that you wish to refresh
        /// </param>
        /// <param name="x">
        /// The x coordinate of the block to be refreshed
        /// </param>
        /// <param name="y">
        /// The y coordinate of the block to be refreshed
        /// </param>
        /// <param name="depth">
        /// The depth of the block to be refreshed
        /// </param>
        public static void RefreshBlock(BlockMap map, int x, int y, int depth)
        {
            for (int x1 = x - 1; x1 <= x + 1; x1++)
            {
                for (int y1 = y - 1; y1 <= y + 1; y1++)
                {
                    Block b = map.GetBlockAt(x1, y1, depth);

                    if (b != null)
                    {
                        b.RefreshBlock();
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        ///Set the variant of the targetted block
        /// </summary>
        /// <param name="map">
        ///The blockmap containing the target block
        /// </param>
        /// <param name="x">
        ///X coordinate of the target block
        /// </param>
        /// <param name="y">
        ///Y coordinate of the target block
        /// </param>
        /// <param name="depth">
        ///Z (depth) coordinte of the target block
        /// </param>
        /// <param name="variant">
        ///Index of the variant to which to set this block
        /// </param>
        public static void SetBlockVariant(BlockMap map, int x, int y, int depth, int variant)
        {
            MapChunk m = map.GetChunkForBlockCoordinate(x, y, depth);

            if (m != null)
            {
                Block eb = map.GetBlockAt(x, y, depth);

                if (eb != null)
                {
                    eb.SetVariant(variant);
                    RefreshBlock(map, x, y, depth);
                }
            }
        }
示例#6
0
        /// <summary>
        ///Remove a block from the map (replacing it with an Empty Block)
        /// </summary>
        /// <param name="map">
        /// The map from which you wish to remove the block
        /// </param>
        /// <param name="x">
        /// The x coordinate of the block
        /// </param>
        /// <param name="y">
        /// The y coordinate of the block
        /// </param>
        /// <param name="depth">
        /// The depth of the block
        /// </param>
        /// <param name="addEmptyBlock">
        /// Add an empty block to the void left after removal?
        /// </param>
        /// <param name="destroyExistingImmediate">
        /// Use DestroyImmediate or Destroy when removing the existing block? (You must use immediate from within the Editor, and cannot use it once physics collisions)
        /// </param>
        public static void RemoveBlockFromMap(BlockMap map, int x, int y, int depth, bool addEmptyBlock, bool destroyImmediate)
        {
            MapChunk m = map.GetChunkForBlockCoordinate(x, y, depth);

            if (m != null)
            {
                Block eb = map.GetBlockAt(x, y, depth);

                if (eb != null)
                {
                    map.SetBlockAt(x, y, depth, null, destroyImmediate);
                }

                if (addEmptyBlock)
                {
                    map.SetBlockAt(x, y, depth, GetEmptyBlock(map), destroyImmediate);
                }
            }
        }
示例#7
0
        /// <summary>
        ///Refresh the map - correcting orientations on all blocks
        /// </summary>
        /// <param name="map">
        /// The map that you wish to refresh
        /// </param>
        /// <param name="randomise">
        /// Randomise the block variations within the map?
        /// </param>
        public static void RefreshMap(BlockMap map, bool randomise)
        {
            map.RefreshMap();

            if (randomise)
            {
                for (int x = 0; x < map.GetMapWidth(); x++)
                {
                    for (int y = 0; y < map.GetMapHeight(); y++)
                    {
                        for (int z = map.mapLowerDepth; z <= map.mapUpperDepth; z++)
                        {
                            Block b = map.GetBlockAt(x, y, z);
                            if (b != null && !b.isNullBlock)
                            {
                                b.RandomiseVariant();
                            }
                        }
                    }
                }
            }
        }
		void RefreshBlocks(int x, int y, int depth, BlockMap map){
			
			EditorUtility.SetDirty(map);
			
			for(int x1 = x -1; x1 <= x + 1; x1++){
				for(int y1 = y - 1; y1 <= y + 1; y1++){
					
					Block b = map.GetBlockAt(x1,y1,depth);
					
					if(b != null){
						
						b.RefreshBlock();
						
						EditorUtility.SetDirty(b);
						
						//if(paintRandom){
							//b.RandomiseVariant();
						//}
						
					}
					
				}
			}
			
		}
示例#9
0
 /// <summary>
 ///Get the block located at the given coordinates
 /// </summary>
 /// <param name="map">
 /// The map from which you wish to retrieve a block
 /// </param>
 /// <param name="x">
 /// The x coordinate of the block
 /// </param>
 /// <param name="y">
 /// The y coordinate of the block
 /// </param>
 /// <param name="depth">
 /// The depth of the block
 /// </param>
 /// <returns>
 /// The block, if one exists, null if not.
 /// </returns>
 public static Block GetBlockAt(BlockMap map, int x, int y, int depth)
 {
     return(map.GetBlockAt(x, y, depth));
 }
		/// <summary>
		/// Cleans a single block 
		/// </summary>
		/// <param name="map">
		/// The map containing the target block
		/// </param>
		/// <param name="x">
		/// The x coordinate of the target block
		/// </param>
		/// <param name="y">
		/// The y coordinate of the target block
		/// </param>
		/// <param name="depth">
		/// The depth coordinate of the target block
		/// </param>
		public static void CleanBlock(BlockMap map, int x, int y, int depth){
			
			Block b = map.GetBlockAt(x,y,depth);
					
			if(b != null){
				
				OrientedBlock ob = (OrientedBlock) b;
				
				if(ob == null){
					return;
				}
				
				BlockSet[] bs = ob.GetBlockSetsAsArray();
				
				BlockSet currentSet = ob.GetCurrentBlockSet();
				
				for(int k = 0; k < bs.Length; k++){
					
					if(bs[k] == currentSet){
						continue;
					}
					
					BlockSet bSet = bs[k];
					
					for(int l = 0; l < bSet.blockSet.Length; l++){
						
						GameObject.Destroy(bSet.blockSet[l].gameObject);
						
					}
				}
				
					
			}
			
		}
		/// <summary>
		/// Refresh the target block - correcting the orientation of the block and the surrounding blocks 
		/// </summary>
		/// <param name="map">
		/// The map housing the block that you wish to refresh
		/// </param>
		/// <param name="x">
		/// The x coordinate of the block to be refreshed
		/// </param>
		/// <param name="y">
		/// The y coordinate of the block to be refreshed
		/// </param>
		/// <param name="depth">
		/// The depth of the block to be refreshed
		/// </param>
		public static void RefreshBlock(BlockMap map, int x, int y, int depth){
						
			for(int x1 = x-1; x1 <= x+1; x1++){
				for(int y1 = y-1; y1 <= y+1; y1++){
					
					Block b = map.GetBlockAt(x1,y1,depth);
					
					if(b != null){
						b.RefreshBlock();
					}
					
				}
			}
			
		}
		/// <summary>
		///Get the block located at the given coordinates 
		/// </summary>
		/// <param name="map">
		/// The map from which you wish to retrieve a block
		/// </param>
		/// <param name="x">
		/// The x coordinate of the block
		/// </param>
		/// <param name="y">
		/// The y coordinate of the block
		/// </param>
		/// <param name="depth">
		/// The depth of the block
		/// </param>
		/// <returns>
		/// The block, if one exists, null if not.
		/// </returns>
		public static Block GetBlockAt(BlockMap map, int x, int y, int depth){
			return map.GetBlockAt(x,y,depth);
		}
		/// <summary>
		///Refresh the map - correcting orientations on all blocks 
		/// </summary>
		/// <param name="map">
		/// The map that you wish to refresh
		/// </param>
		/// <param name="randomise">
		/// Randomise the block variations within the map?
		/// </param>
		public static void RefreshMap(BlockMap map, bool randomise){
			map.RefreshMap();
			
			if(randomise){
				for(int x = 0; x < map.GetMapWidth(); x++){
					for(int y = 0; y < map.GetMapHeight(); y++){
						for(int z = map.mapLowerDepth; z <= map.mapUpperDepth; z++){
							Block b = map.GetBlockAt(x,y,z);
							if(b != null && !b.isNullBlock){
								b.RandomiseVariant();
							}
						}
					}
				}
			}
		}
		/// <summary>
		///Set the variant of the targetted block 
		/// </summary>
		/// <param name="map">
		///The blockmap containing the target block
		/// </param>
		/// <param name="x">
		///X coordinate of the target block
		/// </param>
		/// <param name="y">
		///Y coordinate of the target block
		/// </param>
		/// <param name="depth">
		///Z (depth) coordinte of the target block
		/// </param>
		/// <param name="variant">
		///Index of the variant to which to set this block
		/// </param>
		public static void SetBlockVariant(BlockMap map, int x, int y, int depth, int variant){
			
			MapChunk m = map.GetChunkForBlockCoordinate(x,y,depth);
			
			if(m != null){
				
				Block eb = map.GetBlockAt(x,y,depth);
			
				if(eb != null){
					
					eb.SetVariant(variant);
					RefreshBlock(map,x,y,depth);					
				}
				
			}
			
		}
		/// <summary>
		///Remove a block from the map (replacing it with an Empty Block) 
		/// </summary>
		/// <param name="map">
		/// The map from which you wish to remove the block
		/// </param>
		/// <param name="x">
		/// The x coordinate of the block
		/// </param>
		/// <param name="y">
		/// The y coordinate of the block
		/// </param>
		/// <param name="depth">
		/// The depth of the block
		/// </param>
		/// <param name="addEmptyBlock">
		/// Add an empty block to the void left after removal?
		/// </param>
		/// <param name="destroyExistingImmediate">
		/// Use DestroyImmediate or Destroy when removing the existing block? (You must use immediate from within the Editor, and cannot use it once physics collisions)
		/// </param>
		public static void RemoveBlockFromMap(BlockMap map, int x, int y, int depth, bool addEmptyBlock, bool destroyImmediate){
			
			MapChunk m = map.GetChunkForBlockCoordinate(x,y,depth);
			
			if(m != null){
				
				Block eb = map.GetBlockAt(x,y,depth);
			
				if(eb != null){
					
					map.SetBlockAt(x,y,depth,null,destroyImmediate);
					
				}
				
				if(addEmptyBlock){
					map.SetBlockAt(x,y,depth,GetEmptyBlock(map),destroyImmediate);
				}
				
			}
			
		}