|
| 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 | +} |
0 commit comments