Remove editing slot from linear waypoint editor, make showing points the default and adjust messages to explain this

This commit is contained in:
fullwall 2020-10-13 18:52:45 +08:00
parent c46362b02d
commit 306a448a48
3 changed files with 23 additions and 58 deletions

View File

@ -18,7 +18,6 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -176,10 +175,10 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
private final class LinearWaypointEditor extends WaypointEditor { private final class LinearWaypointEditor extends WaypointEditor {
Conversation conversation; Conversation conversation;
boolean editing = true; boolean editing = true;
int editingSlot = waypoints.size() - 1;
EntityMarkers<Waypoint> markers; EntityMarkers<Waypoint> markers;
private final Player player; private final Player player;
private boolean showPath; private Waypoint selectedWaypoint;
private boolean showPath = true;
private LinearWaypointEditor(Player player) { private LinearWaypointEditor(Player player) {
this.player = player; this.player = player;
@ -192,7 +191,6 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
} }
private void clearWaypoints() { private void clearWaypoints() {
editingSlot = 0;
waypoints.clear(); waypoints.clear();
onWaypointsModified(); onWaypointsModified();
markers.destroyMarkers(); markers.destroyMarkers();
@ -229,20 +227,13 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
if (waypoints.size() == 0 || !editing) { if (waypoints.size() == 0 || !editing) {
return null; return null;
} }
normaliseEditingSlot(); return selectedWaypoint == null ? waypoints.get(waypoints.size() - 1) : selectedWaypoint;
return waypoints.get(editingSlot);
} }
private Location getPreviousWaypoint(int fromSlot) { private Location getPreviousWaypoint() {
if (waypoints.size() <= 1) if (waypoints.size() <= 1)
return null; return null;
if (--fromSlot < 0) return waypoints.get(waypoints.size() - 2).getLocation();
fromSlot = waypoints.size() - 1;
return waypoints.get(fromSlot).getLocation();
}
private void normaliseEditingSlot() {
editingSlot = Math.max(0, Math.min(waypoints.size() - 1, editingSlot));
} }
@EventHandler @EventHandler
@ -309,7 +300,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
return; return;
event.setCancelled(true); event.setCancelled(true);
Location at = event.getClickedBlock().getLocation(); Location at = event.getClickedBlock().getLocation();
Location prev = getPreviousWaypoint(editingSlot); Location prev = getPreviousWaypoint();
if (prev != null && prev.getWorld() == at.getWorld()) { if (prev != null && prev.getWorld() == at.getWorld()) {
double distance = at.distanceSquared(prev); double distance = at.distanceSquared(prev);
@ -322,28 +313,22 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
} }
Waypoint element = new Waypoint(at); Waypoint element = new Waypoint(at);
normaliseEditingSlot(); waypoints.add(element);
if (editingSlot >= waypoints.size()) {
waypoints.add(element);
} else {
waypoints.add(editingSlot, element);
}
if (showPath) { if (showPath) {
markers.createMarker(element, element.getLocation().clone().add(0, 1, 0)); markers.createMarker(element, element.getLocation().clone().add(0, 1, 0));
} }
editingSlot = Math.min(editingSlot + 1, waypoints.size()); Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at),
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), editingSlot + 1,
waypoints.size()); waypoints.size());
} else if (waypoints.size() > 0 && !event.getPlayer().isSneaking()) { } else if (waypoints.size() > 0 && !event.getPlayer().isSneaking()) {
event.setCancelled(true); event.setCancelled(true);
normaliseEditingSlot(); Waypoint waypoint = waypoints.remove(waypoints.size() - 1);
Waypoint waypoint = waypoints.remove(editingSlot); if (waypoint.equals(selectedWaypoint)) {
selectedWaypoint = null;
}
if (showPath) { if (showPath) {
markers.removeMarker(waypoint); markers.removeMarker(waypoint);
} }
editingSlot = Math.max(0, editingSlot - 1); Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size());
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size(),
editingSlot + 1);
} }
onWaypointsModified(); onWaypointsModified();
} }
@ -364,33 +349,15 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
} }
if (slot == -1) if (slot == -1)
return; return;
editingSlot = slot; if (selectedWaypoint != null && waypoints.get(slot) == selectedWaypoint) {
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot, waypoints.remove(slot);
formatLoc(waypoints.get(editingSlot).getLocation())); selectedWaypoint = null;
} Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size());
@EventHandler
public void onPlayerItemHeldChange(PlayerItemHeldEvent event) {
if (!event.getPlayer().equals(player) || waypoints.size() == 0)
return; return;
int previousSlot = event.getPreviousSlot(), newSlot = event.getNewSlot();
// handle wrap-arounds
if (previousSlot == 0 && newSlot == LARGEST_SLOT) {
editingSlot--;
} else if (previousSlot == LARGEST_SLOT && newSlot == 0) {
editingSlot++;
} else {
int diff = newSlot - previousSlot;
if (Math.abs(diff) != 1)
return; // the player isn't scrolling
editingSlot += diff > 0 ? 1 : -1;
} }
normaliseEditingSlot(); selectedWaypoint = waypoints.get(slot);
if (conversation != null) { Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_SELECTED_WAYPOINT,
getCurrentWaypoint().describeTriggers(player); formatLoc(selectedWaypoint.getLocation()));
}
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
formatLoc(waypoints.get(editingSlot).getLocation()));
} }
private void onWaypointsModified() { private void onWaypointsModified() {
@ -412,8 +379,6 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS); Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS);
} }
} }
private static final int LARGEST_SLOT = 8;
} }
private class LinearWaypointGoal implements Goal { private class LinearWaypointGoal implements Goal {

View File

@ -188,11 +188,11 @@ public class Messages {
public static final String LEASHABLE_STOPPED = "citizens.commands.npc.leashable.stopped"; public static final String LEASHABLE_STOPPED = "citizens.commands.npc.leashable.stopped";
public static final String LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT = "citizens.editors.waypoints.linear.added-waypoint"; public static final String LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT = "citizens.editors.waypoints.linear.added-waypoint";
public static final String LINEAR_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.linear.begin"; public static final String LINEAR_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.linear.begin";
public static final String LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET = "citizens.editors.waypoints.linear.edit-slot-set";
public static final String LINEAR_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.linear.end"; public static final String LINEAR_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.linear.end";
public static final String LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS = "citizens.editors.waypoints.linear.not-showing-markers"; public static final String LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS = "citizens.editors.waypoints.linear.not-showing-markers";
public static final String LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED = "citizens.editors.waypoints.linear.range-exceeded"; public static final String LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED = "citizens.editors.waypoints.linear.range-exceeded";
public static final String LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT = "citizens.editors.waypoints.linear.removed-waypoint"; public static final String LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT = "citizens.editors.waypoints.linear.removed-waypoint";
public static final String LINEAR_WAYPOINT_EDITOR_SELECTED_WAYPOINT = "citizens.editors.waypoints.linear.selected-waypoint";
public static final String LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS = "citizens.editors.waypoints.linear.showing-markers"; public static final String LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS = "citizens.editors.waypoints.linear.showing-markers";
public static final String LINEAR_WAYPOINT_EDITOR_WAYPOINTS_CLEARED = "citizens.editors.waypoints.linear.waypoints-cleared"; public static final String LINEAR_WAYPOINT_EDITOR_WAYPOINTS_CLEARED = "citizens.editors.waypoints.linear.waypoints-cleared";
public static final String LLAMA_COLOR_SET = "citizens.commands.npc.llama.color-set"; public static final String LLAMA_COLOR_SET = "citizens.commands.npc.llama.color-set";

View File

@ -332,8 +332,8 @@ citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint. This w
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint. This will be available for NPCs to path to. citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint. This will be available for NPCs to path to.
citizens.editors.waypoints.guided.already-taken=There is already a waypoint here. citizens.editors.waypoints.guided.already-taken=There is already a waypoint here.
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]], [[{2}]]). citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]], [[{2}]]).
citizens.editors.waypoints.linear.begin=<b>Entered the <l>linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints<br> [[cycle]] to make NPCs go back to cycle through waypoints instead of looping. citizens.editors.waypoints.linear.begin=<b>=== <l>Linear Waypoint Editor ===<br> [[Left click]] to add a waypoint, [[right click]] to remove it.<br> You can right click while sneaking to select and remove specific points.<br> Type [[markers]] to hide waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints,<br> [[cycle]] to make NPCs cycle through waypoints instead of looping.
citizens.editors.waypoints.linear.edit-slot-set=Editing slot set to [[{0}]] ({1}). citizens.editors.waypoints.linear.selected-waypoint=Selected waypoint at {1}. Sneak + right click again to remove this waypoint.
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor. citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers. citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers.
citizens.editors.waypoints.linear.range-exceeded=Previous waypoint is {0} blocks away but the distance limit is {1}. citizens.editors.waypoints.linear.range-exceeded=Previous waypoint is {0} blocks away but the distance limit is {1}.