Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface VRKeyboardAccessor {
*
* @param attachTo the screen that has to be attached to keyboard
*/
void showKeyboard(@NotNull Screen attachTo);
void showKeyboard(@Nullable Screen attachTo);

/**
* The screen, keyboard is attached to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Vector3f;

import java.util.Collection;

Expand Down Expand Up @@ -79,6 +81,7 @@ default boolean isInViewDistance(){
*/
boolean isVisible();


/**
* If this overlay is custom,
* i.e. created from template
Expand All @@ -99,6 +102,18 @@ default boolean isBuiltIn(){
return asTemplate() == null;
}

/**
* Get this overlay as template
*
* @return overlay template or null if not an instance of {@link VROverlayTemplate}
*/
default @Nullable VROverlayTemplate asTemplate(){
if(this instanceof VROverlayTemplate overlayTemplate){
return overlayTemplate;
}else{
return null;
}
}

/**
* Get overlay name
Expand Down Expand Up @@ -129,6 +144,11 @@ default Component getDescription(){
}



//---------------------------
//--------- OPTIONS ---------
//---------------------------

/**
* Get collection of overlay options
*
Expand Down Expand Up @@ -217,6 +237,9 @@ default void reloadOption(@NotNull String id){



//---------------------------------------------
//--------- FORCED ANCHOR && DRAGGING ---------
//---------------------------------------------

/**
* Get the forced anchor
Expand All @@ -242,19 +265,61 @@ default void reloadOption(@NotNull String id){


/**
* Get this overlay as template
* Start dragging this overlay with the currently active cursor hand
*/
void startDragging();

/**
* Stop dragging and persist the pose back into pose options when available
*/
void stopDragging();

/**
* If overlay is being dragged rightt now
*
* @return overlay template or null if not an instance of {@link VROverlayTemplate}
* @return true/false
*/
default @Nullable VROverlayTemplate asTemplate(){
if(this instanceof VROverlayTemplate overlayTemplate){
return overlayTemplate;
}else{
return null;
default boolean isBeingDragged() {
return false;
}

/**
* If specified raw cursor position is over the drag handle
*
* @param rawX raw cursor x
* @param rawY raw cursor y
* @return true/false
*/
default boolean isCursorOnDragHandle(float rawX, float rawY) {
if (!supportsDragging()) {
return false;
}
int edgeX = getCursorBoundsX();
int edgeY = getCursorBoundsY();
int edgeWidth = getCursorBoundsWidth();
int edgeHeight = getCursorBoundsHeight();
int width = getWidth();
int height = getHeight();
//If cursorBounds are set
if (width > 0 && height > 0
&& edgeX >= 0 && edgeY >= 0
&& edgeWidth >= 0 && edgeHeight >= 0) {
float rawLeft = (float) edgeX / width;
float rawRight = (float) (edgeX + edgeWidth) / width;
float rawTop = (float) (edgeY + edgeHeight) / height;
float rawBottom = rawTop + 0.15f;
return rawX >= rawLeft && rawX <= rawRight
&& rawY > rawTop && rawY <= rawBottom;
}
return rawX >= 0f && rawX <= 1f
&& rawY > 1.0f && rawY <= 1.15f;
}


//--------------------------------------
//--------- SUPPORTED FEATURES ---------
//--------------------------------------

/**
* If supports update of visibility each render call, instead of tick()
* @return true/false
Expand Down Expand Up @@ -316,7 +381,19 @@ default boolean supportsTwoCursors(){
return false;
}

/**
* If overlay can be dragged and repositioned by the player
*
* @return true/false
*/
default boolean supportsDragging() {
return false;
}


//----------------------------------------
//--------- CURSOR && RESOLUTION ---------
//----------------------------------------

/**
* Get Data for active cursor
Expand Down Expand Up @@ -472,6 +549,10 @@ default boolean isWithinCursorBounds(float rawX, float rawY) {
}


//----------------------------
//--------- MC STUFF ---------
//----------------------------

/**
* Get active cursor position X
*
Expand Down Expand Up @@ -635,6 +716,10 @@ boolean mouseDragged(double mouseX, double mouseY,
boolean charTyped(char chr, int modifiers);


//-------------------------
//--------- EXTRA ---------
//-------------------------

/**
* Override of {@link PrioritySupporter#compareTo(PrioritySupporter)}
* to sort components in reverse priority order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
import me.phoenixra.atumconfig.api.config.ConfigFile;
import org.vmstudio.visor.api.VisorAPI;
import org.vmstudio.visor.api.client.gui.overlays.*;
import org.vmstudio.visor.api.client.gui.overlays.options.types.OverlayOptionsPose;
import org.vmstudio.visor.api.client.player.pose.PlayerPoseType;
import org.vmstudio.visor.api.client.player.pose.PoseAnchor;
import org.vmstudio.visor.api.client.gui.overlays.options.OverlayOptionGroup;
import org.vmstudio.visor.api.client.player.pose.VRPlayerPoseClient;
import org.vmstudio.visor.api.common.HandType;
import org.vmstudio.visor.api.common.VRException;
import org.vmstudio.visor.api.common.addon.component.ComponentPriority;
import org.vmstudio.visor.api.common.addon.VisorAddon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.vmstudio.visor.api.common.player.VRPose;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -66,6 +74,10 @@ public abstract class VROverlayFrameBuffer implements VROverlay {
@Getter
private boolean visible = false;

private boolean beingDragged = false;
private Vector3f dragPositionOffset = new Vector3f(0, 0, -0.3f);
private Matrix4f dragRotationMatrix = new Matrix4f();


public VROverlayFrameBuffer(@NotNull VisorAddon owner,
@NotNull String id){
Expand Down Expand Up @@ -127,9 +139,10 @@ protected void onRender(float partialTicks) {}

protected abstract void onUpdatePose(float partialTicks);


protected abstract boolean updateVisibility();

protected void onStoppedDragging() {};

protected void onEnable() {}

protected void onDisable() {}
Expand Down Expand Up @@ -174,15 +187,7 @@ public void render(float partialTick){
@Override
public final void updatePose(float partialTicks) {
if(forcedAnchor != null) {
VROverlayHelper.applyPose(
this,
forcedAnchor,
forcedAnchor,
getPose().getScale(),
false,
new Vector3f(0,0,-0.3f),
new Vector3f(0,0,0)
);
applyForcedPose();
return;
}
onUpdatePose(partialTicks);
Expand All @@ -203,11 +208,96 @@ public void setEnabled(boolean flag) {
}
}


@Override
public void startDragging() {
var vrClient = VisorAPI.client();

HandType cursorHand = vrClient.getGuiManager().getCursorHandler().getCursorHand();
PoseAnchor dragAnchor = cursorHand == HandType.MAIN
? PoseAnchor.MAIN_HAND
: PoseAnchor.OFFHAND;
VRPlayerPoseClient renderPose = vrClient.getVRLocalPlayer().getPoseData(PlayerPoseType.RENDER);
VRPose anchorPose = dragAnchor.getSupplier().apply(renderPose);

Vector3f dragPositionOffset = anchorPose.reverseCustomVector(
getPose().getPosition().sub(anchorPose.getPosition(), new Vector3f())
).div(renderPose.getWorldScale());
Matrix4f dragRotation = anchorPose.getRotation()
.invert(new Matrix4f())
.mul(getPose().getRotation(), new Matrix4f());

this.dragPositionOffset.set(dragPositionOffset);
this.dragRotationMatrix.set(dragRotation);
this.beingDragged = true;
setForcedAnchor(dragAnchor);
}

@Override
public void stopDragging() {
setForcedAnchor(null);
this.beingDragged = false;

OverlayOptionsPose poseOptions = getOption(OverlayOptionsPose.ID, OverlayOptionsPose.class);
if (poseOptions != null) {
VRPlayerPoseClient renderPose = VisorAPI.client().getVRLocalPlayer().getPoseData(PlayerPoseType.RENDER);

PoseAnchor posAnchor = poseOptions.getPositionAnchor();
VRPose posAnchorPose = posAnchor.getSupplier().apply(renderPose);
Vector3f offsetPos = posAnchorPose.reverseCustomVector(
getPose().getPosition().sub(posAnchorPose.getPosition(), new Vector3f())
).div(renderPose.getWorldScale());

poseOptions.setPositionOffset(offsetPos);

if (!poseOptions.isAimedRotation()) {
PoseAnchor rotAnchor = poseOptions.getRotationAnchor();
VRPose rotAnchorPose = rotAnchor.getSupplier().apply(renderPose);
Vector3f rotOffset = rotAnchor.reverseAnchoredRotation(
rotAnchorPose.getRotation(), getPose().getRotation()
);
poseOptions.setRotationOffset(rotOffset);
}

poseOptions.save();
}

onStoppedDragging();
}

protected void applyForcedPose() {
if (forcedAnchor == null) {
return;
}

VRPlayerPoseClient renderPose = VisorAPI.client().getVRLocalPlayer().getPoseData(PlayerPoseType.RENDER);
VRPose anchorPose = forcedAnchor.getSupplier().apply(renderPose);

Vector3f positionOffset = new Vector3f(dragPositionOffset)
.mul(renderPose.getWorldScale());
Vector3f newPosition = anchorPose.getCustomVector(positionOffset)
.add(anchorPose.getPosition());
Matrix4f newRotation = new Matrix4f(anchorPose.getRotation())
.mul(dragRotationMatrix, new Matrix4f());

getPose().update(
newPosition,
newRotation,
getPose().getScale()
);
}

@Override
public @Nullable OverlayOptionGroup<?> getOption(@NotNull String id) {
return optionsMap.get(id);
}

@Override
public boolean isBeingDragged() {
return beingDragged;
}


@Override
public boolean supportsCursor() {
return false;
Expand Down
Loading