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

Key Binds API #59

Draft
wants to merge 57 commits into
base: 1.20
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
fb28887
Begin Key Bindings API
EnnuiL Nov 28, 2021
f3564b5
Begin dynamic key binding system
EnnuiL Nov 30, 2021
c727b5a
Further progress on Key Binding API
EnnuiL Nov 30, 2021
bd1f189
More API progress
EnnuiL Dec 2, 2021
310c5f0
All ready for a draft PR!
EnnuiL Dec 2, 2021
c277d51
Hm, maybe it's not bad after all
EnnuiL Dec 2, 2021
86aba91
Address suggestions
EnnuiL Dec 2, 2021
bffed77
Minor tweaks and enhancements
EnnuiL Dec 3, 2021
abf6058
Progress...?
EnnuiL Dec 3, 2021
ac3ce12
Fix typos and checkstyle issues
EnnuiL Dec 5, 2021
a88ce91
Apply suggestions, fix AW
EnnuiL Dec 5, 2021
ae115f8
Small progress!
EnnuiL Dec 5, 2021
42e5839
But wait, there's more!
EnnuiL Dec 5, 2021
00043a5
Improve tooltip formatting
EnnuiL Dec 5, 2021
156723e
Progress progress progress
EnnuiL Dec 7, 2021
757b3cd
Fix key binding manager
EnnuiL Dec 8, 2021
b547b72
Add "Middle Button to Unbind" behavior
EnnuiL Dec 9, 2021
aaa1290
oof
EnnuiL Dec 9, 2021
58ba479
Fix conflict tooltips
EnnuiL Dec 9, 2021
fd21328
Add registry test, progress
EnnuiL Dec 9, 2021
dd28d6d
Mappings update
EnnuiL Dec 10, 2021
80c2490
Finish the v1 feature set
EnnuiL Dec 10, 2021
1da6af0
Fix issues
EnnuiL Dec 10, 2021
f38908b
whyyyyyyyyy
EnnuiL Dec 11, 2021
ae29f50
Remove "Middle Click to Unbind"
EnnuiL Dec 11, 2021
709341b
Begin refactor to Key Binds, cleanup tooltip mixin
EnnuiL Feb 11, 2022
e585386
Attempt to remove an unchangable file
EnnuiL Feb 11, 2022
f8db037
Add back Brazilian Portuguese translation (1)
EnnuiL Feb 11, 2022
ffe0758
Update to 22w06a, fix license and testmod
EnnuiL Feb 11, 2022
3c20a93
Depend on resource loader
EnnuiL Feb 11, 2022
0dbac3c
Use the mappings refactor (I)
EnnuiL Feb 19, 2022
04b1b4d
Use the mappings refactor (II)
EnnuiL Feb 20, 2022
ac51db4
Actually fix the Brazilian Portuguese translation
EnnuiL Feb 20, 2022
9acea91
Move to QSL event entrypoints
EnnuiL Feb 20, 2022
16ba2a0
Fix conflict tooltips
EnnuiL Feb 20, 2022
38c18f1
Begin Pink's config system and key chords
EnnuiL Mar 2, 2022
2ad3f63
Apply license; Use sorted maps for chords
EnnuiL Mar 12, 2022
029225d
Add chord support for conflict warnings (I)
EnnuiL Mar 13, 2022
5233854
Uh, licença
EnnuiL Mar 13, 2022
4b366c2
Fix conflict tooltips
EnnuiL Mar 14, 2022
70f4f34
Begin to use FastUtils, add overflow hiding, more!
EnnuiL Mar 15, 2022
a2f180f
Pacify Checkstyle
EnnuiL Mar 15, 2022
a6cbfda
Fix lack of conflicts with the chord map
EnnuiL Mar 15, 2022
f10008d
Allow for setting default chords
EnnuiL Mar 28, 2022
1009b0f
Quiltify Key Binds API, tackle down config issues
EnnuiL Apr 11, 2022
6b19c80
Push changes done to config
EnnuiL Apr 17, 2022
a48e4d1
Fix stuff
EnnuiL Apr 27, 2022
110d0c6
Begin to overhaul toggling
EnnuiL Apr 29, 2022
841bdec
Recalculating
EnnuiL May 1, 2022
3b9b425
Refactor the key bind registry
EnnuiL May 2, 2022
0365268
Begin port to 1.19
EnnuiL Jun 17, 2022
f25afdc
Apply licenses
EnnuiL Jun 17, 2022
336531b
Fix config system
EnnuiL Jul 23, 2022
a161416
Reignite work on Key Binds API
EnnuiL Jul 23, 2022
0b2e598
keyboard mash
EnnuiL Aug 27, 2022
1286571
Partially port key binds api to 1.20
EnnuiL Jun 24, 2023
2d78d04
Merge branch '1.20' into 1.18
EnnuiL Jun 24, 2023
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
3 changes: 3 additions & 0 deletions build-logic/src/main/groovy/qsl.common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ dependencies {
modImplementation "org.quiltmc:quilt-loader:${Versions.LOADER_VERSION}"
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release.set(Versions.JAVA_VERSION)
Expand Down
25 changes: 25 additions & 0 deletions library/gui/key_binds/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id("qsl.module")
}

