-
Notifications
You must be signed in to change notification settings - Fork 176
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
+151
−2
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
82de0e7
add tools to manage SP/VP; track intensity visibility
NickAragua f5d0f82
wording change
NickAragua 2aa06e7
Update MekHQ/src/mekhq/gui/StratconTab.java
NickAragua df520a9
access level modifiers
NickAragua dded3fc
Merge branch 'master' of https://github.com/MegaMek/mekhq into campai…
NickAragua 7b66284
merge from upstream
NickAragua aa86455
Merge branch 'master' of https://github.com/MegaMek/mekhq into campai…
NickAragua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
MekHQ/src/mekhq/gui/stratcon/CampaignManagementDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.