From 65d556918ff2bef64038473f5e43cd073760c584 Mon Sep 17 00:00:00 2001 From: Weaver Date: Sat, 26 Oct 2024 22:39:56 -0700 Subject: [PATCH 1/6] RSWD - Non-functional Testing --- .../dialog/ResolveScenarioWizardDialog.java | 790 ++++++++++-------- 1 file changed, 431 insertions(+), 359 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index 6df2520bd3..872c452f43 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -19,7 +19,78 @@ * You should have received a copy of the GNU General Public License * along with MekHQ. If not, see . */ -package mekhq.gui.dialog; +// switch (currentPanel) { +// case UNITSPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.missingunits")); +// break; +// case PILOTPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.personnel")); +// break; +// case SALVAGEPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.salvage")); +// break; +// case KILLPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.kills")); +// break; +// case PRISONERPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.prisoners")); +// break; +// case PREVIEWPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.preview")); +// break; +// case REWARDPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.reward")); +// break; +// case OBJECTIVEPANEL: +// txtInstructions.setText(resourceMap.getString("txtInstructions.text.objectives")); +// break; +// default: +// txtInstructions.setText(""); +// break; +// } + + package mekhq.gui.dialog; + +import static mekhq.campaign.personnel.randomEvents.PersonalityController.writeDescription; + +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; +import java.util.UUID; + +import javax.swing.BorderFactory; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSlider; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; import megamek.client.ui.Messages; import megamek.client.ui.dialogs.EntityReadoutDialog; @@ -52,14 +123,6 @@ import mekhq.gui.utilities.MarkdownEditorPanel; import mekhq.gui.view.PersonViewPanel; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import java.util.List; -import java.util.*; - -import static mekhq.campaign.personnel.randomEvents.PersonalityController.writeDescription; - /** * @author Taharqa */ @@ -88,13 +151,10 @@ public class ResolveScenarioWizardDialog extends JDialog { private JButton btnNext; private JButton btnFinish; private JButton btnBack; - private JTextArea txtInstructions; - private CardLayout cardLayout; private String currentPanel; + private JTabbedPane tabMain; - private JScrollPane scrMain; - private JPanel pnlMain; private JPanel pnlUnitStatus; private JPanel pnlObjectiveStatus; private JPanel pnlPilotStatus; @@ -212,14 +272,7 @@ public ResolveScenarioWizardDialog(JFrame parent, boolean modal, ResolveScenario * B, C, F, N, ESCAPE */ private void initComponents() { - // Initialize Local Variables GridBagConstraints gridBagConstraints; - int gridy; - int gridx; - int i = 2; - int j = 0; - - cardLayout = new CardLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); @@ -230,36 +283,128 @@ private void initComponents() { setName("Form"); - getContentPane().setLayout(new BorderLayout()); + getContentPane().setLayout(new GridBagLayout()); setTitle(resourceMap.getString("title")); - /* - * Instructions at the top - */ - txtInstructions = new JTextArea(); - txtInstructions.setText(""); - txtInstructions.setEditable(false); - txtInstructions.setLineWrap(true); - txtInstructions.setWrapStyleWord(true); - txtInstructions.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder(resourceMap.getString("txtInstructions.title")), - BorderFactory.createEmptyBorder(5,5,5,5))); - getContentPane().add(txtInstructions, BorderLayout.PAGE_START); + tabMain = new JTabbedPane(); + + //region Make Panels + pnlUnitStatus = makeUnitStatusPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlUnitStatus), UNITSPANEL); + + + pnlPilotStatus = makePilotStatusPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlPilotStatus), PILOTPANEL); + + + pnlSalvage = makeSalvagePanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlSalvage), SALVAGEPANEL); + + + pnlPrisonerStatus = makePrisonerStatusPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlPrisonerStatus), PRISONERPANEL); + + + pnlKills = makeKillsPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlKills), KILLPANEL); + + + pnlRewards = makeRewardsPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlRewards), REWARDPANEL); + + + pnlObjectiveStatus = makeObjectiveStatusPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlObjectiveStatus), OBJECTIVEPANEL); + + + pnlPreview = makePreviewPanel(); + tabMain.add(new JScrollPaneWithSpeed(pnlPreview), PREVIEWPANEL); + + + //scrMain = new JScrollPaneWithSpeed(pnlMain); + //scrMain.setMinimumSize(UIUtil.scaleForGUI(600, 500)); + //scrMain.setPreferredSize(UIUtil.scaleForGUI(900, 500)); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx=0; + gridBagConstraints.gridy=0; + gridBagConstraints.weighty=1.0; + gridBagConstraints.anchor=GridBagConstraints.NORTHWEST; + getContentPane().add(tabMain, gridBagConstraints); + + + // region Button Panel + JPanel panButtons = new JPanel(); + panButtons.setName("panButtons"); + panButtons.setLayout(new GridBagLayout()); + + JButton btnCancel = new JButton(resourceMap.getString("btnCancel.text")); + btnCancel.setName("btnClose"); + btnCancel.setMnemonic(KeyEvent.VK_C); + btnCancel.addActionListener(evt -> cancel()); + + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = 1; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.anchor = GridBagConstraints.EAST; + gridBagConstraints.insets = new Insets(5, 5, 0, 0); + panButtons.add(btnCancel, gridBagConstraints); - /* - * Set up main panel with cards - */ - pnlMain = new JPanel(cardLayout); + btnBack = new JButton(resourceMap.getString("btnBack.text")); + btnBack.setName("btnBack"); + btnBack.setMnemonic(KeyEvent.VK_B); + btnBack.addActionListener(evt -> back()); + gridBagConstraints.gridx = 1; + gridBagConstraints.weightx = 0.0; + panButtons.add(btnBack, gridBagConstraints); + + btnNext = new JButton(resourceMap.getString("btnNext.text")); + btnNext.setName("btnNext"); + btnNext.setMnemonic(KeyEvent.VK_N); + btnNext.addActionListener(evt -> next()); + gridBagConstraints.gridx = 2; + panButtons.add(btnNext, gridBagConstraints); + + btnFinish = new JButton(resourceMap.getString("btnFinish.text")); + btnFinish.setName("btnFinish"); + btnFinish.setMnemonic(KeyEvent.VK_F); + btnFinish.addActionListener(evt -> finish()); + gridBagConstraints.gridx = 3; + panButtons.add(btnFinish, gridBagConstraints); + + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx=0; + gridBagConstraints.gridy=1; + + getContentPane().add(panButtons, gridBagConstraints); + + switchPanel(currentPanel); + if (!usePanel(currentPanel)) { + next(); + } + + tabMain.setEnabled(false); + btnNext.setEnabled(true); + btnBack.setEnabled(false); + btnFinish.setEnabled(false); + + pack(); + } - //region Unit Status Panel - pnlUnitStatus = new JPanel(); + + private JPanel makeUnitStatusPanel() { + GridBagConstraints gridBagConstraints; + int replaceme_i = 2; + int replaceme_j = 0; + + JPanel pnlUnitStatus = new JPanel(); pnlUnitStatus.setLayout(new GridBagLayout()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; - gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.insets = new Insets(5, 5, 0, 0); pnlUnitStatus.add(new JLabel(resourceMap.getString("totaled")), gridBagConstraints); @@ -284,7 +429,7 @@ private void initComponents() { chkTotaled.setName("chkTotaled"); chkTotaled.getAccessibleContext().setAccessibleName(resourceMap.getString("totaled")); chkTotaled.setSelected(status.isTotalLoss()); - chkTotaled.setName(Integer.toString(j)); + chkTotaled.setName(Integer.toString(replaceme_j)); chkTotaled.setActionCommand(unit.getId().toString()); chkTotaled.addItemListener(new CheckTotalListener()); chksTotaled.add(chkTotaled); @@ -296,18 +441,17 @@ private void initComponents() { btnEditUnit = new JButton("Edit Unit"); btnEditUnit.setEnabled(!status.isTotalLoss()); btnEditUnit.setActionCommand(unit.getId().toString()); - btnEditUnit.setName(Integer.toString(j)); + btnEditUnit.setName(Integer.toString(replaceme_j)); btnEditUnit.addActionListener(new EditUnitListener()); btnsEditUnit.add(btnEditUnit); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = i; - gridBagConstraints.gridwidth = 1; + gridBagConstraints.gridy = replaceme_i; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (++j == tracker.getUnits().size()) { + if (++replaceme_j == tracker.getUnits().size()) { gridBagConstraints.weighty = 1.0; } pnlUnitStatus.add(nameLbl, gridBagConstraints); @@ -318,21 +462,17 @@ private void initComponents() { gridBagConstraints.gridx = 3; gridBagConstraints.weightx = 1.0; pnlUnitStatus.add(btnEditUnit, gridBagConstraints); - i++; + replaceme_i++; } - pnlMain.add(pnlUnitStatus, UNITSPANEL); - //endregion Unit Status Panel + return pnlUnitStatus; + } - //region Objective Status Panel - generateObjectiveStatusPanel(); - pnlMain.add(pnlObjectiveStatus, OBJECTIVEPANEL); - //endregion Objective Status Panel - //region Pilot Status Panel - pnlPilotStatus = new JPanel(); + private JPanel makePilotStatusPanel() { + JPanel pnlPilotStatus = new JPanel(); pnlPilotStatus.setLayout(new GridBagLayout()); - gridBagConstraints = new GridBagConstraints(); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 1; @@ -347,8 +487,8 @@ private void initComponents() { gridBagConstraints.gridx = 3; pnlPilotStatus.add(new JLabel(resourceMap.getString("kia")), gridBagConstraints); - j = 0; - gridy = 2; + int replaceme_j = 0; + int replaceme_gridy = 2; Hashtable labelTable = new Hashtable<>(); labelTable.put(0, new JLabel("0") ); @@ -361,31 +501,31 @@ private void initComponents() { for (PersonStatus status : tracker.getSortedPeople()) { pstatuses.add(status); - gridx = 0; + int replaceme_gridx = 0; gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.gridy = gridy++; + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridy = replaceme_gridy++; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (++j == tracker.getPeopleStatus().keySet().size()) { + if (++replaceme_j == tracker.getPeopleStatus().keySet().size()) { gridBagConstraints.weighty = 1.0; } - nameLbl = new JLabel("" + status.getName() + "
" + status.getUnitName() + ""); + JLabel nameLbl = new JLabel("" + status.getName() + "
" + status.getUnitName() + ""); pnlPilotStatus.add(nameLbl, gridBagConstraints); JSlider hitSlider = new JSlider(JSlider.HORIZONTAL, 0, 5, Math.min(status.getHits(), 5)); - hitSlider.setName(Integer.toString(j - 1)); + hitSlider.setName(Integer.toString(replaceme_j - 1)); hitSlider.setMajorTickSpacing(1); hitSlider.setPaintTicks(true); hitSlider.setLabelTable(labelTable); hitSlider.setPaintLabels(true); hitSlider.setSnapToTicks(true); hitSliders.add(hitSlider); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlPilotStatus.add(hitSlider, gridBagConstraints); JCheckBox miaCheck = new JCheckBox(""); @@ -393,7 +533,7 @@ private void initComponents() { miaCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("mia")); miaCheck.setSelected(status.isMissing()); miaBtns.add(miaCheck); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlPilotStatus.add(miaCheck, gridBagConstraints); JCheckBox kiaCheck = new JCheckBox(""); @@ -402,153 +542,29 @@ private void initComponents() { kiaCheck.addItemListener(new CheckBoxKIAListener(hitSlider, miaCheck)); kiaCheck.setSelected(status.isDead()); kiaBtns.add(kiaCheck); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlPilotStatus.add(kiaCheck, gridBagConstraints); JButton btnViewPilot = new JButton("View Personnel"); btnViewPilot.addActionListener(evt -> showPerson(status, false)); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; gridBagConstraints.weightx = 1.0; pnlPilotStatus.add(btnViewPilot, gridBagConstraints); } - pnlMain.add(pnlPilotStatus, PILOTPANEL); - //endregion Pilot Status Panel - - //region Prisoner Status Panel - pnlPrisonerStatus = new JPanel(); - pnlPrisonerStatus.setLayout(new GridBagLayout()); - - gridx = 1; - - prisonerRansomAllButton = new JButton(resourceMap.getString("prisonerRansomAllButton.text")); - - gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx=2; - gridBagConstraints.gridy=0; - gridBagConstraints.gridwidth=3; - gridBagConstraints.anchor = GridBagConstraints.CENTER; - gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPrisonerStatus.add(prisonerRansomAllButton, gridBagConstraints); - - prisonerRansomAllButton.addActionListener(evt -> prisonerRansomAll()); - - - gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.gridy = 1; - gridBagConstraints.gridwidth = 1; - gridBagConstraints.anchor = GridBagConstraints.CENTER; - gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPrisonerStatus.add(new JLabel(resourceMap.getString("hits")), gridBagConstraints); - - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(new JLabel(resourceMap.getString("prisoner")), gridBagConstraints); - - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(new JLabel(resourceMap.getString("prisonerRansomed.text")), gridBagConstraints); - - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(new JLabel(resourceMap.getString("kia")), gridBagConstraints); - - j = 0; - gridy = 2; - - for (OppositionPersonnelStatus status : tracker.getSortedPrisoners()) { - prstatuses.add(status); - - gridx = 0; - - gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.gridy = gridy++; - gridBagConstraints.gridwidth = 1; - gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new Insets(5, 5, 0, 0); - gridBagConstraints.weightx = 0.0; - if (++j == tracker.getOppositionPersonnel().keySet().size()) { - gridBagConstraints.weighty = 1.0; - } - - nameLbl = new JLabel("" + status.getName() + "
" + status.getUnitName() + ""); - pnlPrisonerStatus.add(nameLbl, gridBagConstraints); - - JSlider hitSlider = new JSlider(JSlider.HORIZONTAL, 0, 5, Math.min(status.getHits(), 5)); - hitSlider.setName(Integer.toString(j - 1)); - hitSlider.setMajorTickSpacing(1); - hitSlider.setPaintTicks(true); - hitSlider.setLabelTable(labelTable); - hitSlider.setPaintLabels(true); - hitSlider.setSnapToTicks(true); - pr_hitSliders.add(hitSlider); - gridBagConstraints.anchor = GridBagConstraints.NORTH; - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(hitSlider, gridBagConstraints); - - JCheckBox prisonerCapturedCheck = new JCheckBox(""); - prisonerCapturedCheck.setName("prisonerCapturedCheck"); - prisonerCapturedCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("prisoner")); - prisonerCapturedCheck.setSelected(status.isCaptured()); - prisonerCapturedCheck.addItemListener(evt -> checkPrisonerStatus()); - prisonerCapturedBtns.add(prisonerCapturedCheck); - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(prisonerCapturedCheck, gridBagConstraints); - - JCheckBox prisonerRansomedCheck = new JCheckBox(""); - prisonerRansomedCheck.setName("prisonerRansomedCheck"); - prisonerRansomedCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("prisonerRansomed.text")); - prisonerRansomedCheck.setEnabled(!status.isCaptured()); - prisonerRansomedCheck.addItemListener(evt -> checkPrisonerStatus()); - prisonerRansomedBtns.add(prisonerRansomedCheck); - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(prisonerRansomedCheck, gridBagConstraints); - - JCheckBox kiaCheck = new JCheckBox(""); - kiaCheck.setName("kiaCheck"); - kiaCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("kia")); - kiaCheck.addItemListener(evt -> checkPrisonerStatus()); - prisonerKiaBtns.add(kiaCheck); - gridBagConstraints.gridx = gridx++; - pnlPrisonerStatus.add(kiaCheck, gridBagConstraints); - JButton btnViewPrisoner = new JButton("View Personnel"); - btnViewPrisoner.addActionListener(evt -> showPerson(status, true)); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.weightx = 1.0; - pnlPrisonerStatus.add(btnViewPrisoner, gridBagConstraints); + return pnlPilotStatus; + } - // if the person is dead, set the checkbox and skip all this captured stuff - if ((status.getHits() > 5) || status.isDead()) { - kiaCheck.setSelected(true); - } else if (status.isCaptured() - && tracker.getCampaign().getCampaignOptions().getPrisonerCaptureStyle().isAtB()) { - boolean wasCaptured; - if (status.wasPickedUp()) { - wasCaptured = true; - } else { - wasCaptured = rollForCapture(tracker.getCampaign(), status); - } - prisonerCapturedCheck.setSelected(wasCaptured); - } - // When generating NPC personnel, we use placeholder characters and then later re-assign - // their details to match expected values. - // This causes a disconnect between their name, at point of creation, and the name - // presented to the user. - // We therefore need to re-generate the personality description at this point, - // as this is the earliest point in which that description is visible to the user - writeDescription(status.getPerson()); - } - pnlMain.add(pnlPrisonerStatus, PRISONERPANEL); - //endregion Prisoner Status Panel - - //region Salvage Panel + private JPanel makeSalvagePanel() { // Create the panel - pnlSalvage = new JPanel(); + JPanel pnlSalvage = new JPanel(); pnlSalvage.setLayout(new GridBagLayout()); JPanel pnlSalvageValue = new JPanel(new GridBagLayout()); - gridx = 0; - gridy = 0; + int replaceme_gridx = 0; + int replaceme_gridy = 0; + GridBagConstraints gridBagConstraints; if ((tracker.getMission() instanceof Contract) && !tracker.usesSalvageExchange()) { gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridwidth = 1; @@ -556,36 +572,36 @@ private void initComponents() { gridBagConstraints.insets = new Insets(5, 5, 0, 0); JLabel lblSalvageValueUnit1 = new JLabel(resourceMap.getString("lblSalvageValueUnit1.text")); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.gridy = gridy++; + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridy = replaceme_gridy++; gridBagConstraints.weightx = 0.0; pnlSalvageValue.add(lblSalvageValueUnit1, gridBagConstraints); lblSalvageValueUnit2 = new JLabel(salvageUnit.toAmountAndSymbolString()); - gridBagConstraints.gridx = gridx--; + gridBagConstraints.gridx = replaceme_gridx--; gridBagConstraints.weightx = 1.0; pnlSalvageValue.add(lblSalvageValueUnit2, gridBagConstraints); JLabel lblSalvageValueEmployer1 = new JLabel(resourceMap.getString("lblSalvageValueEmployer1.text")); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.gridy = gridy++; + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridy = replaceme_gridy++; gridBagConstraints.weightx = 0.0; pnlSalvageValue.add(lblSalvageValueEmployer1, gridBagConstraints); lblSalvageValueEmployer2 = new JLabel(salvageEmployer.toAmountAndSymbolString()); - gridBagConstraints.gridx = gridx--; + gridBagConstraints.gridx = replaceme_gridx--; gridBagConstraints.weightx = 1.0; pnlSalvageValue.add(lblSalvageValueEmployer2, gridBagConstraints); JLabel lblSalvagePct1 = new JLabel(resourceMap.getString("lblSalvagePct1.text")); - gridBagConstraints.gridx = gridx++; - gridBagConstraints.gridy = gridy++; + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridy = replaceme_gridy++; gridBagConstraints.weightx = 0.0; pnlSalvageValue.add(lblSalvagePct1, gridBagConstraints); String lead = "" + ((currentSalvagePct > maxSalvagePct) ? "" : ""); lblSalvagePct2 = new JLabel(lead + currentSalvagePct + "% (max " + maxSalvagePct + "%)"); - gridBagConstraints.gridx = gridx--; + gridBagConstraints.gridx = replaceme_gridx--; gridBagConstraints.weightx = 1.0; pnlSalvageValue.add(lblSalvagePct2, gridBagConstraints); @@ -601,23 +617,23 @@ private void initComponents() { } // Update any indexing variables - j = 0; - gridx = 1; + int replaceme_j = 0; + replaceme_gridx = 1; // Create the Title Line gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridy = gridy++; + gridBagConstraints.gridy = replaceme_gridy++; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(new JLabel(resourceMap.getString("lblSalvage.text")), gridBagConstraints); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(new JLabel(resourceMap.getString("lblSell.text")), gridBagConstraints); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(new JLabel(resourceMap.getString("lblEscaped.text")), gridBagConstraints); // Initialize the tracking ArrayLists @@ -633,22 +649,22 @@ private void initComponents() { for (TestUnit u : tracker.getPotentialSalvage()) { // Initial variable work - gridx = 0; + replaceme_gridx = 0; salvageables.add(u); UnitStatus status = tracker.getSalvageStatus().get(u.getId()); // Initial update to the GridBagConstraints gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; - gridBagConstraints.gridy = gridy++; + gridBagConstraints.gridy = replaceme_gridy++; gridBagConstraints.weightx = 0.0; - if ((j + 1) == tracker.getPotentialSalvage().size()) { // we only want the weight change on the last one + if ((replaceme_j + 1) == tracker.getPotentialSalvage().size()) { // we only want the weight change on the last one gridBagConstraints.weighty = 1.0; } // Now, we start creating the boxes JLabel salvageUnit = new JLabel(status.getDesc(true)); salvageUnitLabel.add(salvageUnit); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(salvageUnit, gridBagConstraints); JCheckBox salvaged = new JCheckBox(""); @@ -659,7 +675,7 @@ private void initComponents() { salvaged.addItemListener(evt -> checkSalvageRights()); salvageBoxes.add(salvaged); gridBagConstraints.anchor = GridBagConstraints.NORTH; - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(salvaged, gridBagConstraints); JCheckBox sold = new JCheckBox(""); @@ -668,7 +684,7 @@ private void initComponents() { sold.setEnabled(!tracker.usesSalvageExchange() && tracker.getCampaign().getCampaignOptions().isSellUnits()); sold.addItemListener(evt -> checkSalvageRights()); soldUnitBoxes.add(sold); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(sold, gridBagConstraints); JCheckBox escaped = new JCheckBox(""); @@ -679,37 +695,173 @@ private void initComponents() { escaped.addItemListener(evt -> checkSalvageRights()); escaped.setActionCommand(u.getEntity().getExternalIdAsString()); escapeBoxes.add(escaped); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(escaped, gridBagConstraints); JButton btnSalvageViewUnit = new JButton("View Unit"); btnSalvageViewUnit.setActionCommand(u.getId().toString()); btnSalvageViewUnit.addActionListener(new ViewUnitListener(true)); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; pnlSalvage.add(btnSalvageViewUnit, gridBagConstraints); JButton btnSalvageEditUnit = new JButton("Edit Unit"); - btnSalvageEditUnit.setName(Integer.toString(j++)); + btnSalvageEditUnit.setName(Integer.toString(replaceme_j++)); btnSalvageEditUnit.setActionCommand(u.getId().toString()); btnSalvageEditUnit.addActionListener(new EditUnitListener(true)); btnsSalvageEditUnit.add(btnSalvageEditUnit); - gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridx = replaceme_gridx++; gridBagConstraints.weightx = 1.0; pnlSalvage.add(btnSalvageEditUnit, gridBagConstraints); } checkSalvageRights(); - pnlMain.add(pnlSalvage, SALVAGEPANEL); - //endregion Salvage Panel + return pnlSalvage; + } + + + + private JPanel makePrisonerStatusPanel() { + JPanel pnlPrisonerStatus = new JPanel(); + pnlPrisonerStatus.setLayout(new GridBagLayout()); + + int replaceme_gridx = 1; + + prisonerRansomAllButton = new JButton(resourceMap.getString("prisonerRansomAllButton.text")); + + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx=2; + gridBagConstraints.gridy=0; + gridBagConstraints.gridwidth=3; + gridBagConstraints.anchor = GridBagConstraints.CENTER; + gridBagConstraints.insets = new Insets(5, 5, 0, 0); + pnlPrisonerStatus.add(prisonerRansomAllButton, gridBagConstraints); + + prisonerRansomAllButton.addActionListener(evt -> prisonerRansomAll()); + + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = 1; + gridBagConstraints.anchor = GridBagConstraints.CENTER; + gridBagConstraints.insets = new Insets(5, 5, 0, 0); + pnlPrisonerStatus.add(new JLabel(resourceMap.getString("hits")), gridBagConstraints); + + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(new JLabel(resourceMap.getString("prisoner")), gridBagConstraints); + + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(new JLabel(resourceMap.getString("prisonerRansomed.text")), gridBagConstraints); + + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(new JLabel(resourceMap.getString("kia")), gridBagConstraints); + + int replaceme_j = 0; + int replaceme_gridy = 2; + + Hashtable labelTable = new Hashtable<>(); + labelTable.put(0, new JLabel("0") ); + labelTable.put(1, new JLabel("1") ); + labelTable.put(2, new JLabel("2") ); + labelTable.put(3, new JLabel("3") ); + labelTable.put(4, new JLabel("4") ); + labelTable.put(5, new JLabel("5") ); + + for (OppositionPersonnelStatus status : tracker.getSortedPrisoners()) { + prstatuses.add(status); - /* - * Assign Kills panel - */ - pnlKills = new JPanel(); + replaceme_gridx = 0; + + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridy = replaceme_gridy++; + gridBagConstraints.gridwidth = 1; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new Insets(5, 5, 0, 0); + gridBagConstraints.weightx = 0.0; + if (++replaceme_j == tracker.getOppositionPersonnel().keySet().size()) { + gridBagConstraints.weighty = 1.0; + } + + JLabel nameLbl = new JLabel("" + status.getName() + "
" + status.getUnitName() + ""); + pnlPrisonerStatus.add(nameLbl, gridBagConstraints); + + JSlider hitSlider = new JSlider(JSlider.HORIZONTAL, 0, 5, Math.min(status.getHits(), 5)); + hitSlider.setName(Integer.toString(replaceme_j - 1)); + hitSlider.setMajorTickSpacing(1); + hitSlider.setPaintTicks(true); + hitSlider.setLabelTable(labelTable); + hitSlider.setPaintLabels(true); + hitSlider.setSnapToTicks(true); + pr_hitSliders.add(hitSlider); + gridBagConstraints.anchor = GridBagConstraints.NORTH; + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(hitSlider, gridBagConstraints); + + JCheckBox prisonerCapturedCheck = new JCheckBox(""); + prisonerCapturedCheck.setName("prisonerCapturedCheck"); + prisonerCapturedCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("prisoner")); + prisonerCapturedCheck.setSelected(status.isCaptured()); + prisonerCapturedCheck.addItemListener(evt -> checkPrisonerStatus()); + prisonerCapturedBtns.add(prisonerCapturedCheck); + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(prisonerCapturedCheck, gridBagConstraints); + + JCheckBox prisonerRansomedCheck = new JCheckBox(""); + prisonerRansomedCheck.setName("prisonerRansomedCheck"); + prisonerRansomedCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("prisonerRansomed.text")); + prisonerRansomedCheck.setEnabled(!status.isCaptured()); + prisonerRansomedCheck.addItemListener(evt -> checkPrisonerStatus()); + prisonerRansomedBtns.add(prisonerRansomedCheck); + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(prisonerRansomedCheck, gridBagConstraints); + + JCheckBox kiaCheck = new JCheckBox(""); + kiaCheck.setName("kiaCheck"); + kiaCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("kia")); + kiaCheck.addItemListener(evt -> checkPrisonerStatus()); + prisonerKiaBtns.add(kiaCheck); + gridBagConstraints.gridx = replaceme_gridx++; + pnlPrisonerStatus.add(kiaCheck, gridBagConstraints); + + JButton btnViewPrisoner = new JButton("View Personnel"); + btnViewPrisoner.addActionListener(evt -> showPerson(status, true)); + gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.weightx = 1.0; + pnlPrisonerStatus.add(btnViewPrisoner, gridBagConstraints); + + // if the person is dead, set the checkbox and skip all this captured stuff + if ((status.getHits() > 5) || status.isDead()) { + kiaCheck.setSelected(true); + } else if (status.isCaptured() + && tracker.getCampaign().getCampaignOptions().getPrisonerCaptureStyle().isAtB()) { + boolean wasCaptured; + if (status.wasPickedUp()) { + wasCaptured = true; + } else { + wasCaptured = rollForCapture(tracker.getCampaign(), status); + } + prisonerCapturedCheck.setSelected(wasCaptured); + } + + // When generating NPC personnel, we use placeholder characters and then later re-assign + // their details to match expected values. + // This causes a disconnect between their name, at point of creation, and the name + // presented to the user. + // We therefore need to re-generate the personality description at this point, + // as this is the earliest point in which that description is visible to the user + writeDescription(status.getPerson()); + } + + return pnlPrisonerStatus; + } + + + private JPanel makeKillsPanel() { + JPanel pnlKills = new JPanel(); killChoices = new Hashtable<>(); pnlKills.setLayout(new GridBagLayout()); - gridBagConstraints = new GridBagConstraints(); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 1; @@ -725,13 +877,13 @@ private void initComponents() { gridBagConstraints.weightx = 1.0; pnlKills.add(new JLabel(resourceMap.getString("claim")), gridBagConstraints); - i = 2; + int replaceme_i = 2; JComboBox comboAssign; DefaultComboBoxModel assignModel; - j = 0; + int replaceme_j = 0; for (String killName : tracker.getKillCredits().keySet()) { - j++; - nameLbl = new JLabel(killName); + replaceme_j++; + JLabel nameLbl = new JLabel(killName); assignModel = new DefaultComboBoxModel<>(); assignModel.addElement(resourceMap.getString("none")); int idx = 0; @@ -755,54 +907,56 @@ private void initComponents() { comboAssign.setSelectedIndex(selected); killChoices.put(killName, comboAssign); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = i; + gridBagConstraints.gridy = replaceme_i; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (j == tracker.getKillCredits().keySet().size()) { + if (replaceme_j == tracker.getKillCredits().keySet().size()) { gridBagConstraints.weighty = 1.0; } pnlKills.add(nameLbl, gridBagConstraints); gridBagConstraints.weightx = 1.0; gridBagConstraints.gridx = 1; pnlKills.add(comboAssign, gridBagConstraints); - i++; + replaceme_i++; } - pnlMain.add(pnlKills, KILLPANEL); + return pnlKills; + } - /* - * Collect Rewards Panel - */ - pnlRewards = new JPanel(); + + private JPanel makeRewardsPanel() { + JPanel pnlRewards = new JPanel(); pnlRewards.setLayout(new GridBagLayout()); lootBoxes = new ArrayList<>(); - i = 0; - j = 0; + int replaceme_i = 0; + int replaceme_j = 0; + GridBagConstraints gridBagConstraints; for (Loot loot : loots) { - j++; + replaceme_j++; JCheckBox box = new JCheckBox(loot.getShortDescription()); box.setSelected(false); lootBoxes.add(box); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = i; + gridBagConstraints.gridy = replaceme_i; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; - if (j == (loots.size())) { + if (replaceme_j == (loots.size())) { gridBagConstraints.weighty = 1.0; } gridBagConstraints.insets = new Insets(5, 5, 0, 0); pnlRewards.add(box, gridBagConstraints); - i++; + replaceme_i++; } - pnlMain.add(pnlRewards, REWARDPANEL); + return pnlRewards; + } + + + private JPanel makePreviewPanel() { - /* - * Preview Panel - */ - pnlPreview = new JPanel(); + JPanel pnlPreview = new JPanel(); choiceStatus = new JComboBox<>(); JScrollPane scrRecoveredUnits = new JScrollPaneWithSpeed(); JScrollPane scrRecoveredPilots = new JScrollPaneWithSpeed(); @@ -810,7 +964,6 @@ private void initComponents() { JScrollPane scrMissingPilots = new JScrollPaneWithSpeed(); JScrollPane scrDeadPilots = new JScrollPaneWithSpeed(); JScrollPane scrSalvage = new JScrollPaneWithSpeed(); - txtInstructions = new JTextArea(); txtReport = new MarkdownEditorPanel("After-Action Report"); txtRecoveredUnits = new JTextArea(); txtRecoveredPilots = new JTextArea(); @@ -839,7 +992,7 @@ private void initComponents() { pnlStatus.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5)); pnlStatus.add(lblStatus); pnlStatus.add(choiceStatus); - gridBagConstraints = new GridBagConstraints(); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; @@ -1001,72 +1154,14 @@ private void initComponents() { gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); pnlPreview.add(scrDeadPilots, gridBagConstraints); - pnlMain.add(pnlPreview, PREVIEWPANEL); - - scrMain = new JScrollPaneWithSpeed(pnlMain); - scrMain.setMinimumSize(UIUtil.scaleForGUI(600, 500)); - scrMain.setPreferredSize(UIUtil.scaleForGUI(900, 500)); - getContentPane().add(scrMain, BorderLayout.CENTER); - - - /* - * Set up button panel - */ - JPanel panButtons = new JPanel(); - panButtons.setName("panButtons"); - panButtons.setLayout(new GridBagLayout()); - - JButton btnCancel = new JButton(resourceMap.getString("btnCancel.text")); - btnCancel.setName("btnClose"); - btnCancel.setMnemonic(KeyEvent.VK_C); - btnCancel.addActionListener(evt -> cancel()); - - gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 0; - gridBagConstraints.gridwidth = 1; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.anchor = GridBagConstraints.EAST; - gridBagConstraints.insets = new Insets(5, 5, 0, 0); - panButtons.add(btnCancel, gridBagConstraints); - - btnBack = new JButton(resourceMap.getString("btnBack.text")); - btnBack.setName("btnBack"); - btnBack.setMnemonic(KeyEvent.VK_B); - btnBack.addActionListener(evt -> back()); - gridBagConstraints.gridx = 1; - gridBagConstraints.weightx = 0.0; - panButtons.add(btnBack, gridBagConstraints); - - btnNext = new JButton(resourceMap.getString("btnNext.text")); - btnNext.setName("btnNext"); - btnNext.setMnemonic(KeyEvent.VK_N); - btnNext.addActionListener(evt -> next()); - gridBagConstraints.gridx = 2; - panButtons.add(btnNext, gridBagConstraints); - - btnFinish = new JButton(resourceMap.getString("btnFinish.text")); - btnFinish.setName("btnFinish"); - btnFinish.setMnemonic(KeyEvent.VK_F); - btnFinish.addActionListener(evt -> finish()); - gridBagConstraints.gridx = 3; - panButtons.add(btnFinish, gridBagConstraints); + return pnlPreview; + } - getContentPane().add(panButtons, BorderLayout.PAGE_END); + - switchPanel(currentPanel); - if (!usePanel(currentPanel)) { - next(); - } - - btnNext.setEnabled(true); - btnBack.setEnabled(false); - btnFinish.setEnabled(false); - - pack(); - } + private void prisonerRansomAll() { Iterator capturedBoxes = prisonerCapturedBtns.iterator(); Iterator ransomedBoxes = prisonerRansomedBtns.iterator(); @@ -1080,6 +1175,11 @@ private void prisonerRansomAll() { } + + + + + /** * Rolls the dice to determine if the opposition personnel is captured. * @@ -1102,14 +1202,13 @@ private static boolean rollForCapture(Campaign campaign, OppositionPersonnelStat return false; } - private void generateObjectiveStatusPanel() { - pnlObjectiveStatus = new JPanel(); + private JPanel makeObjectiveStatusPanel() { + JPanel pnlObjectiveStatus = new JPanel(); if (usePanel(OBJECTIVEPANEL)) { pnlObjectiveStatus.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; - gbc.gridy = 1; - gbc.gridwidth = 1; + gbc.gridy = 0; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = new Insets(5, 5, 0, 0); pnlObjectiveStatus.add(new JLabel("Objectives:"), gbc); @@ -1173,6 +1272,7 @@ private void generateObjectiveStatusPanel() { updateObjectiveDisplay(objective, lblObjective); } } + return pnlObjectiveStatus; } @Deprecated // These need to be migrated to the Suite Constants / Suite Options Setup @@ -1192,50 +1292,22 @@ private void switchPanel(String name) { } currentPanel = name; setTitle(currentPanel); - cardLayout.show(pnlMain, currentPanel); - switchInstructions(); - SwingUtilities.invokeLater(() -> scrMain.getVerticalScrollBar().setValue(0)); + // SwingUtilities.invokeLater(() -> scrMain.getVerticalScrollBar().setValue(0)); pack(); } - private void switchInstructions() { - switch (currentPanel) { - case UNITSPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.missingunits")); - break; - case PILOTPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.personnel")); - break; - case SALVAGEPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.salvage")); - break; - case KILLPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.kills")); - break; - case PRISONERPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.prisoners")); - break; - case PREVIEWPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.preview")); - break; - case REWARDPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.reward")); - break; - case OBJECTIVEPANEL: - txtInstructions.setText(resourceMap.getString("txtInstructions.text.objectives")); - break; - default: - txtInstructions.setText(""); - break; - } - txtInstructions.setEditable(false); - txtInstructions.setLineWrap(true); - txtInstructions.setWrapStyleWord(true); - txtInstructions.setBorder(BorderFactory.createCompoundBorder( + + private JTextArea makeInstructions(String instructionText) { + JTextArea toReturn = new JTextArea(); + toReturn.setText(instructionText); + toReturn.setEditable(false); + toReturn.setLineWrap(true); + toReturn.setWrapStyleWord(true); + toReturn.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtInstructions.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - getContentPane().add(txtInstructions, BorderLayout.PAGE_START); + return toReturn; } private void next() { From 81d2843ca3d8f48affff490b0f538834817da2ec Mon Sep 17 00:00:00 2001 From: Weaver Date: Mon, 28 Oct 2024 12:10:28 -0700 Subject: [PATCH 2/6] RSWD - Fully functional, major changes --- .../dialog/ResolveScenarioWizardDialog.java | 800 +++++++++--------- 1 file changed, 402 insertions(+), 398 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index 872c452f43..638f675738 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -19,35 +19,6 @@ * You should have received a copy of the GNU General Public License * along with MekHQ. If not, see . */ -// switch (currentPanel) { -// case UNITSPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.missingunits")); -// break; -// case PILOTPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.personnel")); -// break; -// case SALVAGEPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.salvage")); -// break; -// case KILLPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.kills")); -// break; -// case PRISONERPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.prisoners")); -// break; -// case PREVIEWPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.preview")); -// break; -// case REWARDPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.reward")); -// break; -// case OBJECTIVEPANEL: -// txtInstructions.setText(resourceMap.getString("txtInstructions.text.objectives")); -// break; -// default: -// txtInstructions.setText(""); -// break; -// } package mekhq.gui.dialog; @@ -89,7 +60,6 @@ import javax.swing.JTextArea; import javax.swing.KeyStroke; import javax.swing.ScrollPaneConstants; -import javax.swing.SwingUtilities; import javax.swing.WindowConstants; import megamek.client.ui.Messages; @@ -128,18 +98,17 @@ */ public class ResolveScenarioWizardDialog extends JDialog { //region Variable Declarations - final static String UNITSPANEL = "Unit Status"; - final static String PILOTPANEL = "Pilot Status"; - final static String SALVAGEPANEL = "Claim Salvage"; - final static String PRISONERPANEL= "Captured Personnel Status"; - final static String KILLPANEL = "Assign Kills"; - final static String REWARDPANEL = "Scenario Costs & Payouts"; + final static String UNITSPANEL = "Your Units"; + final static String PILOTPANEL = "Your Personnel"; + final static String SALVAGEPANEL = "Salvage"; + final static String PRISONERPANEL = "Captured Personnel"; + final static String KILLSPANEL = "Assign Kills"; + final static String REWARDPANEL = "Costs & Payouts"; + final static String OBJECTIVEPANEL = "Objective Status"; final static String PREVIEWPANEL = "Preview"; - /* Used by AtB to determine minor contract breaches and bonus rolls */ - final static String OBJECTIVEPANEL = "Objective Status"; final static String[] panelOrder = { - UNITSPANEL, PILOTPANEL, SALVAGEPANEL, PRISONERPANEL, KILLPANEL, REWARDPANEL, + UNITSPANEL, PILOTPANEL, SALVAGEPANEL, PRISONERPANEL, KILLSPANEL, REWARDPANEL, OBJECTIVEPANEL, PREVIEWPANEL }; @@ -152,7 +121,6 @@ public class ResolveScenarioWizardDialog extends JDialog { private JButton btnFinish; private JButton btnBack; - private String currentPanel; private JTabbedPane tabMain; private JPanel pnlUnitStatus; @@ -259,7 +227,6 @@ public ResolveScenarioWizardDialog(JFrame parent, boolean modal, ResolveScenario .dividedBy(salvageUnit.plus(salvageEmployer)).getAmount().intValue(); } } - currentPanel = UNITSPANEL; initComponents(); setLocationRelativeTo(parent); setUserPreferences(); @@ -289,46 +256,48 @@ private void initComponents() { tabMain = new JTabbedPane(); - //region Make Panels + //region Make Tab Panels pnlUnitStatus = makeUnitStatusPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlUnitStatus), UNITSPANEL); + tabMain.add(wrapWithInstructions(pnlUnitStatus, + resourceMap.getString("txtInstructions.text.missingunits")), UNITSPANEL); pnlPilotStatus = makePilotStatusPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlPilotStatus), PILOTPANEL); + tabMain.add(wrapWithInstructions(pnlPilotStatus, + resourceMap.getString("txtInstructions.text.personnel")), PILOTPANEL); pnlSalvage = makeSalvagePanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlSalvage), SALVAGEPANEL); - + tabMain.add(wrapWithInstructions(pnlSalvage, + resourceMap.getString("txtInstructions.text.salvage")), SALVAGEPANEL); pnlPrisonerStatus = makePrisonerStatusPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlPrisonerStatus), PRISONERPANEL); - + tabMain.add(wrapWithInstructions(pnlPrisonerStatus, + resourceMap.getString("txtInstructions.text.prisoners")), PRISONERPANEL); pnlKills = makeKillsPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlKills), KILLPANEL); - + tabMain.add(wrapWithInstructions(pnlKills, + resourceMap.getString("txtInstructions.text.kills")), KILLSPANEL); pnlRewards = makeRewardsPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlRewards), REWARDPANEL); - + tabMain.add(wrapWithInstructions(pnlRewards, + resourceMap.getString("txtInstructions.text.reward")), REWARDPANEL); pnlObjectiveStatus = makeObjectiveStatusPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlObjectiveStatus), OBJECTIVEPANEL); - + tabMain.add(wrapWithInstructions(pnlObjectiveStatus, + resourceMap.getString("txtInstructions.text.objectives")), OBJECTIVEPANEL); pnlPreview = makePreviewPanel(); - tabMain.add(new JScrollPaneWithSpeed(pnlPreview), PREVIEWPANEL); + tabMain.add(wrapWithInstructions(pnlPreview, + resourceMap.getString("txtInstructions.text.preview")), PREVIEWPANEL); - //scrMain = new JScrollPaneWithSpeed(pnlMain); - //scrMain.setMinimumSize(UIUtil.scaleForGUI(600, 500)); - //scrMain.setPreferredSize(UIUtil.scaleForGUI(900, 500)); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx=0; gridBagConstraints.gridy=0; + gridBagConstraints.weightx=1.0; gridBagConstraints.weighty=1.0; + gridBagConstraints.fill=GridBagConstraints.BOTH; gridBagConstraints.anchor=GridBagConstraints.NORTHWEST; getContentPane().add(tabMain, gridBagConstraints); @@ -346,7 +315,6 @@ private void initComponents() { gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; - gridBagConstraints.gridwidth = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.anchor = GridBagConstraints.EAST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); @@ -377,48 +345,50 @@ private void initComponents() { gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx=0; gridBagConstraints.gridy=1; + gridBagConstraints.fill=GridBagConstraints.HORIZONTAL; getContentPane().add(panButtons, gridBagConstraints); - switchPanel(currentPanel); - if (!usePanel(currentPanel)) { - next(); - } - - tabMain.setEnabled(false); - btnNext.setEnabled(true); - btnBack.setEnabled(false); - btnFinish.setEnabled(false); + tabMain.addChangeListener(evt -> tabChanged()); + setEnabledTabs(); - pack(); + // Go to first enabled tab. + for (int i = tabMain.getSelectedIndex(); i < tabMain.getTabCount(); i++ ) { + if (tabMain.isEnabledAt(i)) { + tabMain.setSelectedIndex(i); + break; + } + } + + setMinimumSize(UIUtil.scaleForGUI(850,600)); + setPreferredSize(UIUtil.scaleForGUI(850,1000)); } - + //region Make Unit Status private JPanel makeUnitStatusPanel() { GridBagConstraints gridBagConstraints; - int replaceme_i = 2; - int replaceme_j = 0; - - JPanel pnlUnitStatus = new JPanel(); + + JPanel pnlUnitStatus = new JPanel(new GridBagLayout()); - pnlUnitStatus.setLayout(new GridBagLayout()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.insets = new Insets(5, 5, 0, 0); pnlUnitStatus.add(new JLabel(resourceMap.getString("totaled")), gridBagConstraints); - + chksTotaled = new ArrayList<>(); ustatuses = new ArrayList<>(); btnsEditUnit = new ArrayList<>(); lblsUnitName = new ArrayList<>(); - + JLabel nameLbl; JCheckBox chkTotaled; JButton btnViewUnit; JButton btnEditUnit; - + + int gridy = 2; + int unitIndex = 0; for (Unit unit : tracker.getUnits()) { UnitStatus status = tracker.getUnitsStatus().get(unit.getId()); ustatuses.add(status); @@ -429,7 +399,7 @@ private JPanel makeUnitStatusPanel() { chkTotaled.setName("chkTotaled"); chkTotaled.getAccessibleContext().setAccessibleName(resourceMap.getString("totaled")); chkTotaled.setSelected(status.isTotalLoss()); - chkTotaled.setName(Integer.toString(replaceme_j)); + chkTotaled.setName(Integer.toString(unitIndex)); chkTotaled.setActionCommand(unit.getId().toString()); chkTotaled.addItemListener(new CheckTotalListener()); chksTotaled.add(chkTotaled); @@ -441,17 +411,17 @@ private JPanel makeUnitStatusPanel() { btnEditUnit = new JButton("Edit Unit"); btnEditUnit.setEnabled(!status.isTotalLoss()); btnEditUnit.setActionCommand(unit.getId().toString()); - btnEditUnit.setName(Integer.toString(replaceme_j)); + btnEditUnit.setName(Integer.toString(unitIndex)); btnEditUnit.addActionListener(new EditUnitListener()); btnsEditUnit.add(btnEditUnit); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = replaceme_i; + gridBagConstraints.gridy = gridy; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (++replaceme_j == tracker.getUnits().size()) { + if (unitIndex == tracker.getUnits().size() - 1) { gridBagConstraints.weighty = 1.0; } pnlUnitStatus.add(nameLbl, gridBagConstraints); @@ -460,14 +430,14 @@ private JPanel makeUnitStatusPanel() { gridBagConstraints.gridx = 2; pnlUnitStatus.add(btnViewUnit, gridBagConstraints); gridBagConstraints.gridx = 3; - gridBagConstraints.weightx = 1.0; pnlUnitStatus.add(btnEditUnit, gridBagConstraints); - replaceme_i++; + gridy++; + unitIndex++; } return pnlUnitStatus; } - + // region Make Pilot Status private JPanel makePilotStatusPanel() { JPanel pnlPilotStatus = new JPanel(); pnlPilotStatus.setLayout(new GridBagLayout()); @@ -487,9 +457,6 @@ private JPanel makePilotStatusPanel() { gridBagConstraints.gridx = 3; pnlPilotStatus.add(new JLabel(resourceMap.getString("kia")), gridBagConstraints); - int replaceme_j = 0; - int replaceme_gridy = 2; - Hashtable labelTable = new Hashtable<>(); labelTable.put(0, new JLabel("0") ); labelTable.put(1, new JLabel("1") ); @@ -498,19 +465,22 @@ private JPanel makePilotStatusPanel() { labelTable.put(4, new JLabel("4") ); labelTable.put(5, new JLabel("5") ); + int sortedPeopleIndex = 0; + int gridy = 2; + for (PersonStatus status : tracker.getSortedPeople()) { pstatuses.add(status); - int replaceme_gridx = 0; + int gridx = 0; gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.gridy = replaceme_gridy++; + gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridy = gridy++; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (++replaceme_j == tracker.getPeopleStatus().keySet().size()) { + if (sortedPeopleIndex == tracker.getPeopleStatus().keySet().size() - 1) { gridBagConstraints.weighty = 1.0; } @@ -518,14 +488,14 @@ private JPanel makePilotStatusPanel() { pnlPilotStatus.add(nameLbl, gridBagConstraints); JSlider hitSlider = new JSlider(JSlider.HORIZONTAL, 0, 5, Math.min(status.getHits(), 5)); - hitSlider.setName(Integer.toString(replaceme_j - 1)); + hitSlider.setName(Integer.toString(sortedPeopleIndex)); hitSlider.setMajorTickSpacing(1); hitSlider.setPaintTicks(true); hitSlider.setLabelTable(labelTable); hitSlider.setPaintLabels(true); hitSlider.setSnapToTicks(true); hitSliders.add(hitSlider); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPilotStatus.add(hitSlider, gridBagConstraints); JCheckBox miaCheck = new JCheckBox(""); @@ -533,7 +503,7 @@ private JPanel makePilotStatusPanel() { miaCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("mia")); miaCheck.setSelected(status.isMissing()); miaBtns.add(miaCheck); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPilotStatus.add(miaCheck, gridBagConstraints); JCheckBox kiaCheck = new JCheckBox(""); @@ -542,28 +512,28 @@ private JPanel makePilotStatusPanel() { kiaCheck.addItemListener(new CheckBoxKIAListener(hitSlider, miaCheck)); kiaCheck.setSelected(status.isDead()); kiaBtns.add(kiaCheck); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPilotStatus.add(kiaCheck, gridBagConstraints); JButton btnViewPilot = new JButton("View Personnel"); btnViewPilot.addActionListener(evt -> showPerson(status, false)); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.gridx = gridx++; pnlPilotStatus.add(btnViewPilot, gridBagConstraints); + sortedPeopleIndex++; } return pnlPilotStatus; } - + // region Make Salvage private JPanel makeSalvagePanel() { // Create the panel JPanel pnlSalvage = new JPanel(); pnlSalvage.setLayout(new GridBagLayout()); JPanel pnlSalvageValue = new JPanel(new GridBagLayout()); - int replaceme_gridx = 0; - int replaceme_gridy = 0; + int gridx = 0; + int gridy = 0; GridBagConstraints gridBagConstraints; if ((tracker.getMission() instanceof Contract) && !tracker.usesSalvageExchange()) { gridBagConstraints = new GridBagConstraints(); @@ -572,44 +542,37 @@ private JPanel makeSalvagePanel() { gridBagConstraints.insets = new Insets(5, 5, 0, 0); JLabel lblSalvageValueUnit1 = new JLabel(resourceMap.getString("lblSalvageValueUnit1.text")); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.gridy = replaceme_gridy++; - gridBagConstraints.weightx = 0.0; + gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridy = gridy++; pnlSalvageValue.add(lblSalvageValueUnit1, gridBagConstraints); lblSalvageValueUnit2 = new JLabel(salvageUnit.toAmountAndSymbolString()); - gridBagConstraints.gridx = replaceme_gridx--; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.gridx = gridx--; pnlSalvageValue.add(lblSalvageValueUnit2, gridBagConstraints); JLabel lblSalvageValueEmployer1 = new JLabel(resourceMap.getString("lblSalvageValueEmployer1.text")); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.gridy = replaceme_gridy++; - gridBagConstraints.weightx = 0.0; + gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridy = gridy++; pnlSalvageValue.add(lblSalvageValueEmployer1, gridBagConstraints); lblSalvageValueEmployer2 = new JLabel(salvageEmployer.toAmountAndSymbolString()); - gridBagConstraints.gridx = replaceme_gridx--; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.gridx = gridx--; pnlSalvageValue.add(lblSalvageValueEmployer2, gridBagConstraints); JLabel lblSalvagePct1 = new JLabel(resourceMap.getString("lblSalvagePct1.text")); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.gridy = replaceme_gridy++; - gridBagConstraints.weightx = 0.0; + gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridy = gridy++; pnlSalvageValue.add(lblSalvagePct1, gridBagConstraints); String lead = "" + ((currentSalvagePct > maxSalvagePct) ? "" : ""); lblSalvagePct2 = new JLabel(lead + currentSalvagePct + "% (max " + maxSalvagePct + "%)"); - gridBagConstraints.gridx = replaceme_gridx--; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.gridx = gridx--; pnlSalvageValue.add(lblSalvagePct2, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 4; - gridBagConstraints.weightx = 1.0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(0, 0, 20, 0); @@ -617,23 +580,23 @@ private JPanel makeSalvagePanel() { } // Update any indexing variables - int replaceme_j = 0; - replaceme_gridx = 1; + int salvageIndex = 0; + gridx = 1; // Create the Title Line gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridy = replaceme_gridy++; + gridBagConstraints.gridy = gridy++; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(new JLabel(resourceMap.getString("lblSalvage.text")), gridBagConstraints); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(new JLabel(resourceMap.getString("lblSell.text")), gridBagConstraints); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(new JLabel(resourceMap.getString("lblEscaped.text")), gridBagConstraints); // Initialize the tracking ArrayLists @@ -647,24 +610,23 @@ private JPanel makeSalvagePanel() { gridBagConstraints = new GridBagConstraints(); gridBagConstraints.insets = new Insets(5, 5, 0, 0); - for (TestUnit u : tracker.getPotentialSalvage()) { + for (TestUnit unit : tracker.getPotentialSalvage()) { // Initial variable work - replaceme_gridx = 0; - salvageables.add(u); - UnitStatus status = tracker.getSalvageStatus().get(u.getId()); + gridx = 0; + salvageables.add(unit); + UnitStatus status = tracker.getSalvageStatus().get(unit.getId()); // Initial update to the GridBagConstraints gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; - gridBagConstraints.gridy = replaceme_gridy++; - gridBagConstraints.weightx = 0.0; - if ((replaceme_j + 1) == tracker.getPotentialSalvage().size()) { // we only want the weight change on the last one + gridBagConstraints.gridy = gridy++; + if (salvageIndex == tracker.getPotentialSalvage().size() - 1) { gridBagConstraints.weighty = 1.0; } // Now, we start creating the boxes JLabel salvageUnit = new JLabel(status.getDesc(true)); salvageUnitLabel.add(salvageUnit); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(salvageUnit, gridBagConstraints); JCheckBox salvaged = new JCheckBox(""); @@ -675,7 +637,7 @@ private JPanel makeSalvagePanel() { salvaged.addItemListener(evt -> checkSalvageRights()); salvageBoxes.add(salvaged); gridBagConstraints.anchor = GridBagConstraints.NORTH; - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(salvaged, gridBagConstraints); JCheckBox sold = new JCheckBox(""); @@ -684,33 +646,32 @@ private JPanel makeSalvagePanel() { sold.setEnabled(!tracker.usesSalvageExchange() && tracker.getCampaign().getCampaignOptions().isSellUnits()); sold.addItemListener(evt -> checkSalvageRights()); soldUnitBoxes.add(sold); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(sold, gridBagConstraints); JCheckBox escaped = new JCheckBox(""); escaped.setName("escaped"); escaped.getAccessibleContext().setAccessibleName(resourceMap.getString("lblEscaped.text")); - escaped.setEnabled(!(u.getEntity().isDestroyed() || u.getEntity().isDoomed())); + escaped.setEnabled(!(unit.getEntity().isDestroyed() || unit.getEntity().isDoomed())); escaped.setSelected(!status.isLikelyCaptured()); escaped.addItemListener(evt -> checkSalvageRights()); - escaped.setActionCommand(u.getEntity().getExternalIdAsString()); + escaped.setActionCommand(unit.getEntity().getExternalIdAsString()); escapeBoxes.add(escaped); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(escaped, gridBagConstraints); JButton btnSalvageViewUnit = new JButton("View Unit"); - btnSalvageViewUnit.setActionCommand(u.getId().toString()); + btnSalvageViewUnit.setActionCommand(unit.getId().toString()); btnSalvageViewUnit.addActionListener(new ViewUnitListener(true)); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(btnSalvageViewUnit, gridBagConstraints); JButton btnSalvageEditUnit = new JButton("Edit Unit"); - btnSalvageEditUnit.setName(Integer.toString(replaceme_j++)); - btnSalvageEditUnit.setActionCommand(u.getId().toString()); + btnSalvageEditUnit.setName(Integer.toString(salvageIndex++)); + btnSalvageEditUnit.setActionCommand(unit.getId().toString()); btnSalvageEditUnit.addActionListener(new EditUnitListener(true)); btnsSalvageEditUnit.add(btnSalvageEditUnit); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.gridx = gridx++; pnlSalvage.add(btnSalvageEditUnit, gridBagConstraints); } @@ -719,12 +680,12 @@ private JPanel makeSalvagePanel() { } - + // region Make Prisoner private JPanel makePrisonerStatusPanel() { JPanel pnlPrisonerStatus = new JPanel(); pnlPrisonerStatus.setLayout(new GridBagLayout()); - int replaceme_gridx = 1; + int gridx = 1; prisonerRansomAllButton = new JButton(resourceMap.getString("prisonerRansomAllButton.text")); @@ -739,24 +700,24 @@ private JPanel makePrisonerStatusPanel() { prisonerRansomAllButton.addActionListener(evt -> prisonerRansomAll()); gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.insets = new Insets(5, 5, 0, 0); pnlPrisonerStatus.add(new JLabel(resourceMap.getString("hits")), gridBagConstraints); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(new JLabel(resourceMap.getString("prisoner")), gridBagConstraints); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(new JLabel(resourceMap.getString("prisonerRansomed.text")), gridBagConstraints); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(new JLabel(resourceMap.getString("kia")), gridBagConstraints); - int replaceme_j = 0; - int replaceme_gridy = 2; + int prisonerIndex = 0; + int gridy = 2; Hashtable labelTable = new Hashtable<>(); labelTable.put(0, new JLabel("0") ); @@ -769,16 +730,16 @@ private JPanel makePrisonerStatusPanel() { for (OppositionPersonnelStatus status : tracker.getSortedPrisoners()) { prstatuses.add(status); - replaceme_gridx = 0; + gridx = 0; gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.gridy = replaceme_gridy++; + gridBagConstraints.gridx = gridx++; + gridBagConstraints.gridy = gridy++; gridBagConstraints.gridwidth = 1; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (++replaceme_j == tracker.getOppositionPersonnel().keySet().size()) { + if (prisonerIndex == tracker.getOppositionPersonnel().keySet().size() - 1) { gridBagConstraints.weighty = 1.0; } @@ -786,7 +747,7 @@ private JPanel makePrisonerStatusPanel() { pnlPrisonerStatus.add(nameLbl, gridBagConstraints); JSlider hitSlider = new JSlider(JSlider.HORIZONTAL, 0, 5, Math.min(status.getHits(), 5)); - hitSlider.setName(Integer.toString(replaceme_j - 1)); + hitSlider.setName(Integer.toString(prisonerIndex)); hitSlider.setMajorTickSpacing(1); hitSlider.setPaintTicks(true); hitSlider.setLabelTable(labelTable); @@ -794,7 +755,7 @@ private JPanel makePrisonerStatusPanel() { hitSlider.setSnapToTicks(true); pr_hitSliders.add(hitSlider); gridBagConstraints.anchor = GridBagConstraints.NORTH; - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(hitSlider, gridBagConstraints); JCheckBox prisonerCapturedCheck = new JCheckBox(""); @@ -803,7 +764,7 @@ private JPanel makePrisonerStatusPanel() { prisonerCapturedCheck.setSelected(status.isCaptured()); prisonerCapturedCheck.addItemListener(evt -> checkPrisonerStatus()); prisonerCapturedBtns.add(prisonerCapturedCheck); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(prisonerCapturedCheck, gridBagConstraints); JCheckBox prisonerRansomedCheck = new JCheckBox(""); @@ -812,7 +773,7 @@ private JPanel makePrisonerStatusPanel() { prisonerRansomedCheck.setEnabled(!status.isCaptured()); prisonerRansomedCheck.addItemListener(evt -> checkPrisonerStatus()); prisonerRansomedBtns.add(prisonerRansomedCheck); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(prisonerRansomedCheck, gridBagConstraints); JCheckBox kiaCheck = new JCheckBox(""); @@ -820,13 +781,12 @@ private JPanel makePrisonerStatusPanel() { kiaCheck.getAccessibleContext().setAccessibleName(resourceMap.getString("kia")); kiaCheck.addItemListener(evt -> checkPrisonerStatus()); prisonerKiaBtns.add(kiaCheck); - gridBagConstraints.gridx = replaceme_gridx++; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(kiaCheck, gridBagConstraints); JButton btnViewPrisoner = new JButton("View Personnel"); btnViewPrisoner.addActionListener(evt -> showPerson(status, true)); - gridBagConstraints.gridx = replaceme_gridx++; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.gridx = gridx++; pnlPrisonerStatus.add(btnViewPrisoner, gridBagConstraints); // if the person is dead, set the checkbox and skip all this captured stuff @@ -850,12 +810,53 @@ private JPanel makePrisonerStatusPanel() { // We therefore need to re-generate the personality description at this point, // as this is the earliest point in which that description is visible to the user writeDescription(status.getPerson()); + prisonerIndex++; } return pnlPrisonerStatus; } + /** + * Check Ransom box for every prisoner that has Captured checked. + */ + private void prisonerRansomAll() { + Iterator capturedBoxes = prisonerCapturedBtns.iterator(); + Iterator ransomedBoxes = prisonerRansomedBtns.iterator(); + while (capturedBoxes.hasNext() && ransomedBoxes.hasNext()) { + JCheckBox capturedBox = capturedBoxes.next(); + JCheckBox ransomedBox = ransomedBoxes.next(); + if (capturedBox.isSelected()) { + ransomedBox.setSelected(true); + } + } + } + + + /** + * Rolls the dice to determine if the opposition personnel is captured. + * + * @param status The opposition personnel status object. + * @return True if the opposition personnel was captured, false otherwise. + */ + private static boolean rollForCapture(Campaign campaign, OppositionPersonnelStatus status) { + int target = 6; + + if (campaign.getGameOptions().booleanOption(OptionsConstants.ADVGRNDMOV_EJECTED_PILOTS_FLEE)) { + target = 5; + } + + for (int n = 0; n < status.getHits() + 1; n++) { + if (Utilities.dice(1, 6) >= target) { + return true; + } + } + + return false; + } + + + // region Make Kills private JPanel makeKillsPanel() { JPanel pnlKills = new JPanel(); killChoices = new Hashtable<>(); @@ -877,83 +878,160 @@ private JPanel makeKillsPanel() { gridBagConstraints.weightx = 1.0; pnlKills.add(new JLabel(resourceMap.getString("claim")), gridBagConstraints); - int replaceme_i = 2; JComboBox comboAssign; DefaultComboBoxModel assignModel; - int replaceme_j = 0; + int gridy = 2; + int killIndex = 0; for (String killName : tracker.getKillCredits().keySet()) { - replaceme_j++; JLabel nameLbl = new JLabel(killName); assignModel = new DefaultComboBoxModel<>(); assignModel.addElement(resourceMap.getString("none")); - int idx = 0; + int index = 0; int selected = 0; if (null == tracker.getKillCredits().get(killName)) { continue; } - for (Unit u : tracker.getUnits()) { - idx++; - if (u.getEntity() instanceof GunEmplacement) { - assignModel.addElement("AutoTurret, " + u.getName()); + for (Unit unit : tracker.getUnits()) { + index++; + if (unit.getEntity() instanceof GunEmplacement) { + assignModel.addElement("AutoTurret, " + unit.getName()); } else { - assignModel.addElement(u.getCommander().getFullTitle() + ", " + u.getName()); + assignModel.addElement(unit.getCommander().getFullTitle() + ", " + unit.getName()); } - if (u.getId().toString().equals(tracker.getKillCredits().get(killName))) { - selected = idx; + if (unit.getId().toString().equals(tracker.getKillCredits().get(killName))) { + selected = index; } } comboAssign = new JComboBox<>(assignModel); comboAssign.setSelectedIndex(selected); killChoices.put(killName, comboAssign); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = replaceme_i; - gridBagConstraints.gridwidth = 1; + gridBagConstraints.gridy = gridy; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); gridBagConstraints.weightx = 0.0; - if (replaceme_j == tracker.getKillCredits().keySet().size()) { + if (killIndex == tracker.getKillCredits().keySet().size() - 1) { gridBagConstraints.weighty = 1.0; } pnlKills.add(nameLbl, gridBagConstraints); - gridBagConstraints.weightx = 1.0; gridBagConstraints.gridx = 1; pnlKills.add(comboAssign, gridBagConstraints); - replaceme_i++; + gridy++; + killIndex++; } return pnlKills; } + // region Make Rewards private JPanel makeRewardsPanel() { JPanel pnlRewards = new JPanel(); pnlRewards.setLayout(new GridBagLayout()); lootBoxes = new ArrayList<>(); - int replaceme_i = 0; - int replaceme_j = 0; + int gridy = 0; + int lootIndex = 0; GridBagConstraints gridBagConstraints; for (Loot loot : loots) { - replaceme_j++; JCheckBox box = new JCheckBox(loot.getShortDescription()); box.setSelected(false); lootBoxes.add(box); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = replaceme_i; + gridBagConstraints.gridy = gridy; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; - if (replaceme_j == (loots.size())) { + if (lootIndex == loots.size() - 1) { gridBagConstraints.weighty = 1.0; } gridBagConstraints.insets = new Insets(5, 5, 0, 0); pnlRewards.add(box, gridBagConstraints); - replaceme_i++; + gridy++; + lootIndex++; } return pnlRewards; } + // region Make Objective + private JPanel makeObjectiveStatusPanel() { + JPanel pnlObjectiveStatus = new JPanel(); + pnlObjectiveStatus.setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.insets = new Insets(5, 5, 0, 0); + pnlObjectiveStatus.add(new JLabel("Objectives:"), gbc); + objectiveCheckboxes = new HashMap<>(); + objectiveOverrideCheckboxes = new HashMap<>(); + + objectiveProcessor.evaluateScenarioObjectives(tracker); + + Map> potentialObjectiveUnits = objectiveProcessor.getPotentialObjectiveUnits(); + Map> qualifyingObjectiveUnits = objectiveProcessor.getQualifyingObjectiveUnits(); + + for (ScenarioObjective objective : tracker.getScenario().getScenarioObjectives()) { + // first, we determine the list of units that are potentially associated with the current objective + List currentObjectiveUnits = new ArrayList<>(); + for (String unitID : potentialObjectiveUnits.get(objective)) { + UUID uuid = UUID.fromString(unitID); + if (tracker.getAllInvolvedUnits().containsKey(uuid)) { + currentObjectiveUnits.add(unitID); + } + } + + // if it's a custom objective or there are no associated units, we display + // a single line and an override + if (currentObjectiveUnits.isEmpty()) { + JCheckBox chkObjective = new JCheckBox(); + chkObjective.setText(objective.getDescription()); + chkObjective.setForeground(Color.RED); + gbc.gridy++; + pnlObjectiveStatus.add(chkObjective, gbc); + objectiveOverrideCheckboxes.put(objective, chkObjective); + + chkObjective.addItemListener(e -> { + JCheckBox source = (JCheckBox) e.getSource(); + source.setForeground(source.isSelected() ? Color.green.darker() : Color.RED); + }); + + continue; + } + + // each "standard" objective has a list of units that determine whether it's completed + // the objective matrix contains a set of unit IDs that meet the objective + JLabel lblObjective = new JLabel(objective.toShortString()); + gbc.gridy++; + pnlObjectiveStatus.add(lblObjective, gbc); + + objectiveCheckboxes.put(objective, new ArrayList<>()); + + for (String unitID : currentObjectiveUnits) { + UUID uuid = UUID.fromString(unitID); + + JCheckBox chkItemState = new JCheckBox(tracker.getAllInvolvedUnits().get(uuid).getShortName()); + chkItemState.setSelected(qualifyingObjectiveUnits.get(objective).contains(unitID)); + chkItemState.setActionCommand(unitID); + chkItemState.addItemListener(e -> updateObjectiveDisplay(objective, lblObjective)); + gbc.gridy++; + pnlObjectiveStatus.add(chkItemState, gbc); + objectiveCheckboxes.get(objective).add(chkItemState); + } + + updateObjectiveDisplay(objective, lblObjective); + } + // To push the objective list up to the top of the panel + gbc.gridy++; + gbc.weighty = 1.0; + JLabel lblPlaceholder = new JLabel(" "); + pnlObjectiveStatus.add(lblPlaceholder,gbc); + return pnlObjectiveStatus; + } + + + // region Make Preview private JPanel makePreviewPanel() { JPanel pnlPreview = new JPanel(); @@ -1158,242 +1236,161 @@ private JPanel makePreviewPanel() { return pnlPreview; } - - - - private void prisonerRansomAll() { - Iterator capturedBoxes = prisonerCapturedBtns.iterator(); - Iterator ransomedBoxes = prisonerRansomedBtns.iterator(); - while (capturedBoxes.hasNext() && ransomedBoxes.hasNext()) { - JCheckBox capturedBox = capturedBoxes.next(); - JCheckBox ransomedBox = ransomedBoxes.next(); - if (capturedBox.isSelected()) { - ransomedBox.setSelected(true); - } + // region Misc + @Deprecated // These need to be migrated to the Suite Constants / Suite Options Setup + private void setUserPreferences() { + try { + PreferencesNode preferences = MekHQ.getMHQPreferences().forClass(ResolveScenarioWizardDialog.class); + this.setName("dialog"); + preferences.manage(new JWindowPreference(this)); + } catch (Exception ex) { + logger.error("Failed to set user preferences", ex); } } + /** + * @param toWrap - A JPanel to work with + * @param instructionText - The text for the instruction box + * @return A new JPanel containing the instruction text box above toWrap + */ + private JPanel wrapWithInstructions(JPanel toWrap, String instructionText) { + JTextArea instructions = new JTextArea(); + instructions.setText(instructionText); + instructions.setEditable(false); + instructions.setLineWrap(true); + instructions.setWrapStyleWord(true); + instructions.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createTitledBorder(resourceMap.getString("txtInstructions.title")), + BorderFactory.createEmptyBorder(5, 5, 5, 5))); + + + JPanel container = new JPanel(new GridBagLayout()); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 0.0; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = GridBagConstraints.NORTH; + container.add(instructions, gridBagConstraints); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.fill = GridBagConstraints.BOTH; + gridBagConstraints.anchor = GridBagConstraints.NORTH; + container.add(new JScrollPaneWithSpeed(toWrap), gridBagConstraints); + return container; + } - - + // region Inter-tab updates /** - * Rolls the dice to determine if the opposition personnel is captured. - * - * @param status The opposition personnel status object. - * @return True if the opposition personnel was captured, false otherwise. + * Something changed on the Units panel, update objective panel based on current unit status. */ - private static boolean rollForCapture(Campaign campaign, OppositionPersonnelStatus status) { - int target = 6; - - if (campaign.getGameOptions().booleanOption(OptionsConstants.ADVGRNDMOV_EJECTED_PILOTS_FLEE)) { - target = 5; - } - - for (int n = 0; n < status.getHits() + 1; n++) { - if (Utilities.dice(1, 6) >= target) { - return true; - } + private void updateFromUnitsTab () { + for (JCheckBox box : chksTotaled) { + UUID id = UUID.fromString(box.getActionCommand()); + objectiveProcessor.updateObjectiveEntityState(tracker.getAllInvolvedUnits().get(id), + false, box.isSelected(), !tracker.playerHasBattlefieldControl()); } - - return false; + //recheckObjectives(); } - private JPanel makeObjectiveStatusPanel() { - JPanel pnlObjectiveStatus = new JPanel(); - if (usePanel(OBJECTIVEPANEL)) { - pnlObjectiveStatus.setLayout(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridx = 0; - gbc.gridy = 0; - gbc.anchor = GridBagConstraints.NORTHWEST; - gbc.insets = new Insets(5, 5, 0, 0); - pnlObjectiveStatus.add(new JLabel("Objectives:"), gbc); - objectiveCheckboxes = new HashMap<>(); - objectiveOverrideCheckboxes = new HashMap<>(); - - objectiveProcessor.evaluateScenarioObjectives(tracker); - - Map> potentialObjectiveUnits = objectiveProcessor.getPotentialObjectiveUnits(); - Map> qualifyingObjectiveUnits = objectiveProcessor.getQualifyingObjectiveUnits(); - - for (ScenarioObjective objective : tracker.getScenario().getScenarioObjectives()) { - // first, we determine the list of units that are potentially associated with the current objective - List currentObjectiveUnits = new ArrayList<>(); - for (String unitID : potentialObjectiveUnits.get(objective)) { - UUID uuid = UUID.fromString(unitID); - if (tracker.getAllInvolvedUnits().containsKey(uuid)) { - currentObjectiveUnits.add(unitID); - } - } - - // if it's a custom objective or there are no associated units, we display - // a single line and an override - if (currentObjectiveUnits.isEmpty()) { - JCheckBox chkObjective = new JCheckBox(); - chkObjective.setText(objective.getDescription()); - chkObjective.setForeground(Color.RED); - gbc.gridy++; - pnlObjectiveStatus.add(chkObjective, gbc); - objectiveOverrideCheckboxes.put(objective, chkObjective); - - chkObjective.addItemListener(e -> { - JCheckBox source = (JCheckBox) e.getSource(); - source.setForeground(source.isSelected() ? Color.green.darker() : Color.RED); - }); - - continue; - } - - // each "standard" objective has a list of units that determine whether it's completed - // the objective matrix contains a set of unit IDs that meet the objective - JLabel lblObjective = new JLabel(objective.toShortString()); - gbc.gridy++; - pnlObjectiveStatus.add(lblObjective, gbc); - - objectiveCheckboxes.put(objective, new ArrayList<>()); - - for (String unitID : currentObjectiveUnits) { - UUID uuid = UUID.fromString(unitID); - JCheckBox chkItemState = new JCheckBox(tracker.getAllInvolvedUnits().get(uuid).getShortName()); - chkItemState.setSelected(qualifyingObjectiveUnits.get(objective).contains(unitID)); - chkItemState.setActionCommand(unitID); - chkItemState.addItemListener(e -> updateObjectiveDisplay(objective, lblObjective)); - gbc.gridy++; - pnlObjectiveStatus.add(chkItemState, gbc); - objectiveCheckboxes.get(objective).add(chkItemState); - } - - gbc.gridy++; - updateObjectiveDisplay(objective, lblObjective); - } + /** + * Something changed on the Salvage panel, update objective panel based on current salvage status. + */ + private void updateFromSalvageTab() { + for (JCheckBox box : escapeBoxes) { + UUID id = UUID.fromString(box.getActionCommand()); + objectiveProcessor.updateObjectiveEntityState(tracker.getAllInvolvedUnits().get(id), + box.isSelected(), false, tracker.playerHasBattlefieldControl()); } - return pnlObjectiveStatus; + //recheckObjectives(); } - @Deprecated // These need to be migrated to the Suite Constants / Suite Options Setup - private void setUserPreferences() { - try { - PreferencesNode preferences = MekHQ.getMHQPreferences().forClass(ResolveScenarioWizardDialog.class); - this.setName("dialog"); - preferences.manage(new JWindowPreference(this)); - } catch (Exception ex) { - logger.error("Failed to set user preferences", ex); - } - } - private void switchPanel(String name) { - if (name.equals(PREVIEWPANEL)) { - updatePreviewPanel(); + /** + * Something chnaged about units OR salvage, we need to update the objective panel. + */ + private void recheckObjectives() { + for (ScenarioObjective objective : objectiveCheckboxes.keySet()) { + for (JCheckBox checkBox : objectiveCheckboxes.get(objective)) { + checkBox.setSelected(objectiveProcessor.getQualifyingObjectiveUnits() + .get(objective).contains(checkBox.getActionCommand())); + } } - currentPanel = name; - setTitle(currentPanel); - - // SwingUtilities.invokeLater(() -> scrMain.getVerticalScrollBar().setValue(0)); - pack(); - } - - - private JTextArea makeInstructions(String instructionText) { - JTextArea toReturn = new JTextArea(); - toReturn.setText(instructionText); - toReturn.setEditable(false); - toReturn.setLineWrap(true); - toReturn.setWrapStyleWord(true); - toReturn.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder(resourceMap.getString("txtInstructions.title")), - BorderFactory.createEmptyBorder(5, 5, 5, 5))); - return toReturn; } + // region Tab Movement + /** + * Go to next tab, if there is one + */ private void next() { - btnNext.setEnabled(false); - btnBack.setEnabled(true); - btnFinish.setEnabled(false); - boolean passedCurrent = false; - boolean switchMade = false; - - // if we're done with the units panel, update the objectives state based on selection status - // and damaged editing results - if (currentPanel.equals(ResolveScenarioWizardDialog.UNITSPANEL)) { - for (JCheckBox box : chksTotaled) { - UUID id = UUID.fromString(box.getActionCommand()); - objectiveProcessor.updateObjectiveEntityState(tracker.getAllInvolvedUnits().get(id), - false, box.isSelected(), !tracker.playerHasBattlefieldControl()); + for (int i = tabMain.getSelectedIndex() + 1; i < tabMain.getTabCount(); i++) { + if (tabMain.isEnabledAt(i)) { + tabMain.setSelectedIndex(i); + break; } } + } - // if we're done with the salvage panel, update the objectives state based on selection status - // and damaged editing results - if (currentPanel.equals(ResolveScenarioWizardDialog.SALVAGEPANEL)) { - for (JCheckBox box : escapeBoxes) { - UUID id = UUID.fromString(box.getActionCommand()); - objectiveProcessor.updateObjectiveEntityState(tracker.getAllInvolvedUnits().get(id), - box.isSelected(), false, tracker.playerHasBattlefieldControl()); + /** + * Go to previous tab, if there is one + */ + private void back() { + for (int i = tabMain.getSelectedIndex() - 1; i >= 0; i--) { + if (tabMain.isEnabledAt(i)) { + tabMain.setSelectedIndex(i); + break; } } + } - // now update the objective panel if we updated objective state - if (usePanel(ResolveScenarioWizardDialog.OBJECTIVEPANEL)) { - if (currentPanel.equals(ResolveScenarioWizardDialog.UNITSPANEL) || - currentPanel.equals(ResolveScenarioWizardDialog.SALVAGEPANEL)) { - for (ScenarioObjective objective : objectiveCheckboxes.keySet()) { - for (JCheckBox checkBox : objectiveCheckboxes.get(objective)) { - checkBox.setSelected(objectiveProcessor.getQualifyingObjectiveUnits() - .get(objective).contains(checkBox.getActionCommand())); - } - } + /** + * Update buttons and status because the tab changed + */ + private void tabChanged() { + int current = tabMain.getSelectedIndex(); + boolean nextEnable = false; + boolean prevEnable = false; + + for (int i = current + 1; i < tabMain.getTabCount(); i++) { + if (tabMain.isEnabledAt(i)) { + nextEnable = true; + break; } } - for (String name : panelOrder) { - if (passedCurrent) { - if (usePanel(name)) { - if (!switchMade) { - switchPanel(name); - switchMade = true; - if (name.equals(PREVIEWPANEL)) { - btnFinish.setEnabled(true); - } - } else { - btnNext.setEnabled(true); - break; - } - } - } else if (name.equals(currentPanel)) { - passedCurrent = true; + for (int i = current - 1; i >= 0; i--) { + if (tabMain.isEnabledAt(i)) { + prevEnable = true; + break; } } - } - private void back() { - btnNext.setEnabled(true); - btnBack.setEnabled(false); - btnFinish.setEnabled(false); - boolean passedCurrent = false; - boolean switchMade = false; - for (int i = (panelOrder.length - 1); i >= 0; i--) { - String name = panelOrder[i]; - if (passedCurrent) { - if (usePanel(name)) { - if (!switchMade) { - switchPanel(name); - switchMade = true; - } else { - btnBack.setEnabled(true); - break; - } - } - } else if (name.equals(currentPanel)) { - passedCurrent = true; - } + btnBack.setEnabled(prevEnable); + btnNext.setEnabled(nextEnable); + + if (current == tabMain.getTabCount() - 1) { + btnFinish.setEnabled(true); + } else { + btnFinish.setEnabled(false); } + // Let's just call these all on tab change for safty for now + updateFromUnitsTab(); + updateFromSalvageTab(); + recheckObjectives(); + updatePreviewPanel(); } + + // region Finish private void finish() { //unit status for (JCheckBox box : chksTotaled) { @@ -1507,21 +1504,30 @@ private void cancel() { setVisible(false); } - private boolean usePanel(String panelName) { - return switch (panelName) { - case UNITSPANEL -> !tracker.getUnitsStatus().keySet().isEmpty(); - case OBJECTIVEPANEL -> tracker.getScenario().hasObjectives(); - case PILOTPANEL -> !tracker.getPeopleStatus().keySet().isEmpty(); - case PRISONERPANEL -> !tracker.getOppositionPersonnel().keySet().isEmpty(); - case SALVAGEPANEL -> - !tracker.getPotentialSalvage().isEmpty() && (!(tracker.getMission() instanceof Contract) || ((Contract) tracker.getMission()).canSalvage()); - case KILLPANEL -> !tracker.getKillCredits().isEmpty(); - case REWARDPANEL -> !loots.isEmpty(); - case PREVIEWPANEL -> true; - default -> false; - }; + /** + * Figuires out which tabs should be enabled. Needs to be called after all tabs are generated. + */ + private void setEnabledTabs() { + for( int i = 0; i < tabMain.getTabCount(); i++ ) { + boolean enable = switch (tabMain.getTitleAt(i)) { + case UNITSPANEL -> !tracker.getUnitsStatus().keySet().isEmpty(); + case OBJECTIVEPANEL -> tracker.getScenario().hasObjectives(); + case PILOTPANEL -> !tracker.getPeopleStatus().keySet().isEmpty(); + case PRISONERPANEL -> !tracker.getOppositionPersonnel().keySet().isEmpty(); + case SALVAGEPANEL -> !tracker.getPotentialSalvage().isEmpty() + && (!(tracker.getMission() instanceof Contract) + || ((Contract) tracker.getMission()).canSalvage()); + case KILLSPANEL -> !tracker.getKillCredits().isEmpty(); + case REWARDPANEL -> !loots.isEmpty(); + case PREVIEWPANEL -> true; + default -> false; + }; + tabMain.setEnabledAt(i, enable); + } } + + // region Misc II /** * Count up the selected objective checkboxes * @return the count of selected objective checkboxes @@ -1763,8 +1769,6 @@ private void updatePreviewPanel() { } private void showUnit(UUID id, boolean salvage) { - // TODO : I am not sure I like the pop up dialog, might just make this a view on this - // TODO : dialog UnitStatus ustatus; if (salvage) { ustatus = tracker.getSalvageStatus().get(id); @@ -1777,7 +1781,7 @@ private void showUnit(UUID id, boolean salvage) { } new EntityReadoutDialog(frame, true, ustatus.getEntity()).setVisible(true); } - + private void editUnit(UUID id, int idx, boolean salvage) { UnitStatus ustatus = (salvage ? tracker.getSalvageStatus() : tracker.getUnitsStatus()).get(id); if ((ustatus == null) || (ustatus.getEntity() == null)) { From fb0b4e68a461f395dab17369e18807075499d1c9 Mon Sep 17 00:00:00 2001 From: Weaver Date: Mon, 28 Oct 2024 13:16:50 -0700 Subject: [PATCH 3/6] RSWD - Fix Preview Panel Sizing --- .../dialog/ResolveScenarioWizardDialog.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index 638f675738..5c7267c9b3 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -89,6 +89,7 @@ import mekhq.campaign.stratcon.StratconRulesManager; import mekhq.campaign.unit.TestUnit; import mekhq.campaign.unit.Unit; +import mekhq.gui.baseComponents.DefaultMHQScrollablePanel; import mekhq.gui.utilities.JScrollPaneWithSpeed; import mekhq.gui.utilities.MarkdownEditorPanel; import mekhq.gui.view.PersonViewPanel; @@ -1034,14 +1035,8 @@ private JPanel makeObjectiveStatusPanel() { // region Make Preview private JPanel makePreviewPanel() { - JPanel pnlPreview = new JPanel(); + JPanel pnlPreview = new DefaultMHQScrollablePanel(frame, "Test"); choiceStatus = new JComboBox<>(); - JScrollPane scrRecoveredUnits = new JScrollPaneWithSpeed(); - JScrollPane scrRecoveredPilots = new JScrollPaneWithSpeed(); - JScrollPane scrMissingUnits = new JScrollPaneWithSpeed(); - JScrollPane scrMissingPilots = new JScrollPaneWithSpeed(); - JScrollPane scrDeadPilots = new JScrollPaneWithSpeed(); - JScrollPane scrSalvage = new JScrollPaneWithSpeed(); txtReport = new MarkdownEditorPanel("After-Action Report"); txtRecoveredUnits = new JTextArea(); txtRecoveredPilots = new JTextArea(); @@ -1097,7 +1092,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(new JScrollPaneWithSpeed(txtRewards), gridBagConstraints); + pnlPreview.add(txtRewards, gridBagConstraints); txtReport.setText(""); txtReport.setPreferredSize(UIUtil.scaleForGUI(500, 300)); @@ -1121,7 +1116,6 @@ private JPanel makePreviewPanel() { txtRecoveredUnits.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtRecoveredUnits.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - scrRecoveredUnits.setViewportView(txtRecoveredUnits); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; @@ -1131,7 +1125,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(scrRecoveredUnits, gridBagConstraints); + pnlPreview.add(txtRecoveredUnits, gridBagConstraints); txtRecoveredPilots.setName("txtRecoveredPilots"); txtRecoveredPilots.setText(resourceMap.getString("none")); @@ -1141,7 +1135,6 @@ private JPanel makePreviewPanel() { txtRecoveredPilots.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtRecoveredPilots.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - scrRecoveredPilots.setViewportView(txtRecoveredPilots); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; @@ -1151,7 +1144,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(scrRecoveredPilots, gridBagConstraints); + pnlPreview.add(txtRecoveredPilots, gridBagConstraints); txtMissingUnits.setName("txtMissingUnits"); txtMissingUnits.setText(resourceMap.getString("none")); @@ -1161,7 +1154,6 @@ private JPanel makePreviewPanel() { txtMissingUnits.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtMissingUnits.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - scrMissingUnits.setViewportView(txtMissingUnits); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; @@ -1171,7 +1163,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(scrMissingUnits, gridBagConstraints); + pnlPreview.add(txtMissingUnits, gridBagConstraints); txtMissingPilots.setName("txtMissingPilots"); txtMissingPilots.setText(resourceMap.getString("none")); @@ -1181,7 +1173,6 @@ private JPanel makePreviewPanel() { txtMissingPilots.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtMissingPilots.title")), BorderFactory.createEmptyBorder(5,5,5,5))); - scrMissingPilots.setViewportView(txtMissingPilots); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; @@ -1191,7 +1182,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(scrMissingPilots, gridBagConstraints); + pnlPreview.add(txtMissingPilots, gridBagConstraints); txtSalvage.setName("txtSalvage"); txtSalvage.setText("None"); @@ -1201,7 +1192,6 @@ private JPanel makePreviewPanel() { txtSalvage.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtSalvagedUnits.title")), BorderFactory.createEmptyBorder(5,5,5,5))); - scrSalvage.setViewportView(txtSalvage); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 3; @@ -1211,7 +1201,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(scrSalvage, gridBagConstraints); + pnlPreview.add(txtSalvage, gridBagConstraints); txtDeadPilots.setName("txtDeadPilots"); txtDeadPilots.setText(resourceMap.getString("none")); @@ -1221,7 +1211,6 @@ private JPanel makePreviewPanel() { txtDeadPilots.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("txtDeadPilots.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - scrDeadPilots.setViewportView(txtDeadPilots); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 4; @@ -1231,7 +1220,7 @@ private JPanel makePreviewPanel() { gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(5, 5, 0, 0); - pnlPreview.add(scrDeadPilots, gridBagConstraints); + pnlPreview.add(txtDeadPilots, gridBagConstraints); return pnlPreview; } From 873527c6e2f005c0ccc838e5da0dc7b544491cee Mon Sep 17 00:00:00 2001 From: Weaver Date: Mon, 28 Oct 2024 15:45:58 -0700 Subject: [PATCH 4/6] RSWD - Fix Preview scroll position, cleanup, docs --- .../dialog/ResolveScenarioWizardDialog.java | 326 +++++++++++------- 1 file changed, 209 insertions(+), 117 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index 5c7267c9b3..e058941e58 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -61,6 +61,7 @@ import javax.swing.KeyStroke; import javax.swing.ScrollPaneConstants; import javax.swing.WindowConstants; +import javax.swing.SwingUtilities; import megamek.client.ui.Messages; import megamek.client.ui.dialogs.EntityReadoutDialog; @@ -93,6 +94,7 @@ import mekhq.gui.utilities.JScrollPaneWithSpeed; import mekhq.gui.utilities.MarkdownEditorPanel; import mekhq.gui.view.PersonViewPanel; +import mekhq.utilities.ReportingUtilities; /** * @author Taharqa @@ -193,6 +195,7 @@ public class ResolveScenarioWizardDialog extends JDialog { private final List loots; //region Preview Panel components + private JScrollPane scrPreviewPanel; private JComboBox choiceStatus; private MarkdownEditorPanel txtReport; private JTextArea txtRecoveredUnits; @@ -206,8 +209,8 @@ public class ResolveScenarioWizardDialog extends JDialog { private static final MMLogger logger = MMLogger.create(ResolveScenarioWizardDialog.class); - private final transient ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.ResolveScenarioWizardDialog", - MekHQ.getMHQOptions().getLocale()); + private final transient ResourceBundle resourceMap = + ResourceBundle.getBundle("mekhq.resources.ResolveScenarioWizardDialog", MekHQ.getMHQOptions().getLocale()); //endregion Variable Declarations public ResolveScenarioWizardDialog(JFrame parent, boolean modal, ResolveScenarioTracker t) { @@ -259,37 +262,38 @@ private void initComponents() { //region Make Tab Panels pnlUnitStatus = makeUnitStatusPanel(); - tabMain.add(wrapWithInstructions(pnlUnitStatus, + tabMain.add(wrapWithInstructions(pnlUnitStatus, null, resourceMap.getString("txtInstructions.text.missingunits")), UNITSPANEL); pnlPilotStatus = makePilotStatusPanel(); - tabMain.add(wrapWithInstructions(pnlPilotStatus, + tabMain.add(wrapWithInstructions(pnlPilotStatus, null, resourceMap.getString("txtInstructions.text.personnel")), PILOTPANEL); pnlSalvage = makeSalvagePanel(); - tabMain.add(wrapWithInstructions(pnlSalvage, + tabMain.add(wrapWithInstructions(pnlSalvage, null, resourceMap.getString("txtInstructions.text.salvage")), SALVAGEPANEL); pnlPrisonerStatus = makePrisonerStatusPanel(); - tabMain.add(wrapWithInstructions(pnlPrisonerStatus, + tabMain.add(wrapWithInstructions(pnlPrisonerStatus, null, resourceMap.getString("txtInstructions.text.prisoners")), PRISONERPANEL); pnlKills = makeKillsPanel(); - tabMain.add(wrapWithInstructions(pnlKills, + tabMain.add(wrapWithInstructions(pnlKills, null, resourceMap.getString("txtInstructions.text.kills")), KILLSPANEL); pnlRewards = makeRewardsPanel(); - tabMain.add(wrapWithInstructions(pnlRewards, + tabMain.add(wrapWithInstructions(pnlRewards, null, resourceMap.getString("txtInstructions.text.reward")), REWARDPANEL); pnlObjectiveStatus = makeObjectiveStatusPanel(); - tabMain.add(wrapWithInstructions(pnlObjectiveStatus, + tabMain.add(wrapWithInstructions(pnlObjectiveStatus, null, resourceMap.getString("txtInstructions.text.objectives")), OBJECTIVEPANEL); pnlPreview = makePreviewPanel(); - tabMain.add(wrapWithInstructions(pnlPreview, + scrPreviewPanel = new JScrollPaneWithSpeed(); + tabMain.add(wrapWithInstructions(pnlPreview, scrPreviewPanel, resourceMap.getString("txtInstructions.text.preview")), PREVIEWPANEL); @@ -366,6 +370,10 @@ private void initComponents() { } //region Make Unit Status + /** + * Sub-function of initComponents. Makes the Unit Status Panel. + * @return the Unit Status Panel. + */ private JPanel makeUnitStatusPanel() { GridBagConstraints gridBagConstraints; @@ -439,6 +447,10 @@ private JPanel makeUnitStatusPanel() { } // region Make Pilot Status + /** + * Sub-function of initComponents. Makes the Pilot Panel. + * @return the Pilot Panel + */ private JPanel makePilotStatusPanel() { JPanel pnlPilotStatus = new JPanel(); pnlPilotStatus.setLayout(new GridBagLayout()); @@ -527,6 +539,10 @@ private JPanel makePilotStatusPanel() { } // region Make Salvage + /** + * Sub-function of initComponents. Makes the Salvage Panel. + * @return the Salvage Panel + */ private JPanel makeSalvagePanel() { // Create the panel JPanel pnlSalvage = new JPanel(); @@ -565,8 +581,14 @@ private JPanel makeSalvagePanel() { gridBagConstraints.gridy = gridy++; pnlSalvageValue.add(lblSalvagePct1, gridBagConstraints); - String lead = "" + ((currentSalvagePct > maxSalvagePct) ? "" : ""); - lblSalvagePct2 = new JLabel(lead + currentSalvagePct + "% (max " + maxSalvagePct + "%)"); + StringBuilder salvageUsed = new StringBuilder(); + salvageUsed.append("") + .append((currentSalvagePct <= maxSalvagePct) ? "" : + ReportingUtilities.spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorNegativeHexColor())) + .append(currentSalvagePct).append("%") + .append((currentSalvagePct <= maxSalvagePct) ? "" : ReportingUtilities.CLOSING_SPAN_TAG) + .append("(max ").append(maxSalvagePct).append("%)"); + lblSalvagePct2 = new JLabel(salvageUsed.toString()); gridBagConstraints.gridx = gridx--; pnlSalvageValue.add(lblSalvagePct2, gridBagConstraints); @@ -682,6 +704,10 @@ private JPanel makeSalvagePanel() { // region Make Prisoner + /** + * Sub-function of initComponents. Makes the Prisoner Panel. + * @return the Prisoner Panel + */ private JPanel makePrisonerStatusPanel() { JPanel pnlPrisonerStatus = new JPanel(); pnlPrisonerStatus.setLayout(new GridBagLayout()); @@ -858,6 +884,10 @@ private static boolean rollForCapture(Campaign campaign, OppositionPersonnelStat // region Make Kills + /** + * Sub-function of initComponents. Makes the Kills Panel. + * @return the Kills Panel + */ private JPanel makeKillsPanel() { JPanel pnlKills = new JPanel(); killChoices = new Hashtable<>(); @@ -926,6 +956,10 @@ private JPanel makeKillsPanel() { // region Make Rewards + /** + * Sub-function of initComponents. Makes the Rewards Panel. + * @return the Rewards Panel + */ private JPanel makeRewardsPanel() { JPanel pnlRewards = new JPanel(); pnlRewards.setLayout(new GridBagLayout()); @@ -956,6 +990,10 @@ private JPanel makeRewardsPanel() { // region Make Objective + /** + * Sub-function of initComponents. Makes the Objective Status panel. + * @return the Objective Status panel + */ private JPanel makeObjectiveStatusPanel() { JPanel pnlObjectiveStatus = new JPanel(); pnlObjectiveStatus.setLayout(new GridBagLayout()); @@ -1033,8 +1071,11 @@ private JPanel makeObjectiveStatusPanel() { // region Make Preview + /** + * Sub-function of initComponents. Makes the final panel. + * @return the preview panel + */ private JPanel makePreviewPanel() { - JPanel pnlPreview = new DefaultMHQScrollablePanel(frame, "Test"); choiceStatus = new JComboBox<>(); txtReport = new MarkdownEditorPanel("After-Action Report"); @@ -1240,10 +1281,11 @@ private void setUserPreferences() { /** * @param toWrap - A JPanel to work with + * @param scrPane - JScrollPane to use, or null and we'll make a new one * @param instructionText - The text for the instruction box * @return A new JPanel containing the instruction text box above toWrap */ - private JPanel wrapWithInstructions(JPanel toWrap, String instructionText) { + private JPanel wrapWithInstructions(JPanel toWrap, JScrollPane scrPane, String instructionText) { JTextArea instructions = new JTextArea(); instructions.setText(instructionText); instructions.setEditable(false); @@ -1263,6 +1305,7 @@ private JPanel wrapWithInstructions(JPanel toWrap, String instructionText) { gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.NORTH; container.add(instructions, gridBagConstraints); + gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; @@ -1270,7 +1313,10 @@ private JPanel wrapWithInstructions(JPanel toWrap, String instructionText) { gridBagConstraints.weighty = 1.0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.anchor = GridBagConstraints.NORTH; - container.add(new JScrollPaneWithSpeed(toWrap), gridBagConstraints); + + scrPane = null != scrPane ? scrPane : new JScrollPaneWithSpeed(); + scrPane.setViewportView(toWrap); + container.add(scrPane, gridBagConstraints); return container; } @@ -1287,7 +1333,6 @@ private void updateFromUnitsTab () { objectiveProcessor.updateObjectiveEntityState(tracker.getAllInvolvedUnits().get(id), false, box.isSelected(), !tracker.playerHasBattlefieldControl()); } - //recheckObjectives(); } @@ -1300,7 +1345,6 @@ private void updateFromSalvageTab() { objectiveProcessor.updateObjectiveEntityState(tracker.getAllInvolvedUnits().get(id), box.isSelected(), false, tracker.playerHasBattlefieldControl()); } - //recheckObjectives(); } @@ -1316,9 +1360,102 @@ private void recheckObjectives() { } } + /** + * Updates the final panel with information taken from the other ones. + */ + private void updatePreviewPanel() { + // set victory/defeat status based on scenario objectives + ScenarioStatus scenarioStatus = objectiveProcessor.determineScenarioStatus(tracker.getScenario(), + getObjectiveOverridesStatus(), getObjectiveUnitCounts()); + choiceStatus.setSelectedItem(scenarioStatus); + + // do a "dry run" of the scenario objectives to output a report + StringBuilder reportText = new StringBuilder(); + + if (tracker.getScenario().hasObjectives()) { + for (ScenarioObjective objective : tracker.getScenario().getScenarioObjectives()) { + int qualifyingUnitCount = 0; + + if (objectiveCheckboxes.containsKey(objective)) { + for (JCheckBox box : objectiveCheckboxes.get(objective)) { + if (box.isSelected()) { + qualifyingUnitCount++; + } + } + } + + Boolean override = null; + if (objectiveOverrideCheckboxes.containsKey(objective)) { + override = objectiveOverrideCheckboxes.get(objective).isSelected(); + } + + reportText.append(objectiveProcessor.processObjective( + objective, qualifyingUnitCount, override, tracker, true)); + reportText.append('\n'); + } + + txtReport.setText(reportText.toString()); + } + + //pilots first + StringBuilder missingNames = new StringBuilder(); + StringBuilder kiaNames = new StringBuilder(); + StringBuilder recoverNames = new StringBuilder(); + for (int i = 0; i < pstatuses.size(); i++) { + PersonStatus status = pstatuses.get(i); + if (hitSliders.get(i).getValue() >= 6 || kiaBtns.get(i).isSelected()) { + kiaNames.append(status.getName()).append('\n'); + } else if (miaBtns.get(i).isSelected()) { + missingNames.append(status.getName()).append('\n'); + } else { + recoverNames.append(status.getName()).append('\n'); + } + } + txtRecoveredPilots.setText(recoverNames.toString()); + txtMissingPilots.setText(missingNames.toString()); + txtDeadPilots.setText(kiaNames.toString()); + + //now units + StringBuilder recoverUnits = new StringBuilder(); + StringBuilder missUnits = new StringBuilder(); + for (int i = 0; i < chksTotaled.size(); i++) { + String name = ustatuses.get(i).getName(); + if (chksTotaled.get(i).isSelected()) { + missUnits.append(name).append('\n'); + } else { + recoverUnits.append(name).append('\n'); + } + } + txtRecoveredUnits.setText(recoverUnits.toString()); + txtMissingUnits.setText(missUnits.toString()); + + //now salvage + StringBuilder salvageUnits = new StringBuilder(); + for (int i = 0; i < salvageBoxes.size(); i++) { + JCheckBox box = salvageBoxes.get(i); + if (box.isSelected()) { + salvageUnits.append(salvageables.get(i).getName()).append('\n'); + } + } + txtSalvage.setText(salvageUnits.toString()); + + //now rewards + StringBuilder claimed = new StringBuilder(); + for (int i = 0; i < lootBoxes.size(); i++) { + JCheckBox box = lootBoxes.get(i); + if (box.isSelected()) { + claimed.append(loots.get(i).getShortDescription()).append('\n'); + } + } + txtRewards.setText(claimed.toString()); + SwingUtilities.invokeLater(() -> scrPreviewPanel.getVerticalScrollBar().setValue(0)); + } + + // region Tab Movement + /** - * Go to next tab, if there is one + * Go to next tab, if there is one. Button listener. */ private void next() { for (int i = tabMain.getSelectedIndex() + 1; i < tabMain.getTabCount(); i++) { @@ -1330,7 +1467,7 @@ private void next() { } /** - * Go to previous tab, if there is one + * Go to previous tab, if there is one. Button listener. */ private void back() { for (int i = tabMain.getSelectedIndex() - 1; i >= 0; i--) { @@ -1342,7 +1479,7 @@ private void back() { } /** - * Update buttons and status because the tab changed + * Update buttons and status because the tab changed. Event Listener. */ private void tabChanged() { int current = tabMain.getSelectedIndex(); @@ -1371,15 +1508,20 @@ private void tabChanged() { } else { btnFinish.setEnabled(false); } - // Let's just call these all on tab change for safty for now + // Let's just call these all on tab change for safety for now updateFromUnitsTab(); updateFromSalvageTab(); - recheckObjectives(); + // TODO: WeaverThree - This wipes out user selecitons on the objective panel, so we can't use it right now. + // recheckObjectives(); updatePreviewPanel(); } // region Finish + + /** + * End the wizard and update everything in the game that results from it. + */ private void finish() { //unit status for (JCheckBox box : chksTotaled) { @@ -1493,6 +1635,9 @@ private void cancel() { setVisible(false); } + + // region Misc II + /** * Figuires out which tabs should be enabled. Needs to be called after all tabs are generated. */ @@ -1516,7 +1661,6 @@ private void setEnabledTabs() { } - // region Misc II /** * Count up the selected objective checkboxes * @return the count of selected objective checkboxes @@ -1561,6 +1705,10 @@ private Map getObjectiveOverridesStatus() { return objectiveOverrides; } + + /** + * Event listener for changes to prisoner status. + */ private void checkPrisonerStatus() { for (int i = 0; i < prisonerCapturedBtns.size(); i++) { JCheckBox captured = prisonerCapturedBtns.get(i); @@ -1591,6 +1739,10 @@ private void checkPrisonerStatus() { } } + + /** + * Updates the salvage percentages used and such. Event listener for slavage changes. + */ private void checkSalvageRights() { // Perform a little magic to make sure we aren't trying to do more than one of these things for (int i = 0; i < escapeBoxes.size(); i++) { @@ -1666,100 +1818,27 @@ private void checkSalvageRights() { lblSalvageValueUnit2.setText(salvageUnit.toAmountAndSymbolString()); lblSalvageValueEmployer2.setText(salvageEmployer.toAmountAndSymbolString()); - String lead = (currentSalvagePct <= maxSalvagePct) ? "" : ""; + StringBuilder salvageUsed = new StringBuilder(); - lblSalvagePct2.setText(lead + currentSalvagePct + "% (max " + maxSalvagePct + "%)"); + salvageUsed.append("") + .append((currentSalvagePct <= maxSalvagePct) ? "" : + ReportingUtilities.spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorNegativeHexColor())) + .append(currentSalvagePct).append("%") + .append((currentSalvagePct <= maxSalvagePct) ? "" : ReportingUtilities.CLOSING_SPAN_TAG) + .append("(max ").append(maxSalvagePct).append("%)"); + + lblSalvagePct2.setText(salvageUsed.toString()); } - private void updatePreviewPanel() { - // set victory/defeat status based on scenario objectives - ScenarioStatus scenarioStatus = objectiveProcessor.determineScenarioStatus(tracker.getScenario(), - getObjectiveOverridesStatus(), getObjectiveUnitCounts()); - choiceStatus.setSelectedItem(scenarioStatus); - - // do a "dry run" of the scenario objectives to output a report - StringBuilder sb = new StringBuilder(); - - if (tracker.getScenario().hasObjectives()) { - for (ScenarioObjective objective : tracker.getScenario().getScenarioObjectives()) { - int qualifyingUnitCount = 0; - - if (objectiveCheckboxes.containsKey(objective)) { - for (JCheckBox box : objectiveCheckboxes.get(objective)) { - if (box.isSelected()) { - qualifyingUnitCount++; - } - } - } - - Boolean override = null; - if (objectiveOverrideCheckboxes.containsKey(objective)) { - override = objectiveOverrideCheckboxes.get(objective).isSelected(); - } - - sb.append(objectiveProcessor.processObjective(objective, qualifyingUnitCount, override, tracker, true)); - sb.append('\n'); - } - - txtReport.setText(sb.toString()); - } - - //pilots first - StringBuilder missingNames = new StringBuilder(); - StringBuilder kiaNames = new StringBuilder(); - StringBuilder recoverNames = new StringBuilder(); - for (int i = 0; i < pstatuses.size(); i++) { - PersonStatus status = pstatuses.get(i); - if (hitSliders.get(i).getValue() >= 6 || kiaBtns.get(i).isSelected()) { - kiaNames.append(status.getName()).append('\n'); - } else if (miaBtns.get(i).isSelected()) { - missingNames.append(status.getName()).append('\n'); - } else { - recoverNames.append(status.getName()).append('\n'); - } - } - txtRecoveredPilots.setText(recoverNames.toString()); - txtMissingPilots.setText(missingNames.toString()); - txtDeadPilots.setText(kiaNames.toString()); - - //now units - StringBuilder recoverUnits = new StringBuilder(); - StringBuilder missUnits = new StringBuilder(); - for (int i = 0; i < chksTotaled.size(); i++) { - String name = ustatuses.get(i).getName(); - if (chksTotaled.get(i).isSelected()) { - missUnits.append(name).append('\n'); - } else { - recoverUnits.append(name).append('\n'); - } - } - txtRecoveredUnits.setText(recoverUnits.toString()); - txtMissingUnits.setText(missUnits.toString()); - - //now salvage - StringBuilder salvageUnits = new StringBuilder(); - for (int i = 0; i < salvageBoxes.size(); i++) { - JCheckBox box = salvageBoxes.get(i); - if (box.isSelected()) { - salvageUnits.append(salvageables.get(i).getName()).append('\n'); - } - } - txtSalvage.setText(salvageUnits.toString()); - - //now rewards - StringBuilder claimed = new StringBuilder(); - for (int i = 0; i < lootBoxes.size(); i++) { - JCheckBox box = lootBoxes.get(i); - if (box.isSelected()) { - claimed.append(loots.get(i).getShortDescription()).append('\n'); - } - } - txtRewards.setText(claimed.toString()); - } - private void showUnit(UUID id, boolean salvage) { + /** + * Shows the info for the given unit in a dialog. + * @param id - UUID of the unit to show + * @param isSalvage - is this from the salvage page? + */ + private void showUnit(UUID id, boolean isSalvage) { UnitStatus ustatus; - if (salvage) { + if (isSalvage) { ustatus = tracker.getSalvageStatus().get(id); } else { ustatus = tracker.getUnitsStatus().get(id); @@ -1771,8 +1850,15 @@ private void showUnit(UUID id, boolean salvage) { new EntityReadoutDialog(frame, true, ustatus.getEntity()).setVisible(true); } - private void editUnit(UUID id, int idx, boolean salvage) { - UnitStatus ustatus = (salvage ? tracker.getSalvageStatus() : tracker.getUnitsStatus()).get(id); + + /** + * Opens the unit dmaage editor for a given unit from the units or salvage panel + * @param id - UUID of the unit to show + * @param unitIndex - index into the unit UI elements lists + * @param isSalvage - is this from the salvage page? + */ + private void editUnit(UUID id, int unitIndex, boolean isSalvage) { + UnitStatus ustatus = (isSalvage ? tracker.getSalvageStatus() : tracker.getUnitsStatus()).get(id); if ((ustatus == null) || (ustatus.getEntity() == null)) { return; } @@ -1781,14 +1867,20 @@ private void editUnit(UUID id, int idx, boolean salvage) { med.setVisible(true); ustatus.getUnit().runDiagnostic(false); - if (salvage) { - salvageUnitLabel.get(idx).setText(ustatus.getDesc(true)); + if (isSalvage) { + salvageUnitLabel.get(unitIndex).setText(ustatus.getDesc(true)); checkSalvageRights(); } else { - lblsUnitName.get(idx).setText(ustatus.getDesc()); + lblsUnitName.get(unitIndex).setText(ustatus.getDesc()); } } + + /** + * Shows a person from the pilot or prisoner list in a dialog + * @param status - the record to show + * @param isPrisoner - are they a prisoner? + */ private void showPerson(PersonStatus status, boolean isPrisoner) { if (status == null) { return; From 97fa7849483cd0b437762d10b13f9ee9289953a6 Mon Sep 17 00:00:00 2001 From: Weaver Date: Mon, 28 Oct 2024 16:12:12 -0700 Subject: [PATCH 5/6] RSWD - Add Illiani's changes from #5146 --- .../gui/dialog/ResolveScenarioWizardDialog.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index e058941e58..4cfbb21e15 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -40,6 +40,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.ResourceBundle; import java.util.Set; import java.util.UUID; @@ -322,7 +323,7 @@ private void initComponents() { gridBagConstraints.gridy = 0; gridBagConstraints.weightx = 1.0; gridBagConstraints.anchor = GridBagConstraints.EAST; - gridBagConstraints.insets = new Insets(5, 5, 0, 0); + gridBagConstraints.insets = new Insets(5, 0, 5, 5); panButtons.add(btnCancel, gridBagConstraints); btnBack = new JButton(resourceMap.getString("btnBack.text")); @@ -969,7 +970,7 @@ private JPanel makeRewardsPanel() { GridBagConstraints gridBagConstraints; for (Loot loot : loots) { JCheckBox box = new JCheckBox(loot.getShortDescription()); - box.setSelected(false); + box.setSelected(true); lootBoxes.add(box); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; @@ -1594,10 +1595,12 @@ private void finish() { tracker.assignKills(); //now get loot - for (int i = 0; i < lootBoxes.size(); i++) { - JCheckBox box = lootBoxes.get(i); - if (box.isSelected()) { - tracker.addLoot(loots.get(i)); + if (((ScenarioStatus) Objects.requireNonNull(choiceStatus.getSelectedItem())).isOverallVictory()) { + for (int i = 0; i < lootBoxes.size(); i++) { + JCheckBox box = lootBoxes.get(i); + if (box.isSelected()) { + tracker.addLoot(loots.get(i)); + } } } From 7102f35ee1cea079a871be742ee1cef0de62950d Mon Sep 17 00:00:00 2001 From: Weaver Date: Mon, 28 Oct 2024 19:45:44 -0700 Subject: [PATCH 6/6] RSWD - Set buttons properly on first load --- MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index 4cfbb21e15..cb4e0d6892 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -365,6 +365,8 @@ private void initComponents() { break; } } + + tabChanged(); // Make sure the right buttons are active. setMinimumSize(UIUtil.scaleForGUI(850,600)); setPreferredSize(UIUtil.scaleForGUI(850,1000));