Esempio n. 1
0
 private void LayoutYZ(Vector3i Sides, Vector3i min, Vector3i max)
 {
     Console.WriteLine("long y = {0}; y < {1}; y += {2}", min.Y / Sides.Y, max.Y / Sides.Y, _Map.ChunkScale.Y / Sides.Y);
     for (long y = min.Y / Sides.Y; y < max.Y / Sides.Y; y += _Map.ChunkScale.Y / Sides.Y)
     {
         for (long x = min.X / Sides.X; x < max.X / Sides.X; x += _Map.ChunkScale.X / Sides.X)
         {
             Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X), y + (min.Y / _Map.ChunkScale.Y), (CurrentPosition.Z / _Map.ChunkScale.X));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.SetBounds((int)(cc.Y * _Map.ChunkScale.Y) + 6, (int)(cc.Z * _Map.ChunkScale.Z) + 6, (int)(_Map.ChunkScale.Y), (int)(_Map.ChunkScale.Z));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 /*
                  * MapChunkControl mcc = Chunks[cc];
                  * mcc.SetBounds((int)(cc.Y * _Map.ChunkScale.Y)+6, (int)(cc.Z * _Map.ChunkScale.Z)+6, (int)(_Map.ChunkScale.Y), (int)(_Map.ChunkScale.Z));
                  * Controls.Add(mcc);
                  * Chunks.Add(cc, mcc);*/
             }
         }
     }
 }
Esempio n. 2
0
 private void LayoutXY(Vector3i Sides, Vector3i min, Vector3i max)
 {
     for (int x = 0; x < (Width / Sides.X); x++)
     {
         for (int y = 0; y < (Height / Sides.Y); y++)
         {
             Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X), y + (min.Y / _Map.ChunkScale.Y), (CurrentPosition.Z / _Map.ChunkScale.X));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.SetBounds((int)(cc.X * _Map.ChunkScale.X), (int)(cc.Y * _Map.ChunkScale.Y), (int)(_Map.ChunkScale.X), (int)(_Map.ChunkScale.Y));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(cc.X * _Map.ChunkScale.X), (int)(cc.Y * _Map.ChunkScale.Y), (int)(_Map.ChunkScale.X), (int)(_Map.ChunkScale.Y));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
         }
     }
 }
Esempio n. 3
0
 private void LayoutYZ(Vector3i Sides, Vector3i min, Vector3i max)
 {
     Console.WriteLine("long y = {0}; y < {1}; y += {2}", min.Y / Sides.Y, max.Y / Sides.Y, _Map.ChunkScale.Y / Sides.Y);
     for (long y = min.Y / Sides.Y; y < max.Y / Sides.Y; y += _Map.ChunkScale.Y / Sides.Y)
     {
         for (long x = min.X / Sides.X; x < max.X / Sides.X; x += _Map.ChunkScale.X/Sides.X)
         {
             Vector3i cc = new Vector3i(x+(min.X / _Map.ChunkScale.X), y + (min.Y / _Map.ChunkScale.Y), (CurrentPosition.Z / _Map.ChunkScale.X));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.SetBounds((int)(cc.Y * _Map.ChunkScale.Y)+6, (int)(cc.Z * _Map.ChunkScale.Z)+6, (int)(_Map.ChunkScale.Y), (int)(_Map.ChunkScale.Z));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 /*
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(cc.Y * _Map.ChunkScale.Y)+6, (int)(cc.Z * _Map.ChunkScale.Z)+6, (int)(_Map.ChunkScale.Y), (int)(_Map.ChunkScale.Z));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);*/
             }
         }
     }
 }
