Skip to content

Commit

Permalink
The loading savegame dialog has now been converted to an internal frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
stiangre committed Oct 13, 2024
1 parent 0fe3cc9 commit 3de1ec4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 205 deletions.
1 change: 1 addition & 0 deletions data/strings/FreeColMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3611,6 +3611,7 @@ infoPanel.moves=Moves:
informationPanel.display=Display %object%

# LoadingSavegameDialog
loadingSavegameDialog.ip=IP Address:
loadingSavegameDialog.port=Port:
loadingSavegameDialog.privateMultiplayer=Private multiplayer
loadingSavegameDialog.publicMultiplayer=Public multiplayer
Expand Down
93 changes: 85 additions & 8 deletions src/net/sf/freecol/client/gui/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;

import net.miginfocom.swing.MigLayout;
import net.sf.freecol.FreeCol;
import net.sf.freecol.client.FreeColClient;
import net.sf.freecol.client.gui.SwingGUI.PopupPosition;
import net.sf.freecol.client.gui.dialog.CaptureGoodsDialog;
Expand All @@ -51,10 +58,8 @@
import net.sf.freecol.client.gui.dialog.FirstContactDialog;
import net.sf.freecol.client.gui.dialog.FreeColDialog;
import net.sf.freecol.client.gui.dialog.FreeColDialog.DialogApi;
import net.sf.freecol.client.gui.option.OptionUI;
import net.sf.freecol.client.gui.dialog.GameOptionsDialog;
import net.sf.freecol.client.gui.dialog.LoadDialog;
import net.sf.freecol.client.gui.dialog.LoadingSavegameDialog;
import net.sf.freecol.client.gui.dialog.MapGeneratorOptionsDialog;
import net.sf.freecol.client.gui.dialog.MapSizeDialog;
import net.sf.freecol.client.gui.dialog.MonarchDialog;
Expand All @@ -69,6 +74,7 @@
import net.sf.freecol.client.gui.dialog.SelectGoodsAmountDialog;
import net.sf.freecol.client.gui.dialog.VictoryDialog;
import net.sf.freecol.client.gui.dialog.WarehouseDialog;
import net.sf.freecol.client.gui.option.OptionUI;
import net.sf.freecol.client.gui.panel.AboutPanel;
import net.sf.freecol.client.gui.panel.BuildQueuePanel;
import net.sf.freecol.client.gui.panel.ChatPanel;
Expand Down Expand Up @@ -853,12 +859,83 @@ public File showLoadDialog(File directory, FileFilter[] filters) {
* @return The {@code LoadingSavegameInfo} if the dialog was accepted,
* or null otherwise.
*/
public LoadingSavegameInfo showLoadingSavegameDialog(boolean pubSer,
boolean single) {
LoadingSavegameDialog dialog
= new LoadingSavegameDialog(this.freeColClient, getFrame());
return (this.canvas.showFreeColDialog(dialog, null)) ? dialog.getInfo()
: null;
public LoadingSavegameInfo showLoadingSavegameDialog(boolean pubSer, boolean single) {
final FreeColDialog<LoadingSavegameInfo> dialog = new FreeColDialog<LoadingSavegameInfo>(api -> {
final JPanel content = new JPanel(new MigLayout("fill, wrap 1"));

final JLabel header = Utility.localizedHeaderLabel("loadingSavegameDialog.name", JLabel.CENTER, Utility.FONTSPEC_SUBTITLE);
content.add(header, "growx");


final JLabel serverNameLabel = Utility.localizedLabel("loadingSavegameDialog.serverName");
content.add(serverNameLabel, "newline unrel, growx");

final JTextField serverNameField = new JTextField();
serverNameLabel.setLabelFor(serverNameField);
content.add(serverNameField, "growx");

final JLabel ipLabel = Utility.localizedLabel("loadingSavegameDialog.ip");
content.add(ipLabel, "growx");

final JComboBox<InetAddress> serverAddressBox = Utility.createServerInetAddressBox();
ipLabel.setLabelFor(serverAddressBox);
content.add(serverAddressBox, "growx");

final JLabel portLabel = Utility.localizedLabel("loadingSavegameDialog.port");
content.add(portLabel);
final JSpinner portField = new JSpinner(new SpinnerNumberModel(FreeCol.getServerPort(), 1, 65536, 1));
portLabel.setLabelFor(portField);
portField.setEditor(new JSpinner.NumberEditor(portField, "#"));
content.add(portField);

final ButtonGroup bg = new ButtonGroup();
final JRadioButton singlePlayer = new JRadioButton(Messages.message("loadingSavegameDialog.singlePlayer"));
bg.add(singlePlayer);
content.add(singlePlayer, "newline unrel");
final JRadioButton privateMultiplayer = new JRadioButton(Messages.message("loadingSavegameDialog.privateMultiplayer"));
bg.add(privateMultiplayer);
content.add(privateMultiplayer);
final JRadioButton publicMultiplayer = new JRadioButton(Messages.message("loadingSavegameDialog.publicMultiplayer"));
bg.add(publicMultiplayer);
content.add(publicMultiplayer);

serverAddressBox.addActionListener(event -> {
final InetAddress address = (InetAddress) serverAddressBox.getSelectedItem();
publicMultiplayer.setEnabled(!address.isLoopbackAddress());
});

final InetAddress address = (InetAddress) serverAddressBox.getSelectedItem();
publicMultiplayer.setEnabled(!address.isLoopbackAddress());
if (single) {
singlePlayer.setSelected(true);
} else if (pubSer && publicMultiplayer.isEnabled()) {
publicMultiplayer.setSelected(true);
} else {
privateMultiplayer.setSelected(true);
}

final JButton okButton = new FreeColButton(Messages.message("ok")).withButtonStyle(ButtonStyle.IMPORTANT);
final JButton cancelButton = new FreeColButton(Messages.message("cancel"));
okButton.addActionListener(ae -> {
final InetAddress inetAddress = singlePlayer.isSelected() ? null : (InetAddress) serverAddressBox.getSelectedItem();
final int port = singlePlayer.isSelected() ? -1 : ((Integer) portField.getValue());
final LoadingSavegameInfo result = new LoadingSavegameInfo(singlePlayer.isSelected(), inetAddress, port, serverNameField.getName(), publicMultiplayer.isSelected());

api.setValue(result);
});
cancelButton.addActionListener(ae -> {
api.setValue(null);
});

content.add(okButton, "newline unrel, split 2, tag ok");
content.add(cancelButton, "tag cancel");

api.setInitialFocusComponent(serverNameField);

return content;
});

return canvas.displayModalDialog(dialog);
}

/**
Expand Down
197 changes: 0 additions & 197 deletions src/net/sf/freecol/client/gui/dialog/LoadingSavegameDialog.java

This file was deleted.

0 comments on commit 3de1ec4

Please sign in to comment.