From 3effa7d674e8c69e0b59ba4fed1fbaf08b71c6ef Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Tue, 9 Feb 2021 01:36:04 +0000 Subject: [PATCH] Re-add offline session button & alter play button --- .../launcher/dialog/AccountSelectDialog.java | 17 +++++++++++++---- .../skcraft/launcher/lang/Launcher.properties | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) 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 8a07a91..d7d4da0 100644 --- a/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java +++ b/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java @@ -8,6 +8,7 @@ import com.skcraft.concurrency.ObservableFuture; import com.skcraft.concurrency.ProgressObservable; import com.skcraft.launcher.Launcher; import com.skcraft.launcher.auth.LoginService; +import com.skcraft.launcher.auth.OfflineSession; import com.skcraft.launcher.auth.SavedSession; import com.skcraft.launcher.auth.Session; import com.skcraft.launcher.persistence.Persistence; @@ -23,11 +24,12 @@ import java.util.concurrent.Callable; public class AccountSelectDialog extends JDialog { private final JList accountList; - private final JButton loginButton = new JButton(SharedLocale.tr("login.login")); + private final JButton loginButton = new JButton(SharedLocale.tr("accounts.play")); private final JButton cancelButton = new JButton(SharedLocale.tr("button.cancel")); 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 JButton offlineButton = new JButton(SharedLocale.tr("login.playOffline")); private final LinedBoxPanel buttonsPanel = new LinedBoxPanel(true); private final Launcher launcher; @@ -42,7 +44,7 @@ public class AccountSelectDialog extends JDialog { setTitle(SharedLocale.tr("accounts.title")); initComponents(); setDefaultCloseOperation(DISPOSE_ON_CLOSE); - setMinimumSize(new Dimension(450, 70)); + setMinimumSize(new Dimension(350, 170)); setResizable(false); pack(); setLocationRelativeTo(owner); @@ -52,7 +54,7 @@ public class AccountSelectDialog extends JDialog { setLayout(new BorderLayout()); accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - accountList.setLayoutOrientation(JList.HORIZONTAL_WRAP); + accountList.setLayoutOrientation(JList.VERTICAL); accountList.setVisibleRowCount(0); accountList.setCellRenderer(new AccountRenderer()); @@ -61,8 +63,12 @@ public class AccountSelectDialog extends JDialog { accountPane.setAlignmentX(CENTER_ALIGNMENT); loginButton.setFont(loginButton.getFont().deriveFont(Font.BOLD)); + loginButton.setMargin(new Insets(0, 10, 0, 10)); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(26, 13, 13, 13)); + if (launcher.getConfig().isOfflineEnabled()) { + buttonsPanel.addElement(offlineButton); + } buttonsPanel.addGlue(); buttonsPanel.addElement(loginButton); buttonsPanel.addElement(cancelButton); @@ -100,6 +106,9 @@ public class AccountSelectDialog extends JDialog { addMicrosoftButton.addActionListener(ev -> attemptMicrosoftLogin()); + offlineButton.addActionListener(ev -> + setResult(new OfflineSession(launcher.getProperties().getProperty("offlinePlayerName")))); + removeSelected.addActionListener(ev -> { if (accountList.getSelectedValue() != null) { launcher.getAccounts().remove(accountList.getSelectedValue()); @@ -119,7 +128,7 @@ public class AccountSelectDialog extends JDialog { AccountSelectDialog dialog = new AccountSelectDialog(owner, launcher); dialog.setVisible(true); - if (dialog.selected != null) { + if (dialog.selected != null && dialog.selected.isOnline()) { launcher.getAccounts().update(dialog.selected.toSavedSession()); } 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 c58e082..b729804 100644 --- a/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties +++ b/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties @@ -88,6 +88,7 @@ launcher.requiresUpdateHint=(requires update) launcher.updatePendingHint=(pending update) accounts.title=Select the account to play with +accounts.play=Play! accounts.refreshingStatus=Refreshing login session... accounts.addMojang=Add Mojang account accounts.addMicrosoft=Add Microsoft account