Esempio n. 4
0
 private void LayoutXY(Vector3i Sides, Vector3i min, Vector3i max)
 {
     for (int x = 0; x < (Width/Sides.X); x++)
     {
         for (int y = 0; y < (Height/Sides.Y); y++)
         {
             Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X), y + (min.Y / _Map.ChunkScale.Y), (CurrentPosition.Z / _Map.ChunkScale.X));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.SetBounds((int)(cc.X * _Map.ChunkScale.X), (int)(cc.Y * _Map.ChunkScale.Y), (int)(_Map.ChunkScale.X), (int)(_Map.ChunkScale.Y));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(cc.X * _Map.ChunkScale.X), (int)(cc.Y * _Map.ChunkScale.Y), (int)(_Map.ChunkScale.X), (int)(_Map.ChunkScale.Y));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Only version that works correctly atm.
 /// </summary>
 /// <param name="Sides"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 private void LayoutTopdown(Vector3i Sides, Vector3i min, Vector3i max)
 {
     for (int x = 0; x < Width/Sides.X; x++)
     {
         for (int y = 0; y <Height/Sides.Y; y++)
         {
             Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X),y + (CurrentPosition.Y / _Map.ChunkScale.Y), (min.Y / _Map.ChunkScale.Z));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.MouseClick += new MouseEventHandler(ChunkRightClicked);
                 mcc.SendToBack();
                 mcc.SetBounds((int)(x * _Map.ChunkScale.X)*ZoomLevel+6, (int)(y * _Map.ChunkScale.Y)*ZoomLevel+6, (int)(_Map.ChunkScale.X)*ZoomLevel, (int)(_Map.ChunkScale.Y)*ZoomLevel);
                 //Console.WriteLine("Added chunk to {0},{1}", mcc.Top, mcc.Left);
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(x * _Map.ChunkScale.X) * ZoomLevel+6, (int)(y * _Map.ChunkScale.Y) * ZoomLevel+6, (int)(_Map.ChunkScale.X) * ZoomLevel, (int)(_Map.ChunkScale.Y) * ZoomLevel);
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
         }
     }
     /*
     foreach (KeyValuePair<Guid, Entity> k in _Map.Entities)
     {
         Entity e = k.Value;
         if (e.Pos.X > min.X && e.Pos.X < max.X && e.Pos.Y > min.Y && e.Pos.Y < max.Y)
         {
             Button b = new Button();
             float x = (float)e.Pos.X + (float)min.X;
             float y = (float)e.Pos.Y + (float)min.Y;
             //b.SetBounds((int)y * ZoomLevel - 2, (int)y * ZoomLevel - 2, 16, 16);
             b.SetBounds((int)(e.Pos.X - min.X) * ZoomLevel, (int)(e.Pos.Y - min.Y) * ZoomLevel, 16, 16);
             b.Image = e.Image;
             b.UseVisualStyleBackColor = true;
             b.BackColor = Color.Transparent;
             b.FlatStyle = FlatStyle.Flat;
             b.ImageAlign = ContentAlignment.MiddleCenter;
             b.FlatAppearance.BorderSize = 1;
             b.FlatAppearance.BorderColor = Color.Black;
             b.FlatAppearance.MouseOverBackColor = Color.Transparent;
             b.Click += new EventHandler(OnEntityClicked);
             b.Tag = e;
             Controls.Add(b);
             EntityControls.Add(b);
             b.Show();
             b.BringToFront();
             Console.WriteLine("{0} {1} added to pos {2},{3}", e, e.UUID, b.Top, b.Left);
         }
     }
     foreach (KeyValuePair<Guid, TileEntity> k in _Map.TileEntities)
     {
         TileEntity e = k.Value;
         if (e.Pos.X > min.X && e.Pos.X < max.X && e.Pos.Y > min.Y && e.Pos.Y < max.Y)
         {
             Button b = new Button();
             b.SetBounds((int)(e.Pos.X - min.X) * ZoomLevel + 6, (int)(e.Pos.Y - min.Y) * ZoomLevel + 6, 16, 16);
             b.Image = e.Image;
             b.UseVisualStyleBackColor = true;
             b.BackColor = Color.Transparent;
             b.FlatStyle = FlatStyle.Flat;
             b.ImageAlign = ContentAlignment.MiddleCenter;
             b.FlatAppearance.BorderSize = 1;
             b.FlatAppearance.BorderColor = Color.Black;
             b.FlatAppearance.MouseOverBackColor = Color.Transparent;
             b.Click += new EventHandler(OnTileEntityClicked);
             b.Tag = e;
             Controls.Add(b);
             EntityControls.Add(b);
             b.Show();
             b.BringToFront();
             Console.WriteLine("{0} {1} added to pos {2},{3}", e, e.UUID, b.Top, b.Left);
         }
     }*/
 }
