Show information about current selection in bottom right HUD

This commit is contained in:
UnknownShadow200 2017-07-22 19:59:56 +10:00
parent 644663a0a7
commit 1ebdbd6e1f
16 changed files with 65 additions and 25 deletions

View File

@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.Info {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
Player.Message(p, "Break/build a block to display information."); Player.Message(p, "Break/build a block to display information.");
p.MakeSelection(1, null, PlacedMark); p.MakeSelection(1, "Selecting location for %SBlock info", null, PlacedMark);
} }
bool PlacedMark(Player p, Vec3S32[] marks, object state, ExtBlock block) { bool PlacedMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {

View File

@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.Moderation {
if (LevelInfo.ExistsBackup(p.level.name, message)) { if (LevelInfo.ExistsBackup(p.level.name, message)) {
Player.Message(p, "Select two corners for restore."); Player.Message(p, "Select two corners for restore.");
p.MakeSelection(2, message, DoRestore); p.MakeSelection(2, "Selecting region for %SRestore", message, DoRestore);
} else { } else {
Player.Message(p, "Backup " + message + " does not exist."); Player.Message(p, "Backup " + message + " does not exist.");
} }

View File

@ -55,7 +55,7 @@ namespace MCGalaxy.Commands.Moderation {
Player.Message(p, "Place or break two blocks to determine the edges."); Player.Message(p, "Place or break two blocks to determine the edges.");
UndoAreaArgs args = new UndoAreaArgs(); UndoAreaArgs args = new UndoAreaArgs();
args.ids = ids; args.names = names; args.delta = delta; args.ids = ids; args.names = names; args.delta = delta;
p.MakeSelection(2, args, DoUndoArea); p.MakeSelection(2, "Selecting region for %SUndo player", args, DoUndoArea);
} }
} }

View File

