Implementing components
This commit is contained in:
@@ -15,4 +15,6 @@ public abstract class MinecraftProvider {
|
||||
public abstract int getWidth(String text, int font);
|
||||
|
||||
public abstract void registerBufferedImageTexture(SaturnIdentifier i, BufferedImage bi);
|
||||
|
||||
public abstract String getKeyName(int key);
|
||||
}
|
||||
|
||||
+5
-6
@@ -1,8 +1,7 @@
|
||||
package org.saturnclient.ui.components.inputs;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.config.Theme;
|
||||
import org.saturnclient.config.manager.Key;
|
||||
import org.saturnclient.ui.Element;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
@@ -22,18 +21,18 @@ public abstract class Input extends Element {
|
||||
|
||||
@Override
|
||||
public void keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (keyCode == GLFW.GLFW_KEY_BACKSPACE) {
|
||||
if (keyCode == Key.GLFW_KEY_BACKSPACE) {
|
||||
if (cursorPosition > 0 && validateBackspace()) {
|
||||
text = text.substring(0, cursorPosition - 1) +
|
||||
text.substring(cursorPosition);
|
||||
cursorPosition--;
|
||||
backspace();
|
||||
}
|
||||
} else if (keyCode == GLFW.GLFW_KEY_LEFT) {
|
||||
} else if (keyCode == Key.GLFW_KEY_LEFT) {
|
||||
if (cursorPosition > 0) {
|
||||
cursorPosition--;
|
||||
}
|
||||
} else if (keyCode == GLFW.GLFW_KEY_RIGHT) {
|
||||
} else if (keyCode == Key.GLFW_KEY_RIGHT) {
|
||||
if (cursorPosition < text.length()) {
|
||||
cursorPosition++;
|
||||
}
|
||||
@@ -49,7 +48,7 @@ public abstract class Input extends Element {
|
||||
float textWidth = 0;
|
||||
|
||||
for (int i = 0; i < visibleText.length(); i++) {
|
||||
textWidth = SaturnClient.client.textRenderer.getWidth(visibleText.substring(0, i + 1)) * 0.6f;
|
||||
textWidth = Fonts.getWidth(visibleText.substring(0, i + 1), Theme.FONT.value) * 0.6f;
|
||||
|
||||
if (textWidth > mouseX) {
|
||||
break;
|
||||
+4
-3
@@ -1,7 +1,8 @@
|
||||
package org.saturnclient.ui.components.inputs;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.common.minecraft.MinecraftProvider;
|
||||
import org.saturnclient.config.Theme;
|
||||
import org.saturnclient.config.manager.Key;
|
||||
import org.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui.Element;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
@@ -21,7 +22,7 @@ public class KeybindingSelector extends Element {
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
|
||||
renderScope.drawRoundedRectangle(0, 0, width, height, 10, 0xFF000000);
|
||||
String name = GLFW.glfwGetKeyName(prop.value, GLFW.glfwGetKeyScancode(prop.value));
|
||||
String name = MinecraftProvider.PROVIDER.getKeyName(prop.value);
|
||||
|
||||
renderScope.drawText(0.6f,
|
||||
prop.value == -1 ? "<NONE>"
|
||||
@@ -31,7 +32,7 @@ public class KeybindingSelector extends Element {
|
||||
|
||||
@Override
|
||||
public void keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (keyCode == GLFW.GLFW_KEY_BACKSPACE) {
|
||||
if (keyCode == Key.GLFW_KEY_BACKSPACE) {
|
||||
prop.value = -1;
|
||||
} else {
|
||||
prop.value = keyCode;
|
||||
@@ -38,4 +38,9 @@ public class SaturnClientProvider extends MinecraftProvider {
|
||||
public void registerBufferedImageTexture(SaturnIdentifier i, BufferedImage bi) {
|
||||
IdentifierUtils.registerBufferedImageTextureFast((Identifier) i.inner, bi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyName(int key) {
|
||||
return GLFW.glfwGetKeyName(key, GLFW.glfwGetKeyScancode(key));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user