mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:17:14 +02:00
Enable/disable grouping buttons depending on current group selection
This commit is contained in:
parent
c4eac1660c
commit
1b866fdf9e
3 changed files with 80 additions and 16 deletions
|
@ -16,7 +16,8 @@ Groups = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var groupRootEntityIDs = [],
|
var groupRootEntityIDs = [],
|
||||||
groupSelectionDetails = [];
|
groupSelectionDetails = [],
|
||||||
|
numberOfEntitiesSelected = 0;
|
||||||
|
|
||||||
if (!this instanceof Groups) {
|
if (!this instanceof Groups) {
|
||||||
return new Groups();
|
return new Groups();
|
||||||
|
@ -25,11 +26,13 @@ Groups = function () {
|
||||||
function add(selection) {
|
function add(selection) {
|
||||||
groupRootEntityIDs.push(selection[0].id);
|
groupRootEntityIDs.push(selection[0].id);
|
||||||
groupSelectionDetails.push(Object.clone(selection));
|
groupSelectionDetails.push(Object.clone(selection));
|
||||||
|
numberOfEntitiesSelected += selection.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(selection) {
|
function remove(selection) {
|
||||||
var index = groupRootEntityIDs.indexOf(selection[0].id);
|
var index = groupRootEntityIDs.indexOf(selection[0].id);
|
||||||
|
|
||||||
|
numberOfEntitiesSelected -= groupSelectionDetails[index].length;
|
||||||
groupRootEntityIDs.splice(index, 1);
|
groupRootEntityIDs.splice(index, 1);
|
||||||
groupSelectionDetails.splice(index, 1);
|
groupSelectionDetails.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
@ -68,10 +71,14 @@ Groups = function () {
|
||||||
return groupRootEntityIDs.indexOf(rootEntityID) !== -1;
|
return groupRootEntityIDs.indexOf(rootEntityID) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function count() {
|
function groupsCount() {
|
||||||
return groupSelectionDetails.length;
|
return groupSelectionDetails.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function entitiesCount() {
|
||||||
|
return numberOfEntitiesSelected;
|
||||||
|
}
|
||||||
|
|
||||||
function group() {
|
function group() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -93,7 +100,8 @@ Groups = function () {
|
||||||
toggle: toggle,
|
toggle: toggle,
|
||||||
selection: selection,
|
selection: selection,
|
||||||
includes: includes,
|
includes: includes,
|
||||||
count: count,
|
groupsCount: groupsCount,
|
||||||
|
entitiesCount: entitiesCount,
|
||||||
group: group,
|
group: group,
|
||||||
ungroup: ungroup,
|
ungroup: ungroup,
|
||||||
clear: clear,
|
clear: clear,
|
||||||
|
|
|
@ -24,7 +24,7 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
menuCallbacks = [],
|
menuCallbacks = [],
|
||||||
optionsOverlays = [],
|
optionsOverlays = [],
|
||||||
optionsCallbacks = [],
|
optionsCallbacks = [],
|
||||||
optionsItems,
|
optionsEnabled = [],
|
||||||
highlightOverlay,
|
highlightOverlay,
|
||||||
|
|
||||||
LEFT_HAND = 0,
|
LEFT_HAND = 0,
|
||||||
|
@ -100,8 +100,9 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
properties: {
|
properties: {
|
||||||
dimensions: { x: 0.07, y: 0.03, z: 0.01 },
|
dimensions: { x: 0.07, y: 0.03, z: 0.01 },
|
||||||
localPosition: { x: 0, y: -0.025, z: -0.005 },
|
localPosition: { x: 0, y: -0.025, z: -0.005 },
|
||||||
color: { red: 64, green: 240, blue: 64 }
|
color: { red: 200, green: 200, blue: 200 }
|
||||||
},
|
},
|
||||||
|
enabledColor: { red: 64, green: 240, blue: 64 },
|
||||||
callback: "groupButton"
|
callback: "groupButton"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -110,13 +111,17 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
properties: {
|
properties: {
|
||||||
dimensions: { x: 0.07, y: 0.03, z: 0.01 },
|
dimensions: { x: 0.07, y: 0.03, z: 0.01 },
|
||||||
localPosition: { x: 0, y: 0.025, z: -0.005 },
|
localPosition: { x: 0, y: 0.025, z: -0.005 },
|
||||||
color: { red: 240, green: 64, blue: 64 }
|
color: { red: 200, green: 200, blue: 200 }
|
||||||
},
|
},
|
||||||
|
enabledColor: { red: 240, green: 64, blue: 64 },
|
||||||
callback: "ungroupButton"
|
callback: "ungroupButton"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
GROUP_BUTTON_INDEX = 1,
|
||||||
|
UNGROUP_BUTTON_INDEX = 2,
|
||||||
|
|
||||||
MENU_ITEMS = [
|
MENU_ITEMS = [
|
||||||
{
|
{
|
||||||
// Background element
|
// Background element
|
||||||
|
@ -174,8 +179,10 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
|
|
||||||
NONE = -1,
|
NONE = -1,
|
||||||
|
|
||||||
|
optionsItems,
|
||||||
intersectionOverlays,
|
intersectionOverlays,
|
||||||
intersectionCallbacks,
|
intersectionCallbacks,
|
||||||
|
intersectionCallbacksEnabled,
|
||||||
intersectionProperties,
|
intersectionProperties,
|
||||||
highlightedItem,
|
highlightedItem,
|
||||||
highlightedSource,
|
highlightedSource,
|
||||||
|
@ -183,6 +190,8 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
pressedItem,
|
pressedItem,
|
||||||
pressedSource,
|
pressedSource,
|
||||||
isButtonPressed,
|
isButtonPressed,
|
||||||
|
isGroupButtonEnabled,
|
||||||
|
isUngroupButtonEnabled,
|
||||||
|
|
||||||
isDisplaying = false,
|
isDisplaying = false,
|
||||||
|
|
||||||
|
@ -221,6 +230,8 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
Overlays.deleteOverlay(optionsOverlays[i]);
|
Overlays.deleteOverlay(optionsOverlays[i]);
|
||||||
optionsOverlays = [];
|
optionsOverlays = [];
|
||||||
optionsCallbacks = [];
|
optionsCallbacks = [];
|
||||||
|
optionsEnabled = [];
|
||||||
|
optionsItems = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open specified panel, if any.
|
// Open specified panel, if any.
|
||||||
|
@ -234,18 +245,27 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
optionsOverlays.push(Overlays.addOverlay(UI_ELEMENTS[optionsItems[i].type].overlay, properties));
|
optionsOverlays.push(Overlays.addOverlay(UI_ELEMENTS[optionsItems[i].type].overlay, properties));
|
||||||
parentID = optionsOverlays[0]; // Menu buttons parent to menu panel.
|
parentID = optionsOverlays[0]; // Menu buttons parent to menu panel.
|
||||||
optionsCallbacks.push(optionsItems[i].callback);
|
optionsCallbacks.push(optionsItems[i].callback);
|
||||||
|
optionsEnabled.push(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special handling for Group options.
|
||||||
|
if (toolOptions === "groupOptions") {
|
||||||
|
optionsEnabled[GROUP_BUTTON_INDEX] = false;
|
||||||
|
optionsEnabled[UNGROUP_BUTTON_INDEX] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearTool() {
|
function clearTool() {
|
||||||
openOptions();
|
openOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(intersectionOverlayID) {
|
function update(intersectionOverlayID, groupsCount, entitiesCount) {
|
||||||
var intersectedItem,
|
var intersectedItem,
|
||||||
parentProperties,
|
parentProperties,
|
||||||
BUTTON_PRESS_DELTA = 0.004;
|
BUTTON_PRESS_DELTA = 0.004,
|
||||||
|
enableGroupButton,
|
||||||
|
enableUngroupButton;
|
||||||
|
|
||||||
// Intersection details.
|
// Intersection details.
|
||||||
if (intersectionOverlayID) {
|
if (intersectionOverlayID) {
|
||||||
|
@ -253,12 +273,14 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
if (intersectedItem !== -1) {
|
if (intersectedItem !== -1) {
|
||||||
intersectionOverlays = menuOverlays;
|
intersectionOverlays = menuOverlays;
|
||||||
intersectionCallbacks = menuCallbacks;
|
intersectionCallbacks = menuCallbacks;
|
||||||
|
intersectionCallbacksEnabled = null;
|
||||||
intersectionProperties = MENU_ITEMS;
|
intersectionProperties = MENU_ITEMS;
|
||||||
} else {
|
} else {
|
||||||
intersectedItem = optionsOverlays.indexOf(intersectionOverlayID);
|
intersectedItem = optionsOverlays.indexOf(intersectionOverlayID);
|
||||||
if (intersectedItem !== -1) {
|
if (intersectedItem !== -1) {
|
||||||
intersectionOverlays = optionsOverlays;
|
intersectionOverlays = optionsOverlays;
|
||||||
intersectionCallbacks = optionsCallbacks;
|
intersectionCallbacks = optionsCallbacks;
|
||||||
|
intersectionCallbacksEnabled = optionsEnabled;
|
||||||
intersectionProperties = optionsItems;
|
intersectionProperties = optionsItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,7 +331,7 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
pressedItem = NONE;
|
pressedItem = NONE;
|
||||||
}
|
}
|
||||||
isButtonPressed = isHighlightingButton && controlHand.triggerClicked();
|
isButtonPressed = isHighlightingButton && controlHand.triggerClicked();
|
||||||
if (isButtonPressed) {
|
if (isButtonPressed && (intersectionCallbacksEnabled === null || intersectionCallbacksEnabled[intersectedItem])) {
|
||||||
// Press new button.
|
// Press new button.
|
||||||
Overlays.editOverlay(intersectionOverlays[intersectedItem], {
|
Overlays.editOverlay(intersectionOverlays[intersectedItem], {
|
||||||
localPosition: Vec3.sum(intersectionProperties[intersectedItem].properties.localPosition,
|
localPosition: Vec3.sum(intersectionProperties[intersectedItem].properties.localPosition,
|
||||||
|
@ -320,9 +342,34 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
|
|
||||||
// Button press actions.
|
// Button press actions.
|
||||||
if (intersectionOverlays === menuOverlays) {
|
if (intersectionOverlays === menuOverlays) {
|
||||||
openOptions(intersectionProperties[highlightedItem].toolOptions);
|
openOptions(intersectionProperties[intersectedItem].toolOptions);
|
||||||
}
|
}
|
||||||
commandCallback(intersectionCallbacks[highlightedItem]);
|
commandCallback(intersectionCallbacks[intersectedItem]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special handling for Group options.
|
||||||
|
if (optionsItems && optionsItems === OPTONS_PANELS.groupOptions) {
|
||||||
|
enableGroupButton = groupsCount > 1;
|
||||||
|
if (enableGroupButton !== isGroupButtonEnabled) {
|
||||||
|
isGroupButtonEnabled = enableGroupButton;
|
||||||
|
Overlays.editOverlay(optionsOverlays[GROUP_BUTTON_INDEX], {
|
||||||
|
color: isGroupButtonEnabled
|
||||||
|
? OPTONS_PANELS.groupOptions[GROUP_BUTTON_INDEX].enabledColor
|
||||||
|
: OPTONS_PANELS.groupOptions[GROUP_BUTTON_INDEX].properties.color
|
||||||
|
});
|
||||||
|
optionsEnabled[GROUP_BUTTON_INDEX] = enableGroupButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
enableUngroupButton = groupsCount === 1 && entitiesCount > 1;
|
||||||
|
if (enableUngroupButton !== isUngroupButtonEnabled) {
|
||||||
|
isUngroupButtonEnabled = enableUngroupButton;
|
||||||
|
Overlays.editOverlay(optionsOverlays[UNGROUP_BUTTON_INDEX], {
|
||||||
|
color: isUngroupButtonEnabled
|
||||||
|
? OPTONS_PANELS.groupOptions[UNGROUP_BUTTON_INDEX].enabledColor
|
||||||
|
: OPTONS_PANELS.groupOptions[UNGROUP_BUTTON_INDEX].properties.color
|
||||||
|
});
|
||||||
|
optionsEnabled[UNGROUP_BUTTON_INDEX] = enableUngroupButton;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -376,8 +423,10 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
highlightOverlay = Overlays.addOverlay("cube", properties);
|
highlightOverlay = Overlays.addOverlay("cube", properties);
|
||||||
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
|
optionsItems = null;
|
||||||
intersectionOverlays = null;
|
intersectionOverlays = null;
|
||||||
intersectionCallbacks = null;
|
intersectionCallbacks = null;
|
||||||
|
intersectionCallbacksEnabled = null;
|
||||||
intersectionProperties = null;
|
intersectionProperties = null;
|
||||||
highlightedItem = NONE;
|
highlightedItem = NONE;
|
||||||
highlightedSource = null;
|
highlightedSource = null;
|
||||||
|
@ -385,6 +434,8 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
pressedItem = NONE;
|
pressedItem = NONE;
|
||||||
pressedSource = null;
|
pressedSource = null;
|
||||||
isButtonPressed = false;
|
isButtonPressed = false;
|
||||||
|
isGroupButtonEnabled = false;
|
||||||
|
isUngroupButtonEnabled = false;
|
||||||
|
|
||||||
isDisplaying = true;
|
isDisplaying = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,7 @@
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
if (isDisplaying) {
|
if (isDisplaying) {
|
||||||
toolMenu.update(getIntersection().overlayID);
|
toolMenu.update(getIntersection().overlayID, grouping.groupsCount(), grouping.entitiesCount());
|
||||||
createPalette.update(getIntersection().overlayID);
|
createPalette.update(getIntersection().overlayID);
|
||||||
toolIcon.update();
|
toolIcon.update();
|
||||||
}
|
}
|
||||||
|
@ -1100,7 +1100,7 @@
|
||||||
|
|
||||||
function toggle(selection) {
|
function toggle(selection) {
|
||||||
groups.toggle(selection);
|
groups.toggle(selection);
|
||||||
if (groups.count() === 0) {
|
if (groups.groupsCount() === 0) {
|
||||||
hasHighlights = false;
|
hasHighlights = false;
|
||||||
highlights.clear();
|
highlights.clear();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1113,8 +1113,12 @@
|
||||||
return groups.includes(rootEntityID);
|
return groups.includes(rootEntityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function count() {
|
function groupsCount() {
|
||||||
return groups.count();
|
return groups.groupsCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
function entitiesCount() {
|
||||||
|
return groups.entitiesCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
function group() {
|
function group() {
|
||||||
|
@ -1171,7 +1175,8 @@
|
||||||
return {
|
return {
|
||||||
toggle: toggle,
|
toggle: toggle,
|
||||||
includes: includes,
|
includes: includes,
|
||||||
count: count,
|
groupsCount: groupsCount,
|
||||||
|
entitiesCount: entitiesCount,
|
||||||
group: group,
|
group: group,
|
||||||
ungroup: ungroup,
|
ungroup: ungroup,
|
||||||
update: update,
|
update: update,
|
||||||
|
|
Loading…
Reference in a new issue