private void txtPlayerNameKeyPressed( java.awt.event.KeyEvent evt) { // GEN-FIRST:event_txtPlayerNameKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { Settings.getInstance().setUsername(txtPlayerName.getText()); int index = cboLoginMode.getSelectedIndex(); if (index < 0) return; IAuthenticator l = IAuthenticator.LOGINS.get(index); if (l.isHidePasswordBox()) btnRunActionPerformed(); else if (!l.isLoggedIn()) txtPassword.requestFocus(); } } // GEN-LAST:event_txtPlayerNameKeyPressed
// <editor-fold defaultstate="collapsed" desc="Game Launch"> void genLaunchCode(final Consumer<GameLauncher> listener) { if (isLaunching) return; isLaunching = true; HMCLog.log("Start generating launching command..."); File file = getCurrentProfile().getCanonicalGameDirFile(); if (!file.exists()) { HMCLog.warn("The minecraft path is wrong, please check it yourself."); MessageBox.Show(C.i18n("minecraft.wrong_path")); return; } final String name = (String) cboProfiles.getSelectedItem(); if (StrUtils.isBlank(name) || getCurrentProfile().getSelectedMinecraftVersion() == null) { HMCLog.warn("There's no selected version, rechoose a version."); MessageBox.Show(C.i18n("minecraft.no_selected_version")); return; } final int index = cboLoginMode.getSelectedIndex(); if (index < 0 || index >= IAuthenticator.LOGINS.size()) { HMCLog.warn("There's no login method."); MessageBox.Show(C.i18n("login.methods.no_method")); return; } final IAuthenticator l = IAuthenticator.LOGINS.get(index); final LoginInfo li = new LoginInfo( Settings.getInstance().getUsername(), l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword())); Thread t = new Thread() { @Override public void run() { Thread.currentThread().setName("Game Launcher"); DefaultGameLauncher gl = new DefaultGameLauncher( getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource()); gl.failEvent.register( (sender, s) -> { if (s != null) MessageBox.Show(s); MainFrame.instance.closeMessage(); isLaunching = false; return true; }); gl.successEvent.register( (sender, s) -> { isLaunching = false; return true; }); listener.accept(gl); gl.makeLaunchCommand(); } }; t.start(); }
public void onShow(boolean showLeft) { if (showLeft) SwingUtilities.invokeLater( () -> MainFrame.instance.showMessage(C.i18n("ui.message.first_load"))); if (cboLoginMode.getSelectedIndex() >= 0 && cboLoginMode.getSelectedIndex() < cboLoginMode.getItemCount()) { IAuthenticator l = IAuthenticator.LOGINS.get(cboLoginMode.getSelectedIndex()); if (!l.isHidePasswordBox() && !l.isLoggedIn()) SwingUtilities.invokeLater( () -> MainFrame.instance.showMessage(C.i18n("ui.message.enter_password"))); } }
private void cboLoginModeItemStateChanged( java.awt.event.ItemEvent evt) { // GEN-FIRST:event_cboLoginModeItemStateChanged if (preaparingAuth) return; int index = cboLoginMode.getSelectedIndex(); if (index < 0) return; IAuthenticator l = IAuthenticator.LOGINS.get(index); if (l.isHidePasswordBox()) { pnlPassword.setVisible(false); lblUserName.setText(C.i18n("login.username")); } else { pnlPassword.setVisible(true); lblUserName.setText(C.i18n("login.account")); } CardLayout cl = (CardLayout) pnlPassword.getLayout(); if (l.isLoggedIn()) cl.last(pnlPassword); else cl.first(pnlPassword); String username = Settings.getInstance().getUsername(); if (StrUtils.isNotBlank(username)) txtPlayerName.setText(username); Settings.getInstance().setLoginType(index); } // GEN-LAST:event_cboLoginModeItemStateChanged