mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-31 01:44:22 +07:00
Persistent player spectating on desktop
This commit is contained in:
parent
81282edce9
commit
1558783b7d
@ -236,15 +236,18 @@ public class DesktopInput extends InputHandler{
|
||||
if(!detached){
|
||||
panning = false;
|
||||
}
|
||||
spectating = null;
|
||||
}
|
||||
|
||||
if(input.keyDown(Binding.pan)){
|
||||
panCam = 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))){
|
||||
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));
|
||||
}else if(!player.dead() && !panning){
|
||||
}else if((!player.dead() || spectating != null) && !panning){
|
||||
//TODO do not pan
|
||||
Team corePanTeam = state.won ? state.rules.waveTeam : player.team();
|
||||
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){
|
||||
|
@ -100,6 +100,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
public Seq<BuildPlan> selectPlans = new Seq<>(BuildPlan.class);
|
||||
public Queue<BuildPlan> lastPlans = new Queue<>();
|
||||
public @Nullable Unit lastUnit;
|
||||
public @Nullable Unit spectating;
|
||||
|
||||
//for RTS controls
|
||||
public Seq<Unit> selectedUnits = new Seq<>();
|
||||
@ -801,7 +802,16 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
return !selectPlans.isEmpty();
|
||||
}
|
||||
|
||||
public void spectate(Unit unit){
|
||||
spectating = unit;
|
||||
camera.position.set(unit);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(spectating != null && (!spectating.isValid() || spectating.team != player.team())){
|
||||
spectating = null;
|
||||
}
|
||||
|
||||
if(logicCutscene && !renderer.isCutscene()){
|
||||
Core.camera.position.lerpDelta(logicCamPan, logicCamSpeed);
|
||||
}else{
|
||||
|
@ -779,7 +779,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
if(!Core.settings.getBool("keyboard") && !locked && !scene.hasKeyboard()){
|
||||
//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));
|
||||
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")){
|
||||
@ -940,6 +944,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//pan player
|
||||
Core.camera.position.x -= deltaX;
|
||||
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);
|
||||
|
@ -13,7 +13,6 @@ import arc.util.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.input.*;
|
||||
import mindustry.net.*;
|
||||
import mindustry.net.Packets.*;
|
||||
import mindustry.ui.*;
|
||||
@ -127,11 +126,8 @@ public class PlayerListFragment{
|
||||
|
||||
iconTable.tapped(() -> {
|
||||
if(!user.dead() && clickable){
|
||||
Core.camera.position.set(user.unit());
|
||||
control.input.spectate(user.unit());
|
||||
ui.showInfoFade(Core.bundle.format("viewplayer", user.name), 1f);
|
||||
if(control.input instanceof DesktopInput input){
|
||||
input.panning = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user