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

View File

@ -192,6 +192,7 @@ public class DesktopInput extends InputHandler{
ui.listfrag.toggle();
}
boolean locked = locked();
boolean panCam = false;
float camSpeed = (!Core.input.keyDown(Binding.boost) ? panSpeed : panBoostSpeed) * Time.delta;
@ -204,24 +205,27 @@ public class DesktopInput extends InputHandler{
panning = false;
}
if(((player.dead() || state.isPaused()) && !ui.chatfrag.shown()) && !scene.hasField() && !scene.hasDialog()){
if(input.keyDown(Binding.mouse_move)){
panCam = true;
if(!locked){
if(((player.dead() || state.isPaused()) && !ui.chatfrag.shown()) && !scene.hasField() && !scene.hasDialog()){
if(input.keyDown(Binding.mouse_move)){
panCam = true;
}
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(camSpeed));
}else if(!player.dead() && !panning){
Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f);
}
if(panCam){
Core.camera.position.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * panScale, -1, 1) * camSpeed;
Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * panScale, -1, 1) * camSpeed;
}
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(camSpeed));
}else if(!player.dead() && !panning){
Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f);
}
if(panCam){
Core.camera.position.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 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() && !locked;
shouldShoot = !scene.hasMouse();
if(!scene.hasMouse()){
if(!scene.hasMouse() && !locked){
if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){
Unit on = selectedUnit();
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());
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;
return;
}

View File

@ -50,6 +50,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
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 @Nullable Block block;
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(){
return cons -> {
for(BuildPlan request : player.unit().plans()) cons.get(request);

View File

@ -435,7 +435,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, KeyCode button){
if(state.isMenu()) return false;
if(state.isMenu() || locked()) return false;
down = true;
@ -515,7 +515,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
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
Tile cursor = tileAt(x, y);
@ -575,7 +575,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
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;
@ -654,6 +654,8 @@ public class MobileInput extends InputHandler implements GestureListener{
public void update(){
super.update();
boolean locked = locked();
if(player.dead()){
mode = none;
manualShooting = false;
@ -661,11 +663,11 @@ public class MobileInput extends InputHandler implements GestureListener{
}
//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));
}
if(!Core.settings.getBool("keyboard")){
if(!Core.settings.getBool("keyboard") && !locked){
//move camera around
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));
@ -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());
}
@ -791,7 +793,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
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();
deltaX *= scale;