Skip to content

Commit

Permalink
Improve menu interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jan 22, 2024
1 parent 8ac0b72 commit 8545126
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/bit-systems/link-hover-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Interacted,
LinkHoverMenuItem,
LinkInitializing,
ObjectMenuTransform
ObjectMenuTransform,
CursorRaycastable
} from "../bit-components";
import { findAncestorWithComponent, findChildWithComponent } from "../utils/bit-utils";
import { hubIdFromUrl } from "../utils/media-url-utils";
Expand All @@ -24,6 +25,12 @@ const hoveredLinksQuery = defineQuery([HoveredRemoteRight, Link, Not(LinkInitial
const hoveredMenuItemQuery = defineQuery([HoveredRemoteRight, LinkHoverMenuItem]);
const clickedMenuItemQuery = defineQuery([Interacted, LinkHoverMenuItem]);

function setCursorRaycastable(world: HubsWorld, menu: EntityID, enable: boolean) {
let change = enable ? addComponent : removeComponent;
change(world, CursorRaycastable, menu);
change(world, CursorRaycastable, LinkHoverMenu.linkButtonRef[menu]);
}

function updateLinkMenuTarget(world: HubsWorld, menu: EntityID, sceneIsFrozen: boolean) {
if (LinkHoverMenu.targetObjectRef[menu] && !entityExists(world, LinkHoverMenu.targetObjectRef[menu])) {
// Clear the invalid entity reference. (The link entity was removed).
Expand Down Expand Up @@ -145,6 +152,8 @@ function flushToObject3Ds(world: HubsWorld, menu: EntityID, frozen: boolean, for
} else {
buttonObj.visible = false;
}

setCursorRaycastable(world, menu, visible);
}

export function linkHoverMenuSystem(world: HubsWorld, sceneIsFrozen: boolean) {
Expand Down
12 changes: 11 additions & 1 deletion src/bit-systems/pdf-menu-system.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { addComponent, defineQuery, entityExists, hasComponent } from "bitecs";
import { addComponent, defineQuery, entityExists, hasComponent, removeComponent } from "bitecs";
import { Text } from "troika-three-text";
import type { HubsWorld } from "../app";
import {
CursorRaycastable,
Deleting,
EntityStateDirty,
HoveredRemoteRight,
Expand All @@ -17,6 +18,13 @@ import { takeOwnership } from "../utils/take-ownership";
import { PDFResourcesMap } from "./pdf-system";
import { ObjectMenuTransformFlags } from "../inflators/object-menu-transform";

function setCursorRaycastable(world: HubsWorld, menu: EntityID, enable: boolean) {
let change = enable ? addComponent : removeComponent;
change(world, CursorRaycastable, menu);
change(world, CursorRaycastable, PDFMenu.prevButtonRef[menu]);
change(world, CursorRaycastable, PDFMenu.nextButtonRef[menu]);
}

function clicked(world: HubsWorld, eid: EntityID) {
return hasComponent(world, Interacted, eid);
}
Expand Down Expand Up @@ -100,6 +108,8 @@ function flushToObject3Ds(world: HubsWorld, menu: EntityID, frozen: boolean) {
const numPages = PDFResourcesMap.get(target)!.pdf.numPages;
(world.eid2obj.get(PDFMenu.pageLabelRef[menu]) as Text).text = `${NetworkedPDF.pageNumber[target]} / ${numPages}`;
}

setCursorRaycastable(world, menu, visible);
}

const hoveredQuery = defineQuery([HoveredRemoteRight]);
Expand Down
2 changes: 2 additions & 0 deletions src/bit-systems/video-menu-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function setCursorRaycastable(world: HubsWorld, menu: number, enable: boolean) {
let change = enable ? addComponent : removeComponent;
change(world, CursorRaycastable, menu);
change(world, CursorRaycastable, VideoMenu.trackRef[menu]);
change(world, CursorRaycastable, VideoMenu.playIndicatorRef[menu]);
change(world, CursorRaycastable, VideoMenu.pauseIndicatorRef[menu]);
}

const intersectInThePlaneOf = (() => {
Expand Down

0 comments on commit 8545126

Please sign in to comment.