コード例 #1
0
ファイル: MainPagePanel.java プロジェクト: jtrent238/HMCL
  // <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();
  }
コード例 #2
0
ファイル: MainPagePanel.java プロジェクト: jtrent238/HMCL
  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
コード例 #3
0
ファイル: MainPagePanel.java プロジェクト: jtrent238/HMCL
 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
コード例 #4
0
ファイル: MainPagePanel.java プロジェクト: jtrent238/HMCL
 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")));
   }
 }
コード例 #5
0
ファイル: MainPagePanel.java プロジェクト: jtrent238/HMCL
  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