Cleaned up duplicate SettingsMenuDialog code
This commit is contained in:
@@ -200,6 +200,18 @@ public class Weapon implements Cloneable{
|
|||||||
boolean can = unit.canShoot();
|
boolean can = unit.canShoot();
|
||||||
mount.reload = Math.max(mount.reload - Time.delta * unit.reloadMultiplier, 0);
|
mount.reload = Math.max(mount.reload - Time.delta * unit.reloadMultiplier, 0);
|
||||||
|
|
||||||
|
//rotate if applicable
|
||||||
|
if(rotate && (mount.rotate || mount.shoot) && can){
|
||||||
|
float axisX = unit.x + Angles.trnsx(unit.rotation - 90, x, y),
|
||||||
|
axisY = unit.y + Angles.trnsy(unit.rotation - 90, x, y);
|
||||||
|
|
||||||
|
mount.targetRotation = Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - unit.rotation;
|
||||||
|
mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, rotateSpeed * Time.delta);
|
||||||
|
}else if(!rotate){
|
||||||
|
mount.rotation = 0;
|
||||||
|
mount.targetRotation = unit.angleTo(mount.aimX, mount.aimY);
|
||||||
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : 0),
|
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : 0),
|
||||||
mountX = unit.x + Angles.trnsx(unit.rotation - 90, x, y),
|
mountX = unit.x + Angles.trnsx(unit.rotation - 90, x, y),
|
||||||
@@ -256,7 +268,7 @@ public class Weapon implements Cloneable{
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//heat decreases when not firing
|
//heat decreases when not firing
|
||||||
mount.heat = Math.max(mount.heat - Time.delta * unit.reloadMultiplier / mount.weapon.cooldownTime, 0);
|
mount.heat = Math.max(mount.heat - Time.delta * unit.reloadMultiplier / cooldownTime, 0);
|
||||||
|
|
||||||
if(mount.sound != null){
|
if(mount.sound != null){
|
||||||
mount.sound.update(bulletX, bulletY, false);
|
mount.sound.update(bulletX, bulletY, false);
|
||||||
@@ -270,26 +282,14 @@ public class Weapon implements Cloneable{
|
|||||||
mount.side = !mount.side;
|
mount.side = !mount.side;
|
||||||
}
|
}
|
||||||
|
|
||||||
//rotate if applicable
|
|
||||||
if(rotate && (mount.rotate || mount.shoot) && can){
|
|
||||||
float axisX = unit.x + Angles.trnsx(unit.rotation - 90, x, y),
|
|
||||||
axisY = unit.y + Angles.trnsy(unit.rotation - 90, x, y);
|
|
||||||
|
|
||||||
mount.targetRotation = Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - unit.rotation;
|
|
||||||
mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, rotateSpeed * Time.delta);
|
|
||||||
}else if(!rotate){
|
|
||||||
mount.rotation = 0;
|
|
||||||
mount.targetRotation = unit.angleTo(mount.aimX, mount.aimY);
|
|
||||||
}
|
|
||||||
|
|
||||||
//shoot if applicable
|
//shoot if applicable
|
||||||
if(mount.shoot && //must be shooting
|
if(mount.shoot && //must be shooting
|
||||||
can && //must be able to shoot
|
can && //must be able to shoot
|
||||||
(!useAmmo || unit.ammo > 0 || !state.rules.unitAmmo || unit.team.rules().infiniteAmmo) && //check ammo
|
(!useAmmo || unit.ammo > 0 || !state.rules.unitAmmo || unit.team.rules().infiniteAmmo) && //check ammo
|
||||||
(!alternate || mount.side == flipSprite) &&
|
(!alternate || mount.side == flipSprite) &&
|
||||||
unit.vel.len() >= mount.weapon.minShootVelocity && //check velocity requirements
|
unit.vel.len() >= minShootVelocity && //check velocity requirements
|
||||||
mount.reload <= 0.0001f && //reload has to be 0
|
mount.reload <= 0.0001f && //reload has to be 0
|
||||||
Angles.within(rotate ? mount.rotation : unit.rotation, mount.targetRotation, mount.weapon.shootCone) //has to be within the cone
|
Angles.within(rotate ? mount.rotation : unit.rotation, mount.targetRotation, shootCone) //has to be within the cone
|
||||||
){
|
){
|
||||||
shoot(unit, mount, bulletX, bulletY, mount.aimX, mount.aimY, mountX, mountY, shootAngle, Mathf.sign(x));
|
shoot(unit, mount, bulletX, bulletY, mount.aimX, mount.aimY, mountX, mountY, shootAngle, Mathf.sign(x));
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import arc.util.*;
|
|||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.content.TechTree.*;
|
import mindustry.content.TechTree.*;
|
||||||
import mindustry.core.GameState.*;
|
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
@@ -32,7 +31,7 @@ import java.util.zip.*;
|
|||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class SettingsMenuDialog extends Dialog{
|
public class SettingsMenuDialog extends BaseDialog{
|
||||||
public SettingsTable graphics;
|
public SettingsTable graphics;
|
||||||
public SettingsTable game;
|
public SettingsTable game;
|
||||||
public SettingsTable sound;
|
public SettingsTable sound;
|
||||||
@@ -48,39 +47,20 @@ public class SettingsMenuDialog extends Dialog{
|
|||||||
addCloseButton();
|
addCloseButton();
|
||||||
|
|
||||||
cont.add(main = new SettingsTable());
|
cont.add(main = new SettingsTable());
|
||||||
|
shouldPause = true;
|
||||||
hidden(() -> {
|
|
||||||
Sounds.back.play();
|
|
||||||
if(state.isGame()){
|
|
||||||
if(!wasPaused || net.active())
|
|
||||||
state.set(State.playing);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
shown(() -> {
|
shown(() -> {
|
||||||
back();
|
back();
|
||||||
if(state.isGame()){
|
|
||||||
wasPaused = state.is(State.paused);
|
|
||||||
state.set(State.paused);
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuildMenu();
|
rebuildMenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(ResizeEvent.class, event -> {
|
onResize(() -> {
|
||||||
if(isShown() && Core.scene.getDialog() == this){
|
graphics.rebuild();
|
||||||
graphics.rebuild();
|
sound.rebuild();
|
||||||
sound.rebuild();
|
game.rebuild();
|
||||||
game.rebuild();
|
updateScrollFocus();
|
||||||
updateScrollFocus();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setFillParent(true);
|
|
||||||
title.setAlignment(Align.center);
|
|
||||||
titleTable.row();
|
|
||||||
titleTable.add(new Image()).growX().height(3f).pad(4f).get().setColor(Pal.accent);
|
|
||||||
|
|
||||||
cont.clearChildren();
|
cont.clearChildren();
|
||||||
cont.remove();
|
cont.remove();
|
||||||
buttons.remove();
|
buttons.remove();
|
||||||
|
|||||||
Reference in New Issue
Block a user