feat: add right click menu on Edit Mods dialog

This commit is contained in:
Ryan Dowling 2019-12-21 17:47:15 +11:00
parent 362d6c9c77
commit 1c485e78c9
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
9 changed files with 167 additions and 25 deletions

View file

@ -1,9 +1,5 @@
# Changelog
## 3.3.2.0
## 3.3.3.0
- Add in ability to download worlds from CurseForge
- Fix mods from curse able to be installed with no loader
- Add setting to disable add mod restrictions for instances
- Small tweak to save password warning (https://github.com/ATLauncher/ATLauncher/pull/376)
- Add Feral gamemode integration (https://github.com/ATLauncher/ATLauncher/pull/377/)
- Add right click menu on Edit Mods dialog

View file

@ -135,8 +135,15 @@ Revision should be incremented when there are no new features and only contains
previous minor.
Build is used for beta releases allowing you to have higher version numbers but force users to
update when the real
release comes.
update when the real release comes.
### Updating The Version
The version should be updated manually in the following files:
- CHANGELOG.md
- build.gradle
- /src/main/java/com/atlauncher/data/Constants.java
## Translating

View file

@ -26,7 +26,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
group = 'com.atlauncher'
version = '3.3.2.0'
version = '3.3.3.0'
repositories {
mavenCentral()

View file

@ -18,7 +18,7 @@
package com.atlauncher.data;
public class Constants {
public static final LauncherVersion VERSION = new LauncherVersion(3, 3, 2, 0);
public static final LauncherVersion VERSION = new LauncherVersion(3, 3, 3, 0);
public static final String LAUNCHER_NAME = "ATLauncher";
public static final String DISCORD_CLIENT_ID = "589393213723246592";
public static final String GA_TRACKING_ID = "UA-88820616-7";

View file

@ -31,6 +31,7 @@ import java.util.jar.JarOutputStream;
import com.atlauncher.FileSystem;
import com.atlauncher.LogManager;
import com.atlauncher.data.curse.CurseFile;
import com.atlauncher.data.curse.CurseMod;
import com.atlauncher.gui.dialogs.CurseModFileSelectorDialog;
import com.atlauncher.managers.DialogManager;
import com.atlauncher.network.Analytics;
@ -53,10 +54,12 @@ public class DisableableMod implements Serializable {
public boolean wasSelected = true; // Default to it being selected on install
public Integer curseModId;
public Integer curseFileId;
public CurseMod curseMod;
public CurseFile curseFile;
public DisableableMod(String name, String version, boolean optional, String file, Type type, Color colour,
String description, boolean disabled, boolean userAdded, boolean wasSelected, Integer curseModId,
Integer curseFileId) {
Integer curseFileId, CurseMod curseMod, CurseFile curseFile) {
this.name = name;
this.version = version;
this.optional = optional;
@ -69,16 +72,34 @@ public class DisableableMod implements Serializable {
this.wasSelected = wasSelected;
this.curseModId = curseModId;
this.curseFileId = curseFileId;
this.curseMod = curseMod;
this.curseFile = curseFile;
}
public DisableableMod(String name, String version, boolean optional, String file, Type type, Color colour,
String description, boolean disabled, boolean userAdded, boolean wasSelected, CurseMod curseMod,
CurseFile curseFile) {
this(name, version, optional, file, type, colour, description, disabled, userAdded, wasSelected, curseMod.id,
curseFile.id, curseMod, curseFile);
}
public DisableableMod(String name, String version, boolean optional, String file, Type type, Color colour,
String description, boolean disabled, boolean userAdded, boolean wasSelected, Integer curseModId,
Integer curseFileId) {
this(name, version, optional, file, type, colour, description, disabled, userAdded, wasSelected, curseModId,
curseFileId, null, null);
}
public DisableableMod(String name, String version, boolean optional, String file, Type type, Color colour,
String description, boolean disabled, boolean userAdded, boolean wasSelected) {
this(name, version, optional, file, type, colour, description, disabled, userAdded, wasSelected, null, null);
this(name, version, optional, file, type, colour, description, disabled, userAdded, wasSelected, null, null,
null, null);
}
public DisableableMod(String name, String version, boolean optional, String file, Type type, Color colour,
String description, boolean disabled, boolean userAdded) {
this(name, version, optional, file, type, colour, description, disabled, userAdded, true, null, null);
this(name, version, optional, file, type, colour, description, disabled, userAdded, true, null, null, null,
null);
}
public DisableableMod() {
@ -131,6 +152,10 @@ public class DisableableMod implements Serializable {
return this.curseModId != null && this.curseFileId != null;
}
public boolean hasFullCurseInformation() {
return this.curseMod != null && this.curseFile != null;
}
public Integer getCurseModId() {
return this.curseModId;
}

View file

@ -1767,8 +1767,9 @@ public class Instance implements Cloneable {
// add this mod
this.mods.add(new DisableableMod(mod.name, file.displayName, true, file.fileName,
mod.categorySection.gameCategoryId == Constants.CURSE_RESOURCE_PACKS_SECTION_ID ? Type.resourcepack
: (mod.categorySection.gameCategoryId == Constants.CURSE_WORLDS_SECTION_ID ? Type.worlds : Type.mods),
null, mod.summary, false, true, true, mod.id, file.id));
: (mod.categorySection.gameCategoryId == Constants.CURSE_WORLDS_SECTION_ID ? Type.worlds
: Type.mods),
null, mod.summary, false, true, true, mod, file));
this.save(false);

View file

@ -684,7 +684,7 @@ public class InstanceV2 extends MinecraftVersion {
mod.categorySection.gameCategoryId == Constants.CURSE_RESOURCE_PACKS_SECTION_ID ? Type.resourcepack
: (mod.categorySection.gameCategoryId == Constants.CURSE_WORLDS_SECTION_ID ? Type.worlds
: Type.mods),
null, mod.summary, false, true, true, mod.id, file.id));
null, mod.summary, false, true, true, mod, file));
this.save();

View file

@ -18,9 +18,14 @@
package com.atlauncher.gui.components;
import javax.swing.JCheckBox;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JToolTip;
import javax.swing.border.Border;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import com.atlauncher.App;
import com.atlauncher.builders.HTMLBuilder;
import com.atlauncher.data.DisableableMod;
@ -28,6 +33,10 @@ import com.atlauncher.data.json.Mod;
import com.atlauncher.gui.CustomLineBorder;
import com.atlauncher.gui.dialogs.EditModsDialog;
import com.atlauncher.gui.dialogs.ModsChooser;
import com.atlauncher.utils.OS;
import com.atlauncher.utils.Utils;
import org.mini2Dx.gettext.GetText;
/**
* This class extends {@link JCheckBox} and overrides the need to use JCheckBox
@ -36,18 +45,16 @@ import com.atlauncher.gui.dialogs.ModsChooser;
* hover tooltip for a mods description, as well as giving pack developers a way
* to colour mod's names.
*/
@SuppressWarnings("serial")
public class ModsJCheckBox extends JCheckBox {
/**
* Auto generated serial.
*/
private static final long serialVersionUID = -4560260483416099547L;
/**
* The mod this object will use to display it's data. Will be type {@link Mod},
* {@link com.atlauncher.data.json.Mod} or {@link DisableableMod}.
*/
private Object mod;
private EditModsDialog dialog;
/**
* Static object for the {@link Border} to show around the tooltips for mods
* with descriptions.
@ -59,31 +66,51 @@ public class ModsJCheckBox extends JCheckBox {
*
* @param mod The mod this object is displaying data for
*/
public ModsJCheckBox(Mod mod) {
public ModsJCheckBox(Mod mod, EditModsDialog dialog) {
super(mod.getName());
if (mod.hasColour() && mod.getCompiledColour() != null) {
setForeground(mod.getCompiledColour());
}
this.mod = mod;
this.dialog = dialog;
if (mod.hasDescription()) {
this.setToolTipText(new HTMLBuilder().text(mod.getDescription()).split(100).build());
}
}
public ModsJCheckBox(Mod mod) {
this(mod, null);
}
/**
* Constructor for use in the {@link EditModsDialog} dialog.
*
* @param mod The mod this object is displaying data for
*/
public ModsJCheckBox(DisableableMod mod) {
public ModsJCheckBox(DisableableMod mod, EditModsDialog dialog) {
super(mod.getName());
if (mod.hasColour()) {
setForeground(mod.getColour());
}
this.mod = mod;
this.dialog = dialog;
if (mod.getDescription() != null && !mod.getDescription().isEmpty()) {
this.setToolTipText(mod.getDescription());
}
if (this.dialog != null) {
setupContextMenu();
}
}
public ModsJCheckBox(DisableableMod mod) {
this(mod, null);
}
/**
@ -104,6 +131,92 @@ public class ModsJCheckBox extends JCheckBox {
return (DisableableMod) this.mod;
}
private void setupContextMenu() {
JPopupMenu contextMenu = new JPopupMenu();
if (getDisableableMod().hasFullCurseInformation()) {
JMenuItem openOnCurse = new JMenuItem(GetText.tr("Open On Curse"));
openOnCurse.addActionListener(e -> {
OS.openWebBrowser(getDisableableMod().curseMod.websiteUrl);
});
contextMenu.add(openOnCurse);
contextMenu.add(new JPopupMenu.Separator());
}
JMenuItem enableDisableButton = new JMenuItem(GetText.tr(getDisableableMod().disabled ? "Enable" : "Disable"));
enableDisableButton.addActionListener(e -> {
if (dialog.instance != null) {
if (getDisableableMod().disabled) {
getDisableableMod().enable(dialog.instance);
} else {
getDisableableMod().disable(dialog.instance);
}
} else if (dialog.instanceV2 != null) {
if (getDisableableMod().disabled) {
getDisableableMod().enable(dialog.instanceV2);
} else {
getDisableableMod().disable(dialog.instanceV2);
}
}
dialog.reloadPanels();
});
contextMenu.add(enableDisableButton);
contextMenu.add(new JPopupMenu.Separator());
JMenuItem remove = new JMenuItem(GetText.tr("Remove"));
remove.addActionListener(e -> {
if (dialog.instance != null) {
dialog.instance.removeInstalledMod(getDisableableMod());
} else if (dialog.instanceV2 != null) {
dialog.instanceV2.launcher.mods.remove(getDisableableMod());
Utils.delete((getDisableableMod().isDisabled() ? getDisableableMod().getDisabledFile(dialog.instanceV2)
: getDisableableMod().getFile(dialog.instanceV2)));
}
dialog.reloadPanels();
});
contextMenu.add(remove);
if (getDisableableMod().isFromCurse()) {
contextMenu.add(new JPopupMenu.Separator());
JMenuItem reinstall = new JMenuItem(GetText.tr("Reinstall"));
reinstall.addActionListener(e -> {
if (dialog.instance != null) {
getDisableableMod().reinstall(dialog.instance);
} else if (dialog.instanceV2 != null) {
getDisableableMod().reinstall(dialog.instanceV2);
}
dialog.reloadPanels();
});
contextMenu.add(reinstall);
JMenuItem checkForUpdates = new JMenuItem(GetText.tr("Check For Updates"));
checkForUpdates.addActionListener(e -> {
if (dialog.instance != null) {
getDisableableMod().checkForUpdate(dialog.instance);
} else if (dialog.instanceV2 != null) {
getDisableableMod().checkForUpdate(dialog.instanceV2);
}
dialog.reloadPanels();
});
contextMenu.add(checkForUpdates);
}
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
contextMenu.show(ModsJCheckBox.this, e.getX(), e.getY());
}
}
});
}
@Override
public JToolTip createToolTip() {
JToolTip tip = super.createToolTip();

View file

@ -289,7 +289,7 @@ public class EditModsDialog extends JDialog {
instanceV2.launcher.mods.add(mod);
} else {
instance.getInstalledMods().add(mod);
disabledMods.add(new ModsJCheckBox(mod));
disabledMods.add(new ModsJCheckBox(mod, this));
}
reload = true;
}
@ -363,7 +363,7 @@ public class EditModsDialog extends JDialog {
ModsJCheckBox checkBox = null;
int nameSize = getFontMetrics(Utils.getFont()).stringWidth(mod.getName());
checkBox = new ModsJCheckBox(mod);
checkBox = new ModsJCheckBox(mod, this);
if (mod.isDisabled()) {
checkBox.setBounds(0, (dCount * 20), Math.max(nameSize + 23, 250), 20);
disabledMods.add(checkBox);