Skip to content

Commit 5fed750

Browse files
allow configuring markers via the gui
1 parent 42eb191 commit 5fed750

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.quiltmc.enigma.gui.element.menu_bar.view;
2+
3+
import org.quiltmc.config.api.values.TrackedValue;
4+
import org.quiltmc.enigma.gui.Gui;
5+
import org.quiltmc.enigma.gui.config.Config;
6+
import org.quiltmc.enigma.gui.config.EntryMarkersSection;
7+
import org.quiltmc.enigma.gui.element.menu_bar.AbstractEnigmaMenu;
8+
import org.quiltmc.enigma.util.I18n;
9+
10+
import javax.swing.JCheckBoxMenuItem;
11+
import javax.swing.JMenu;
12+
13+
public class EntryMarkersMenu extends AbstractEnigmaMenu {
14+
private static void syncStateWithConfig(JCheckBoxMenuItem box, TrackedValue<Boolean> config) {
15+
box.setState(config.value());
16+
17+
box.addActionListener(e -> {
18+
final boolean checked = box.getState();
19+
if (checked != config.value()) {
20+
config.setValue(checked);
21+
}
22+
});
23+
24+
config.registerCallback(updated -> {
25+
final boolean configured = updated.value();
26+
if (configured != box.getState()) {
27+
box.setState(configured);
28+
}
29+
});
30+
}
31+
32+
private final JCheckBoxMenuItem interactable = new JCheckBoxMenuItem();
33+
34+
private final JMenu markMenu = new JMenu();
35+
private final JCheckBoxMenuItem markObfuscated = new JCheckBoxMenuItem();
36+
private final JCheckBoxMenuItem markFallback = new JCheckBoxMenuItem();
37+
private final JCheckBoxMenuItem markProposed = new JCheckBoxMenuItem();
38+
private final JCheckBoxMenuItem markDeobfuscated = new JCheckBoxMenuItem();
39+
40+
public EntryMarkersMenu(Gui gui) {
41+
super(gui);
42+
43+
this.add(this.interactable);
44+
45+
this.markMenu.add(this.markObfuscated);
46+
this.markMenu.add(this.markFallback);
47+
this.markMenu.add(this.markProposed);
48+
this.markMenu.add(this.markDeobfuscated);
49+
50+
this.add(this.markMenu);
51+
52+
final EntryMarkersSection markerConfig = Config.editor().entryMarkers;
53+
syncStateWithConfig(this.interactable, markerConfig.interactable);
54+
syncStateWithConfig(this.markObfuscated, markerConfig.markObfuscated);
55+
syncStateWithConfig(this.markFallback, markerConfig.markFallback);
56+
syncStateWithConfig(this.markProposed, markerConfig.markProposed);
57+
syncStateWithConfig(this.markDeobfuscated, markerConfig.markDeobfuscated);
58+
59+
this.retranslate();
60+
}
61+
62+
@Override
63+
public void retranslate() {
64+
this.setText(I18n.translate("menu.view.entry_markers"));
65+
66+
this.interactable.setText(I18n.translate("menu.view.entry_markers.interactable"));
67+
68+
this.markMenu.setText(I18n.translate("menu.view.entry_markers.mark"));
69+
70+
this.markObfuscated.setText(I18n.translate("menu.view.entry_markers.mark.obfuscated"));
71+
this.markFallback.setText(I18n.translate("menu.view.entry_markers.mark.fallback"));
72+
this.markProposed.setText(I18n.translate("menu.view.entry_markers.mark.proposed"));
73+
this.markDeobfuscated.setText(I18n.translate("menu.view.entry_markers.mark.deobfuscated"));
74+
}
75+
}

enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/menu_bar/view/ViewMenu.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ViewMenu extends AbstractEnigmaMenu {
1515
private final ThemesMenu themes;
1616
private final ScaleMenu scale;
1717
private final SelectionHighlightMenu selectionHighlight;
18+
private final EntryMarkersMenu entryMarkers;
1819

1920
private final JMenuItem fontItem = new JMenuItem();
2021

@@ -26,13 +27,15 @@ public ViewMenu(Gui gui) {
2627
this.themes = new ThemesMenu(gui);
2728
this.scale = new ScaleMenu(gui);
2829
this.selectionHighlight = new SelectionHighlightMenu(gui);
30+
this.entryMarkers = new EntryMarkersMenu(gui);
2931

3032
this.add(this.themes);
3133
this.add(this.selectionHighlight);
3234
this.add(this.languages);
3335
this.add(this.notifications);
3436
this.add(this.scale);
3537
this.add(this.stats);
38+
this.add(this.entryMarkers);
3639
this.add(this.fontItem);
3740

3841
this.fontItem.addActionListener(e -> this.onFontClicked(this.gui));
@@ -48,6 +51,7 @@ public void retranslate() {
4851
this.scale.retranslate();
4952
this.stats.retranslate();
5053
this.selectionHighlight.retranslate();
54+
this.entryMarkers.retranslate();
5155
this.fontItem.setText(I18n.translate("menu.view.font"));
5256
}
5357

enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ Optional<MarkerParams> getParams(Token token, TokenType type, TokenStore tokenSt
511511
? Optional.of(new MarkerParams(colors.obfuscatedOutline.value(), OBFUSCATED_PRIORITY))
512512
: Optional.empty();
513513
case DEOBFUSCATED -> this.deobfuscated
514-
? Optional.of(new MarkerParams(colors.deobfuscated.value(), DEOBFUSCATED_PRIORITY))
514+
? Optional.of(new MarkerParams(colors.deobfuscatedOutline.value(), DEOBFUSCATED_PRIORITY))
515515
: Optional.empty();
516516
case JAR_PROPOSED, DYNAMIC_PROPOSED -> this.proposed
517517
? Optional.of(new MarkerParams(colors.proposedOutline.value(), PROPOSED_PRIORITY))

enigma/src/main/resources/lang/en_us.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@
9191
"menu.view.stat_icons.count_fallback": "Count fallback-proposed names",
9292
"menu.view.stat_icons.included_types": "Included types",
9393
"menu.view.stat_icons.enable_icons": "Enable icons",
94+
"menu.view.entry_markers": "Entry Markers",
95+
"menu.view.entry_markers.interactable": "Clickable markers",
96+
"menu.view.entry_markers.mark": "Mark entries",
97+
"menu.view.entry_markers.mark.obfuscated": "Obfuscated",
98+
"menu.view.entry_markers.mark.fallback": "Fallback",
99+
"menu.view.entry_markers.mark.proposed": "Proposed",
100+
"menu.view.entry_markers.mark.deobfuscated": "Deobfuscated",
94101
"menu.view.font": "Fonts...",
95102
"menu.view.change.title": "Changes",
96103
"menu.view.change.summary": "Changes will be applied after the next restart.",

0 commit comments

Comments
 (0)