qslModule {
name = "Quilt Key Binds API"
moduleName = "key_binds"
id = "quilt_key_binds"
description = "Key binds registration and utilities."
moduleDependencies {
core {
api("resource_loader")
api("qsl_base")
testmodOnly("lifecycle_events")
}
}
clientOnly()
injectedInterface("net/minecraft/class_304") {
values = [
"org/quiltmc/qsl/key/binds/api/ChordedKeyBind",
"org/quiltmc/qsl/key/binds/api/QuiltKeyBind",
"org/quiltmc/qsl/key/binds/api/ToggleableKeyBind"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.key.binds.api;

import com.mojang.blaze3d.platform.InputUtil;

import net.minecraft.client.option.KeyBind;

import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.base.api.util.InjectedInterface;
import org.quiltmc.qsl.key.binds.impl.chords.KeyChord;

// TODO - Explain what are key chords.
/**
* An interface that adds key chord support to key binds.
*/
@ClientOnly
@InjectedInterface(KeyBind.class)
public interface ChordedKeyBind {
/**
* Gets the bound key chord of the key bind.
*
* @return the key bind's bound key chord.
*/
default KeyChord getBoundChord() {
throw new IllegalStateException("Mixin injection failed.");
}

/**
* Sets the bound key chord of the key bind.
*/
default void setBoundChord(KeyChord chord) {}

// TODO - This is a temporary measure until Chasm arrives. Replace it with a proper constructor or builder
/**
* Specifies the default key chord for the key bind.
* <p>
* This method is to be used only on creating a key bind instance.
*
* @param keys the keys of the default key chord
* @return the original key bind instance
*/
default KeyBind withChord(InputUtil.Key... keys) {
throw new IllegalStateException("Mixin injection failed.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021-2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.key.binds.api;

import java.util.List;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.client.option.KeyBind;

import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.key.binds.impl.KeyBindRegistryImpl;

// TODO - This isn't a registry anymore; What the heck should it be named?
/**
* Handles the registration of modded key binds and allows for changing their properties,
* such as their state.
*
* <p>This class also allows for getting key binds registered by other mods.
*/
@ClientOnly
public class KeyBindRegistry {
// TODO - Shouldn't we use Vanilla's Map for getAllKeyBinds instead? Two birds, one stone, zero thoughts, head empty
/**
* Searches for a modded key bind with the specified translation key in the registry.
*
* @param translationKey the key bind's translation key
* @return the key bind if found, {@code null} otherwise
*/
public static KeyBind getKeyBind(String translationKey) {
return KeyBindRegistryImpl.getKeyBind(translationKey);
}

/**
* Returns a list containing all key binds.
*
* @return a list containing key binds
*/
public static List<KeyBind> getAllKeyBinds() {
return KeyBindRegistryImpl.getAllKeyBinds();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.key.binds.api;

import com.mojang.blaze3d.platform.InputUtil;

import net.minecraft.client.option.KeyBind;

import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.base.api.util.InjectedInterface;

/**
* An injected interface for KeyBind that adds few Quilt-relevant utility methods.
*/
@ClientOnly
@InjectedInterface(KeyBind.class)
public interface QuiltKeyBind {
/**
* Gets whenever the key bind is from Vanilla or not.
* This is automatically determined by using GameOptions' allKeys property.
*
* @return {@code true} if the key bind is from Vanilla, or {@code false} otherwise
*/
default boolean isVanilla() {
throw new IllegalStateException("Mixin injection failed.");
}

/**
* Gets the bound key of the key bind.
*
* <p>The bound key is only directly used by the key bind system's internal logic.
* If possible, use the methods provided by the KeyBind class instead.
*
* @return the key bind's bound key
*/
default InputUtil.Key getBoundKey() {
throw new IllegalStateException("Mixin injection failed.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.key.binds.api;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.client.option.KeyBind;

import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.base.api.util.InjectedInterface;

// TODO - Add Javadocs; You can nab the ones from KeyBindRegistry
/**
* An interface for adding toggling capabilities to key binds.
*/
@ClientOnly
@InjectedInterface(KeyBind.class)
public interface ToggleableKeyBind {
/**
* Gets whenever the key bind is enabled or not.
*
* @return {@code true} if the key bind is enabled, {@code false} otherwise
*/
default boolean isEnabled() {
throw new IllegalStateException("Mixin injection failed.");
}

/**
* Gets whenever the key bind is disabled or not.
*
* @return {@code true} if the key bind is disabled, {@code false} otherwise
*/
default boolean isDisabled() {
throw new IllegalStateException("Mixin injection failed.");
}

/**
* Gets whenever the key bind can be disabled or not.
*
* @return {@code true} if the key bind can be disabled, {@code false} otherwise
*/
default boolean canDisable() {
throw new IllegalStateException("Mixin injection failed.");
}

/**
* Enables the key bind.
* <p>
* If the key bind has been disabled more than once, this method will only
* decrement its internal counter instead of enabling the key bind.
*/
default void enable() {
throw new IllegalStateException("Mixin injection failed.");
}

/**
* Disables the key bind.
* <p>
* When a key bind is disabled, it is effectively hidden from the game,
* being non-existent to it. config/quilt/key_binds.json, however, will
* still remember the key bind's bound keys, similar to non-existent key binds.
* <p>
* If the key bind is disabled while already disabled, it will be increment
* an internal counter, making the next enable only decrement it instead of
* enabling the key bind.
*/
default void disable() {
throw new IllegalStateException("Mixin injection failed.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.key.binds.impl;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public interface InternalQuiltKeyBind {
void markAsVanilla();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021-2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.key.binds.impl;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.KeyBind;

import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.key.binds.mixin.client.GameOptionsAccessor;

@ClientOnly
@ApiStatus.Internal
public class KeyBindManager {
private final GameOptions options;
private final KeyBind[] allKeys;

public KeyBindManager(GameOptions options, KeyBind[] allKeys) {
this.options = options;
this.allKeys = allKeys;
}

public void addModdedKeyBinds() {
((GameOptionsAccessor) this.options).setAllKeys(KeyBindRegistryImpl.getKeyBinds());
}

public KeyBind[] getAllKeys() {
return this.allKeys;
}
}
Loading