It allows you to view a map from console.
The plugin just shows what it your map would typically look like from a top view.
Any suggestions/questions welcome !
- Code: Select all
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace MCDzienny.Plugins
{
public class MapView : Plugin
{
// The name of the plugin.
string name = "MapView";
// A relatively short description of the plugin.
string description = "View a map from outside the game";
// A name or names of the authors of the plugin.
string author = "ismellike";
// A version number that is displayed to the end users.
string version = "1.1";
// A version number that is used for update checking. It's an absolute number that
// represents a release number. It should be incremented by 1 each time the new version
// is released.
int versionNumber = 1;
// A user control that contains graphical user interface of the plugin.
UserControl gui = new MapView_GUI();
public override string Description
{
get { return description; }
}
public override string Author
{
get { return author; }
}
public override string Name
{
get { return name; }
}
public override UserControl MainInterface
{
get { return gui; }
}
public override string Version
{
get { return version; }
}
public override int VersionNumber
{
get { return versionNumber; }
}
public override void Initialize()
{
if (!Directory.Exists("extra/plugins"))
{
Directory.CreateDirectory("extra/plugins");
}
if (!Directory.Exists("extra/plugins/appdata"))
{
Directory.CreateDirectory("extra/plugins/appdata");
}
}
public override void Terminate()
{
}
}
}
namespace MCDzienny.Plugins
{
public partial class MapView_GUI : UserControl
{
public MapView_GUI()
{
InitializeComponent();
}
}
}
namespace MCDzienny.Plugins
{
partial class MapView_GUI
{
public bool ignoreAdminium = false;
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void button1_Click(object sender, EventArgs e)
{
try
{
Level level = Level.Load(comboBox1.Text);
if (level == null)
{
MessageBox.Show("Level not found");
return;
}
ushort x = level.width;
ushort z = level.depth;
ushort y = level.height;
x -= 1; y -= 1; z -= 1;
Bitmap bm = new Bitmap(x + 1, z + 1);
for (ushort b = 0; b <= z; b++)
for (ushort a = 0; a <= x; a++)
{
bm.SetPixel(b, a, GetColor(b, y, a, level));
}
int mult = 1;
foreach (Control c in Controls)
if (c is RadioButton)
if (((RadioButton)c).Checked)
{
mult = Convert.ToInt32(c.Name);
}
pictureBox1.Image = ResizeBitmap(bm, bm.Width * mult, bm.Height * mult);
if (level.PlayersCount == 0)
level.unload = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Bitmap ResizeBitmap(Image image, int width, int height)
{
Image originalImage = image;
Bitmap result = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(result))
using (SolidBrush brush = new SolidBrush(Color.Red))
{
g.DrawImage(originalImage, 0, 0, width, height);
}
return result;
}
Color GetColor(ushort x, ushort y, ushort z, Level level)
{
byte block = level.GetTile(x, y, z);
string name = Block.Name(block);
if (block == Block.air)
return GetColor(x, (ushort)(y - 1), z, level);
if (block == Block.Zero)
return Color.White;
if (Block.Walkthrough(block))
{
if (name.Contains("water"))
return Color.CadetBlue;
if (name.Contains("lava"))
return Color.DarkRed;
}
if (name[0] == 'g')
{
if (name.Contains("grass"))
return Color.LawnGreen;
if (name.Contains("glass"))
return Color.Transparent;
if (name.Contains("gold"))
return Color.Gold;
}
if (name[0] == 'b')
{
if (name.Contains("brick"))
return Color.IndianRed;
if (name.Contains("blue"))
return Color.Blue;
if (name.Contains("black"))
return Color.Black;
}
if (name[0] == 'c')
{
if (name.Contains("cobblestone"))
return Color.DimGray;
if (name.Contains("cyan"))
return Color.Cyan;
}
if (name[0] == 's')
{
if (name.Contains("sand"))
return Color.LightGoldenrodYellow;
if (name.Contains("stair"))
return Color.LightSlateGray;
if (name.Contains("stone"))
return Color.SlateGray;
}
if (name[0] == 'w')
{
if (name.Contains("wood"))
return Color.SandyBrown;
if (name.Contains("white"))
return Color.White;
}
if (name.Contains("dirt"))
return Color.SaddleBrown;
if (name.Contains("tree"))
return Color.Brown;
if (name.Contains("adminium") && !checkBox1.Checked)
return Color.DarkMagenta;
if (name.Contains("red"))
return Color.Red;
if (name.Contains("yellow"))
return Color.Yellow;
if (name.Contains("green"))
return Color.Green;
if (name.Contains("tnt"))
return Color.Maroon;
if (name.Contains("obsidian"))
return Color.DarkGray;
if (name.Contains("iron"))
return Color.Silver;
if (name.Contains("pink"))
return Color.Pink;
if (name.Contains("leaves"))
return Color.ForestGreen;
if (y <= 0)
return GetColor(x, (ushort)(y - 1), z, level);
else
return Color.White;
}
bool @bool = false;
private void comboBox1_Click(object sender, EventArgs e)
{
if (@bool == false)
{
foreach (string fi in Directory.GetFiles("levels"))
{
if (fi.Contains(".lvl") && !fi.Contains(".backup"))
{
comboBox1.Items.Add(fi.Substring(0, fi.LastIndexOf('.')).Split('\\')[1]);
}
}
@bool = true;
}
}
private void InitializeComponent()
{
try
{
button1 = new Button();
pictureBox1 = new PictureBox();
comboBox1 = new ComboBox();
label1 = new Label();
radioButton1 = new RadioButton();
radioButton2 = new RadioButton();
radioButton3 = new RadioButton();
radioButton4 = new RadioButton();
radioButton5 = new RadioButton();
checkBox1 = new CheckBox();
((System.ComponentModel.ISupportInitialize)(pictureBox1)).BeginInit();
SuspendLayout();
//
// button1
//
button1.BackColor = Color.White;
button1.Location = new Point(12, 563);
button1.Name = "button1";
button1.Size = new Size(480, 74);
button1.TabIndex = 0;
button1.Text = "Generate";
button1.UseVisualStyleBackColor = false;
button1.Click += new EventHandler(button1_Click);
//
// pictureBox1
//
pictureBox1.Location = new Point(12, 12);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(480, 464);
pictureBox1.TabIndex = 1;
pictureBox1.TabStop = false;
//
// comboBox1
//
comboBox1.FormattingEnabled = true;
comboBox1.Location = new Point(244, 535);
comboBox1.Name = "comboBox1";
comboBox1.Size = new Size(248, 22);
comboBox1.TabIndex = 2;
comboBox1.Click += new EventHandler(comboBox1_Click);
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(208, 538);
label1.Name = "label1";
label1.Size = new Size(30, 14);
label1.TabIndex = 3;
label1.Text = "Map";
//
// radioButton1
//
radioButton1.AutoSize = true;
radioButton1.Location = new Point(402, 482);
radioButton1.Name = "1";
radioButton1.Size = new Size(38, 18);
radioButton1.TabIndex = 4;
radioButton1.TabStop = true;
radioButton1.Text = "x1";
radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
radioButton2.AutoSize = true;
radioButton2.Location = new Point(306, 482);
radioButton2.Name = "2";
radioButton2.Size = new Size(38, 18);
radioButton2.TabIndex = 5;
radioButton2.TabStop = true;
radioButton2.Text = "x2";
radioButton2.UseVisualStyleBackColor = true;
//
// radioButton3
//
radioButton3.AutoSize = true;
radioButton3.Location = new Point(210, 482);
radioButton3.Name = "3";
radioButton3.Size = new Size(38, 18);
radioButton3.TabIndex = 6;
radioButton3.TabStop = true;
radioButton3.Text = "x3";
radioButton3.UseVisualStyleBackColor = true;
//
// radioButton4
//
radioButton4.AutoSize = true;
radioButton4.Location = new Point(114, 482);
radioButton4.Name = "4";
radioButton4.Size = new Size(38, 18);
radioButton4.TabIndex = 7;
radioButton4.TabStop = true;
radioButton4.Text = "x4";
radioButton4.UseVisualStyleBackColor = true;
//
// radioButton5
//
radioButton5.AutoSize = true;
radioButton5.Location = new Point(12, 482);
radioButton5.Name = "5";
radioButton5.Size = new Size(38, 18);
radioButton5.TabIndex = 8;
radioButton5.TabStop = true;
radioButton5.Text = "x5";
radioButton5.UseVisualStyleBackColor = true;
//
// checkBox1
//
checkBox1.AutoSize = true;
checkBox1.Location = new Point(36, 534);
checkBox1.Name = "checkBox1";
checkBox1.Size = new Size(116, 18);
checkBox1.TabIndex = 9;
checkBox1.Text = "Ignore Adminium?";
checkBox1.UseVisualStyleBackColor = true;
//
// GUI
//
AutoScaleDimensions = new SizeF(6F, 14F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.White;
ClientSize = new Size(504, 504);
Controls.Add(checkBox1);
Controls.Add(radioButton5);
Controls.Add(radioButton4);
Controls.Add(radioButton3);
Controls.Add(radioButton2);
Controls.Add(radioButton1);
Controls.Add(label1);
Controls.Add(comboBox1);
Controls.Add(pictureBox1);
Controls.Add(button1);
Font = new Font("Miramonte", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
ForeColor = Color.Black;
Name = "GUI";
Text = "GUI";
((System.ComponentModel.ISupportInitialize)(pictureBox1)).EndInit();
ResumeLayout(false);
PerformLayout();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
private Button button1;
private PictureBox pictureBox1;
public ComboBox comboBox1;
private Label label1;
private RadioButton radioButton1;
private RadioButton radioButton2;
private RadioButton radioButton3;
private RadioButton radioButton4;
private RadioButton radioButton5;
private CheckBox checkBox1;
}
}
Here is an example of a 526x526 map(I think)
--v1.1 made load on startup faster for servers with lots of maps.