Consistent request->plan naming

This commit is contained in:
Anuken
2022-02-22 16:17:22 -05:00
parent 7df4478f85
commit 040c43fe54
11 changed files with 267 additions and 269 deletions

View File

@@ -38,9 +38,9 @@ public class DesktopInput extends InputHandler{
public PlaceMode mode;
/** Animation scale for line. */
public float selectScale;
/** Selected build request for movement. */
/** Selected build plan for movement. */
public @Nullable BuildPlan sreq;
/** Whether player is currently deleting removal requests. */
/** Whether player is currently deleting removal plans. */
public boolean deleting = false, shouldShoot = false, panning = false;
/** Mouse pan speed. */
public float panScale = 0.005f, panSpeed = 4.5f, panBoostSpeed = 15f;
@@ -50,7 +50,7 @@ public class DesktopInput extends InputHandler{
public Tile prevSelected;
boolean showHint(){
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectRequests.isEmpty() &&
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectPlans.isEmpty() &&
(!isBuilding && !Core.settings.getBool("buildautopause") || player.unit().isBuilding() || !player.dead() && !player.unit().spawnedByCore());
}
@@ -84,7 +84,7 @@ public class DesktopInput extends InputHandler{
//schematic controls
group.fill(t -> {
t.visible(() -> ui.hudfrag.shown && lastSchematic != null && !selectRequests.isEmpty());
t.visible(() -> ui.hudfrag.shown && lastSchematic != null && !selectPlans.isEmpty());
t.bottom();
t.table(Styles.black6, b -> {
b.defaults().left();
@@ -186,38 +186,38 @@ public class DesktopInput extends InputHandler{
drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid);
}
sreq.block.drawPlan(sreq, allRequests(), valid);
sreq.block.drawPlan(sreq, allPlans(), valid);
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
drawSelected(sreq.x, sreq.y, sreq.block, getPlan(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
}
//draw hover request
//draw hover plans
if(mode == none && !isPlacing()){
BuildPlan req = getRequest(cursorX, cursorY);
BuildPlan req = getPlan(cursorX, cursorY);
if(req != null){
drawSelected(req.x, req.y, req.breaking ? req.tile().block() : req.block, Pal.accent);
}
}
//draw schematic requests
selectRequests.each(req -> {
//draw schematic plans
selectPlans.each(req -> {
req.animScale = 1f;
drawPlan(req);
});
selectRequests.each(this::drawOverPlan);
selectPlans.each(this::drawOverPlan);
if(player.isBuilder()){
//draw things that may be placed soon
if(mode == placing && block != null){
for(int i = 0; i < lineRequests.size; i++){
BuildPlan req = lineRequests.get(i);
if(i == lineRequests.size - 1 && req.block.rotate){
for(int i = 0; i < linePlans.size; i++){
BuildPlan req = linePlans.get(i);
if(i == linePlans.size - 1 && req.block.rotate){
drawArrow(block, req.x, req.y, req.rotation);
}
drawPlan(lineRequests.get(i));
drawPlan(linePlans.get(i));
}
lineRequests.each(this::drawOverPlan);
linePlans.each(this::drawOverPlan);
}else if(isPlacing()){
if(block.rotate && block.drawArrow){
drawArrow(block, cursorX, cursorY, rotation);
@@ -229,10 +229,10 @@ public class DesktopInput extends InputHandler{
if(block.saveConfig){
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
brequest.set(cursorX, cursorY, rotation, block);
brequest.config = block.lastConfig;
block.drawPlanConfig(brequest, allRequests());
brequest.config = null;
bplan.set(cursorX, cursorY, rotation, block);
bplan.config = block.lastConfig;
block.drawPlanConfig(bplan, allPlans());
bplan.config = null;
Draw.reset();
}
@@ -333,7 +333,7 @@ public class DesktopInput extends InputHandler{
//zoom camera
if((!Core.scene.hasScroll() || Core.input.keyDown(Binding.diagonal_placement)) && !ui.chatfrag.shown() && Math.abs(Core.input.axisTap(Binding.zoom)) > 0
&& !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectRequests.isEmpty()))){
&& !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectPlans.isEmpty()))){
renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
}
@@ -379,8 +379,8 @@ public class DesktopInput extends InputHandler{
if(isPlacing() && mode == placing){
updateLine(selectX, selectY);
}else if(!selectRequests.isEmpty() && !ui.chatfrag.shown()){
rotateRequests(selectRequests, Mathf.sign(Core.input.axisTap(Binding.rotate)));
}else if(!selectPlans.isEmpty() && !ui.chatfrag.shown()){
rotatePlans(selectPlans, Mathf.sign(Core.input.axisTap(Binding.rotate)));
}
}
@@ -391,7 +391,7 @@ public class DesktopInput extends InputHandler{
cursorType = cursor.build.getCursor();
}
if((isPlacing() && player.isBuilder()) || !selectRequests.isEmpty()){
if((isPlacing() && player.isBuilder()) || !selectPlans.isEmpty()){
cursorType = SystemCursor.hand;
}
@@ -403,7 +403,7 @@ public class DesktopInput extends InputHandler{
cursorType = ui.targetCursor;
}
if(getRequest(cursor.x, cursor.y) != null && mode == none){
if(getPlan(cursor.x, cursor.y) != null && mode == none){
cursorType = SystemCursor.hand;
}
@@ -430,8 +430,8 @@ public class DesktopInput extends InputHandler{
schematicX = tileX(getMouseX());
schematicY = tileY(getMouseY());
selectRequests.clear();
selectRequests.addAll(schematics.toRequests(schem, schematicX, schematicY));
selectPlans.clear();
selectPlans.addAll(schematics.toPlans(schem, schematicX, schematicY));
mode = none;
}
@@ -477,10 +477,10 @@ public class DesktopInput extends InputHandler{
buildWasAutoPaused = true;
}
if(!selectRequests.isEmpty()){
if(!selectPlans.isEmpty()){
int shiftX = rawCursorX - schematicX, shiftY = rawCursorY - schematicY;
selectRequests.each(s -> {
selectPlans.each(s -> {
s.x += shiftX;
s.y += shiftY;
});
@@ -512,26 +512,26 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyTap(Binding.clear_building) || isPlacing()){
lastSchematic = null;
selectRequests.clear();
selectPlans.clear();
}
if(Core.input.keyRelease(Binding.schematic_select) && !Core.scene.hasKeyboard() && selectX == -1 && selectY == -1 && schemX != -1 && schemY != -1){
lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
useSchematic(lastSchematic);
if(selectRequests.isEmpty()){
if(selectPlans.isEmpty()){
lastSchematic = null;
}
schemX = -1;
schemY = -1;
}
if(!selectRequests.isEmpty()){
if(!selectPlans.isEmpty()){
if(Core.input.keyTap(Binding.schematic_flip_x)){
flipRequests(selectRequests, true);
flipPlans(selectPlans, true);
}
if(Core.input.keyTap(Binding.schematic_flip_y)){
flipRequests(selectRequests, false);
flipPlans(selectPlans, false);
}
}
@@ -544,7 +544,7 @@ public class DesktopInput extends InputHandler{
}
if(block == null || mode != placing){
lineRequests.clear();
linePlans.clear();
}
if(Core.input.keyTap(Binding.pause_building)){
@@ -581,12 +581,12 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){
tappedOne = false;
BuildPlan req = getRequest(cursorX, cursorY);
BuildPlan req = getPlan(cursorX, cursorY);
if(Core.input.keyDown(Binding.break_block)){
mode = none;
}else if(!selectRequests.isEmpty()){
flushRequests(selectRequests);
}else if(!selectPlans.isEmpty()){
flushPlans(selectPlans);
}else if(isPlacing()){
selectX = cursorX;
selectY = cursorY;
@@ -616,8 +616,8 @@ public class DesktopInput extends InputHandler{
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
block = null;
mode = none;
}else if(Core.input.keyTap(Binding.deselect) && !selectRequests.isEmpty()){
selectRequests.clear();
}else if(Core.input.keyTap(Binding.deselect) && !selectPlans.isEmpty()){
selectPlans.clear();
lastSchematic = null;
}else if(Core.input.keyTap(Binding.break_block) && !Core.scene.hasMouse() && player.isBuilder() && !commandMode){
//is recalculated because setting the mode to breaking removes potential multiblock cursor offset
@@ -630,7 +630,7 @@ public class DesktopInput extends InputHandler{
}
if(Core.input.keyDown(Binding.select) && mode == none && !isPlacing() && deleting){
BuildPlan req = getRequest(cursorX, cursorY);
BuildPlan req = getPlan(cursorX, cursorY);
if(req != null && req.breaking){
player.unit().plans().remove(req);
}
@@ -656,8 +656,8 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){
if(mode == placing && block != null){ //touch up while placing, place everything in selection
flushRequests(lineRequests);
lineRequests.clear();
flushPlans(linePlans);
linePlans.clear();
Events.fire(new LineConfirmEvent());
}else if(mode == breaking){ //touch up while breaking, break everything in selection
removeSelection(selectX, selectY, cursorX, cursorY, !Core.input.keyDown(Binding.schematic_select) ? maxLength : Vars.maxSchematicSize);
@@ -672,7 +672,7 @@ public class DesktopInput extends InputHandler{
tryDropItems(selected == null ? null : selected.build, Core.input.mouseWorld().x, Core.input.mouseWorld().y);
if(sreq != null){
if(getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null){
if(getPlan(sreq.x, sreq.y, sreq.block.size, sreq) != null){
player.unit().plans().remove(sreq, true);
}
sreq = null;
@@ -783,7 +783,7 @@ public class DesktopInput extends InputHandler{
mode = none;
block = null;
sreq = null;
selectRequests.clear();
selectPlans.clear();
}
}

View File

@@ -74,9 +74,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public GestureDetector detector;
public PlaceLine line = new PlaceLine();
public BuildPlan resultreq;
public BuildPlan brequest = new BuildPlan();
public Seq<BuildPlan> lineRequests = new Seq<>();
public Seq<BuildPlan> selectRequests = new Seq<>();
public BuildPlan bplan = new BuildPlan();
public Seq<BuildPlan> linePlans = new Seq<>();
public Seq<BuildPlan> selectPlans = new Seq<>();
//for RTS controls
public Seq<Unit> selectedUnits = new Seq<>();
@@ -89,15 +89,15 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
private Seq<BuildPlan> plansOut = new Seq<>(BuildPlan.class);
private QuadTree<BuildPlan> playerPlanTree = new QuadTree<>(new Rect());
private final Eachable<BuildPlan> allRequests = cons -> {
private final Eachable<BuildPlan> allPlans = cons -> {
player.unit().plans().each(cons);
selectRequests.each(cons);
lineRequests.each(cons);
selectPlans.each(cons);
linePlans.each(cons);
};
private final Eachable<BuildPlan> allSelectLines = cons -> {
selectRequests.each(cons);
lineRequests.each(cons);
selectPlans.each(cons);
linePlans.each(cons);
};
public InputHandler(){
@@ -554,12 +554,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return inputLocks.contains(Boolp::get);
}
public Eachable<BuildPlan> allRequests(){
return allRequests;
public Eachable<BuildPlan> allPlans(){
return allPlans;
}
public boolean isUsingSchematic(){
return !selectRequests.isEmpty();
return !selectPlans.isEmpty();
}
public void update(){
@@ -692,11 +692,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Drawf.selected(x, y, block, color);
}
public void drawBreaking(BuildPlan request){
if(request.breaking){
drawBreaking(request.x, request.y);
public void drawBreaking(BuildPlan plan){
if(plan.breaking){
drawBreaking(plan.x, plan.y);
}else{
drawSelected(request.x, request.y, request.block, Pal.remove);
drawSelected(plan.x, plan.y, plan.block, Pal.remove);
}
}
@@ -716,9 +716,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
public boolean requestMatches(BuildPlan request){
Tile tile = world.tile(request.x, request.y);
return tile != null && tile.build instanceof ConstructBuild cons && cons.current == request.block;
public boolean planMatches(BuildPlan plan){
Tile tile = world.tile(plan.x, plan.y);
return tile != null && tile.build instanceof ConstructBuild cons && cons.current == plan.block;
}
public void drawBreaking(int x, int y){
@@ -730,7 +730,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
public void useSchematic(Schematic schem){
selectRequests.addAll(schematics.toRequests(schem, player.tileX(), player.tileY()));
selectPlans.addAll(schematics.toPlans(schem, player.tileX(), player.tileY()));
}
protected void showSchematicSave(){
@@ -755,10 +755,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
});
}
public void rotateRequests(Seq<BuildPlan> requests, int direction){
public void rotatePlans(Seq<BuildPlan> plans, int direction){
int ox = schemOriginX(), oy = schemOriginY();
requests.each(req -> {
plans.each(req -> {
if(req.breaking) return;
req.pointConfig(p -> {
@@ -775,7 +775,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
p.set(cx, cy);
});
//rotate actual request, centered on its multiblock position
//rotate actual plan, centered on its multiblock position
float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset;
float x = wx;
if(direction >= 0){
@@ -791,10 +791,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
});
}
public void flipRequests(Seq<BuildPlan> requests, boolean x){
public void flipPlans(Seq<BuildPlan> plans, boolean x){
int origin = (x ? schemOriginX() : schemOriginY()) * tilesize;
requests.each(req -> {
plans.each(req -> {
if(req.breaking) return;
float value = -((x ? req.x : req.y) * tilesize - origin + req.block.offset) + origin;
@@ -830,13 +830,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return rawTileY();
}
/** Returns the selection request that overlaps this position, or null. */
protected BuildPlan getRequest(int x, int y){
return getRequest(x, y, 1, null);
/** @return the selection plan that overlaps this position, or null. */
protected @Nullable BuildPlan getPlan(int x, int y){
return getPlan(x, y, 1, null);
}
/** Returns the selection request that overlaps this position, or null. */
protected BuildPlan getRequest(int x, int y, int size, BuildPlan skip){
/** Returns the selection plan that overlaps this position, or null. */
protected @Nullable BuildPlan getPlan(int x, int y, int size, BuildPlan skip){
float offset = ((size + 1) % 2) * tilesize / 2f;
r2.setSize(tilesize * size);
r2.setCenter(x * tilesize + offset, y * tilesize + offset);
@@ -863,7 +863,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(test.get(req)) return req;
}
return selectRequests.find(test);
return selectPlans.find(test);
}
protected void drawBreakSelection(int x1, int y1, int x2, int y2, int maxLength){
@@ -891,7 +891,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
for(BuildPlan req : selectRequests){
for(BuildPlan req : selectPlans){
if(req.breaking) continue;
if(req.bounds(Tmp.r2).overlaps(Tmp.r1)){
drawBreaking(req);
@@ -928,22 +928,22 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
}
protected void flushSelectRequests(Seq<BuildPlan> requests){
for(BuildPlan req : requests){
protected void flushSelectPlans(Seq<BuildPlan> plans){
for(BuildPlan req : plans){
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
BuildPlan other = getRequest(req.x, req.y, req.block.size, null);
BuildPlan other = getPlan(req.x, req.y, req.block.size, null);
if(other == null){
selectRequests.add(req.copy());
selectPlans.add(req.copy());
}else if(!other.breaking && other.x == req.x && other.y == req.y && other.block.size == req.block.size){
selectRequests.remove(other);
selectRequests.add(req.copy());
selectPlans.remove(other);
selectPlans.add(req.copy());
}
}
}
}
protected void flushRequests(Seq<BuildPlan> requests){
for(BuildPlan req : requests){
protected void flushPlans(Seq<BuildPlan> plans){
for(BuildPlan req : plans){
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
BuildPlan copy = req.copy();
req.block.onNewPlan(copy);
@@ -952,25 +952,25 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
protected void drawOverPlan(BuildPlan request){
boolean valid = validPlace(request.x, request.y, request.block, request.rotation);
protected void drawOverPlan(BuildPlan plan){
boolean valid = validPlace(plan.x, plan.y, plan.block, plan.rotation);
Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
Draw.alpha(1f);
request.block.drawPlanConfigTop(request, allSelectLines);
plan.block.drawPlanConfigTop(plan, allSelectLines);
Draw.reset();
}
protected void drawPlan(BuildPlan request){
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
protected void drawPlan(BuildPlan plan){
plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation));
}
/** Draws a placement icon for a specific block. */
protected void drawPlan(int x, int y, Block block, int rotation){
brequest.set(x, y, rotation, block);
brequest.animScale = 1f;
block.drawPlan(brequest, allRequests(), validPlace(x, y, block, rotation));
bplan.set(x, y, rotation, block);
bplan.animScale = 1f;
block.drawPlan(bplan, allPlans(), validPlace(x, y, block, rotation));
}
/** Remove everything from the queue in a selection. */
@@ -1002,13 +1002,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(!flush){
tryBreakBlock(wx, wy);
}else if(validBreak(tile.x, tile.y) && !selectRequests.contains(r -> r.tile() != null && r.tile() == tile)){
selectRequests.add(new BuildPlan(tile.x, tile.y));
}else if(validBreak(tile.x, tile.y) && !selectPlans.contains(r -> r.tile() != null && r.tile() == tile)){
selectPlans.add(new BuildPlan(tile.x, tile.y));
}
}
}
//remove build requests
//remove build plans
Tmp.r1.set(result.x * tilesize, result.y * tilesize, (result.x2 - result.x) * tilesize, (result.y2 - result.y) * tilesize);
Iterator<BuildPlan> it = player.unit().plans().iterator();
@@ -1019,7 +1019,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
it = selectRequests.iterator();
it = selectPlans.iterator();
while(it.hasNext()){
BuildPlan req = it.next();
if(!req.breaking && req.bounds(Tmp.r2).overlaps(Tmp.r1)){
@@ -1048,23 +1048,23 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
protected void updateLine(int x1, int y1, int x2, int y2){
lineRequests.clear();
linePlans.clear();
iterateLine(x1, y1, x2, y2, l -> {
rotation = l.rotation;
BuildPlan req = new BuildPlan(l.x, l.y, l.rotation, block, block.nextConfig());
req.animScale = 1f;
lineRequests.add(req);
linePlans.add(req);
});
if(Core.settings.getBool("blockreplace")){
lineRequests.each(req -> {
Block replace = req.block.getReplacement(req, lineRequests);
linePlans.each(req -> {
Block replace = req.block.getReplacement(req, linePlans);
if(replace.unlockedNow()){
req.block = replace;
}
});
block.handlePlacementLine(lineRequests);
block.handlePlacementLine(linePlans);
}
}

View File

@@ -47,10 +47,10 @@ public class MobileInput extends InputHandler implements GestureListener{
/** Animation data for crosshair. */
public float crosshairScale;
public Teamc lastTarget;
/** Used for shifting build requests. */
/** Used for shifting build plans. */
public float shiftDeltaX, shiftDeltaY;
/** Place requests to be removed. */
/** Place plans to be removed. */
public Seq<BuildPlan> removals = new Seq<>();
/** Whether the player is currently shifting all placed tiles. */
public boolean selecting;
@@ -60,7 +60,7 @@ public class MobileInput extends InputHandler implements GestureListener{
public PlaceMode mode = none;
/** Whether no recipe was available when switching to break mode. */
public @Nullable Block lastBlock;
/** Last placed request. Used for drawing block overlay. */
/** Last placed plan. Used for drawing block overlay. */
public @Nullable BuildPlan lastPlaced;
/** Down tracking for panning. */
public boolean down = false;
@@ -103,17 +103,17 @@ public class MobileInput extends InputHandler implements GestureListener{
}
}
/** Returns whether this tile is in the list of requests, or at least colliding with one. */
boolean hasRequest(Tile tile){
return getRequest(tile) != null;
/** Returns whether this tile is in the list of plans, or at least colliding with one. */
boolean hasPlan(Tile tile){
return getPlan(tile) != null;
}
/** Returns whether this block overlaps any selection requests. */
/** Returns whether this block overlaps any selection plans. */
boolean checkOverlapPlacement(int x, int y, Block block){
r2.setSize(block.size * tilesize);
r2.setCenter(x * tilesize + block.offset, y * tilesize + block.offset);
for(BuildPlan req : selectRequests){
for(BuildPlan req : selectPlans){
Tile other = req.tile();
if(other == null || req.breaking) continue;
@@ -141,12 +141,12 @@ public class MobileInput extends InputHandler implements GestureListener{
return false;
}
/** Returns the selection request that overlaps this tile, or null. */
BuildPlan getRequest(Tile tile){
/** Returns the selection plan that overlaps this tile, or null. */
BuildPlan getPlan(Tile tile){
r2.setSize(tilesize);
r2.setCenter(tile.worldx(), tile.worldy());
for(BuildPlan req : selectRequests){
for(BuildPlan req : selectPlans){
Tile other = req.tile();
if(other == null) continue;
@@ -165,10 +165,10 @@ public class MobileInput extends InputHandler implements GestureListener{
return null;
}
void removeRequest(BuildPlan request){
selectRequests.remove(request, true);
if(!request.breaking){
removals.add(request);
void removePlan(BuildPlan plan){
selectPlans.remove(plan, true);
if(!plan.breaking){
removals.add(plan);
}
}
@@ -220,48 +220,48 @@ public class MobileInput extends InputHandler implements GestureListener{
//confirm button
table.button(Icon.ok, Styles.clearPartiali, () -> {
for(BuildPlan request : selectRequests){
Tile tile = request.tile();
for(BuildPlan plan : selectPlans){
Tile tile = plan.tile();
//actually place/break all selected blocks
if(tile != null){
if(!request.breaking){
if(validPlace(request.x, request.y, request.block, request.rotation)){
BuildPlan other = getRequest(request.x, request.y, request.block.size, null);
BuildPlan copy = request.copy();
if(!plan.breaking){
if(validPlace(plan.x, plan.y, plan.block, plan.rotation)){
BuildPlan other = getPlan(plan.x, plan.y, plan.block.size, null);
BuildPlan copy = plan.copy();
if(other == null){
player.unit().addBuild(copy);
}else if(!other.breaking && other.x == request.x && other.y == request.y && other.block.size == request.block.size){
}else if(!other.breaking && other.x == plan.x && other.y == plan.y && other.block.size == plan.block.size){
player.unit().plans().remove(other);
player.unit().addBuild(copy);
}
}
rotation = request.rotation;
rotation = plan.rotation;
}else{
tryBreakBlock(tile.x, tile.y);
}
}
}
//move all current requests to removal array so they fade out
removals.addAll(selectRequests.select(r -> !r.breaking));
selectRequests.clear();
//move all current plans to removal array so they fade out
removals.addAll(selectPlans.select(r -> !r.breaking));
selectPlans.clear();
selecting = false;
}).visible(() -> !selectRequests.isEmpty()).name("confirmplace");
}).visible(() -> !selectPlans.isEmpty()).name("confirmplace");
}
@Override
public void buildUI(Group group){
Boolp schem = () -> lastSchematic != null && !selectRequests.isEmpty();
Boolp schem = () -> lastSchematic != null && !selectPlans.isEmpty();
group.fill(t -> {
t.visible(() -> (player.unit().isBuilding() || block != null || mode == breaking || !selectRequests.isEmpty()) && !schem.get());
t.visible(() -> (player.unit().isBuilding() || block != null || mode == breaking || !selectPlans.isEmpty()) && !schem.get());
t.bottom().left();
t.button("@cancel", Icon.cancel, () -> {
player.unit().clearBuilding();
selectRequests.clear();
selectPlans.clear();
mode = none;
block = null;
}).width(155f).height(50f).margin(12f);
@@ -277,14 +277,14 @@ public class MobileInput extends InputHandler implements GestureListener{
b.button(Icon.save, style, this::showSchematicSave).disabled(f -> lastSchematic == null || lastSchematic.file != null);
b.button(Icon.cancel, style, () -> {
selectRequests.clear();
selectPlans.clear();
lastSchematic = null;
});
b.row();
b.button(Icon.flipX, style, () -> flipRequests(selectRequests, true));
b.button(Icon.flipY, style, () -> flipRequests(selectRequests, false));
b.button(Icon.flipX, style, () -> flipPlans(selectPlans, true));
b.button(Icon.flipY, style, () -> flipPlans(selectPlans, false));
b.row();
b.button(Icon.rotate, style, () -> rotateRequests(selectRequests, 1));
b.button(Icon.rotate, style, () -> rotatePlans(selectPlans, 1));
}).margin(4f);
});
@@ -294,18 +294,18 @@ public class MobileInput extends InputHandler implements GestureListener{
public void drawBottom(){
Lines.stroke(1f);
//draw requests about to be removed
for(BuildPlan request : removals){
Tile tile = request.tile();
//draw plans about to be removed
for(BuildPlan plan : removals){
Tile tile = plan.tile();
if(tile == null) continue;
request.animScale = Mathf.lerpDelta(request.animScale, 0f, 0.2f);
plan.animScale = Mathf.lerpDelta(plan.animScale, 0f, 0.2f);
if(request.breaking){
drawSelected(request.x, request.y, tile.block(), Pal.remove);
if(plan.breaking){
drawSelected(plan.x, plan.y, tile.block(), Pal.remove);
}else{
request.block.drawPlan(request, allRequests(), true);
plan.block.drawPlan(plan, allPlans(), true);
}
}
@@ -319,15 +319,15 @@ public class MobileInput extends InputHandler implements GestureListener{
if(mode == placing && block != null){
//draw placing
for(int i = 0; i < lineRequests.size; i++){
BuildPlan request = lineRequests.get(i);
if(i == lineRequests.size - 1 && request.block.rotate){
drawArrow(block, request.x, request.y, request.rotation);
for(int i = 0; i < linePlans.size; i++){
BuildPlan plan = linePlans.get(i);
if(i == linePlans.size - 1 && plan.block.rotate){
drawArrow(block, plan.x, plan.y, plan.rotation);
}
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null);
drawSelected(request.x, request.y, request.block, Pal.accent);
plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation) && getPlan(plan.x, plan.y, plan.block.size, null) == null);
drawSelected(plan.x, plan.y, plan.block, Pal.accent);
}
lineRequests.each(this::drawOverPlan);
linePlans.each(this::drawOverPlan);
}else if(mode == breaking){
drawBreakSelection(lineStartX, lineStartY, tileX, tileY);
}
@@ -346,39 +346,39 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public void drawOverSelect(){
//draw list of requests
for(BuildPlan request : selectRequests){
Tile tile = request.tile();
//draw list of plans
for(BuildPlan plan : selectPlans){
Tile tile = plan.tile();
if(tile == null) continue;
if((!request.breaking && validPlace(tile.x, tile.y, request.block, request.rotation))
|| (request.breaking && validBreak(tile.x, tile.y))){
request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.2f);
if((!plan.breaking && validPlace(tile.x, tile.y, plan.block, plan.rotation))
|| (plan.breaking && validBreak(tile.x, tile.y))){
plan.animScale = Mathf.lerpDelta(plan.animScale, 1f, 0.2f);
}else{
request.animScale = Mathf.lerpDelta(request.animScale, 0.6f, 0.1f);
plan.animScale = Mathf.lerpDelta(plan.animScale, 0.6f, 0.1f);
}
Tmp.c1.set(Draw.getMixColor());
if(!request.breaking && request == lastPlaced && request.block != null){
if(!plan.breaking && plan == lastPlaced && plan.block != null){
Draw.mixcol();
if(request.block.rotate) drawArrow(request.block, tile.x, tile.y, request.rotation);
if(plan.block.rotate) drawArrow(plan.block, tile.x, tile.y, plan.rotation);
}
Draw.reset();
drawPlan(request);
if(!request.breaking){
drawOverPlan(request);
drawPlan(plan);
if(!plan.breaking){
drawOverPlan(plan);
}
//draw last placed request
if(!request.breaking && request == lastPlaced && request.block != null && request.block.drawArrow){
boolean valid = validPlace(tile.x, tile.y, request.block, rotation);
//draw last placed plan
if(!plan.breaking && plan == lastPlaced && plan.block != null && plan.block.drawArrow){
boolean valid = validPlace(tile.x, tile.y, plan.block, rotation);
Draw.mixcol();
request.block.drawPlace(tile.x, tile.y, rotation, valid);
plan.block.drawPlace(tile.x, tile.y, rotation, valid);
drawOverlapCheck(request.block, tile.x, tile.y, valid);
drawOverlapCheck(plan.block, tile.x, tile.y, valid);
}
}
@@ -399,15 +399,15 @@ public class MobileInput extends InputHandler implements GestureListener{
}
@Override
protected void drawPlan(BuildPlan request){
if(request.tile() == null) return;
brequest.animScale = request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.1f);
protected void drawPlan(BuildPlan plan){
if(plan.tile() == null) return;
bplan.animScale = plan.animScale = Mathf.lerpDelta(plan.animScale, 1f, 0.1f);
if(request.breaking){
drawSelected(request.x, request.y, request.tile().block(), Pal.remove);
if(plan.breaking){
drawSelected(plan.x, plan.y, plan.tile().block(), Pal.remove);
}else{
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
drawSelected(request.x, request.y, request.block, Pal.accent);
plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation));
drawSelected(plan.x, plan.y, plan.block, Pal.accent);
}
}
@@ -417,15 +417,15 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
protected int schemOriginX(){
Tmp.v1.setZero();
selectRequests.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectRequests.size).x);
selectPlans.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectPlans.size).x);
}
@Override
protected int schemOriginY(){
Tmp.v1.setZero();
selectRequests.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectRequests.size).y);
selectPlans.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectPlans.size).y);
}
@Override
@@ -440,8 +440,8 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public void useSchematic(Schematic schem){
selectRequests.clear();
selectRequests.addAll(schematics.toRequests(schem, World.toTile(Core.camera.position.x), World.toTile(Core.camera.position.y)));
selectPlans.clear();
selectPlans.addAll(schematics.toPlans(schem, World.toTile(Core.camera.position.x), World.toTile(Core.camera.position.y)));
lastSchematic = schem;
}
@@ -461,8 +461,8 @@ public class MobileInput extends InputHandler implements GestureListener{
//ignore off-screen taps
if(cursor == null || Core.scene.hasMouse(screenX, screenY)) return false;
//only begin selecting if the tapped block is a request
selecting = hasRequest(cursor);
//only begin selecting if the tapped block is a plan
selecting = hasPlan(cursor);
//call tap events
if(pointer == 0 && !selecting){
@@ -501,7 +501,7 @@ public class MobileInput extends InputHandler implements GestureListener{
int tileY = tileY(screenY);
if(mode == placing && isPlacing()){
flushSelectRequests(lineRequests);
flushSelectPlans(linePlans);
Events.fire(new LineConfirmEvent());
}else if(mode == breaking){
removeSelection(lineStartX, lineStartY, tileX, tileY, true);
@@ -509,10 +509,10 @@ public class MobileInput extends InputHandler implements GestureListener{
lineMode = false;
}else if(mode == schematicSelect){
selectRequests.clear();
selectPlans.clear();
lastSchematic = schematics.create(lineStartX, lineStartY, lastLineX, lastLineY);
useSchematic(lastSchematic);
if(selectRequests.isEmpty()){
if(selectPlans.isEmpty()){
lastSchematic = null;
}
schematicMode = false;
@@ -566,7 +566,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//ignore off-screen taps
if(cursor == null) return false;
//remove request if it's there
//remove plan if it's there
//long pressing enables line mode otherwise
lineStartX = cursor.x;
lineStartY = cursor.y;
@@ -605,16 +605,16 @@ public class MobileInput extends InputHandler implements GestureListener{
checkTargets(worldx, worldy);
}
//remove if request present
if(hasRequest(cursor)){
removeRequest(getRequest(cursor));
//remove if plan present
if(hasPlan(cursor)){
removePlan(getPlan(cursor));
}else if(mode == placing && isPlacing() && validPlace(cursor.x, cursor.y, block, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, block)){
//add to selection queue if it's a valid place position
selectRequests.add(lastPlaced = new BuildPlan(cursor.x, cursor.y, rotation, block, block.nextConfig()));
selectPlans.add(lastPlaced = new BuildPlan(cursor.x, cursor.y, rotation, block, block.nextConfig()));
block.onNewPlan(lastPlaced);
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasRequest(linked)){
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasPlan(linked)){
//add to selection queue if it's a valid BREAK position
selectRequests.add(new BuildPlan(linked.x, linked.y));
selectPlans.add(new BuildPlan(linked.x, linked.y));
}else{
//control units
if(count == 2){
@@ -650,7 +650,7 @@ public class MobileInput extends InputHandler implements GestureListener{
super.updateState();
if(state.isMenu()){
selectRequests.clear();
selectPlans.clear();
removals.clear();
mode = none;
manualShooting = false;
@@ -671,7 +671,7 @@ public class MobileInput extends InputHandler implements GestureListener{
}
//zoom camera
if(!locked && Math.abs(Core.input.axisTap(Binding.zoom)) > 0 && !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectRequests.isEmpty()))){
if(!locked && Math.abs(Core.input.axisTap(Binding.zoom)) > 0 && !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectPlans.isEmpty()))){
renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
}
@@ -751,15 +751,14 @@ public class MobileInput extends InputHandler implements GestureListener{
updateLine(lineStartX, lineStartY, lx, ly);
}
}else{
lineRequests.clear();
linePlans.clear();
lineScale = 0f;
}
//remove place requests that have disappeared
//remove place plans that have disappeared
for(int i = removals.size - 1; i >= 0; i--){
BuildPlan request = removals.get(i);
if(request.animScale <= 0.0001f){
if(removals.get(i).animScale <= 0.0001f){
removals.remove(i);
i--;
}
@@ -815,7 +814,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//do not pan with manual shooting enabled
if(!down || manualShooting) return false;
if(selecting){ //pan all requests
if(selecting){ //pan all plans
shiftDeltaX += deltaX;
shiftDeltaY += deltaY;
@@ -823,8 +822,8 @@ public class MobileInput extends InputHandler implements GestureListener{
int shiftedY = (int)(shiftDeltaY / tilesize);
if(Math.abs(shiftedX) > 0 || Math.abs(shiftedY) > 0){
for(BuildPlan req : selectRequests){
if(req.breaking) continue; //don't shift removal requests
for(BuildPlan req : selectPlans){
if(req.breaking) continue; //don't shift removal plans
req.x += shiftedX;
req.y += shiftedY;
}