2019-12-25 01:39:38 -05:00
|
|
|
package mindustry.input;
|
2017-05-03 00:09:48 -04:00
|
|
|
|
2019-12-25 01:39:38 -05:00
|
|
|
import arc.*;
|
|
|
|
import arc.Graphics.*;
|
|
|
|
import arc.Graphics.Cursor.*;
|
|
|
|
import arc.graphics.g2d.*;
|
|
|
|
import arc.math.*;
|
|
|
|
import arc.scene.*;
|
|
|
|
import arc.scene.event.*;
|
|
|
|
import arc.scene.ui.*;
|
|
|
|
import arc.scene.ui.layout.*;
|
|
|
|
import arc.util.ArcAnnotate.*;
|
2019-12-29 00:09:46 -05:00
|
|
|
import arc.util.*;
|
2019-12-25 01:39:38 -05:00
|
|
|
import mindustry.*;
|
|
|
|
import mindustry.core.GameState.*;
|
|
|
|
import mindustry.entities.traits.BuilderTrait.*;
|
|
|
|
import mindustry.game.EventType.*;
|
|
|
|
import mindustry.game.*;
|
|
|
|
import mindustry.gen.*;
|
|
|
|
import mindustry.graphics.*;
|
|
|
|
import mindustry.ui.*;
|
|
|
|
import mindustry.world.*;
|
2017-05-03 00:09:48 -04:00
|
|
|
|
2019-12-25 01:39:38 -05:00
|
|
|
import static arc.Core.scene;
|
|
|
|
import static mindustry.Vars.*;
|
|
|
|
import static mindustry.input.PlaceMode.*;
|
2018-01-03 20:15:05 -05:00
|
|
|
|
2017-12-15 01:39:54 -05:00
|
|
|
public class DesktopInput extends InputHandler{
|
2019-04-08 09:03:18 -04:00
|
|
|
/** Current cursor type. */
|
2018-12-26 13:22:31 -05:00
|
|
|
private Cursor cursorType = SystemCursor.arrow;
|
2019-04-08 09:03:18 -04:00
|
|
|
/** Position where the player started dragging a line. */
|
2019-10-14 21:34:06 -04:00
|
|
|
private int selectX, selectY, schemX, schemY;
|
2019-10-06 16:56:31 -04:00
|
|
|
/** Last known line positions.*/
|
2019-10-18 00:41:30 -04:00
|
|
|
private int lastLineX, lastLineY, schematicX, schematicY;
|
2019-04-08 09:03:18 -04:00
|
|
|
/** Whether selecting mode is active. */
|
2018-05-30 13:43:49 -04:00
|
|
|
private PlaceMode mode;
|
2019-04-08 09:03:18 -04:00
|
|
|
/** Animation scale for line. */
|
2018-05-30 00:32:20 -04:00
|
|
|
private float selectScale;
|
2019-10-07 19:51:52 -04:00
|
|
|
/** Selected build request for movement. */
|
|
|
|
private @Nullable BuildRequest sreq;
|
2019-10-07 20:26:08 -04:00
|
|
|
/** Whether player is currently deleting removal requests. */
|
|
|
|
private boolean deleting = false;
|
2019-03-19 15:26:30 -04:00
|
|
|
|
2019-10-06 16:56:31 -04:00
|
|
|
@Override
|
|
|
|
public void buildUI(Group group){
|
|
|
|
group.fill(t -> {
|
2019-10-07 17:17:01 -04:00
|
|
|
t.bottom().update(() -> t.getColor().a = Mathf.lerpDelta(t.getColor().a, player.isBuilding() ? 1f : 0f, 0.15f));
|
2019-10-18 11:38:00 -04:00
|
|
|
t.visible(() -> Core.settings.getBool("hints") && selectRequests.isEmpty());
|
2019-10-23 16:48:55 -04:00
|
|
|
t.touchable(() -> t.getColor().a < 0.1f ? Touchable.disabled : Touchable.childrenOnly);
|
2019-10-07 20:26:08 -04:00
|
|
|
t.table(Styles.black6, b -> {
|
|
|
|
b.defaults().left();
|
2019-11-05 13:08:45 -08:00
|
|
|
b.label(() -> Core.bundle.format(!player.isBuilding ? "resumebuilding" : "pausebuilding", Core.keybinds.get(Binding.pause_building).key.toString())).style(Styles.outlineLabel);
|
2019-10-07 20:26:08 -04:00
|
|
|
b.row();
|
2019-11-14 18:48:12 -05:00
|
|
|
b.label(() -> Core.bundle.format("cancelbuilding", Core.keybinds.get(Binding.clear_building).key.toString())).style(Styles.outlineLabel);
|
2019-10-18 17:18:29 -04:00
|
|
|
b.row();
|
2019-11-14 18:48:12 -05:00
|
|
|
b.label(() -> Core.bundle.format("selectschematic", Core.keybinds.get(Binding.schematic_select).key.toString())).style(Styles.outlineLabel);
|
2019-10-07 20:26:08 -04:00
|
|
|
}).margin(10f);
|
2019-10-06 16:56:31 -04:00
|
|
|
});
|
2019-10-18 11:38:00 -04:00
|
|
|
|
|
|
|
group.fill(t -> {
|
|
|
|
t.visible(() -> lastSchematic != null && !selectRequests.isEmpty());
|
|
|
|
t.bottom();
|
|
|
|
t.table(Styles.black6, b -> {
|
|
|
|
b.defaults().left();
|
2019-11-14 18:48:12 -05:00
|
|
|
b.label( () -> Core.bundle.format("schematic.flip",
|
2019-11-05 13:08:45 -08:00
|
|
|
Core.keybinds.get(Binding.schematic_flip_x).key.toString(),
|
|
|
|
Core.keybinds.get(Binding.schematic_flip_y).key.toString())).style(Styles.outlineLabel);
|
2019-10-18 11:38:00 -04:00
|
|
|
b.row();
|
|
|
|
b.table(a -> {
|
2020-01-17 13:57:04 -05:00
|
|
|
a.addImageTextButton("$schematic.add", Icon.save, this::showSchematicSave).colspan(2).size(250f, 50f).disabled(f -> lastSchematic == null || lastSchematic.file != null);
|
2019-10-18 11:38:00 -04:00
|
|
|
});
|
|
|
|
}).margin(6f);
|
|
|
|
});
|
2019-10-06 16:56:31 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 00:32:20 -04:00
|
|
|
@Override
|
2019-10-06 23:03:02 -04:00
|
|
|
public void drawTop(){
|
2019-01-03 18:22:13 -05:00
|
|
|
Lines.stroke(1f);
|
2018-12-22 22:17:28 -05:00
|
|
|
int cursorX = tileX(Core.input.mouseX());
|
|
|
|
int cursorY = tileY(Core.input.mouseY());
|
2018-05-21 15:03:34 -04:00
|
|
|
|
2018-07-12 20:37:14 -04:00
|
|
|
//draw selection(s)
|
2019-01-20 13:49:53 -05:00
|
|
|
if(mode == placing && block != null){
|
2019-10-06 16:56:31 -04:00
|
|
|
for(int i = 0; i < lineRequests.size; i++){
|
|
|
|
BuildRequest req = lineRequests.get(i);
|
2019-10-06 23:03:02 -04:00
|
|
|
if(i == lineRequests.size - 1 && req.block.rotate){
|
2019-10-06 16:56:31 -04:00
|
|
|
drawArrow(block, req.x, req.y, req.rotation);
|
2018-05-30 12:40:51 -04:00
|
|
|
}
|
2019-10-06 16:56:31 -04:00
|
|
|
drawRequest(lineRequests.get(i));
|
|
|
|
}
|
2018-05-30 13:43:49 -04:00
|
|
|
}else if(mode == breaking){
|
2019-10-18 14:38:43 -04:00
|
|
|
drawBreakSelection(selectX, selectY, cursorX, cursorY);
|
2018-05-30 13:43:49 -04:00
|
|
|
}else if(isPlacing()){
|
2019-01-20 13:49:53 -05:00
|
|
|
if(block.rotate){
|
2019-03-19 15:26:30 -04:00
|
|
|
drawArrow(block, cursorX, cursorY, rotation);
|
2018-05-30 12:40:51 -04:00
|
|
|
}
|
2019-10-06 23:03:02 -04:00
|
|
|
Draw.color();
|
2019-10-06 16:56:31 -04:00
|
|
|
drawRequest(cursorX, cursorY, block, rotation);
|
2019-01-20 13:49:53 -05:00
|
|
|
block.drawPlace(cursorX, cursorY, rotation, validPlace(cursorX, cursorY, block, rotation));
|
2018-05-30 12:40:51 -04:00
|
|
|
}
|
2018-04-19 21:57:55 -04:00
|
|
|
|
2019-10-07 19:51:52 -04:00
|
|
|
if(mode == none && !isPlacing()){
|
|
|
|
BuildRequest req = getRequest(cursorX, cursorY);
|
|
|
|
if(req != null){
|
|
|
|
drawSelected(req.x, req.y, req.breaking ? req.tile().block() : req.block, Pal.accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 00:41:30 -04:00
|
|
|
//draw schematic requests
|
|
|
|
for(BuildRequest request : selectRequests){
|
|
|
|
request.animScale = 1f;
|
|
|
|
drawRequest(request);
|
|
|
|
}
|
|
|
|
|
2019-10-07 19:51:52 -04:00
|
|
|
if(sreq != null){
|
|
|
|
boolean valid = validPlace(sreq.x, sreq.y, sreq.block, sreq.rotation, sreq);
|
|
|
|
if(sreq.block.rotate){
|
|
|
|
drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
sreq.block.drawRequest(sreq, allRequests(), valid);
|
|
|
|
|
|
|
|
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
|
|
|
|
}
|
|
|
|
|
2019-12-07 14:10:39 -05:00
|
|
|
if(Core.input.keyDown(Binding.schematic_select) && !Core.scene.hasKeyboard()){
|
2019-10-18 14:38:43 -04:00
|
|
|
drawSelection(schemX, schemY, cursorX, cursorY, Vars.maxSchematicSize);
|
2019-10-14 21:34:06 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 12:40:51 -04:00
|
|
|
Draw.reset();
|
2018-05-30 00:32:20 -04:00
|
|
|
}
|
2017-12-24 14:40:08 -05:00
|
|
|
|
2018-07-12 20:37:14 -04:00
|
|
|
@Override
|
|
|
|
public void update(){
|
2019-09-07 14:11:50 -04:00
|
|
|
if(net.active() && Core.input.keyTap(Binding.player_list)){
|
2018-06-25 19:25:26 -04:00
|
|
|
ui.listfrag.toggle();
|
|
|
|
}
|
|
|
|
|
2019-12-29 21:45:59 -05:00
|
|
|
if(((player.getClosestCore() == null && player.isDead()) || state.isPaused()) && !ui.chatfrag.shown()){
|
2019-12-29 00:09:46 -05:00
|
|
|
//move camera around
|
2019-12-29 15:40:56 -05:00
|
|
|
float camSpeed = !Core.input.keyDown(Binding.dash) ? 3f : 8f;
|
2019-12-29 00:09:46 -05:00
|
|
|
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(Time.delta() * camSpeed));
|
2019-12-29 17:56:10 -05:00
|
|
|
|
|
|
|
if(Core.input.keyDown(Binding.mouse_move)){
|
|
|
|
Core.camera.position.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * camSpeed;
|
|
|
|
Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * camSpeed;
|
|
|
|
}
|
2019-12-29 00:09:46 -05:00
|
|
|
}
|
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
if(Core.input.keyRelease(Binding.select)){
|
2018-08-30 16:46:41 -04:00
|
|
|
player.isShooting = false;
|
|
|
|
}
|
|
|
|
|
2019-12-29 17:56:10 -05:00
|
|
|
if(!state.is(State.menu) && Core.input.keyTap(Binding.minimap) && !scene.hasDialog() && !(scene.getKeyboardFocus() instanceof TextField)){
|
|
|
|
ui.minimapfrag.toggle();
|
2019-04-28 10:34:53 -04:00
|
|
|
}
|
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
if(state.is(State.menu) || Core.scene.hasDialog()) return;
|
2018-08-07 18:19:02 -04:00
|
|
|
|
2019-12-12 14:56:32 -08:00
|
|
|
//zoom camera
|
2019-12-29 14:38:03 -05:00
|
|
|
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) || ((!isPlacing() || !block.rotate) && selectRequests.isEmpty()))){
|
2018-12-28 13:01:35 -05:00
|
|
|
renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
|
2018-08-07 18:19:02 -04:00
|
|
|
}
|
|
|
|
|
2019-03-18 23:09:03 -04:00
|
|
|
if(player.isDead()){
|
|
|
|
cursorType = SystemCursor.arrow;
|
|
|
|
return;
|
|
|
|
}
|
2018-04-28 19:52:38 -04:00
|
|
|
|
2018-08-30 16:46:41 -04:00
|
|
|
pollInput();
|
|
|
|
|
|
|
|
//deselect if not placing
|
2018-07-12 20:37:14 -04:00
|
|
|
if(!isPlacing() && mode == placing){
|
|
|
|
mode = none;
|
2018-05-30 00:32:20 -04:00
|
|
|
}
|
2018-04-28 19:52:38 -04:00
|
|
|
|
2018-06-13 17:06:46 -04:00
|
|
|
if(player.isShooting && !canShoot()){
|
2018-07-12 20:37:14 -04:00
|
|
|
player.isShooting = false;
|
2018-06-13 17:06:46 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 12:40:51 -04:00
|
|
|
if(isPlacing()){
|
2018-12-26 13:22:31 -05:00
|
|
|
cursorType = SystemCursor.hand;
|
2018-05-30 00:32:20 -04:00
|
|
|
selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f);
|
|
|
|
}else{
|
2018-07-12 20:37:14 -04:00
|
|
|
selectScale = 0f;
|
2018-05-30 00:32:20 -04:00
|
|
|
}
|
|
|
|
|
2019-12-12 14:56:32 -08:00
|
|
|
if(!Core.input.keyDown(Binding.diagonal_placement) && Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0){
|
2019-11-02 14:09:16 -04:00
|
|
|
rotation = Mathf.mod(rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
|
|
|
|
|
|
|
if(sreq != null){
|
|
|
|
sreq.rotation = Mathf.mod(sreq.rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
|
|
|
}
|
2019-10-07 19:51:52 -04:00
|
|
|
|
2019-10-18 14:38:43 -04:00
|
|
|
if(isPlacing() && mode == placing){
|
|
|
|
updateLine(selectX, selectY);
|
|
|
|
}else if(!selectRequests.isEmpty()){
|
|
|
|
rotateRequests(selectRequests, (int)Core.input.axisTap(Binding.rotate));
|
|
|
|
}
|
2019-10-06 17:30:11 -04:00
|
|
|
}
|
2018-06-02 00:46:40 -04:00
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
Tile cursor = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
2018-02-03 21:49:43 -05:00
|
|
|
|
2019-03-18 23:09:03 -04:00
|
|
|
if(cursor != null){
|
2019-05-05 19:05:46 -04:00
|
|
|
cursor = cursor.link();
|
2018-06-02 00:19:31 -04:00
|
|
|
|
2018-06-06 14:51:25 -04:00
|
|
|
cursorType = cursor.block().getCursor(cursor);
|
2018-06-02 00:19:31 -04:00
|
|
|
|
2019-10-18 00:41:30 -04:00
|
|
|
if(isPlacing() || !selectRequests.isEmpty()){
|
2018-12-26 13:22:31 -05:00
|
|
|
cursorType = SystemCursor.hand;
|
2018-06-14 18:36:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!isPlacing() && canMine(cursor)){
|
2018-12-26 13:22:31 -05:00
|
|
|
cursorType = ui.drillCursor;
|
2018-06-02 21:45:07 -04:00
|
|
|
}
|
|
|
|
|
2019-10-07 19:51:52 -04:00
|
|
|
if(getRequest(cursor.x, cursor.y) != null && mode == none){
|
|
|
|
cursorType = SystemCursor.hand;
|
|
|
|
}
|
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
if(canTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y)){
|
2018-12-26 13:22:31 -05:00
|
|
|
cursorType = ui.unloadCursor;
|
2018-06-02 00:19:31 -04:00
|
|
|
}
|
2019-09-29 19:54:52 -04:00
|
|
|
|
2020-01-31 11:07:25 -05:00
|
|
|
if(cursor.interactable(player.getTeam()) && !isPlacing() && Math.abs(Core.input.axisTap(Binding.rotate)) > 0 && Core.input.keyDown(Binding.rotateplaced) && cursor.block().rotate){
|
2019-09-29 19:54:52 -04:00
|
|
|
Call.rotateBlock(player, cursor, Core.input.axisTap(Binding.rotate) > 0);
|
|
|
|
}
|
2018-05-30 00:32:20 -04:00
|
|
|
}
|
2018-04-13 23:55:53 -04:00
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
if(!Core.scene.hasMouse()){
|
2018-12-26 13:22:31 -05:00
|
|
|
Core.graphics.cursor(cursorType);
|
2018-07-12 20:37:14 -04:00
|
|
|
}
|
2018-04-13 23:55:53 -04:00
|
|
|
|
2018-12-26 13:22:31 -05:00
|
|
|
cursorType = SystemCursor.arrow;
|
2018-07-12 20:37:14 -04:00
|
|
|
}
|
2018-03-23 22:42:40 -04:00
|
|
|
|
2019-10-18 00:41:30 -04:00
|
|
|
@Override
|
|
|
|
public void useSchematic(Schematic schem){
|
|
|
|
block = null;
|
|
|
|
schematicX = tileX(getMouseX());
|
|
|
|
schematicY = tileY(getMouseY());
|
|
|
|
|
2019-10-20 10:56:17 -04:00
|
|
|
selectRequests.clear();
|
2019-10-18 00:41:30 -04:00
|
|
|
selectRequests.addAll(schematics.toRequests(schem, schematicX, schematicY));
|
|
|
|
mode = none;
|
|
|
|
}
|
|
|
|
|
2019-10-14 23:43:13 -04:00
|
|
|
@Override
|
|
|
|
public boolean isBreaking(){
|
|
|
|
return mode == breaking;
|
|
|
|
}
|
|
|
|
|
2019-10-19 19:54:41 -04:00
|
|
|
@Override
|
|
|
|
public void buildPlacementUI(Table table){
|
|
|
|
table.addImage().color(Pal.gray).height(4f).colspan(4).growX();
|
|
|
|
table.row();
|
|
|
|
table.left().margin(0f).defaults().size(48f).left();
|
|
|
|
|
2020-01-17 13:57:04 -05:00
|
|
|
table.addImageButton(Icon.paste, Styles.clearPartiali, () -> {
|
2019-10-19 19:54:41 -04:00
|
|
|
ui.schematics.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-30 16:46:41 -04:00
|
|
|
void pollInput(){
|
2019-10-20 12:48:39 -04:00
|
|
|
if(scene.getKeyboardFocus() instanceof TextField) return;
|
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
Tile selected = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
|
|
|
int cursorX = tileX(Core.input.mouseX());
|
|
|
|
int cursorY = tileY(Core.input.mouseY());
|
2019-10-14 21:34:06 -04:00
|
|
|
int rawCursorX = world.toTile(Core.input.mouseWorld().x), rawCursorY = world.toTile(Core.input.mouseWorld().y);
|
2017-05-03 00:09:48 -04:00
|
|
|
|
2019-11-08 16:56:06 -05:00
|
|
|
// automatically pause building if the current build queue is empty
|
|
|
|
if(Core.settings.getBool("buildautopause") && player.isBuilding && !player.isBuilding()){
|
|
|
|
player.isBuilding = false;
|
|
|
|
player.buildWasAutoPaused = true;
|
|
|
|
}
|
|
|
|
|
2019-10-18 00:41:30 -04:00
|
|
|
if(!selectRequests.isEmpty()){
|
|
|
|
int shiftX = rawCursorX - schematicX, shiftY = rawCursorY - schematicY;
|
|
|
|
|
|
|
|
selectRequests.each(s -> {
|
|
|
|
s.x += shiftX;
|
|
|
|
s.y += shiftY;
|
|
|
|
});
|
|
|
|
|
|
|
|
schematicX += shiftX;
|
|
|
|
schematicY += shiftY;
|
|
|
|
}
|
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
if(Core.input.keyTap(Binding.deselect)){
|
2018-09-24 22:56:48 -04:00
|
|
|
player.setMineTile(null);
|
|
|
|
}
|
|
|
|
|
2019-10-06 16:56:31 -04:00
|
|
|
if(Core.input.keyTap(Binding.clear_building)){
|
|
|
|
player.clearBuilding();
|
|
|
|
}
|
|
|
|
|
2019-12-07 14:10:39 -05:00
|
|
|
if(Core.input.keyTap(Binding.schematic_select) && !Core.scene.hasKeyboard()){
|
2019-10-14 21:34:06 -04:00
|
|
|
schemX = rawCursorX;
|
|
|
|
schemY = rawCursorY;
|
|
|
|
}
|
|
|
|
|
2019-12-07 14:10:39 -05:00
|
|
|
if(Core.input.keyTap(Binding.schematic_menu) && !Core.scene.hasKeyboard()){
|
2019-10-25 13:05:04 -04:00
|
|
|
if(ui.schematics.isShown()){
|
|
|
|
ui.schematics.hide();
|
|
|
|
}else{
|
|
|
|
ui.schematics.show();
|
|
|
|
}
|
2019-10-19 21:09:59 -04:00
|
|
|
}
|
|
|
|
|
2019-12-27 01:22:50 -05:00
|
|
|
if(Core.input.keyTap(Binding.clear_building) || isPlacing()){
|
2019-10-19 18:53:27 -04:00
|
|
|
lastSchematic = null;
|
|
|
|
selectRequests.clear();
|
|
|
|
}
|
|
|
|
|
2019-12-07 14:10:39 -05:00
|
|
|
if(Core.input.keyRelease(Binding.schematic_select) && !Core.scene.hasKeyboard()){
|
2019-10-18 11:38:00 -04:00
|
|
|
lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
|
|
|
|
useSchematic(lastSchematic);
|
|
|
|
if(selectRequests.isEmpty()){
|
|
|
|
lastSchematic = null;
|
|
|
|
}
|
2019-10-14 21:34:06 -04:00
|
|
|
}
|
|
|
|
|
2019-10-18 14:38:43 -04:00
|
|
|
if(!selectRequests.isEmpty()){
|
|
|
|
if(Core.input.keyTap(Binding.schematic_flip_x)){
|
|
|
|
flipRequests(selectRequests, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Core.input.keyTap(Binding.schematic_flip_y)){
|
|
|
|
flipRequests(selectRequests, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 19:51:52 -04:00
|
|
|
if(sreq != null){
|
|
|
|
float offset = ((sreq.block.size + 2) % 2) * tilesize / 2f;
|
|
|
|
float x = Core.input.mouseWorld().x + offset;
|
|
|
|
float y = Core.input.mouseWorld().y + offset;
|
|
|
|
sreq.x = (int)(x / tilesize);
|
|
|
|
sreq.y = (int)(y / tilesize);
|
|
|
|
}
|
|
|
|
|
2019-10-06 16:56:31 -04:00
|
|
|
if(block == null || mode != placing){
|
|
|
|
lineRequests.clear();
|
|
|
|
}
|
|
|
|
|
2019-10-07 20:26:08 -04:00
|
|
|
if(Core.input.keyTap(Binding.pause_building)){
|
|
|
|
player.isBuilding = !player.isBuilding;
|
2019-11-08 16:56:06 -05:00
|
|
|
player.buildWasAutoPaused = false;
|
2019-10-07 20:26:08 -04:00
|
|
|
}
|
|
|
|
|
2019-10-06 16:56:31 -04:00
|
|
|
if((cursorX != lastLineX || cursorY != lastLineY) && isPlacing() && mode == placing){
|
|
|
|
updateLine(selectX, selectY);
|
|
|
|
lastLineX = cursorX;
|
|
|
|
lastLineY = cursorY;
|
|
|
|
}
|
|
|
|
|
2018-12-22 22:17:28 -05:00
|
|
|
if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){
|
2019-10-07 19:51:52 -04:00
|
|
|
BuildRequest req = getRequest(cursorX, cursorY);
|
|
|
|
|
2019-12-15 14:26:13 -08:00
|
|
|
if(Core.input.keyDown(Binding.break_block)){
|
|
|
|
mode = none;
|
|
|
|
}else if(!selectRequests.isEmpty()){
|
2019-10-18 00:41:30 -04:00
|
|
|
flushRequests(selectRequests);
|
|
|
|
}else if(isPlacing()){
|
2018-10-13 17:47:58 -04:00
|
|
|
selectX = cursorX;
|
|
|
|
selectY = cursorY;
|
2019-10-06 16:56:31 -04:00
|
|
|
lastLineX = cursorX;
|
|
|
|
lastLineY = cursorY;
|
2018-09-29 20:49:19 -04:00
|
|
|
mode = placing;
|
2019-10-06 16:56:31 -04:00
|
|
|
updateLine(selectX, selectY);
|
2019-10-12 12:52:50 -04:00
|
|
|
}else if(req != null && !req.breaking && mode == none && !req.initialized){
|
2019-10-07 19:51:52 -04:00
|
|
|
sreq = req;
|
2019-10-07 20:26:08 -04:00
|
|
|
}else if(req != null && req.breaking){
|
|
|
|
deleting = true;
|
2018-10-13 17:47:58 -04:00
|
|
|
}else if(selected != null){
|
2018-09-29 20:49:19 -04:00
|
|
|
//only begin shooting if there's no cursor event
|
2019-10-27 14:58:26 -04:00
|
|
|
if(!tileTapped(selected) && !tryTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y) && (player.buildQueue().size == 0 || !player.isBuilding) && !droppingItem &&
|
2019-12-07 14:10:39 -05:00
|
|
|
!tryBeginMine(selected) && player.getMineTile() == null && !Core.scene.hasKeyboard()){
|
2018-09-29 20:49:19 -04:00
|
|
|
player.isShooting = true;
|
|
|
|
}
|
2019-12-07 14:10:39 -05:00
|
|
|
}else if(!Core.scene.hasKeyboard()){ //if it's out of bounds, shooting is just fine
|
2018-10-13 17:47:58 -04:00
|
|
|
player.isShooting = true;
|
2018-09-29 20:49:19 -04:00
|
|
|
}
|
2019-12-15 14:26:13 -08:00
|
|
|
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
|
2019-01-20 13:49:53 -05:00
|
|
|
block = null;
|
2018-09-29 20:49:19 -04:00
|
|
|
mode = none;
|
2019-12-15 14:26:13 -08:00
|
|
|
}else if(Core.input.keyTap(Binding.deselect) && !selectRequests.isEmpty()){
|
|
|
|
selectRequests.clear();
|
|
|
|
lastSchematic = null;
|
2018-12-22 22:17:28 -05:00
|
|
|
}else if(Core.input.keyTap(Binding.break_block) && !Core.scene.hasMouse()){
|
2018-10-22 22:21:22 -04:00
|
|
|
//is recalculated because setting the mode to breaking removes potential multiblock cursor offset
|
2019-10-07 20:26:08 -04:00
|
|
|
deleting = false;
|
2018-09-29 20:49:19 -04:00
|
|
|
mode = breaking;
|
2018-12-22 22:17:28 -05:00
|
|
|
selectX = tileX(Core.input.mouseX());
|
|
|
|
selectY = tileY(Core.input.mouseY());
|
2018-05-30 23:51:42 -04:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:26:08 -04:00
|
|
|
if(Core.input.keyDown(Binding.select) && mode == none && !isPlacing() && deleting){
|
|
|
|
BuildRequest req = getRequest(cursorX, cursorY);
|
|
|
|
if(req != null && req.breaking){
|
|
|
|
player.buildQueue().remove(req);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
deleting = false;
|
|
|
|
}
|
|
|
|
|
2019-10-06 16:56:31 -04:00
|
|
|
if(mode == placing && block != null){
|
2019-12-26 17:46:01 -05:00
|
|
|
if(!overrideLineRotation && !Core.input.keyDown(Binding.diagonal_placement) && (selectX != cursorX || selectY != cursorY) && ((int)Core.input.axisTap(Binding.rotate) != 0)){
|
2019-09-21 15:03:05 -07:00
|
|
|
rotation = ((int)((Angles.angle(selectX, selectY, cursorX, cursorY) + 45) / 90f)) % 4;
|
|
|
|
overrideLineRotation = true;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
overrideLineRotation = false;
|
|
|
|
}
|
|
|
|
|
2019-03-18 23:09:03 -04:00
|
|
|
if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){
|
2018-05-30 12:40:51 -04:00
|
|
|
|
2019-03-18 23:09:03 -04:00
|
|
|
if(mode == placing && block != null){ //touch up while placing, place everything in selection
|
2019-10-06 16:56:31 -04:00
|
|
|
flushRequests(lineRequests);
|
|
|
|
lineRequests.clear();
|
2019-08-08 17:03:45 -04:00
|
|
|
Events.fire(new LineConfirmEvent());
|
2018-08-30 16:46:41 -04:00
|
|
|
}else if(mode == breaking){ //touch up while breaking, break everything in selection
|
2019-10-07 17:17:01 -04:00
|
|
|
removeSelection(selectX, selectY, cursorX, cursorY);
|
2018-05-30 13:43:49 -04:00
|
|
|
}
|
2018-06-02 21:45:07 -04:00
|
|
|
|
2018-10-13 17:47:58 -04:00
|
|
|
if(selected != null){
|
2019-05-05 19:05:46 -04:00
|
|
|
tryDropItems(selected.link(), Core.input.mouseWorld().x, Core.input.mouseWorld().y);
|
2018-10-13 17:47:58 -04:00
|
|
|
}
|
2018-02-03 21:49:43 -05:00
|
|
|
|
2019-10-07 19:51:52 -04:00
|
|
|
if(sreq != null){
|
|
|
|
if(getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null){
|
2019-10-07 20:26:08 -04:00
|
|
|
player.buildQueue().remove(sreq, true);
|
2019-10-07 19:51:52 -04:00
|
|
|
}
|
|
|
|
sreq = null;
|
|
|
|
}
|
|
|
|
|
2018-08-30 16:46:41 -04:00
|
|
|
mode = none;
|
|
|
|
}
|
2019-11-09 00:00:02 -05:00
|
|
|
|
|
|
|
if(Core.input.keyTap(Binding.toggle_power_lines)){
|
|
|
|
if(Core.settings.getInt("lasersopacity") == 0){
|
|
|
|
Core.settings.put("lasersopacity", Core.settings.getInt("preferredlaseropacity", 100));
|
|
|
|
}else{
|
|
|
|
Core.settings.put("preferredlaseropacity", Core.settings.getInt("lasersopacity"));
|
|
|
|
Core.settings.put("lasersopacity", 0);
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 23:09:03 -04:00
|
|
|
}
|
|
|
|
|
2018-10-22 22:21:22 -04:00
|
|
|
@Override
|
|
|
|
public boolean selectedBlock(){
|
|
|
|
return isPlacing() && mode != breaking;
|
|
|
|
}
|
|
|
|
|
2018-05-12 07:30:23 -07:00
|
|
|
@Override
|
2018-07-12 20:37:14 -04:00
|
|
|
public float getMouseX(){
|
2019-02-10 17:32:22 -05:00
|
|
|
return Core.input.mouseX();
|
2018-05-12 07:30:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-12 20:37:14 -04:00
|
|
|
public float getMouseY(){
|
2019-02-10 17:32:22 -05:00
|
|
|
return Core.input.mouseY();
|
2018-05-12 07:30:23 -07:00
|
|
|
}
|
|
|
|
|
2018-05-23 22:23:52 -04:00
|
|
|
@Override
|
2019-09-21 15:35:59 -04:00
|
|
|
public void updateState(){
|
2018-07-15 22:33:14 -04:00
|
|
|
if(state.is(State.menu)){
|
|
|
|
droppingItem = false;
|
2019-04-07 16:58:22 -04:00
|
|
|
mode = none;
|
|
|
|
block = null;
|
2019-10-07 19:51:52 -04:00
|
|
|
sreq = null;
|
2019-10-18 00:41:30 -04:00
|
|
|
selectRequests.clear();
|
2018-07-15 22:33:14 -04:00
|
|
|
}
|
2018-05-12 07:30:23 -07:00
|
|
|
}
|
2017-05-03 00:09:48 -04:00
|
|
|
}
|