Allow commanding units properly even when player is dead
This commit is contained in:
@@ -113,8 +113,6 @@ public class OverlayRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(player.dead()) return; //dead players don't draw
|
|
||||||
|
|
||||||
InputHandler input = control.input;
|
InputHandler input = control.input;
|
||||||
|
|
||||||
Sized select = input.selectedUnit();
|
Sized select = input.selectedUnit();
|
||||||
@@ -150,9 +148,11 @@ public class OverlayRenderer{
|
|||||||
tile.drawConfigure();
|
tile.drawConfigure();
|
||||||
}
|
}
|
||||||
|
|
||||||
input.drawTop();
|
if(!player.dead()) input.drawTop();
|
||||||
input.drawUnitSelection();
|
input.drawUnitSelection();
|
||||||
|
|
||||||
|
if(player.dead()) return; //dead players don't draw
|
||||||
|
|
||||||
buildFade = Mathf.lerpDelta(buildFade, input.isPlacing() || input.isUsingSchematic() ? 1f : 0f, 0.06f);
|
buildFade = Mathf.lerpDelta(buildFade, input.isPlacing() || input.isUsingSchematic() ? 1f : 0f, 0.06f);
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import mindustry.graphics.*;
|
|||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
|
||||||
import static arc.Core.camera;
|
|
||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
import static mindustry.input.PlaceMode.*;
|
import static mindustry.input.PlaceMode.*;
|
||||||
@@ -62,7 +61,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
public long lastPayloadKeyHoldMillis;
|
public long lastPayloadKeyHoldMillis;
|
||||||
|
|
||||||
private float buildPlanMouseOffsetX, buildPlanMouseOffsetY;
|
private float buildPlanMouseOffsetX, buildPlanMouseOffsetY;
|
||||||
private boolean changedCursor;
|
private boolean changedCursor, pressedCommandRect;
|
||||||
|
|
||||||
boolean showHint(){
|
boolean showHint(){
|
||||||
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectPlans.isEmpty() && !player.dead() &&
|
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectPlans.isEmpty() && !player.dead() &&
|
||||||
@@ -438,6 +437,20 @@ public class DesktopInput extends InputHandler{
|
|||||||
if(Core.input.keyTap(Binding.minimap)) ui.minimapfrag.toggle();
|
if(Core.input.keyTap(Binding.minimap)) ui.minimapfrag.toggle();
|
||||||
if(Core.input.keyTap(Binding.planetMap) && state.isCampaign()) ui.planet.toggle();
|
if(Core.input.keyTap(Binding.planetMap) && state.isCampaign()) ui.planet.toggle();
|
||||||
if(Core.input.keyTap(Binding.research) && state.isCampaign()) ui.research.toggle();
|
if(Core.input.keyTap(Binding.research) && state.isCampaign()) ui.research.toggle();
|
||||||
|
if(Core.input.keyTap(Binding.schematicMenu)) ui.schematics.toggle();
|
||||||
|
|
||||||
|
if(Core.input.keyTap(Binding.toggleBlockStatus)){
|
||||||
|
Core.settings.put("blockstatus", !Core.settings.getBool("blockstatus"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Core.input.keyTap(Binding.togglePowerLines)){
|
||||||
|
if(Core.settings.getInt("lasersopacity") == 0){
|
||||||
|
Core.settings.put("lasersopacity", Core.settings.getInt("preferredlaseropacity", 100));
|
||||||
|
}else{
|
||||||
|
Core.settings.put("preferredlaseropacity", Core.settings.getInt("lasersopacity"));
|
||||||
|
Core.settings.put("lasersopacity", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state.isMenu() || Core.scene.hasDialog()) return;
|
if(state.isMenu() || Core.scene.hasDialog()) return;
|
||||||
@@ -456,98 +469,17 @@ public class DesktopInput extends InputHandler{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Core.input.keyRelease(Binding.select) && commandRect){
|
||||||
|
selectUnitsRect();
|
||||||
|
}
|
||||||
|
|
||||||
if(player.dead() || locked){
|
if(player.dead() || locked){
|
||||||
cursorType = SystemCursor.arrow;
|
cursorType = SystemCursor.arrow;
|
||||||
if(!Core.scene.hasMouse()){
|
if(!locked){
|
||||||
Core.graphics.cursor(cursorType);
|
pollInputNoPlayer();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pollInput();
|
|
||||||
|
|
||||||
//deselect if not placing
|
|
||||||
if(!isPlacing() && mode == placing){
|
|
||||||
mode = none;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(player.shooting && !canShoot()){
|
|
||||||
player.shooting = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isPlacing() && player.isBuilder()){
|
|
||||||
cursorType = SystemCursor.hand;
|
|
||||||
selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f);
|
|
||||||
}else{
|
}else{
|
||||||
selectScale = 0f;
|
pollInputPlayer();
|
||||||
}
|
|
||||||
|
|
||||||
if(!Core.input.keyDown(Binding.diagonalPlacement) && Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0){
|
|
||||||
rotation = Mathf.mod(rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
|
||||||
|
|
||||||
if(splan != null){
|
|
||||||
splan.rotation = Mathf.mod(splan.rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isPlacing() && mode == placing){
|
|
||||||
updateLine(selectX, selectY);
|
|
||||||
}else if(!selectPlans.isEmpty() && !ui.chatfrag.shown()){
|
|
||||||
rotatePlans(selectPlans, Mathf.sign(Core.input.axisTap(Binding.rotate)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Tile cursor = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
|
||||||
|
|
||||||
cursorType = SystemCursor.arrow;
|
|
||||||
|
|
||||||
if(cursor != null){
|
|
||||||
if(cursor.build != null && cursor.build.interactable(player.team())){
|
|
||||||
cursorType = cursor.build.getCursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(canRepairDerelict(cursor) && !player.dead() && player.unit().canBuild()){
|
|
||||||
cursorType = ui.repairCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((isPlacing() && player.isBuilder()) || !selectPlans.isEmpty()){
|
|
||||||
cursorType = SystemCursor.hand;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isPlacing() && canMine(cursor)){
|
|
||||||
cursorType = ui.drillCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(commandMode && selectedUnits.any()){
|
|
||||||
boolean canAttack = (cursor.build != null && !cursor.build.inFogTo(player.team()) && cursor.build.team != player.team());
|
|
||||||
|
|
||||||
if(!canAttack){
|
|
||||||
var unit = selectedEnemyUnit(input.mouseWorldX(), input.mouseWorldY());
|
|
||||||
if(unit != null){
|
|
||||||
canAttack = selectedUnits.contains(u -> u.canTarget(unit));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(canAttack){
|
|
||||||
cursorType = ui.targetCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(input.keyTap(Binding.commandQueue) && Binding.commandQueue.value.key.type != KeyType.mouse){
|
|
||||||
commandTap(input.mouseX(), input.mouseY(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(getPlan(cursor.x, cursor.y) != null && mode == none){
|
|
||||||
cursorType = SystemCursor.hand;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(canTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y)){
|
|
||||||
cursorType = ui.unloadCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(cursor.build != null && cursor.interactable(player.team()) && !isPlacing() && Math.abs(Core.input.axisTap(Binding.rotate)) > 0 && Core.input.keyDown(Binding.rotatePlaced) && cursor.block().rotate && cursor.block().quickRotate){
|
|
||||||
Call.rotateBlock(player, cursor.build, Core.input.axisTap(Binding.rotate) > 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Core.scene.hasMouse() && !ui.minimapfrag.shown()){
|
if(!Core.scene.hasMouse() && !ui.minimapfrag.shown()){
|
||||||
@@ -560,10 +492,6 @@ public class DesktopInput extends InputHandler{
|
|||||||
changedCursor = false;
|
changedCursor = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Core.input.keyRelease(Binding.select)){
|
|
||||||
player.shooting = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -603,7 +531,20 @@ public class DesktopInput extends InputHandler{
|
|||||||
}).visible(() -> state.isCampaign()).tooltip("@planetmap");
|
}).visible(() -> state.isCampaign()).tooltip("@planetmap");
|
||||||
}
|
}
|
||||||
|
|
||||||
void pollInput(){
|
void pollInputNoPlayer(){
|
||||||
|
if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){
|
||||||
|
tappedOne = false;
|
||||||
|
|
||||||
|
if(commandMode){
|
||||||
|
commandRect = true;
|
||||||
|
commandRectX = input.mouseWorldX();
|
||||||
|
commandRectY = input.mouseWorldY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//player input: for controlling the player unit (will crash if the unit is not present)
|
||||||
|
void pollInputPlayer(){
|
||||||
if(scene.hasField()) return;
|
if(scene.hasField()) return;
|
||||||
|
|
||||||
Tile selected = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
Tile selected = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
||||||
@@ -642,14 +583,6 @@ public class DesktopInput extends InputHandler{
|
|||||||
schemY = rawCursorY;
|
schemY = rawCursorY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Core.input.keyTap(Binding.schematicMenu) && !Core.scene.hasKeyboard()){
|
|
||||||
if(ui.schematics.isShown()){
|
|
||||||
ui.schematics.hide();
|
|
||||||
}else{
|
|
||||||
ui.schematics.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Core.input.keyTap(Binding.clearBuilding) || isPlacing()){
|
if(Core.input.keyTap(Binding.clearBuilding) || isPlacing()){
|
||||||
lastSchematic = null;
|
lastSchematic = null;
|
||||||
selectPlans.clear();
|
selectPlans.clear();
|
||||||
@@ -711,11 +644,6 @@ public class DesktopInput extends InputHandler{
|
|||||||
lastLineY = cursorY;
|
lastLineY = cursorY;
|
||||||
}
|
}
|
||||||
|
|
||||||
//select some units
|
|
||||||
if(Core.input.keyRelease(Binding.select) && commandRect){
|
|
||||||
selectUnitsRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Core.input.keyRelease(Binding.select) && !Core.scene.hasMouse()){
|
if(Core.input.keyRelease(Binding.select) && !Core.scene.hasMouse()){
|
||||||
BuildPlan plan = getPlan(cursorX, cursorY);
|
BuildPlan plan = getPlan(cursorX, cursorY);
|
||||||
|
|
||||||
@@ -849,17 +777,92 @@ public class DesktopInput extends InputHandler{
|
|||||||
mode = none;
|
mode = none;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Core.input.keyTap(Binding.toggleBlockStatus)){
|
|
||||||
Core.settings.put("blockstatus", !Core.settings.getBool("blockstatus"));
|
//deselect if not placing
|
||||||
|
if(!isPlacing() && mode == placing){
|
||||||
|
mode = none;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Core.input.keyTap(Binding.togglePowerLines)){
|
if(player.shooting && !canShoot()){
|
||||||
if(Core.settings.getInt("lasersopacity") == 0){
|
player.shooting = false;
|
||||||
Core.settings.put("lasersopacity", Core.settings.getInt("preferredlaseropacity", 100));
|
}
|
||||||
}else{
|
|
||||||
Core.settings.put("preferredlaseropacity", Core.settings.getInt("lasersopacity"));
|
if(isPlacing() && player.isBuilder()){
|
||||||
Core.settings.put("lasersopacity", 0);
|
cursorType = SystemCursor.hand;
|
||||||
|
selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f);
|
||||||
|
}else{
|
||||||
|
selectScale = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Core.input.keyDown(Binding.diagonalPlacement) && Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0){
|
||||||
|
rotation = Mathf.mod(rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
||||||
|
|
||||||
|
if(splan != null){
|
||||||
|
splan.rotation = Mathf.mod(splan.rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isPlacing() && mode == placing){
|
||||||
|
updateLine(selectX, selectY);
|
||||||
|
}else if(!selectPlans.isEmpty() && !ui.chatfrag.shown()){
|
||||||
|
rotatePlans(selectPlans, Mathf.sign(Core.input.axisTap(Binding.rotate)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Tile cursor = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
||||||
|
|
||||||
|
cursorType = SystemCursor.arrow;
|
||||||
|
|
||||||
|
if(cursor != null){
|
||||||
|
if(cursor.build != null && cursor.build.interactable(player.team())){
|
||||||
|
cursorType = cursor.build.getCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canRepairDerelict(cursor) && !player.dead() && player.unit().canBuild()){
|
||||||
|
cursorType = ui.repairCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((isPlacing() && player.isBuilder()) || !selectPlans.isEmpty()){
|
||||||
|
cursorType = SystemCursor.hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isPlacing() && canMine(cursor)){
|
||||||
|
cursorType = ui.drillCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(commandMode && selectedUnits.any()){
|
||||||
|
boolean canAttack = (cursor.build != null && !cursor.build.inFogTo(player.team()) && cursor.build.team != player.team());
|
||||||
|
|
||||||
|
if(!canAttack){
|
||||||
|
var unit = selectedEnemyUnit(input.mouseWorldX(), input.mouseWorldY());
|
||||||
|
if(unit != null){
|
||||||
|
canAttack = selectedUnits.contains(u -> u.canTarget(unit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canAttack){
|
||||||
|
cursorType = ui.targetCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(input.keyTap(Binding.commandQueue) && Binding.commandQueue.value.key.type != KeyType.mouse){
|
||||||
|
commandTap(input.mouseX(), input.mouseY(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getPlan(cursor.x, cursor.y) != null && mode == none){
|
||||||
|
cursorType = SystemCursor.hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y)){
|
||||||
|
cursorType = ui.unloadCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cursor.build != null && cursor.interactable(player.team()) && !isPlacing() && Math.abs(Core.input.axisTap(Binding.rotate)) > 0 && Core.input.keyDown(Binding.rotatePlaced) && cursor.block().rotate && cursor.block().quickRotate){
|
||||||
|
Call.rotateBlock(player, cursor.build, Core.input.axisTap(Binding.rotate) > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Core.input.keyRelease(Binding.select)){
|
||||||
|
player.shooting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user