Esempio n. 6
0
        void ChunkRightClicked(object sender, MouseEventArgs e)
        {
            MapChunkControl mcc = (MapChunkControl)sender;

            SelectedVoxel = new Vector3i(
                CurrentPosition.X + (e.X / _ZoomLevel) + (mcc.AssignedChunk.X * _Map.ChunkScale.X),
                CurrentPosition.Y + (e.Y / _ZoomLevel) + (mcc.AssignedChunk.Y * _Map.ChunkScale.Y),
                CurrentPosition.Z);
            if (e.Button == MouseButtons.Left)
            {
                Vector3i bp = new Vector3i(e.X / ZoomLevel, e.Y / ZoomLevel, CurrentPosition.Z);
                Chunk    c  = _Map.GetChunk(mcc.AssignedChunk.X, mcc.AssignedChunk.Y);
                if (c == null)
                {
                    return;
                }
                c.Blocks[bp.X, bp.Y, bp.Z] = CurrentMaterial;
                c.Save();
            }
            if (e.Button == MouseButtons.Right)
            {
                Vector3i bp = new Vector3i(e.X / ZoomLevel, e.Y / ZoomLevel, CurrentPosition.Z);
                Chunk    c  = _Map.GetChunk(mcc.AssignedChunk);
                Block    b  = Blocks.Get(0);
                if (c != null)
                {
                    byte bid = c.GetBlock(bp);
                    b = Blocks.Get(bid);
                }
                ContextMenu cmnu = new System.Windows.Forms.ContextMenu();
                cmnu.MenuItems.AddRange(new MenuItem[] {
                    new MenuItem("What's this?", new EventHandler(delegate(object s, EventArgs ea){
                        MessageBox.Show("That is a(n) " + b.ToString() + " block.");
                    })),
                    new MenuItem("Remove this.", new EventHandler(delegate(object s, EventArgs ea){
                        c.SetBlock(bp, 0x00);
                        mcc.Render();
                        mcc.Refresh();
                    })),
                    new MenuItem("-"),
                    new MenuItem("Replace..."), //,new EventHandler(delegate(object s,EventArgs ea){})),
                    new MenuItem("Paint..."),   //,new EventHandler(delegate(object s,EventArgs ea){})),
                    new MenuItem("Generate...", new EventHandler(delegate(object s, EventArgs ea){
                        double min, max;
                        Map.Generate(mcc.AssignedChunk.X, mcc.AssignedChunk.Y, out min, out max);
                        Map.LoadChunk(mcc.AssignedChunk.X, mcc.AssignedChunk.Y);
                        mcc.Render();
                        mcc.Refresh();
                    })),
                    new MenuItem("-"),
                    new MenuItem("Delete Chunk...", new EventHandler(delegate(object s, EventArgs ea){
                        Map.LoadChunk(mcc.AssignedChunk.X, mcc.AssignedChunk.Y);
                        c.Delete();
                        mcc.Render();
                        mcc.Refresh();
                    })),
                    new MenuItem("Refresh", new EventHandler(delegate(object s, EventArgs ea){
                        mcc.Render();
                        mcc.Refresh();
                    })),
                    new MenuItem("Chunk Properties...", new EventHandler(delegate(object s, EventArgs ea){
                        dlgChunk chunkdlg = new dlgChunk(_Map, mcc.AssignedChunk);
                        chunkdlg.ShowDialog();
                    })),
                });
                cmnu.Show(mcc, new Point(0, 0));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Only version that works correctly atm.
        /// </summary>
        /// <param name="Sides"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        private void LayoutTopdown(Vector3i Sides, Vector3i min, Vector3i max)
        {
            for (int x = 0; x < Width / Sides.X; x++)
            {
                for (int y = 0; y < Height / Sides.Y; y++)
                {
                    Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X), y + (CurrentPosition.Y / _Map.ChunkScale.Y), (min.Y / _Map.ChunkScale.Z));
                    if (!Chunks.ContainsKey(cc))
                    {
                        MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                        mcc.MouseClick += new MouseEventHandler(ChunkRightClicked);
                        mcc.SendToBack();
                        mcc.SetBounds((int)(x * _Map.ChunkScale.X) * ZoomLevel + 6, (int)(y * _Map.ChunkScale.Y) * ZoomLevel + 6, (int)(_Map.ChunkScale.X) * ZoomLevel, (int)(_Map.ChunkScale.Y) * ZoomLevel);
                        //Console.WriteLine("Added chunk to {0},{1}", mcc.Top, mcc.Left);
                        Controls.Add(mcc);
                        Chunks.Add(cc, mcc);
                    }
                    else
                    {
                        MapChunkControl mcc = Chunks[cc];
                        mcc.SetBounds((int)(x * _Map.ChunkScale.X) * ZoomLevel + 6, (int)(y * _Map.ChunkScale.Y) * ZoomLevel + 6, (int)(_Map.ChunkScale.X) * ZoomLevel, (int)(_Map.ChunkScale.Y) * ZoomLevel);
                        Controls.Add(mcc);
                        Chunks.Add(cc, mcc);
                    }
                }
            }

            /*
             * foreach (KeyValuePair<Guid, Entity> k in _Map.Entities)
             * {
             *  Entity e = k.Value;
             *  if (e.Pos.X > min.X && e.Pos.X < max.X && e.Pos.Y > min.Y && e.Pos.Y < max.Y)
             *  {
             *      Button b = new Button();
             *      float x = (float)e.Pos.X + (float)min.X;
             *      float y = (float)e.Pos.Y + (float)min.Y;
             *      //b.SetBounds((int)y * ZoomLevel - 2, (int)y * ZoomLevel - 2, 16, 16);
             *      b.SetBounds((int)(e.Pos.X - min.X) * ZoomLevel, (int)(e.Pos.Y - min.Y) * ZoomLevel, 16, 16);
             *      b.Image = e.Image;
             *      b.UseVisualStyleBackColor = true;
             *      b.BackColor = Color.Transparent;
             *      b.FlatStyle = FlatStyle.Flat;
             *      b.ImageAlign = ContentAlignment.MiddleCenter;
             *      b.FlatAppearance.BorderSize = 1;
             *      b.FlatAppearance.BorderColor = Color.Black;
             *      b.FlatAppearance.MouseOverBackColor = Color.Transparent;
             *      b.Click += new EventHandler(OnEntityClicked);
             *      b.Tag = e;
             *      Controls.Add(b);
             *      EntityControls.Add(b);
             *      b.Show();
             *      b.BringToFront();
             *      Console.WriteLine("{0} {1} added to pos {2},{3}", e, e.UUID, b.Top, b.Left);
             *  }
             * }
             * foreach (KeyValuePair<Guid, TileEntity> k in _Map.TileEntities)
             * {
             *  TileEntity e = k.Value;
             *  if (e.Pos.X > min.X && e.Pos.X < max.X && e.Pos.Y > min.Y && e.Pos.Y < max.Y)
             *  {
             *      Button b = new Button();
             *      b.SetBounds((int)(e.Pos.X - min.X) * ZoomLevel + 6, (int)(e.Pos.Y - min.Y) * ZoomLevel + 6, 16, 16);
             *      b.Image = e.Image;
             *      b.UseVisualStyleBackColor = true;
             *      b.BackColor = Color.Transparent;
             *      b.FlatStyle = FlatStyle.Flat;
             *      b.ImageAlign = ContentAlignment.MiddleCenter;
             *      b.FlatAppearance.BorderSize = 1;
             *      b.FlatAppearance.BorderColor = Color.Black;
             *      b.FlatAppearance.MouseOverBackColor = Color.Transparent;
             *      b.Click += new EventHandler(OnTileEntityClicked);
             *      b.Tag = e;
             *      Controls.Add(b);
             *      EntityControls.Add(b);
             *      b.Show();
             *      b.BringToFront();
             *      Console.WriteLine("{0} {1} added to pos {2},{3}", e, e.UUID, b.Top, b.Left);
             *  }
             * }*/
        }