Skip to content

Commit f668b47

Browse files
committed
The end turn panel can now be resized.
1 parent b005bbe commit f668b47

File tree

6 files changed

+105
-122
lines changed

6 files changed

+105
-122
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All savegames (without mods) from 0.12.0 and up should continue working with 1.2
55
### User Interface ###
66
* Changes the default for most confirm dialogs to OK instead of Cancel.
77
* Lots of dialogs, that where previously popups outside the game window, have now moved into the main game window.
8+
* The end turn panel can now be resized.
89
* 10 in now the minimum font size. This mitigates the effect from low reported DPI on macos when a non-native resolution is used.
910
* Scroll bar speed is now adjusted according to the current font size. This applies when scrolling with the mouse wheel or the scroll bar buttons.
1011
* Bugfix: Attack animations are now played in the correct position.

src/net/sf/freecol/client/control/InGameController.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -1109,12 +1109,7 @@ private void doEndTurn(boolean showDialog) {
11091109
List<Unit> units = transform(player.getUnits(), Unit::isCandidateForNextActiveUnit);
11101110
if (!units.isEmpty()) {
11111111
// Modal dialog takes over
1112-
getGUI().showEndTurnDialog(units,
1113-
(Boolean value) -> {
1114-
if (value != null && value) {
1115-
endTurn(false);
1116-
}
1117-
});
1112+
getGUI().showEndTurnDialog(units);
11181113
return;
11191114
}
11201115
}

