now plugins can add their own buttons to the toolbar

This commit is contained in:
codeimp 2008-05-26 12:14:48 +00:00
parent efdc703f94
commit 87ea1c0e51
8 changed files with 241 additions and 145 deletions

View file

@ -1,14 +1,7 @@
- All core builder modes must be config-specific so that anyone
can remove them to replace them with their own mode
- Change toolbar buttons
- Make seperate attribute for editing modes to create a button
- Make classes and attributes to manually add buttons to the toolbar
- Add log in main window for debug versions
- Make things filter
- Add log in main window for debug versions
- Change linedefs in configurations
- Proper formatting
- Enummed arguments support
@ -41,4 +34,5 @@
- Make dialog and editing mode help documentation
- Make Plugin Development Kit
- Add proper XML comments to classes, properties and methods

View file

@ -43,6 +43,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
this.thingsmenu = new System.Windows.Forms.ToolStripMenuItem();
this.rotatethingscwitem = new System.Windows.Forms.ToolStripMenuItem();
this.rotatethingsccwitem = new System.Windows.Forms.ToolStripMenuItem();
this.toolstrip = new System.Windows.Forms.ToolStrip();
this.menustrip.SuspendLayout();
this.SuspendLayout();
//
@ -167,10 +168,19 @@ namespace CodeImp.DoomBuilder.BuilderModes
this.rotatethingsccwitem.Size = new System.Drawing.Size(204, 22);
this.rotatethingsccwitem.Text = "Rotate Counterclockwise";
//
// toolstrip
//
this.toolstrip.Location = new System.Drawing.Point(0, 24);
this.toolstrip.Name = "toolstrip";
this.toolstrip.Size = new System.Drawing.Size(423, 25);
this.toolstrip.TabIndex = 1;
this.toolstrip.Text = "toolstrip";
//
// MenusForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(423, 248);
this.Controls.Add(this.toolstrip);
this.Controls.Add(this.menustrip);
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
@ -205,5 +215,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
private System.Windows.Forms.ToolStripMenuItem rotatethingsccwitem;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
private System.Windows.Forms.ToolStripMenuItem splitlinedefsitem;
private System.Windows.Forms.ToolStrip toolstrip;
}
}

View file

@ -42,7 +42,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Menus list
private ToolStripItem[] menus;
// Buttons list
private ToolStripItem[] buttons;
#endregion
#region ================== Properties
@ -64,6 +67,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
// List all menus
menus = new ToolStripItem[menustrip.Items.Count];
for(int i = 0; i < menustrip.Items.Count; i++) menus[i] = menustrip.Items[i];
// List all buttons
buttons = new ToolStripItem[toolstrip.Items.Count];
for(int i = 0; i < toolstrip.Items.Count; i++) buttons[i] = toolstrip.Items[i];
}
#endregion
@ -76,6 +83,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Add the menus to the core
foreach(ToolStripMenuItem m in menus)
General.Interface.AddMenu(m);
// Add the buttons to the core
foreach(ToolStripItem b in buttons)
General.Interface.AddButton(b);
}
// This unregisters from the core
@ -84,6 +95,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Remove the menus from the core
foreach(ToolStripMenuItem m in menus)
General.Interface.RemoveMenu(m);
// Remove the buttons from the core
foreach(ToolStripItem b in buttons)
General.Interface.RemoveButton(b);
}
// This hides all menus

View file

@ -120,4 +120,7 @@
<metadata name="menustrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolstrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>118, 17</value>
</metadata>
</root>

View file

@ -177,52 +177,52 @@ namespace CodeImp.DoomBuilder.Editing
General.MainWindow.UpdateCoordinates(new Vector2D(camanglexy, camanglez));
}
// Key down
public override void OnKeyDown(KeyEventArgs e)
[BeginAction("moveforward", BaseAction = true)]
public virtual void BeginMoveForward()
{
string[] actions;
base.OnKeyDown(e);
/* WRONG
// Get the actions for this key
actions = General.Actions.GetActionsByKey((int)e.KeyData);
foreach(string a in actions)
{
// Check what key was pressed down
switch(a)
{
case "moveforward": keyforward = true; break;
case "movebackward": keybackward = true; break;
case "moveleft": keyleft = true; break;
case "moveright": keyright = true; break;
}
}
*/
keyforward = true;
}
// Key up
public override void OnKeyUp(KeyEventArgs e)
[EndAction("moveforward", BaseAction = true)]
public virtual void EndMoveForward()
{
string[] actions;
keyforward = false;
}
base.OnKeyUp(e);
[BeginAction("movebackward", BaseAction = true)]
public virtual void BeginMoveBackward()
{
keybackward = true;
}
/* WRONG
// Get the actions for this key
actions = General.Actions.GetActionsByKey((int)e.KeyData);
foreach(string a in actions)
{
// Check what key was pressed down
switch(a)
{
case "moveforward": keyforward = false; break;
case "movebackward": keybackward = false; break;
case "moveleft": keyleft = false; break;
case "moveright": keyright = false; break;
}
}
*/
[EndAction("movebackward", BaseAction = true)]
public virtual void EndMoveBackward()
{
keybackward = false;
}
[BeginAction("moveleft", BaseAction = true)]
public virtual void BeginMoveLeft()
{
keyleft = true;
}
[EndAction("moveleft", BaseAction = true)]
public virtual void EndMoveLeft()
{
keyleft = false;
}
[BeginAction("moveright", BaseAction = true)]
public virtual void BeginMoveRight()
{
keyright = true;
}
[EndAction("moveright", BaseAction = true)]
public virtual void EndMoveRight()
{
keyright = false;
}
#endregion

