From 41d44a50899d3ba45bfbd22f4d623575afe303d8 Mon Sep 17 00:00:00 2001 From: lbmaian Date: Mon, 11 Dec 2023 00:35:50 -0800 Subject: [PATCH] Move omnivehicle turret tonnage check to pre-save tonnage validation Also improve validation error behavior a bit --- saw/src/main/java/saw/gui/frmVee.java | 49 +++++++++++++------ saw/src/main/java/saw/gui/frmVeeWide.java | 49 +++++++++++++------ .../src/main/java/components/CVLoadout.java | 24 ++------- 3 files changed, 72 insertions(+), 50 deletions(-) diff --git a/saw/src/main/java/saw/gui/frmVee.java b/saw/src/main/java/saw/gui/frmVee.java index c27ea7fc..b5050559 100644 --- a/saw/src/main/java/saw/gui/frmVee.java +++ b/saw/src/main/java/saw/gui/frmVee.java @@ -5959,24 +5959,43 @@ private boolean VerifyVehicle( ActionEvent evt ) { } // ensure we're not overweight + ArrayList loadouts = new ArrayList<>(); if( CurVee.IsOmni() ) { - ArrayList v = CurVee.GetLoadouts(); - for( int i = 0; i < v.size(); i++ ) { - CurVee.SetCurLoadout( ((ifCVLoadout) v.get( i )).GetName() ); - if( CurVee.GetCurrentTons() > CurVee.GetTonnage() ) { - Media.Messager( this, ((ifCVLoadout) v.get( i )).GetName() + - " loadout is overweight. Reduce the weight\nto equal or below the Vehicle's tonnage." ); - //cmbOmniVariant.setSelectedItem( ((ifCVLoadout) v.get( i )).GetName() ); - //cmbOmniVariantActionPerformed( evt ); - tbpMainTabPane.setSelectedComponent( pnlBasicSetup ); - SetSource = true; - return false; - } - } + loadouts.addAll( CurVee.GetLoadouts() ); } else { + loadouts.add( null ); + } + for( ifCVLoadout loadout : loadouts ) { + String name; + JPanel panel; + if( loadout == null ) { + name = "This Vehicle"; + panel = pnlBasicSetup; + } else { + name = loadout.GetName() + " loadout"; + CurVee.SetCurLoadout( loadout.GetName() ); + panel = pnlEquipment; + } if( CurVee.GetCurrentTons() > CurVee.GetTonnage() ) { - Media.Messager( this, "This Vehicle is overweight. Reduce the weight to\nequal or below the Vehicle's tonnage." ); - tbpMainTabPane.setSelectedComponent( pnlBasicSetup ); + Media.Messager( this, name + " is overweight.\n" + + "Reduce the weight to equal or below the Vehicle's tonnage." ); + tbpMainTabPane.setSelectedComponent( panel ); + SetSource = true; + return false; + } + Turret turret = CurVee.GetLoadout().GetTurret(); + if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) { + Media.Messager( this, name + "'s turret is overweight.\n" + + "Reduce the turret's weight to equal or below its max tonnage." ); + tbpMainTabPane.setSelectedComponent( panel ); + SetSource = true; + return false; + } + turret = CurVee.GetLoadout().GetRearTurret(); + if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) { + Media.Messager( this, name + "'s rear turret is overweight.\n" + + "Reduce the rear turret's weight to equal or below its max tonnage." ); + tbpMainTabPane.setSelectedComponent( panel ); SetSource = true; return false; } diff --git a/saw/src/main/java/saw/gui/frmVeeWide.java b/saw/src/main/java/saw/gui/frmVeeWide.java index db52ebb0..e01129db 100644 --- a/saw/src/main/java/saw/gui/frmVeeWide.java +++ b/saw/src/main/java/saw/gui/frmVeeWide.java @@ -3687,24 +3687,43 @@ private boolean VerifyVehicle( ActionEvent evt ) { //} // ensure we're not overweight + ArrayList loadouts = new ArrayList<>(); if( CurVee.IsOmni() ) { - ArrayList v = CurVee.GetLoadouts(); - for (Object o : v) { - CurVee.SetCurLoadout(((ifCVLoadout) o).GetName()); - if (CurVee.GetCurrentTons() > CurVee.GetTonnage()) { - Media.Messager(this, ((ifCVLoadout) o).GetName() + - " loadout is overweight. Reduce the weight\nto equal or below the Vehicle's tonnage."); - //cmbOmniVariant.setSelectedItem( ((ifCVLoadout) v.get( i )).GetName() ); - //cmbOmniVariantActionPerformed( evt ); - tbpMainTabPane.setSelectedComponent(pnlBasicSetup); - SetSource = true; - return false; - } - } + loadouts.addAll( CurVee.GetLoadouts() ); } else { + loadouts.add( null ); + } + for( ifCVLoadout loadout : loadouts ) { + String name; + JPanel panel; + if( loadout == null ) { + name = "This Vehicle"; + panel = pnlBasicSetup; + } else { + name = loadout.GetName() + " loadout"; + CurVee.SetCurLoadout( loadout.GetName() ); + panel = pnlEquipment; + } if( CurVee.GetCurrentTons() > CurVee.GetTonnage() ) { - Media.Messager( this, "This Vehicle is overweight. Reduce the weight to\nequal or below the Vehicle's tonnage." ); - tbpMainTabPane.setSelectedComponent( pnlBasicSetup ); + Media.Messager( this, name + " is overweight.\n" + + "Reduce the weight to equal or below the Vehicle's tonnage." ); + tbpMainTabPane.setSelectedComponent( panel ); + SetSource = true; + return false; + } + Turret turret = CurVee.GetLoadout().GetTurret(); + if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) { + Media.Messager( this, name + "'s turret is overweight.\n" + + "Reduce the turret's weight to equal or below its max tonnage." ); + tbpMainTabPane.setSelectedComponent( panel ); + SetSource = true; + return false; + } + turret = CurVee.GetLoadout().GetRearTurret(); + if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) { + Media.Messager( this, name + "'s rear turret is overweight.\n" + + "Reduce the rear turret's weight to equal or below its max tonnage." ); + tbpMainTabPane.setSelectedComponent( panel ); SetSource = true; return false; } diff --git a/sswlib/src/main/java/components/CVLoadout.java b/sswlib/src/main/java/components/CVLoadout.java index 08243904..4e4429be 100644 --- a/sswlib/src/main/java/components/CVLoadout.java +++ b/sswlib/src/main/java/components/CVLoadout.java @@ -364,32 +364,16 @@ public void AddTo(abPlaceable p, int Loc) throws Exception { throw new Exception(p.ActualName() + " cannot be allocated to the Side."); break; case LocationIndex.CV_LOC_TURRET1: - if ( p.CanAllocCVTurret() ) { + if ( p.CanAllocCVTurret() ) Turret1Items.add(p); - if ( Turret1.isTonnageSet() ) { - double tons = Turret1.GetTonnageFromItems(); - if ( tons > Turret1.GetMaxTonnage() ) { - Turret1Items.remove(p); - throw new Exception( String.format( "Turret is out of space: %.1f/%.1f", - tons, Turret1.GetMaxTonnage()) ); - } - } - } else + else throw new Exception(p.ActualName() + " cannot be allocated to the Turret."); break; case LocationIndex.CV_LOC_TURRET2: - if ( p.CanAllocCVTurret() ) { + if ( p.CanAllocCVTurret() ) Turret2Items.add(p); - if ( Turret2.isTonnageSet() ) { - double tons = Turret2.GetTonnageFromItems(); - if ( tons > Turret2.GetMaxTonnage() ) { - Turret2Items.remove(p); - throw new Exception( String.format( "Turret is out of space: %.1f/%.1f", - tons, Turret2.GetMaxTonnage()) ); - } - } - } else + else throw new Exception(p.ActualName() + " cannot be allocated to the Rear Turret."); break; case LocationIndex.CV_LOC_SPONSON_LEFT: