diff --git a/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java b/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java index 3199ec8..a511882 100644 --- a/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java +++ b/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java @@ -23,7 +23,9 @@ public class AccountSelectDialog extends JDialog { private final JList accountList; private final JButton loginButton = new JButton(SharedLocale.tr("login.login")); private final JButton cancelButton = new JButton(SharedLocale.tr("button.cancel")); - private final JButton addAccountButton = new JButton(SharedLocale.tr("accounts.addMojang")); + private final JButton addMojangButton = new JButton(SharedLocale.tr("accounts.addMojang")); + private final JButton addMicrosoftButton = new JButton(SharedLocale.tr("accounts.addMicrosoft")); + private final JButton removeSelected = new JButton(SharedLocale.tr("accounts.removeSelected")); private final LinedBoxPanel buttonsPanel = new LinedBoxPanel(true); private final Launcher launcher; @@ -38,13 +40,15 @@ public class AccountSelectDialog extends JDialog { setTitle(SharedLocale.tr("accounts.title")); initComponents(); setDefaultCloseOperation(DISPOSE_ON_CLOSE); - setMinimumSize(new Dimension(420, 50)); + setMinimumSize(new Dimension(450, 70)); setResizable(false); pack(); setLocationRelativeTo(owner); } private void initComponents() { + setLayout(new BorderLayout()); + accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); accountList.setLayoutOrientation(JList.HORIZONTAL_WRAP); accountList.setVisibleRowCount(0); @@ -52,7 +56,7 @@ public class AccountSelectDialog extends JDialog { JScrollPane accountPane = new JScrollPane(accountList); accountPane.setPreferredSize(new Dimension(250, 100)); - accountPane.setAlignmentX(LEFT_ALIGNMENT); + accountPane.setAlignmentX(CENTER_ALIGNMENT); loginButton.setFont(loginButton.getFont().deriveFont(Font.BOLD)); @@ -61,12 +65,21 @@ public class AccountSelectDialog extends JDialog { buttonsPanel.addElement(loginButton); buttonsPanel.addElement(cancelButton); + LinedBoxPanel loginButtonsRow = new LinedBoxPanel(true); + loginButtonsRow.add(addMojangButton); + loginButtonsRow.add(addMicrosoftButton); + loginButtonsRow.addGlue(); + loginButtonsRow.add(removeSelected); + loginButtonsRow.setAlignmentX(CENTER_ALIGNMENT); + loginButtonsRow.setBorder(null); + JPanel listPane = new JPanel(); - listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); + listPane.setLayout(new BoxLayout(listPane, BoxLayout.Y_AXIS)); listPane.add(accountPane); listPane.add(Box.createVerticalStrut(5)); - listPane.add(addAccountButton); + listPane.add(loginButtonsRow); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + listPane.setAlignmentX(CENTER_ALIGNMENT); add(listPane, BorderLayout.CENTER); add(buttonsPanel, BorderLayout.SOUTH); @@ -74,7 +87,7 @@ public class AccountSelectDialog extends JDialog { loginButton.addActionListener(ev -> attemptLogin(accountList.getSelectedValue())); cancelButton.addActionListener(ev -> dispose()); - addAccountButton.addActionListener(ev -> { + addMojangButton.addActionListener(ev -> { Session newSession = LoginDialog.showLoginRequest(this, launcher); if (newSession != null) { @@ -82,6 +95,18 @@ public class AccountSelectDialog extends JDialog { setResult(newSession); } }); + + addMicrosoftButton.addActionListener(ev -> { + // TODO + }); + + removeSelected.addActionListener(ev -> { + if (accountList.getSelectedValue() != null) { + launcher.getAccounts().remove(accountList.getSelectedValue()); + } + }); + + accountList.setSelectedIndex(0); } @Override @@ -96,9 +121,10 @@ public class AccountSelectDialog extends JDialog { if (dialog.selected != null) { launcher.getAccounts().update(dialog.selected.toSavedSession()); - Persistence.commitAndForget(launcher.getAccounts()); } + Persistence.commitAndForget(launcher.getAccounts()); + return dialog.selected; } @@ -108,6 +134,8 @@ public class AccountSelectDialog extends JDialog { } private void attemptLogin(SavedSession session) { + if (session == null) return; + LoginService loginService = launcher.getLoginService(session.getType()); RestoreSessionCallable callable = new RestoreSessionCallable(loginService, session); diff --git a/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties b/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties index 2554685..e673794 100644 --- a/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties +++ b/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties @@ -89,11 +89,10 @@ launcher.updatePendingHint=(pending update) accounts.title=Select the account to play with accounts.refreshingStatus=Refreshing login session... -accounts.addMojang=Log in via Mojang -accounts.addMicrosoft=Log in via Microsoft +accounts.addMojang=Add Mojang account +accounts.addMicrosoft=Add Microsoft account +accounts.removeSelected=Forget selected account -login.rememberId=Remember my account in the list -login.rememberPassword=Remember my password login.login=Login... login.recoverAccount=Forgot your login? login.playOffline=Play offline