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

Fix objectives tab name disappearing after switching to history. #11781

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Changes from all 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
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