This commit is contained in:
huangyuhui
2016-02-10 23:08:58 +08:00
parent 8e8584656e
commit 98282fd319
15 changed files with 358 additions and 287 deletions

View File

@@ -149,7 +149,7 @@ public abstract class IMinecraftProvider {
*/ */
public abstract void refreshVersions(); public abstract void refreshVersions();
public final EventHandler<Void> onRefreshingVersions = new EventHandler<>(this), public final EventHandler<IMinecraftService> onRefreshingVersions = new EventHandler<>(this),
onRefreshedVersions = new EventHandler<>(this); onRefreshedVersions = new EventHandler<>(this);
public final EventHandler<String> onLoadedVersion = new EventHandler<>(this); public final EventHandler<String> onLoadedVersion = new EventHandler<>(this);

View File

@@ -68,7 +68,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public void refreshVersions() { public void refreshVersions() {
onRefreshingVersions.execute(null); onRefreshingVersions.execute(service);
try { try {
MCUtils.tryWriteProfile(service.baseDirectory()); MCUtils.tryWriteProfile(service.baseDirectory());
@@ -146,7 +146,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", e); HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", e);
} }
} }
onRefreshedVersions.execute(null); onRefreshedVersions.execute(service);
} }
@Override @Override

View File

@@ -98,6 +98,7 @@ public final class Config {
public void setLast(String last) { public void setLast(String last) {
this.last = last; this.last = last;
Settings.onProfileChanged();
Settings.save(); Settings.save();
} }

View File

@@ -49,7 +49,7 @@ public final class Profile {
gameDir = MCUtils.getInitGameDir().getPath(); gameDir = MCUtils.getInitGameDir().getPath();
} }
public Profile(Profile v) { public Profile(String name, Profile v) {
this(); this();
if (v == null) if (v == null)
return; return;
@@ -132,7 +132,7 @@ public final class Profile {
return name; return name;
} }
public void setName(String name) { void setName(String name) {
this.name = name; this.name = name;
propertyChanged.execute("name"); propertyChanged.execute("name");
} }
@@ -140,4 +140,8 @@ public final class Profile {
public void checkFormat() { public void checkFormat() {
gameDir = gameDir.replace('/', OS.os().fileSeparator).replace('\\', OS.os().fileSeparator); gameDir = gameDir.replace('/', OS.os().fileSeparator).replace('\\', OS.os().fileSeparator);
} }
public void onSelected() {
service().version().refreshVersions();
}
} }

View File

@@ -27,6 +27,7 @@ import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType; import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.util.CollectionUtils; import org.jackhuang.hellominecraft.util.CollectionUtils;
import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.system.IOUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
@@ -56,7 +57,9 @@ public final class Settings {
if (!getProfiles().containsKey(DEFAULT_PROFILE)) if (!getProfiles().containsKey(DEFAULT_PROFILE))
getProfiles().put(DEFAULT_PROFILE, new Profile()); getProfiles().put(DEFAULT_PROFILE, new Profile());
for (Profile e : getProfiles().values()) { for (Map.Entry<String, Profile> entry : getProfiles().entrySet()) {
Profile e = entry.getValue();
e.setName(entry.getKey());
e.checkFormat(); e.checkFormat();
e.propertyChanged.register(Settings::save); e.propertyChanged.register(Settings::save);
} }
@@ -91,6 +94,10 @@ public final class Settings {
} }
} }
public static Profile getLastProfile() {
return getProfile(getInstance().getLast());
}
public static Profile getProfile(String name) { public static Profile getProfile(String name) {
if (name == null) if (name == null)
return getProfiles().get("Default"); return getProfiles().get("Default");
@@ -113,7 +120,7 @@ public final class Settings {
return SETTINGS.getConfigurations().firstEntry().getValue(); return SETTINGS.getConfigurations().firstEntry().getValue();
} }
public static boolean trySetProfile(Profile ver) { public static boolean putProfile(Profile ver) {
if (ver == null || ver.getName() == null || getProfiles().containsKey(ver.getName())) if (ver == null || ver.getName() == null || getProfiles().containsKey(ver.getName()))
return false; return false;
getProfiles().put(ver.getName(), ver); getProfiles().put(ver.getName(), ver);
@@ -131,4 +138,18 @@ public final class Settings {
} }
return getProfiles().remove(ver) != null; return getProfiles().remove(ver) != null;
} }
public static final EventHandler<Profile> profileChangedEvent = new EventHandler(null);
public static final EventHandler<Void> profileLoadingEvent = new EventHandler(null);
static void onProfileChanged() {
Profile p = getLastProfile();
profileChangedEvent.execute(p);
p.onSelected();
}
public static void onProfileLoading() {
profileLoadingEvent.execute(null);
onProfileChanged();
}
} }

View File

@@ -89,8 +89,22 @@ public class AnimatedPanel extends JPanel implements Selectable {
g.drawImage(image, 0, 0, this); g.drawImage(image, 0, 0, this);
} }
boolean selected = false;
@Override
public boolean isSelected() {
return selected;
}
@Override @Override
public void onSelected() { public void onSelected() {
animate(); if (!selected)
animate();
selected = true;
}
@Override
public void onLeaving() {
selected = false;
} }
} }

View File

