🐛 Fix a lot of newly introduced bugs.

This commit is contained in:
LambdAurora
2019-12-12 23:49:34 +01:00
parent cf1df6302d
commit ba125fd527
6 changed files with 146 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.7.2+build.174 loader_version=0.7.2+build.174
# Mod Properties # Mod Properties
mod_version = 1.0.0-SNAPSHOT1 mod_version = 1.0.0-SNAPSHOT2
maven_group = me.lambdaurora maven_group = me.lambdaurora
archives_base_name = lambdacontrols archives_base_name = lambdacontrols

View File

@@ -9,6 +9,7 @@
package me.lambdaurora.lambdacontrols; package me.lambdaurora.lambdacontrols;
import me.lambdaurora.lambdacontrols.gui.LabelWidget;
import me.lambdaurora.lambdacontrols.gui.LambdaControlsControlsScreen; import me.lambdaurora.lambdacontrols.gui.LambdaControlsControlsScreen;
import me.lambdaurora.lambdacontrols.mixin.EntryListWidgetAccessor; import me.lambdaurora.lambdacontrols.mixin.EntryListWidgetAccessor;
import me.lambdaurora.lambdacontrols.util.AbstractContainerScreenAccessor; import me.lambdaurora.lambdacontrols.util.AbstractContainerScreenAccessor;
@@ -82,15 +83,18 @@ public class ControllerInput
public void on_tick(@NotNull MinecraftClient client) public void on_tick(@NotNull MinecraftClient client)
{ {
this.prev_target_yaw = this.target_yaw;
this.prev_target_pitch = this.target_pitch;
// Handles the key bindings.
if (LambdaControls.BINDING_LOOK_UP.isPressed()) { if (LambdaControls.BINDING_LOOK_UP.isPressed()) {
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 2); this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 2);
} else if (LambdaControls.BINDING_LOOK_DOWN.isPressed()) { } else if (LambdaControls.BINDING_LOOK_DOWN.isPressed()) {
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 1); this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 1);
} }
if (LambdaControls.BINDING_LOOK_LEFT.isPressed()) {
if (LambdaControls.BINDING_LOOK_RIGHT.isPressed()) {
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 2); this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 2);
} else if (LambdaControls.BINDING_LOOK_LEFT.isPressed()) { } else if (LambdaControls.BINDING_LOOK_RIGHT.isPressed()) {
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 1); this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 1);
} }
} }
@@ -110,8 +114,6 @@ public class ControllerInput
// Decreases the cooldown for GUI actions. // Decreases the cooldown for GUI actions.
if (this.action_gui_cooldown > 0) if (this.action_gui_cooldown > 0)
--this.action_gui_cooldown; --this.action_gui_cooldown;
this.prev_target_yaw = this.target_yaw;
this.prev_target_pitch = this.target_pitch;
this.prev_target_mouse_x = this.target_mouse_x; this.prev_target_mouse_x = this.target_mouse_x;
this.prev_target_mouse_y = this.target_mouse_y; this.prev_target_mouse_y = this.target_mouse_y;
@@ -464,6 +466,9 @@ public class ControllerInput
button_widget.playDownSound(MinecraftClient.getInstance().getSoundManager()); button_widget.playDownSound(MinecraftClient.getInstance().getSoundManager());
button_widget.onPress(); button_widget.onPress();
return true; return true;
} else if (focused instanceof LabelWidget) {
((LabelWidget) focused).on_press();
return true;
} else if (focused instanceof WorldListWidget) { } else if (focused instanceof WorldListWidget) {
WorldListWidget list = (WorldListWidget) focused; WorldListWidget list = (WorldListWidget) focused;
list.method_20159().ifPresent(WorldListWidget.Entry::play); list.method_20159().ifPresent(WorldListWidget.Entry::play);

View File

@@ -9,13 +9,19 @@
package me.lambdaurora.lambdacontrols.gui; package me.lambdaurora.lambdacontrols.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Element;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.Matrix4f;
import net.minecraft.client.util.math.MatrixStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@@ -28,31 +34,34 @@ public class LabelWidget extends DrawableHelper implements Element, Drawable
}; };
private final MinecraftClient client = MinecraftClient.getInstance(); private final MinecraftClient client = MinecraftClient.getInstance();
private final Consumer<LabelWidget> click_action; private final Consumer<LabelWidget> press_action;
private final int x; private final int x;
private final int y; private final int y;
private final int max_width; private final int max_width;
//private final int max_height; //private final int max_height;
private String text; private String text;
private String tooltip_text;
public boolean visible; public boolean visible;
private int width; private int width;
private int height; private int height;
private boolean centered; private boolean centered;
protected boolean hovered;
protected boolean focused;
public LabelWidget(int x, int y, @NotNull String text, int max_width, @NotNull Consumer<LabelWidget> click_action, boolean centered) public LabelWidget(int x, int y, @NotNull String text, int max_width, @NotNull Consumer<LabelWidget> press_action, boolean centered)
{ {
this.visible = true; this.visible = true;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.max_width = max_width; this.max_width = max_width;
this.click_action = click_action; this.press_action = press_action;
this.centered = centered; this.centered = centered;
this.set_text(text); this.set_text(text);
} }
public LabelWidget(int x, int y, @NotNull String text, int max_width, @NotNull Consumer<LabelWidget> click_action) public LabelWidget(int x, int y, @NotNull String text, int max_width, @NotNull Consumer<LabelWidget> press_action)
{ {
this(x, y, text, max_width, click_action, false); this(x, y, text, max_width, press_action, false);
} }
public LabelWidget(int x, int y, @NotNull String text, int max_width, boolean centered) public LabelWidget(int x, int y, @NotNull String text, int max_width, boolean centered)
@@ -73,18 +82,26 @@ public class LabelWidget extends DrawableHelper implements Element, Drawable
public void set_text(@NotNull String text) public void set_text(@NotNull String text)
{ {
int width = this.client.textRenderer.getStringWidth(text); int width = this.client.textRenderer.getStringWidth(text);
if (width > this.max_width) {
while (width > this.max_width) { while (width > this.max_width) {
text = text.substring(0, text.length() - 1); text = text.substring(0, text.length() - 1);
width = this.client.textRenderer.getStringWidth(text); width = this.client.textRenderer.getStringWidth(text);
} }
}
this.text = text; this.text = text;
this.width = width; this.width = width;
this.height = this.client.textRenderer.fontHeight; this.height = this.client.textRenderer.fontHeight;
} }
/**
* Sets the tooltip text of this label.
*
* @param text The tooltip text.
*/
public void set_tooltip_text(String text)
{
this.tooltip_text = text;
}
/** /**
* Gets the width of this label widget. * Gets the width of this label widget.
* *
@@ -105,24 +122,118 @@ public class LabelWidget extends DrawableHelper implements Element, Drawable
return this.height; return this.height;
} }
/**
* Fires the press event on this label widget.
*/
public void on_press()
{
this.press_action.accept(this);
}
@Override @Override
public void render(int mouse_x, int mouse_y, float delta) public void render(int mouse_x, int mouse_y, float delta)
{ {
if (this.centered) if (this.visible) {
this.drawCenteredString(this.client.textRenderer, this.text, this.x, this.y, 10526880); int x = this.centered ? this.x - this.client.textRenderer.getStringWidth(this.text) / 2 : this.x;
else this.hovered = mouse_x >= x && mouse_y >= this.y && mouse_x < x + this.width && mouse_y < this.y + this.height;
this.drawString(this.client.textRenderer, this.text, this.x, this.y, 10526880); this.drawString(this.client.textRenderer, this.text, x, this.y, 10526880);
if (this.tooltip_text != null && !this.tooltip_text.isEmpty()) {
List<String> wrapped_tooltip_text = this.client.textRenderer.wrapStringToWidthAsList(this.tooltip_text, Math.max(this.width / 2, 200));
if (this.hovered)
this.render_tooltip(wrapped_tooltip_text, mouse_x, mouse_y);
else if (this.focused)
this.render_tooltip(wrapped_tooltip_text, this.x - 12, this.y);
}
}
} }
@Override @Override
public boolean mouseClicked(double mouse_x, double mouse_y, int button) public boolean mouseClicked(double mouse_x, double mouse_y, int button)
{ {
if (this.visible && button == GLFW.GLFW_MOUSE_BUTTON_1) { if (this.visible && button == GLFW.GLFW_MOUSE_BUTTON_1) {
if (mouse_x >= (double) this.x && mouse_y >= (double) this.y && mouse_x < (double) (this.x + this.width) && mouse_y < (double) (this.y + this.height)) { if (this.hovered) {
this.click_action.accept(this); this.on_press();
return true; return true;
} }
} }
return false; return false;
} }
@Override
public boolean changeFocus(boolean down)
{
if (this.visible) {
this.focused = !this.focused;
return this.focused;
} else {
return false;
}
}
public void render_tooltip(List<String> text, int x, int y)
{
if (!text.isEmpty()) {
RenderSystem.disableRescaleNormal();
RenderSystem.disableDepthTest();
int i = 0;
for (String string : text) {
int j = this.client.textRenderer.getStringWidth(string);
if (j > i) {
i = j;
}
}
int k = x + 12;
int l = y - 12;
int n = 8;
if (text.size() > 1) {
n += 2 + (text.size() - 1) * 10;
}
if (k + i > this.client.getWindow().getScaledWidth()) {
k -= 28 + i;
}
if (l + n + 6 > this.client.getWindow().getScaledHeight()) {
l = this.client.getWindow().getScaledHeight() - n - 6;
}
this.setBlitOffset(300);
this.client.getItemRenderer().zOffset = 300.0F;
this.fillGradient(k - 3, l - 4, k + i + 3, l - 3, -267386864, -267386864);
this.fillGradient(k - 3, l + n + 3, k + i + 3, l + n + 4, -267386864, -267386864);
this.fillGradient(k - 3, l - 3, k + i + 3, l + n + 3, -267386864, -267386864);
this.fillGradient(k - 4, l - 3, k - 3, l + n + 3, -267386864, -267386864);
this.fillGradient(k + i + 3, l - 3, k + i + 4, l + n + 3, -267386864, -267386864);
this.fillGradient(k - 3, l - 3 + 1, k - 3 + 1, l + n + 3 - 1, 1347420415, 1344798847);
this.fillGradient(k + i + 2, l - 3 + 1, k + i + 3, l + n + 3 - 1, 1347420415, 1344798847);
this.fillGradient(k - 3, l - 3, k + i + 3, l - 3 + 1, 1347420415, 1347420415);
this.fillGradient(k - 3, l + n + 2, k + i + 3, l + n + 3, 1344798847, 1344798847);
MatrixStack matrixStack = new MatrixStack();
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
matrixStack.translate(0.0D, 0.0D, this.client.getItemRenderer().zOffset);
Matrix4f matrix4f = matrixStack.peek().getModel();
for (int r = 0; r < text.size(); ++r) {
String string2 = text.get(r);
if (string2 != null) {
this.client.textRenderer.draw(string2, (float) k, (float) l, -1, true, matrix4f, immediate, false, 0, 15728880);
}
if (r == 0) {
l += 2;
}
l += 10;
}
immediate.draw();
this.setBlitOffset(0);
this.client.getItemRenderer().zOffset = 0.0F;
RenderSystem.enableDepthTest();
RenderSystem.enableRescaleNormal();
}
}
} }

