"Snap Selected Vertices to Grid" mode: renamed to "Snap Selected Map Elements to Grid". Now it aligns things as well.

Edit forms: some realtime controls were applying relative values incorrectly.
This commit is contained in:
MaxED 2013-08-22 15:30:50 +00:00
parent 710a1227ce
commit 9080f8885c
10 changed files with 103 additions and 85 deletions

View file

@ -900,10 +900,10 @@
<td>Opens the window, which lets user to change textures, which will be used in next drawing operations.</td>
</tr>
<tr>
<td>Snap Selected Vertices to Grid</td>
<td><a href="features/classic_modes/mode_snapverts.html">Snap Selected Map Elements to Grid</a></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td>Snaps selected vertices to grid.</td>
<td>Snaps selected map elements to grid.</td>
</tr>
<tr>
<td>Snap to Grid</td>

View file

@ -13,13 +13,15 @@
<param name="keyword" value="Template">
</object>
<div id="gz_title"><h1>Snap selected vertices to grid mode</h1></div>
<div id="gz_title">
<h1>Snap selected map elements to grid mode</h1>
</div>
<div id="contents">
<p>
Activate this mode to snap selected vertices to the current grid.<br>
<b>Menu:</b> Edit -> Snap selected vertices to the grid.<br>
Activate this mode to snap selected map elements to the current grid.<br>
<b>Menu:</b> Edit -> Snap selected map elements to the grid.<br>
<b>Found in:</b> Preferences -> Controls -> Drawing.<br>
<b>Default key:</b> none.<br>
</div>
</div>
</body>

View file

@ -194,7 +194,6 @@ namespace CodeImp.DoomBuilder.Controls
public int GetResult(int original)
{
string textpart = this.Text;
int result;
// Strip prefixes
textpart = textpart.Replace("+", "");
@ -203,35 +202,33 @@ namespace CodeImp.DoomBuilder.Controls
// Any numbers left?
if(textpart.Length > 0)
{
int result;
// Prefixed with ++?
if(this.Text.StartsWith("++"))
{
// Add number to original
if(!int.TryParse(textpart, out result)) result = 0;
int.TryParse(textpart, out result);
return original + result;
}
// Prefixed with --?
else if(this.Text.StartsWith("--"))
if(this.Text.StartsWith("--"))
{
// Subtract number from original
if(!int.TryParse(textpart, out result)) result = 0;
int.TryParse(textpart, out result);
int newvalue = original - result;
if(!allownegative && (newvalue < 0)) newvalue = 0;
return newvalue;
}
else
{
//mxd. Return the new value
if(!int.TryParse(this.Text, out result)) return original;
if(!allownegative && (result < 0)) return 0;
return result;
}
}
else
{
// Nothing given, keep original value
return original;
//mxd. Return the new value
if(!int.TryParse(this.Text, out result)) return original;
if(!allownegative && (result < 0)) return 0;
return result;
}
// Nothing given, keep original value
return original;
}
// This determines the result value

View file

@ -266,17 +266,16 @@ namespace CodeImp.DoomBuilder.Windows
UpdateSectorHeight();
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(ceilingheight.Text)) {
int i = 0;
foreach(Sector s in sectors)
s.CeilHeight = sectorProps[i++].CeilHeight;
//update values
} else {
foreach(Sector s in sectors)
s.CeilHeight = ceilingheight.GetResult(s.CeilHeight);
foreach(Sector s in sectors)
s.CeilHeight = ceilingheight.GetResult(sectorProps[i++].CeilHeight);
}
General.Map.IsChanged = true;
@ -289,17 +288,16 @@ namespace CodeImp.DoomBuilder.Windows
UpdateSectorHeight();
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(floorheight.Text)) {
int i = 0;
foreach(Sector s in sectors)
s.FloorHeight = sectorProps[i++].FloorHeight;
//update values
} else {
foreach(Sector s in sectors)
s.FloorHeight = floorheight.GetResult(s.FloorHeight);
s.FloorHeight = floorheight.GetResult(sectorProps[i++].FloorHeight);
}
General.Map.IsChanged = true;
@ -352,17 +350,16 @@ namespace CodeImp.DoomBuilder.Windows
private void brightness_WhenTextChanged(object sender, EventArgs e) {
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(brightness.Text)) {
int i = 0;
foreach(Sector s in sectors)
s.Brightness = sectorProps[i++].Brightness;
//update values
} else {
foreach(Sector s in sectors)
s.Brightness = General.Clamp(brightness.GetResult(s.Brightness), General.Map.FormatInterface.MinBrightness, General.Map.FormatInterface.MaxBrightness);
s.Brightness = General.Clamp(brightness.GetResult(sectorProps[i++].Brightness), General.Map.FormatInterface.MinBrightness, General.Map.FormatInterface.MaxBrightness);
}
General.Map.IsChanged = true;

