mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
1.21.6-1.21.8 backport
This commit is contained in:
@@ -2,12 +2,9 @@ package de.shiewk.widgets;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.input.CharInput;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -46,23 +43,23 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
|
||||
public abstract JsonElement saveState();
|
||||
public abstract void loadState(JsonElement state);
|
||||
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseReleased(Click click){
|
||||
public boolean mouseReleased(double mouseX, double mouseY){
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean charTyped(CharInput input) {
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean keyPressed(KeyInput input) {
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean keyReleased(KeyInput input) {
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class WidgetsModClient implements ClientModInitializer {
|
||||
"widgets.key.config",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_RIGHT_SHIFT,
|
||||
KeyBinding.Category.create(Identifier.of(WidgetsMod.MOD_ID, "main"))
|
||||
"widgets.key.category"
|
||||
));
|
||||
|
||||
// in-game /widgetsmod command
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package de.shiewk.widgets.client.screen;
|
||||
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
@@ -75,12 +73,12 @@ public class ContextMenuScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
if (!isInBounds(click.x(), click.y())){
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (!isInBounds(mouseX, mouseY)){
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
int opt = (int) (click.y() - menuY - 1) / 15;
|
||||
int opt = (int) (mouseY - menuY - 1) / 15;
|
||||
if (opt < options.size()){
|
||||
Option option = options.get(opt);
|
||||
close();
|
||||
@@ -98,7 +96,7 @@ public class ContextMenuScreen extends Screen {
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
||||
super.render(context, mouseX, mouseY, deltaTicks);
|
||||
parent.render(context, -67, -67, deltaTicks);
|
||||
context.drawStrokedRectangle(
|
||||
context.drawBorder(
|
||||
menuX,
|
||||
menuY,
|
||||
menuWidth,
|
||||
@@ -127,7 +125,6 @@ public class ContextMenuScreen extends Screen {
|
||||
y + 15,
|
||||
0x30_ff_ff_ff
|
||||
);
|
||||
context.setCursor(StandardCursors.POINTING_HAND);
|
||||
}
|
||||
context.drawText(textRenderer, option.title, menuX + 5, y + 3, option.highlighted ? 0xff_00_ff_ff : 0xff_ff_ff_ff, false);
|
||||
y += 15;
|
||||
|
||||
@@ -6,9 +6,7 @@ import de.shiewk.widgets.WidgetSettings;
|
||||
import de.shiewk.widgets.client.WidgetManager;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
@@ -93,15 +91,11 @@ public class EditWidgetPositionsScreen extends AnimatedScreen {
|
||||
}
|
||||
}
|
||||
if (selectedWidget == null ? hoveredWidget == widget : selectedWidget == widget){
|
||||
context.drawStrokedRectangle(wx-1,wy-1, ww+2, wh+2, SELECT_COLOR);
|
||||
context.drawStrokedRectangle(wx, wy, ww, wh, SELECT_COLOR);
|
||||
context.drawBorder(wx-1,wy-1, ww+2, wh+2, SELECT_COLOR);
|
||||
context.drawBorder(wx, wy, ww, wh, SELECT_COLOR);
|
||||
}
|
||||
widget.render(context, mt, textRenderer, wx, wy);
|
||||
}
|
||||
|
||||
if (hoveredWidget != null){
|
||||
context.setCursor(StandardCursors.RESIZE_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canAlign(int val1, int val2){
|
||||
@@ -220,8 +214,8 @@ public class EditWidgetPositionsScreen extends AnimatedScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
if (click.button() == 0 && selectedWidget != null){
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
if (button == 0 && selectedWidget != null){
|
||||
if (align){
|
||||
AlignResult alignedX = alignX(selectedWidget);
|
||||
if (alignedX != null){
|
||||
@@ -243,18 +237,18 @@ public class EditWidgetPositionsScreen extends AnimatedScreen {
|
||||
onEdit.accept(selectedWidget);
|
||||
selectedWidget = null;
|
||||
}
|
||||
return super.mouseReleased(click);
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
if (click.button() == 0 && hoveredWidget != null){
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button == 0 && hoveredWidget != null){
|
||||
selectedWidget = hoveredWidget;
|
||||
focusedExtraX = (int) (click.x() - hoveredWidget.getX(scaledWindowWidth));
|
||||
focusedExtraY = (int) (click.y() - hoveredWidget.getY(scaledWindowHeight));
|
||||
} else if (click.button() == 1){
|
||||
int x = (int) click.x();
|
||||
int y = (int) click.y();
|
||||
focusedExtraX = (int) (mouseX - hoveredWidget.getX(scaledWindowWidth));
|
||||
focusedExtraY = (int) (mouseY - hoveredWidget.getY(scaledWindowHeight));
|
||||
} else if (button == 1){
|
||||
int x = (int) mouseX;
|
||||
int y = (int) mouseY;
|
||||
ModWidget hovered = hoveredWidget;
|
||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
||||
assert client != null;
|
||||
@@ -347,12 +341,12 @@ public class EditWidgetPositionsScreen extends AnimatedScreen {
|
||||
));
|
||||
}
|
||||
}
|
||||
return super.mouseClicked(click, doubled);
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(Click click, double deltaX, double deltaY) {
|
||||
if (click.button() == 0){
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
if (button == 0){
|
||||
assert client != null;
|
||||
final ModWidget widget = selectedWidget;
|
||||
if (widget != null){
|
||||
@@ -361,14 +355,14 @@ public class EditWidgetPositionsScreen extends AnimatedScreen {
|
||||
int wx = MathHelper.clamp(widget.getX(scaledWindowWidth), 0, this.width - ww);
|
||||
final int wh = (int) (widget.height() * widget.getScaleFactor());
|
||||
int wy = MathHelper.clamp(widget.getY(scaledWindowHeight), 0, this.height - wh);
|
||||
if (click.x() <= wx + ww + deltaX && click.x() >= wx + deltaX){
|
||||
if (click.y() <= wy + wh + deltaY && click.y() >= wy + deltaY){
|
||||
Anchor anchor = Anchor.getAnchor(scaledWindowWidth, scaledWindowHeight, (int) click.x(), (int) click.y());
|
||||
if (mouseX <= wx + ww + deltaX && mouseX >= wx + deltaX){
|
||||
if (mouseY <= wy + wh + deltaY && mouseY >= wy + deltaY){
|
||||
Anchor anchor = Anchor.getAnchor(scaledWindowWidth, scaledWindowHeight, (int) mouseX, (int) mouseY);
|
||||
if (anchor == null) {
|
||||
return false;
|
||||
}
|
||||
int newOffX = (int) (click.x() - anchor.getAlignStartPosX(scaledWindowWidth)) - focusedExtraX;
|
||||
int newOffY = (int) (click.y() - anchor.getAlignStartPosY(scaledWindowHeight)) - focusedExtraY;
|
||||
int newOffX = (int) (mouseX - anchor.getAlignStartPosX(scaledWindowWidth)) - focusedExtraX;
|
||||
int newOffY = (int) (mouseY - anchor.getAlignStartPosY(scaledWindowHeight)) - focusedExtraY;
|
||||
|
||||
settings.setPos(anchor, newOffX, newOffY);
|
||||
|
||||
@@ -395,7 +389,7 @@ public class EditWidgetPositionsScreen extends AnimatedScreen {
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.mouseDragged(click, deltaX, deltaY);
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.shiewk.widgets.client.screen;
|
||||
|
||||
import de.shiewk.widgets.ModWidget;
|
||||
import de.shiewk.widgets.client.screen.components.WidgetSettingsEditWidget;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
@@ -38,13 +37,13 @@ public class WidgetSettingsScreen extends AnimatedScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
for (Element child : children()) {
|
||||
if (child instanceof ClickableWidget s){
|
||||
s.mouseReleased(click);
|
||||
s.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
return super.mouseReleased(click);
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.shiewk.widgets.client.screen.components;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
@@ -36,7 +35,7 @@ public class ScaledTextWidget extends ClickableWidget {
|
||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import de.shiewk.widgets.ModWidget;
|
||||
import de.shiewk.widgets.client.WidgetManager;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
@@ -101,18 +100,15 @@ public class WidgetListWidget extends ScrollableWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
double mouseY = click.y();
|
||||
double mouseX = click.x();
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
mouseY += getScrollY();
|
||||
Click newClick = new Click(mouseX, mouseY, click.buttonInfo());
|
||||
for (Element element : elements) {
|
||||
if (element.mouseClicked(newClick, doubled)){
|
||||
if (element.mouseClicked(mouseX, mouseY, button)){
|
||||
client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.checkScrollbarDragged(newClick);
|
||||
return super.checkScrollbarDragged(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+15
-20
@@ -3,12 +3,9 @@ package de.shiewk.widgets.client.screen.components;
|
||||
import de.shiewk.widgets.ModWidget;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ScrollableWidget;
|
||||
import net.minecraft.client.input.CharInput;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
import org.joml.Matrix3x2fStack;
|
||||
|
||||
@@ -84,16 +81,14 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
double mouseY = click.y();
|
||||
double mouseX = click.x();
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
mouseY += getScrollY();
|
||||
for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) {
|
||||
if (!customSetting.shouldShow()) continue;
|
||||
if (customSetting.isHovered(mouseX, mouseY)){
|
||||
focus = customSetting;
|
||||
customSetting.setFocused(true);
|
||||
if (customSetting.mouseClicked(new Click(mouseX, mouseY + getScrollY(), click.buttonInfo()), doubled)){
|
||||
if (customSetting.mouseClicked(mouseX, mouseY + getScrollY(), button)){
|
||||
onChange.run();
|
||||
return true;
|
||||
}
|
||||
@@ -101,52 +96,52 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
||||
customSetting.setFocused(false);
|
||||
}
|
||||
}
|
||||
return checkScrollbarDragged(click);
|
||||
return checkScrollbarDragged(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) {
|
||||
if (!customSetting.shouldShow()) continue;
|
||||
if (customSetting.mouseReleased(new Click(click.x(), click.y() + getScrollY(), click.buttonInfo()))){
|
||||
if (customSetting.mouseReleased(mouseX, mouseY + getScrollY())){
|
||||
onChange.run();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.mouseReleased(click);
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(CharInput input) {
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
if (this.focus != null){
|
||||
if (this.focus.charTyped(input)){
|
||||
if (this.focus.charTyped(chr, modifiers)){
|
||||
onChange.run();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.charTyped(input);
|
||||
return super.charTyped(chr, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(KeyInput input) {
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (this.focus != null){
|
||||
if (this.focus.keyPressed(input)){
|
||||
if (this.focus.keyPressed(keyCode, scanCode, modifiers)){
|
||||
onChange.run();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.keyPressed(input);
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(KeyInput input) {
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
if (this.focus != null){
|
||||
if (this.focus.keyReleased(input)){
|
||||
if (this.focus.keyReleased(keyCode, scanCode, modifiers)){
|
||||
onChange.run();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.keyReleased(input);
|
||||
return super.keyReleased(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,9 +5,7 @@ import de.shiewk.widgets.client.screen.WidgetSettingsScreen;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.text.OrderedText;
|
||||
@@ -69,10 +67,6 @@ public class WidgetWidget extends ClickableWidget {
|
||||
}
|
||||
this.renderToggleButton(context, mouseX, mouseY, widgetEnabled);
|
||||
|
||||
if (hover || isMouseOverToggle(mouseX, mouseY)){
|
||||
context.setCursor(StandardCursors.POINTING_HAND);
|
||||
}
|
||||
|
||||
context.drawHorizontalLine(getX(), getX() + getWidth() - 1, getY(), COLOR_BORDER);
|
||||
context.drawHorizontalLine(getX() + 1, getX() + getWidth() - 1, getY() + getHeight() - 1, COLOR_BORDER);
|
||||
context.drawVerticalLine(getX(), getY(), getY() + getHeight(), COLOR_BORDER);
|
||||
@@ -80,11 +74,11 @@ public class WidgetWidget extends ClickableWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
if (isMouseOver(click.x(), click.y())){
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isMouseOver(mouseX, mouseY)){
|
||||
client.setScreen(new WidgetSettingsScreen(client.currentScreen, widget, onEdit));
|
||||
return true;
|
||||
} else if (isMouseOverToggle(click.x(), click.y())){
|
||||
} else if (isMouseOverToggle(mouseX, mouseY)){
|
||||
this.toggleWidget();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package de.shiewk.widgets.mixin;
|
||||
|
||||
import de.shiewk.widgets.widgets.CPSWidget;
|
||||
import net.minecraft.client.Mouse;
|
||||
import net.minecraft.client.input.MouseInput;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -11,18 +11,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(Mouse.class)
|
||||
public class MixinMouse {
|
||||
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;leftButtonClicked:Z"), method = "onMouseButton")
|
||||
public void onLeftClick(long window, MouseInput input, int action, CallbackInfo ci){
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;leftButtonClicked:Z", opcode = Opcodes.PUTFIELD), method = "onMouseButton")
|
||||
public void onLeftClick(long window, int button, int action, int mods, CallbackInfo ci){
|
||||
if (action == 1) CPSWidget.clickLeft();
|
||||
}
|
||||
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;middleButtonClicked:Z"), method = "onMouseButton")
|
||||
public void onMiddleClick(long window, MouseInput input, int action, CallbackInfo ci){
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;middleButtonClicked:Z", opcode = Opcodes.PUTFIELD), method = "onMouseButton")
|
||||
public void onMiddleClick(long window, int button, int action, int mods, CallbackInfo ci){
|
||||
if (action == 1) CPSWidget.clickMiddle();
|
||||
}
|
||||
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;rightButtonClicked:Z"), method = "onMouseButton")
|
||||
public void onRightClick(long window, MouseInput input, int action, CallbackInfo ci){
|
||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;rightButtonClicked:Z", opcode = Opcodes.PUTFIELD), method = "onMouseButton")
|
||||
public void onRightClick(long window, int button, int action, int mods, CallbackInfo ci){
|
||||
if (action == 1) CPSWidget.clickRight();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SpeedWidget extends BasicTextWidget {
|
||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||
if (player != null) {
|
||||
Vec3d lastPos = this.lastPos;
|
||||
Vec3d newPos = this.lastPos = player.getEntityPos();
|
||||
Vec3d newPos = this.lastPos = player.getPos();
|
||||
Vec3d velocity = lastPos.subtract(newPos);
|
||||
double rt = 0;
|
||||
if (withXVelocity) rt += velocity.getX() * velocity.getX();
|
||||
|
||||
@@ -6,9 +6,7 @@ import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@@ -78,9 +76,6 @@ public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption {
|
||||
this.changed = true;
|
||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
||||
}
|
||||
if (hover){
|
||||
context.setCursor(StandardCursors.POINTING_HAND);
|
||||
}
|
||||
nx += textRendererWidth + 20;
|
||||
}
|
||||
|
||||
@@ -89,13 +84,13 @@ public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
mouseClick = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
public boolean mouseReleased(double mouseX, double mouseY) {
|
||||
mouseClick = false;
|
||||
boolean changed = this.changed;
|
||||
this.changed = false;
|
||||
|
||||
@@ -5,12 +5,10 @@ import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
|
||||
@@ -28,11 +26,11 @@ public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(KeyInput input) {
|
||||
if (maxValue > value && input.isRight()) {
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (maxValue > value && keyCode == GLFW.GLFW_KEY_RIGHT) {
|
||||
value++;
|
||||
return true;
|
||||
} else if (minValue < value && input.isLeft()){
|
||||
} else if (minValue < value && keyCode == GLFW.GLFW_KEY_LEFT){
|
||||
value--;
|
||||
return true;
|
||||
}
|
||||
@@ -72,9 +70,6 @@ public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
this.changed = true;
|
||||
this.value = MathHelper.clamp(xPosToValue(mouseX), minValue, maxValue);
|
||||
}
|
||||
if (isHovering(mouseX, mouseY)){
|
||||
context.setCursor(StandardCursors.RESIZE_EW);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isHovering(int mouseX, int mouseY) {
|
||||
@@ -85,13 +80,13 @@ public class IntSliderWidgetSetting extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
this.clicked = true;
|
||||
return super.mouseClicked(click, doubled);
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
public boolean mouseReleased(double mouseX, double mouseY) {
|
||||
this.clicked = false;
|
||||
boolean t = this.changed;
|
||||
this.changed = false;
|
||||
|
||||
@@ -6,16 +6,14 @@ import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -88,10 +86,6 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
0xff_ff_ff_ff,
|
||||
true
|
||||
);
|
||||
|
||||
if (this.isHovered(mouseX, mouseY)){
|
||||
context.setCursor(StandardCursors.POINTING_HAND);
|
||||
}
|
||||
}
|
||||
|
||||
private String toHexSingle(int comp){
|
||||
@@ -104,7 +98,7 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
||||
client.setScreen(
|
||||
@@ -181,7 +175,7 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
||||
parent.render(context, 0, 0, deltaTicks);
|
||||
context.fill(x, y, x+ RECT_WIDTH, y+ RECT_HEIGHT,0xc0_00_00_00);
|
||||
context.drawStrokedRectangle(x, y, RECT_WIDTH, RECT_HEIGHT, 0x67_ff_ff_ff);
|
||||
context.drawBorder(x, y, RECT_WIDTH, RECT_HEIGHT, 0x67_ff_ff_ff);
|
||||
super.render(context, mouseX, mouseY, deltaTicks);
|
||||
}
|
||||
|
||||
@@ -191,13 +185,13 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
if (click.x() < x || click.y() < y || click.x() > x + RECT_WIDTH || click.y() > y + RECT_HEIGHT){
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (mouseX < x || mouseY < y || mouseX > x + RECT_WIDTH || mouseY > y + RECT_HEIGHT){
|
||||
close();
|
||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_OFF);
|
||||
return false;
|
||||
}
|
||||
return super.mouseClicked(click, doubled);
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public class ColorBar extends ClickableWidget {
|
||||
@@ -265,9 +259,6 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
int textWidth = textRenderer.getWidth(text);
|
||||
context.drawText(textRenderer, text, getX() + (getWidth() / 2 - textWidth / 2), getY() + 142, 0xffffffff, true);
|
||||
}
|
||||
if (isHovered()){
|
||||
context.setCursor(StandardCursors.RESIZE_NS);
|
||||
}
|
||||
}
|
||||
|
||||
private String componentLabel() {
|
||||
@@ -281,14 +272,14 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
return this.mouseDragged(click, 0, 0);
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return this.mouseDragged(mouseX, mouseY, button, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(Click click, double offsetX, double offsetY) {
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double offsetX, double offsetY) {
|
||||
if (isHovered()){
|
||||
double pos = click.y() - this.getY() - 10;
|
||||
double pos = mouseY - this.getY() - 10;
|
||||
int val = (int) (255 - pos * 2);
|
||||
setValue(val);
|
||||
return true;
|
||||
@@ -307,15 +298,15 @@ public class RGBAColorWidgetSetting extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(KeyInput input) {
|
||||
if (input.isUp()) {
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (keyCode == GLFW.GLFW_KEY_UP) {
|
||||
setValue(getValue() + 1);
|
||||
return true;
|
||||
} else if (input.isDown()) {
|
||||
} else if (keyCode == GLFW.GLFW_KEY_DOWN) {
|
||||
setValue(getValue() - 1);
|
||||
return true;
|
||||
} else {
|
||||
return super.keyPressed(input);
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-13
@@ -6,11 +6,8 @@ import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.WidgetsMod;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.input.CharInput;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class TextFieldWidgetSettingOption extends WidgetSettingOption {
|
||||
@@ -95,28 +92,28 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
return isFocused() && textField.mouseClicked(click, doubled);
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return isFocused() && textField.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
return isFocused() && textField.mouseReleased(click);
|
||||
public boolean mouseReleased(double mouseX, double mouseY) {
|
||||
return isFocused() && textField.mouseReleased(mouseX, mouseY, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(CharInput input) {
|
||||
return isFocused() && textField.charTyped(input);
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
return isFocused() && textField.charTyped(chr, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(KeyInput input) {
|
||||
return isFocused() && textField.keyPressed(input);
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return isFocused() && textField.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(KeyInput input) {
|
||||
return isFocused() && textField.keyReleased(input);
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
return isFocused() && textField.keyReleased(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,9 +4,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.shiewk.widgets.WidgetSettingOption;
|
||||
import de.shiewk.widgets.utils.WidgetUtils;
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Util;
|
||||
@@ -56,14 +54,9 @@ public class ToggleWidgetSetting extends WidgetSettingOption {
|
||||
: value ? getX() + getWidth() - 4 - 12 : getX() + 4;
|
||||
context.fill(getX() + 2, getY() + 2, getX() + getWidth() - 2, getY() + getHeight() - 2, col);
|
||||
context.fill(thumbLoc, getY() + 4, thumbLoc + 12, getY() + getHeight() - 4, thumb);
|
||||
|
||||
if (this.isHovered(mouseX, mouseY)){
|
||||
context.setCursor(StandardCursors.POINTING_HAND);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user