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

feat: Add hotkey option which opens sign search menu #10

Closed
wants to merge 5 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Build with Gradle
run: ./gradlew build --full-stacktrace
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/*-release.jar
11 changes: 9 additions & 2 deletions core/src/main/java/com/rappytv/signsearch/SignSearchAddon.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rappytv.signsearch;

import com.rappytv.signsearch.gui.settings.SignSearchSettingsActivity;
import com.rappytv.signsearch.listeners.KeyPressListener;
import com.rappytv.signsearch.listeners.PauseMenuListener;
import com.rappytv.signsearch.utils.SignManager;
import com.rappytv.signsearch.utils.SignSearchSettings;
Expand All @@ -13,15 +14,17 @@ public class SignSearchAddon extends LabyAddon<SignSearchConfiguration> {
private static SignSearchConfiguration config;
private static SignManager signManager;
private static SignSearchSettings searchSettings;
private SignSearchSettingsActivity settingsActivity;

@Override
protected void enable() {
registerSettingCategory();
config = configuration();
signManager = new SignManager();
searchSettings = new SignSearchSettings(config.enabled());
SignSearchSettingsActivity activity = new SignSearchSettingsActivity(searchSettings);
registerListener(new PauseMenuListener(activity));
settingsActivity = new SignSearchSettingsActivity(searchSettings);
registerListener(new KeyPressListener(this));
registerListener(new PauseMenuListener(settingsActivity));
}

@Override
Expand All @@ -40,4 +43,8 @@ public static SignManager getSignManager() {
public static SignSearchSettings getSearchSettings() {
return searchSettings;
}

public SignSearchSettingsActivity getSettingsActivity() {
return settingsActivity;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package com.rappytv.signsearch;

import net.labymod.api.addon.AddonConfig;
import net.labymod.api.client.gui.screen.key.Key;
import net.labymod.api.client.gui.screen.widget.widgets.input.KeybindWidget.KeyBindSetting;
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting;
import net.labymod.api.configuration.loader.property.ConfigProperty;

public class SignSearchConfiguration extends AddonConfig {

@SwitchSetting
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(true);

@KeyBindSetting
private final ConfigProperty<Key> menuHotkey = new ConfigProperty<>(Key.NONE);

@Override
public ConfigProperty<Boolean> enabled() {
return enabled;
}

public ConfigProperty<Key> menuHotkey() {
return menuHotkey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rappytv.signsearch.listeners;

import com.rappytv.signsearch.SignSearchAddon;
import net.labymod.api.Laby;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.input.KeyEvent;
import net.labymod.api.event.client.input.KeyEvent.State;

public class KeyPressListener {

private final SignSearchAddon addon;

public KeyPressListener(SignSearchAddon addon) {
this.addon = addon;
}

@Subscribe
public void onKeyDown(KeyEvent event) {
if(event.state() != State.PRESS
|| Laby.labyAPI().minecraft().minecraftWindow().isScreenOpened()
|| event.key() != addon.configuration().menuHotkey().get()) return;

Laby.labyAPI().minecraft().minecraftWindow().displayScreen(addon.getSettingsActivity());
}

}
3 changes: 3 additions & 0 deletions core/src/main/resources/assets/signsearch/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"settings": {
"enabled": {
"name": "Enabled"
},
"menuHotkey": {
"name": "Settings hotkey"
}
},
"ui": {
Expand Down