From 53c96b7a2990a67fffbab4c6c3b44ed52d9b38f8 Mon Sep 17 00:00:00 2001 From: Stian Grenborgen Date: Fri, 19 May 2023 22:21:10 +0200 Subject: [PATCH] Removing ClassicMapControls since CornerMapControls is skinable. The latter can be expanded with more functionality if needed. --- data/base/client-options.xml | 9 +- src/net/sf/freecol/client/ClientOptions.java | 3 + src/net/sf/freecol/client/gui/SwingGUI.java | 4 +- .../client/gui/panel/ClassicMapControls.java | 160 ------------------ .../freecol/client/gui/panel/MapControls.java | 23 --- 5 files changed, 7 insertions(+), 192 deletions(-) delete mode 100644 src/net/sf/freecol/client/gui/panel/ClassicMapControls.java diff --git a/data/base/client-options.xml b/data/base/client-options.xml index fa7912f7f..68f511610 100644 --- a/data/base/client-options.xml +++ b/data/base/client-options.xml @@ -155,14 +155,7 @@ defaultValue="false"/> - - - - - - + defaultValue="true"/> diff --git a/src/net/sf/freecol/client/ClientOptions.java b/src/net/sf/freecol/client/ClientOptions.java index a5db4adce..98fc1379f 100644 --- a/src/net/sf/freecol/client/ClientOptions.java +++ b/src/net/sf/freecol/client/ClientOptions.java @@ -874,6 +874,9 @@ public class ClientOptions extends OptionGroup { addPercentageOption(MUSIC_VOLUME, AUDIO_GROUP, 100); addPercentageOption(SOUND_EFFECTS_VOLUME, AUDIO_GROUP, 100); // end @compat 0.13.0 + // @compat 1.1.0 + remove("model.option.mapControls"); + // end @compat 1.1.0 } private void addPercentageOption(String id, String gr, int val) { diff --git a/src/net/sf/freecol/client/gui/SwingGUI.java b/src/net/sf/freecol/client/gui/SwingGUI.java index 1f49aa902..be169cacc 100644 --- a/src/net/sf/freecol/client/gui/SwingGUI.java +++ b/src/net/sf/freecol/client/gui/SwingGUI.java @@ -68,6 +68,7 @@ import net.sf.freecol.client.gui.mapviewer.MapViewer; import net.sf.freecol.client.gui.mapviewer.MapViewerState; import net.sf.freecol.client.gui.mapviewer.TileViewer; import net.sf.freecol.client.gui.panel.ColonyPanel; +import net.sf.freecol.client.gui.panel.CornerMapControls; import net.sf.freecol.client.gui.panel.FreeColImageBorder; import net.sf.freecol.client.gui.panel.FreeColPanel; import net.sf.freecol.client.gui.panel.InformationPanel; @@ -795,7 +796,8 @@ public class SwingGUI extends GUI { public void startGUI(final Dimension desiredWindowSize) { final FreeColClient fcc = getFreeColClient(); final ClientOptions opts = getClientOptions(); - this.mapControls = MapControls.newInstance(fcc); + this.mapControls = new CornerMapControls(fcc); + final ActionListener al = (ActionEvent ae) -> { final Tile tile = mapViewer.getMapViewerState().getCursorTile(); if (tile != null) { diff --git a/src/net/sf/freecol/client/gui/panel/ClassicMapControls.java b/src/net/sf/freecol/client/gui/panel/ClassicMapControls.java deleted file mode 100644 index 59489b05a..000000000 --- a/src/net/sf/freecol/client/gui/panel/ClassicMapControls.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Copyright (C) 2002-2022 The FreeCol Team - * - * This file is part of FreeCol. - * - * FreeCol is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * FreeCol is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with FreeCol. If not, see . - */ - -package net.sf.freecol.client.gui.panel; - -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JPanel; - -import net.miginfocom.swing.MigLayout; - -import net.sf.freecol.client.FreeColClient; -import net.sf.freecol.client.gui.action.ActionManager; -import net.sf.freecol.client.gui.ImageLibrary; -import net.sf.freecol.common.resources.ResourceManager; -import static net.sf.freecol.common.util.StringUtils.*; - - -/** - * A collection of panels and buttons that are used to provide the - * user with a more detailed view of certain elements on the map and - * also to provide a means of input in case the user can't use the - * keyboard. - */ -public final class ClassicMapControls extends MapControls { - - /** The main panel. */ - private final JPanel panel; - - /** A font for the buttons. */ - private final Font arrowFont; - - /** Helper container for the abstract API functions. */ - private final List componentList = new ArrayList<>(); - - - /** - * The basic constructor. - * - * @param freeColClient The {@code FreeColClient} for the game. - */ - public ClassicMapControls(final FreeColClient freeColClient) { - super(freeColClient, false); - - final ImageLibrary lib = freeColClient.getGUI().getFixedImageLibrary(); - - this.panel = new MigPanel(new MigLayout("wrap 3")); - this.panel.add(this.miniMap, "span" - + ", width " + lib.scaleInt(MINI_MAP_WIDTH) - + ", height " + lib.scaleInt(MINI_MAP_HEIGHT)); - this.panel.add(this.miniMapZoomInButton, "newline 10"); - this.panel.add(this.miniMapZoomOutButton, "skip"); - - String[] arrows = { - ResourceManager.getString("arrow.NW"), - ResourceManager.getString("arrow.N"), - ResourceManager.getString("arrow.NE"), - ResourceManager.getString("arrow.W"), - ResourceManager.getString("arrow.E"), - ResourceManager.getString("arrow.SW"), - ResourceManager.getString("arrow.S"), - ResourceManager.getString("arrow.SE"), - }; - - this.arrowFont = lib.getScaledFont("simple-bold-small", - join("", arrows)); - this.panel.add(makeButton("NW", arrows[0]), "newline 20"); - this.panel.add(makeButton("N", arrows[1])); - this.panel.add(makeButton("NE", arrows[2])); - this.panel.add(makeButton("W", arrows[3])); - this.panel.add(makeButton("E", arrows[4]), "skip"); - this.panel.add(makeButton("SW", arrows[5])); - this.panel.add(makeButton("S", arrows[6])); - this.panel.add(makeButton("SE", arrows[7]), "wrap 20"); - // initialization completes in initializeUnitButtons - - this.componentList.add(this.panel); - } - - /** - * Makes a {@code JButton} for a given arrow direction. - * By default, the direction and arrow parameters should - * be the same literal direction, just formatted for a - * unique context. - * - * @param direction The Direction on the {@code Map} to move - * @param arrow The Direction of the arrow itself - * @return A JButton with the correct display and action - * - * @since 0.10.6 - */ - private JButton makeButton(String direction, String arrow) { - final ActionManager am = getFreeColClient().getActionManager(); - JButton button - = new JButton(am.getFreeColAction("moveAction." + direction)); - button.setFont(arrowFont); - button.setText(arrow); - return button; - } - - /** - * {@inheritDoc} - */ - @Override - protected boolean initializeUnitButtons() { - if (!super.initializeUnitButtons()) return false; - - for (UnitButton ub : this.unitButtons) this.panel.add(ub); - this.panel.add(this.infoPanel, "newline push, span, width " - + this.infoPanel.getWidth() + ", height " - + this.infoPanel.getHeight()); - return true; - } - - // Implement MapControls - - /** - * {@inheritDoc} - */ - @Override - public List getComponentsToAdd(Dimension newSize) { - if (getGame() == null || this.panel.isShowing()) { - return Collections.emptyList(); - } - int width = (int)this.panel.getPreferredSize().getWidth(); - this.panel.setSize(width, newSize.height); - this.panel.setLocation(newSize.width - width, 0); - return this.componentList; - } - - /** - * {@inheritDoc} - */ - @Override - public List getComponentsPresent() { - return (this.panel.isShowing()) ? this.componentList - : Collections.emptyList(); - } -} diff --git a/src/net/sf/freecol/client/gui/panel/MapControls.java b/src/net/sf/freecol/client/gui/panel/MapControls.java index 2c5fe8cf1..f343dd987 100644 --- a/src/net/sf/freecol/client/gui/panel/MapControls.java +++ b/src/net/sf/freecol/client/gui/panel/MapControls.java @@ -196,29 +196,6 @@ public abstract class MapControls extends FreeColClientHolder { repaint(); } - /** - * Create a new map controls instance for a FreeColClient. - * - * @param freeColClient The {@code FreeColClient} to query. - * @return A new {@code MapControls} or null on error. - */ - public static MapControls newInstance(final FreeColClient freeColClient) { - final String className = freeColClient.getClientOptions() - .getString(ClientOptions.MAP_CONTROLS); - final String panelName = "net.sf.freecol.client.gui.panel." - + lastPart(className, "."); - try { - return (MapControls)Introspector.instantiate(panelName, - new Class[] { FreeColClient.class }, - new Object[] { freeColClient }); - } catch (Introspector.IntrospectorException ie) { - logger.log(Level.WARNING, "Failed in make map controls for: " - + panelName, ie); - } - return null; - } - - public void clear() { unitButtons.clear(); }