mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-02-23 17:19:44 +08:00
moved some buttons!
This commit is contained in:
parent
ed876fa607
commit
cd972f5945
@ -63,6 +63,7 @@ public final class Config {
|
||||
|
||||
public transient final EventHandler<Theme> themeChangedEvent = new EventHandler<>(this);
|
||||
public transient final EventHandler<DownloadType> downloadTypeChangedEvent = new EventHandler<>(this);
|
||||
public transient final EventHandler<IAuthenticator> authChangedEvent = new EventHandler<>(this);
|
||||
|
||||
public Theme getTheme() {
|
||||
return Theme.values()[theme];
|
||||
@ -133,7 +134,10 @@ public final class Config {
|
||||
}
|
||||
|
||||
public void setLoginType(int logintype) {
|
||||
if (logintype < 0 || logintype >= IAuthenticator.LOGINS.size())
|
||||
return;
|
||||
this.logintype = logintype;
|
||||
authChangedEvent.execute(IAuthenticator.LOGINS.get(logintype));
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,8 @@ public class DefaultMinecraftService extends IMinecraftService {
|
||||
this.p = p;
|
||||
this.provider = new HMCLGameProvider(this);
|
||||
provider.initializeMiencraft();
|
||||
provider.onRefreshingVersions.register((sender, x) -> {
|
||||
versionSettings.clear();
|
||||
return true;
|
||||
});
|
||||
provider.onLoadedVersion.register((sender, id) -> {
|
||||
provider.onRefreshingVersions.register(versionSettings::clear);
|
||||
provider.onLoadedVersion.register(id -> {
|
||||
VersionSetting vs = new VersionSetting();
|
||||
File f = new File(provider.versionRoot(id), "hmclversion.cfg");
|
||||
if (f.exists()) {
|
||||
@ -66,7 +63,6 @@ public class DefaultMinecraftService extends IMinecraftService {
|
||||
}
|
||||
vs.id = id;
|
||||
versionSettings.put(id, vs);
|
||||
return true;
|
||||
});
|
||||
this.mms = new MinecraftModService(this);
|
||||
this.mds = new MinecraftDownloadService(this);
|
||||
|
@ -26,6 +26,7 @@ import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.YggdrasilAuthenticator;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
|
||||
import org.jackhuang.hellominecraft.launcher.ui.MainFrame;
|
||||
import org.jackhuang.hellominecraft.util.EventHandler;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
|
||||
/**
|
||||
@ -75,8 +76,11 @@ public class DefaultPlugin implements IPlugin {
|
||||
public void onProcessingLoginResult(UserProfileProvider result) {
|
||||
}
|
||||
|
||||
public transient final EventHandler<LaunchOptions> onProcessingLaunchOptionsEvent = new EventHandler<>(this);
|
||||
|
||||
@Override
|
||||
public void onProcessingLaunchOptions(LaunchOptions p) {
|
||||
onProcessingLaunchOptionsEvent.execute(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.launcher.setting;
|
||||
|
||||
import java.io.File;
|
||||
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.DefaultGameLauncher;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class HMCLGameLauncher {
|
||||
|
||||
Profile profile;
|
||||
boolean isLaunching = false;
|
||||
|
||||
public HMCLGameLauncher(Profile p) {
|
||||
this.profile = p;
|
||||
}
|
||||
|
||||
public void genLaunchCode(final Consumer<GameLauncher> listener, final Consumer<String> failed, String passwordIfNeeded) {
|
||||
if (isLaunching || profile == null)
|
||||
return;
|
||||
isLaunching = true;
|
||||
HMCLog.log("Start generating launching command...");
|
||||
File file = profile.getCanonicalGameDirFile();
|
||||
if (!file.exists()) {
|
||||
failed.accept(C.i18n("minecraft.wrong_path"));
|
||||
isLaunching = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.getSelectedVersion() == null) {
|
||||
failed.accept(C.i18n("minecraft.no_selected_version"));
|
||||
isLaunching = false;
|
||||
return;
|
||||
}
|
||||
|
||||
final IAuthenticator l = IAuthenticator.LOGINS.get(Settings.getInstance().getLoginType());
|
||||
final LoginInfo li = new LoginInfo(l.getUsername(), l.isLoggedIn() || !l.hasPassword() ? null : passwordIfNeeded);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Game Launcher");
|
||||
try {
|
||||
LaunchOptions options = profile.getSelectedVersionSetting().createLaunchOptions(profile.getCanonicalGameDirFile());
|
||||
PluginManager.NOW_PLUGIN.onProcessingLaunchOptions(options);
|
||||
DefaultGameLauncher gl = new DefaultGameLauncher(options, profile.service(), li, l);
|
||||
gl.setTag(profile.getSelectedVersionSetting().getLauncherVisibility());
|
||||
gl.successEvent.register(() -> isLaunching = false);
|
||||
listener.accept(gl);
|
||||
gl.makeLaunchCommand();
|
||||
} catch (GameException e) {
|
||||
failed.accept(C.i18n("launch.failed") + ", " + e.getMessage());
|
||||
isLaunching = false;
|
||||
} catch (AuthenticationException e) {
|
||||
failed.accept(C.i18n("login.failed") + ", " + e.getMessage());
|
||||
isLaunching = false;
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
}
|
@ -35,6 +35,7 @@ public final class Profile {
|
||||
private String name, selectedMinecraftVersion = "", gameDir;
|
||||
|
||||
private transient IMinecraftService service;
|
||||
private transient HMCLGameLauncher launcher = new HMCLGameLauncher(this);
|
||||
public transient final EventHandler<String> propertyChanged = new EventHandler<>(this);
|
||||
|
||||
public Profile() {
|
||||
@ -60,6 +61,10 @@ public final class Profile {
|
||||
return service;
|
||||
}
|
||||
|
||||
public HMCLGameLauncher launcher() {
|
||||
return launcher;
|
||||
}
|
||||
|
||||
private transient final VersionSetting defaultVersionSetting = new VersionSetting();
|
||||
|
||||
public VersionSetting getSelectedVersionSetting() {
|
||||
|
@ -53,20 +53,14 @@ public final class Settings {
|
||||
|
||||
static {
|
||||
SETTINGS = initSettings();
|
||||
SETTINGS.downloadTypeChangedEvent.register((sender, t) -> {
|
||||
DownloadType.setSuggestedDownloadType(t);
|
||||
return true;
|
||||
});
|
||||
SETTINGS.downloadTypeChangedEvent.register(DownloadType::setSuggestedDownloadType);
|
||||
DownloadType.setSuggestedDownloadType(SETTINGS.getDownloadSource());
|
||||
if (!getProfiles().containsKey(DEFAULT_PROFILE))
|
||||
getProfiles().put(DEFAULT_PROFILE, new Profile());
|
||||
|
||||
for (Profile e : getProfiles().values()) {
|
||||
e.checkFormat();
|
||||
e.propertyChanged.register((sender, t) -> {
|
||||
save();
|
||||
return true;
|
||||
});
|
||||
e.propertyChanged.register(Settings::save);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,28 @@
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="pnlTop" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="tabVersionEdit" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="tabVersionEdit" alignment="1" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="btnMakeLaunchScript" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnShowLog" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnTestGame" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnIncludeMinecraft" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="916" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
@ -37,6 +54,19 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="tabVersionEdit" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnTestGame" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnShowLog" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnMakeLaunchScript" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace pref="402" max="32767" attributes="0"/>
|
||||
<Component id="btnIncludeMinecraft" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@ -165,7 +195,7 @@
|
||||
<Component id="lblDimension" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtWidth" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="84" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="54" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnDownloadAllAssets" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnCleanGame" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
@ -421,7 +451,7 @@
|
||||
<Component id="lblServerIP" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="txtServerIP" min="-2" pref="26" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="76" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="46" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="chkDebug" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="chkNoJVMArgs" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
@ -586,7 +616,7 @@
|
||||
<Component id="btnRemoveMod" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jScrollPane1" pref="284" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" pref="254" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblModInfo" min="-2" max="-2" attributes="0"/>
|
||||
@ -907,5 +937,43 @@
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="btnTestGame">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="测试游戏"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTestGameActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnShowLog">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="mainwindow.show_log" replaceFormat="C.i18n("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnShowLogActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnMakeLaunchScript">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="mainwindow.make_launch_script" replaceFormat="C.i18n("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMakeLaunchScriptActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnIncludeMinecraft">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="setupwindow.include_minecraft" replaceFormat="C.i18n("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnIncludeMinecraftActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -59,8 +59,10 @@ import org.jackhuang.hellominecraft.util.OverridableSwingWorker;
|
||||
import org.jackhuang.hellominecraft.util.version.MinecraftVersionRequest;
|
||||
import org.jackhuang.hellominecraft.util.system.OS;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.Java;
|
||||
import org.jackhuang.hellominecraft.util.ui.LogWindow;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -291,6 +293,10 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
btnNewProfile = new javax.swing.JButton();
|
||||
btnRemoveProfile = new javax.swing.JButton();
|
||||
btnExplore = new javax.swing.JButton();
|
||||
btnTestGame = new javax.swing.JButton();
|
||||
btnShowLog = new javax.swing.JButton();
|
||||
btnMakeLaunchScript = new javax.swing.JButton();
|
||||
btnIncludeMinecraft = new javax.swing.JButton();
|
||||
|
||||
setBackground(new java.awt.Color(255, 255, 255));
|
||||
setOpaque(false);
|
||||
@ -481,7 +487,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
.addComponent(lblDimensionX, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblDimension)
|
||||
.addComponent(txtWidth, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
|
||||
.addGroup(pnlSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnDownloadAllAssets)
|
||||
.addComponent(btnCleanGame))
|
||||
@ -607,7 +613,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
.addComponent(lblServerIP)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(txtServerIP, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
|
||||
.addGroup(pnlAdvancedSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(chkDebug)
|
||||
.addComponent(chkNoJVMArgs)
|
||||
@ -673,7 +679,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnRemoveMod)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE))
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(lblModInfo))
|
||||
);
|
||||
@ -841,15 +847,56 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
btnTestGame.setText("测试游戏");
|
||||
btnTestGame.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnTestGameActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnShowLog.setText(C.i18n("mainwindow.show_log")); // NOI18N
|
||||
btnShowLog.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnShowLogActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnMakeLaunchScript.setText(C.i18n("mainwindow.make_launch_script")); // NOI18N
|
||||
btnMakeLaunchScript.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnMakeLaunchScriptActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnIncludeMinecraft.setText(C.i18n("setupwindow.include_minecraft")); // NOI18N
|
||||
btnIncludeMinecraft.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnIncludeMinecraftActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(pnlTop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(tabVersionEdit)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(tabVersionEdit)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(btnMakeLaunchScript)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnShowLog)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnTestGame)))
|
||||
.addContainerGap())
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(btnIncludeMinecraft)
|
||||
.addContainerGap(916, Short.MAX_VALUE)))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
@ -857,7 +904,17 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
.addComponent(pnlTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(tabVersionEdit)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnTestGame)
|
||||
.addComponent(btnShowLog)
|
||||
.addComponent(btnMakeLaunchScript))
|
||||
.addContainerGap())
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap(402, Short.MAX_VALUE)
|
||||
.addComponent(btnIncludeMinecraft)
|
||||
.addContainerGap()))
|
||||
);
|
||||
|
||||
((NewTabPane)tabVersionEdit).initializing = false;
|
||||
@ -1063,6 +1120,35 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
getProfile().service().version().cleanFolder();
|
||||
}//GEN-LAST:event_btnCleanGameActionPerformed
|
||||
|
||||
private void btnTestGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestGameActionPerformed
|
||||
LogWindow.INSTANCE.setVisible(true);
|
||||
MainFrame.INSTANCE.mainPanel.runGame();
|
||||
}//GEN-LAST:event_btnTestGameActionPerformed
|
||||
|
||||
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
|
||||
LogWindow.INSTANCE.setVisible(true);
|
||||
}//GEN-LAST:event_btnShowLogActionPerformed
|
||||
|
||||
private void btnMakeLaunchScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeLaunchScriptActionPerformed
|
||||
MainFrame.INSTANCE.mainPanel.makeLaunchScript();
|
||||
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
|
||||
|
||||
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
|
||||
JFileChooser fc = new JFileChooser(IOUtils.currentDir());
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
File newGameDir = fc.getSelectedFile();
|
||||
String name = JOptionPane.showInputDialog(C.i18n("setupwindow.give_a_name"));
|
||||
if (StrUtils.isBlank(name)) {
|
||||
MessageBox.Show(C.i18n("setupwindow.no_empty_name"));
|
||||
return;
|
||||
}
|
||||
Settings.trySetProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
|
||||
MessageBox.Show(C.i18n("setupwindow.find_in_configurations"));
|
||||
loadProfiles();
|
||||
}
|
||||
}//GEN-LAST:event_btnIncludeMinecraftActionPerformed
|
||||
|
||||
// </editor-fold>
|
||||
// <editor-fold defaultstate="collapsed" desc="Load">
|
||||
private void loadProfiles() {
|
||||
@ -1259,11 +1345,15 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
private javax.swing.JButton btnCleanGame;
|
||||
private javax.swing.JButton btnDownloadAllAssets;
|
||||
private javax.swing.JButton btnExplore;
|
||||
private javax.swing.JButton btnIncludeMinecraft;
|
||||
private javax.swing.JButton btnMakeLaunchScript;
|
||||
private javax.swing.JButton btnModify;
|
||||
private javax.swing.JButton btnNewProfile;
|
||||
private javax.swing.JButton btnRefreshVersions;
|
||||
private javax.swing.JButton btnRemoveMod;
|
||||
private javax.swing.JButton btnRemoveProfile;
|
||||
private javax.swing.JButton btnShowLog;
|
||||
private javax.swing.JButton btnTestGame;
|
||||
private javax.swing.JComboBox cboJava;
|
||||
private javax.swing.JComboBox cboLauncherVisibility;
|
||||
private javax.swing.JComboBox cboProfiles;
|
||||
|
@ -149,10 +149,7 @@ public final class MainFrame extends DraggableFrame {
|
||||
}
|
||||
((JPanel) getContentPane()).setOpaque(true);
|
||||
|
||||
Settings.getInstance().themeChangedEvent.register((sender, t) -> {
|
||||
MainFrame.INSTANCE.reloadColor(t);
|
||||
return true;
|
||||
});
|
||||
Settings.getInstance().themeChangedEvent.register(this::reloadColor);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
|
@ -45,7 +45,7 @@
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="cboProfiles" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="cboProfiles" alignment="0" pref="128" max="32767" attributes="0"/>
|
||||
<Component id="cboVersions" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
@ -60,9 +60,6 @@
|
||||
<Component id="txtPlayerName" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="btnMakeLaunchScript" alignment="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="btnShowLog" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="btnIncludeMinecraft" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="btnExportModpack" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="btnImportModpack" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
@ -95,17 +92,11 @@
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="pnlPassword" min="-2" pref="26" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="146" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="248" max="32767" attributes="0"/>
|
||||
<Component id="btnImportModpack" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnExportModpack" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnIncludeMinecraft" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="btnMakeLaunchScript" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnShowLog" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@ -263,36 +254,6 @@
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="btnMakeLaunchScript">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="mainwindow.make_launch_script" replaceFormat="C.i18n("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMakeLaunchScriptActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnShowLog">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="mainwindow.show_log" replaceFormat="C.i18n("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnShowLogActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnIncludeMinecraft">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="setupwindow.include_minecraft" replaceFormat="C.i18n("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnIncludeMinecraftActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnImportModpack">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
|
@ -29,13 +29,9 @@ import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.DefaultGameLauncher;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
|
||||
import org.jackhuang.hellominecraft.launcher.setting.Profile;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
@ -43,14 +39,11 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
|
||||
import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility;
|
||||
import org.jackhuang.hellominecraft.launcher.setting.Settings;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
|
||||
import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager;
|
||||
import org.jackhuang.hellominecraft.launcher.ui.modpack.ModpackWizard;
|
||||
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
|
||||
import org.jackhuang.hellominecraft.util.Event;
|
||||
import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.JavaProcessMonitor;
|
||||
@ -62,7 +55,7 @@ import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer;
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
public class MainPagePanel extends AnimatedPanel {
|
||||
|
||||
/**
|
||||
* Creates new form MainPagePanel
|
||||
@ -94,6 +87,8 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
pnlMore.setOpaque(true);
|
||||
|
||||
prepareAuths();
|
||||
|
||||
Settings.getInstance().authChangedEvent.register(onAuthChanged);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,9 +115,6 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
txtPassword = new javax.swing.JPasswordField();
|
||||
jPanel3 = new javax.swing.JPanel();
|
||||
btnLogout = new javax.swing.JButton();
|
||||
btnMakeLaunchScript = new javax.swing.JButton();
|
||||
btnShowLog = new javax.swing.JButton();
|
||||
btnIncludeMinecraft = new javax.swing.JButton();
|
||||
btnImportModpack = new javax.swing.JButton();
|
||||
btnExportModpack = new javax.swing.JButton();
|
||||
|
||||
@ -232,27 +224,6 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
|
||||
pnlPassword.add(jPanel3, "card3");
|
||||
|
||||
btnMakeLaunchScript.setText(C.i18n("mainwindow.make_launch_script")); // NOI18N
|
||||
btnMakeLaunchScript.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnMakeLaunchScriptActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnShowLog.setText(C.i18n("mainwindow.show_log")); // NOI18N
|
||||
btnShowLog.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnShowLogActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnIncludeMinecraft.setText(C.i18n("setupwindow.include_minecraft")); // NOI18N
|
||||
btnIncludeMinecraft.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnIncludeMinecraftActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnImportModpack.setText(C.i18n("modpack.install.task")); // NOI18N
|
||||
btnImportModpack.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
@ -281,7 +252,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
.addComponent(lblVersion, javax.swing.GroupLayout.Alignment.TRAILING))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(cboProfiles, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(cboProfiles, 0, 128, Short.MAX_VALUE)
|
||||
.addComponent(cboVersions, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
|
||||
.addGroup(pnlMoreLayout.createSequentialGroup()
|
||||
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
@ -291,9 +262,6 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(cboLoginMode, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtPlayerName)))
|
||||
.addComponent(btnMakeLaunchScript, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
||||
.addComponent(btnShowLog, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnIncludeMinecraft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnExportModpack, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnImportModpack, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
@ -319,16 +287,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
.addComponent(txtPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pnlPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 146, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 248, Short.MAX_VALUE)
|
||||
.addComponent(btnImportModpack)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnExportModpack)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnIncludeMinecraft)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnMakeLaunchScript)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnShowLog)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@ -350,7 +312,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
return;
|
||||
if (preparingAuth)
|
||||
return;
|
||||
loginModeChanged();
|
||||
Settings.getInstance().setLoginType(cboLoginMode.getSelectedIndex());
|
||||
}//GEN-LAST:event_cboLoginModeItemStateChanged
|
||||
|
||||
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
|
||||
@ -367,12 +329,6 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
getProfile().setSelectedMinecraftVersion(mcv);
|
||||
}//GEN-LAST:event_cboVersionsItemStateChanged
|
||||
|
||||
@Override
|
||||
public boolean call(Object sender, String mcv) {
|
||||
cboVersions.setToolTipText(mcv);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void txtPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPasswordFocusGained
|
||||
MainFrame.INSTANCE.closeMessage();
|
||||
}//GEN-LAST:event_txtPasswordFocusGained
|
||||
@ -409,30 +365,6 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
runGame();
|
||||
}//GEN-LAST:event_txtPasswordKeyPressed
|
||||
|
||||
private void btnMakeLaunchScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeLaunchScriptActionPerformed
|
||||
MainFrame.INSTANCE.mainPanel.makeLaunchScript();
|
||||
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
|
||||
|
||||
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
|
||||
LogWindow.INSTANCE.setVisible(true);
|
||||
}//GEN-LAST:event_btnShowLogActionPerformed
|
||||
|
||||
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
|
||||
JFileChooser fc = new JFileChooser(IOUtils.currentDir());
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
File newGameDir = fc.getSelectedFile();
|
||||
String name = JOptionPane.showInputDialog(C.i18n("setupwindow.give_a_name"));
|
||||
if (StrUtils.isBlank(name)) {
|
||||
MessageBox.Show(C.i18n("setupwindow.no_empty_name"));
|
||||
return;
|
||||
}
|
||||
Settings.trySetProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
|
||||
MessageBox.Show(C.i18n("setupwindow.find_in_configurations"));
|
||||
refreshMinecrafts(name);
|
||||
}
|
||||
}//GEN-LAST:event_btnIncludeMinecraftActionPerformed
|
||||
|
||||
private void btnImportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportModpackActionPerformed
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
@ -453,60 +385,6 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
WizardDisplayer.showWizard(new ModpackWizard(getProfile().service()).createWizard());
|
||||
}//GEN-LAST:event_btnExportModpackActionPerformed
|
||||
|
||||
boolean isLaunching = false;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Game Launch">
|
||||
void genLaunchCode(final Consumer<GameLauncher> listener) {
|
||||
if (isLaunching || getProfile() == null)
|
||||
return;
|
||||
isLaunching = true;
|
||||
HMCLog.log("Start generating launching command...");
|
||||
File file = getProfile().getCanonicalGameDirFile();
|
||||
if (!file.exists()) {
|
||||
HMCLog.warn("The minecraft path is wrong, please check it yourself.");
|
||||
MessageBox.ShowLocalized("minecraft.wrong_path");
|
||||
return;
|
||||
}
|
||||
final String name = (String) cboProfiles.getSelectedItem();
|
||||
if (StrUtils.isBlank(name) || getProfile().getSelectedVersion() == null) {
|
||||
HMCLog.warn("There's no selected version, rechoose a version.");
|
||||
MessageBox.ShowLocalized("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.ShowLocalized("login.methods.no_method");
|
||||
return;
|
||||
}
|
||||
final IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
final LoginInfo li = new LoginInfo(l.getUsername(), l.isLoggedIn() || !l.hasPassword() ? null : new String(txtPassword.getPassword()));
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Game Launcher");
|
||||
try {
|
||||
LaunchOptions options = getProfile().getSelectedVersionSetting().createLaunchOptions(getProfile().getCanonicalGameDirFile());
|
||||
PluginManager.NOW_PLUGIN.onProcessingLaunchOptions(options);
|
||||
DefaultGameLauncher gl = new DefaultGameLauncher(options, getProfile().service(), li, l);
|
||||
gl.setTag(getProfile().getSelectedVersionSetting().getLauncherVisibility());
|
||||
gl.successEvent.register((sender, s) -> {
|
||||
isLaunching = false;
|
||||
return true;
|
||||
});
|
||||
listener.accept(gl);
|
||||
gl.makeLaunchCommand();
|
||||
} catch (GameException e) {
|
||||
failed(C.i18n("launch.failed") + ", " + e.getMessage());
|
||||
} catch (AuthenticationException e) {
|
||||
failed(C.i18n("login.failed") + ", " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Loads">
|
||||
private void prepareAuths() {
|
||||
preparingAuth = true;
|
||||
@ -517,36 +395,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
int loginType = Settings.getInstance().getLoginType();
|
||||
if (0 <= loginType && loginType < cboLoginMode.getItemCount()) {
|
||||
cboLoginMode.setSelectedIndex(loginType);
|
||||
loginModeChanged();
|
||||
Settings.getInstance().setLoginType(loginType);
|
||||
}
|
||||
}
|
||||
|
||||
private void loginModeChanged() {
|
||||
int index = cboLoginMode.getSelectedIndex();
|
||||
if (index < 0)
|
||||
return;
|
||||
Settings.getInstance().setLoginType(index);
|
||||
|
||||
IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
if (l.hasPassword()) {
|
||||
pnlPassword.setVisible(true);
|
||||
lblUserName.setText(C.i18n("login.account"));
|
||||
} else {
|
||||
pnlPassword.setVisible(false);
|
||||
lblUserName.setText(C.i18n("login.username"));
|
||||
}
|
||||
|
||||
CardLayout cl = (CardLayout) pnlPassword.getLayout();
|
||||
if (l.isLoggedIn())
|
||||
cl.last(pnlPassword);
|
||||
else
|
||||
cl.first(pnlPassword);
|
||||
String username = l.getUsername();
|
||||
if (username == null)
|
||||
username = "";
|
||||
txtPlayerName.setText(username);
|
||||
}
|
||||
|
||||
void loadFromSettings() {
|
||||
for (Profile s : Settings.getProfilesFiltered())
|
||||
cboProfiles.addItem(s.getName());
|
||||
@ -558,7 +410,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
isLoading = true;
|
||||
cboVersions.removeAllItems();
|
||||
int index = 0, i = 0;
|
||||
getProfile().selectedVersionChangedEvent.register(this);
|
||||
getProfile().selectedVersionChangedEvent.register(onVersionChanged);
|
||||
getProfile().service().version().refreshVersions();
|
||||
String selVersion = getProfile().getSelectedVersion();
|
||||
if (getProfile().service().version().getVersions().isEmpty()) {
|
||||
@ -609,36 +461,26 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
private static final int DEFAULT_WIDTH = 800, DEFAULT_HEIGHT = 480;
|
||||
//</editor-fold>
|
||||
|
||||
class PrepareAuthDoneListener implements Event<List<String>> {
|
||||
|
||||
@Override
|
||||
public boolean call(Object sender, List<String> value) {
|
||||
prepareAuths();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void runGame() {
|
||||
void runGame() {
|
||||
MainFrame.INSTANCE.showMessage(C.i18n("ui.message.launching"));
|
||||
genLaunchCode(value -> {
|
||||
getProfile().launcher().genLaunchCode(value -> {
|
||||
value.successEvent.register(new LaunchFinisher());
|
||||
value.successEvent.register(new PrepareAuthDoneListener());
|
||||
});
|
||||
value.successEvent.register(this::prepareAuths);
|
||||
}, this::failed, txtPassword.getText());
|
||||
}
|
||||
|
||||
public void makeLaunchScript() {
|
||||
void makeLaunchScript() {
|
||||
MainFrame.INSTANCE.showMessage(C.i18n("ui.message.launching"));
|
||||
genLaunchCode(value -> {
|
||||
getProfile().launcher().genLaunchCode(value -> {
|
||||
value.successEvent.register(new LaunchScriptFinisher());
|
||||
value.successEvent.register(new PrepareAuthDoneListener());
|
||||
});
|
||||
value.successEvent.register(this::prepareAuths);
|
||||
}, this::failed, txtPassword.getText());
|
||||
}
|
||||
|
||||
private void failed(String s) {
|
||||
if (s != null)
|
||||
MessageBox.Show(s);
|
||||
MainFrame.INSTANCE.closeMessage();
|
||||
isLaunching = false;
|
||||
}
|
||||
|
||||
public class LaunchFinisher implements Event<List<String>> {
|
||||
@ -646,7 +488,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
@Override
|
||||
public boolean call(Object sender, List<String> str) {
|
||||
final GameLauncher obj = (GameLauncher) sender;
|
||||
obj.launchEvent.register((sender1, p) -> {
|
||||
obj.launchEvent.register(p -> {
|
||||
if ((LauncherVisibility) obj.getTag() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) {
|
||||
HMCLog.log("Without the option of keeping the launcher visible, this application will exit and will NOT catch game logs, but you can turn on \"Debug Mode\".");
|
||||
System.exit(0);
|
||||
@ -658,25 +500,21 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
MainFrame.INSTANCE.dispose();
|
||||
}
|
||||
JavaProcessMonitor jpm = new JavaProcessMonitor(p);
|
||||
jpm.applicationExitedAbnormallyEvent.register((sender2, t) -> {
|
||||
jpm.applicationExitedAbnormallyEvent.register(t -> {
|
||||
HMCLog.err("The game exited abnormally, exit code: " + t);
|
||||
MessageBox.Show(C.i18n("launch.exited_abnormally") + ", exit code: " + t);
|
||||
return true;
|
||||
});
|
||||
jpm.jvmLaunchFailedEvent.register((sender2, t) -> {
|
||||
jpm.jvmLaunchFailedEvent.register(t -> {
|
||||
HMCLog.err("Cannot create jvm, exit code: " + t);
|
||||
MessageBox.Show(C.i18n("launch.cannot_create_jvm") + ", exit code: " + t);
|
||||
return true;
|
||||
});
|
||||
jpm.stoppedEvent.register((sender2, t) -> {
|
||||
jpm.stoppedEvent.register(() -> {
|
||||
if ((LauncherVisibility) obj.getTag() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible()) {
|
||||
HMCLog.log("Without the option of keeping the launcher visible, this application will exit and will NOT catch game logs, but you can turn on \"Debug Mode\".");
|
||||
System.exit(0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
jpm.start();
|
||||
return true;
|
||||
});
|
||||
try {
|
||||
obj.launch(str);
|
||||
@ -720,10 +558,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnExportModpack;
|
||||
private javax.swing.JButton btnImportModpack;
|
||||
private javax.swing.JButton btnIncludeMinecraft;
|
||||
private javax.swing.JButton btnLogout;
|
||||
private javax.swing.JButton btnMakeLaunchScript;
|
||||
private javax.swing.JButton btnShowLog;
|
||||
private javax.swing.JComboBox cboLoginMode;
|
||||
private javax.swing.JComboBox cboProfiles;
|
||||
private javax.swing.JComboBox cboVersions;
|
||||
@ -739,4 +574,32 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
private javax.swing.JPasswordField txtPassword;
|
||||
private javax.swing.JTextField txtPlayerName;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
final Event<String> onVersionChanged = (sender, v) -> {
|
||||
cboVersions.setToolTipText(v);
|
||||
return true;
|
||||
};
|
||||
|
||||
final Event<IAuthenticator> onAuthChanged = (sender, l) -> {
|
||||
if (l.hasPassword()) {
|
||||
pnlPassword.setVisible(true);
|
||||
lblUserName.setText(C.i18n("login.account"));
|
||||
} else {
|
||||
pnlPassword.setVisible(false);
|
||||
lblUserName.setText(C.i18n("login.username"));
|
||||
}
|
||||
|
||||
CardLayout cl = (CardLayout) pnlPassword.getLayout();
|
||||
if (l.isLoggedIn())
|
||||
cl.last(pnlPassword);
|
||||
else
|
||||
cl.first(pnlPassword);
|
||||
String username = l.getUsername();
|
||||
if (username == null)
|
||||
username = "";
|
||||
txtPlayerName.setText(username);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -106,12 +106,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
System.out.println(text);
|
||||
|
||||
if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LogWindow.INSTANCE.showAsCrashWindow(Settings.UPDATE_CHECKER.OUT_DATED);
|
||||
}
|
||||
});
|
||||
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(Settings.UPDATE_CHECKER.OUT_DATED));
|
||||
if (!Settings.UPDATE_CHECKER.OUT_DATED)
|
||||
reportToServer(text, s);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hellominecraft.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -26,11 +27,12 @@ import java.util.HashSet;
|
||||
*/
|
||||
public class EventHandler<T> {
|
||||
|
||||
HashSet<Event<T>> handlers;
|
||||
HashSet<Event<T>> handlers = new HashSet<>();
|
||||
HashSet<Consumer<T>> consumers = new HashSet<>();
|
||||
HashSet<Runnable> runnables = new HashSet<>();
|
||||
Object sender;
|
||||
|
||||
public EventHandler(Object sender) {
|
||||
handlers = new HashSet<>();
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@ -38,15 +40,35 @@ public class EventHandler<T> {
|
||||
handlers.add(t);
|
||||
}
|
||||
|
||||
public void register(Consumer<T> t) {
|
||||
consumers.add(t);
|
||||
}
|
||||
|
||||
public void register(Runnable t) {
|
||||
runnables.add(t);
|
||||
}
|
||||
|
||||
public void unregister(Event<T> t) {
|
||||
handlers.remove(t);
|
||||
}
|
||||
|
||||
public void unregister(Consumer<T> t) {
|
||||
consumers.remove(t);
|
||||
}
|
||||
|
||||
public void unregister(Runnable t) {
|
||||
runnables.remove(t);
|
||||
}
|
||||
|
||||
public boolean execute(T x) {
|
||||
boolean flag = true;
|
||||
for (Event<T> t : handlers)
|
||||
if (!t.call(sender, x))
|
||||
flag = false;
|
||||
for (Consumer<T> t : consumers)
|
||||
t.accept(x);
|
||||
for (Runnable t : runnables)
|
||||
t.run();
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user