Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to quilt config #167

Merged
merged 26 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.concurrent.CopyOnWriteArrayList;

public abstract class EnigmaServer {
// https://discordapp.com/channels/507304429255393322/566418023372816394/700292322918793347
public static final int DEFAULT_PORT = 34712;
public static final int PROTOCOL_VERSION = 1;
public static final int CHECKSUM_SIZE = 20;
Expand Down
1 change: 1 addition & 0 deletions enigma-swing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation libs.jopt
implementation libs.flatlaf
implementation libs.flatlaf.extras // for SVG icons
implementation libs.quilt.config
implementation libs.swing.dpi
implementation libs.fontchooser
testImplementation(testFixtures(project(':enigma')))
Expand Down
48 changes: 21 additions & 27 deletions enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import org.quiltmc.enigma.api.analysis.EntryReference;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper;
import org.quiltmc.enigma.gui.config.NetConfig;
import org.quiltmc.enigma.gui.config.Themes;
import org.quiltmc.enigma.gui.config.UiConfig;
import org.quiltmc.enigma.gui.config.Config;
import org.quiltmc.enigma.gui.dialog.JavadocDialog;
import org.quiltmc.enigma.gui.dialog.SearchDialog;
import org.quiltmc.enigma.gui.docker.AllClassesDocker;
Expand Down Expand Up @@ -131,7 +129,6 @@ public Gui(EnigmaProfile profile, Set<EditableType> editableTypes, boolean visib
this.setupUi();

LanguageUtil.addListener(this::retranslateUi);
Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame()));

this.mainWindow.setVisible(visible);
}
Expand All @@ -147,6 +144,10 @@ private void setupDockers() {
this.dockerManager.registerDocker(new AllClassesDocker(this));
this.dockerManager.registerDocker(new DeobfuscatedClassesDocker(this));

if (Config.dockers().buttonLocations.value().isEmpty()) {
Config.dockers().updateButtonLocations(this.dockerManager);
}

// set default docker sizes
for (Docker docker : this.dockerManager.getDockers()) {
docker.setPreferredSize(new Dimension(300, 100));
Expand Down Expand Up @@ -190,11 +191,7 @@ private void setupUi() {
this.splitRight.setResizeWeight(1);
this.splitLeft.setResizeWeight(0);

if (UiConfig.getHostedDockers(this.dockerManager, Docker.Side.LEFT).isPresent() || UiConfig.getHostedDockers(this.dockerManager, Docker.Side.RIGHT).isPresent()) {
this.dockerManager.restoreStateFromConfig();
} else {
this.dockerManager.setupDefaultConfiguration();
}
this.dockerManager.restoreStateFromConfig();

// init state
this.setConnectionState(ConnectionState.NOT_CONNECTED);
Expand All @@ -203,16 +200,12 @@ private void setupUi() {
JFrame frame = this.mainWindow.getFrame();
frame.addWindowListener(GuiUtil.onWindowClose(e -> this.close()));

frame.setSize(UiConfig.getWindowSize(UiConfig.MAIN_WINDOW, ScaleUtil.getDimension(1024, 576)));
frame.setSize(Config.main().windowSize.value().toDimension());
frame.setMinimumSize(ScaleUtil.getDimension(640, 480));
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

Point windowPos = UiConfig.getWindowPos(UiConfig.MAIN_WINDOW, null);
if (windowPos != null) {
frame.setLocation(windowPos);
} else {
frame.setLocationRelativeTo(null);
}
Point windowPos = Config.main().windowPos.value().toPoint();
frame.setLocation(windowPos);

this.retranslateUi();
}
Expand Down Expand Up @@ -514,11 +507,12 @@ public void close() {
}

private void exit() {
UiConfig.setWindowPos(UiConfig.MAIN_WINDOW, this.mainWindow.getFrame().getLocationOnScreen());
UiConfig.setWindowSize(UiConfig.MAIN_WINDOW, this.mainWindow.getFrame().getSize());
this.dockerManager.getLeftDock().saveDividerState();
this.dockerManager.getRightDock().saveDividerState();
Config.main().windowPos.setValue(Config.Vec2i.fromPoint(this.mainWindow.getFrame().getLocationOnScreen()), true);
Config.main().windowSize.setValue(Config.Vec2i.fromDimension(this.mainWindow.getFrame().getSize()), true);

this.dockerManager.saveStateToConfig();
UiConfig.save();
Config.main().save();

this.searchDialog.dispose();
this.mainWindow.getFrame().dispose();
Expand Down Expand Up @@ -614,17 +608,17 @@ public void addMessage(ServerMessage message) {
// popup notifications
switch (message.getType()) {
case CHAT -> {
if (UiConfig.getServerNotificationLevel().equals(NotificationManager.ServerNotificationLevel.FULL) && !message.user.equals(NetConfig.getUsername())) {
if (Config.main().serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.net().username.value())) {
this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_CHAT, message.translate()));
}
}
case CONNECT -> {
if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) {
if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) {
this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_CONNECTED, message.translate()));
}
}
case DISCONNECT -> {
if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) {
if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) {
this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_LEFT, message.translate()));
}
}
Expand Down Expand Up @@ -698,11 +692,11 @@ public void reloadKeyBinds() {
}

