Skip to content

Commit

Permalink
Fix objectives tab name disappearing after switching to history. (#11781
Browse files Browse the repository at this point in the history
)

* Fix objectives tab name disappearing after switching to 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 1ce2262
Showing 1 changed file with 21 additions and 27 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(null);
// Register a change listener
tabsPanel.addChangeListener(
evt -> {
Expand Down Expand Up @@ -522,6 +516,24 @@ private void addZoomKeyboardShortcuts() {
mapPanel.getScale() - (ClientSetting.mapZoomFactor.getValueOrThrow() / 100f)));
}

private void addTabs(HistoryDetailsPanel historyDetailPanel) {
if (historyDetailPanel != null) {
tabsPanel.add("History", historyDetailPanel);
} else {
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 addTab(final String title, final Component component, final KeyCode hotkey) {
tabsPanel.addTab(title, null, component, "Hotkey: CTRL+" + hotkey);
SwingKeyBinding.addKeyBindingWithMetaAndCtrlMasks(
Expand Down Expand Up @@ -1775,16 +1787,7 @@ private void showHistory() {
final HistoryDetailsPanel historyDetailPanel =
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(historyDetailPanel);
actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(false));
historyComponent.removeAll();
historyComponent.setLayout(new BorderLayout());
Expand Down Expand Up @@ -1952,16 +1955,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(null);
actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(true));
gameMainPanel.removeAll();
gameMainPanel.setLayout(new BorderLayout());
Expand Down

0 comments on commit 1ce2262

Please sign in to comment.