@@ -250,7 +250,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkFullscreenFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkFullscreenItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JTextField" name="txtJavaDir"> <Component class="javax.swing.JTextField" name="txtJavaDir">
@@ -302,7 +302,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="cboLauncherVisibilityFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboLauncherVisibilityItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblLauncherVisibility"> <Component class="javax.swing.JLabel" name="lblLauncherVisibility">
@@ -326,7 +326,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="cboRunDirectoryFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboRunDirectoryItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="btnChoosingJavaDir"> <Component class="javax.swing.JButton" name="btnChoosingJavaDir">
@@ -470,7 +470,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkDebugFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkDebugItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblJavaArgs"> <Component class="javax.swing.JLabel" name="lblJavaArgs">
@@ -521,7 +521,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkNoJVMArgsFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkNoJVMArgsItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="chkCancelWrapper"> <Component class="javax.swing.JCheckBox" name="chkCancelWrapper">
@@ -531,7 +531,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkCancelWrapperFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkCancelWrapperItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblPrecalledCommand"> <Component class="javax.swing.JLabel" name="lblPrecalledCommand">

View File

@@ -33,6 +33,7 @@ import java.awt.event.KeyEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@@ -49,16 +50,16 @@ import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.launcher.util.FileNameFilter; import org.jackhuang.hellominecraft.launcher.util.FileNameFilter;
import org.jackhuang.hellominecraft.launcher.core.mod.ModInfo; import org.jackhuang.hellominecraft.launcher.core.mod.ModInfo;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerType; import org.jackhuang.hellominecraft.launcher.core.install.InstallerType;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType; import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.util.DefaultMinecraftService;
import org.jackhuang.hellominecraft.launcher.setting.VersionSetting; import org.jackhuang.hellominecraft.launcher.setting.VersionSetting;
import org.jackhuang.hellominecraft.util.Event;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.OverridableSwingWorker; import org.jackhuang.hellominecraft.util.OverridableSwingWorker;
import org.jackhuang.hellominecraft.util.version.MinecraftVersionRequest; import org.jackhuang.hellominecraft.util.version.MinecraftVersionRequest;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.system.OS;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.func.Consumer;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.system.IOUtils;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
@@ -102,6 +103,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
for (Java j : Java.JAVA) for (Java j : Java.JAVA)
cboJava.addItem(j.getLocalizedName()); cboJava.addItem(j.getLocalizedName());
Settings.profileLoadingEvent.register(onLoadingProfiles);
Settings.profileChangedEvent.register(onSelectedProfilesChanged);
dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this); dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this);
} }
@@ -341,9 +345,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
lblDimensionX.setText("x"); lblDimensionX.setText("x");
chkFullscreen.setText(C.i18n("settings.fullscreen")); // NOI18N chkFullscreen.setText(C.i18n("settings.fullscreen")); // NOI18N
chkFullscreen.addFocusListener(new java.awt.event.FocusAdapter() { chkFullscreen.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkFullscreenFocusLost(evt); chkFullscreenItemStateChanged(evt);
} }
}); });
@@ -374,9 +378,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}); });
cboLauncherVisibility.setModel(new javax.swing.DefaultComboBoxModel(new String[] { C.i18n("advancedsettings.launcher_visibility.close"), C.i18n("advancedsettings.launcher_visibility.hide"), C.i18n("advancedsettings.launcher_visibility.keep") })); cboLauncherVisibility.setModel(new javax.swing.DefaultComboBoxModel(new String[] { C.i18n("advancedsettings.launcher_visibility.close"), C.i18n("advancedsettings.launcher_visibility.hide"), C.i18n("advancedsettings.launcher_visibility.keep") }));
cboLauncherVisibility.addFocusListener(new java.awt.event.FocusAdapter() { cboLauncherVisibility.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboLauncherVisibilityFocusLost(evt); cboLauncherVisibilityItemStateChanged(evt);
} }
}); });
@@ -385,9 +389,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
lblRunDirectory.setText(C.i18n("settings.run_directory")); // NOI18N lblRunDirectory.setText(C.i18n("settings.run_directory")); // NOI18N
cboRunDirectory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { C.i18n("advancedsettings.game_dir.default"), C.i18n("advancedsettings.game_dir.independent") })); cboRunDirectory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { C.i18n("advancedsettings.game_dir.default"), C.i18n("advancedsettings.game_dir.independent") }));
cboRunDirectory.addFocusListener(new java.awt.event.FocusAdapter() { cboRunDirectory.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboRunDirectoryFocusLost(evt); cboRunDirectoryItemStateChanged(evt);
} }
}); });
@@ -509,9 +513,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
tabVersionEdit.addTab(C.i18n("settings"), pnlSettings); // NOI18N tabVersionEdit.addTab(C.i18n("settings"), pnlSettings); // NOI18N
chkDebug.setText(C.i18n("advancedsettings.debug_mode")); // NOI18N chkDebug.setText(C.i18n("advancedsettings.debug_mode")); // NOI18N
chkDebug.addFocusListener(new java.awt.event.FocusAdapter() { chkDebug.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkDebugFocusLost(evt); chkDebugItemStateChanged(evt);
} }
}); });
@@ -541,16 +545,16 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}); });
chkNoJVMArgs.setText(C.i18n("advancedsettings.no_jvm_args")); // NOI18N chkNoJVMArgs.setText(C.i18n("advancedsettings.no_jvm_args")); // NOI18N
chkNoJVMArgs.addFocusListener(new java.awt.event.FocusAdapter() { chkNoJVMArgs.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkNoJVMArgsFocusLost(evt); chkNoJVMArgsItemStateChanged(evt);
} }
}); });
chkCancelWrapper.setText(C.i18n("advancedsettings.cancel_wrapper_launcher")); // NOI18N chkCancelWrapper.setText(C.i18n("advancedsettings.cancel_wrapper_launcher")); // NOI18N
chkCancelWrapper.addFocusListener(new java.awt.event.FocusAdapter() { chkCancelWrapper.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkCancelWrapperFocusLost(evt); chkCancelWrapperItemStateChanged(evt);
} }
}); });
@@ -933,12 +937,8 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
// <editor-fold defaultstate="collapsed" desc="UI Events"> // <editor-fold defaultstate="collapsed" desc="UI Events">
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
if (!isLoading) { if (!isLoading)
Settings.getInstance().setLast((String) cboProfiles.getSelectedItem()); Settings.getInstance().setLast((String) cboProfiles.getSelectedItem());
if (getProfile().service().version().getVersionCount() <= 0)
versionChanged(null);
prepareProfile(getProfile());
}
}//GEN-LAST:event_cboProfilesItemStateChanged }//GEN-LAST:event_cboProfilesItemStateChanged
private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed
@@ -956,8 +956,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem())) if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem()))
return; return;
String mcv = (String) cboVersions.getSelectedItem(); getProfile().setSelectedMinecraftVersion((String) cboVersions.getSelectedItem());
getProfile().setSelectedMinecraftVersion(mcv);
}//GEN-LAST:event_cboVersionsItemStateChanged }//GEN-LAST:event_cboVersionsItemStateChanged
private void btnRefreshVersionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshVersionsActionPerformed private void btnRefreshVersionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshVersionsActionPerformed
@@ -972,73 +971,11 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
ppmManage.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y); ppmManage.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y);
}//GEN-LAST:event_btnModifyMouseClicked }//GEN-LAST:event_btnModifyMouseClicked
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost
getProfile().getSelectedVersionSetting().setJavaArgs(txtJavaArgs.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
getProfile().getSelectedVersionSetting().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
getProfile().getSelectedVersionSetting().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost
private void chkDebugFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDebugFocusLost
getProfile().getSelectedVersionSetting().setDebug(chkDebug.isSelected());
}//GEN-LAST:event_chkDebugFocusLost
private void chkNoJVMArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkNoJVMArgsFocusLost
getProfile().getSelectedVersionSetting().setNoJVMArgs(chkNoJVMArgs.isSelected());
}//GEN-LAST:event_chkNoJVMArgsFocusLost
private void chkCancelWrapperFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkCancelWrapperFocusLost
getProfile().getSelectedVersionSetting().setCanceledWrapper(chkCancelWrapper.isSelected());
}//GEN-LAST:event_chkCancelWrapperFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
getProfile().getSelectedVersionSetting().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
getProfile().getSelectedVersionSetting().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost
private void cboRunDirectoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboRunDirectoryFocusLost
if (cboRunDirectory.getSelectedIndex() >= 0)
getProfile().getSelectedVersionSetting().setGameDirType(GameDirType.values()[cboRunDirectory.getSelectedIndex()]);
}//GEN-LAST:event_cboRunDirectoryFocusLost
private void cboLauncherVisibilityFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityFocusLost
if (cboLauncherVisibility.getSelectedIndex() >= 0)
getProfile().getSelectedVersionSetting().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
}//GEN-LAST:event_cboLauncherVisibilityFocusLost
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
if (mcVersion != null) if (mcVersion != null)
getProfile().service().asset().downloadAssets(mcVersion).run(); getProfile().service().asset().downloadAssets(mcVersion).run();
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed }//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
getProfile().getSelectedVersionSetting().setMaxMemory(txtMaxMemory.getText());
}//GEN-LAST:event_txtMaxMemoryFocusLost
private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost
getProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText());
}//GEN-LAST:event_txtJavaDirFocusLost
private void chkFullscreenFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkFullscreenFocusLost
getProfile().getSelectedVersionSetting().setFullscreen(chkFullscreen.isSelected());
}//GEN-LAST:event_chkFullscreenFocusLost
private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost
getProfile().getSelectedVersionSetting().setHeight(txtHeight.getText());
}//GEN-LAST:event_txtHeightFocusLost
private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost
getProfile().getSelectedVersionSetting().setWidth(txtWidth.getText());
}//GEN-LAST:event_txtWidthFocusLost
private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost
getProfile().setGameDir(txtGameDir.getText()); getProfile().setGameDir(txtGameDir.getText());
loadVersions(); loadVersions();
@@ -1155,34 +1092,80 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
MessageBox.Show(C.i18n("setupwindow.no_empty_name")); MessageBox.Show(C.i18n("setupwindow.no_empty_name"));
return; return;
} }
Settings.trySetProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath())); Settings.putProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
MessageBox.Show(C.i18n("setupwindow.find_in_configurations")); MessageBox.Show(C.i18n("setupwindow.find_in_configurations"));
loadProfiles(); loadProfiles();
} }
}//GEN-LAST:event_btnIncludeMinecraftActionPerformed }//GEN-LAST:event_btnIncludeMinecraftActionPerformed
private void cboRunDirectoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboRunDirectoryItemStateChanged
if (!isLoading && cboRunDirectory.getSelectedIndex() >= 0)
getProfile().getSelectedVersionSetting().setGameDirType(GameDirType.values()[cboRunDirectory.getSelectedIndex()]);
}//GEN-LAST:event_cboRunDirectoryItemStateChanged
private void cboLauncherVisibilityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityItemStateChanged
if (!isLoading && cboLauncherVisibility.getSelectedIndex() >= 0)
getProfile().getSelectedVersionSetting().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
}//GEN-LAST:event_cboLauncherVisibilityItemStateChanged
private void chkFullscreenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkFullscreenItemStateChanged
if (!isLoading)
getProfile().getSelectedVersionSetting().setFullscreen(chkFullscreen.isSelected());
}//GEN-LAST:event_chkFullscreenItemStateChanged
private void chkDebugItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDebugItemStateChanged
if (!isLoading)
getProfile().getSelectedVersionSetting().setDebug(chkDebug.isSelected());
}//GEN-LAST:event_chkDebugItemStateChanged
private void chkCancelWrapperItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkCancelWrapperItemStateChanged
if (!isLoading)
getProfile().getSelectedVersionSetting().setCanceledWrapper(chkCancelWrapper.isSelected());
}//GEN-LAST:event_chkCancelWrapperItemStateChanged
private void chkNoJVMArgsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNoJVMArgsItemStateChanged
if (!isLoading)
getProfile().getSelectedVersionSetting().setNoJVMArgs(chkNoJVMArgs.isSelected());
}//GEN-LAST:event_chkNoJVMArgsItemStateChanged
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
getProfile().getSelectedVersionSetting().setMaxMemory(txtMaxMemory.getText());
}//GEN-LAST:event_txtMaxMemoryFocusLost
private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost
getProfile().getSelectedVersionSetting().setWidth(txtWidth.getText());
}//GEN-LAST:event_txtWidthFocusLost
private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost
getProfile().getSelectedVersionSetting().setHeight(txtHeight.getText());
}//GEN-LAST:event_txtHeightFocusLost
private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost
getProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText());
}//GEN-LAST:event_txtJavaDirFocusLost
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost
getProfile().getSelectedVersionSetting().setJavaArgs(txtJavaArgs.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
getProfile().getSelectedVersionSetting().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
getProfile().getSelectedVersionSetting().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
getProfile().getSelectedVersionSetting().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
getProfile().getSelectedVersionSetting().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost
// </editor-fold> // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Load"> // <editor-fold defaultstate="collapsed" desc="Load">
private void loadProfiles() {
isLoading = true;
cboProfiles.removeAllItems();
int index = 0, i = 0;
for (Profile s : Settings.getProfilesFiltered()) {
cboProfiles.addItem(s.getName());
if (StrUtils.isEquals(s.getName(), Settings.getInstance().getLast()))
index = i;
i++;
}
isLoading = false;
if (index < cboProfiles.getItemCount()) {
isLoading = true;
cboProfiles.setSelectedIndex(index);
isLoading = false;
prepareProfile(getProfile());
}
}
final Profile getProfile() { final Profile getProfile() {
return Settings.getProfile((String) cboProfiles.getSelectedItem()); return Settings.getProfile((String) cboProfiles.getSelectedItem());
} }
@@ -1191,24 +1174,10 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
return getProfile().getSelectedVersion(); return getProfile().getSelectedVersion();
} }
Event<Void> onRefreshedVersions = (sender, e) -> {
loadVersions();
return true;
};
void prepareProfile(Profile profile) {
if (profile == null)
return;
profile.selectedVersionChangedEvent.register(selectedVersionChangedEvent);
profile.service().version().onRefreshedVersions.register(onRefreshedVersions);
txtGameDir.setText(profile.getGameDir());
loadVersions();
}
void prepareVersionSetting(VersionSetting profile) { void prepareVersionSetting(VersionSetting profile) {
if (profile == null) if (profile == null)
return; return;
isLoading = true;
txtWidth.setText(profile.getWidth()); txtWidth.setText(profile.getWidth());
txtHeight.setText(profile.getHeight()); txtHeight.setText(profile.getHeight());
txtMaxMemory.setText(profile.getMaxMemory()); txtMaxMemory.setText(profile.getMaxMemory());
@@ -1224,33 +1193,11 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
chkCancelWrapper.setSelected(profile.isCanceledWrapper()); chkCancelWrapper.setSelected(profile.isCanceledWrapper());
cboLauncherVisibility.setSelectedIndex(profile.getLauncherVisibility().ordinal()); cboLauncherVisibility.setSelectedIndex(profile.getLauncherVisibility().ordinal());
cboRunDirectory.setSelectedIndex(profile.getGameDirType().ordinal()); cboRunDirectory.setSelectedIndex(profile.getGameDirType().ordinal());
isLoading = true;
cboJava.setSelectedIndex(profile.getJavaIndexInAllJavas()); cboJava.setSelectedIndex(profile.getJavaIndexInAllJavas());
isLoading = false; isLoading = false;
cboJavaItemStateChanged(new ItemEvent(cboJava, 0, cboJava.getSelectedItem(), ItemEvent.SELECTED)); cboJavaItemStateChanged(new ItemEvent(cboJava, 0, cboJava.getSelectedItem(), ItemEvent.SELECTED));
} }
void loadVersions() {
isLoading = true;
cboVersions.removeAllItems();
int index = 0, i = 0;
String selectedMC = getProfile().getSelectedVersion();
for (MinecraftVersion each : getProfile().service().version().getVersions()) {
cboVersions.addItem(each.id);
if (StrUtils.isEquals(each.id, selectedMC))
index = i;
i++;
}
isLoading = false;
if (index < cboVersions.getItemCount())
cboVersions.setSelectedIndex(index);
reloadMods();
prepareVersionSetting(((DefaultMinecraftService) getProfile().service()).getVersionSetting(getProfile().getSelectedVersion()));
loadMinecraftVersion(getProfile().getSelectedVersion());
}
/** /**
* Anaylze the jar of selected minecraft version of current getProfile() to * Anaylze the jar of selected minecraft version of current getProfile() to
* get the version. * get the version.
@@ -1330,21 +1277,37 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
// </editor-fold> // </editor-fold>
public void versionChanged(String version) { void save() {
this.mcVersion = version; VersionSetting vs = getProfile().getSelectedVersionSetting();
prepareVersionSetting(getProfile().getVersionSetting(version)); if (txtServerIP.hasFocus())
loadMinecraftVersion(version); vs.setServerIp(txtServerIP.getText());
for (InstallerPanel p : installerPanels) if (txtPrecalledCommand.hasFocus())
p.loadVersions(); vs.setPrecalledCommand(txtPrecalledCommand.getText());
if (txtPermSize.hasFocus())
vs.setPermSize(txtPermSize.getText());
if (txtMinecraftArgs.hasFocus())
vs.setMinecraftArgs(txtMinecraftArgs.getText());
if (txtJavaArgs.hasFocus())
vs.setJavaArgs(txtJavaArgs.getText());
if (txtJavaDir.hasFocus())
vs.setJavaDir(txtJavaDir.getText());
if (txtHeight.hasFocus())
vs.setHeight(txtHeight.getText());
if (txtWidth.hasFocus())
vs.setWidth(txtWidth.getText());
if (txtMaxMemory.hasFocus())
vs.setMaxMemory(txtMaxMemory.getText());
} }
@Override @Override
public void onSelected() { public void onSelected() {
loadProfiles(); super.onSelected();
if (getProfile().service().version().getVersionCount() <= 0) Settings.onProfileLoading();
versionChanged(null); }
else
versionChanged((String) cboVersions.getSelectedItem()); public void onLeaving() {
super.onLeaving();
save();
} }
public void showGameDownloads() { public void showGameDownloads() {
@@ -1424,9 +1387,53 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private final javax.swing.JPanel pnlGameDownloads; private final javax.swing.JPanel pnlGameDownloads;
// </editor-fold> // </editor-fold>
Event<String> selectedVersionChangedEvent = (Object sender, String e) -> { final Runnable onLoadingProfiles = this::loadProfiles;
versionChanged(e);
cboVersions.setToolTipText(e); private void loadProfiles() {
return true; DefaultComboBoxModel model = new DefaultComboBoxModel();
for (Profile s : Settings.getProfilesFiltered())
model.addElement(s.getName());
cboProfiles.setModel(model);
}
final Consumer<IMinecraftService> onRefreshedVersions = t -> {
if (getProfile().service() == t)
loadVersions();
};
void loadVersions() {
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (MinecraftVersion each : getProfile().service().version().getVersions()) {
if (each.hidden)
continue;
model.addElement(each.id);
}
cboVersions.setModel(model);
if (getProfile().getSelectedVersion() != null)
selectedVersionChangedEvent.accept(getProfile().getSelectedVersion());
}
final Consumer<String> selectedVersionChangedEvent = this::versionChanged;
public void versionChanged(String version) {
isLoading = true;
((DefaultComboBoxModel) cboVersions.getModel()).setSelectedItem(version);
cboVersions.setToolTipText(version);
this.mcVersion = version;
reloadMods();
prepareVersionSetting(getProfile().getVersionSetting(version));
loadMinecraftVersion(version);
for (InstallerPanel p : installerPanels)
p.loadVersions();
isLoading = false;
}
final Consumer<Profile> onSelectedProfilesChanged = t -> {
t.service().version().onRefreshedVersions.register(onRefreshedVersions);
t.selectedVersionChangedEvent.register(selectedVersionChangedEvent);
((DefaultComboBoxModel) cboProfiles.getModel()).setSelectedItem(t.getName());
txtGameDir.setText(t.getGameDir());
}; };
} }

View File

@@ -204,7 +204,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkEnableShadowFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkEnableShadowItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblTheme"> <Component class="javax.swing.JLabel" name="lblTheme">
@@ -286,7 +286,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkEnableAnimationFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkEnableAnimationItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="chkDecorated"> <Component class="javax.swing.JCheckBox" name="chkDecorated">
@@ -296,7 +296,7 @@
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="chkDecoratedFocusLost"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkDecoratedItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblModpack"> <Component class="javax.swing.JLabel" name="lblModpack">

View File

@@ -142,9 +142,9 @@ public class LauncherSettingsPanel extends AnimatedPanel {
}); });
chkEnableShadow.setText(C.i18n("launcher.enable_shadow")); // NOI18N chkEnableShadow.setText(C.i18n("launcher.enable_shadow")); // NOI18N
chkEnableShadow.addFocusListener(new java.awt.event.FocusAdapter() { chkEnableShadow.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkEnableShadowFocusLost(evt); chkEnableShadowItemStateChanged(evt);
} }
}); });
@@ -192,16 +192,16 @@ public class LauncherSettingsPanel extends AnimatedPanel {
lblProxyPassword.setText(C.i18n("proxy.password")); // NOI18N lblProxyPassword.setText(C.i18n("proxy.password")); // NOI18N
chkEnableAnimation.setText(C.i18n("launcher.enable_animation")); // NOI18N chkEnableAnimation.setText(C.i18n("launcher.enable_animation")); // NOI18N
chkEnableAnimation.addFocusListener(new java.awt.event.FocusAdapter() { chkEnableAnimation.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkEnableAnimationFocusLost(evt); chkEnableAnimationItemStateChanged(evt);
} }
}); });
chkDecorated.setText(C.i18n("launcher.decorated")); // NOI18N chkDecorated.setText(C.i18n("launcher.decorated")); // NOI18N
chkDecorated.addFocusListener(new java.awt.event.FocusAdapter() { chkDecorated.addItemListener(new java.awt.event.ItemListener() {
public void focusLost(java.awt.event.FocusEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkDecoratedFocusLost(evt); chkDecoratedItemStateChanged(evt);
} }
}); });
@@ -359,14 +359,30 @@ public class LauncherSettingsPanel extends AnimatedPanel {
Settings.UPDATE_CHECKER.process(true); Settings.UPDATE_CHECKER.process(true);
}//GEN-LAST:event_btnCheckUpdateActionPerformed }//GEN-LAST:event_btnCheckUpdateActionPerformed
private void chkEnableShadowFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkEnableShadowFocusLost
Settings.getInstance().setEnableShadow(chkEnableShadow.isSelected());
}//GEN-LAST:event_chkEnableShadowFocusLost
private void cboThemeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboThemeItemStateChanged private void cboThemeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboThemeItemStateChanged
Settings.getInstance().setTheme(cboTheme.getSelectedIndex()); Settings.getInstance().setTheme(cboTheme.getSelectedIndex());
}//GEN-LAST:event_cboThemeItemStateChanged }//GEN-LAST:event_cboThemeItemStateChanged
private void lblModpackMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModpackMouseClicked
SwingUtils.openLink("http://blog.163.com/huanghongxun2008@126/blog/static/7738046920160323812771/");
}//GEN-LAST:event_lblModpackMouseClicked
private void cboLangItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLangItemStateChanged
Settings.getInstance().setLocalization(SupportedLocales.values()[cboLang.getSelectedIndex()].name());
}//GEN-LAST:event_cboLangItemStateChanged
private void chkEnableShadowItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkEnableShadowItemStateChanged
Settings.getInstance().setEnableShadow(chkEnableShadow.isSelected());
}//GEN-LAST:event_chkEnableShadowItemStateChanged
private void chkDecoratedItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDecoratedItemStateChanged
Settings.getInstance().setDecorated(chkDecorated.isSelected());
}//GEN-LAST:event_chkDecoratedItemStateChanged
private void chkEnableAnimationItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkEnableAnimationItemStateChanged
Settings.getInstance().setEnableAnimation(chkEnableAnimation.isSelected());
}//GEN-LAST:event_chkEnableAnimationItemStateChanged
private void txtProxyHostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyHostFocusLost private void txtProxyHostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyHostFocusLost
Settings.getInstance().setProxyHost(txtProxyHost.getText()); Settings.getInstance().setProxyHost(txtProxyHost.getText());
}//GEN-LAST:event_txtProxyHostFocusLost }//GEN-LAST:event_txtProxyHostFocusLost
@@ -383,22 +399,6 @@ public class LauncherSettingsPanel extends AnimatedPanel {
Settings.getInstance().setProxyPassword(txtProxyPassword.getText()); Settings.getInstance().setProxyPassword(txtProxyPassword.getText());
}//GEN-LAST:event_txtProxyPasswordFocusLost }//GEN-LAST:event_txtProxyPasswordFocusLost
private void chkEnableAnimationFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkEnableAnimationFocusLost
Settings.getInstance().setEnableAnimation(chkEnableAnimation.isSelected());
}//GEN-LAST:event_chkEnableAnimationFocusLost
private void chkDecoratedFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDecoratedFocusLost
Settings.getInstance().setDecorated(chkDecorated.isSelected());
}//GEN-LAST:event_chkDecoratedFocusLost
private void lblModpackMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModpackMouseClicked
SwingUtils.openLink("http://blog.163.com/huanghongxun2008@126/blog/static/7738046920160323812771/");
}//GEN-LAST:event_lblModpackMouseClicked
private void cboLangItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLangItemStateChanged
Settings.getInstance().setLocalization(SupportedLocales.values()[cboLang.getSelectedIndex()].name());
}//GEN-LAST:event_cboLangItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCheckUpdate; private javax.swing.JButton btnCheckUpdate;
private javax.swing.JButton btnSelBackgroundPath; private javax.swing.JButton btnSelBackgroundPath;

View File

@@ -105,6 +105,7 @@ public final class MainFrame extends DraggableFrame {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
closing();
} }
@Override @Override
@@ -268,6 +269,7 @@ public final class MainFrame extends DraggableFrame {
private AnimatedPanel tabContent[]; private AnimatedPanel tabContent[];
public void selectTab(String tabName) { public void selectTab(String tabName) {
int chosen = -1;
for (int i = 0; i < tabHeader.size(); i++) for (int i = 0; i < tabHeader.size(); i++)
if (tabName.equalsIgnoreCase(tabHeader.get(i).getActionCommand())) { if (tabName.equalsIgnoreCase(tabHeader.get(i).getActionCommand())) {
if (tabContent[i] == null) { if (tabContent[i] == null) {
@@ -277,22 +279,36 @@ public final class MainFrame extends DraggableFrame {
throw new Error(mustnothappen); throw new Error(mustnothappen);
} }
tabWrapper[i].add(tabContent[i]); tabWrapper[i].add(tabContent[i]);
} } else if (tabContent[i].isSelected())
boolean flag = tabHeader.get(i).isActive(); continue;
for (int j = 0; j < tabHeader.size(); j++) chosen = i;
if (j != i)
tabHeader.get(j).setIsActive(false);
tabHeader.get(i).setIsActive(true);
tabContent[i].onSelected();
if (!flag)
tabContent[i].animate();
break; break;
} }
if (chosen != -1) {
for (int i = 0; i < tabHeader.size(); i++)
if (i != chosen && tabContent[i] != null && tabContent[i].isSelected())
tabContent[i].onLeaving();
for (int i = 0; i < tabHeader.size(); i++)
if (i == chosen) {
for (int j = 0; j < tabHeader.size(); j++)
if (j != i)
tabHeader.get(j).setIsActive(false);
tabHeader.get(i).setIsActive(true);
tabContent[i].onSelected();
}
this.infoLayout.show(this.infoSwap, tabName); this.infoLayout.show(this.infoSwap, tabName);
}
}
protected void closing() {
for (int i = 0; i < tabHeader.size(); i++)
if (tabContent[i] != null && tabContent[i].isSelected())
tabContent[i].onLeaving();
} }
protected void closeWindow() { protected void closeWindow() {
closing();
System.exit(0); System.exit(0);
} }

View File

@@ -22,6 +22,7 @@ import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@@ -34,10 +35,12 @@ import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager; import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.ui.modpack.ModpackWizard; import org.jackhuang.hellominecraft.launcher.ui.modpack.ModpackWizard;
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils; import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
import org.jackhuang.hellominecraft.util.Event; import org.jackhuang.hellominecraft.util.Event;
import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton; 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.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer; import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer;
@@ -78,6 +81,8 @@ public class MainPagePanel extends AnimatedPanel {
pnlMore.setOpaque(true); pnlMore.setOpaque(true);
Settings.getInstance().authChangedEvent.register(onAuthChanged); Settings.getInstance().authChangedEvent.register(onAuthChanged);
Settings.profileLoadingEvent.register(onLoadingProfiles);
Settings.profileChangedEvent.register(onSelectedProfilesChanged);
MainFrame.INSTANCE.daemon.customizedSuccessEvent = this::prepareAuths; MainFrame.INSTANCE.daemon.customizedSuccessEvent = this::prepareAuths;
@@ -314,10 +319,8 @@ public class MainPagePanel extends AnimatedPanel {
}//GEN-LAST:event_cboLoginModeItemStateChanged }//GEN-LAST:event_cboLoginModeItemStateChanged
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
if (!isLoading && cboProfiles.getSelectedIndex() != -1 && !StrUtils.isBlank((String) cboProfiles.getSelectedItem())) { if (!isLoading && cboProfiles.getSelectedIndex() != -1 && !StrUtils.isBlank((String) cboProfiles.getSelectedItem()))
Settings.getInstance().setLast((String) cboProfiles.getSelectedItem()); Settings.getInstance().setLast((String) cboProfiles.getSelectedItem());
loadMinecraftVersions();
}
}//GEN-LAST:event_cboProfilesItemStateChanged }//GEN-LAST:event_cboProfilesItemStateChanged
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
@@ -374,7 +377,7 @@ public class MainPagePanel extends AnimatedPanel {
return; return;
String suggestedModpackId = JOptionPane.showInputDialog("Please enter your favourite game name", FileUtils.getBaseName(fc.getSelectedFile().getName())); String suggestedModpackId = JOptionPane.showInputDialog("Please enter your favourite game name", FileUtils.getBaseName(fc.getSelectedFile().getName()));
TaskWindow.factory().append(ModpackManager.install(fc.getSelectedFile(), getProfile().service(), suggestedModpackId)).create(); TaskWindow.factory().append(ModpackManager.install(fc.getSelectedFile(), getProfile().service(), suggestedModpackId)).create();
loadMinecraftVersions(); getProfile().service().version().refreshVersions();
}//GEN-LAST:event_btnImportModpackActionPerformed }//GEN-LAST:event_btnImportModpackActionPerformed
private void btnExportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportModpackActionPerformed private void btnExportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportModpackActionPerformed
@@ -400,57 +403,6 @@ public class MainPagePanel extends AnimatedPanel {
Settings.getInstance().setLoginType(loginType); Settings.getInstance().setLoginType(loginType);
} }
} }
void loadFromSettings() {
for (Profile s : Settings.getProfilesFiltered())
cboProfiles.addItem(s.getName());
}
boolean showedNoVersion = false;
void loadMinecraftVersions() {
isLoading = true;
cboVersions.removeAllItems();
int index = 0, i = 0;
getProfile().selectedVersionChangedEvent.register(onVersionChanged);
getProfile().service().version().refreshVersions();
String selVersion = getProfile().getSelectedVersion();
if (getProfile().service().version().getVersions().isEmpty()) {
if (!showedNoVersion)
SwingUtilities.invokeLater(() -> {
if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
MainFrame.INSTANCE.invokeAction("showGameDownloads");
showedNoVersion = true;
});
} else {
for (MinecraftVersion mcVersion : getProfile().service().version().getVersions()) {
if (mcVersion.hidden)
continue;
cboVersions.addItem(mcVersion.id);
if (mcVersion.id.equals(selVersion))
index = i;
i++;
}
if (index < cboVersions.getItemCount())
cboVersions.setSelectedIndex(index);
}
isLoading = false;
}
private void refreshMinecrafts(String last) {
isLoading = true;
cboProfiles.removeAllItems();
loadFromSettings();
for (int i = 0; i < cboProfiles.getItemCount(); i++) {
String s = (String) cboProfiles.getItemAt(i);
if (s != null && s.equals(last)) {
cboProfiles.setSelectedIndex(i);
break;
}
}
isLoading = false;
loadMinecraftVersions();
}
//</editor-fold> //</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Private Variables"> // <editor-fold defaultstate="collapsed" desc="Private Variables">
@@ -462,12 +414,13 @@ public class MainPagePanel extends AnimatedPanel {
//</editor-fold> //</editor-fold>
public Profile getProfile() { public Profile getProfile() {
return Settings.getProfile((String) cboProfiles.getSelectedItem()); return Settings.getProfile(Settings.getInstance().getLast());
} }
@Override @Override
public void onSelected() { public void onSelected() {
refreshMinecrafts(Settings.getInstance().getLast()); super.onSelected();
Settings.onProfileLoading();
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
@@ -490,11 +443,6 @@ public class MainPagePanel extends AnimatedPanel {
private javax.swing.JTextField txtPlayerName; private javax.swing.JTextField txtPlayerName;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
final Event<String> onVersionChanged = (sender, v) -> {
cboVersions.setToolTipText(v);
return true;
};
final Event<IAuthenticator> onAuthChanged = (sender, l) -> { final Event<IAuthenticator> onAuthChanged = (sender, l) -> {
if (l.hasPassword()) { if (l.hasPassword()) {
pnlPassword.setVisible(true); pnlPassword.setVisible(true);
@@ -517,4 +465,55 @@ public class MainPagePanel extends AnimatedPanel {
return true; return true;
}; };
final Runnable onLoadingProfiles = this::loadProfiles;
private void loadProfiles() {
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (Profile s : Settings.getProfilesFiltered())
model.addElement(s.getName());
cboProfiles.setModel(model);
}
final Consumer<IMinecraftService> onRefreshedVersions = t -> {
if (getProfile().service() == t)
loadVersions();
};
boolean showedNoVersion = false;
void loadVersions() {
isLoading = true;
cboVersions.removeAllItems();
String selVersion = getProfile().getSelectedVersion();
if (getProfile().service().version().getVersions().isEmpty()) {
if (!showedNoVersion)
SwingUtilities.invokeLater(() -> {
if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
MainFrame.INSTANCE.invokeAction("showGameDownloads");
showedNoVersion = true;
});
} else {
for (MinecraftVersion mcVersion : getProfile().service().version().getVersions()) {
if (mcVersion.hidden)
continue;
cboVersions.addItem(mcVersion.id);
}
versionChanged.accept(selVersion);
}
isLoading = false;
}
final Consumer<String> versionChanged = this::versionChanged;
void versionChanged(String selectedVersion) {
((DefaultComboBoxModel) cboVersions.getModel()).setSelectedItem(selectedVersion);
cboVersions.setToolTipText(selectedVersion);
}
final Consumer<Profile> onSelectedProfilesChanged = t -> {
t.service().version().onRefreshedVersions.register(onRefreshedVersions);
t.selectedVersionChangedEvent.register(versionChanged);
((DefaultComboBoxModel) cboProfiles.getModel()).setSelectedItem(t.getName());
};
} }

View File

@@ -127,9 +127,7 @@ public final class NewProfileWindow extends javax.swing.JDialog {
private void txtNewProfileNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNewProfileNameKeyTyped private void txtNewProfileNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNewProfileNameKeyTyped
switch (evt.getKeyCode()) { switch (evt.getKeyCode()) {
case 13: case 13:
Profile newProfile = new Profile(Settings.getProfile(cboProfiles.getSelectedItem().toString())); act();
newProfile.setName(txtNewProfileName.getText());
Settings.trySetProfile(newProfile);
break; break;
case 27: case 27:
this.dispose(); this.dispose();
@@ -140,13 +138,16 @@ public final class NewProfileWindow extends javax.swing.JDialog {
}//GEN-LAST:event_txtNewProfileNameKeyTyped }//GEN-LAST:event_txtNewProfileNameKeyTyped
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
act();
}//GEN-LAST:event_btnOKActionPerformed
void act() {
if (!StrUtils.isBlank(txtNewProfileName.getText())) { if (!StrUtils.isBlank(txtNewProfileName.getText())) {
Profile newProfile = new Profile(Settings.getProfile(cboProfiles.getSelectedItem().toString())); Profile newProfile = new Profile(txtNewProfileName.getText(), Settings.getProfile(cboProfiles.getSelectedItem().toString()));
newProfile.setName(txtNewProfileName.getText()); Settings.putProfile(newProfile);
Settings.trySetProfile(newProfile);
} }
this.dispose(); this.dispose();
}//GEN-LAST:event_btnOKActionPerformed }
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.dispose(); this.dispose();

View File

@@ -24,4 +24,8 @@ package org.jackhuang.hellominecraft.launcher.ui;
public interface Selectable { public interface Selectable {
void onSelected(); void onSelected();
boolean isSelected();
void onLeaving();
} }

View File

@@ -91,6 +91,10 @@ public class DefaultMinecraftService extends IMinecraftService {
vs = C.GSON.fromJson(s, VersionSetting.class); vs = C.GSON.fromJson(s, VersionSetting.class);
} }
vs.id = id; vs.id = id;
vs.propertyChanged.register((sender, t) -> {
saveVersionSetting(((VersionSetting) sender).id);
return true;
});
versionSettings.put(id, vs); versionSettings.put(id, vs);
} }