public void openMostRecentFiles() {
var pair = UiConfig.getMostRecentFilePair();
Config.RecentProject project = Config.getMostRecentProject();

if (pair.isPresent()) {
this.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.get().a().toString(), pair.get().b().toString()));
this.controller.openJar(pair.get().a()).whenComplete((v, t) -> this.controller.openMappings(pair.get().b()));
if (project != null) {
this.getNotificationManager().notify(ParameterizedMessage.openedProject(project.jarPath(), project.mappingsPath()));
this.controller.openJar(project.getJarPath()).whenComplete((v, t) -> this.controller.openMappings(project.getMappingsPath()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import org.quiltmc.enigma.api.class_handle.ClassHandle;
import org.quiltmc.enigma.api.class_handle.ClassHandleProvider;
import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider;
import org.quiltmc.enigma.gui.config.NetConfig;
import org.quiltmc.enigma.gui.config.UiConfig;
import org.quiltmc.enigma.gui.config.Config;
import org.quiltmc.enigma.gui.dialog.ProgressDialog;
import org.quiltmc.enigma.gui.docker.CollabDocker;
import org.quiltmc.enigma.api.stats.StatType;
Expand Down Expand Up @@ -125,7 +124,7 @@ public CompletableFuture<Void> openJar(final Path jarPath) {
return ProgressDialog.runOffThread(this.gui, progress -> {
this.project = this.enigma.openJar(jarPath, new ClasspathClassProvider(), progress);
this.indexTreeBuilder = new IndexTreeBuilder(this.project.getJarIndex());
this.chp = new ClassHandleProvider(this.project, UiConfig.getDecompiler().service);
this.chp = new ClassHandleProvider(this.project, Config.decompiler().activeDecompiler.value().service);
this.statsGenerator = new StatsGenerator(this.project);

SwingUtilities.invokeLater(() -> {
Expand Down Expand Up @@ -153,7 +152,7 @@ public CompletableFuture<Void> openMappings(MappingFormat format, Path path) {
}

this.gui.setMappingsFile(path);
UiConfig.addRecentFilePair(this.project.getJarPath(), path);
Config.insertRecentProject(this.project.getJarPath().toString(), path.toString());
this.gui.getMenuBar().reloadOpenRecentMenu(this.gui);

return ProgressDialog.runOffThread(this.gui, progress -> {
Expand Down Expand Up @@ -557,7 +556,7 @@ private void applyChange0(ValidationContext vc, EntryChange<?> change, boolean u
public void openStatsTree(Set<StatType> includedTypes) {
ProgressDialog.runOffThread(this.gui, progress -> {
StatsResult overall = this.getStatsGenerator().getResultNullable().getOverall();
StatsTree<Integer> tree = overall.buildTree(UiConfig.getLastTopLevelPackage(), includedTypes);
StatsTree<Integer> tree = overall.buildTree(Config.main().stats.lastTopLevelPackage.value(), includedTypes);
String treeJson = GSON.toJson(tree.root);

try {
Expand Down Expand Up @@ -619,7 +618,7 @@ public void createServer(int port, char[] password) throws IOException {
this.server.start();
this.client = new EnigmaClient(this, "127.0.0.1", port);
this.client.connect();
this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, NetConfig.getUsername()));
this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, Config.net().username.value()));
this.gui.setConnectionState(ConnectionState.HOSTING);
}

Expand Down Expand Up @@ -648,7 +647,7 @@ public synchronized void disconnectIfConnected(String reason) {
});

this.gui.setUserList(new ArrayList<>());
if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) {
if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) {
this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.LEFT_SERVER));
}

Expand Down
14 changes: 7 additions & 7 deletions enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.quiltmc.enigma.api.EnigmaProfile;
import org.quiltmc.enigma.gui.config.keybind.KeyBinds;
import org.quiltmc.enigma.gui.config.Themes;
import org.quiltmc.enigma.gui.config.UiConfig;
import org.quiltmc.enigma.gui.config.theme.Themes;
import org.quiltmc.enigma.gui.config.Config;
import org.quiltmc.enigma.gui.dialog.CrashDialog;
import org.quiltmc.enigma.util.I18n;
import org.quiltmc.enigma.util.validation.Message;
Expand Down Expand Up @@ -96,7 +96,7 @@ public static void main(String[] args) throws IOException {

EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile));

I18n.setLanguage(UiConfig.getLanguage());
I18n.setLanguage(Config.main().language.value());
setDefaultSystemProperty("apple.laf.useScreenMenuBar", "true");
setDefaultSystemProperty("awt.useSystemAAFontSettings", "on");
setDefaultSystemProperty("swing.aatext", "true");
Expand Down Expand Up @@ -131,10 +131,10 @@ public static void main(String[] args) throws IOException {
gui.getNotificationManager().notify(ParameterizedMessage.openedProject(jarPath.toString(), mappingsPath.toString()));
} else {
// search for mappings that are associated with the jar
for (var pair : UiConfig.getRecentFilePairs()) {
if (pair.a().equals(jarPath)) {
gui.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.a().toString(), pair.b().toString()));
gui.getController().openMappings(pair.b());
for (Config.RecentProject recentProject : Config.main().recentProjects.value()) {
if (recentProject.getJarPath().equals(jarPath)) {
gui.getNotificationManager().notify(ParameterizedMessage.openedProject(recentProject.jarPath(), recentProject.mappingsPath()));
gui.getController().openMappings(recentProject.getMappingsPath());
break;
}
}
Expand Down
Loading