Made desktop selection rebindable

This commit is contained in:
Anuken
2018-08-30 16:46:41 -04:00
parent 9816bab151
commit f29673a6e3
3 changed files with 114 additions and 119 deletions
+7 -1
View File
@@ -21,6 +21,7 @@ text.level.delete.title=Confirm Delete
text.map.delete=Are you sure you want to delete the map "[orange]{0}[]"? text.map.delete=Are you sure you want to delete the map "[orange]{0}[]"?
text.level.select=Level Select text.level.select=Level Select
text.level.mode=Gamemode: text.level.mode=Gamemode:
text.construction.desktop=Desktop controls have been changed.\nTo deselect a block or stop building, [accent]use space[].
text.construction.title=Block Construction Guide text.construction.title=Block Construction Guide
text.construction=\ text.construction=\
You've just selected [accent]block construction mode[].\n\n\ You've just selected [accent]block construction mode[].\n\n\
@@ -362,8 +363,9 @@ category.multiplayer.name=Multiplayer
keybind.move_x.name=Move x keybind.move_x.name=Move x
keybind.move_y.name=Move y keybind.move_y.name=Move y
keybind.select.name=Select keybind.select.name=Select/Shoot
keybind.break.name=Break keybind.break.name=Break
keybind.deselect.name=Deselect
keybind.shoot.name=Shoot keybind.shoot.name=Shoot
keybind.zoom_hold.name=Zoom Hold keybind.zoom_hold.name=Zoom Hold
keybind.zoom.name=Zoom keybind.zoom.name=Zoom
@@ -607,6 +609,10 @@ block.titan-pad.name=Titan Pad
block.thermal-generator.name=Thermal Generator block.thermal-generator.name=Thermal Generator
block.alloy-smelter.name=Alloy Smtler block.alloy-smelter.name=Alloy Smtler
block.mend-projector.name=Mend Projector block.mend-projector.name=Mend Projector
block.surge-wall.name=Surge Wall
block.surge-wall-large.name=Large Surge Wall
block.cyclone.name=Cyclone
block.fuse.name=Fuse
unit.alpha-drone.name=Alpha Drone unit.alpha-drone.name=Alpha Drone
unit.drone.name=Drone unit.drone.name=Drone
@@ -19,12 +19,12 @@ public class DefaultKeybinds{
new Category("general"), new Category("general"),
"move_x", new Axis(Input.A, Input.D), "move_x", new Axis(Input.A, Input.D),
"move_y", new Axis(Input.S, Input.W), "move_y", new Axis(Input.S, Input.W),
//"select", Input.MOUSE_LEFT, "select", Input.MOUSE_LEFT,
//"break", Input.MOUSE_RIGHT, "deselect", Input.SPACE,
//"shoot", Input.MOUSE_LEFT, "break", Input.MOUSE_RIGHT,
"rotate", new Axis(Input.SCROLL), "rotate", new Axis(Input.SCROLL),
"dash", Input.SHIFT_LEFT, "dash", Input.SHIFT_LEFT,
"ability", Input.SPACE, "ability", Input.Q,
"drop_unit", Input.SHIFT_LEFT, "drop_unit", Input.SHIFT_LEFT,
new Category("view"), new Category("view"),
"zoom_hold", Input.CONTROL_LEFT, "zoom_hold", Input.CONTROL_LEFT,
@@ -1,7 +1,6 @@
package io.anuke.mindustry.input; package io.anuke.mindustry.input;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
@@ -149,6 +148,10 @@ public class DesktopInput extends InputHandler{
ui.listfrag.toggle(); ui.listfrag.toggle();
} }
if(Inputs.keyRelease(section, "select")){
player.isShooting = false;
}
if(state.is(State.menu) || ui.hasDialog()) return; if(state.is(State.menu) || ui.hasDialog()) return;
boolean controller = KeyBinds.getSection(section).device.type == DeviceType.controller; boolean controller = KeyBinds.getSection(section).device.type == DeviceType.controller;
@@ -162,13 +165,15 @@ public class DesktopInput extends InputHandler{
if(player.isDead()) return; if(player.isDead()) return;
pollInput();
if(recipe != null && !Settings.getBool("desktop-place-help", false)){ if(recipe != null && !Settings.getBool("desktop-place-help", false)){
ui.showInfo("Desktop controls have been changed.\nTo deselect a block or stop building, [accent]use the middle mouse button[]."); ui.showInfo("$text.construction.desktop");
Settings.putBool("desktop-place-help", true); Settings.putBool("desktop-place-help", true);
Settings.save(); Settings.save();
} }
//deslect if not placing //deselect if not placing
if(!isPlacing() && mode == placing){ if(!isPlacing() && mode == placing){
mode = none; mode = none;
} }
@@ -215,57 +220,41 @@ public class DesktopInput extends InputHandler{
cursorType = normal; cursorType = normal;
} }
@Override void pollInput(){
public boolean touchDown(int screenX, int screenY, int pointer, int button){ Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
if(player.isDead() || state.is(State.menu) || ui.hasDialog() || ui.hasMouse()) return false; if(cursor == null){
mode = none;
return;
}
Tile cursor = tileAt(screenX, screenY); if(!ui.hasMouse()){
if(cursor == null) return false; if(Inputs.keyTap(section, "select")){
float worldx = Graphics.world(screenX, screenY).x, worldy = Graphics.world(screenX, screenY).y;
if(button == Buttons.LEFT){ //left = begin placing
if(isPlacing()){ if(isPlacing()){
selectX = cursor.x; selectX = cursor.x;
selectY = cursor.y; selectY = cursor.y;
mode = placing; mode = placing;
}else{ }else{
//only begin shooting if there's no cursor event //only begin shooting if there's no cursor event
if(!tileTapped(cursor) && !tryTapPlayer(worldx, worldy) && player.getPlaceQueue().size == 0 && !droppingItem && if (!tileTapped(cursor) && !tryTapPlayer(Graphics.mouseWorld().x, Graphics.mouseWorld().y) && player.getPlaceQueue().size == 0 && !droppingItem &&
!tryBeginMine(cursor) && player.getMineTile() == null) { !tryBeginMine(cursor) && player.getMineTile() == null) {
player.isShooting = true; player.isShooting = true;
} }
} }
}else if(button == Buttons.RIGHT){ //right = begin breaking }else if(Inputs.keyTap(section, "deselect") && (recipe != null || mode != none || player.isBuilding())){
selectX = cursor.x;
selectY = cursor.y;
mode = breaking;
}else if(button == Buttons.MIDDLE){ //middle button = cancel placing
if(recipe == null){ if(recipe == null){
player.clearBuilding(); player.clearBuilding();
} }
recipe = null; recipe = null;
mode = none; mode = none;
}else if(Inputs.keyTap(section, "break")){
selectX = cursor.x;
selectY = cursor.y;
mode = breaking;
}
} }
return false; if(Inputs.keyRelease(section, "break") || Inputs.keyRelease(section, "select")){
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button){
if(button == Buttons.LEFT){
player.isShooting = false;
}
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false;
Tile cursor = tileAt(screenX, screenY);
if(cursor == null){
mode = none;
return false;
}
if(mode == placing){ //touch up while placing, place everything in selection if(mode == placing){ //touch up while placing, place everything in selection
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength); NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
@@ -295,11 +284,11 @@ public class DesktopInput extends InputHandler{
} }
} }
tryDropItems(cursor.target(), Graphics.world(screenX, screenY).x, Graphics.world(screenX, screenY).y); tryDropItems(cursor.target(), Graphics.mouseWorld().x, Graphics.mouseWorld().y);
mode = none; mode = none;
}
return false;
} }
@Override @Override