Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'vivecraft/Multiloader-1.20' into Multil…
Browse files Browse the repository at this point in the history
…oader-1.20-No-PBuffers

# Conflicts:
#	common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java
  • Loading branch information
thejudge156 committed Nov 5, 2023
2 parents 2499518 + 52eb124 commit 2e69009
Show file tree
Hide file tree
Showing 42 changed files with 950 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ public boolean isSafeBinding(KeyMapping kb) {
}

public boolean isModBinding(KeyMapping kb) {
return !this.vanillaBindingSet.contains(kb);
return !this.vanillaBindingSet.contains(kb) && kb != mc.options.keyUse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.jetbrains.annotations.NotNull;
import org.vivecraft.client.gui.widgets.TextScrollWidget;


public class ErrorScreen extends Screen {

private final Screen lastScreen;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.vivecraft.client.gui.settings;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.screens.Screen;
import org.vivecraft.client.gui.framework.GuiVROption;
import org.vivecraft.client.gui.framework.GuiVROptionsBase;
import org.vivecraft.client.gui.framework.VROptionEntry;
import org.vivecraft.client_vr.VRState;
import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler;
import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler;
import org.vivecraft.client_vr.settings.VRSettings;

public class GuiHUDSettings extends GuiVROptionsBase {
Expand All @@ -20,20 +21,20 @@ public class GuiHUDSettings extends GuiVROptionsBase {
new VROptionEntry(VRSettings.VrOptions.HUD_OPACITY),
new VROptionEntry(VRSettings.VrOptions.RENDER_MENU_BACKGROUND),
new VROptionEntry(VRSettings.VrOptions.TOUCH_HOTBAR),
new VROptionEntry(VRSettings.VrOptions.AUTO_OPEN_KEYBOARD),
new VROptionEntry(VRSettings.VrOptions.MENU_ALWAYS_FOLLOW_FACE),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD, (button, mousePos) -> {
KeyboardHandler.setOverlayShowing(false);
return false;
}),
new VROptionEntry(VRSettings.VrOptions.GUI_APPEAR_OVER_BLOCK),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD_SCALE),
new VROptionEntry(VRSettings.VrOptions.DOUBLE_GUI_RESOLUTION),
new VROptionEntry(VRSettings.VrOptions.GUI_SCALE),
new VROptionEntry(VRSettings.VrOptions.HUD_MAX_GUI_SCALE),
new VROptionEntry(VRSettings.VrOptions.SHADER_GUI_RENDER),
new VROptionEntry("vivecraft.options.screen.keyboard.button", (button, mousePos) -> {
Minecraft.getInstance().setScreen(new GuiKeyboardSettings(this));
return true;
}),
new VROptionEntry("vivecraft.options.screen.menuworld.button", (button, mousePos) -> {
Minecraft.getInstance().setScreen(new GuiMenuWorldSettings(this));
return true;
}),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD_THEME),
new VROptionEntry(VRSettings.VrOptions.SHADER_GUI_RENDER)
};