View file

@ -94,5 +94,8 @@ namespace CodeImp.DoomBuilder.Interface
/// that you want to invoke.</param>
/// <param name="e">Unused.</param>
void InvokeTaggedAction(object sender, EventArgs e);
void AddButton(ToolStripItem button);
void RemoveButton(ToolStripItem button);
}
}

View file

@ -117,6 +117,7 @@ namespace CodeImp.DoomBuilder.Interface
this.redrawtimer = new System.Windows.Forms.Timer(this.components);
this.display = new CodeImp.DoomBuilder.Interface.RenderTargetControl();
this.processor = new System.Windows.Forms.Timer(this.components);
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
@ -470,7 +471,8 @@ namespace CodeImp.DoomBuilder.Interface
this.buttonsnaptogrid,
this.buttonautomerge,
this.toolStripSeparator5,
this.buttontest});
this.buttontest,
this.toolStripSeparator6});
this.toolbar.Location = new System.Drawing.Point(0, 24);
this.toolbar.Name = "toolbar";
this.toolbar.Size = new System.Drawing.Size(839, 25);
@ -945,6 +947,11 @@ namespace CodeImp.DoomBuilder.Interface
this.processor.Interval = 10;
this.processor.Tick += new System.EventHandler(this.processor_Tick);
//
// toolStripSeparator6
//
this.toolStripSeparator6.Name = "toolStripSeparator6";
this.toolStripSeparator6.Size = new System.Drawing.Size(6, 25);
//
// MainForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@ -1058,5 +1065,6 @@ namespace CodeImp.DoomBuilder.Interface
private System.Windows.Forms.ToolStripButton buttontest;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem5;
private System.Windows.Forms.ToolStripMenuItem itemtestmap;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
}
}

View file

