muddesigner/VisualDesigner/frmDesigner.cs
Scionwest_cp d6a999c729 Visual Designer:
* Can now add multiple tabs when dragging objects onto the designer
 * Object properties are shown in the propertygrid when tabs are swapped.
 * Dragging an object onto any tab will create a new tab for that object.
2009-11-14 09:48:43 -08:00

123 lines
4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ManagedScripting;
using MUDEngine;
using MUDEngine.Objects;
using MUDEngine.Objects.Environment;
using MUDEngine.FileSystem;
namespace VisualDesigner
{
public partial class frmMain : Form
{
ScriptingEngine engine = new ScriptingEngine();
ScriptObject currentScript;
Type[] types;
object movingObject;
public frmMain()
{
InitializeComponent();
engine.LoadAssembly(Application.StartupPath + "/MUDEngine.dll");
types = engine.GetAssembly.GetTypes();
currentScript = new ScriptObject();
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void frmMain_Load(object sender, EventArgs e)
{
//Load the engine
engine.LoadAssembly(Application.StartupPath + "/MUDEngine.dll");
Type[] foundTypes = engine.GetAssembly.GetTypes();
Button button = new Button();
List<Type> tempTypes = new List<Type>();
ListBox lst = new ListBox();
lst.Sorted = true;
foreach (Type t in foundTypes)
{
if (t.BaseType.Name == "BaseObject")
{
tempTypes.Add(t);
lst.Items.Add(t.Name);
}
}
foreach (string t in lst.Items)
{
button = new Button();
button.Width = flowLayoutPanel1.Width - 10;
button.Text = t;
button.AllowDrop = true;
button.MouseDown += new MouseEventHandler(newObject_MouseDown);
button.FlatStyle = FlatStyle.Flat;
flowLayoutPanel1.Controls.Add(button);
}
propertyGrid1.ViewForeColor = Color.Blue;
propertyGrid1.SelectedObject = engine;
}
void newObject_MouseDown(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
movingObject = button;
DoDragDrop(button, DragDropEffects.Copy);
}
private void page1_DragDrop(object sender, DragEventArgs e)
{
if (movingObject is Button)
{
Button button = (Button)movingObject;
foreach (Type t in types)
{
if (t.Name == button.Text)
{
engine.InstanceObject(t, null);
currentScript = engine.GetObject(t.Name);
propertyGrid1.SelectedObject = currentScript.Instance;
if (page1.Text == "Empty")
{
page1.Text = currentScript.Name;
}
else
{
TabPage tab = new TabPage(currentScript.Name);
tab.DragDrop +=new DragEventHandler(page1_DragDrop);
tab.DragEnter += new DragEventHandler(page1_DragEnter);
tab.AllowDrop = true;
tabControl1.TabPages.Add(tab);
tabControl1.SelectedTab = tab;
}
}
}
}
}
private void page1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
currentScript = engine.GetObject(tabControl1.SelectedTab.Text);
propertyGrid1.SelectedObject = currentScript.Instance;
}
}
}