View file

@ -493,17 +493,16 @@ namespace CodeImp.DoomBuilder.Windows
UpdateSectorHeight();
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(ceilingheight.Text)) {
int i = 0;
foreach(Sector s in sectors)
s.CeilHeight = sectorProps[i++].CeilHeight;
//update values
} else {
foreach(Sector s in sectors)
s.CeilHeight = ceilingheight.GetResult(s.CeilHeight);
s.CeilHeight = ceilingheight.GetResult(sectorProps[i++].CeilHeight);
}
General.Map.IsChanged = true;
@ -514,17 +513,16 @@ namespace CodeImp.DoomBuilder.Windows
UpdateSectorHeight();
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(floorheight.Text)) {
int i = 0;
foreach(Sector s in sectors)
s.FloorHeight = sectorProps[i++].FloorHeight;
//update values
//update values
} else {
foreach(Sector s in sectors)
s.FloorHeight = floorheight.GetResult(s.FloorHeight);
s.FloorHeight = floorheight.GetResult(sectorProps[i++].FloorHeight);
}
General.Map.IsChanged = true;
@ -533,11 +531,10 @@ namespace CodeImp.DoomBuilder.Windows
private void brightness_WhenTextChanged(object sender, EventArgs e) {
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(brightness.Text)) {
int i = 0;
foreach(Sector s in sectors)
s.Brightness = sectorProps[i++].Brightness;
//update values
@ -551,7 +548,7 @@ namespace CodeImp.DoomBuilder.Windows
}
foreach(Sector s in sectors)
s.Brightness = General.Clamp(brightness.GetResult(s.Brightness), General.Map.FormatInterface.MinBrightness, General.Map.FormatInterface.MaxBrightness);
s.Brightness = General.Clamp(brightness.GetResult(sectorProps[i++].Brightness), General.Map.FormatInterface.MinBrightness, General.Map.FormatInterface.MaxBrightness);
}
General.Map.IsChanged = true;

View file

@ -675,18 +675,17 @@ namespace CodeImp.DoomBuilder.Windows
//mxd
private void updateAngle() {
if(preventchanges) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(angle.Text)) {
int i = 0;
// Apply rotation
foreach(Thing t in things)
t.Rotate(thingProps[i++].AngleDoom);
} else { //update values
// Apply rotation
foreach(Thing t in things)
t.Rotate(angle.GetResult(t.AngleDoom));
t.Rotate(angle.GetResult(thingProps[i++].AngleDoom));
}
General.Map.IsChanged = true;

View file