View File

@@ -36,7 +36,7 @@ public class LambdaControlsHud extends DrawableHelper
*/ */
public void render() public void render()
{ {
if (this.mod.config.get_controls_mode() == ControlsMode.CONTROLLER && this.mod.config.is_hud_enabled() && this.client.currentScreen == null) { if (this.mod.config.get_controls_mode() == ControlsMode.CONTROLLER && this.mod.config.is_hud_enabled() && this.client.currentScreen == null && !this.client.options.hudHidden) {
int x = 10, y = bottom(10); int x = 10, y = bottom(10);
x += this.draw_button_tip(x, y, ButtonBinding.INVENTORY, true) + 10; x += this.draw_button_tip(x, y, ButtonBinding.INVENTORY, true) + 10;
this.draw_button_tip(x, y, ButtonBinding.SWAP_HANDS, true); this.draw_button_tip(x, y, ButtonBinding.SWAP_HANDS, true);

View File

@@ -147,6 +147,7 @@ public class LambdaControlsSettingsScreen extends Screen
this.gamepad_tool_url_label = new LabelWidget(this.width / 2, this.height - 29 - (5 + this.font.fontHeight) * 2, this.controller_mappings_url_text, this.width, this.gamepad_tool_url_label = new LabelWidget(this.width / 2, this.height - 29 - (5 + this.font.fontHeight) * 2, this.controller_mappings_url_text, this.width,
label -> Util.getOperatingSystem().open(GAMEPAD_TOOL_URL), true); label -> Util.getOperatingSystem().open(GAMEPAD_TOOL_URL), true);
this.gamepad_tool_url_label.set_tooltip_text(I18n.translate("chat.link.open"));
this.children.add(this.gamepad_tool_url_label); this.children.add(this.gamepad_tool_url_label);
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height - 29, 300, button_height, I18n.translate("gui.done"), this.addButton(new ButtonWidget(this.width / 2 - 155, this.height - 29, 300, button_height, I18n.translate("gui.done"),

View File

@@ -253,4 +253,10 @@ public class TouchscreenOverlay extends Screen
{ {
super.render(mouseX, mouseY, delta); super.render(mouseX, mouseY, delta);
} }
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button)
{
return false;
}
} }