scaling, but click issue
This commit is contained in:
@@ -7,6 +7,7 @@ import org.saturnclient.saturnclient.config.Property;
|
|||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.Textures;
|
import org.saturnclient.ui.Textures;
|
||||||
import org.saturnclient.ui.animations.Slide;
|
import org.saturnclient.ui.animations.Slide;
|
||||||
|
import org.saturnclient.ui.components.SaturnFloat;
|
||||||
import org.saturnclient.ui.components.SaturnInteger;
|
import org.saturnclient.ui.components.SaturnInteger;
|
||||||
import org.saturnclient.ui.components.SaturnToggle;
|
import org.saturnclient.ui.components.SaturnToggle;
|
||||||
import org.saturnclient.ui.widgets.SaturnScroll;
|
import org.saturnclient.ui.widgets.SaturnScroll;
|
||||||
@@ -30,14 +31,14 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
int rectX = (width - rectWidth) / 2;
|
int rectX = (width - rectWidth) / 2;
|
||||||
int rectY = (height - rectHeight + 15) / 2;
|
int rectY = (height - rectHeight + 15) / 2;
|
||||||
|
|
||||||
// draw(
|
draw(
|
||||||
// new SaturnSprite(Textures.SETTINGS_BG)
|
new SaturnSprite(Textures.SETTINGS_BG)
|
||||||
// .setX(rectX)
|
.setX(rectX)
|
||||||
// .setY(rectY)
|
.setY(rectY)
|
||||||
// .setWidth(rectWidth)
|
.setWidth(rectWidth)
|
||||||
// .setHeight(rectHeight)
|
.setHeight(rectHeight)
|
||||||
// .setAnimations(new Slide(1, 10))
|
.setAnimations(new Slide(1, 10))
|
||||||
// );
|
);
|
||||||
|
|
||||||
int tabsX = (width - 43) / 2;
|
int tabsX = (width - 43) / 2;
|
||||||
int tabsY = rectY - 17;
|
int tabsY = rectY - 17;
|
||||||
@@ -72,7 +73,7 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int modX = ((rectWidth / 2) - 17) * col;
|
int modX = ((rectWidth / 2) - 17) * col;
|
||||||
int modY = 12 * row;
|
int modY = 14 * row;
|
||||||
|
|
||||||
switch (prop.getType()) {
|
switch (prop.getType()) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
@@ -88,6 +89,7 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
)
|
)
|
||||||
.setX(modX + 18)
|
.setX(modX + 18)
|
||||||
.setY(modY)
|
.setY(modY)
|
||||||
|
.setScale(0.8f)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
@@ -98,6 +100,7 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
)
|
)
|
||||||
.setX(modX)
|
.setX(modX)
|
||||||
.setY(modY)
|
.setY(modY)
|
||||||
|
.setScale(0.8f)
|
||||||
);
|
);
|
||||||
|
|
||||||
configScroll.draw(
|
configScroll.draw(
|
||||||
@@ -105,7 +108,27 @@ public class ConfigEditor extends SaturnUi {
|
|||||||
(Property<Integer>) prop,
|
(Property<Integer>) prop,
|
||||||
(rectWidth / 2) - 17,
|
(rectWidth / 2) - 17,
|
||||||
modY,
|
modY,
|
||||||
40
|
70
|
||||||
|
)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case FLOAT:
|
||||||
|
configScroll.draw(
|
||||||
|
new SaturnText(
|
||||||
|
propName.substring(0, 1).toUpperCase() +
|
||||||
|
propName.substring(1)
|
||||||
|
)
|
||||||
|
.setX(modX)
|
||||||
|
.setY(modY)
|
||||||
|
.setScale(0.8f)
|
||||||
|
);
|
||||||
|
|
||||||
|
configScroll.draw(
|
||||||
|
new SaturnFloat(
|
||||||
|
(Property<Float>) prop,
|
||||||
|
(rectWidth / 2) - 17,
|
||||||
|
modY,
|
||||||
|
70
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,18 +1,55 @@
|
|||||||
package org.saturnclient.saturnmods;
|
package org.saturnclient.saturnmods;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
|
||||||
import org.saturnclient.saturnclient.menus.HudEditor;
|
|
||||||
import org.saturnclient.saturnmods.mods.ArmorDisplay;
|
|
||||||
import org.saturnclient.saturnmods.mods.Coordinates;
|
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.menus.HudEditor;
|
||||||
|
import org.saturnclient.saturnmods.mods.ArmorDisplay;
|
||||||
|
import org.saturnclient.saturnmods.mods.Coordinates;
|
||||||
|
|
||||||
public class ModManager {
|
public class ModManager {
|
||||||
|
|
||||||
public static SaturnMod[] MODS = {
|
public static SaturnMod[] MODS = {
|
||||||
new Coordinates(),
|
new Coordinates(),
|
||||||
new ArmorDisplay()
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
|
new ArmorDisplay(),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
@@ -20,7 +57,10 @@ public class ModManager {
|
|||||||
MinecraftClient client = MinecraftClient.getInstance();
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
TextRenderer textRenderer = client.textRenderer;
|
TextRenderer textRenderer = client.textRenderer;
|
||||||
|
|
||||||
if (textRenderer != null && !(client.currentScreen instanceof HudEditor)) {
|
if (
|
||||||
|
textRenderer != null &&
|
||||||
|
!(client.currentScreen instanceof HudEditor)
|
||||||
|
) {
|
||||||
SaturnClient.textRenderer = textRenderer;
|
SaturnClient.textRenderer = textRenderer;
|
||||||
|
|
||||||
for (SaturnMod m : MODS) {
|
for (SaturnMod m : MODS) {
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
import net.minecraft.text.Style;
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
public class SaturnUi extends Screen {
|
public class SaturnUi extends Screen {
|
||||||
|
|
||||||
@@ -66,7 +68,25 @@ public class SaturnUi extends Screen {
|
|||||||
widget.x + widget.width > mouseX &&
|
widget.x + widget.width > mouseX &&
|
||||||
widget.y < mouseY &&
|
widget.y < mouseY &&
|
||||||
widget.y + widget.height > mouseY;
|
widget.y + widget.height > mouseY;
|
||||||
widget.render(context, isMouseInside, mouseX, mouseY);
|
|
||||||
|
SaturnClient.LOGGER.info(
|
||||||
|
"Render mouse X: " +
|
||||||
|
(mouseX - widget.x) +
|
||||||
|
", mouse Y: " +
|
||||||
|
(mouseY - widget.y)
|
||||||
|
);
|
||||||
|
|
||||||
|
MatrixStack matrices = context.getMatrices();
|
||||||
|
matrices.push();
|
||||||
|
matrices.translate(widget.x, widget.y, 0);
|
||||||
|
matrices.scale(widget.scale, widget.scale, 1.0f);
|
||||||
|
widget.render(
|
||||||
|
context,
|
||||||
|
isMouseInside,
|
||||||
|
mouseX - widget.x,
|
||||||
|
mouseY - widget.y
|
||||||
|
);
|
||||||
|
matrices.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,14 +97,27 @@ public class SaturnUi extends Screen {
|
|||||||
widget.focused = false;
|
widget.focused = false;
|
||||||
if (!widget.visible) continue;
|
if (!widget.visible) continue;
|
||||||
|
|
||||||
|
double adjustedMouseX = (mouseX - widget.x) / widget.scale;
|
||||||
|
double adjustedMouseY = (mouseY - widget.y) / widget.scale;
|
||||||
boolean isMouseInside =
|
boolean isMouseInside =
|
||||||
widget.x < mouseX &&
|
adjustedMouseX >= 0 &&
|
||||||
widget.x + widget.width > mouseX &&
|
adjustedMouseX <= widget.width &&
|
||||||
widget.y < mouseY &&
|
adjustedMouseY >= 0 &&
|
||||||
widget.y + widget.height > mouseY;
|
adjustedMouseY <= widget.height;
|
||||||
|
|
||||||
|
SaturnClient.LOGGER.info(
|
||||||
|
"CLick mouse X: " +
|
||||||
|
adjustedMouseX +
|
||||||
|
", mouse Y: " +
|
||||||
|
adjustedMouseY
|
||||||
|
);
|
||||||
|
|
||||||
if (isMouseInside) {
|
if (isMouseInside) {
|
||||||
widget.focused = true;
|
widget.focused = true;
|
||||||
widget.click((int) mouseX, (int) mouseY);
|
widget.click(
|
||||||
|
((int) mouseX) - widget.x,
|
||||||
|
((int) mouseY) - widget.y
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,16 +148,18 @@ public class SaturnUi extends Screen {
|
|||||||
double verticalAmount
|
double verticalAmount
|
||||||
) {
|
) {
|
||||||
for (SaturnWidget widget : new ArrayList<>(widgets)) {
|
for (SaturnWidget widget : new ArrayList<>(widgets)) {
|
||||||
|
double adjustedMouseX = (mouseX - widget.x) / widget.scale;
|
||||||
|
double adjustedMouseY = (mouseY - widget.y) / widget.scale;
|
||||||
boolean isMouseInside =
|
boolean isMouseInside =
|
||||||
widget.x < mouseX &&
|
adjustedMouseX >= 0 &&
|
||||||
widget.x + widget.width > mouseX &&
|
adjustedMouseX <= widget.width &&
|
||||||
widget.y < mouseY &&
|
adjustedMouseY >= 0 &&
|
||||||
widget.y + widget.height > mouseY;
|
adjustedMouseY <= widget.height;
|
||||||
|
|
||||||
if (isMouseInside) {
|
if (isMouseInside) {
|
||||||
widget.mouseScrolled(
|
widget.mouseScrolled(
|
||||||
(int) mouseX,
|
((int) mouseX) - widget.x,
|
||||||
(int) mouseY,
|
((int) mouseY) - widget.y,
|
||||||
horizontalAmount,
|
horizontalAmount,
|
||||||
verticalAmount
|
verticalAmount
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ public class SaturnWidget {
|
|||||||
public int width = 0;
|
public int width = 0;
|
||||||
public int height = 0;
|
public int height = 0;
|
||||||
public float alpha = 1.0f;
|
public float alpha = 1.0f;
|
||||||
|
public float scale = 1.0f;
|
||||||
public SaturnAnimation[] animations = null;
|
public SaturnAnimation[] animations = null;
|
||||||
public boolean visible = true;
|
public boolean visible = true;
|
||||||
public boolean focused = false;
|
public boolean focused = false;
|
||||||
@@ -72,4 +73,9 @@ public class SaturnWidget {
|
|||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SaturnWidget setScale(float scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class SaturnInteger extends SaturnWidget {
|
|||||||
this.prop = prop;
|
this.prop = prop;
|
||||||
this.text = String.valueOf(prop.value);
|
this.text = String.valueOf(prop.value);
|
||||||
this.height = textRenderer.fontHeight + 4;
|
this.height = textRenderer.fontHeight + 4;
|
||||||
|
this.scale = 0.8f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +40,7 @@ public class SaturnInteger extends SaturnWidget {
|
|||||||
for (int i = 0; i < visibleText.length(); i++) {
|
for (int i = 0; i < visibleText.length(); i++) {
|
||||||
textWidth = textRenderer.getWidth(visibleText.substring(0, i + 1));
|
textWidth = textRenderer.getWidth(visibleText.substring(0, i + 1));
|
||||||
|
|
||||||
if (textWidth > (mouseX - x)) {
|
if (textWidth > mouseX) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,12 +103,12 @@ public class SaturnInteger extends SaturnWidget {
|
|||||||
) {
|
) {
|
||||||
context.drawGuiTexture(
|
context.drawGuiTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.BUTTON,
|
Textures.BUTTON_BORDER,
|
||||||
this.x,
|
0,
|
||||||
this.y,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
SaturnClient.getWhite(this.alpha)
|
focused ? SaturnClient.COLOR : SaturnClient.getWhite(this.alpha)
|
||||||
);
|
);
|
||||||
|
|
||||||
int scrollOffset = getScrollOffset();
|
int scrollOffset = getScrollOffset();
|
||||||
@@ -117,15 +118,14 @@ public class SaturnInteger extends SaturnWidget {
|
|||||||
context.drawText(
|
context.drawText(
|
||||||
textRenderer,
|
textRenderer,
|
||||||
SaturnUi.text(visibleText),
|
SaturnUi.text(visibleText),
|
||||||
x + 2,
|
2,
|
||||||
y + 2,
|
2,
|
||||||
textColor,
|
textColor,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
int cursorX =
|
int cursorX =
|
||||||
x +
|
|
||||||
2 +
|
2 +
|
||||||
textRenderer.getWidth(
|
textRenderer.getWidth(
|
||||||
SaturnUi.text(
|
SaturnUi.text(
|
||||||
@@ -134,9 +134,9 @@ public class SaturnInteger extends SaturnWidget {
|
|||||||
);
|
);
|
||||||
context.fill(
|
context.fill(
|
||||||
cursorX,
|
cursorX,
|
||||||
y + 2,
|
2,
|
||||||
cursorX + 1,
|
cursorX + 1,
|
||||||
y + textRenderer.fontHeight + 4,
|
textRenderer.fontHeight + 4,
|
||||||
0xFFFFFFFF
|
0xFFFFFFFF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ public class SaturnModComp extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.MOD_BG,
|
Textures.MOD_BG,
|
||||||
x,
|
0,
|
||||||
y,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
86,
|
86,
|
||||||
@@ -55,8 +55,8 @@ public class SaturnModComp extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.MOD,
|
Textures.MOD,
|
||||||
x,
|
0,
|
||||||
y,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
86,
|
86,
|
||||||
@@ -69,8 +69,8 @@ public class SaturnModComp extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
mod.getIconTexture(),
|
mod.getIconTexture(),
|
||||||
x + 4,
|
4,
|
||||||
y + 4,
|
4,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
size,
|
size,
|
||||||
@@ -83,8 +83,8 @@ public class SaturnModComp extends SaturnWidget {
|
|||||||
context.drawText(
|
context.drawText(
|
||||||
SaturnClient.textRenderer,
|
SaturnClient.textRenderer,
|
||||||
SaturnUi.text(mod.getName()),
|
SaturnUi.text(mod.getName()),
|
||||||
x + 20,
|
20,
|
||||||
y + (21 - SaturnClient.textRenderer.fontHeight) / 2,
|
(21 - SaturnClient.textRenderer.fontHeight) / 2,
|
||||||
color,
|
color,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -92,8 +92,8 @@ public class SaturnModComp extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.SETTINGS,
|
Textures.SETTINGS,
|
||||||
x + 77,
|
77,
|
||||||
y + 11,
|
11,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
7,
|
7,
|
||||||
@@ -117,8 +117,8 @@ public class SaturnModComp extends SaturnWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean settingsHovering(int mouseX, int mouseY) {
|
public boolean settingsHovering(int mouseX, int mouseY) {
|
||||||
int sX = x + 77;
|
int sX = 77;
|
||||||
int sY = y + 11;
|
int sY = 11;
|
||||||
int size = 7;
|
int size = 7;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ public class SaturnToggle extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.TOGGLE_BG,
|
Textures.TOGGLE_BG,
|
||||||
x,
|
0,
|
||||||
y + 1,
|
1,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
w,
|
w,
|
||||||
@@ -49,8 +49,8 @@ public class SaturnToggle extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.TOGGLE_INDICATOR,
|
Textures.TOGGLE_INDICATOR,
|
||||||
prop.value ? x + 5 : x,
|
prop.value ? 5 : 0,
|
||||||
y,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
s,
|
s,
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
context.drawGuiTexture(
|
context.drawGuiTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.BUTTON,
|
Textures.BUTTON,
|
||||||
this.x,
|
0,
|
||||||
this.y,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
SaturnClient.getWhite(this.alpha)
|
SaturnClient.getWhite(this.alpha)
|
||||||
@@ -65,8 +65,8 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
context.drawGuiTexture(
|
context.drawGuiTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.BUTTON_BORDER,
|
Textures.BUTTON_BORDER,
|
||||||
this.x,
|
0,
|
||||||
this.y,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
hoverColor
|
hoverColor
|
||||||
@@ -79,13 +79,11 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
context.drawText(
|
context.drawText(
|
||||||
minecraftClient.textRenderer,
|
minecraftClient.textRenderer,
|
||||||
SaturnUi.text(text),
|
SaturnUi.text(text),
|
||||||
this.x +
|
|
||||||
((this.width -
|
((this.width -
|
||||||
minecraftClient.textRenderer.getWidth(
|
minecraftClient.textRenderer.getWidth(
|
||||||
SaturnUi.text(text)
|
SaturnUi.text(text)
|
||||||
)) /
|
)) /
|
||||||
2),
|
2),
|
||||||
this.y +
|
|
||||||
((this.height - minecraftClient.textRenderer.fontHeight + 1) /
|
((this.height - minecraftClient.textRenderer.fontHeight + 1) /
|
||||||
2),
|
2),
|
||||||
hovering
|
hovering
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ public class SaturnClickableImage extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
texture,
|
texture,
|
||||||
x,
|
0,
|
||||||
y,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
width,
|
width,
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ public class SaturnClickableSprite extends SaturnWidget {
|
|||||||
context.drawGuiTexture(
|
context.drawGuiTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
sprite,
|
sprite,
|
||||||
this.x,
|
0,
|
||||||
this.y,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
(hovering || selected ? hoverColor : color) |
|
(hovering || selected ? hoverColor : color) |
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class SaturnImage extends SaturnWidget {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
sprite,
|
sprite,
|
||||||
x,
|
0,
|
||||||
y,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
width,
|
width,
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ public class SaturnImageButton extends SaturnButton {
|
|||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
sprite,
|
sprite,
|
||||||
(x + (width - imageWidth) / 2),
|
((width - imageWidth) / 2),
|
||||||
(y + (height - imageHeight) / 2),
|
((height - imageHeight) / 2),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
imageWidth,
|
imageWidth,
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public class SaturnInputBox extends SaturnWidget {
|
|||||||
|
|
||||||
public SaturnInputBox(
|
public SaturnInputBox(
|
||||||
String placeholder,
|
String placeholder,
|
||||||
int x,
|
|
||||||
int y,
|
int y,
|
||||||
|
int x,
|
||||||
int width,
|
int width,
|
||||||
int height
|
int height
|
||||||
) {
|
) {
|
||||||
@@ -83,8 +83,8 @@ public class SaturnInputBox extends SaturnWidget {
|
|||||||
context.drawGuiTexture(
|
context.drawGuiTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
Textures.BUTTON,
|
Textures.BUTTON,
|
||||||
this.x,
|
0,
|
||||||
this.y,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
SaturnClient.getWhite(this.alpha)
|
SaturnClient.getWhite(this.alpha)
|
||||||
@@ -97,28 +97,21 @@ public class SaturnInputBox extends SaturnWidget {
|
|||||||
context.drawText(
|
context.drawText(
|
||||||
textRenderer,
|
textRenderer,
|
||||||
SaturnUi.text(visibleText),
|
SaturnUi.text(visibleText),
|
||||||
x + 5,
|
5,
|
||||||
y + 5,
|
5,
|
||||||
textColor,
|
textColor,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
int cursorX =
|
int cursorX =
|
||||||
x +
|
|
||||||
5 +
|
5 +
|
||||||
textRenderer.getWidth(
|
textRenderer.getWidth(
|
||||||
SaturnUi.text(
|
SaturnUi.text(
|
||||||
visibleText.substring(0, cursorPosition - scrollOffset)
|
visibleText.substring(0, cursorPosition - scrollOffset)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
context.fill(
|
context.fill(cursorX, 3, cursorX + 1, height - 3, 0xFFFFFFFF);
|
||||||
cursorX,
|
|
||||||
y + 3,
|
|
||||||
cursorX + 1,
|
|
||||||
y + height - 3,
|
|
||||||
0xFFFFFFFF
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package org.saturnclient.ui.widgets;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.ui.SaturnWidget;
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
|
|
||||||
public class SaturnScroll extends SaturnWidget {
|
public class SaturnScroll extends SaturnWidget {
|
||||||
@@ -18,6 +20,8 @@ public class SaturnScroll extends SaturnWidget {
|
|||||||
double horizontalAmount,
|
double horizontalAmount,
|
||||||
double verticalAmount
|
double verticalAmount
|
||||||
) {
|
) {
|
||||||
|
verticalAmount *= 2;
|
||||||
|
|
||||||
if (scroll - verticalAmount <= 0) {
|
if (scroll - verticalAmount <= 0) {
|
||||||
scroll = 0;
|
scroll = 0;
|
||||||
} else if (scroll - verticalAmount >= maxScroll) {
|
} else if (scroll - verticalAmount >= maxScroll) {
|
||||||
@@ -34,31 +38,32 @@ public class SaturnScroll extends SaturnWidget {
|
|||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY
|
int mouseY
|
||||||
) {
|
) {
|
||||||
context.enableScissor(x, y, x + width, y + height);
|
context.enableScissor(0, 0, width, height);
|
||||||
|
|
||||||
for (SaturnWidget child : children) {
|
for (SaturnWidget child : children) {
|
||||||
if (!child.visible) continue;
|
if (!child.visible) continue;
|
||||||
|
|
||||||
int xx = child.x;
|
|
||||||
int yy = child.y;
|
|
||||||
|
|
||||||
child.x += x;
|
|
||||||
child.y += y - scroll;
|
|
||||||
|
|
||||||
boolean isMouseInside =
|
boolean isMouseInside =
|
||||||
child.x < mouseX &&
|
child.x < mouseX &&
|
||||||
child.x + child.width > mouseX &&
|
child.x + child.width > mouseX &&
|
||||||
child.y < mouseY &&
|
child.y < mouseY &&
|
||||||
child.y + child.height > mouseY;
|
child.y + child.height > mouseY;
|
||||||
|
|
||||||
if (child.y < y + height && child.y + child.height > y) {
|
if (child.y - scroll < height && child.y + child.height > scroll) {
|
||||||
child.render(context, isMouseInside, mouseX, mouseY);
|
MatrixStack matrices = context.getMatrices();
|
||||||
|
matrices.push();
|
||||||
|
matrices.translate(child.x, child.y - scroll, 0);
|
||||||
|
matrices.scale(child.scale, child.scale, 1.0f);
|
||||||
|
|
||||||
|
child.render(
|
||||||
|
context,
|
||||||
|
isMouseInside,
|
||||||
|
mouseX - child.x,
|
||||||
|
mouseY - (child.y - scroll)
|
||||||
|
);
|
||||||
|
matrices.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
child.x = xx;
|
|
||||||
child.y = yy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.disableScissor();
|
context.disableScissor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,28 +94,11 @@ public class SaturnScroll extends SaturnWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(int keyCode, int scanCode, int modifiers) {
|
public void keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||||
System.out.println(
|
|
||||||
"[SaturnScroll] Key Pressed: keyCode=" +
|
|
||||||
keyCode +
|
|
||||||
", scanCode=" +
|
|
||||||
scanCode +
|
|
||||||
", modifiers=" +
|
|
||||||
modifiers
|
|
||||||
);
|
|
||||||
|
|
||||||
for (SaturnWidget child : children) {
|
for (SaturnWidget child : children) {
|
||||||
if (!child.visible || !child.focused) {
|
if (!child.visible || !child.focused) {
|
||||||
System.out.println(
|
|
||||||
"[SaturnScroll] Skipping child " +
|
|
||||||
child +
|
|
||||||
" (Not visible or focused)"
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(
|
|
||||||
"[SaturnScroll] Passing key event to child: " + child
|
|
||||||
);
|
|
||||||
child.keyPressed(keyCode, scanCode, modifiers);
|
child.keyPressed(keyCode, scanCode, modifiers);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -118,21 +106,11 @@ public class SaturnScroll extends SaturnWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void charTyped(char typedChar) {
|
public void charTyped(char typedChar) {
|
||||||
System.out.println("[SaturnScroll] Char Typed: '" + typedChar + "'");
|
|
||||||
|
|
||||||
for (SaturnWidget child : children) {
|
for (SaturnWidget child : children) {
|
||||||
if (!child.visible || !child.focused) {
|
if (!child.visible || !child.focused) {
|
||||||
System.out.println(
|
|
||||||
"[SaturnScroll] Skipping child " +
|
|
||||||
child +
|
|
||||||
" (Not visible or focused)"
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(
|
|
||||||
"[SaturnScroll] Passing char event to child: " + child
|
|
||||||
);
|
|
||||||
child.charTyped(typedChar);
|
child.charTyped(typedChar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -150,22 +128,20 @@ public class SaturnScroll extends SaturnWidget {
|
|||||||
for (SaturnWidget widget : children) {
|
for (SaturnWidget widget : children) {
|
||||||
widget.focused = false;
|
widget.focused = false;
|
||||||
if (!widget.visible) {
|
if (!widget.visible) {
|
||||||
System.out.println(
|
|
||||||
"[SaturnScroll] Skipping hidden child: " + widget
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double adjustedMouseX = (mouseX - widget.x) / widget.scale;
|
||||||
|
double adjustedMouseY = (mouseY - widget.y) / widget.scale;
|
||||||
boolean isMouseInside =
|
boolean isMouseInside =
|
||||||
widget.x < mouseX &&
|
adjustedMouseX >= 0 &&
|
||||||
widget.x + widget.width > mouseX &&
|
adjustedMouseX <= widget.width &&
|
||||||
widget.y < mouseY &&
|
adjustedMouseY >= 0 &&
|
||||||
widget.y + widget.height > mouseY;
|
adjustedMouseY <= widget.height;
|
||||||
|
|
||||||
if (isMouseInside) {
|
if (isMouseInside) {
|
||||||
System.out.println("[SaturnScroll] Child clicked: " + widget);
|
|
||||||
widget.focused = true;
|
widget.focused = true;
|
||||||
widget.click(mouseX, mouseY);
|
widget.click((int) adjustedMouseX, (int) adjustedMouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class SaturnSprite extends SaturnWidget {
|
|||||||
context.drawGuiTexture(
|
context.drawGuiTexture(
|
||||||
RenderLayer::getGuiTextured,
|
RenderLayer::getGuiTextured,
|
||||||
sprite,
|
sprite,
|
||||||
this.x,
|
0,
|
||||||
this.y,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
ColorHelper.getWhite(this.alpha)
|
ColorHelper.getWhite(this.alpha)
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ public class SaturnText extends SaturnWidget {
|
|||||||
context.drawText(
|
context.drawText(
|
||||||
SaturnClient.textRenderer,
|
SaturnClient.textRenderer,
|
||||||
SaturnUi.text(text),
|
SaturnUi.text(text),
|
||||||
x,
|
0,
|
||||||
y,
|
0,
|
||||||
SaturnClient.getWhite(alpha),
|
SaturnClient.getWhite(alpha),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user