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

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

View File

@@ -16,51 +16,51 @@ public class DefaultKeybinds{
for(String section : sections){ for(String section : sections){
KeyBinds.defaultSection(section, DeviceType.keyboard, KeyBinds.defaultSection(section, DeviceType.keyboard,
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,
"zoom", new Axis(Input.SCROLL), "zoom", new Axis(Input.SCROLL),
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS), "zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE, "menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
"pause", Input.Q, "pause", Input.Q,
"toggle_menus", Input.C, "toggle_menus", Input.C,
new Category("multiplayer"), new Category("multiplayer"),
"player_list", Input.TAB, "player_list", Input.TAB,
"chat", Input.ENTER, "chat", Input.ENTER,
"chat_history_prev", Input.UP, "chat_history_prev", Input.UP,
"chat_history_next", Input.DOWN, "chat_history_next", Input.DOWN,
"chat_scroll", new Axis(Input.SCROLL), "chat_scroll", new Axis(Input.SCROLL),
"console", Input.GRAVE "console", Input.GRAVE
); );
KeyBinds.defaultSection(section, DeviceType.controller, KeyBinds.defaultSection(section, DeviceType.controller,
new Category("general"), new Category("general"),
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS), "move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS), "move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS), "cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS), "cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
//"select", Input.CONTROLLER_R_BUMPER, //"select", Input.CONTROLLER_R_BUMPER,
//"break", Input.CONTROLLER_L_BUMPER, //"break", Input.CONTROLLER_L_BUMPER,
//"shoot", Input.CONTROLLER_R_TRIGGER, //"shoot", Input.CONTROLLER_R_TRIGGER,
"dash", Input.CONTROLLER_Y, "dash", Input.CONTROLLER_Y,
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT), "rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B), "rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
new Category("view"), new Category("view"),
"zoom_hold", Input.ANY_KEY, "zoom_hold", Input.ANY_KEY,
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP), "zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
"menu", Input.CONTROLLER_X, "menu", Input.CONTROLLER_X,
"pause", Input.CONTROLLER_L_TRIGGER, "pause", Input.CONTROLLER_L_TRIGGER,
new Category("multiplayer"), new Category("multiplayer"),
"player_list", Input.CONTROLLER_START "player_list", Input.CONTROLLER_START
); );
} }

View File

@@ -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,91 +220,75 @@ 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;
Tile cursor = tileAt(screenX, screenY);
if(cursor == null) return false;
float worldx = Graphics.world(screenX, screenY).x, worldy = Graphics.world(screenX, screenY).y;
if(button == Buttons.LEFT){ //left = begin placing
if(isPlacing()){
selectX = cursor.x;
selectY = cursor.y;
mode = placing;
}else{
//only begin shooting if there's no cursor event
if(!tileTapped(cursor) && !tryTapPlayer(worldx, worldy) && player.getPlaceQueue().size == 0 && !droppingItem &&
!tryBeginMine(cursor) && player.getMineTile() == null){
player.isShooting = true;
}
}
}else if(button == Buttons.RIGHT){ //right = begin breaking
selectX = cursor.x;
selectY = cursor.y;
mode = breaking;
}else if(button == Buttons.MIDDLE){ //middle button = cancel placing
if(recipe == null){
player.clearBuilding();
}
recipe = null;
mode = none;
}
return false;
}
@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){ if(cursor == null){
mode = none; mode = none;
return false; return;
} }
if(mode == placing){ //touch up while placing, place everything in selection if(!ui.hasMouse()){
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength); if(Inputs.keyTap(section, "select")){
if(isPlacing()){
selectX = cursor.x;
selectY = cursor.y;
mode = placing;
}else{
//only begin shooting if there's no cursor event
if (!tileTapped(cursor) && !tryTapPlayer(Graphics.mouseWorld().x, Graphics.mouseWorld().y) && player.getPlaceQueue().size == 0 && !droppingItem &&
!tryBeginMine(cursor) && player.getMineTile() == null) {
player.isShooting = true;
}
}
}else if(Inputs.keyTap(section, "deselect") && (recipe != null || mode != none || player.isBuilding())){
if(recipe == null){
player.clearBuilding();
}
for(int i = 0; i <= result.getLength(); i += recipe.result.size){ recipe = null;
int x = selectX + i * Mathf.sign(cursor.x - selectX) * Mathf.bool(result.isX()); mode = none;
int y = selectY + i * Mathf.sign(cursor.y - selectY) * Mathf.bool(!result.isX()); }else if(Inputs.keyTap(section, "break")){
selectX = cursor.x;
rotation = result.rotation; selectY = cursor.y;
mode = breaking;
tryPlaceBlock(x, y);
} }
}else if(mode == breaking){ //touch up while breaking, break everything in selection }
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, false, maxLength);
if(debug && Inputs.keyDown(Input.CONTROL_LEFT)){ if(Inputs.keyRelease(section, "break") || Inputs.keyRelease(section, "select")){
printArea(result);
}else{
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
int wx = selectX + x * Mathf.sign(cursor.x - selectX);
int wy = selectY + y * Mathf.sign(cursor.y - selectY);
tryBreakBlock(wx, wy); if(mode == placing){ //touch up while placing, place everything in selection
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
int x = selectX + i * Mathf.sign(cursor.x - selectX) * Mathf.bool(result.isX());
int y = selectY + i * Mathf.sign(cursor.y - selectY) * Mathf.bool(!result.isX());
rotation = result.rotation;
tryPlaceBlock(x, y);
}
}else if(mode == breaking){ //touch up while breaking, break everything in selection
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, false, maxLength);
if(debug && Inputs.keyDown(Input.CONTROL_LEFT)){
printArea(result);
}else{
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
int wx = selectX + x * Mathf.sign(cursor.x - selectX);
int wy = selectY + y * Mathf.sign(cursor.y - selectY);
tryBreakBlock(wx, wy);
}
} }
} }
} }
tryDropItems(cursor.target(), Graphics.mouseWorld().x, Graphics.mouseWorld().y);
mode = none;
} }
tryDropItems(cursor.target(), Graphics.world(screenX, screenY).x, Graphics.world(screenX, screenY).y);
mode = none;
return false;
} }
@Override @Override