Make more commands use MakeSelection.

This commit is contained in:
UnknownShadow200 2016-06-27 11:59:11 +10:00
parent a5ddc7b5b9
commit 94687c57bb
6 changed files with 36 additions and 111 deletions

View File

@ -44,8 +44,6 @@ namespace MCGalaxy.Commands.Building {
op.Skip = (byte)state;
return DrawOp.DoDrawOp(op, null, p, marks);
}
struct CatchPos { public byte skip; }
public override void Help(Player p) {
Player.Message(p, "%T/hollow");

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building {
DrawArgs dArgs = (DrawArgs)state;
OutlineDrawOp op = new OutlineDrawOp();
op.Type = dArgs.type; op.ExtType = dArgs.extType;
op.NewType = dArgs.newType; op.NewExtType = dArgs.newExtType;
op.NewType = dArgs.newType; op.NewExtType = dArgs.newExtType;
return DrawOp.DoDrawOp(op, null, p, marks);
}
struct DrawArgs { public byte type, extType, newType, newExtType; }

View File

@ -1,7 +1,7 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
@ -28,31 +28,14 @@ namespace MCGalaxy.Commands.Building {
public CmdRainbow() { }
public override void Use(Player p, string message) {
CatchPos cpos = default(CatchPos);
p.blockchangeObject = cpos;
Player.Message(p, "Place two blocks to determine the edges.");
p.ClearBlockchange();
p.Blockchange += PlacedMark1;
p.MakeSelection(2, null, DoRainbow);
}
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += PlacedMark2;
}
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
bool DoRainbow(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
RainbowDrawOp op = new RainbowDrawOp();
if (!DrawOp.DoDrawOp(op, null, p, x, y, z, cpos.x, cpos.y, cpos.z ))
return;
if (p.staticCommands)
p.Blockchange += PlacedMark1;
return DrawOp.DoDrawOp(op, null, p, marks);
}
struct CatchPos { public ushort x, y, z; }
public override void Help(Player p) {
Player.Message(p, "%T/rainbow");

View File

@ -36,60 +36,38 @@ namespace MCGalaxy.Commands.Building {
", so therefore cannot use this command."); return;
}
CatchPos cpos = default(CatchPos);
cpos.message = message.ToLower();
p.blockchangeObject = cpos;
Player.Message(p, "Place two blocks to determine the edges.");
p.ClearBlockchange();
p.Blockchange += PlacedMark1;
}
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z;
p.blockchangeObject = bp;
p.Blockchange += PlacedMark2;
}
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
type = type < 128 ? p.bindings[type] : type;
string[] parts = cpos.message.SplitSpaces(3);
if (parts.Length < 2) { Help(p); return; }
p.MakeSelection(2, message.ToLower(), DoReplace);
}
bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
type = type < 128 ? p.bindings[type] : type;
string[] parts = ((string)state).SplitSpaces(3);
if (parts.Length < 2) { Help(p); return false; }
byte extTile = 0;
byte tile = DrawCmd.GetBlock(p, parts[0], out extTile);
if (tile == Block.Zero) return;
if (tile == Block.Zero) return false;
string brushName = CmdBrush.FindBrush(parts[1]);
if (brushName == null) {
Player.Message(p, "No brush found with name \"" + parts[1] + "\".");
Player.Message(p, "Available brushes: " + CmdBrush.AvailableBrushes);
return;
return false;
}
string brushMessage = parts.Length > 2 ? parts[2].ToLower() : "";
BrushArgs args = new BrushArgs(p, brushMessage, type, extType);
Brush brush = Brush.Brushes[brushName](args);
if (brush == null) return;
if (brush == null) return false;
DrawOp drawOp = null;
if (ReplaceNot) drawOp = new ReplaceNotDrawOp(tile, extTile);
else drawOp = new ReplaceDrawOp(tile, extTile);
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
if (p.staticCommands)
p.Blockchange += PlacedMark1;
else drawOp = new ReplaceDrawOp(tile, extTile);
return DrawOp.DoDrawOp(drawOp, brush, p, marks);
}
protected virtual bool ReplaceNot { get { return false; } }
struct CatchPos { public ushort x, y, z; public string message; }
public override void Help(Player p) {
Player.Message(p, "%T/rb [block] [brush name] <brush args>");
Player.Message(p, "%HReplaces all blocks of the given type, " +

View File

@ -41,42 +41,28 @@ namespace MCGalaxy.Commands.Building {
if (!byte.TryParse(args[0], out scale)) scale = 1;
if (!byte.TryParse(args[1], out spacing)) spacing = 1;
CatchPos cpos = default(CatchPos);
cpos.scale = scale; cpos.spacing = spacing;
cpos.givenMessage = args[2].ToUpper();
p.blockchangeObject = cpos;
WriteArgs wArgs = default(WriteArgs);
wArgs.scale = scale; wArgs.spacing = spacing;
wArgs.message = args[2].ToUpper();
Player.Message(p, "Place two blocks to determine direction.");
p.ClearBlockchange();
p.Blockchange += PlacedMark1;
p.MakeSelection(2, wArgs, DoWrite);
}
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += PlacedMark2;
}
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
bool DoWrite(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
type = type < 128 ? p.bindings[type] : type;
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
Level lvl = p.level;
if (x == cpos.x && z == cpos.z) { Player.Message(p, "No direction was selected"); return; }
WriteArgs wArgs = (WriteArgs)state;
if (marks[0].X == marks[1].X && marks[0].Z == marks[1].Z) {
Player.Message(p, "No direction was selected"); return false;
}
WriteDrawOp op = new WriteDrawOp();
op.Text = cpos.givenMessage;
op.Scale = cpos.scale; op.Spacing = cpos.spacing;
op.Text = wArgs.message;
op.Scale = wArgs.scale; op.Spacing = wArgs.spacing;
Brush brush = new SolidBrush(type, extType);
if (!DrawOp.DoDrawOp(op, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
if (p.staticCommands)
p.Blockchange += PlacedMark1;
return DrawOp.DoDrawOp(op, brush, p, marks);
}
struct CatchPos { public byte scale, spacing; public ushort x, y, z; public string givenMessage; }
struct WriteArgs { public byte scale, spacing; public ushort x, y, z; public string message; }
public override void Help(Player p) {
Player.Message(p, "%T/wrt [scale] [spacing] [message]");

View File

@ -28,41 +28,21 @@ namespace MCGalaxy.Commands.Building {
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public override void Use(Player p, string message) {
CatchPos cpos = default(CatchPos);
cpos.message = message.ToLower();
p.blockchangeObject = cpos;
Player.Message(p, "Place two blocks to determine the edges.");
p.ClearBlockchange();
p.Blockchange += PlacedMark1;
p.MakeSelection(2, message.ToLower(), DoReplace);
}
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z;
p.blockchangeObject = bp;
p.Blockchange += PlacedMark2;
}
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
BrushArgs args = new BrushArgs(p, cpos.message, type, extType);
bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
BrushArgs args = new BrushArgs(p, (string)state, type, extType);
Brush brush = ReplaceNot ? ReplaceNotBrush.Process(args) : ReplaceBrush.Process(args);
if (brush == null) return;
if (brush == null) return false;
DrawOp drawOp = new CuboidDrawOp();
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
if (p.staticCommands)
p.Blockchange += PlacedMark1;
return DrawOp.DoDrawOp(drawOp, brush, p, marks);
}
protected virtual bool ReplaceNot { get { return false; } }
struct CatchPos { public ushort x, y, z; public string message; }
public override void Help(Player p) {
Player.Message(p, "%T/replace [block] [block2].. [new]");
Player.Message(p, "%HReplaces [block] with [new] between two points.");