private void btnLogoutActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnLogoutActionPerformed if (preaparingAuth) return; int index = cboLoginMode.getSelectedIndex(); IAuthenticator l = IAuthenticator.LOGINS.get(index); CardLayout cl = (CardLayout) pnlPassword.getLayout(); if (l.isLoggedIn()) l.logout(); cl.first(pnlPassword); } // GEN-LAST:event_btnLogoutActionPerformed
// <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(); }
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
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"))); } }
// <editor-fold defaultstate="collapsed" desc="Loads"> private void prepareAuths() { preaparingAuth = true; cboLoginMode.removeAllItems(); for (IAuthenticator str : IAuthenticator.LOGINS) try { cboLoginMode.addItem(str.getName()); } catch (Exception ex) { HMCLog.warn("Failed to get login name", ex); } int loginType = Settings.getInstance().getLoginType(); if (0 <= loginType && loginType < cboLoginMode.getItemCount()) { preaparingAuth = false; cboLoginMode.setSelectedIndex(loginType); cboLoginModeItemStateChanged(null); } }
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