cloaks search
This commit is contained in:
@@ -3,17 +3,22 @@ package org.saturnclient.saturnclient.menus;
|
|||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.auth.SaturnSocket;
|
import org.saturnclient.saturnclient.auth.SaturnSocket;
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.Textures;
|
import org.saturnclient.ui.Textures;
|
||||||
import org.saturnclient.ui.widgets.SaturnClickableImage;
|
import org.saturnclient.ui.widgets.SaturnClickableImage;
|
||||||
import org.saturnclient.ui.widgets.SaturnClickableSprite;
|
import org.saturnclient.ui.widgets.SaturnClickableSprite;
|
||||||
import org.saturnclient.ui.widgets.SaturnImage;
|
import org.saturnclient.ui.widgets.SaturnImage;
|
||||||
|
import org.saturnclient.ui.widgets.SaturnInputBox;
|
||||||
import org.saturnclient.ui.widgets.SaturnScroll;
|
import org.saturnclient.ui.widgets.SaturnScroll;
|
||||||
import org.saturnclient.ui.widgets.SaturnSprite;
|
import org.saturnclient.ui.widgets.SaturnSprite;
|
||||||
|
|
||||||
public class CloaksMenu extends SaturnUi {
|
public class CloaksMenu extends SaturnUi {
|
||||||
|
|
||||||
|
private SaturnScroll scroll;
|
||||||
|
private Property<String> search = new Property<>("");
|
||||||
|
|
||||||
public CloaksMenu() {
|
public CloaksMenu() {
|
||||||
super(Text.of("Cloaks Menu"));
|
super(Text.of("Cloaks Menu"));
|
||||||
}
|
}
|
||||||
@@ -44,6 +49,15 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
.setHeight(15)
|
.setHeight(15)
|
||||||
.setAnimations(SaturnClient.getAnimations()));
|
.setAnimations(SaturnClient.getAnimations()));
|
||||||
|
|
||||||
|
draw(
|
||||||
|
new SaturnInputBox(search, rectX + rectWidth - 72, tabsY, 70).onUpdate(() -> {
|
||||||
|
scroll.clear();
|
||||||
|
drawItems(rectX, rectY, rectWidth, rectHeight);
|
||||||
|
})
|
||||||
|
.setHeight(15)
|
||||||
|
.setWidth(72)
|
||||||
|
.setAnimations(SaturnClient.getAnimations()));
|
||||||
|
|
||||||
int tabSize = 9;
|
int tabSize = 9;
|
||||||
tabsX = (width - tabSize) / 2;
|
tabsX = (width - tabSize) / 2;
|
||||||
draw(
|
draw(
|
||||||
@@ -77,6 +91,21 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimations(SaturnClient.getAnimations()));
|
.setAnimations(SaturnClient.getAnimations()));
|
||||||
|
|
||||||
|
scroll = new SaturnScroll();
|
||||||
|
|
||||||
|
drawItems(rectX, rectY, rectWidth, rectHeight);
|
||||||
|
|
||||||
|
draw(scroll
|
||||||
|
.setX(rectX + 17)
|
||||||
|
.setY(rectY + 10)
|
||||||
|
.setWidth(rectWidth - 17)
|
||||||
|
.setHeight(rectHeight - 10)
|
||||||
|
.setAnimations(SaturnClient.getAnimations()));
|
||||||
|
|
||||||
|
super.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawItems(int rectX, int rectY, int rectWidth, int rectHeight) {
|
||||||
int cloakWidth = 32;
|
int cloakWidth = 32;
|
||||||
int cloakHeight = 70;
|
int cloakHeight = 70;
|
||||||
|
|
||||||
@@ -84,10 +113,16 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
int modY = 0;
|
int modY = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
SaturnScroll modsScroll = new SaturnScroll();
|
String[] searchTokens = search.value.split("\\ ");
|
||||||
|
|
||||||
for (String cloak : Cloaks.availableCloaks) {
|
outer: for (String cloak : Cloaks.availableCloaks) {
|
||||||
modsScroll.draw(
|
for (String searchToken : searchTokens) {
|
||||||
|
if (!cloak.contains(searchToken)) {
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scroll.draw(
|
||||||
new SaturnClickableSprite(Textures.BUTTON_BORDER, () -> {
|
new SaturnClickableSprite(Textures.BUTTON_BORDER, () -> {
|
||||||
Cloaks.setCloak(SaturnSocket.uuid, cloak);
|
Cloaks.setCloak(SaturnSocket.uuid, cloak);
|
||||||
})
|
})
|
||||||
@@ -96,7 +131,7 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
.setWidth(cloakWidth + 6)
|
.setWidth(cloakWidth + 6)
|
||||||
.setHeight(cloakHeight + 6));
|
.setHeight(cloakHeight + 6));
|
||||||
|
|
||||||
modsScroll.draw(
|
scroll.draw(
|
||||||
new SaturnImage(Textures.getCloakPreview(cloak))
|
new SaturnImage(Textures.getCloakPreview(cloak))
|
||||||
.setX(modX + 3)
|
.setX(modX + 3)
|
||||||
.setY(modY + 3)
|
.setY(modY + 3)
|
||||||
@@ -113,15 +148,5 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(
|
|
||||||
modsScroll
|
|
||||||
.setX(rectX + 17)
|
|
||||||
.setY(rectY + 10)
|
|
||||||
.setWidth(rectWidth - 17)
|
|
||||||
.setHeight(rectHeight - 10)
|
|
||||||
.setAnimations(SaturnClient.getAnimations()));
|
|
||||||
|
|
||||||
super.init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ public class Textures {
|
|||||||
// Widgets
|
// Widgets
|
||||||
public static final Identifier BUTTON_BORDER = Identifier.of("saturnclient", "button_border");
|
public static final Identifier BUTTON_BORDER = Identifier.of("saturnclient", "button_border");
|
||||||
public static final Identifier BUTTON = Identifier.of("saturnclient", "button");
|
public static final Identifier BUTTON = Identifier.of("saturnclient", "button");
|
||||||
|
public static final Identifier BUTTON_OP = Identifier.of("saturnclient", "button_op");
|
||||||
public static final Identifier SETTINGS_BG = Identifier.of("saturnclient", "settings_bg");
|
public static final Identifier SETTINGS_BG = Identifier.of("saturnclient", "settings_bg");
|
||||||
public static final Identifier RECT = Identifier.of("saturnclient", "rect");
|
public static final Identifier RECT = Identifier.of("saturnclient", "rect");
|
||||||
|
public static final Identifier RECT_BORDER = Identifier.of("saturnclient", "rect_border");
|
||||||
public static final Identifier MOD = Identifier.of("saturnclient", "textures/gui/components/mod.png");
|
public static final Identifier MOD = Identifier.of("saturnclient", "textures/gui/components/mod.png");
|
||||||
public static final Identifier MOD_BG = Identifier.of("saturnclient", "textures/gui/components/mod_bg.png");
|
public static final Identifier MOD_BG = Identifier.of("saturnclient", "textures/gui/components/mod_bg.png");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
package org.saturnclient.ui.widgets;
|
||||||
|
|
||||||
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.font.TextRenderer;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.ui.SaturnUi;
|
||||||
|
import org.saturnclient.ui.Textures;
|
||||||
|
|
||||||
|
public class SaturnInputBox extends SaturnWidget {
|
||||||
|
|
||||||
|
private TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||||
|
private int tick = 0;
|
||||||
|
private boolean cursorVisible = true;
|
||||||
|
|
||||||
|
public Property<String> prop;
|
||||||
|
public int cursorPosition = 0;
|
||||||
|
public Runnable onUpdate;
|
||||||
|
|
||||||
|
public SaturnInputBox(Property<String> prop, int x, int y, int width) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.prop = prop;
|
||||||
|
this.height = textRenderer.fontHeight + 4;
|
||||||
|
this.scale = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(int mouseX, int mouseY) {
|
||||||
|
int scrollOffset = getScrollOffset();
|
||||||
|
String visibleText = prop.value.substring(scrollOffset);
|
||||||
|
|
||||||
|
int newCursorPos = scrollOffset;
|
||||||
|
int textWidth = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < visibleText.length(); i++) {
|
||||||
|
textWidth = textRenderer.getWidth(visibleText.substring(0, i + 1));
|
||||||
|
|
||||||
|
if (textWidth > mouseX) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
newCursorPos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
cursorPosition = newCursorPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void charTyped(char chr) {
|
||||||
|
prop.value = prop.value.substring(0, cursorPosition) +
|
||||||
|
chr +
|
||||||
|
prop.value.substring(cursorPosition);
|
||||||
|
|
||||||
|
cursorPosition++;
|
||||||
|
|
||||||
|
onUpdate.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||||
|
if (keyCode == GLFW.GLFW_KEY_BACKSPACE) {
|
||||||
|
if (cursorPosition > 0) {
|
||||||
|
prop.value = prop.value.substring(0, cursorPosition - 1) +
|
||||||
|
prop.value.substring(cursorPosition);
|
||||||
|
cursorPosition--;
|
||||||
|
}
|
||||||
|
onUpdate.run();
|
||||||
|
} else if (keyCode == GLFW.GLFW_KEY_LEFT) {
|
||||||
|
if (cursorPosition > 0) {
|
||||||
|
cursorPosition--;
|
||||||
|
}
|
||||||
|
} else if (keyCode == GLFW.GLFW_KEY_RIGHT) {
|
||||||
|
if (cursorPosition < prop.value.length()) {
|
||||||
|
cursorPosition++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(
|
||||||
|
DrawContext context,
|
||||||
|
boolean hovering,
|
||||||
|
int mouseX,
|
||||||
|
int mouseY) {
|
||||||
|
SaturnUi.drawHighResGuiTexture(
|
||||||
|
context,
|
||||||
|
Textures.BUTTON,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
|
focused
|
||||||
|
? SaturnClient.COLOR.value
|
||||||
|
: SaturnClient.getWhite(this.alpha));
|
||||||
|
SaturnUi.drawHighResGuiTexture(
|
||||||
|
context,
|
||||||
|
Textures.BUTTON_BORDER,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
|
focused
|
||||||
|
? SaturnClient.COLOR.value
|
||||||
|
: SaturnClient.getWhite(this.alpha));
|
||||||
|
|
||||||
|
int scrollOffset = getScrollOffset();
|
||||||
|
String visibleText = getVisibleText(scrollOffset);
|
||||||
|
|
||||||
|
MatrixStack matrices = context.getMatrices();
|
||||||
|
matrices.push();
|
||||||
|
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
|
||||||
|
matrices.scale(0.9f, 0.9f, 1.0f);
|
||||||
|
context.drawText(
|
||||||
|
textRenderer,
|
||||||
|
SaturnUi.text(visibleText),
|
||||||
|
3,
|
||||||
|
textRenderer.fontHeight / 2,
|
||||||
|
textColor,
|
||||||
|
false);
|
||||||
|
|
||||||
|
if (focused && cursorVisible) {
|
||||||
|
int cursorX = 2 +
|
||||||
|
textRenderer.getWidth(
|
||||||
|
SaturnUi.text(
|
||||||
|
visibleText.substring(0, cursorPosition - scrollOffset)));
|
||||||
|
matrices.translate(cursorX, 0, 0);
|
||||||
|
context.fill(
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
textRenderer.fontHeight + 3,
|
||||||
|
0xFFFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
matrices.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearText() {
|
||||||
|
prop.value = "";
|
||||||
|
cursorPosition = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getScrollOffset() {
|
||||||
|
if (prop.value.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int offset = 0;
|
||||||
|
int maxWidth = width - 4; // Available width for prop.value
|
||||||
|
while (offset < cursorPosition) { // Ensure cursor remains visible
|
||||||
|
String visibleText = prop.value.substring(offset, cursorPosition);
|
||||||
|
if (textRenderer.getWidth(SaturnUi.text(visibleText)) > maxWidth) {
|
||||||
|
offset++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getVisibleText(int scrollOffset) {
|
||||||
|
String visibleText = prop.value.substring(scrollOffset);
|
||||||
|
|
||||||
|
// Ensure prop.value does not overflow past the available width
|
||||||
|
for (int i = 1; i <= visibleText.length(); i++) {
|
||||||
|
if (textRenderer.getWidth(
|
||||||
|
SaturnUi.text(visibleText.substring(0, i))) > width - 4) {
|
||||||
|
return visibleText.substring(0, i - 1); // Trim overflow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return visibleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaturnInputBox onUpdate(Runnable onUpdate) {
|
||||||
|
this.onUpdate = onUpdate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (focused) {
|
||||||
|
if (tick < 45 || tick < 60 && cursorVisible) {
|
||||||
|
tick++;
|
||||||
|
} else {
|
||||||
|
tick = 0;
|
||||||
|
cursorVisible = !cursorVisible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -143,4 +143,8 @@ public class SaturnScroll extends SaturnWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
children.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"gui": {
|
||||||
|
"scaling": {
|
||||||
|
"type": "nine_slice",
|
||||||
|
"width": 228,
|
||||||
|
"height": 228,
|
||||||
|
"border": 13
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user