@ -64,7 +64,6 @@ namespace MCGalaxy.Commands.World {
Level.LoadMetadata(lvl); Level.LoadMetadata(lvl);
if (!PlayerActions.ChangeMap(p, lvl)) return; if (!PlayerActions.ChangeMap(p, lvl)) return;
p.ClearBlockchange();
} }
static void SetLevelProps(Level lvl) { static void SetLevelProps(Level lvl) {

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
Player.Message(p, "Place or break two blocks to determine the edges."); Player.Message(p, "Place or break two blocks to determine the edges.");
p.MakeSelection(2, null, DoCentre); p.MakeSelection(2, "Selecting region for %SCentre", null, DoCentre);
} }
bool DoCentre(Player p, Vec3S32[] m, object state, ExtBlock block) { bool DoCentre(Player p, Vec3S32[] m, object state, ExtBlock block) {

View File

@ -90,7 +90,7 @@ namespace MCGalaxy.Commands.Building {
} }
Player.Message(p, "Place or break two blocks to determine the edges."); Player.Message(p, "Place or break two blocks to determine the edges.");
p.MakeSelection(2, cArgs, DoCopy); p.MakeSelection(2, "Selecting region for %SCopy", cArgs, DoCopy);
} }
bool DoCopy(Player p, Vec3S32[] m, object state, ExtBlock block) { bool DoCopy(Player p, Vec3S32[] m, object state, ExtBlock block) {
@ -144,7 +144,7 @@ namespace MCGalaxy.Commands.Building {
Player.Message(p, format, cState.UsedBlocks); Player.Message(p, format, cState.UsedBlocks);
if (cArgs.offsetIndex != -1) { if (cArgs.offsetIndex != -1) {
Player.Message(p, "Place a block to determine where to paste from"); Player.Message(p, "Place a block to determine where to paste from");
p.MakeSelection(1, null, PlacedOffsetMark); p.MakeSelection(1, "Selecting paste offset for %SCopy", null, PlacedOffsetMark);
} }
return false; return false;
} }

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Building {
if (message != "" && !CommandParser.GetUShort(p, message, "Distance", ref dist)) return; if (message != "" && !CommandParser.GetUShort(p, message, "Distance", ref dist)) return;
Player.Message(p, "Destroy the block you wish to drill."); Player.Message(p, "Destroy the block you wish to drill.");
p.MakeSelection(1, dist, DoDrill); p.MakeSelection(1, "Selecting location for %SDrill", dist, DoDrill);
} }
bool DoDrill(Player p, Vec3S32[] marks, object state, ExtBlock block) { bool DoDrill(Player p, Vec3S32[] marks, object state, ExtBlock block) {

View File

@ -79,7 +79,7 @@ namespace MCGalaxy.Commands.Building {
Player.Message(p, "The URL entered was invalid!"); return; Player.Message(p, "The URL entered was invalid!"); return;
} }
Player.Message(p, "Place or break two blocks to determine direction."); Player.Message(p, "Place or break two blocks to determine direction.");
p.MakeSelection(2, dArgs, DoImage); p.MakeSelection(2, "Selecting direction for %SImagePrint", dArgs, DoImage);
} }
bool DownloadWebFile(string url, Player p) { bool DownloadWebFile(string url, Player p) {

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.Building {
if (message != "" && !CommandParser.GetBlock(p, message, out skip)) return; if (message != "" && !CommandParser.GetBlock(p, message, out skip)) return;
Player.Message(p, "Place or break two blocks to determine the edges."); Player.Message(p, "Place or break two blocks to determine the edges.");
p.MakeSelection(2, skip, DoMeasure); p.MakeSelection(2, "Selecting region for %SMeasure", skip, DoMeasure);
} }
bool DoMeasure(Player p, Vec3S32[] m, object state, ExtBlock block) { bool DoMeasure(Player p, Vec3S32[] m, object state, ExtBlock block) {

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Building {
if (brush == null) return; if (brush == null) return;
Player.Message(p, "Place a block in the corner of where you want to paste."); Player.Message(p, "Place a block in the corner of where you want to paste.");
p.MakeSelection(1, brush, DoPaste); p.MakeSelection(1, "Selecting location for %SPaste", brush, DoPaste);
} }
bool DoPaste(Player p, Vec3S32[] m, object state, ExtBlock block) { bool DoPaste(Player p, Vec3S32[] m, object state, ExtBlock block) {

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Commands.Building {
if (message != "" && !ParseArgs(p, message, ref extraInfo)) return; if (message != "" && !ParseArgs(p, message, ref extraInfo)) return;
Player.Message(p, "Place or break two blocks to determine the edges."); Player.Message(p, "Place or break two blocks to determine the edges.");
p.MakeSelection(2, extraInfo, DoRestart); p.MakeSelection(2, "Selecting region for %SRestart physics", extraInfo, DoRestart);
} }
bool ParseArgs(Player p, string message, ref PhysicsArgs args) { bool ParseArgs(Player p, string message, ref PhysicsArgs args) {

View File

@ -59,7 +59,7 @@ namespace MCGalaxy.Commands.Building {
if (!CheckBrush(p, dArgs.brushMsg)) return; if (!CheckBrush(p, dArgs.brushMsg)) return;
Player.Message(p, "Select where you wish your tree to grow"); Player.Message(p, "Select where you wish your tree to grow");
p.MakeSelection(1, dArgs, DoTree); p.MakeSelection(1, "Selecting location for %STree", dArgs, DoTree);
} }
static bool CheckBrush(Player p, string brushMsg) { static bool CheckBrush(Player p, string brushMsg) {

View File

@ -46,7 +46,7 @@ namespace MCGalaxy.Commands.Building {
wArgs.scale = scale; wArgs.spacing = spacing; wArgs.scale = scale; wArgs.spacing = spacing;
wArgs.message = args[2].ToUpper(); wArgs.message = args[2].ToUpper();
Player.Message(p, "Place or break two blocks to determine direction."); Player.Message(p, "Place or break two blocks to determine direction.");
p.MakeSelection(2, wArgs, DoWrite); p.MakeSelection(2, "Selecting direction for %SWrite", wArgs, DoWrite);
} }
bool DoWrite(Player p, Vec3S32[] marks, object state, ExtBlock block) { bool DoWrite(Player p, Vec3S32[] marks, object state, ExtBlock block) {

View File

@ -48,7 +48,7 @@ namespace MCGalaxy.Commands.Building {
if (!factory.Validate(bArgs)) return; if (!factory.Validate(bArgs)) return;
Player.Message(p, PlaceMessage); Player.Message(p, PlaceMessage);
p.MakeSelection(MarksCount, dArgs, DoDraw); p.MakeSelection(MarksCount, "Selecting region for %S" + dArgs.Op.Name, dArgs, DoDraw);
} }
protected virtual bool DoDraw(Player p, Vec3S32[] marks, object state, ExtBlock block) { protected virtual bool DoDraw(Player p, Vec3S32[] marks, object state, ExtBlock block) {

View File

@ -255,7 +255,7 @@ namespace MCGalaxy {
public event OnBlockChange Blockchange; public event OnBlockChange Blockchange;
internal bool HasBlockchange { get { return Blockchange != null; } } internal bool HasBlockchange { get { return Blockchange != null; } }
public void ClearBlockchange() { Blockchange = null; } public void ClearBlockchange() { ClearSelection(); }
public object blockchangeObject; public object blockchangeObject;
/// <summary> Called when the player has finished providing all the marks for a selection. </summary> /// <summary> Called when the player has finished providing all the marks for a selection. </summary>

View File

@ -485,19 +485,40 @@ namespace MCGalaxy {
return false; return false;
} }
public void CheckForMessageSpam() {
if (spamChecker != null) spamChecker.CheckChatSpam();
}
string selTitle;
readonly object selLock = new object(); readonly object selLock = new object();
Vec3S32[] selMarks; Vec3S32[] selMarks;
object selState; object selState;
SelectionHandler selCallback; SelectionHandler selCallback;
int selIndex; int selIndex;
public void MakeSelection(int marks, object state, SelectionHandler callback) { public void MakeSelection(int marks, string title, object state, SelectionHandler callback) {
lock (selLock) { lock (selLock) {
selMarks = new Vec3S32[marks]; selMarks = new Vec3S32[marks];
selTitle = title;
selState = state; selState = state;
selCallback = callback; selCallback = callback;
selIndex = 0; selIndex = 0;
Blockchange = SelectionBlockChange; Blockchange = SelectionBlockChange;
if (title != null) InitSelectionHUD();
}
}
public void MakeSelection(int marks, object state, SelectionHandler callback) {
MakeSelection(marks, null, state, callback);
}
public void ClearSelection() {
lock (selLock) {
if (selTitle != null) ResetSelectionHUD();
selTitle = null;
selState = null;
selCallback = null;
Blockchange = null;
} }
} }
@ -508,23 +529,43 @@ namespace MCGalaxy {
selMarks[selIndex] = new Vec3S32(x, y, z); selMarks[selIndex] = new Vec3S32(x, y, z);
selIndex++; selIndex++;
if (selIndex == 1) {
SendCpeMessage(CpeMessageType.BottomRight2, "Mark #1" + FormatSelectionMark(selMarks[0]));
} else if (selIndex == 2) {
SendCpeMessage(CpeMessageType.BottomRight1, "Mark #2" + FormatSelectionMark(selMarks[0]));
}
if (selIndex != selMarks.Length) return; if (selIndex != selMarks.Length) return;
object state = selState; selState = null; string title = selTitle;
SelectionHandler callback = selCallback; selCallback = null; object state = selState;
SelectionHandler callback = selCallback;
ClearSelection();
Blockchange = null;
if (!block.IsPhysicsType) block = p.BlockBindings[block.RawID]; if (!block.IsPhysicsType) block = p.BlockBindings[block.RawID];
bool canRepeat = callback(this, selMarks, state, block); bool canRepeat = callback(this, selMarks, state, block);
if (canRepeat && staticCommands) { if (canRepeat && staticCommands) {
MakeSelection(selIndex, state, callback); MakeSelection(selIndex, title, state, callback);
} }
} }
} }
public void CheckForMessageSpam() { string FormatSelectionMark(Vec3S32 P) {
if (spamChecker != null) spamChecker.CheckChatSpam(); return ": %S(" + P.X + ", " + P.Y + ", " + P.Z + ")";
}
void InitSelectionHUD() {
SendCpeMessage(CpeMessageType.BottomRight3, selTitle);
int marks = selMarks.Length;
if (marks >= 1) SendCpeMessage(CpeMessageType.BottomRight2, "Mark #1: %S(Not yet set)");
if (marks >= 2) SendCpeMessage(CpeMessageType.BottomRight1, "Mark #2: %S(Not yet set)");
}
void ResetSelectionHUD() {
SendCpeMessage(CpeMessageType.BottomRight3, "");
SendCpeMessage(CpeMessageType.BottomRight2, "");
SendCpeMessage(CpeMessageType.BottomRight1, "");
} }
} }
} }