use of games.strategy.triplea.ui.history.HistoryLog in project triplea by triplea-game.
the class ForumPosterComponent method layoutComponents.
/**
* Invoked by the parent container to layout the components of this panel based on the specified state.
*
* @return A reference to this panel; must be added to the parent container's layout.
*/
public ForumPosterComponent layoutComponents(final PBEMMessagePoster poster, final IAbstractForumPosterDelegate forumPosterDelegate, final MainGameFrame frame, final boolean hasPosted, final boolean allowIncludeTerritorySummary, final boolean allowIncludeTerritoryAllPlayersSummary, final boolean allowIncludeProductionSummary, final boolean allowDiceBattleDetails, final boolean allowDiceStatistics) {
this.forumPosterDelegate = forumPosterDelegate;
this.frame = frame;
this.poster = poster;
historyLog = new HistoryLog();
updateHistoryLog();
// only show widgets if there are PBEM messengers
removeAll();
if (allowIncludeTerritorySummary) {
add(includeTerritoryCheckBox);
}
if (allowIncludeTerritoryAllPlayersSummary) {
add(includeTerritoryAllPlayersCheckBox);
}
if (allowIncludeProductionSummary) {
add(includeProductionCheckBox);
}
if (allowDiceBattleDetails) {
showDetailsCheckBox.setSelected(true);
add(showDetailsCheckBox);
}
if (allowDiceStatistics) {
add(showDiceStatisticsCheckBox);
}
// we always send savegame with emails i think?
includeSavegameCheckBox.setSelected(this.poster.getEmailSender() != null || (this.poster.getForumPoster() != null && this.poster.getForumPoster().getIncludeSaveGame()));
add(includeSavegameCheckBox);
repostTurnSummaryCheckBox.setSelected(!hasPosted);
add(repostTurnSummaryCheckBox);
add(new JButton(SwingAction.of("View " + title, e -> viewHistoryLog())));
postButton.setEnabled(!hasPosted);
add(postButton);
add(new JButton(doneAction));
validate();
return this;
}
use of games.strategy.triplea.ui.history.HistoryLog in project triplea by triplea-game.
the class TripleAFrame method showHistory.
private void showHistory() {
inHistory = true;
inGame = false;
setWidgetActivation();
final GameData clonedGameData;
data.acquireReadLock();
try {
// we want to use a clone of the data, so we can make changes to it
// as we walk up and down the history
clonedGameData = GameDataUtils.cloneGameData(data);
if (clonedGameData == null) {
return;
}
data.removeDataChangeListener(dataChangeListener);
clonedGameData.testLocksOnRead();
if (historySyncher != null) {
throw new IllegalStateException("Two history synchers?");
}
historySyncher = new HistorySynchronizer(clonedGameData, game);
clonedGameData.addDataChangeListener(dataChangeListener);
} finally {
data.releaseReadLock();
}
statsPanel.setGameData(clonedGameData);
economyPanel.setGameData(clonedGameData);
if (objectivePanel != null && !objectivePanel.isEmpty()) {
objectivePanel.setGameData(clonedGameData);
}
details.setGameData(clonedGameData);
mapPanel.setGameData(clonedGameData);
final HistoryDetailsPanel historyDetailPanel = new HistoryDetailsPanel(clonedGameData, mapPanel);
tabsPanel.removeAll();
tabsPanel.add("History", historyDetailPanel);
addTab("Players", statsPanel, 'P');
addTab("Resources", economyPanel, 'R');
if (objectivePanel != null && !objectivePanel.isEmpty()) {
addTab(objectivePanel.getName(), objectivePanel, 'O');
}
addTab("Notes", notesPanel, 'N');
addTab("Territory", details, 'T');
if (getEditMode()) {
tabsPanel.add("Edit", editPanel);
}
if (actionButtons.getCurrent() != null) {
actionButtons.getCurrent().setActive(false);
}
historyComponent.removeAll();
historyComponent.setLayout(new BorderLayout());
// create history tree context menu
// actions need to clear the history panel popup state when done
final JPopupMenu popup = new JPopupMenu();
popup.add(new AbstractAction("Show Summary Log") {
private static final long serialVersionUID = -6730966512179268157L;
@Override
public void actionPerformed(final ActionEvent ae) {
final HistoryLog historyLog = new HistoryLog();
historyLog.printRemainingTurn(historyPanel.getCurrentPopupNode(), false, data.getDiceSides(), null);
historyLog.printTerritorySummary(historyPanel.getCurrentPopupNode(), clonedGameData);
historyLog.printProductionSummary(clonedGameData);
historyPanel.clearCurrentPopupNode();
historyLog.setVisible(true);
}
});
popup.add(new AbstractAction("Show Detailed Log") {
private static final long serialVersionUID = -8709762764495294671L;
@Override
public void actionPerformed(final ActionEvent ae) {
final HistoryLog historyLog = new HistoryLog();
historyLog.printRemainingTurn(historyPanel.getCurrentPopupNode(), true, data.getDiceSides(), null);
historyLog.printTerritorySummary(historyPanel.getCurrentPopupNode(), clonedGameData);
historyLog.printProductionSummary(clonedGameData);
historyPanel.clearCurrentPopupNode();
historyLog.setVisible(true);
}
});
popup.add(new AbstractAction("Export Map Snapshot") {
private static final long serialVersionUID = 1222760138263428443L;
@Override
public void actionPerformed(final ActionEvent ae) {
ScreenshotExporter.exportScreenshot(TripleAFrame.this, data, historyPanel.getCurrentPopupNode());
historyPanel.clearCurrentPopupNode();
}
});
popup.add(new AbstractAction("Save Game at this point (BETA)") {
private static final long serialVersionUID = 1430512376199927896L;
@Override
public void actionPerformed(final ActionEvent ae) {
JOptionPane.showMessageDialog(TripleAFrame.this, "Please first left click on the spot you want to save from, Then right click and select 'Save Game From " + "History'" + "\n\nIt is recommended that when saving the game from the History panel:" + "\n * Your CURRENT GAME is at the start of some player's turn, and that no moves have been made and " + "no actions taken yet." + "\n * The point in HISTORY that you are trying to save at, is at the beginning of a player's turn, " + "or the beginning of a round." + "\nSaving at any other point, could potentially create errors." + "\nFor example, saving while your current game is in the middle of a move or battle phase will " + "always create errors in the savegame." + "\nAnd you will also get errors in the savegame if you try to create a save at a point in history " + "such as a move or battle phase.", "Save Game from History", JOptionPane.INFORMATION_MESSAGE);
data.acquireReadLock();
try {
final File f = TripleAMenuBar.getSaveGameLocation(TripleAFrame.this);
if (f != null) {
try (FileOutputStream fout = new FileOutputStream(f)) {
final GameData datacopy = GameDataUtils.cloneGameData(data, true);
datacopy.getHistory().gotoNode(historyPanel.getCurrentPopupNode());
datacopy.getHistory().removeAllHistoryAfterNode(historyPanel.getCurrentPopupNode());
// TODO: the saved current delegate is still the current delegate,
// rather than the delegate at that history popup node
// TODO: it still shows the current round number, rather than the round at the history popup node
// TODO: this could be solved easily if rounds/steps were changes,
// but that could greatly increase the file size :(
// TODO: this also does not undo the runcount of each delegate step
@SuppressWarnings("unchecked") final Enumeration<TreeNode> enumeration = ((DefaultMutableTreeNode) datacopy.getHistory().getRoot()).preorderEnumeration();
enumeration.nextElement();
int round = 0;
String stepDisplayName = datacopy.getSequence().getStep(0).getDisplayName();
PlayerID currentPlayer = datacopy.getSequence().getStep(0).getPlayerId();
while (enumeration.hasMoreElements()) {
final HistoryNode node = (HistoryNode) enumeration.nextElement();
if (node instanceof Round) {
round = Math.max(0, ((Round) node).getRoundNo() - datacopy.getSequence().getRoundOffset());
currentPlayer = null;
stepDisplayName = node.getTitle();
} else if (node instanceof Step) {
currentPlayer = ((Step) node).getPlayerId();
stepDisplayName = node.getTitle();
}
}
datacopy.getSequence().setRoundAndStep(round, stepDisplayName, currentPlayer);
GameDataManager.saveGame(fout, datacopy);
JOptionPane.showMessageDialog(TripleAFrame.this, "Game Saved", "Game Saved", JOptionPane.INFORMATION_MESSAGE);
} catch (final IOException e) {
ClientLogger.logQuietly("Failed to save game: " + f.getAbsolutePath(), e);
}
}
} finally {
data.releaseReadLock();
}
historyPanel.clearCurrentPopupNode();
}
});
final JSplitPane split = new JSplitPane();
split.setOneTouchExpandable(true);
split.setDividerSize(8);
historyPanel = new HistoryPanel(clonedGameData, historyDetailPanel, popup, uiContext);
split.setLeftComponent(historyPanel);
split.setRightComponent(gameCenterPanel);
split.setDividerLocation(150);
historyComponent.add(split, BorderLayout.CENTER);
historyComponent.add(gameSouthPanel, BorderLayout.SOUTH);
getContentPane().removeAll();
getContentPane().add(historyComponent, BorderLayout.CENTER);
validate();
}
use of games.strategy.triplea.ui.history.HistoryLog in project triplea by triplea-game.
the class FileMenu method addPostPbem.
private JMenuItem addPostPbem() {
final JMenuItem menuPbem = new JMenuItem(SwingAction.of("Post PBEM/PBF Gamesave", e -> {
if (!PBEMMessagePoster.gameDataHasPlayByEmailOrForumMessengers(gameData)) {
return;
}
final String title = "Manual Gamesave Post";
try {
gameData.acquireReadLock();
final GameStep step = gameData.getSequence().getStep();
final PlayerID currentPlayer = (step == null ? PlayerID.NULL_PLAYERID : (step.getPlayerId() == null ? PlayerID.NULL_PLAYERID : step.getPlayerId()));
final int round = gameData.getSequence().getRound();
final HistoryLog historyLog = new HistoryLog();
historyLog.printFullTurn(gameData, true, GameStepPropertiesHelper.getTurnSummaryPlayers(gameData));
final PBEMMessagePoster poster = new PBEMMessagePoster(gameData, currentPlayer, round, title);
PBEMMessagePoster.postTurn(title, historyLog, true, poster, null, frame, null);
} finally {
gameData.releaseReadLock();
}
}));
menuPbem.setMnemonic(KeyEvent.VK_P);
menuPbem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
return menuPbem;
}
Aggregations