@ -176,17 +176,16 @@ namespace CodeImp.DoomBuilder.Windows
private void positionx_WhenTextChanged(object sender, EventArgs e) {
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(positionx.Text)) {
int i = 0;
// Apply position
foreach(Vertex v in vertices)
v.Move(new Vector2D(vertexProps[i++].X, v.Position.y));
} else { //update values
// Verify the coordinates
float px = positionx.GetResultFloat(0.0f);
float px = positionx.GetResultFloat(vertexProps[i++].X);
if(px < General.Map.FormatInterface.MinCoordinate) {
positionx.Text = General.Map.FormatInterface.MinCoordinate.ToString();
return;
@ -206,17 +205,16 @@ namespace CodeImp.DoomBuilder.Windows
private void positiony_WhenTextChanged(object sender, EventArgs e) {
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(positiony.Text)) {
int i = 0;
// Apply position
foreach(Vertex v in vertices)
v.Move(new Vector2D(v.Position.x, vertexProps[i++].Y));
} else { //update values
// Verify the coordinates
float py = positiony.GetResultFloat(0.0f);
float py = positiony.GetResultFloat(vertexProps[i++].Y);
if(py < General.Map.FormatInterface.MinCoordinate) {
positiony.Text = General.Map.FormatInterface.MinCoordinate.ToString();
return;
@ -236,11 +234,10 @@ namespace CodeImp.DoomBuilder.Windows
private void zceiling_WhenTextChanged(object sender, EventArgs e) {
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(zceiling.Text)) {
int i = 0;
foreach(Vertex v in vertices)
v.ZCeiling = vertexProps[i++].ZCeiling;
//clear values
@ -250,7 +247,7 @@ namespace CodeImp.DoomBuilder.Windows
//update values
} else {
foreach(Vertex v in vertices)
v.ZCeiling = zceiling.GetResultFloat(v.ZCeiling);
v.ZCeiling = zceiling.GetResultFloat(vertexProps[i++].ZCeiling);
}
General.Map.IsChanged = true;
@ -259,11 +256,10 @@ namespace CodeImp.DoomBuilder.Windows
private void zfloor_WhenTextChanged(object sender, EventArgs e) {
if(blockUpdate) return;
int i = 0;
//restore values
if(string.IsNullOrEmpty(zfloor.Text)) {
int i = 0;
foreach(Vertex v in vertices)
v.ZFloor = vertexProps[i++].ZFloor;
//clear values
@ -272,8 +268,8 @@ namespace CodeImp.DoomBuilder.Windows
v.ZFloor = float.NaN;
//update values
} else {
foreach(Vertex v in vertices)
v.ZFloor = zfloor.GetResultFloat(v.ZFloor);
foreach(Vertex v in vertices)
v.ZFloor = zfloor.GetResultFloat(vertexProps[i++].ZFloor);
}
General.Map.IsChanged = true;

View file

@ -8,7 +8,7 @@ using CodeImp.DoomBuilder.Windows;
namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes
{
[EditMode(DisplayName = "Snap Vertices to Grid",
[EditMode(DisplayName = "Snap Map Elements to Grid",
SwitchAction = "snapvertstogrid",
AllowCopyPaste = false,
Optional = false,
@ -31,32 +31,62 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes
//nothing selected?
if (verts.Count == 0) {
General.Interface.DisplayStatus(StatusType.Warning, "Select some vertices first!");
base.OnCancel();
General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name);
return;
//check things
List<Thing> things = General.Map.Map.GetMarkedThings(true);
if (things.Count == 0) {
General.Interface.DisplayStatus(StatusType.Warning, "Select some map elements first!");
base.OnCancel();
General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name);
} else {
snapThings(things);
}
} else {
snapVertices(verts);
}
// Make undo for the snapping
General.Map.UndoRedo.CreateUndo("Snap vertices");
int snappedCount = 0;
//snap them all!
foreach (Vertex v in verts) {
Vector2D pos = v.Position;
v.SnapToGrid();
if (v.Position.x != pos.x || v.Position.y != pos.y)
snappedCount++;
}
//done
General.Interface.DisplayStatus(StatusType.Info, "Snapped " + snappedCount + " vertices.");
base.OnAccept();
General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name);
}
private void snapVertices(List<Vertex> verts) {
// Make undo for the snapping
General.Map.UndoRedo.CreateUndo("Snap vertices");
int snappedCount = 0;
//snap them all!
foreach(Vertex v in verts) {
Vector2D pos = v.Position;
v.SnapToGrid();
if(v.Position.x != pos.x || v.Position.y != pos.y)
snappedCount++;
}
//done
General.Interface.DisplayStatus(StatusType.Info, "Snapped " + snappedCount + " vertices.");
base.OnAccept();
General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name);
}
private void snapThings(List<Thing> things) {
// Make undo for the snapping
General.Map.UndoRedo.CreateUndo("Snap things");
int snappedCount = 0;
//snap them all!
foreach(Thing t in things) {
Vector2D pos = t.Position;
t.SnapToGrid();
if(t.Position.x != pos.x || t.Position.y != pos.y)
snappedCount++;
}
//done
General.Interface.DisplayStatus(StatusType.Info, "Snapped " + snappedCount + " things.");
base.OnAccept();
General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name);
}
// Disenagaging
public override void OnDisengage() {
base.OnDisengage();

View file

@ -224,7 +224,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.AddMenu(exportToObjMenuItem, MenuSection.FileNewOpenClose);
//mxd. add "Snap Vertices" menu button
snapModeMenuItem = new ToolStripMenuItem("Snap selected vertices to grid");
snapModeMenuItem = new ToolStripMenuItem("Snap selected map elements to grid");
snapModeMenuItem.Tag = "snapvertstogrid";
snapModeMenuItem.Click += new EventHandler(InvokeTaggedAction);
snapModeMenuItem.Image = CodeImp.DoomBuilder.BuilderModes.Properties.Resources.SnapVerts;

View file

@ -187,9 +187,9 @@ bridgemode
//mxd
snapvertstogrid
{
title = "Snap Selected Vertices to Grid";
title = "Snap Selected Map Elements to Grid";
category = "edit";
description = "Snaps selected vertices to grid.";
description = "Snaps selected map elements to grid.";
allowkeys = true;
allowmouse = false;
allowscroll = false;