-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Keyboard #659
Open
SirEndii
wants to merge
17
commits into
dev/0.8
Choose a base branch
from
feat/keyboard
base: dev/0.8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Keyboard #659
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8bc766d
[IntelligenceModding/Advanced-Peripherals-Features#59] Keyboard item …
SirEndii 6695fda
Remove custom indentation
SirEndii 027787b
Binding/Unbinding for the keyboard
SirEndii 19f4de9
Use translatable components and add name and description for the keyb…
SirEndii c507f0a
Removed owner tag from the memory card
SirEndii ab6a8cd
Key press/Char typed sync to the computer logic
SirEndii 5af40a8
The keyboard is now a working module, it currently uses the hotkey mo…
SirEndii b94b8be
Mouse events for the keyboard module
SirEndii 9ba1214
Fixed an issue where the keyboard does not bound to the glasses when …
SirEndii e8f70d7
Render a little info text when the player is using the keyboard
SirEndii 1b147a3
Preven JEI/REI/EMI from rendering in the keyboard screen
SirEndii 48ce6e5
Merge branch 'dev/0.8' into feat/keyboard
SirEndii b689497
checkstyle
SirEndii 36193be
Simplify KeyboardScreen
SirEndii 5e439b9
Sort ClientRegistry.java
SirEndii a7c5984
Merge branch 'dev/0.8' into feat/keyboard
SirEndii f5efd86
Add language entries
SirEndii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 17 additions & 17 deletions
34
src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// 1.19.2 2024-05-28T14:53:16.656615 LootTables | ||
d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json | ||
a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json | ||
f50f506ae1987537f76be4c05a81689b25798f91 data/advancedperipherals/loot_tables/blocks/colony_integrator.json | ||
4dcad851450e4ddd8d28a0017a417bf6e5579bda data/advancedperipherals/loot_tables/blocks/distance_detector.json | ||
1d1b858d09538dc66bab2c33a2f9c58361a9c472 data/advancedperipherals/loot_tables/blocks/energy_detector.json | ||
317004b1358ef9bf83957d2d6796529a226161c7 data/advancedperipherals/loot_tables/blocks/environment_detector.json | ||
df6186990887f77b7db37ebb8ee50a7e7f096b0a data/advancedperipherals/loot_tables/blocks/fluid_detector.json | ||
cea5a036d4ccdcc6ef026d1a226b5e13f1060676 data/advancedperipherals/loot_tables/blocks/gas_detector.json | ||
d5a3964f518b138cbd7305c819a36af3d9340e4a data/advancedperipherals/loot_tables/blocks/geo_scanner.json | ||
8aa1deea908fd02f049e047c8ca16679bbef68a2 data/advancedperipherals/loot_tables/blocks/inventory_manager.json | ||
9a2898a63e2e0c087ce8eba211c63d1c8b9fd4aa data/advancedperipherals/loot_tables/blocks/me_bridge.json | ||
973770040bacb61482adb9739fd1d977f16c107f data/advancedperipherals/loot_tables/blocks/nbt_storage.json | ||
b4b80e8c9d62b53d9252cdfc5918c077d3a01f6e data/advancedperipherals/loot_tables/blocks/peripheral_casing.json | ||
58b6adbea5d4ae43ed9af0b627df2b8a4907acde data/advancedperipherals/loot_tables/blocks/player_detector.json | ||
a58aebcc52684302968e7af4f50a12aff93aaf2d data/advancedperipherals/loot_tables/blocks/redstone_integrator.json | ||
0ef1678f88b8fcb744bfd95261f66745340be8f4 data/advancedperipherals/loot_tables/blocks/rs_bridge.json | ||
// 1.19.2 2024-09-23T21:28:44.4809605 LootTables | ||
618b63c020ab64890c8a2d2506dd61cd30259a44 data/advancedperipherals/loot_tables/blocks/block_reader.json | ||
0923665563d05307a7fa7d711a2d7a994a31eb6e data/advancedperipherals/loot_tables/blocks/chat_box.json | ||
bf2a80256cfba0bd8c0283d493882e5816882f1f data/advancedperipherals/loot_tables/blocks/colony_integrator.json | ||
cff4b81aa381bc0d1172b0a4c8bb35c1b954a018 data/advancedperipherals/loot_tables/blocks/distance_detector.json | ||
1c5dbe1a8e07e040a3c2893a002cd535ee41dc20 data/advancedperipherals/loot_tables/blocks/energy_detector.json | ||
8cc03eca1d191f725bc558836f26a85a466cb127 data/advancedperipherals/loot_tables/blocks/environment_detector.json | ||
12589e7642b383029457d97a64637494ea8507a3 data/advancedperipherals/loot_tables/blocks/fluid_detector.json | ||
421a3ece56485bd46374844639bfd606ce4665ec data/advancedperipherals/loot_tables/blocks/gas_detector.json | ||
a2ae352dce564b878daecf47026f268dd432fbcf data/advancedperipherals/loot_tables/blocks/geo_scanner.json | ||
807d449d02c0af701f84d3e806ebac20d3a1f91c data/advancedperipherals/loot_tables/blocks/inventory_manager.json | ||
bb9b442dfad1d5f31397585c8394c85243fa169a data/advancedperipherals/loot_tables/blocks/me_bridge.json | ||
52b1fe2e265be456ebf48d7e0d9ebcc8c994176f data/advancedperipherals/loot_tables/blocks/nbt_storage.json | ||
2651e6053857a31f5bccc360969924848a197ad5 data/advancedperipherals/loot_tables/blocks/peripheral_casing.json | ||
6b5058b6bc49689bf2b858b89f3981a4bb681750 data/advancedperipherals/loot_tables/blocks/player_detector.json | ||
6af6542c7b64aa22dbfcdb01299daf4911827a49 data/advancedperipherals/loot_tables/blocks/redstone_integrator.json | ||
b221c6a82da0875264a112b54f847ac6a1f36797 data/advancedperipherals/loot_tables/blocks/rs_bridge.json |
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.19.2 2024-05-28T14:53:16.658014 Languages: en_us | ||
2580077212426421e05822910bde2edff88e2346 assets/advancedperipherals/lang/en_us.json | ||
// 1.19.2 2024-09-25T15:15:12.3008086 Languages: en_us | ||
c5dde7701295d5ad506663dba947865df73d753c assets/advancedperipherals/lang/en_us.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
package de.srendi.advancedperipherals.client.screens; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import dan200.computercraft.client.gui.ClientInputHandler; | ||
import dan200.computercraft.shared.computer.core.InputHandler; | ||
import de.srendi.advancedperipherals.client.screens.base.BaseScreen; | ||
import de.srendi.advancedperipherals.common.container.KeyboardContainer; | ||
import net.minecraft.SharedConstants; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import java.util.BitSet; | ||
|
||
/** | ||
* A simple screen but without any rendering calls. Used to unlock the mouse so we can freely write stuff | ||
* <p> | ||
* Char/key logic stolen from CC's WidgetTerminal | ||
*/ | ||
public class KeyboardScreen extends BaseScreen<KeyboardContainer> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do not extend from |
||
|
||
protected final InputHandler input; | ||
private final BitSet keysDown = new BitSet(256); | ||
|
||
private float terminateTimer = -1; | ||
private float rebootTimer = -1; | ||
private float shutdownTimer = -1; | ||
|
||
private int lastMouseButton = -1; | ||
private int lastMouseX = -1; | ||
private int lastMouseY = -1; | ||
|
||
public KeyboardScreen(KeyboardContainer screenContainer, Inventory inv, Component titleIn) { | ||
super(screenContainer, inv, titleIn); | ||
input = new ClientInputHandler(menu); | ||
} | ||
|
||
@Override | ||
public void render(@NotNull PoseStack poseStack, int x, int y, float partialTicks) { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
float scale = 2f; | ||
int screenWidth = minecraft.getWindow().getGuiScaledWidth(); | ||
int screenHeight = minecraft.getWindow().getGuiScaledHeight(); | ||
// Make the text a bit smaller on small screens | ||
if (screenWidth <= 1080) | ||
scale = 1f; | ||
|
||
poseStack.scale(scale, scale, 1); | ||
String text = "Press ESC to close the Keyboard Screen."; | ||
float textX = (screenWidth / 2f - minecraft.font.width(text) * scale / 2f) / scale; | ||
minecraft.font.drawShadow(poseStack, text, textX, 1, 0xFFFFFF); | ||
|
||
// Prevents JEI/REI/EMI from rendering. Maybe not the best way, but it works for now. | ||
SirEndii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
poseStack.scale(4f, 4f, 1); | ||
minecraft.font.draw(poseStack, "", screenWidth, screenHeight, 0xFFFFFF); | ||
} | ||
|
||
@Override | ||
protected void renderBg(@NotNull PoseStack matrixStack, float partialTicks, int x, int y) { | ||
} | ||
|
||
@Override | ||
public void renderBackground(@NotNull PoseStack pPoseStack) { | ||
} | ||
|
||
@Override | ||
public boolean charTyped(char ch, int modifiers) { | ||
if (ch >= 32 && ch <= 126 || ch >= 160 && ch <= 255) { // printable chars in byte range | ||
SirEndii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Queue the "char" event | ||
input.queueEvent("char", new Object[]{Character.toString(ch)}); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean keyPressed(int key, int scancode, int modifiers) { | ||
if (key == GLFW.GLFW_KEY_ESCAPE) { | ||
onClose(); | ||
return true; | ||
} | ||
if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0) { | ||
switch (key) { | ||
case GLFW.GLFW_KEY_T: | ||
if (terminateTimer < 0) terminateTimer = 0; | ||
return true; | ||
case GLFW.GLFW_KEY_S: | ||
if (shutdownTimer < 0) shutdownTimer = 0; | ||
return true; | ||
case GLFW.GLFW_KEY_R: | ||
if (rebootTimer < 0) rebootTimer = 0; | ||
return true; | ||
|
||
case GLFW.GLFW_KEY_V: | ||
// Ctrl+V for paste | ||
String clipboard = Minecraft.getInstance().keyboardHandler.getClipboard(); | ||
if (clipboard != null) { | ||
// Clip to the first occurrence of \r or \n | ||
int newLineIndex1 = clipboard.indexOf("\r"); | ||
int newLineIndex2 = clipboard.indexOf("\n"); | ||
if (newLineIndex1 >= 0 && newLineIndex2 >= 0) { | ||
clipboard = clipboard.substring(0, Math.min(newLineIndex1, newLineIndex2)); | ||
} else if (newLineIndex1 >= 0) { | ||
clipboard = clipboard.substring(0, newLineIndex1); | ||
} else if (newLineIndex2 >= 0) { | ||
clipboard = clipboard.substring(0, newLineIndex2); | ||
} | ||
|
||
// Filter the string | ||
clipboard = SharedConstants.filterText(clipboard); | ||
if (!clipboard.isEmpty()) { | ||
// Clip to 512 characters and queue the event | ||
if (clipboard.length() > 512) clipboard = clipboard.substring(0, 512); | ||
SirEndii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
input.queueEvent("paste", new Object[]{clipboard}); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
||
if (key >= 0 && terminateTimer < 0 && rebootTimer < 0 && shutdownTimer < 0) { | ||
// Queue the "key" event and add to the down set | ||
boolean repeat = keysDown.get(key); | ||
keysDown.set(key); | ||
input.keyDown(key, repeat); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean keyReleased(int key, int scancode, int modifiers) { | ||
// Queue the "key_up" event and remove from the down set | ||
if (key >= 0 && keysDown.get(key)) { | ||
keysDown.set(key, false); | ||
input.keyUp(key); | ||
} | ||
|
||
switch (key) { | ||
case GLFW.GLFW_KEY_T: | ||
terminateTimer = -1; | ||
break; | ||
case GLFW.GLFW_KEY_R: | ||
rebootTimer = -1; | ||
break; | ||
case GLFW.GLFW_KEY_S: | ||
shutdownTimer = -1; | ||
break; | ||
case GLFW.GLFW_KEY_LEFT_CONTROL: | ||
case GLFW.GLFW_KEY_RIGHT_CONTROL: | ||
terminateTimer = rebootTimer = shutdownTimer = -1; | ||
break; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
input.mouseClick(button + 1, (int) mouseX, (int) mouseY); | ||
|
||
lastMouseButton = button; | ||
lastMouseX = (int) mouseX; | ||
lastMouseY = (int) mouseY; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean mouseReleased(double mouseX, double mouseY, int button) { | ||
if (lastMouseButton == button) { | ||
input.mouseUp(lastMouseButton + 1, (int) mouseX, (int) mouseY); | ||
lastMouseButton = -1; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean mouseDragged(double mouseX, double mouseY, int button, double v2, double v3) { | ||
if (button == lastMouseButton && (mouseX != lastMouseX || mouseY != lastMouseY)) { | ||
input.mouseDrag(button + 1, (int) mouseX, (int) mouseY); | ||
lastMouseX = (int) mouseX; | ||
lastMouseY = (int) mouseY; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean mouseScrolled(double mouseX, double mouseY, double delta) { | ||
input.mouseScroll(delta < 0 ? 1 : -1, (int) mouseX, (int) mouseY); | ||
|
||
lastMouseX = (int) mouseX; | ||
lastMouseY = (int) mouseY; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int getSizeX() { | ||
return 256; | ||
} | ||
|
||
@Override | ||
public int getSizeY() { | ||
return 256; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTexture() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pretend I didn't see those
(although I think you should merge from dev/0.8)