@ -76,6 +76,9 @@ namespace CodeImp.DoomBuilder.Interface
// Edit modes
private List<ToolStripItem> editmodeitems;
// Toolbar
private EventHandler buttonvisiblechangedhandler;
#endregion
#region ================== Properties
@ -106,6 +109,9 @@ namespace CodeImp.DoomBuilder.Interface
buttongrid.Font = menufile.Font;
buttongrid.DropDownDirection = ToolStripDropDownDirection.AboveLeft;
// Event handlers
buttonvisiblechangedhandler = new EventHandler(ToolbarButtonVisibleChanged);
// Bind any methods
General.Actions.BindMethods(this);
@ -158,9 +164,6 @@ namespace CodeImp.DoomBuilder.Interface
string asmname;
this.Update();
//asmname = General.ThisAssembly.GetName().Name.ToLowerInvariant();
//General.Actions[asmname + "_" + (sender as ToolStripItem).Tag.ToString()].Begin();
//General.Actions[asmname + "_" + (sender as ToolStripItem).Tag.ToString()].End();
General.Actions[(sender as ToolStripItem).Tag.ToString()].Begin();
General.Actions[(sender as ToolStripItem).Tag.ToString()].End();
this.Update();
@ -524,98 +527,6 @@ namespace CodeImp.DoomBuilder.Interface
#endregion
#region ================== Toolbar
// This enables or disables all editing mode items
private void UpdateEditModeItems()
{
// Enable/disable all items
foreach(ToolStripItem i in editmodeitems) i.Enabled = (General.Map != null);
}
// This checks one of the edit mode items (and unchecks all others)
internal void CheckEditModeButton(string modeclassname)
{
// Go for all items
foreach(ToolStripItem i in editmodeitems)
{
// Check what type it is
if(i is ToolStripMenuItem)
{
// Check if mode type matches with given name
(i as ToolStripMenuItem).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
}
else if(i is ToolStripButton)
{
// Check if mode type matches with given name
(i as ToolStripButton).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
}
}
}
// This removes the config-specific editing mode buttons
internal void RemoveSpecificEditModeButtons()
{
bool removed;
do
{
// Go for all items
removed = false;
foreach(ToolStripItem i in editmodeitems)
{
// Only remove the button if it is for a config-specific editing mode
if((i.Tag as EditModeInfo).ConfigSpecific)
{
// Remove it and restart
editmodeitems.Remove(i);
toolbar.Items.Remove(i);
menuedit.DropDownItems.Remove(i);
removed = true;
break;
}
}
}
while(removed);
}
// This adds an editing mode button to the toolbar and edit menu
internal void AddEditModeButton(EditModeInfo modeinfo)
{
ToolStripItem item;
int index;
// Create a button
index = toolbar.Items.IndexOf(buttoneditmodesseperator);
item = new ToolStripButton(modeinfo.ButtonDesc, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
item.DisplayStyle = ToolStripItemDisplayStyle.Image;
item.Tag = modeinfo;
item.Enabled = (General.Map != null);
toolbar.Items.Insert(index, item);
editmodeitems.Add(item);
// Create menu item
index = menuedit.DropDownItems.IndexOf(itemeditmodesseperator);
item = new ToolStripMenuItem(modeinfo.ButtonDesc, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
item.Tag = modeinfo;
item.Enabled = (General.Map != null);
menuedit.DropDownItems.Insert(index, item);
editmodeitems.Add(item);
}
// This handles edit mode button clicks
private void EditModeButtonHandler(object sender, EventArgs e)
{
EditModeInfo modeinfo;
this.Update();
modeinfo = (EditModeInfo)((sender as ToolStripItem).Tag);
General.Actions[modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly)].Begin();
this.Update();
}
#endregion
#region ================== Display
// This shows the splash screen on display
@ -958,6 +869,157 @@ namespace CodeImp.DoomBuilder.Interface
#endregion
#region ================== Toolbar
// This adds a button to the toolbar
public void AddButton(ToolStripItem button)
{
// Find the plugin that called this method
Plugin plugin = General.Plugins.FindPluginByAssembly(Assembly.GetCallingAssembly());
// Fix tags to full action names
ToolStripItemCollection items = new ToolStripItemCollection(toolbar, new ToolStripItem[0]);
items.Add(button);
RenameTagsToFullActions(items, plugin);
// Bind visible changed event
if(!(button is ToolStripSeparator)) button.VisibleChanged += buttonvisiblechangedhandler;
// Insert the button at the end of the toolbar
toolbar.Items.Add(button);
UpdateSeperators();
}
// Removes a button
public void RemoveButton(ToolStripItem button)
{
// Unbind visible changed event
if(!(button is ToolStripSeparator)) button.VisibleChanged -= buttonvisiblechangedhandler;
// Remove button
toolbar.Items.Remove(button);
UpdateSeperators();
}
// This handle visibility changes in the toolbar buttons
private void ToolbarButtonVisibleChanged(object sender, EventArgs e)
{
// Update the seeprators
UpdateSeperators();
}
// This updates the seperators
// Hides redundant seperators and shows single seperators
private void UpdateSeperators()
{
ToolStripItem pvi = null;
foreach(ToolStripItem i in toolbar.Items)
{
// This is a seperator?
if(i is ToolStripSeparator)
{
// Make visible when previous item was not a seperator
i.Visible = !(pvi is ToolStripSeparator);
}
// Keep as previous visible item
if(i.Visible) pvi = i;
}
// Hide last item if it is a seperator
if(pvi is ToolStripSeparator) pvi.Visible = false;
}
// This enables or disables all editing mode items
private void UpdateEditModeItems()
{
// Enable/disable all items
foreach(ToolStripItem i in editmodeitems) i.Enabled = (General.Map != null);
}
// This checks one of the edit mode items (and unchecks all others)
internal void CheckEditModeButton(string modeclassname)
{
// Go for all items
foreach(ToolStripItem i in editmodeitems)
{
// Check what type it is
if(i is ToolStripMenuItem)
{
// Check if mode type matches with given name
(i as ToolStripMenuItem).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
}
else if(i is ToolStripButton)
{
// Check if mode type matches with given name
(i as ToolStripButton).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
}
}
}
// This removes the config-specific editing mode buttons
internal void RemoveSpecificEditModeButtons()
{
bool removed;
do
{
// Go for all items
removed = false;
foreach(ToolStripItem i in editmodeitems)
{
// Only remove the button if it is for a config-specific editing mode
if((i.Tag as EditModeInfo).ConfigSpecific)
{
// Remove it and restart
editmodeitems.Remove(i);
toolbar.Items.Remove(i);
menuedit.DropDownItems.Remove(i);
removed = true;
break;
}
}
}
while(removed);
}
// This adds an editing mode button to the toolbar and edit menu
internal void AddEditModeButton(EditModeInfo modeinfo)
{
ToolStripItem item;
int index;
// Create a button
index = toolbar.Items.IndexOf(buttoneditmodesseperator);
item = new ToolStripButton(modeinfo.ButtonDesc, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
item.DisplayStyle = ToolStripItemDisplayStyle.Image;
item.Tag = modeinfo;
item.Enabled = (General.Map != null);
toolbar.Items.Insert(index, item);
editmodeitems.Add(item);
// Create menu item
index = menuedit.DropDownItems.IndexOf(itemeditmodesseperator);
item = new ToolStripMenuItem(modeinfo.ButtonDesc, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
item.Tag = modeinfo;
item.Enabled = (General.Map != null);
menuedit.DropDownItems.Insert(index, item);
editmodeitems.Add(item);
}
// This handles edit mode button clicks
private void EditModeButtonHandler(object sender, EventArgs e)
{
EditModeInfo modeinfo;
this.Update();
modeinfo = (EditModeInfo)((sender as ToolStripItem).Tag);
General.Actions[modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly)].Begin();
this.Update();
}
#endregion
#region ================== Menus
// This adds a menu to the menus bar