diff --git a/src/main/java/ninjabrainbot/gui/buttons/WikiButton.java b/src/main/java/ninjabrainbot/gui/buttons/WikiButton.java new file mode 100644 index 00000000..3b4ef056 --- /dev/null +++ b/src/main/java/ninjabrainbot/gui/buttons/WikiButton.java @@ -0,0 +1,32 @@ +package ninjabrainbot.gui.buttons; + +import java.awt.Desktop; +import java.net.URL; +import java.util.Objects; + +import javax.swing.ImageIcon; + +import ninjabrainbot.Main; +import ninjabrainbot.gui.style.StyleManager; + +public class WikiButton extends FlatButton { + + private final String wikiUrl; + + public WikiButton(StyleManager styleManager, String wikiUrl) { + super(styleManager, new ImageIcon(Objects.requireNonNull(Main.class.getResource("/help_icon.png")))); + this.wikiUrl = wikiUrl; + setBackgroundColor(styleManager.currentTheme.COLOR_NEUTRAL); + setHoverColor(styleManager.currentTheme.COLOR_NEUTRAL); + addActionListener(__ -> openWikiPageInBrowser()); + } + + private void openWikiPageInBrowser() { + try { + Desktop.getDesktop().browse(new URL(wikiUrl).toURI()); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/ninjabrainbot/gui/components/preferences/CheckboxPanel.java b/src/main/java/ninjabrainbot/gui/components/preferences/CheckboxPanel.java index 8e930ac8..5f535d93 100644 --- a/src/main/java/ninjabrainbot/gui/components/preferences/CheckboxPanel.java +++ b/src/main/java/ninjabrainbot/gui/components/preferences/CheckboxPanel.java @@ -6,6 +6,7 @@ import javax.swing.Box; +import ninjabrainbot.gui.buttons.WikiButton; import ninjabrainbot.gui.components.labels.ThemedLabel; import ninjabrainbot.gui.components.panels.ThemedPanel; import ninjabrainbot.gui.frames.OptionsFrame; @@ -35,7 +36,9 @@ public int getTextSize(SizePreference p) { } public Dimension getPreferredSize() { - return new Dimension(t.getWidth() - 2 * OptionsFrame.PADDING - 32, super.getPreferredSize().height); + Dimension superPreferredSize = super.getPreferredSize(); + int preferredWidth = Math.min(superPreferredSize.width, t.getWidth() - 2 * OptionsFrame.PADDING - 32); + return new Dimension(preferredWidth, superPreferredSize.height); } @Override @@ -60,6 +63,12 @@ public void onChanged(boolean ticked) { disabledCol = styleManager.currentTheme.TEXT_COLOR_WEAK; } + public CheckboxPanel withWikiButton(WikiButton wikiButton) { + add(Box.createHorizontalStrut(OptionsFrame.PADDING)); + add(wikiButton); + return this; + } + @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); diff --git a/src/main/java/ninjabrainbot/gui/options/sections/AdvancedOptionsPanel.java b/src/main/java/ninjabrainbot/gui/options/sections/AdvancedOptionsPanel.java index e78df7bb..363e3ce2 100644 --- a/src/main/java/ninjabrainbot/gui/options/sections/AdvancedOptionsPanel.java +++ b/src/main/java/ninjabrainbot/gui/options/sections/AdvancedOptionsPanel.java @@ -10,6 +10,7 @@ import ninjabrainbot.event.DisposeHandler; import ninjabrainbot.gui.buttons.FlatButton; +import ninjabrainbot.gui.buttons.WikiButton; import ninjabrainbot.gui.components.layout.StackPanel; import ninjabrainbot.gui.components.preferences.CheckboxPanel; import ninjabrainbot.gui.components.preferences.DoublePreferencePanel; @@ -91,7 +92,8 @@ public int getTextSize(SizePreference p) { column2.add(new CheckboxPanel(styleManager, I18n.get("settings.color_negative_coords"), preferences.colorCodeNegativeCoords)); column2.add(new CheckboxPanel(styleManager, I18n.get("settings.use_advanced_stronghold_statistics"), preferences.useAdvStatistics)); column2.add(new CheckboxPanel(styleManager, I18n.get("settings.use_alternative_clipboard_reader"), preferences.altClipboardReader)); - column2.add(new CheckboxPanel(styleManager, I18n.get("settings.enable_api"), preferences.enableHttpServer)); + column2.add(new CheckboxPanel(styleManager, I18n.get("settings.enable_api"), preferences.enableHttpServer) + .withWikiButton(new WikiButton(styleManager, "https://github.com/Ninjabrain1/Ninjabrain-Bot/wiki/API"))); disposeHandler.add(preferences.useAltStd.whenModified().subscribeEDT(this::setAltSigmaEnabled)); disposeHandler.add(preferences.sigma.whenModified().subscribeEDT(sigmaPanel::updateValue)); diff --git a/src/main/java/ninjabrainbot/gui/options/sections/AllAdvancementsOptionsPanel.java b/src/main/java/ninjabrainbot/gui/options/sections/AllAdvancementsOptionsPanel.java index c98d713c..db644c7b 100644 --- a/src/main/java/ninjabrainbot/gui/options/sections/AllAdvancementsOptionsPanel.java +++ b/src/main/java/ninjabrainbot/gui/options/sections/AllAdvancementsOptionsPanel.java @@ -2,6 +2,7 @@ import javax.swing.border.EmptyBorder; +import ninjabrainbot.gui.buttons.WikiButton; import ninjabrainbot.gui.components.labels.ThemedLabel; import ninjabrainbot.gui.components.layout.StackPanel; import ninjabrainbot.gui.components.preferences.CheckboxPanel; @@ -39,7 +40,8 @@ public int getTextSize(SizePreference p) { add(new CheckboxPanel(styleManager, I18n.get("settings.enable_all_advancements_mode"), preferences.allAdvancements)); - add(oneDotTwentyPlusAA = new CheckboxPanel(styleManager, I18n.get("settings.enable_120plus_all_advancements_mode"), preferences.oneDotTwentyPlusAA)); + add(oneDotTwentyPlusAA = new CheckboxPanel(styleManager, I18n.get("settings.enable_120plus_all_advancements_mode"), preferences.oneDotTwentyPlusAA) + .withWikiButton(new WikiButton(styleManager, "https://github.com/Ninjabrain1/Ninjabrain-Bot/wiki/All-advancements-mode-with-Minecraft-version-1.20-and-later"))); add(switchTypeRadioButtonPanel = new RadioButtonPanel(styleManager, I18n.get("settings.all_advancements.switch_type"), preferences.allAdvancementsToggleType, true)); add(toggleHotkeyPanel = new HotkeyPanel(styleManager, I18n.get("settings.all_advancements.toggle_aa_mode_hotkey"), preferences.hotkeyToggleAllAdvancementsMode)); diff --git a/src/main/java/ninjabrainbot/gui/options/sections/BoatMeasurementOptionsPanel.java b/src/main/java/ninjabrainbot/gui/options/sections/BoatMeasurementOptionsPanel.java index 5c7a38b1..138975d1 100644 --- a/src/main/java/ninjabrainbot/gui/options/sections/BoatMeasurementOptionsPanel.java +++ b/src/main/java/ninjabrainbot/gui/options/sections/BoatMeasurementOptionsPanel.java @@ -6,6 +6,7 @@ import javax.swing.border.EmptyBorder; import ninjabrainbot.event.DisposeHandler; +import ninjabrainbot.gui.buttons.WikiButton; import ninjabrainbot.gui.components.layout.StackPanel; import ninjabrainbot.gui.components.preferences.CheckboxPanel; import ninjabrainbot.gui.components.preferences.DoublePreferencePanel; @@ -36,8 +37,8 @@ public BoatMeasurementOptionsPanel(StyleManager styleManager, NinjabrainBotPrefe column1.setOpaque(false); add(column1); - CheckboxPanel enableBoatMeasurementsCheckbox = new CheckboxPanel(styleManager, I18n.get("settings.use_precise_angle"), preferences.usePreciseAngle); - column1.add(enableBoatMeasurementsCheckbox); + column1.add(new CheckboxPanel(styleManager, I18n.get("settings.use_precise_angle"), preferences.usePreciseAngle) + .withWikiButton(new WikiButton(styleManager, "https://github.com/Ninjabrain1/Ninjabrain-Bot/wiki/Boat-measurements"))); sensitivityManual = new FloatPreferencePanel(styleManager, I18n.get("settings.sensitivityManual"), preferences.sensitivityManual); sensitivityManual.setWidth(130); diff --git a/src/main/resources/help_icon.png b/src/main/resources/help_icon.png new file mode 100644 index 00000000..510e6b53 Binary files /dev/null and b/src/main/resources/help_icon.png differ