Example #1
0
 /// <summary>
 /// Initialize and set up events for this MapChunk.
 /// </summary>
 /// <param name="mc">Parent mapcontrol</param>
 /// <param name="pos">Position of chunk</param>
 /// <param name="sz">Chunk size</param>
 public MapChunkControl(MapControl mc, Vector3i pos, Vector3i sz)
 {
     parent        = mc;
     Map           = parent.Map;
     AssignedChunk = pos;
     ChunkSize     = sz;
     MyChunk       = Map.GetChunk(AssignedChunk);
     //Console.WriteLine("{0}: Chunk ({1},{2}), origin ({3},{4}), size {5}", this, pos.X, pos.Y, pos.X * sz.X, pos.Y * sz.Y, sz);
     InitializeComponent();
     Paint += new PaintEventHandler(MapChunkControl_Paint);
 }
Example #2
0
 void Reload()
 {
     MyChunk = Map.GetChunk(ChunkPos);
     if (MyChunk == null)
     {
         return;
     }
     txtChunkCoords.Text = string.Format("({0},{1})", ChunkPos.X, ChunkPos.Y);
     txtChunkFile.Text   = MyChunk.Filename;
     txtChunkSz.Text     = MyChunk.Size.ToString();
     txtCreation.Text    = MyChunk.CreationDate.ToShortDateString();
     txtMaxMin.Text      = string.Format("{0}m max, {1}m min", MyChunk.MaxHeight, MyChunk.MinHeight);
 }
Example #3
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));
            }
        }