Picture at the bottom
The code also has the method _x and _y which I found extremely useful in making the gui.
The plugin is pretty self explanatory so not much else to talk about.
- Code: Select all
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
namespace MCDzienny.Plugins
{
public class LevelShare : Plugin
{
// The name of the plugin.
string name = "Command Add";
// A relatively short description of the plugin.
string description = "Add a command easily.";
// 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.0";
// 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 GuiExample();
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()
{
}
public override void Terminate()
{
}
}
}
namespace MCDzienny.Plugins
{
public partial class GuiExample : UserControl
{
public GuiExample()
{
InitializeComponent();
}
}
}
namespace MCDzienny.Plugins
{
partial class GuiExample
{
private string cmdname;
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void Add_Command(object sender, EventArgs e)
{
try
{
if (commandname.Text.Length == 0)
{
MessageBox.Show("Command name cannot be left blank");
return;
}
cmdname = commandname.Text;
if (code.Text.Length == 0)
{
MessageBox.Show("Code cannot be left blank");
return;
}
if (File.Exists(@"extra\\commands\\source\\Cmd" + cmdname + ".cs") && Override.Checked != true)
{
MessageBox.Show("Command already exists");
return;
}
//transfer code to a code file
File.WriteAllText(@"extra\\commands\\source\\Cmd" + cmdname + ".cs", code.Text);
string done = "";
if (compile.Checked)
{
Command.all.Find("compile").Use(null, cmdname);
done += "+compile ";
}
if (unload.Checked)
{
Command.all.Find("cmdunload").Use(null, cmdname);
done += "+unload ";
}
if (load.Checked)
{
Command.all.Find("cmdload").Use(null, cmdname);
done += "+load ";
}
if (cmdautoload.Checked)
{
if (!File.ReadAllText("text/cmdautoload.txt").Contains(cmdname))
{
File.AppendAllText("text/cmdautoload.txt", Environment.NewLine + cmdname);
done += "+auto ";
}
else
{
MessageBox.Show(cmdname + " is already on the autoload list");
}
}
MessageBox.Show("Command added " + done);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Clear_Click(object sender, EventArgs e)
{
code.Text = "";
commandname.Text = "";
}
private int _x(Control x)
{
return Convert.ToInt32(x.Size.Width + x.Location.X + 10);
}
private int _y(Control y)
{
return Convert.ToInt32(y.Height + y.Location.Y + 10);
}
private void InitializeComponent()
{
try
{
lcode = new Label();
lname = new Label();
lcs = new Label();
Clear = new Button();
Override = new CheckBox();
compile = new CheckBox();
unload = new CheckBox();
load = new CheckBox();
cmdautoload = new CheckBox();
code = new TextBox();
commandname = new TextBox();
Cmdadd = new Button();
SuspendLayout();
//Top Labels
lcode.AutoSize = lcs.AutoSize = lname.AutoSize = true;
lcode.TabIndex = lcs.TabIndex = lname.TabIndex = 0;
lcode.ForeColor = lcs.ForeColor = lname.ForeColor = Color.Black;
lcode.Location = new Point(10, 10);
lcode.Name = "label1";
lcode.Size = new Size(40, 20);
lcode.Text = "Code:";
lcode.Font = lcs.Font = lname.Font = new Font("Courier New", 12F);
//
// code : TextBox
//
code.Location = new Point(10, _y(lcode) - 10);
code.Name = "code";
code.Size = new Size(480, 500);
code.TabIndex = 0;
code.Multiline = true;
code.ScrollBars = ScrollBars.Vertical;
//
// CHECKBOXES
//
this.compile.AutoSize = unload.AutoSize = load.AutoSize = cmdautoload.AutoSize = Override.AutoSize = true;
this.compile.Size = unload.Size = load.Size = cmdautoload.Size = Override.Size = new Size(80, 20);
this.compile.TabIndex = unload.TabIndex = load.TabIndex = cmdautoload.TabIndex = Override.TabIndex = 0;
this.compile.UseVisualStyleBackColor = unload.UseVisualStyleBackColor = load.UseVisualStyleBackColor = cmdautoload.UseVisualStyleBackColor = Override.UseVisualStyleBackColor = false;
//^same for all checkboxes
this.compile.Text = compile.Name = "Compile";
this.compile.Location = new Point(10, _y(code));
unload.Text = unload.Name = "Unload";
unload.Location = new Point(_x(compile), compile.Location.Y);
load.Text = load.Name = "load";
load.Location = new Point(_x(unload), compile.Location.Y);
cmdautoload.Text = cmdautoload.Name = "cmdautoload";
cmdautoload.Location = new Point(_x(load), compile.Location.Y);
Override.Text = Override.Name = "override";
Override.Location = new Point(_x(cmdautoload), compile.Location.Y);
//
// Cmdadd : Button
//
Cmdadd.BackColor = Clear.BackColor = Color.Black;
Cmdadd.ForeColor = Clear.ForeColor = Color.Yellow;
Cmdadd.Location = new Point(10, _y(compile));
Cmdadd.Name = "download";
Cmdadd.Size = new Size(480, 25);
Cmdadd.TabIndex = 0;
Cmdadd.Text = "Add!";
Cmdadd.UseVisualStyleBackColor = Clear.UseVisualStyleBackColor = false;
Cmdadd.Click += new EventHandler(Add_Command);
//Cmd label
lname.Location = new Point(10, _y(Cmdadd)+3);
lname.Name = "Cmd";
lname.Size = new Size(40, 40);
lname.Text = "Cmd";
// Command name : Textbox
commandname.Location = new Point(_x(lname) - 15, _y(Cmdadd));
commandname.Name = "cmdname";
commandname.Size = new Size(50, 30);
commandname.TabIndex = 0;
//.cs label
lcs.Location = new Point(_x(commandname) - 15, _y(Cmdadd) + 3);
lcs.Name = ".cs";
lcs.Size = new Size(40, 40);
lcs.Text = ".cs";
// clear : Button
Clear.Location = new Point(_x(lcs)+10, commandname.Location.Y);
Clear.Name = "clear text";
Clear.Size = new Size(340, 30);
Clear.TabIndex = 0;
Clear.Text = "Clear Text";
Clear.Click += new EventHandler(Clear_Click);
//
// Gui
//
AutoScaleDimensions = new SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.LightSlateGray;
Name = "Gui";
Size = new Size(465, 378);
Controls.Add(Cmdadd);
Controls.Add(code);
Controls.Add(compile);
Controls.Add(unload);
Controls.Add(load);
Controls.Add(cmdautoload);
Controls.Add(Override);
Controls.Add(commandname);
Controls.Add(Clear);
Controls.Add(lcode);
Controls.Add(lcs);
Controls.Add(lname);
ResumeLayout(false);
PerformLayout();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
private Label lcode, lname, lcs;
private Button Cmdadd, Clear;
private TextBox code, commandname;
private CheckBox compile, unload, load, cmdautoload, Override;
}
}