Skip to content

Commit

Permalink
Add wiki links to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjabrain1 committed Sep 29, 2024
1 parent 6c292c7 commit 3021ca8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
32 changes: 32 additions & 0 deletions src/main/java/ninjabrainbot/gui/buttons/WikiButton.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Binary file added src/main/resources/help_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3021ca8

Please sign in to comment.