Added InputHandler lock system

This commit is contained in:
Anuken
2021-10-03 11:21:53 -04:00
parent b20cdb97c5
commit aed57aaac3
3 changed files with 40 additions and 22 deletions
+8 -4
View File
@@ -192,6 +192,7 @@ public class DesktopInput extends InputHandler{
ui.listfrag.toggle(); ui.listfrag.toggle();
} }
boolean locked = locked();
boolean panCam = false; boolean panCam = false;
float camSpeed = (!Core.input.keyDown(Binding.boost) ? panSpeed : panBoostSpeed) * Time.delta; float camSpeed = (!Core.input.keyDown(Binding.boost) ? panSpeed : panBoostSpeed) * Time.delta;
@@ -204,6 +205,7 @@ public class DesktopInput extends InputHandler{
panning = false; panning = false;
} }
if(!locked){
if(((player.dead() || state.isPaused()) && !ui.chatfrag.shown()) && !scene.hasField() && !scene.hasDialog()){ if(((player.dead() || state.isPaused()) && !ui.chatfrag.shown()) && !scene.hasField() && !scene.hasDialog()){
if(input.keyDown(Binding.mouse_move)){ if(input.keyDown(Binding.mouse_move)){
panCam = true; panCam = true;
@@ -219,9 +221,11 @@ public class DesktopInput extends InputHandler{
Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * panScale, -1, 1) * camSpeed; Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * panScale, -1, 1) * camSpeed;
} }
shouldShoot = !scene.hasMouse(); }
if(!scene.hasMouse()){ shouldShoot = !scene.hasMouse() && !locked;
if(!scene.hasMouse() && !locked){
if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){ if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){
Unit on = selectedUnit(); Unit on = selectedUnit();
var build = selectedControlBuild(); var build = selectedControlBuild();
@@ -236,7 +240,7 @@ public class DesktopInput extends InputHandler{
} }
} }
if(!player.dead() && !state.isPaused() && !scene.hasField() && !renderer.isCutscene()){ if(!player.dead() && !state.isPaused() && !scene.hasField() && !locked){
updateMovement(player.unit()); updateMovement(player.unit());
if(Core.input.keyTap(Binding.respawn)){ if(Core.input.keyTap(Binding.respawn)){
@@ -271,7 +275,7 @@ public class DesktopInput extends InputHandler{
} }
} }
if(player.dead()){ if(player.dead() || locked){
cursorType = SystemCursor.arrow; cursorType = SystemCursor.arrow;
return; return;
} }
@@ -50,6 +50,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public final OverlayFragment frag = new OverlayFragment(); public final OverlayFragment frag = new OverlayFragment();
/** If any of these functions return true, input is locked. */
public Seq<Boolp> inputLocks = Seq.with(() -> renderer.isCutscene());
public Interval controlInterval = new Interval(); public Interval controlInterval = new Interval();
public @Nullable Block block; public @Nullable Block block;
public boolean overrideLineRotation; public boolean overrideLineRotation;
@@ -433,6 +435,16 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
/** Adds an input lock; if this function returns true, input is locked. Used for mod cutscenes or panning. */
public void addLock(Boolp lock){
inputLocks.add(lock);
}
/** @return whether most input is locked, for 'cutscenes' */
public boolean locked(){
return inputLocks.contains(Boolp::get);
}
public Eachable<BuildPlan> allRequests(){ public Eachable<BuildPlan> allRequests(){
return cons -> { return cons -> {
for(BuildPlan request : player.unit().plans()) cons.get(request); for(BuildPlan request : player.unit().plans()) cons.get(request);
+9 -7
View File
@@ -435,7 +435,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
public boolean touchDown(int screenX, int screenY, int pointer, KeyCode button){ public boolean touchDown(int screenX, int screenY, int pointer, KeyCode button){
if(state.isMenu()) return false; if(state.isMenu() || locked()) return false;
down = true; down = true;
@@ -515,7 +515,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
public boolean longPress(float x, float y){ public boolean longPress(float x, float y){
if(state.isMenu()|| player.dead()) return false; if(state.isMenu()|| player.dead() || locked()) return false;
//get tile on cursor //get tile on cursor
Tile cursor = tileAt(x, y); Tile cursor = tileAt(x, y);
@@ -575,7 +575,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
public boolean tap(float x, float y, int count, KeyCode button){ public boolean tap(float x, float y, int count, KeyCode button){
if(state.isMenu() || lineMode) return false; if(state.isMenu() || lineMode || locked()) return false;
float worldx = Core.input.mouseWorld(x, y).x, worldy = Core.input.mouseWorld(x, y).y; float worldx = Core.input.mouseWorld(x, y).x, worldy = Core.input.mouseWorld(x, y).y;
@@ -654,6 +654,8 @@ public class MobileInput extends InputHandler implements GestureListener{
public void update(){ public void update(){
super.update(); super.update();
boolean locked = locked();
if(player.dead()){ if(player.dead()){
mode = none; mode = none;
manualShooting = false; manualShooting = false;
@@ -661,11 +663,11 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
//zoom camera //zoom camera
if(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) && selectRequests.isEmpty()))){
renderer.scaleCamera(Core.input.axisTap(Binding.zoom)); renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
} }
if(!Core.settings.getBool("keyboard")){ if(!Core.settings.getBool("keyboard") && !locked){
//move camera around //move camera around
float camSpeed = 6f; float camSpeed = 6f;
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)); 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));
@@ -681,7 +683,7 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
} }
if(!player.dead() && !state.isPaused() && !renderer.isCutscene()){ if(!player.dead() && !state.isPaused() && !locked){
updateMovement(player.unit()); updateMovement(player.unit());
} }
@@ -791,7 +793,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
public boolean pan(float x, float y, float deltaX, float deltaY){ public boolean pan(float x, float y, float deltaX, float deltaY){
if(Core.scene == null || Core.scene.hasDialog() || Core.settings.getBool("keyboard")) return false; if(Core.scene == null || Core.scene.hasDialog() || Core.settings.getBool("keyboard") || locked()) return false;
float scale = Core.camera.width / Core.graphics.getWidth(); float scale = Core.camera.width / Core.graphics.getWidth();
deltaX *= scale; deltaX *= scale;