public GuiHUDSettings(Screen guiScreen) {
Expand All @@ -53,12 +54,15 @@ protected void loadDefaults() {

protected void actionPerformed(AbstractWidget widget) {
if (widget instanceof GuiVROption button) {
if (button.getId() == VRSettings.VrOptions.PHYSICAL_KEYBOARD_THEME.ordinal()) {
KeyboardHandler.physicalKeyboard.init();
}
if (button.getId() == VRSettings.VrOptions.MENU_ALWAYS_FOLLOW_FACE.ordinal()) {
GuiHandler.onScreenChanged(Minecraft.getInstance().screen, Minecraft.getInstance().screen, false);
}
if ((button.getId() == VRSettings.VrOptions.DOUBLE_GUI_RESOLUTION.ordinal()
|| button.getId() == VRSettings.VrOptions.GUI_SCALE.ordinal())
&& VRState.vrEnabled) {
this.dataholder.vrRenderer.resizeFrameBuffers("GUI Setting Changed");
this.reinit = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.vivecraft.client.gui.settings;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.screens.Screen;
import org.vivecraft.client.gui.framework.GuiVROption;
import org.vivecraft.client.gui.framework.GuiVROptionsBase;
import org.vivecraft.client.gui.framework.VROptionEntry;
import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler;
import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler;
import org.vivecraft.client_vr.settings.VRSettings;

public class GuiKeyboardSettings extends GuiVROptionsBase {
private final VROptionEntry[] keyboardOptions = new VROptionEntry[]{
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD, (button, mousePos) -> {
KeyboardHandler.setOverlayShowing(false);
return false;
}),
new VROptionEntry(VRSettings.VrOptions.AUTO_OPEN_KEYBOARD),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD_SCALE),
new VROptionEntry(VRSettings.VrOptions.KEYBOARD_PRESS_BINDS),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD_THEME)
};

public GuiKeyboardSettings(Screen guiScreen) {
super(guiScreen);
}

public void init() {
this.vrTitle = "vivecraft.options.screen.keyboard";
super.init(this.keyboardOptions, true);
super.addDefaultButtons();
}

protected void loadDefaults() {
super.loadDefaults();
}

protected void actionPerformed(AbstractWidget widget) {
if (widget instanceof GuiVROption button) {
if (button.getId() == VRSettings.VrOptions.PHYSICAL_KEYBOARD_THEME.ordinal()) {
KeyboardHandler.physicalKeyboard.init();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.ComponentRenderUtils;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.Style;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Mth;
import org.lwjgl.glfw.GLFW;

import java.util.List;
Expand All @@ -23,35 +25,35 @@ public class TextScrollWidget extends AbstractWidget {

private final int scrollBarWidth = 5;
private final int padding = 5;
private final List<FormattedText> formattedText;
private final List<FormattedCharSequence> formattedChars;

public TextScrollWidget(int x, int y, int width, int height, String text) {
super(x, y, width, height, Component.literal(""));

formattedText = Minecraft.getInstance().font.getSplitter().splitLines(text, width - scrollBarWidth * 2, Style.EMPTY);
formattedChars = ComponentRenderUtils.wrapComponents(Component.literal(text), width - scrollBarWidth * 2, Minecraft.getInstance().font);

initScroll();
}

public TextScrollWidget(int x, int y, int width, int height, Component text) {
super(x, y, width, height, Component.literal(""));

formattedText = Minecraft.getInstance().font.getSplitter().splitLines(text, width - scrollBarWidth * 2, Style.EMPTY);
formattedChars = ComponentRenderUtils.wrapComponents(text, width - scrollBarWidth * 2, Minecraft.getInstance().font);
initScroll();
}

private void initScroll() {

maxLines = (height - 2 - padding + 3) / 12;
currentLine = 0;
scrollSteps = formattedText.size() - maxLines;
scrollSteps = formattedChars.size() - maxLines;
scrollSteps = Math.max(scrollSteps, 0);
scrollBarSize = scrollSteps == 0 ? height - 2 : (int) (Math.max(formattedText.size(), maxLines) / (float) (scrollSteps) * 12);
scrollBarSize = scrollSteps == 0 ? height - 2 : (int) (Math.max(formattedChars.size(), maxLines) / (float) (scrollSteps) * 12);
scrollBarOffset = height - scrollBarSize - 2;
}

@Override
public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
public void renderWidget(GuiGraphics guiGraphics, int x, int y, float f) {
// draw box outline
guiGraphics.fill(
getX(),
Expand All @@ -68,8 +70,8 @@ public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
-16777216);

// draw text
for (int line = 0; line + currentLine < formattedText.size() && line < maxLines; line++) {
guiGraphics.drawString(Minecraft.getInstance().font, formattedText.get(line + currentLine).getString(), getX() + padding, getY() + padding + line * 12, 16777215);
for (int line = 0; line + currentLine < formattedChars.size() && line < maxLines; line++) {
guiGraphics.drawString(Minecraft.getInstance().font, formattedChars.get(line + currentLine), getX() + padding, getY() + padding + line * 12, 16777215);
}

float scrollbarStart = scrollSteps == 0 ? 0 : currentLine / (float) scrollSteps * scrollBarOffset;
Expand All @@ -91,6 +93,8 @@ public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
getX() + width - (isFocused() || isHovered ? 2 : 1),
(int) (getY() + (isFocused() || isHovered ? 0 : 1) + scrollbarStart + scrollBarSize),
-6250336);

renderMouseover(guiGraphics, x, y);
}

@Override
Expand All @@ -102,10 +106,15 @@ protected void updateWidgetNarration(NarrationElementOutput narrationElementOutp
public void onClick(double x, double y) {
if (x >= getX() + width - scrollBarWidth && x <= getX() + width && y >= getY() && y <= getY() + height) {
scrollDragActive = true;
if (maxLines < formattedText.size()) {
if (maxLines < formattedChars.size()) {
// update scroll position
setCurrentLineFromYPos(y);
}
} else if (this.clicked(x, y)) {
Style style = getMouseoverStyle(x, y);
if (style != null && style.getClickEvent() != null) {
Minecraft.getInstance().screen.handleComponentClicked(style);
}
}
}

Expand Down Expand Up @@ -154,4 +163,28 @@ public boolean keyPressed(int key, int scancode, int mods) {
}
return super.keyPressed(key, scancode, mods);
}

public Style getMouseoverStyle(double x, double y) {
int lineIndex = this.getLineIndex(x, y);
if (lineIndex >= 0 && lineIndex < this.formattedChars.size()) {
FormattedCharSequence line = this.formattedChars.get(lineIndex);
return Minecraft.getInstance().font.getSplitter().componentStyleAtWidth(line, Mth.floor(x - this.getX()));
}
return null;
}

private int getLineIndex(double x, double y) {
if (!this.clicked(x, y)) {
return -1;
} else {
return (int) ((y - this.getY() - padding * 0.5) / 12.0);
}
}

public void renderMouseover(GuiGraphics guiGraphics, int x, int y) {
Style style = this.getMouseoverStyle(x, y);
if (style != null && style.getHoverEvent() != null) {
guiGraphics.renderComponentHoverEffect(Minecraft.getInstance().font, style, x, y);
}
}
}
4 changes: 2 additions & 2 deletions common/src/main/java/org/vivecraft/client_vr/VRState.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void initializeVR() {
dh.vr = new NullVR(Minecraft.getInstance(), dh);
}
if (!dh.vr.init()) {
throw new RenderConfigException("VR init Error", Component.translatable("vivecraft.messages.rendersetupfailed", dh.vr.initStatus + "\nVR provider: " + dh.vr.getName()));
throw new RenderConfigException("VR init Error", Component.translatable("vivecraft.messages.rendersetupfailed", dh.vr.initStatus, dh.vr.getName()));
}

dh.vrRenderer = dh.vr.createVRRenderer();
Expand All @@ -45,7 +45,7 @@ public static void initializeVR() {
dh.vrRenderer.setupRenderConfiguration();
RenderPassManager.setVanillaRenderPass();
} catch (RenderConfigException renderConfigException) {
throw new RenderConfigException("VR Render Error", Component.translatable("vivecraft.messages.rendersetupfailed", renderConfigException.error.getString() + "\nVR provider: " + dh.vr.getName()));
throw new RenderConfigException("VR Render Error", Component.translatable("vivecraft.messages.rendersetupfailed", renderConfigException.error, dh.vr.getName()));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.vivecraft.client_vr.extensions;

public interface WindowExtension {
int vivecraft$getActualScreenHeight();

int vivecraft$getActualScreenWidth();
}
Loading

0 comments on commit 2e69009

Please sign in to comment.