Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Campaign Options IIC Preset Picker #4981

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,6 @@ btnNewYear.toolTipText=Advance to the first day of the next year (e.g., 01-JAN-3
btnNewQuinquennial.text=New Quinquennial
btnNewQuinquennial.toolTipText=<html>Advance to the first day of the next quinquennial (e.g., 01-JAN-3025, 01-JAN-3030). <br>WARNING: This will take a large amount of RAM to run, and may cause MekHQ to crash if there is not enough allocated.</html>

### CampaignPresetSelectionDialog Class
CampaignPresetSelectionDialog.title=Select Campaign Preset

### StoryArcSelectionDialog Class
StoryArcSelectionDialog.title=Select a Story Arc

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## SelectPresetDialog Class
# SelectPresetDialog
presetDialog.title=Select a Campaign Preset
presetDialog.description=Choose a preset to tailor your experience. Each option provides a\
\ well-balanced challenge, suitable for both newcomers and seasoned players.
presetDialogSelect.name=Confirm
presetDialogSelect.tooltip=Confirm the currently selected preset.
presetDialogCustomize.name=Customize
presetDialogCustomize.tooltip=Select a preset, then open the campaign options menu.
presetDialogCancel.name=Cancel
presetDialogCancel.tooltip=Return to the prior screen.
49 changes: 20 additions & 29 deletions MekHQ/src/mekhq/campaign/CampaignPreset.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,6 @@
*/
package mekhq.campaign;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.Version;
import megamek.common.annotations.Nullable;
import megamek.common.options.GameOptions;
Expand All @@ -64,15 +37,26 @@
import mekhq.campaign.universe.Systems;
import mekhq.campaign.universe.companyGeneration.CompanyGenerationOptions;
import mekhq.utilities.MHQXMLUtility;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.swing.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
* This is an object which holds a set of objects that collectively define the
* initial options setup for a campaign.
*
* <p>
* It includes both startup values, which are only used on initial startup (the
* date, starting planet, and rank system), and continuous options, which can be
* applied at any time (campaign options, skills, SPAs).
*
* <p>
* It also includes a short title and description that allows one to create and
* save different presets. The goal is to allow users to create and load various
* different presets.
Expand Down Expand Up @@ -162,6 +146,13 @@ public boolean isUserData() {
return userData;
}

/**
* @return the title of the {@link CampaignPreset}
*/
public String getTitle() {
return title;
}

public void setTitle(final String title) {
this.title = title;
}
Expand Down
13 changes: 8 additions & 5 deletions MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import mekhq.gui.dialog.reportDialogs.*;
import mekhq.gui.enums.MHQTabType;
import mekhq.gui.model.PartsTableModel;
import mekhq.gui.panes.campaignOptions.SelectPresetDialog;
import mekhq.io.FileType;
import mekhq.utilities.MHQXMLUtility;
import org.w3c.dom.Document;
Expand All @@ -95,6 +96,8 @@
import java.util.stream.IntStream;
import java.util.zip.GZIPOutputStream;

import static mekhq.gui.panes.campaignOptions.SelectPresetDialog.PRESET_SELECTION_CANCELLED;

/**
* The application's main frame.
*/
Expand Down Expand Up @@ -307,7 +310,7 @@ private void setUserPreferences() {
* as they are both accessed through the same GUI page.
* The following mnemonic keys are being used as of 30-MAR-2020:
* A, B, C, E, F, H, I, L, M, N, O, P, R, S, T, V, W, /
*
* <p>
* Note 1: the slash is used for the help, as it is normally the same key as the
* ?
* Note 2: the A mnemonic is used for the Advance Day button
Expand Down Expand Up @@ -376,9 +379,9 @@ private void initMenu() {
miImportCampaignPreset.setMnemonic(KeyEvent.VK_C);
miImportCampaignPreset.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
miImportCampaignPreset.addActionListener(evt -> {
final CampaignPresetSelectionDialog campaignPresetSelectionDialog = new CampaignPresetSelectionDialog(
getFrame());
if (!campaignPresetSelectionDialog.showDialog().isConfirmed()) {
final SelectPresetDialog campaignPresetSelectionDialog =
new SelectPresetDialog(getFrame(), true, false);
if (campaignPresetSelectionDialog.getReturnState() == PRESET_SELECTION_CANCELLED) {
return;
}
final CampaignPreset preset = campaignPresetSelectionDialog.getSelectedPreset();
Expand Down Expand Up @@ -1545,7 +1548,7 @@ private void menuOptionsActionPerformed(final ActionEvent evt) {
getCampaign().getUnitMarket().setOffers(unitMarket.getOffers());
miUnitMarket.setVisible(!getCampaign().getUnitMarket().getMethod().isNone());
}

AbstractContractMarket contractMarket = getCampaign().getContractMarket();
if (contractMarket.getMethod() != newOptions.getContractMarketMethod()) {
getCampaign().setContractMarket(newOptions.getContractMarketMethod().getContractMarket());
Expand Down
8 changes: 6 additions & 2 deletions MekHQ/src/mekhq/gui/dialog/CampaignOptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
import mekhq.gui.FileDialogs;
import mekhq.gui.baseComponents.AbstractMHQValidationButtonDialog;
import mekhq.gui.panes.CampaignOptionsPane;
import mekhq.gui.panes.campaignOptions.SelectPresetDialog;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;

import static mekhq.gui.panes.campaignOptions.SelectPresetDialog.PRESET_SELECTION_CANCELLED;

/**
* @author Jay Lawson (jaylawson39 at yahoo.com) (Original Version, now largely CampaignOptionsPane)
* @author Justin 'Windchild' Bowen (Current Version)
Expand Down Expand Up @@ -105,8 +108,9 @@ protected JPanel createButtonPanel() {

panel.add(new MMButton("btnLoadPreset", resources, "btnLoadPreset.text",
"btnLoadPreset.toolTipText", evt -> {
final CampaignPresetSelectionDialog presetSelectionDialog = new CampaignPresetSelectionDialog(getFrame());
if (presetSelectionDialog.showDialog().isConfirmed()) {
final SelectPresetDialog presetSelectionDialog =
new SelectPresetDialog(getFrame(), true, false);
if (presetSelectionDialog.getReturnState() != PRESET_SELECTION_CANCELLED) {
applyPreset(presetSelectionDialog.getSelectedPreset());
}
}));
Expand Down
79 changes: 0 additions & 79 deletions MekHQ/src/mekhq/gui/dialog/CampaignPresetSelectionDialog.java

This file was deleted.

67 changes: 40 additions & 27 deletions MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,6 @@
*/
package mekhq.gui.dialog;

import java.awt.BorderLayout;
import java.awt.Container;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.time.LocalDate;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;

import megamek.client.generator.RandomCallsignGenerator;
import megamek.client.generator.RandomNameGenerator;
import megamek.client.ui.swing.util.UIUtil;
Expand Down Expand Up @@ -66,6 +49,21 @@
import mekhq.campaign.universe.Systems;
import mekhq.campaign.universe.eras.Eras;
import mekhq.gui.baseComponents.AbstractMHQDialog;
import mekhq.gui.panes.campaignOptions.SelectPresetDialog;

import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.time.LocalDate;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import static mekhq.gui.panes.campaignOptions.SelectPresetDialog.PRESET_SELECTION_CANCELLED;
import static mekhq.gui.panes.campaignOptions.SelectPresetDialog.PRESET_SELECTION_CUSTOMIZE;
import static mekhq.gui.panes.campaignOptions.SelectPresetDialog.PRESET_SELECTION_SELECT;

public class DataLoadingDialog extends AbstractMHQDialog implements PropertyChangeListener {
private static final MMLogger logger = MMLogger.create(DataLoadingDialog.class);
Expand Down Expand Up @@ -290,12 +288,23 @@ public Campaign doInBackground() throws Exception {
campaign = new Campaign();

// Campaign Preset
final CampaignPresetSelectionDialog presetSelectionDialog = new CampaignPresetSelectionDialog(dialog,
getFrame());
if (presetSelectionDialog.showDialog().isCancelled()) {
return null;
final SelectPresetDialog presetSelectionDialog =
new SelectPresetDialog(getFrame(), true, true);
CampaignPreset preset;
boolean isSelect = false;

switch (presetSelectionDialog.getReturnState()) {
case PRESET_SELECTION_CANCELLED -> {
return null;
}
case PRESET_SELECTION_SELECT -> {
preset = presetSelectionDialog.getSelectedPreset();
isSelect = true;
}
case PRESET_SELECTION_CUSTOMIZE -> preset = presetSelectionDialog.getSelectedPreset();
default -> throw new IllegalStateException("Unexpected value in mekhq/gui/dialog/DataLoadingDialog.java/Step 6: "
+ presetSelectionDialog.getReturnState());
}
final CampaignPreset preset = presetSelectionDialog.getSelectedPreset();

// Date
final LocalDate date = ((preset == null) || (preset.getDate() == null))
Expand All @@ -319,11 +328,15 @@ public Campaign doInBackground() throws Exception {
setVisible(false);

// Campaign Options
CampaignOptionsDialog optionsDialog = new CampaignOptionsDialog(dialog, getFrame(), campaign, true);
optionsDialog.setLocationRelativeTo(getFrame());
optionsDialog.applyPreset(preset);
if (optionsDialog.showDialog().isCancelled()) {
return null;
if (isSelect && preset != null) {
preset.applyContinuousToCampaign(campaign);
} else {
CampaignOptionsDialog optionsDialog = new CampaignOptionsDialog(dialog, getFrame(), campaign, true);
optionsDialog.setLocationRelativeTo(getFrame());
optionsDialog.applyPreset(preset);
if (optionsDialog.showDialog().isCancelled()) {
return null;
}
}

// initialize reputation
Expand Down
Loading