mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-31 12:50:52 +00:00
actions can now be defined with ActionAttribute
This commit is contained in:
parent
1eedfae8bf
commit
3066b1bf68
8 changed files with 284 additions and 11 deletions
|
@ -1,7 +1,13 @@
|
||||||
|
|
||||||
shortcuts
|
shortcuts
|
||||||
{
|
{
|
||||||
|
scrolleast = 39;
|
||||||
|
scrollsouth = 40;
|
||||||
|
zoomout = 65531;
|
||||||
|
scrollnorth = 38;
|
||||||
|
scrollwest = 37;
|
||||||
newmap = 131150;
|
newmap = 131150;
|
||||||
|
zoomin = 65530;
|
||||||
openmap = 131151;
|
openmap = 131151;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +15,9 @@ shortcuts
|
||||||
mainwindow
|
mainwindow
|
||||||
{
|
{
|
||||||
positionx = 124;
|
positionx = 124;
|
||||||
sizeheight = 572;
|
|
||||||
positiony = 35;
|
|
||||||
windowstate = 2;
|
windowstate = 2;
|
||||||
|
positiony = 35;
|
||||||
|
sizeheight = 572;
|
||||||
sizewidth = 739;
|
sizewidth = 739;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Controls\ActionAttribute.cs" />
|
||||||
<Compile Include="Editing\EditMode.cs" />
|
<Compile Include="Editing\EditMode.cs" />
|
||||||
<Compile Include="Editing\FrozenOverviewMode.cs" />
|
<Compile Include="Editing\FrozenOverviewMode.cs" />
|
||||||
<Compile Include="Editing\ViewClassicMode.cs" />
|
<Compile Include="Editing\ViewClassicMode.cs" />
|
||||||
|
|
|
@ -37,6 +37,12 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
public const string SAVEMAP = "savemap";
|
public const string SAVEMAP = "savemap";
|
||||||
public const string SAVEMAPAS = "savemapas";
|
public const string SAVEMAPAS = "savemapas";
|
||||||
public const string SHOWOVERVIEW = "showoverview";
|
public const string SHOWOVERVIEW = "showoverview";
|
||||||
|
public const string SCROLLNORTH = "scrollnorth";
|
||||||
|
public const string SCROLLSOUTH = "scrollsouth";
|
||||||
|
public const string SCROLLWEST = "scrollwest";
|
||||||
|
public const string SCROLLEAST = "scrolleast";
|
||||||
|
public const string ZOOMIN = "zoomin";
|
||||||
|
public const string ZOOMOUT = "zoomout";
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
135
Source/Controls/ActionAttribute.cs
Normal file
135
Source/Controls/ActionAttribute.cs
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
|
||||||
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
||||||
|
* This program is released under GNU General Public License
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Namespaces
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace CodeImp.DoomBuilder.Controls
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Method, Inherited=true, AllowMultiple=true)]
|
||||||
|
internal class ActionAttribute : Attribute
|
||||||
|
{
|
||||||
|
#region ================== Variables
|
||||||
|
|
||||||
|
// The action to bind to
|
||||||
|
private string action;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Constructor / Disposer
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public ActionAttribute(string action)
|
||||||
|
{
|
||||||
|
// Initialize
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Static Methods
|
||||||
|
|
||||||
|
// This binds all methods marked with this attribute
|
||||||
|
public static void BindMethods(Type type)
|
||||||
|
{
|
||||||
|
// Bind static methods
|
||||||
|
BindMethods(null, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This binds all methods marked with this attribute
|
||||||
|
public static void BindMethods(object obj)
|
||||||
|
{
|
||||||
|
// Bind instance methods
|
||||||
|
BindMethods(obj, obj.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
// This binds all methods marked with this attribute
|
||||||
|
private static void BindMethods(object obj, Type type)
|
||||||
|
{
|
||||||
|
MethodInfo[] methods;
|
||||||
|
ActionAttribute[] attrs;
|
||||||
|
ActionDelegate del;
|
||||||
|
|
||||||
|
// Go for all methods on obj
|
||||||
|
methods = type.GetMethods();
|
||||||
|
foreach(MethodInfo m in methods)
|
||||||
|
{
|
||||||
|
// Check if the method has this attribute
|
||||||
|
attrs = (ActionAttribute[])m.GetCustomAttributes(typeof(ActionAttribute), true);
|
||||||
|
|
||||||
|
// Go for all attributes
|
||||||
|
foreach(ActionAttribute a in attrs)
|
||||||
|
{
|
||||||
|
// Create a delegate for this method
|
||||||
|
del = (ActionDelegate)Delegate.CreateDelegate(typeof(ActionDelegate), obj, m);
|
||||||
|
|
||||||
|
// Bind method to action
|
||||||
|
General.Actions[a.action].Bind(del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This unbinds all methods marked with this attribute
|
||||||
|
public static void UnbindMethods(Type type)
|
||||||
|
{
|
||||||
|
// Unbind static methods
|
||||||
|
UnbindMethods(null, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This unbinds all methods marked with this attribute
|
||||||
|
public static void UnbindMethods(object obj)
|
||||||
|
{
|
||||||
|
// Unbind instance methods
|
||||||
|
UnbindMethods(obj, obj.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
// This unbinds all methods marked with this attribute
|
||||||
|
private static void UnbindMethods(object obj, Type type)
|
||||||
|
{
|
||||||
|
MethodInfo[] methods;
|
||||||
|
ActionAttribute[] attrs;
|
||||||
|
ActionDelegate del;
|
||||||
|
|
||||||
|
// Go for all methods on obj
|
||||||
|
methods = type.GetMethods();
|
||||||
|
foreach(MethodInfo m in methods)
|
||||||
|
{
|
||||||
|
// Check if the method has this attribute
|
||||||
|
attrs = (ActionAttribute[])m.GetCustomAttributes(typeof(ActionAttribute), true);
|
||||||
|
|
||||||
|
// Go for all attributes
|
||||||
|
foreach(ActionAttribute a in attrs)
|
||||||
|
{
|
||||||
|
// Create a delegate for this method
|
||||||
|
del = (ActionDelegate)Delegate.CreateDelegate(typeof(ActionDelegate), obj, m);
|
||||||
|
|
||||||
|
// Unbind method from action
|
||||||
|
General.Actions[a.action].Unbind(del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ using CodeImp.DoomBuilder.IO;
|
||||||
using CodeImp.DoomBuilder.Map;
|
using CodeImp.DoomBuilder.Map;
|
||||||
using CodeImp.DoomBuilder.Rendering;
|
using CodeImp.DoomBuilder.Rendering;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using CodeImp.DoomBuilder.Controls;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -65,6 +66,9 @@ namespace CodeImp.DoomBuilder.Editing
|
||||||
// Initialize
|
// Initialize
|
||||||
this.graphics = General.Map.Graphics;
|
this.graphics = General.Map.Graphics;
|
||||||
|
|
||||||
|
// Bind any methods
|
||||||
|
ActionAttribute.BindMethods(this);
|
||||||
|
|
||||||
// We have no destructor
|
// We have no destructor
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
@ -75,6 +79,9 @@ namespace CodeImp.DoomBuilder.Editing
|
||||||
// Not already disposed?
|
// Not already disposed?
|
||||||
if(!isdisposed)
|
if(!isdisposed)
|
||||||
{
|
{
|
||||||
|
// Unbind any methods
|
||||||
|
ActionAttribute.UnbindMethods(this);
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
|
|
|
@ -28,6 +28,7 @@ using CodeImp.DoomBuilder.Interface;
|
||||||
using CodeImp.DoomBuilder.IO;
|
using CodeImp.DoomBuilder.IO;
|
||||||
using CodeImp.DoomBuilder.Map;
|
using CodeImp.DoomBuilder.Map;
|
||||||
using CodeImp.DoomBuilder.Rendering;
|
using CodeImp.DoomBuilder.Rendering;
|
||||||
|
using CodeImp.DoomBuilder.Controls;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -74,7 +75,71 @@ namespace CodeImp.DoomBuilder.Editing
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Methods
|
#region ================== Scroll / Zoom
|
||||||
|
|
||||||
|
// This scrolls the view north
|
||||||
|
[Action(Action.SCROLLNORTH)]
|
||||||
|
public void ScrollNorth()
|
||||||
|
{
|
||||||
|
// Scroll
|
||||||
|
ScrollBy(0f, 100f / renderer.Scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This scrolls the view south
|
||||||
|
[Action(Action.SCROLLSOUTH)]
|
||||||
|
public void ScrollSouth()
|
||||||
|
{
|
||||||
|
// Scroll
|
||||||
|
ScrollBy(0f, -100f / renderer.Scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This scrolls the view west
|
||||||
|
[Action(Action.SCROLLWEST)]
|
||||||
|
public void ScrollWest()
|
||||||
|
{
|
||||||
|
// Scroll
|
||||||
|
ScrollBy(-100f / renderer.Scale, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This scrolls the view east
|
||||||
|
[Action(Action.SCROLLEAST)]
|
||||||
|
public void ScrollEast()
|
||||||
|
{
|
||||||
|
// Scroll
|
||||||
|
ScrollBy(100f / renderer.Scale, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This zooms in
|
||||||
|
[Action(Action.ZOOMIN)]
|
||||||
|
public void ZoomIn()
|
||||||
|
{
|
||||||
|
// Zoom
|
||||||
|
ZoomBy(0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This zooms out
|
||||||
|
[Action(Action.ZOOMOUT)]
|
||||||
|
public void ZoomOut()
|
||||||
|
{
|
||||||
|
// Zoom
|
||||||
|
ZoomBy(-0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This scrolls anywhere
|
||||||
|
private void ScrollBy(float deltax, float deltay)
|
||||||
|
{
|
||||||
|
// Scroll now
|
||||||
|
renderer.PositionView(renderer.OffsetX + deltax, renderer.OffsetY + deltay);
|
||||||
|
RedrawDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This zooms
|
||||||
|
private void ZoomBy(float deltaz)
|
||||||
|
{
|
||||||
|
// Zoom now
|
||||||
|
renderer.ScaleView(renderer.Scale + deltaz);
|
||||||
|
RedrawDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,10 +198,8 @@ namespace CodeImp.DoomBuilder
|
||||||
// Create action manager
|
// Create action manager
|
||||||
actions = new ActionManager();
|
actions = new ActionManager();
|
||||||
|
|
||||||
// Bind my methods to actions
|
// Bind static methods to actions
|
||||||
actions[Action.NEWMAP].Bind(new ActionDelegate(NewMap));
|
ActionAttribute.BindMethods(typeof(General));
|
||||||
actions[Action.OPENMAP].Bind(new ActionDelegate(OpenMap));
|
|
||||||
actions[Action.CLOSEMAP].Bind(new ActionDelegate(CloseMap));
|
|
||||||
|
|
||||||
// Create main window
|
// Create main window
|
||||||
mainwindow = new MainForm();
|
mainwindow = new MainForm();
|
||||||
|
@ -226,10 +224,8 @@ namespace CodeImp.DoomBuilder
|
||||||
// This terminates the program
|
// This terminates the program
|
||||||
public static void Terminate()
|
public static void Terminate()
|
||||||
{
|
{
|
||||||
// Unbind my methods to actions
|
// Unbind static methods from actions
|
||||||
actions[Action.NEWMAP].Unbind(new ActionDelegate(NewMap));
|
ActionAttribute.UnbindMethods(typeof(General));
|
||||||
actions[Action.OPENMAP].Unbind(new ActionDelegate(OpenMap));
|
|
||||||
actions[Action.CLOSEMAP].Unbind(new ActionDelegate(CloseMap));
|
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
mainwindow.Dispose();
|
mainwindow.Dispose();
|
||||||
|
@ -247,6 +243,7 @@ namespace CodeImp.DoomBuilder
|
||||||
#region ================== Management
|
#region ================== Management
|
||||||
|
|
||||||
// This creates a new map
|
// This creates a new map
|
||||||
|
[Action(Action.NEWMAP)]
|
||||||
public static void NewMap()
|
public static void NewMap()
|
||||||
{
|
{
|
||||||
MapOptions newoptions = new MapOptions();
|
MapOptions newoptions = new MapOptions();
|
||||||
|
@ -294,6 +291,7 @@ namespace CodeImp.DoomBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// This closes the current map
|
// This closes the current map
|
||||||
|
[Action(Action.CLOSEMAP)]
|
||||||
public static void CloseMap()
|
public static void CloseMap()
|
||||||
{
|
{
|
||||||
// Ask the user to save changes (if any)
|
// Ask the user to save changes (if any)
|
||||||
|
@ -316,6 +314,7 @@ namespace CodeImp.DoomBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// This loads a map from file
|
// This loads a map from file
|
||||||
|
[Action(Action.OPENMAP)]
|
||||||
public static void OpenMap()
|
public static void OpenMap()
|
||||||
{
|
{
|
||||||
OpenFileDialog openfile;
|
OpenFileDialog openfile;
|
||||||
|
|
|
@ -31,3 +31,57 @@ closemap
|
||||||
allowmouse = false;
|
allowmouse = false;
|
||||||
allowscroll = false;
|
allowscroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scrollwest
|
||||||
|
{
|
||||||
|
title = "2D: Scroll West";
|
||||||
|
description = "Scrolls the 2D map view to the left.";
|
||||||
|
allowkeys = true;
|
||||||
|
allowmouse = true;
|
||||||
|
allowscroll = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrolleast
|
||||||
|
{
|
||||||
|
title = "2D: Scroll East";
|
||||||
|
description = "Scrolls the 2D map view to the right.";
|
||||||
|
allowkeys = true;
|
||||||
|
allowmouse = true;
|
||||||
|
allowscroll = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollnorth
|
||||||
|
{
|
||||||
|
title = "2D: Scroll North";
|
||||||
|
description = "Scrolls the 2D map view to the north.";
|
||||||
|
allowkeys = true;
|
||||||
|
allowmouse = true;
|
||||||
|
allowscroll = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollsouth
|
||||||
|
{
|
||||||
|
title = "2D: Scroll South";
|
||||||
|
description = "Scrolls the 2D map view to the south.";
|
||||||
|
allowkeys = true;
|
||||||
|
allowmouse = true;
|
||||||
|
allowscroll = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
zoomin
|
||||||
|
{
|
||||||
|
title = "2D: Zoom In";
|
||||||
|
description = "Zooms in on the map at the current mouse location.";
|
||||||
|
allowkeys = true;
|
||||||
|
allowmouse = true;
|
||||||
|
allowscroll = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
zoomout
|
||||||
|
{
|
||||||
|
title = "2D: Zoom Out";
|
||||||
|
description = "Zooms out on the map from the current mouse location.";
|
||||||
|
allowkeys = true;
|
||||||
|
allowmouse = true;
|
||||||
|
allowscroll = true;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue