Skip to content

Commit

Permalink
Fix objectives tab name disappearing after switching to history.
Browse files Browse the repository at this point in the history
This was broken by #10839 which removed one call to objectivePanel.getName() but not two others.

This PR refactors the code to not duplicate logic and makes all three places use the correct logic for the name of that tab.
  • Loading branch information
asvitkine committed Jul 15, 2023
1 parent a244e69 commit 5f41dfd
Showing 1 changed file with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,17 @@ public void focusGained(final FocusEvent e) {

SwingUtilities.invokeLater(() -> mapPanel.addKeyListener(getArrowKeyListener()));

addTab("Actions", actionButtons, KeyCode.C);
actionButtons.setBorder(null);
statsPanel = new StatPanel(data, uiContext);
addTab("Players", statsPanel, KeyCode.P);
economyPanel = new EconomyPanel(data, uiContext);
addTab("Resources", economyPanel, KeyCode.R);
objectivePanel = new ObjectivePanel(data, uiContext);
if (objectivePanel.isEmpty()) {
objectivePanel.removeDataChangeListener();
objectivePanel = null;
} else {
String objectivePanelName = new ObjectiveProperties(uiContext.getResourceLoader()).getName();
addTab(objectivePanelName, objectivePanel, KeyCode.O);
}
territoryDetails = new TerritoryDetailPanel(mapPanel, data, uiContext, this);
addTab("Territory", territoryDetails, KeyCode.T);
editPanel = new EditPanel(data, mapPanel, this);
addTabs(true);
// Register a change listener
tabsPanel.addChangeListener(
evt -> {
Expand Down Expand Up @@ -1776,15 +1770,7 @@ private void showHistory() {
new HistoryDetailsPanel(clonedGameData, mapPanel);
tabsPanel.removeAll();
tabsPanel.add("History", historyDetailPanel);
addTab("Players", statsPanel, KeyCode.P);
addTab("Resources", economyPanel, KeyCode.R);
if (objectivePanel != null && !objectivePanel.isEmpty()) {
addTab(objectivePanel.getName(), objectivePanel, KeyCode.O);
}
addTab("Territory", territoryDetails, KeyCode.T);
if (mapPanel.getEditMode()) {
tabsPanel.add("Edit", editPanel);
}
addTabs(false);
actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(false));
historyComponent.removeAll();
historyComponent.setLayout(new BorderLayout());
Expand Down Expand Up @@ -1952,16 +1938,7 @@ private void showGame() {
tabsPanel.removeAll();
}
setWidgetActivation();
addTab("Actions", actionButtons, KeyCode.C);
addTab("Players", statsPanel, KeyCode.P);
addTab("Resources", economyPanel, KeyCode.R);
if (objectivePanel != null && !objectivePanel.isEmpty()) {
addTab(objectivePanel.getName(), objectivePanel, KeyCode.O);
}
addTab("Territory", territoryDetails, KeyCode.T);
if (mapPanel.getEditMode()) {
tabsPanel.add("Edit", editPanel);
}
addTabs(true);
actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(true));
gameMainPanel.removeAll();
gameMainPanel.setLayout(new BorderLayout());
Expand All @@ -1975,6 +1952,22 @@ private void showGame() {
mapPanel.setRoute(null);
}

private void addTabs(boolean includeActionsTab) {
if (includeActionsTab) {
addTab("Actions", actionButtons, KeyCode.C);
}
addTab("Players", statsPanel, KeyCode.P);
addTab("Resources", economyPanel, KeyCode.R);
if (objectivePanel != null && !objectivePanel.isEmpty()) {
String objectivePanelName = new ObjectiveProperties(uiContext.getResourceLoader()).getName();
addTab(objectivePanelName, objectivePanel, KeyCode.O);
}
addTab("Territory", territoryDetails, KeyCode.T);
if (mapPanel.getEditMode()) {
tabsPanel.add("Edit", editPanel);
}
}

private void setWidgetActivation() {
SwingAction.invokeNowOrLater(
() -> {
Expand Down

0 comments on commit 5f41dfd

Please sign in to comment.