src/net/sf/freecol/client/gui/GUI.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -2091,10 +2091,8 @@ public void showEmigrationDialog(final Player player,
20912091
* Show a dialog for the end of turn.
20922092
*
20932093
* @param units A list of {@code Unit}s that can still move.
2094-
* @param handler A callback to handle the user selected end turn state.
20952094
*/
2096-
public void showEndTurnDialog(final List<Unit> units,
2097-
DialogHandler<Boolean> handler) {}
2095+
public void showEndTurnDialog(final List<Unit> units) {}
20982096

20992097
/**
21002098
* Show an error panel.

src/net/sf/freecol/client/gui/SwingGUI.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -2224,9 +2224,8 @@ public void showEmigrationDialog(final Player player,
22242224
* {@inheritDoc}
22252225
*/
22262226
@Override
2227-
public void showEndTurnDialog(final List<Unit> units,
2228-
DialogHandler<Boolean> handler) {
2229-
this.widgets.showEndTurnDialog(units, handler);
2227+
public void showEndTurnDialog(final List<Unit> units) {
2228+
this.widgets.showEndTurnDialog(units);
22302229
}
22312230

22322231
/**

src/net/sf/freecol/client/gui/Widgets.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,9 @@ public void showEmigrationDialog(Player player, boolean fountainOfYouth,
624624
* @param units A list of {@code Unit}s that could still move.
625625
* @param handler A {@code DialogHandler} for the dialog response.
626626
*/
627-
public void showEndTurnDialog(List<Unit> units,
628-
DialogHandler<Boolean> handler) {
629-
new DialogCallback<>(new EndTurnDialog(this.freeColClient,
630-
getFrame(), units),
631-
null, handler);
627+
public void showEndTurnDialog(List<Unit> units) {
628+
final EndTurnDialog endTurnPanel = new EndTurnDialog(this.freeColClient, units);
629+
this.canvas.showFreeColPanel(endTurnPanel, PopupPosition.LEFT, true);
632630
}
633631

634632
/**

src/net/sf/freecol/client/gui/dialog/EndTurnDialog.java

+97-105
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import javax.swing.AbstractAction;
3131
import javax.swing.DefaultListModel;
3232
import javax.swing.ImageIcon;
33-
import javax.swing.JFrame;
33+
import javax.swing.JButton;
3434
import javax.swing.JLabel;
3535
import javax.swing.JList;
3636
import javax.swing.JPanel;
@@ -46,24 +46,115 @@
4646

4747
import net.miginfocom.swing.MigLayout;
4848
import net.sf.freecol.client.FreeColClient;
49+
import net.sf.freecol.client.gui.panel.FreeColButton.ButtonStyle;
50+
import net.sf.freecol.client.gui.panel.FreeColPanel;
4951
import net.sf.freecol.client.gui.panel.MigPanel;
5052
import net.sf.freecol.client.gui.panel.Utility;
5153
import net.sf.freecol.client.gui.plaf.FreeColSelectedPanelUI;
5254
import net.sf.freecol.common.i18n.Messages;
53-
import net.sf.freecol.common.model.Player;
5455
import net.sf.freecol.common.model.StringTemplate;
5556
import net.sf.freecol.common.model.Unit;
5657

5758

5859
/**
59-
* Centers the map on a known settlement or colony. Pressing ENTER
60-
* opens a panel if appropriate.
60+
* Displays units that have no orders and allows the player to
61+
* either end turn immediately or stop to give them orders.
6162
*/
62-
public final class EndTurnDialog extends FreeColConfirmDialog {
63+
public final class EndTurnDialog extends FreeColPanel {
6364

6465
@SuppressWarnings("unused")
6566
private static final Logger logger = Logger.getLogger(EndTurnDialog.class.getName());
6667

68+
/** The list of units to display. */
69+
private final JList<UnitWrapper> unitList;
70+
71+
72+
/**
73+
* Creates a new dialog.
74+
*
75+
* @param freeColClient The {@code FreeColClient}
76+
* @param units The list of units that still have moves left.
77+
*/
78+
public EndTurnDialog(FreeColClient freeColClient, List<Unit> units) {
79+
super(freeColClient, null, new MigLayout("wrap 1, fill", "[align center]", "[][][growprio 200][]"));
80+
81+
final JLabel header = Utility.localizedHeader(Messages.nameKey("endTurnDialog"), Utility.FONTSPEC_TITLE);
82+
83+
JTextArea text = Utility.localizedTextArea(StringTemplate
84+
.template("endTurnDialog.areYouSure")
85+
.addAmount("%number%", units.size()));
86+
87+
DefaultListModel<UnitWrapper> model = new DefaultListModel<>();
88+
for (Unit unit : units) {
89+
model.addElement(new UnitWrapper(unit));
90+
}
91+
92+
final int numUnitRows = Math.min(4, units.size());
93+
94+
this.unitList = new JList<>(model);
95+
this.unitList.setVisibleRowCount(numUnitRows);
96+
this.unitList.setCellRenderer(new UnitCellRenderer());
97+
this.unitList.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "select");
98+
this.unitList.getActionMap().put("select", new AbstractAction() {
99+
@Override
100+
public void actionPerformed(ActionEvent ae) {
101+
selectUnit();
102+
}
103+
});
104+
105+
this.unitList.addListSelectionListener(new ListSelectionListener() {
106+
@Override
107+
public void valueChanged(ListSelectionEvent e) {
108+
if (e.getValueIsAdjusting()) return;
109+
selectUnit();
110+
}
111+
});
112+
113+
JScrollPane listScroller = new JScrollPane(this.unitList);
114+
115+
add(header, "growx, shrinkx");
116+
add(text, "newline 20, growx, shrinkx, wmin 100");
117+
add(listScroller, "newline 10, grow, shrink");
118+
119+
final JButton okButton = Utility.localizedButton("ok").withButtonStyle(ButtonStyle.IMPORTANT);
120+
okButton.addActionListener(ae -> {
121+
getGUI().removeComponent(this);
122+
getFreeColClient().getInGameController().endTurn(false);
123+
});
124+
add(okButton, "newline, split 2, tag ok");
125+
126+
final JButton cancelButton = Utility.localizedButton("cancel");
127+
cancelButton.addActionListener(ae -> {
128+
getGUI().removeComponent(this);
129+
});
130+
add(cancelButton, "tag cancel");
131+
132+
setEscapeAction(new AbstractAction() {
133+
@Override
134+
public void actionPerformed(ActionEvent ae) {
135+
cancelButton.doClick();
136+
}
137+
});
138+
}
139+
140+
/**
141+
* Select the current unit in the list.
142+
*/
143+
private void selectUnit() {
144+
final UnitWrapper wrapper = this.unitList.getSelectedValue();
145+
if (wrapper != null && wrapper.unit != null) {
146+
if (wrapper.unit.isInEurope()) {
147+
getGUI().showEuropePanel();
148+
} else {
149+
getGUI().changeView(wrapper.unit, false);
150+
if (wrapper.unit.getColony() != null) {
151+
getGUI().showColonyPanel(wrapper.unit.getColony(), wrapper.unit);
152+
}
153+
}
154+
}
155+
}
156+
157+
67158
/**
68159
* We need to wrap the Unit class in order to make the JList
69160
* support keystroke navigation. JList.getNextMatch uses the
@@ -84,12 +175,6 @@ public UnitWrapper(Unit unit) {
84175
.getLocationLabelFor(unit.getOwner()));
85176
}
86177

87-
88-
// Override Object
89-
90-
/**
91-
* {@inheritDoc}
92-
*/
93178
@Override
94179
public String toString() {
95180
return name;
@@ -102,16 +187,8 @@ public UnitCellRenderer() {
102187

103188
}
104189

105-
106-
/**
107-
* {@inheritDoc}
108-
*/
109-
@Override
110190
public Component getListCellRendererComponent(JList<? extends UnitWrapper> list,
111-
UnitWrapper value,
112-
int index,
113-
boolean isSelected,
114-
boolean cellHasFocus) {
191+
UnitWrapper value, int index, boolean isSelected, boolean cellHasFocus) {
115192
final JLabel imageLabel = new JLabel();
116193
imageLabel.setIcon(new ImageIcon(getImageLibrary().getSmallerUnitImage(value.unit)));
117194
imageLabel.setHorizontalAlignment(SwingConstants.CENTER);
@@ -158,89 +235,4 @@ private Dimension largestIconSize(JList<? extends UnitWrapper> list) {
158235
return new Dimension(largestWidth, largestHeight);
159236
}
160237
}
161-
162-
163-
/** The list of units to display. */
164-
private final JList<UnitWrapper> unitList;
165-
166-
167-
/**
168-
* The constructor to use.
169-
*
170-
* @param freeColClient The freecol client.
171-
* @param frame The owner frame.
172-
* @param units The unit list.
173-
*/
174-
public EndTurnDialog(FreeColClient freeColClient, JFrame frame, List<Unit> units) {
175-
super(freeColClient, frame);
176-
177-
final Player player = getMyPlayer();
178-
179-
JLabel header = Utility.localizedHeader(Messages.nameKey("endTurnDialog"),
180-
Utility.FONTSPEC_TITLE);
181-
JTextArea text = Utility.localizedTextArea(StringTemplate
182-
.template("endTurnDialog.areYouSure")
183-
.addAmount("%number%", units.size()));
184-
185-
DefaultListModel<UnitWrapper> model = new DefaultListModel<>();
186-
for (Unit unit : units) {
187-
model.addElement(new UnitWrapper(unit));
188-
}
189-
190-
this.unitList = new JList<>(model);
191-
this.unitList.setCellRenderer(new UnitCellRenderer());
192-
this.unitList.getInputMap().put(KeyStroke.getKeyStroke("ENTER"),
193-
"select");
194-
this.unitList.getActionMap().put("select", new AbstractAction() {
195-
@Override
196-
public void actionPerformed(ActionEvent ae) {
197-
selectUnit();
198-
}
199-
});
200-
this.unitList.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"),
201-
"quit");
202-
this.unitList.getActionMap().put("quit", new AbstractAction() {
203-
@Override
204-
public void actionPerformed(ActionEvent ae) {
205-
EndTurnDialog.this.setValue(options.get(1));
206-
}
207-
});
208-
this.unitList.addListSelectionListener(new ListSelectionListener() {
209-
@Override
210-
public void valueChanged(ListSelectionEvent e) {
211-
if (e.getValueIsAdjusting()) return;
212-
selectUnit();
213-
}
214-
});
215-
JScrollPane listScroller = new JScrollPane(this.unitList);
216-
217-
JPanel panel = new MigPanel(new MigLayout("wrap 1, fill",
218-
"[align center]"));
219-
panel.add(header);
220-
panel.add(text, "newline 20");
221-
panel.add(listScroller, "newline 10");
222-
panel.setSize(panel.getPreferredSize());
223-
224-
ImageIcon icon = new ImageIcon(
225-
getImageLibrary().getScaledNationImage(player.getNation()));
226-
initializeConfirmDialog(frame, false, panel, icon, "ok", "cancel");
227-
}
228-
229-
/**
230-
* Select the current unit in the list.
231-
*/
232-
private void selectUnit() {
233-
UnitWrapper wrapper = this.unitList.getSelectedValue();
234-
if (wrapper != null && wrapper.unit != null) {
235-
if (wrapper.unit.isInEurope()) {
236-
getGUI().showEuropePanel();
237-
} else {
238-
getGUI().changeView(wrapper.unit, false);
239-
if (wrapper.unit.getColony() != null) {
240-
getGUI().showColonyPanel(wrapper.unit.getColony(),
241-
wrapper.unit);
242-
}
243-
}
244-
}
245-
}
246238
}

0 commit comments

Comments
 (0)