fix a bunch of stuff that I intentionally broke

This commit is contained in:
GiantLuigi4 2023-09-22 16:25:45 -04:00
parent 2c931928d8
commit 5281694d6a
14 changed files with 864 additions and 838 deletions

View File

@ -153,19 +153,19 @@ public class GuiKeyboard extends WDScreen {
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if(quitOnEscape && keyCode == GLFW.GLFW_KEY_ESCAPE)
Minecraft.getInstance().setScreen(null);
addKey(new TypeData(TypeData.Action.PRESS, keyCode, modifiers));
addKey(new TypeData(TypeData.Action.PRESS, keyCode, modifiers, scanCode));
return super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
public boolean charTyped(char codePoint, int modifiers) {
addKey(new TypeData(TypeData.Action.TYPE, codePoint, modifiers));
addKey(new TypeData(TypeData.Action.TYPE, codePoint, modifiers, 0));
return super.charTyped(codePoint, modifiers);
}
@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
addKey(new TypeData(TypeData.Action.RELEASE, keyCode, modifiers));
addKey(new TypeData(TypeData.Action.RELEASE, keyCode, modifiers, scanCode));
return super.keyPressed(keyCode, scanCode, modifiers);
}

File diff suppressed because it is too large Load Diff

View File

@ -116,11 +116,11 @@ public abstract class WDScreen extends Screen {
if(defaultBackground)
renderBackground(poseStack);
// for(Control ctrl: controls)
// ctrl.draw(poseStack, mouseX, mouseY, ptt);
//
// for(Control ctrl: postDrawList)
// ctrl.postDraw(poseStack, mouseX, mouseY, ptt);
for(Control ctrl: controls)
ctrl.draw(poseStack, mouseX, mouseY, ptt);
for(Control ctrl: postDrawList)
ctrl.postDraw(poseStack, mouseX, mouseY, ptt);
}
@Override
@ -363,12 +363,12 @@ public abstract class WDScreen extends Screen {
}
}
public void drawItemStackTooltip(PoseStack poseStack, ItemStack is, int x, int y) {
// renderTooltip(poseStack, is, x, y); //Since it's protected...
public void drawItemStackTooltip(GuiGraphics poseStack, ItemStack is, int x, int y) {
poseStack.renderTooltip(Minecraft.getInstance().font, is, x, y); //Since it's protected...
}
public void drawTooltip(PoseStack poseStack, List<String> lines, int x, int y) {
// renderTooltip(poseStack, lines.stream().map(a -> FormattedCharSequence.forward(a, Style.EMPTY)).collect(Collectors.toList()), x, y, font); //This is also protected...
public void drawTooltip(GuiGraphics poseStack, List<String> lines, int x, int y) {
poseStack.renderTooltip(Minecraft.getInstance().font, lines.stream().map(a -> FormattedCharSequence.forward(a, Style.EMPTY)).collect(Collectors.toList()), x, y); //This is also protected...
}
public void requirePostDraw(Control ctrl) {

View File

@ -9,6 +9,7 @@ import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import org.lwjgl.glfw.GLFW;
@ -83,6 +84,7 @@ public class Button extends Control {
@Override
public void draw(GuiGraphics poseStack, int mouseX, int mouseY, float ptt) {
btn.setFGColor(16777215);
btn.render(poseStack, mouseX, mouseY, ptt);
}
@ -114,20 +116,17 @@ public class Button extends Control {
@Override
public void setPos(int x, int y) {
// btn.x = x;
// btn.y = y;
btn.setPosition(x, y);
}
@Override
public int getX() {
// return btn.x;
return 0;
return btn.getX();
}
@Override
public int getY() {
// return btn.y;
return 0;
return btn.getY();
}
public net.minecraft.client.gui.components.Button getMcButton() {
@ -217,8 +216,10 @@ public class Button extends Control {
@Override
public void load(JsonOWrapper json) {
super.load(json);
// btn.x = json.getInt("x", 0);
// btn.y = json.getInt("y", 0);
btn.setPosition(
json.getInt("x", 0),
json.getInt("y", 0)
);
btn.setWidth(json.getInt("width", 200));
btn.setHeight(json.getInt("height", 20));
btn.setMessage(Component.nullToEmpty(tr(json.getString("label", btn.getMessage().getContents().toString()))));

View File

@ -7,6 +7,7 @@ package net.montoyo.wd.client.gui.controls;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.resources.ResourceLocation;
@ -77,20 +78,20 @@ public class CheckBox extends BasicControl {
@Override
public void draw(GuiGraphics poseStack, int mouseX, int mouseY, float ptt) {
// if(visible) {
//// GlStateManager.disableAlpha();
// poseStack.pushPose();
// RenderSystem.setShaderTexture(2, checked ? texChecked : texUnchecked);
// RenderSystem.bindTexture(2);
// RenderSystem.enableBlend();
// fillTexturedRect(poseStack, x, y, WIDTH, HEIGHT, 0.0, 0.0, 1.0, 1.0);
// RenderSystem.disableBlend();
// RenderSystem.bindTexture(-1);
//
// poseStack.popPose();
// boolean inside = (!disabled && mouseX >= x && mouseX <= x + WIDTH + 2 + labelW && mouseY >= y && mouseY < y + HEIGHT);
//// font.draw(poseStack, label, x + WIDTH + 2, y + 4, inside ? 0xFF0080FF : COLOR_WHITE);
// }
if(visible) {
// GlStateManager.disableAlpha();
poseStack.pose().pushPose();
RenderSystem.setShaderTexture(2, checked ? texChecked : texUnchecked);
RenderSystem.bindTexture(2);
RenderSystem.enableBlend();
fillTexturedRect(poseStack.pose(), x, y, WIDTH, HEIGHT, 0.0, 0.0, 1.0, 1.0);
RenderSystem.disableBlend();
RenderSystem.bindTexture(-1);
poseStack.pose().popPose();
boolean inside = (!disabled && mouseX >= x && mouseX <= x + WIDTH + 2 + labelW && mouseY >= y && mouseY < y + HEIGHT);
poseStack.drawString(Minecraft.getInstance().font, label, x + WIDTH + 2, y + 4, inside ? 0xFF0080FF : COLOR_WHITE, false);
}
}
public void setLabel(String label) {
@ -137,7 +138,7 @@ public class CheckBox extends BasicControl {
@Override
public void postDraw(GuiGraphics poseStack, int mouseX, int mouseY, float ptt) {
if(tooltip != null && !disabled && mouseX >= x && mouseX <= x + WIDTH + 2 + labelW && mouseY >= y && mouseY < y + HEIGHT)
parent.drawTooltip(poseStack.pose(), tooltip, mouseX, mouseY);
parent.drawTooltip(poseStack, tooltip, mouseX, mouseY);
}
}

View File

@ -164,11 +164,11 @@ public abstract class Control {
RenderSystem.setShaderTexture(0, resLoc);
}
public void drawBorder(PoseStack poseStack, int x, int y, int w, int h, int color) {
public void drawBorder(GuiGraphics poseStack, int x, int y, int w, int h, int color) {
drawBorder(poseStack, x, y, w, h, color, 1.0);
}
public void drawBorder(PoseStack poseStack, int x, int y, int w, int h, int color, double sz) {
public void drawBorder(GuiGraphics poseStack, int x, int y, int w, int h, int color, double sz) {
double x1 = (double) x;
double y1 = (double) y;
double x2 = (double) (x + w);
@ -213,13 +213,17 @@ public abstract class Control {
// RenderSystem.enableTexture();
}
public PoseStack beginFramebuffer(RenderTarget fbo, float vpW, float vpH) {
public GuiGraphics beginFramebuffer(RenderTarget fbo, float vpW, float vpH) {
GuiGraphics tmpGraphics = new GuiGraphics(Minecraft.getInstance(), Minecraft.getInstance().renderBuffers().bufferSource());
fbo.bindWrite(true);
RenderSystem.backupProjectionMatrix();
RenderSystem.setProjectionMatrix(new Matrix4f().ortho(0.0f, vpW, vpH, 0.0f, -1.0f,1.0f), VertexSorting.ORTHOGRAPHIC_Z);
PoseStack poseStack = RenderSystem.getModelViewStack();
tmpGraphics.pose().last().pose().set(RenderSystem.getModelViewStack().last().pose());
tmpGraphics.pose().last().normal().set(RenderSystem.getModelViewStack().last().normal());
PoseStack poseStack = tmpGraphics.pose();
poseStack.pushPose();
poseStack.setIdentity();
// poseStack.mulPose(Vector3f.XP.rotationDegrees(180.0f));
@ -228,17 +232,17 @@ public abstract class Control {
if(!fbo.useDepth)
RenderSystem.disableDepthTest();
return poseStack;
return tmpGraphics;
}
public void endFramebuffer(PoseStack poseStack, RenderTarget fbo) {
public void endFramebuffer(GuiGraphics poseStack, RenderTarget fbo) {
if(!fbo.useDepth)
RenderSystem.enableDepthTest();
RenderSystem.colorMask(true, true, true, true);
RenderSystem.restoreProjectionMatrix();
poseStack.popPose();
poseStack.pose().popPose();
RenderSystem.applyModelViewMatrix();
fbo.unbindWrite();
mc.getMainRenderTarget().bindWrite(true);

View File

@ -9,6 +9,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import net.montoyo.wd.utilities.Bounds;
@ -164,8 +165,8 @@ public class ControlGroup extends Container {
// RenderSystem.enableTexture();
poseStack.pose().popPose();
// if(labelW != 0)
// font.drawShadow(poseStack, label, x + 10 + ((int) bp), y, labelColor, labelShadowed);
if(labelW != 0)
poseStack.drawString(Minecraft.getInstance().font, label, x + 10 + ((int) bp), y, labelColor, labelShadowed);
}
}

View File

@ -5,6 +5,7 @@
package net.montoyo.wd.client.gui.controls;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
@ -74,8 +75,11 @@ public class Label extends BasicControl {
@Override
public void draw(GuiGraphics poseStack, int mouseX, int mouseY, float ptt) {
// if(visible)
// font.drawShadow(poseStack, label, x, y, color, shadowed);
if(visible)
poseStack.drawString(
Minecraft.getInstance().font,
label, x, y, color, shadowed
);
}
@Override

View File

@ -107,8 +107,8 @@ public class List extends BasicControl {
}
private void renderToFBO() {
PoseStack poseStack = beginFramebuffer(fbo, width, height);
poseStack.pushPose();
GuiGraphics poseStack = beginFramebuffer(fbo, width, height);
poseStack.pose().pushPose();
fillRect(0, 0, width, height, COLOR_BLACK);
RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f);
@ -121,13 +121,13 @@ public class List extends BasicControl {
break;
int color = (i == selected) ? selColor : COLOR_WHITE;
// font.draw(poseStack, content.get(i).text, 4, i * 12 + offset, color);
poseStack.drawString(font, content.get(i).text, 4, i * 12 + offset, color);
}
}
drawBorder(poseStack, 0, 0, width, height, 0xFF808080);
endFramebuffer(poseStack, fbo);
poseStack.popPose();
poseStack.pose().popPose();
}
@Override
@ -321,7 +321,7 @@ public class List extends BasicControl {
fbo.bindRead(); //TODO: Make sure is right
RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f);
// fillTexturedRect(poseStack, x, y, width, height, 0.0, 1.0, 1.0, 0.0);
fillTexturedRect(poseStack.pose(), x, y, width, height, 0.0, 1.0, 1.0, 0.0);
fbo.unbindRead();
fillRect(x + width - 5, y + 1 + scrollPos, 4, scrollSize, (scrolling || isInScrollbar(mouseX, mouseY)) ? 0xFF202020 : 0xFF404040);

View File

@ -166,7 +166,9 @@ public class TextField extends Control {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
return field.mouseClicked(mouseX, mouseY, mouseButton);
if (field.mouseClicked(mouseX, mouseY, mouseButton))
setFocused(true);
return false;
}
@Override
@ -242,25 +244,25 @@ public class TextField extends Control {
@Override
public void setPos(int x, int y) {
// field.x = x + 1;
// field.y = y + 1;
field.setPosition(
x + 1,
y + 1
);
}
@Override
public int getX() {
// return field.x - 1;
return 0;
return field.getX() - 1;
}
@Override
public int getY() {
// return field.y - 1;
return 0;
return field.getY() - 1;
}
public void setDisabled(boolean en) {
enabled = !en;
// field.setFocus(enabled);
field.setFocused(enabled);
}
public boolean isDisabled() {
@ -268,12 +270,12 @@ public class TextField extends Control {
}
public void enable() {
// field.setFocus(true);
field.setFocused(true);
enabled = true;
}
public void disable() {
// field.setFocus(false);
field.setFocused(false);
enabled = false;
}
@ -294,7 +296,7 @@ public class TextField extends Control {
}
public void setFocused(boolean val) {
// field.setFocus(val);
field.setFocused(val);
}
public boolean hasFocus() {
@ -302,7 +304,7 @@ public class TextField extends Control {
}
public void focus() {
// field.setFocus(true);
field.setFocused(true);
}
public void setTextColor(int color) {
@ -339,8 +341,10 @@ public class TextField extends Control {
@Override
public void load(JsonOWrapper json) {
super.load(json);
// field.x = json.getInt("x", 0) + 1;
// field.y = json.getInt("y", 0) + 1;
field.setPosition(
json.getInt("x", 0) + 1,
json.getInt("y", 0) + 1
);
field.setWidth(json.getInt("width", 200) - 2);
field.setHeight(json.getInt("height", 22) - 2);
field.setValue(tr(json.getString("text", "")));

View File

@ -45,7 +45,7 @@ public class UpgradeGroup extends BasicControl {
@Override
public void postDraw(GuiGraphics poseStack, int mouseX, int mouseY, float ptt) {
if(overStack != null)
parent.drawItemStackTooltip(poseStack.pose(), overStack, mouseX, mouseY);
parent.drawItemStackTooltip(poseStack, overStack, mouseX, mouseY);
}
@Override

View File

@ -317,7 +317,7 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
code = ((Double) oCode).intValue();
}
data.add(new TypeData(dataAction, code, 0));
data.add(new TypeData(dataAction, code, 0, 0));
}
return realType(WebDisplays.GSON.toJson(data));

View File

@ -556,20 +556,23 @@ public class TileEntityScreen extends BlockEntity {
return;
}
if (scr.browser != null) {
if (scr.browser instanceof MCEFBrowser mcefBrowser) {
if (event == ClickControl.ControlType.CLICK) {
mcefBrowser.sendMouseMove(vec.x, vec.y); //Move to target
mcefBrowser.sendMousePress(vec.x, vec.y, button); //Press
mcefBrowser.sendMouseRelease(vec.x, vec.y, button); //Release
} else if (event == ClickControl.ControlType.DOWN) {
mcefBrowser.sendMouseMove(vec.x, vec.y); //Move to target
mcefBrowser.sendMousePress(vec.x, vec.y, button); //Press
} else if (event == ClickControl.ControlType.MOVE)
mcefBrowser.sendMouseMove(vec.x, vec.y); //Move
else if (event == ClickControl.ControlType.UP)
mcefBrowser.sendMouseRelease(scr.lastMousePos.x, scr.lastMousePos.y, button); //Release
}
if (scr.browser instanceof MCEFBrowser mcefBrowser) {
if (button == 1) button = 0;
else if (button == 0) button = 1;
if (event == ClickControl.ControlType.CLICK) {
mcefBrowser.sendMouseMove(vec.x, vec.y); //Move to target
mcefBrowser.sendMousePress(vec.x, vec.y, button); //Press
mcefBrowser.sendMouseRelease(vec.x, vec.y, button); //Release
} else if (event == ClickControl.ControlType.DOWN) {
mcefBrowser.sendMouseMove(vec.x, vec.y); //Move to target
mcefBrowser.sendMousePress(vec.x, vec.y, button); //Press
} else if (event == ClickControl.ControlType.MOVE)
mcefBrowser.sendMouseMove(vec.x, vec.y); //Move
else if (event == ClickControl.ControlType.UP)
mcefBrowser.sendMouseRelease(scr.lastMousePos.x, scr.lastMousePos.y, button); //Release
mcefBrowser.setFocus(true);
if (vec != null) {
scr.lastMousePos.x = vec.x;
@ -889,18 +892,19 @@ public class TileEntityScreen extends BlockEntity {
if (ev.getKeyCode() == 257) {
ev = new TypeData(
ev.getAction(),
10, ev.getModifier()
10, ev.getModifier(),
ev.getScanCode()
);
}
switch (ev.getAction()) {
case PRESS -> {
mcefBrowser.sendKeyPress(ev.getKeyCode(), (char) ev.getKeyCode(), ev.getModifier());
mcefBrowser.sendKeyPress(ev.getKeyCode(), ev.getScanCode(), ev.getModifier());
if (ev.getKeyCode() == 10)
mcefBrowser.sendKeyTyped('\r', ev.getModifier());
}
case RELEASE ->
mcefBrowser.sendKeyRelease(ev.getKeyCode(), (char) ev.getKeyCode(), ev.getModifier());
mcefBrowser.sendKeyRelease(ev.getKeyCode(), ev.getScanCode(), ev.getModifier());
case TYPE -> mcefBrowser.sendKeyTyped((char) ev.getKeyCode(), ev.getModifier()); // TODO: check
default -> throw new RuntimeException("Invalid type action '" + ev.getAction() + '\'');

View File

@ -24,17 +24,20 @@ public class TypeData {
private final Action a;
private final int k;
private final int m;
private final int s;
public TypeData() {
a = Action.INVALID;
k = 0;
m = 0;
s = 0;
}
public TypeData(Action action, int code, int modifier) {
public TypeData(Action action, int code, int modifier, int scan) {
a = action;
k = code;
m = modifier;
s = scan;
}
public Action getAction() {
@ -48,4 +51,8 @@ public class TypeData {
public int getModifier() {
return m;
}
public int getScanCode() {
return s;
}
}