Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public static List<Integer> getPressedButtons() {
return Interface.get().map(Interface::getPressedButtons).orElseGet(ArrayList::new);
}

public static void textInputFocusChange(Object owner, boolean focused) {
Keyboard.Interface.get().ifPresent(i -> i.textInputFocusChange(owner, focused));
}

public enum Modifier {
CTRL,
SHIFT,
Expand All @@ -25,5 +29,7 @@ static Optional<Interface> get() {
}

List<Integer> getPressedButtons();

void textInputFocusChange(Object owner, boolean focused);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public InfoVarComponent(InfoVar infoVar, InputField inputField) {
addButton.setButtonCallback(mouseButton -> {
if (mouseButton != Mouse.Button.LEFT) return;
inputField.typeContentAtCursor("{" + infoVar.getFullName() + "}");
inputField.focus();
inputField.setFocused(true);
});
buttonHolder.passPositionTo(addButton, PERCENT.NONE, Anchor.CENTER_RIGHT);
components.add(addButton);
Expand Down Expand Up @@ -296,7 +296,7 @@ public ColorItem(ScrollableList<ColorItem> parent, InputField inputField, Colors
new Vector2D(0, 0), new Vector2D(1, 1),
mouseButton -> {
inputField.typeContentAtCursor("{" + color.getName() + "}");
inputField.focus();
inputField.setFocused(true);
}
);
button.normalColor = Theme.NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.kurrycat.mpkmod.compatibility.MCClasses.FontRenderer;
import io.github.kurrycat.mpkmod.compatibility.MCClasses.InputConstants;
import io.github.kurrycat.mpkmod.compatibility.MCClasses.Keyboard;
import io.github.kurrycat.mpkmod.compatibility.MCClasses.Renderer2D;
import io.github.kurrycat.mpkmod.gui.interfaces.KeyInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseInputListener;
Expand Down Expand Up @@ -47,8 +48,9 @@ public InputField(String content, Vector2D pos, double width) {
this(content, pos, width, false);
}

public void focus() {
isFocused = true;
public void setFocused(boolean focused) {
isFocused = focused;
Keyboard.textInputFocusChange(this, focused);
}

public InputField setName(String name) {
Expand Down Expand Up @@ -118,11 +120,11 @@ private double getCursorX() {
}

@Override
public boolean handleKeyInput(int keyCode, int scanCode, int modifiers, boolean isCharTyped) {
public boolean handleKeyInput(int keyCode, int scanCode, int modifiers, boolean pressed) {
if (!isFocused) return false;
boolean inputPerformed = true;

if (isCharTyped && String.valueOf((char) keyCode).matches(getFilter())) {
if (pressed && String.valueOf((char) keyCode).matches(getFilter())) {
typeContentAtCursor(Character.toString((char) keyCode));
} else {
switch (keyCode) {
Expand Down Expand Up @@ -196,7 +198,7 @@ private void updateContent(String content) {
}

public void clear() {
isFocused = false;
setFocused(false);
cursorPos = 0;
highlightStart = 0;
highlightEnd = 0;
Expand All @@ -209,13 +211,13 @@ public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Butt
switch (state) {
case DOWN:
if (contains(mousePos)) {
isFocused = true;
setFocused(true);
cursorPos = getCursorPosFromMousePos(mousePos);
highlightStart = cursorPos;
highlightEnd = cursorPos;
return true;
} else {
isFocused = false;
setFocused(false);
}
case DRAG:
case UP:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.kurrycat.mpkmod.compatibility.fabric_26_3;

import com.mojang.blaze3d.platform.TextInputManager;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
import io.github.kurrycat.mpkmod.compatibility.MCClasses.*;
Expand Down Expand Up @@ -404,6 +405,12 @@ public Player.KeyInput getKeyInput() {
return new Player.KeyInput(w, a, s, d, sprint, sneak, jump);
}

@Override
public void textInputFocusChange(Object owner, boolean focused) {
TextInputManager textInputManager = net.minecraft.client.Minecraft.getInstance().textInputManager();
textInputManager.onTextInputFocusChange(owner, focused);
}

private record PointsRenderState(
Collection<Vector2D> points,
int r, int g, int b, int a,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,7 @@ public Player.KeyInput getKeyInput() {

return new Player.KeyInput(w, a, s, d, sprint, sneak, jump);
}

@Override
public void textInputFocusChange(Object owner, boolean focused) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,7 @@ public Player.KeyInput getKeyInput() {

return new Player.KeyInput(w, a, s, d, sprint, sneak, jump);
}

@Override
public void textInputFocusChange(Object owner, boolean focused) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,7 @@ public Player.KeyInput getKeyInput() {

return new Player.KeyInput(w, a, s, d, sprint, sneak, jump);
}

@Override
public void textInputFocusChange(Object owner, boolean focused) {}
}
Loading