Persistent player spectating on desktop

This commit is contained in:
Anuken
2024-10-29 10:08:04 -04:00
parent 81282edce9
commit 1558783b7d
4 changed files with 24 additions and 8 deletions

View File

@ -236,15 +236,18 @@ public class DesktopInput extends InputHandler{
if(!detached){ if(!detached){
panning = false; panning = false;
} }
spectating = null;
} }
if(input.keyDown(Binding.pan)){ if(input.keyDown(Binding.pan)){
panCam = true; panCam = true;
panning = true; panning = true;
spectating = null;
} }
if((Math.abs(Core.input.axis(Binding.move_x)) > 0 || Math.abs(Core.input.axis(Binding.move_y)) > 0 || input.keyDown(Binding.mouse_move))){ if((Math.abs(Core.input.axis(Binding.move_x)) > 0 || Math.abs(Core.input.axis(Binding.move_y)) > 0 || input.keyDown(Binding.mouse_move))){
panning = false; panning = false;
spectating = null;
} }
} }
@ -258,11 +261,13 @@ public class DesktopInput extends InputHandler{
} }
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(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){ }else if((!player.dead() || spectating != null) && !panning){
//TODO do not pan //TODO do not pan
Team corePanTeam = state.won ? state.rules.waveTeam : player.team(); Team corePanTeam = state.won ? state.rules.waveTeam : player.team();
Position coreTarget = state.gameOver && !state.rules.pvp && corePanTeam.data().lastCore != null ? corePanTeam.data().lastCore : null; Position coreTarget = state.gameOver && !state.rules.pvp && corePanTeam.data().lastCore != null ? corePanTeam.data().lastCore : null;
Core.camera.position.lerpDelta(coreTarget != null ? coreTarget : player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f); Position panTarget = coreTarget != null ? coreTarget : spectating != null ? spectating : player;
Core.camera.position.lerpDelta(panTarget, Core.settings.getBool("smoothcamera") ? 0.08f : 1f);
} }
if(panCam){ if(panCam){

View File

@ -100,6 +100,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public Seq<BuildPlan> selectPlans = new Seq<>(BuildPlan.class); public Seq<BuildPlan> selectPlans = new Seq<>(BuildPlan.class);
public Queue<BuildPlan> lastPlans = new Queue<>(); public Queue<BuildPlan> lastPlans = new Queue<>();
public @Nullable Unit lastUnit; public @Nullable Unit lastUnit;
public @Nullable Unit spectating;
//for RTS controls //for RTS controls
public Seq<Unit> selectedUnits = new Seq<>(); public Seq<Unit> selectedUnits = new Seq<>();
@ -801,7 +802,16 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return !selectPlans.isEmpty(); return !selectPlans.isEmpty();
} }
public void spectate(Unit unit){
spectating = unit;
camera.position.set(unit);
}
public void update(){ public void update(){
if(spectating != null && (!spectating.isValid() || spectating.team != player.team())){
spectating = null;
}
if(logicCutscene && !renderer.isCutscene()){ if(logicCutscene && !renderer.isCutscene()){
Core.camera.position.lerpDelta(logicCamPan, logicCamSpeed); Core.camera.position.lerpDelta(logicCamPan, logicCamSpeed);
}else{ }else{

View File

@ -779,7 +779,11 @@ public class MobileInput extends InputHandler implements GestureListener{
if(!Core.settings.getBool("keyboard") && !locked && !scene.hasKeyboard()){ if(!Core.settings.getBool("keyboard") && !locked && !scene.hasKeyboard()){
//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)); Vec2 delta = 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(delta);
if(!delta.isZero()){
spectating = null;
}
} }
if(Core.settings.getBool("keyboard")){ if(Core.settings.getBool("keyboard")){
@ -940,6 +944,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//pan player //pan player
Core.camera.position.x -= deltaX; Core.camera.position.x -= deltaX;
Core.camera.position.y -= deltaY; Core.camera.position.y -= deltaY;
spectating = null;
} }
camera.position.clamp(-camera.width/4f, -camera.height/4f, world.unitWidth() + camera.width/4f, world.unitHeight() + camera.height/4f); camera.position.clamp(-camera.width/4f, -camera.height/4f, world.unitWidth() + camera.width/4f, world.unitHeight() + camera.height/4f);

View File

@ -13,7 +13,6 @@ import arc.util.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.input.*;
import mindustry.net.*; import mindustry.net.*;
import mindustry.net.Packets.*; import mindustry.net.Packets.*;
import mindustry.ui.*; import mindustry.ui.*;
@ -127,11 +126,8 @@ public class PlayerListFragment{
iconTable.tapped(() -> { iconTable.tapped(() -> {
if(!user.dead() && clickable){ if(!user.dead() && clickable){
Core.camera.position.set(user.unit()); control.input.spectate(user.unit());
ui.showInfoFade(Core.bundle.format("viewplayer", user.name), 1f); ui.showInfoFade(Core.bundle.format("viewplayer", user.name), 1f);
if(control.input instanceof DesktopInput input){
input.panning = true;
}
} }
}); });