From 7f415588f4f413922ed7997e37948b3104dbe77a Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 28 Sep 2021 14:41:35 -0400 Subject: [PATCH] Cleaned up duplicate SettingsMenuDialog code --- core/src/mindustry/type/Weapon.java | 30 ++++++++-------- .../ui/dialogs/SettingsMenuDialog.java | 34 ++++--------------- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java index f72e60f3a3..c96482d15d 100644 --- a/core/src/mindustry/type/Weapon.java +++ b/core/src/mindustry/type/Weapon.java @@ -200,6 +200,18 @@ public class Weapon implements Cloneable{ boolean can = unit.canShoot(); 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 weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : 0), mountX = unit.x + Angles.trnsx(unit.rotation - 90, x, y), @@ -256,7 +268,7 @@ public class Weapon implements Cloneable{ } }else{ //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){ mount.sound.update(bulletX, bulletY, false); @@ -270,26 +282,14 @@ public class Weapon implements Cloneable{ 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 if(mount.shoot && //must be shooting can && //must be able to shoot (!useAmmo || unit.ammo > 0 || !state.rules.unitAmmo || unit.team.rules().infiniteAmmo) && //check ammo (!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 - 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)); diff --git a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java index d8d0b40826..ea864a0064 100644 --- a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -17,7 +17,6 @@ import arc.util.*; import arc.util.io.*; import mindustry.content.*; import mindustry.content.TechTree.*; -import mindustry.core.GameState.*; import mindustry.core.*; import mindustry.ctype.*; import mindustry.game.EventType.*; @@ -32,7 +31,7 @@ import java.util.zip.*; import static arc.Core.*; import static mindustry.Vars.*; -public class SettingsMenuDialog extends Dialog{ +public class SettingsMenuDialog extends BaseDialog{ public SettingsTable graphics; public SettingsTable game; public SettingsTable sound; @@ -48,39 +47,20 @@ public class SettingsMenuDialog extends Dialog{ addCloseButton(); cont.add(main = new SettingsTable()); - - hidden(() -> { - Sounds.back.play(); - if(state.isGame()){ - if(!wasPaused || net.active()) - state.set(State.playing); - } - }); + shouldPause = true; shown(() -> { back(); - if(state.isGame()){ - wasPaused = state.is(State.paused); - state.set(State.paused); - } - rebuildMenu(); }); - Events.on(ResizeEvent.class, event -> { - if(isShown() && Core.scene.getDialog() == this){ - graphics.rebuild(); - sound.rebuild(); - game.rebuild(); - updateScrollFocus(); - } + onResize(() -> { + graphics.rebuild(); + sound.rebuild(); + game.rebuild(); + 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.remove(); buttons.remove();