-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
205 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package entralinked.gui; | ||
|
||
import java.awt.GridBagLayout; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.JButton; | ||
import javax.swing.JDialog; | ||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JOptionPane; | ||
import javax.swing.JPanel; | ||
|
||
import com.formdev.flatlaf.extras.components.FlatTextField; | ||
|
||
import entralinked.Entralinked; | ||
import entralinked.model.user.User; | ||
import entralinked.model.user.UserManager; | ||
import entralinked.utility.SwingUtility; | ||
|
||
public class PidToolDialog { | ||
|
||
public static final Pattern WFC_ID_PATTERN = Pattern.compile("[0-9]{16}"); | ||
public static final Pattern FRIEND_CODE_PATTERN = Pattern.compile("[0-9]{12}"); | ||
|
||
public PidToolDialog(Entralinked entralinked, JFrame frame) { | ||
// Create dialog | ||
JDialog dialog = new JDialog(frame, "PID Tool"); | ||
|
||
// Create input fields | ||
FlatTextField wfcIdField = new FlatTextField(); | ||
wfcIdField.setPlaceholderText("XXXX-XXXX-XXXX-XXXX"); | ||
FlatTextField friendCodeField = new FlatTextField(); | ||
friendCodeField.setPlaceholderText("XXXX-XXXX-XXXX"); | ||
|
||
// Create logic | ||
JButton updateButton = new JButton("Update"); | ||
updateButton.addActionListener(event -> { | ||
if(!entralinked.isInitialized()) { | ||
JOptionPane.showMessageDialog(dialog, "Please wait for Entralinked to finish starting.", "Attention", JOptionPane.WARNING_MESSAGE); | ||
return; | ||
} | ||
|
||
String userId = wfcIdField.getText().replace("-", ""); | ||
String friendCode = friendCodeField.getText().replace("-", ""); | ||
|
||
// Make sure WFC ID is valid | ||
if(!WFC_ID_PATTERN.matcher(userId).matches()) { | ||
JOptionPane.showMessageDialog(dialog, "Please enter a valid Wi-Fi Connection ID.", "Attention", JOptionPane.WARNING_MESSAGE); | ||
return; | ||
} | ||
|
||
// Make sure Friend Code is valid | ||
if(!FRIEND_CODE_PATTERN.matcher(friendCode).matches()) { | ||
JOptionPane.showMessageDialog(dialog, "Please enter a valid Friend Code.", "Attention", JOptionPane.WARNING_MESSAGE); | ||
return; | ||
} | ||
|
||
UserManager userManager = entralinked.getUserManager(); | ||
User user = userManager.getUser(userId.substring(0, 13)); | ||
int profileId = (int)(Long.parseLong(friendCode) & 0x7FFFFFFF); | ||
|
||
// Make sure user exists | ||
if(user == null) { | ||
JOptionPane.showMessageDialog(dialog, "This Wi-Fi Connection ID does not exist.", "Attention", JOptionPane.WARNING_MESSAGE); | ||
return; | ||
} | ||
|
||
// Show warning if this user has multiple profiles | ||
if(user.getProfiles().size() > 1) { | ||
if(JOptionPane.showConfirmDialog(dialog, "Multiple profiles detected. Do you want to update all of them?\n" | ||
+ "This may cause error 60000 to occur on your other game cartridges.", | ||
"Attention", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { | ||
return; | ||
} | ||
} | ||
|
||
userManager.updateProfileIdForUser(user, profileId); | ||
JOptionPane.showMessageDialog(dialog, "Profile has been updated. Please restart your game and use Game Sync."); | ||
}); | ||
|
||
// Create content panel | ||
JPanel panel = new JPanel(new GridBagLayout()); | ||
String infoLabel = """ | ||
<html> | ||
Enter the Wi-Fi Connection ID found in the internet settings of your DS<br> | ||
as well as your Friend Code which you can view in-game using the Pal Pad.<br> | ||
Confirm that the input data is correct and press 'Update'<br> | ||
</html> | ||
"""; | ||
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); | ||
panel.add(new JLabel(infoLabel), SwingUtility.createConstraints(0, 0, 2, 1)); | ||
panel.add(new JLabel("Wi-Fi Connection ID"), SwingUtility.createConstraints(0, 1, 1, 1, 0, 1)); | ||
panel.add(wfcIdField, SwingUtility.createConstraints(1, 1)); | ||
panel.add(new JLabel("Friend Code"), SwingUtility.createConstraints(0, 2, 1, 1, 0, 1)); | ||
panel.add(friendCodeField, SwingUtility.createConstraints(1, 2)); | ||
panel.add(updateButton, SwingUtility.createConstraints(0, 3, 2, 1)); | ||
|
||
// Set dialog properties | ||
dialog.setResizable(false); | ||
dialog.add(panel); | ||
dialog.pack(); | ||
dialog.setLocationRelativeTo(frame); | ||
dialog.setVisible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package entralinked.utility; | ||
|
||
import java.awt.GridBagConstraints; | ||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.AbstractAction; | ||
import javax.swing.Action; | ||
import javax.swing.Icon; | ||
|
||
public class SwingUtility { | ||
|
||
@SuppressWarnings("serial") | ||
public static Action createAction(String name, Icon icon, Runnable handler) { | ||
AbstractAction action = new AbstractAction(name, icon) { | ||
@Override | ||
public void actionPerformed(ActionEvent event) { | ||
handler.run(); | ||
} | ||
}; | ||
|
||
if(icon != null) { | ||
action.putValue(Action.SHORT_DESCRIPTION, name); | ||
} | ||
|
||
return action; | ||
} | ||
|
||
public static Action createAction(String name, Runnable handler) { | ||
return createAction(name, null, handler); | ||
} | ||
|
||
public static GridBagConstraints createConstraints(int x, int y) { | ||
return createConstraints(x, y, 1, 1); | ||
} | ||
|
||
public static GridBagConstraints createConstraints(int x, int y, int width, int height) { | ||
return createConstraints(x, y, width, height, 1, 1); | ||
} | ||
|
||
public static GridBagConstraints createConstraints(int x, int y, int width, int height, double weightX, double weightY) { | ||
return createConstraints(x, y, width, height, weightX, weightY, 8, 8); | ||
} | ||
|
||
public static GridBagConstraints createConstraints(int x, int y, int width, int height, double weightX, double weightY, | ||
int paddingX, int paddingY) { | ||
GridBagConstraints constraints = new GridBagConstraints(); | ||
constraints.fill = GridBagConstraints.BOTH; | ||
constraints.gridx = x; | ||
constraints.gridy = y; | ||
constraints.gridwidth = width; | ||
constraints.gridheight = height; | ||
constraints.weightx = weightX; | ||
constraints.weighty = weightY; | ||
constraints.ipadx = paddingX; | ||
constraints.ipady = paddingY; | ||
return constraints; | ||
} | ||
} |