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

TripleA-2.6.929 show Zoom percentage request #10693 #12082

Merged
Show file tree
Hide file tree
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 @@ -80,6 +80,7 @@ public class GameData implements Serializable, GameState {
@RemoveOnNextMajorRelease @Deprecated private Version gameVersion;
private int diceSides;
private transient List<TerritoryListener> territoryListeners = new CopyOnWriteArrayList<>();

private transient List<GameDataChangeListener> dataChangeListeners = new CopyOnWriteArrayList<>();
private transient Map<String, IDelegate> delegates = new HashMap<>();
private final AllianceTracker alliances = new AllianceTracker();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package games.strategy.engine.data.events;

/**
* A ZoomMapListener will be notified of events that affect a map zoom in ViewMenu in onClick on OK
* button.
*/
public interface ZoomMapListener {
void zoomMapChanged(Integer newZoom);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import games.strategy.engine.data.Territory;
import games.strategy.engine.data.TerritoryEffect;
import games.strategy.engine.data.events.TerritoryListener;
import games.strategy.engine.data.events.ZoomMapListener;
import games.strategy.triplea.Constants;
import games.strategy.triplea.attachments.TerritoryAttachment;
import games.strategy.triplea.util.UnitCategory;
Expand Down Expand Up @@ -43,7 +44,7 @@
import org.triplea.swing.jpanel.GridBagConstraintsFill;

@Slf4j
public class BottomBar extends JPanel implements TerritoryListener {
public class BottomBar extends JPanel implements TerritoryListener, ZoomMapListener {
private final UiContext uiContext;

private final ResourceBar resourceBar;
Expand All @@ -55,6 +56,7 @@ public class BottomBar extends JPanel implements TerritoryListener {
private final JLabel playerLabel = new JLabel("xxxxxx");
private final JLabel stepLabel = new JLabel("xxxxxx");
private final JLabel roundLabel = new JLabel("xxxxxx");
private final JLabel zoomLabel = new JLabel("");

public BottomBar(final UiContext uiContext, final GameData data, final boolean usingDiceServer) {
this.uiContext = uiContext;
Expand Down Expand Up @@ -83,8 +85,14 @@ private JPanel createCenterPanel() {
statusMessage.setVisible(false);
statusMessage.setPreferredSize(new Dimension(0, 0));
statusMessage.setBorder(new EtchedBorder(EtchedBorder.RAISED));

zoomLabel.setVisible(false);
zoomLabel.setBorder(new EtchedBorder(EtchedBorder.RAISED));

centerPanel.add(
statusMessage, gridBuilder.gridX(2).anchor(GridBagConstraintsAnchor.EAST).build());
centerPanel.add(
zoomLabel, gridBuilder.weightX(0).anchor(GridBagConstraintsAnchor.EAST).build());
return centerPanel;
}

Expand Down Expand Up @@ -264,6 +272,10 @@ public void setCurrentPlayer(GamePlayer player, boolean isRemotePlayer) {
playerLabel.setText((isRemotePlayer ? "REMOTE: " : "") + player.getName());
}

public void setMapZoomEnabled(boolean enabled) {
zoomLabel.setVisible(enabled);
}

private void listenForTerritoryUpdates(@Nullable Territory territory) {
// Run async, as this is called while holding a GameData lock so we shouldn't grab a different
// data's lock in this case.
Expand Down Expand Up @@ -302,4 +314,9 @@ public void ownerChanged(Territory territory) {}

@Override
public void attachmentChanged(Territory territory) {}

@Override
public void zoomMapChanged(Integer newZoom) {
zoomLabel.setText(String.format("Zoom: %d%%", newZoom));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import games.strategy.engine.data.Unit;
import games.strategy.engine.data.events.GameDataChangeListener;
import games.strategy.engine.data.events.TerritoryListener;
import games.strategy.engine.data.events.ZoomMapListener;
import games.strategy.triplea.Constants;
import games.strategy.triplea.delegate.EditDelegate;
import games.strategy.triplea.delegate.Matches;
Expand Down Expand Up @@ -88,6 +89,7 @@ public class MapPanel extends ImageScrollerLargeView {
private final List<MapSelectionListener> mapSelectionListeners = new ArrayList<>();
private final List<UnitSelectionListener> unitSelectionListeners = new ArrayList<>();
private final List<MouseOverUnitListener> mouseOverUnitsListeners = new ArrayList<>();
private final List<ZoomMapListener> zoomMapListeners = new ArrayList<>();
private GameData gameData;
// the territory that the mouse is currently over
@Getter private @Nullable Territory currentTerritory;
Expand Down Expand Up @@ -470,6 +472,14 @@ public void setRoute(
SwingUtilities.invokeLater(this::repaint);
}

public void addZoomMapListener(final ZoomMapListener listener) {
zoomMapListeners.add(listener);
}

public void removeZoomMapListener(final ZoomMapListener listener) {
zoomMapListeners.remove(listener);
}

public void addMapSelectionListener(final MapSelectionListener listener) {
mapSelectionListeners.add(listener);
}
Expand Down Expand Up @@ -841,6 +851,8 @@ public double getScale() {
@Override
public void setScale(final double newScale) {
super.setScale(newScale);
zoomMapListeners.forEach(
(zoomMapListener -> zoomMapListener.zoomMapChanged((int) (scale * 100))));
// setScale will check bounds, and normalize the scale correctly
uiContext.setScale(scale);
repaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ protected void paintComponent(final Graphics g) {
data.addGameDataEventListener(
GameDataEvent.TECH_ATTACHMENT_CHANGED, this::clearCachedUnitImages);
uiContext.addShutdownWindow(this);
mapPanel.addZoomMapListener(bottomBar);
}

private void clearCachedUnitImages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ final class ViewMenu extends JMenu {
}
addShowMapDetails();
addShowMapBlends();
addShowZoomMenu();
addMapFontAndColorEditorMenu();
addChatTimeMenu();
addShowCommentLog();
Expand Down Expand Up @@ -324,6 +325,17 @@ private void addShowUnitsMenu() {
add(showUnitsBox);
}

private void addShowZoomMenu() {
final JCheckBoxMenuItem showMapZoomBox = new JCheckBoxMenuItem("Show Zoom Percentage");

showMapZoomBox.addActionListener(
e -> {
this.frame.getBottomBar().setMapZoomEnabled(showMapZoomBox.isSelected());
});

add(showMapZoomBox);
}

private void addShowUnitsInStatusBarMenu() {
JCheckBoxMenuItem checkbox = new JCheckBoxMenuItem("Show Units in Status Bar");
checkbox.setSelected(true);
Expand Down