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

add tools to manage SP/VP; track intensity visibility #2725

Merged
merged 7 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 23 additions & 2 deletions MekHQ/src/mekhq/gui/StratconTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/
package mekhq.gui;

import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
Expand All @@ -23,6 +25,7 @@
import java.util.Objects;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
Expand All @@ -39,6 +42,7 @@
import mekhq.campaign.stratcon.StratconCampaignState;
import mekhq.campaign.stratcon.StratconStrategicObjective;
import mekhq.campaign.stratcon.StratconTrackState;
import mekhq.gui.stratcon.CampaignManagementDialog;

/**
* This class contains code relevant to rendering the StratCon ("AtB Campaign State") tab.
Expand All @@ -56,6 +60,8 @@ public class StratconTab extends CampaignGuiTab {
private JScrollPane expandedObjectivePanel;
private boolean objectivesCollapsed = true;

CampaignManagementDialog cmd;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see no good reason to have this always initialized and not just recreate it as required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, I don't see a reason to keep creating/destroying a bunch of buttons and whatnot.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how we handle it in MekHQ, and... permanent memory vs clearable memory regularly matters when using a weaker computer.


/**
* Creates an instance of the StratconTab.
*/
Expand All @@ -77,7 +83,7 @@ public void initTab() {
campaignStatusText = new JLabel();
campaignStatusText.setHorizontalAlignment(SwingConstants.LEFT);
campaignStatusText.setVerticalAlignment(SwingConstants.TOP);

objectiveStatusText = new JLabel();
objectiveStatusText.setHorizontalAlignment(SwingConstants.LEFT);
objectiveStatusText.setVerticalAlignment(SwingConstants.TOP);
Expand All @@ -102,6 +108,8 @@ public void mousePressed(MouseEvent me) {

initializeInfoPanel();
this.add(infoPanel);

cmd = new CampaignManagementDialog(this);

MekHQ.registerHandler(this);
}
Expand All @@ -115,6 +123,12 @@ private void initializeInfoPanel() {

infoPanel.add(new JLabel("Current Campaign Status:"));
infoPanel.add(campaignStatusText);

JButton btnManageCampaignState = new JButton("Manage SP/VP");
btnManageCampaignState.setHorizontalAlignment(SwingConstants.LEFT);
btnManageCampaignState.setVerticalAlignment(SwingConstants.TOP);
btnManageCampaignState.addActionListener(this::showCampaignStateManagement);
infoPanel.add(btnManageCampaignState);

expandedObjectivePanel = new JScrollPane(objectiveStatusText);
expandedObjectivePanel.setMaximumSize(new Dimension(400, 300));
Expand Down Expand Up @@ -177,7 +191,7 @@ public GuiTabType tabType() {
* Worker function that updates the campaign state section of the info panel
* with such info as current objective status, VP/SP totals, etc.
*/
private void updateCampaignState() {
public void updateCampaignState() {
if ((cboCurrentTrack == null) || (campaignStatusText == null)) {
return;
}
Expand Down Expand Up @@ -394,6 +408,13 @@ private void repopulateTrackList() {
stratconPanel.setVisible(false);
}
}

private void showCampaignStateManagement(ActionEvent e) {
TrackDropdownItem selectedTrack = (TrackDropdownItem) cboCurrentTrack.getSelectedItem();
cmd.display(selectedTrack.contract.getStratconCampaignState(), selectedTrack.track, getCampaign().isGM());
cmd.setModalityType(ModalityType.APPLICATION_MODAL);
cmd.setVisible(true);
}
Windchild292 marked this conversation as resolved.
Show resolved Hide resolved

@Subscribe
public void handleNewDay(NewDayEvent ev) {
Expand Down
128 changes: 128 additions & 0 deletions MekHQ/src/mekhq/gui/stratcon/CampaignManagementDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* MegaMek - Copyright (C) 2021 - The MegaMek Team
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*/

package mekhq.gui.stratcon;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

import mekhq.campaign.stratcon.StratconCampaignState;
import mekhq.campaign.stratcon.StratconTrackState;
import mekhq.gui.StratconTab;

/**
* This class handles the UI for campaign VP/SP management
* @author NickAragua
*/
public class CampaignManagementDialog extends JDialog {
private StratconCampaignState currentCampaignState;
private StratconTab parent;
private JButton btnConvertVPToSP;
private JButton btnConvertSPtoBonusPart;
private JButton btnGMAddVP;
private JButton btnGMAddSP;
private JLabel lblTrackScenarioOdds;

public CampaignManagementDialog(StratconTab parent) {
this.parent = parent;
this.setTitle("Manage SP/VP");
initializeUI();
}

/**
* Show the dialog for a given campaign state, and whether GM mode is on or not
*/
public void display(StratconCampaignState campaignState, StratconTrackState currentTrack, boolean gmMode) {
currentCampaignState = campaignState;

btnConvertVPToSP.setEnabled(currentCampaignState.getVictoryPoints() > 0);
btnConvertSPtoBonusPart.setEnabled(currentCampaignState.getSupportPoints() > 0);
btnGMAddVP.setEnabled(gmMode);
btnGMAddSP.setEnabled(gmMode);

lblTrackScenarioOdds.setVisible(gmMode);
if (gmMode) {
lblTrackScenarioOdds.setText(String.format("Track Scenario Odds: %d%%", currentTrack.getScenarioOdds()));
}
}

/**
* One-time set up for all the buttons.
*/
private void initializeUI() {
GridLayout layout = new GridLayout();
layout.setColumns(2);
layout.setRows(0);
layout.setHgap(1);
layout.setVgap(1);

getContentPane().removeAll();
getContentPane().setLayout(layout);

btnConvertVPToSP = new JButton();
btnConvertVPToSP.setText("Convert VP to SP");
btnConvertVPToSP.addActionListener(this::convertVPtoSPHandler);
getContentPane().add(btnConvertVPToSP);

btnConvertSPtoBonusPart = new JButton();
btnConvertSPtoBonusPart.setText("Convert SP to bonus part");
btnConvertSPtoBonusPart.addActionListener(this::convertSPtoBonusPartHandler);
getContentPane().add(btnConvertSPtoBonusPart);

btnGMAddVP = new JButton();
btnGMAddVP.setText("Add VP (GM)");
btnGMAddVP.addActionListener(this::gmAddVPHandler);
getContentPane().add(btnGMAddVP);

btnGMAddSP = new JButton();
btnGMAddSP.setText("Add SP (GM)");
btnGMAddSP.addActionListener(this::gmAddSPHandler);
getContentPane().add(btnGMAddSP);

lblTrackScenarioOdds = new JLabel();
getContentPane().add(lblTrackScenarioOdds);

pack();
}

private void convertVPtoSPHandler(ActionEvent e) {
currentCampaignState.convertVictoryToSupportPoint();
btnConvertVPToSP.setEnabled(currentCampaignState.getVictoryPoints() > 0);
btnConvertSPtoBonusPart.setEnabled(currentCampaignState.getSupportPoints() > 0);
parent.updateCampaignState();
}

private void convertSPtoBonusPartHandler(ActionEvent e) {
currentCampaignState.useSupportPoint();
currentCampaignState.getContract().addBonusParts(1);
btnConvertSPtoBonusPart.setEnabled(currentCampaignState.getSupportPoints() > 0);
parent.updateCampaignState();
}

private void gmAddVPHandler(ActionEvent e) {
currentCampaignState.updateVictoryPoints(1);
btnConvertVPToSP.setEnabled(currentCampaignState.getVictoryPoints() > 0);
parent.updateCampaignState();
}

private void gmAddSPHandler(ActionEvent e) {
currentCampaignState.addSupportPoints(1);
btnConvertSPtoBonusPart.setEnabled(currentCampaignState.getSupportPoints() > 0);
parent.updateCampaignState();
}
}