mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-23 12:22:35 +00:00
47cebd9b20
Updated hint system. Corrected 2 typos in action names.
109 lines
3.5 KiB
C#
109 lines
3.5 KiB
C#
using System;
|
|
using CodeImp.DoomBuilder.Editing;
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes {
|
|
[EditMode(DisplayName = "Draw Ellipse Mode",
|
|
SwitchAction = "drawellipsemode",
|
|
AllowCopyPaste = false,
|
|
Volatile = true,
|
|
Optional = false)]
|
|
|
|
public class DrawEllipseMode : DrawRectangleMode {
|
|
private static int storedSubdivisions;
|
|
|
|
public DrawEllipseMode() : base() {
|
|
maxSubdivisions = 32;
|
|
minSubdivisions = 6;
|
|
undoName = "Ellipse draw";
|
|
shapeName = "ellipse";
|
|
|
|
if(storedSubdivisions == 0)
|
|
storedSubdivisions = minSubdivisions + 2;
|
|
subdivisions = storedSubdivisions;
|
|
}
|
|
|
|
public override void OnDisengage() {
|
|
base.OnDisengage();
|
|
storedSubdivisions = subdivisions;
|
|
}
|
|
|
|
override protected Vector2D[] getShape(Vector2D pStart, Vector2D pEnd) {
|
|
//no shape
|
|
if (pEnd.x == pStart.x && pEnd.y == pStart.y)
|
|
return new Vector2D[0];
|
|
|
|
//line
|
|
if(pEnd.x == pStart.x || pEnd.y == pStart.y)
|
|
return new Vector2D[] { pStart, pEnd };
|
|
|
|
//got shape
|
|
int bevelSign = (bevelWidth > 0 ? 1 : -1);
|
|
currentBevelWidth = Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2) * bevelSign;
|
|
|
|
Vector2D[] shape = new Vector2D[subdivisions + 1];
|
|
|
|
bool doBevel = false;
|
|
int hw = width / 2;
|
|
int hh = height / 2;
|
|
|
|
Vector2D center = new Vector2D(pStart.x + hw, pStart.y + hh);
|
|
float curAngle = 0;
|
|
float angleStep = -Angle2D.PI / subdivisions * 2;
|
|
int px, py;
|
|
|
|
for (int i = 0; i < subdivisions; i++) {
|
|
if (doBevel) {
|
|
px = (int)(center.x - (float)Math.Sin(curAngle) * (hw + currentBevelWidth));
|
|
py = (int)(center.y - (float)Math.Cos(curAngle) * (hh + currentBevelWidth));
|
|
} else {
|
|
px = (int)(center.x - (float)Math.Sin(curAngle) * hw);
|
|
py = (int)(center.y - (float)Math.Cos(curAngle) * hh);
|
|
}
|
|
doBevel = !doBevel;
|
|
shape[i] = new Vector2D(px, py);
|
|
curAngle += angleStep;
|
|
}
|
|
//add final point
|
|
shape[subdivisions] = shape[0];
|
|
return shape;
|
|
}
|
|
|
|
protected override string getHintText() {
|
|
return "BVL: "+bevelWidth+"; VERTS: "+subdivisions;
|
|
}
|
|
|
|
//mxd. Setup hints for current editing mode
|
|
protected override void SetupHints() {
|
|
string selectKey = Actions.Action.GetShortcutKeyDesc("builder_classicselect");
|
|
string editKey = Actions.Action.GetShortcutKeyDesc("builder_classicedit");
|
|
string cancelKey = Actions.Action.GetShortcutKeyDesc("builder_cancelmode");
|
|
string incSub = Actions.Action.GetShortcutKeyDesc("buildermodes_increasesubdivlevel");
|
|
string decSub = Actions.Action.GetShortcutKeyDesc("buildermodes_decreasesubdivlevel");
|
|
string incBvl = Actions.Action.GetShortcutKeyDesc("buildermodes_increasebevel");
|
|
string decBvl = Actions.Action.GetShortcutKeyDesc("buildermodes_decreasebevel");
|
|
|
|
hints = new[]{"Press " + selectKey + " to place a vertex",
|
|
"Use " + incBvl + " and " + decBvl + " to change bevel by current grid size",
|
|
"Use " + incSub + " and " + decSub + " to change the number of points in ellipse",
|
|
"Place second vertex to finish drawing",
|
|
"Press " + cancelKey + " or " + editKey + " to cancel"
|
|
};
|
|
}
|
|
|
|
//ACTIONS
|
|
override protected void increaseSubdivLevel() {
|
|
if (subdivisions < maxSubdivisions) {
|
|
subdivisions += 2;
|
|
Update();
|
|
}
|
|
}
|
|
|
|
override protected void decreaseSubdivLevel() {
|
|
if (subdivisions > minSubdivisions) {
|
|
subdivisions -= 2;
|
|
Update();
|
|
}
|
|
}
|
|
}
|
|
}
|