From ad2e4261fbb6a1a3ffcb76ddac01869e9e6c2afd Mon Sep 17 00:00:00 2001 From: HoneySkull Date: Wed, 17 Apr 2024 21:37:20 -0500 Subject: [PATCH] Mek Quad turret firing arc reflects turret rotation changes. --- .../client/ui/swing/TurretFacingDialog.java | 22 +++++++++++++++++++ .../ui/swing/unitDisplay/WeaponPanel.java | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/megamek/src/megamek/client/ui/swing/TurretFacingDialog.java b/megamek/src/megamek/client/ui/swing/TurretFacingDialog.java index 1731b7ed6f7..ae2f607ad69 100644 --- a/megamek/src/megamek/client/ui/swing/TurretFacingDialog.java +++ b/megamek/src/megamek/client/ui/swing/TurretFacingDialog.java @@ -226,12 +226,34 @@ public void actionPerformed(ActionEvent ae) { } else { locToChange = turret.getLocation(); } + + Mounted firstMountedWeapon = null; // Take note of the first weapon mounted on this turret. + Mounted currentSelectedWeapon = null; // Take note of current selected weapon. + if (clientgui.getUnitDisplay() != null) { + currentSelectedWeapon = clientgui.getUnitDisplay().wPan.getSelectedWeapon(); + } + for (Mounted weapon : mech.getWeaponList()) { if ((weapon.getLocation() == locToChange) && weapon.isMechTurretMounted()) { weapon.setFacing(facing); clientgui.getClient().sendMountFacingChange(mech.getId(), mech.getEquipmentNum(weapon), facing); + + // Tag the first mounted weapon as a backup option to refresh after the turret rotation. + if (firstMountedWeapon == null) { + firstMountedWeapon = weapon; + } + + // If the currently selected weapon is in the turret, refresh it by default. + if (mech.getEquipmentNum(currentSelectedWeapon) == mech.getEquipmentNum(weapon)) { + firstMountedWeapon = currentSelectedWeapon; + } } } + + // Select the mounted weapon in the unit display to refresh the firing arch. + if (clientgui.getUnitDisplay() != null) { + clientgui.getUnitDisplay().wPan.selectWeapon(mech.getEquipmentNum(firstMountedWeapon)); + } } else if (tank != null) { tank.setDualTurretOffset(((6 - tank.getFacing()) + facing) % 6); clientgui.getClient().sendUpdateEntity(tank); diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java index a259db44982..de82aa1dd92 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java @@ -2191,6 +2191,10 @@ private void setFieldOfFire(Mounted mounted) { if (entity.isSecondaryArcWeapon(entity.getEquipmentNum(mounted))) { facing = entity.getSecondaryFacing(); } + // If this is mech with turrets, check to see if the weapon is on a turret. + if ((entity instanceof Mech) && (entity.getEquipment(weaponId).isMechTurretMounted())) { + facing = mounted.getFacing(); + } // If this is a tank with dual turrets, check to see if the weapon is a second turret. if ((entity instanceof Tank) && (entity.getEquipment(weaponId).getLocation() == ((Tank) entity).getLocTurret2())) {