From e676348c4f4bff3ed348eb96a79435abb5f839a5 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 16 May 2018 10:40:28 -0700 Subject: [PATCH] fixing some menu reog bugs --- .../qml/hifi/dialogs/RunningScripts.qml | 4 +- .../qml/hifi/dialogs/TabletRunningScripts.qml | 4 +- interface/src/Menu.cpp | 66 ++--- interface/src/avatar/MyAvatar.cpp | 1 - interface/src/ui/PreferencesDialog.cpp | 11 +- ...oggleAdvancedMovementForHandControllers.js | 246 ++++++++++-------- 6 files changed, 160 insertions(+), 172 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/RunningScripts.qml b/interface/resources/qml/hifi/dialogs/RunningScripts.qml index 9e3ebcbab0..9a180a66f6 100644 --- a/interface/resources/qml/hifi/dialogs/RunningScripts.qml +++ b/interface/resources/qml/hifi/dialogs/RunningScripts.qml @@ -79,7 +79,7 @@ ScrollingWindow { interval: 1000 repeat: true running: false - onTriggered: developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus"); + onTriggered: developerMenuEnabled = MenuInterface.isOptionChecked("Developer Menu"); } Component { @@ -98,7 +98,7 @@ ScrollingWindow { Component.onCompleted: { isHMD = HMD.active; updateRunningScripts(); - developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus"); + developerMenuEnabled = MenuInterface.isOptionChecked("Developer Menu"); checkMenu.restart(); } diff --git a/interface/resources/qml/hifi/dialogs/TabletRunningScripts.qml b/interface/resources/qml/hifi/dialogs/TabletRunningScripts.qml index 83f91c78c5..018c8f5737 100644 --- a/interface/resources/qml/hifi/dialogs/TabletRunningScripts.qml +++ b/interface/resources/qml/hifi/dialogs/TabletRunningScripts.qml @@ -65,7 +65,7 @@ Rectangle { interval: 1000 repeat: true running: false - onTriggered: developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus"); + onTriggered: developerMenuEnabled = MenuInterface.isOptionChecked("Developer Menu"); } Component { @@ -84,7 +84,7 @@ Rectangle { Component.onCompleted: { isHMD = HMD.active; updateRunningScripts(); - developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus"); + developerMenuEnabled = MenuInterface.isOptionChecked("Developer Menu"); checkMenu.restart(); } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 5633089019..1cde12a13c 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -100,19 +100,19 @@ Menu::Menu() { addActionToQMenuAndActionHash(editMenu, redoAction); editMenu->addSeparator(); - + // Edit > Cut addActionToQMenuAndActionHash(editMenu, "Cut", Qt::CTRL | Qt::Key_X); - + // Edit > Copy addActionToQMenuAndActionHash(editMenu, "Copy", Qt::CTRL | Qt::Key_C); - + // Edit > Paste addActionToQMenuAndActionHash(editMenu, "Paste", Qt::CTRL | Qt::Key_V); - + // Edit > Delete addActionToQMenuAndActionHash(editMenu, "Delete", Qt::Key_Delete); - + editMenu->addSeparator(); // Edit > Running Scripts @@ -280,7 +280,7 @@ Menu::Menu() { }); // Settings > Notifications - MenuWrapper * notificationsMenu = settingsMenu->addMenu("Notifications"); //This was in notifications.js. The menu needs to be moved here. + MenuWrapper * notificationsMenu = settingsMenu->addMenu("Notifications"); //This was in notifications.js. The menu needs to be moved here. //TODO: Hookup notification actions below. // Settings > Notifications > Play Notification Sounds @@ -308,43 +308,9 @@ Menu::Menu() { settings->setValue(MenuOption::NotificationSoundsTablet, action->isChecked()); }); - //Further sound notificaions disabled until new notification system will be implemented - /* - // Settings > Notifications > Level of Detail - action = addCheckableActionToQMenuAndActionHash(notificationsMenu, "Level of Detail", 0, - settings->getValue("play_notification_sounds_type_1").toBool()); - connect(action, &QAction::triggered, [action, settings] { - settings->setValue("play_notification_sounds_type_1", action->isChecked()); - }); - // Settings > Notifications > Connection - action = addCheckableActionToQMenuAndActionHash(notificationsMenu, "Connection", 0, - settings->getValue("play_notification_sounds_type_2").toBool()); - connect(action, &QAction::triggered, [action, settings] { - settings->setValue("play_notification_sounds_type_2", action->isChecked()); - }); - // Settings > Notifications > Connection Refused - action = addCheckableActionToQMenuAndActionHash(notificationsMenu, "Connection Refused", 0, - settings->getValue("play_notification_sounds_type_3").toBool()); - connect(action, &QAction::triggered, [action, settings] { - settings->setValue("play_notification_sounds_type_3", action->isChecked()); - }); - // Settings > Notifications > Edit Error - action = addCheckableActionToQMenuAndActionHash(notificationsMenu, "Edit Error", 0, - settings->getValue("play_notification_sounds_type_4").toBool()); - connect(action, &QAction::triggered, [action, settings] { - settings->setValue("play_notification_sounds_type_4", action->isChecked()); - }); - // Settings > Notifications > Wallet - addActionToQMenuAndActionHash(notificationsMenu, "Wallet"); - action = addCheckableActionToQMenuAndActionHash(notificationsMenu, "Wallet", 0, - settings->getValue("play_notification_sounds_type_6").toBool()); - connect(action, &QAction::triggered, [action, settings] { - settings->setValue("play_notification_sounds_type_6", action->isChecked()); - }); -*/ // Settings > Developer Menu addCheckableActionToQMenuAndActionHash(settingsMenu, "Developer Menu", 0, false, this, SLOT(toggleDeveloperMenus())); - + // Settings > Ask to Reset Settings addCheckableActionToQMenuAndActionHash(settingsMenu, MenuOption::AskToResetSettings, 0, false); @@ -375,7 +341,7 @@ Menu::Menu() { if (mainViewShadowTaskConfig) { if (action->isChecked()) { mainViewShadowTaskConfig->setPreset("Enabled"); - } else { + } else { mainViewShadowTaskConfig->setPreset("None"); } } @@ -844,7 +810,7 @@ Menu::Menu() { // Help/Application menu ---------------------------------- MenuWrapper * helpMenu = addMenu("Help"); - + // Help > About High Fidelity action = addActionToQMenuAndActionHash(helpMenu, "About High Fidelity"); connect(action, &QAction::triggered, [] { @@ -852,35 +818,35 @@ Menu::Menu() { QString("hifi/dialogs/TabletAboutDialog.qml"), "AboutDialog"); }); helpMenu->addSeparator(); - + // Help > HiFi Docs action = addActionToQMenuAndActionHash(helpMenu, "Online Documentation"); connect(action, &QAction::triggered, qApp, [] { QDesktopServices::openUrl(QUrl("https://docs.highfidelity.com/")); }); - + // Help > HiFi Forum action = addActionToQMenuAndActionHash(helpMenu, "Online Forums"); connect(action, &QAction::triggered, qApp, [] { QDesktopServices::openUrl(QUrl("https://forums.highfidelity.com/")); }); - + // Help > Scripting Reference action = addActionToQMenuAndActionHash(helpMenu, "Online Script Reference"); connect(action, &QAction::triggered, qApp, [] { QDesktopServices::openUrl(QUrl("https://docs.highfidelity.com/api-reference")); }); - + addActionToQMenuAndActionHash(helpMenu, "Controls Reference", 0, qApp, SLOT(showHelp())); - + helpMenu->addSeparator(); - + // Help > Release Notes action = addActionToQMenuAndActionHash(helpMenu, "Release Notes"); connect(action, &QAction::triggered, qApp, [] { QDesktopServices::openUrl(QUrl("http://steamcommunity.com/games/390540/announcements/")); }); - + // Help > Report a Bug! action = addActionToQMenuAndActionHash(helpMenu, "Report a Bug!"); connect(action, &QAction::triggered, qApp, [] { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 046dbafcc3..5fb4e80b80 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2654,7 +2654,6 @@ void MyAvatar::updateMotionBehaviorFromMenu() { } else { _motionBehaviors &= ~AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED; } - setCollisionsEnabled(menu->isOptionChecked(MenuOption::EnableAvatarCollisions)); setProperty("lookAtSnappingEnabled", menu->isOptionChecked(MenuOption::EnableLookAtSnapping)); } diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 3e23e57bd0..3af5848d2a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -266,16 +266,7 @@ void setupPreferences() { static const QString movementsControlChannel = QStringLiteral("Hifi-Advanced-Movement-Disabler"); auto getter = [=]()->bool { return myAvatar->useAdvancedMovementControls(); }; - auto setter = [=](bool value) { - auto messagesClient = DependencyManager::get().data(); - myAvatar->setUseAdvancedMovementControls(value); - if (value) { - messagesClient->sendMessage(movementsControlChannel, QStringLiteral("enable_mappings"), true); - } else { - messagesClient->sendMessage(movementsControlChannel, QStringLiteral("disable_mappings"), true); - } - - }; + auto setter = [=](bool value) { myAvatar->setUseAdvancedMovementControls(value); }; preferences->addPreference(new CheckPreference(MOVEMENT, QStringLiteral("Advanced movement for hand controllers"), getter, setter)); diff --git a/scripts/system/controllers/toggleAdvancedMovementForHandControllers.js b/scripts/system/controllers/toggleAdvancedMovementForHandControllers.js index 40721e7f72..a1b96ac607 100644 --- a/scripts/system/controllers/toggleAdvancedMovementForHandControllers.js +++ b/scripts/system/controllers/toggleAdvancedMovementForHandControllers.js @@ -11,132 +11,164 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +/* jslint bitwise: true */ + +/* global Script, Quat, MyAvatar, HMD, Controller, Messages*/ + (function() { // BEGIN LOCAL_SCOPE -var mappingName, basicMapping, isChecked; + var TWO_SECONDS_INTERVAL = 2000; + var FLYING_MAPPING_NAME = 'Hifi-Flying-Dev-' + Math.random(); + var DRIVING_MAPPING_NAME = 'Hifi-Driving-Dev-' + Math.random(); -var TURN_RATE = 1000; -var isDisabled = false; -var previousSetting = MyAvatar.useAdvancedMovementControls; -if (previousSetting === false) { - previousSetting = false; - isChecked = false; -} + var flyingMapping = null; + var drivingMapping = null; -if (previousSetting === true) { - previousSetting = true; - isChecked = true; -} + var TURN_RATE = 1000; + var isDisabled = false; -function rotate180() { - var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.angleAxis(180, { - x: 0, - y: 1, - z: 0 - })) - MyAvatar.orientation = newOrientation -} + var previousFlyingState = MyAvatar.getFlyingEnabled(); + var previousDrivingState = MyAvatar.useAdvancedMovementControls; -var inFlipTurn = false; + function rotate180() { + var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.angleAxis(180, { + x: 0, + y: 1, + z: 0 + })); + MyAvatar.orientation = newOrientation; + } -function registerBasicMapping() { - mappingName = 'Hifi-AdvancedMovement-Dev-' + Math.random(); - basicMapping = Controller.newMapping(mappingName); - basicMapping.from(Controller.Standard.LY).to(function(value) { - if (isDisabled) { - return; - } - var stick = Controller.getValue(Controller.Standard.LS); - if (value === 1 && Controller.Hardware.OculusTouch !== undefined) { - rotate180(); - } else if (Controller.Hardware.Vive !== undefined) { - if (value > 0.75 && inFlipTurn === false) { - inFlipTurn = true; + var inFlipTurn = false; + + function registerBasicMapping() { + + drivingMapping = Controller.newMapping(DRIVING_MAPPING_NAME); + drivingMapping.from(Controller.Standard.LY).to(function(value) { + if (isDisabled) { + return; + } + + if (value === 1 && Controller.Hardware.OculusTouch !== undefined) { rotate180(); - Script.setTimeout(function() { - inFlipTurn = false; - }, TURN_RATE) + } else if (Controller.Hardware.Vive !== undefined) { + if (value > 0.75 && inFlipTurn === false) { + inFlipTurn = true; + rotate180(); + Script.setTimeout(function() { + inFlipTurn = false; + }, TURN_RATE); + } + } + return; + }); + + flyingMapping = Controller.newMapping(FLYING_MAPPING_NAME); + flyingMapping.from(Controller.Standard.RY).to(function(value) { + if (isDisabled) { + return; + } + + if (value === 1 && Controller.Hardware.OculusTouch !== undefined) { + rotate180(); + } else if (Controller.Hardware.Vive !== undefined) { + if (value > 0.75 && inFlipTurn === false) { + inFlipTurn = true; + rotate180(); + Script.setTimeout(function() { + inFlipTurn = false; + }, TURN_RATE); + } + } + return; + }); + } + + function scriptEnding() { + Controller.disableMapping(FLYING_MAPPING_NAME); + Controller.disableMapping(DRIVING_MAPPING_NAME); + } + + Script.scriptEnding.connect(scriptEnding); + + registerBasicMapping(); + + Script.setTimeout(function() { + if (MyAvatar.useAdvanceMovementControls) { + Controller.disableMapping(DRIVING_MAPPING_NAME); + } else { + Controller.enableMapping(DRIVING_MAPPING_NAME); + } + + if (MyAvatar.getFyingEnabled()) { + Controller.disableMapping(FLYING_MAPPING_NAME); + } else { + Controller.enableMapping(FLYING_MAPPING_NAME); + } + }, 100); + + + HMD.displayModeChanged.connect(function(isHMDMode) { + if (isHMDMode) { + if (Controller.Hardware.Vive !== undefined || Controller.Hardware.OculusTouch !== undefined) { + if (MyAvatar.useAdvancedMovementControls) { + Controller.disableMapping(DRIVING_MAPPING_NAME); + } else { + Controller.enableMapping(DRIVING_MAPPING_NAME); + } + + if (MyAvatar.getFlyingEnabled()) { + Controller.disableMapping(FLYING_MAPPING_NAME); + } else { + Controller.enableMapping(FLYING_MAPPING_NAME); + } + } } - return; }); - basicMapping.from(Controller.Standard.RY).to(function(value) { - if (isDisabled) { - return; - } - var stick = Controller.getValue(Controller.Standard.RS); - if (value === 1 && Controller.Hardware.OculusTouch !== undefined) { - rotate180(); - } else if (Controller.Hardware.Vive !== undefined) { - if (value > 0.75 && inFlipTurn === false) { - inFlipTurn = true; - rotate180(); - Script.setTimeout(function() { - inFlipTurn = false; - }, TURN_RATE) - } - } - return; - }) -} -function enableMappings() { - Controller.enableMapping(mappingName); -} + function update() { + if ((Controller.Hardware.Vive !== undefined || Controller.Hardware.OculusTouch !== undefined) && HMD.active) { + var flying = MyAvatar.getFlyingEnabled(); + var driving = MyAvatar.useAdvancedMovementControls; -function disableMappings() { - Controller.disableMapping(mappingName); -} + if (flying !== previousFlyingState) { + if (flying) { + Controller.disableMapping(FLYING_MAPPING_NAME); + } else { + Controller.enableMapping(FLYING_MAPPING_NAME); + } -function scriptEnding() { - disableMappings(); -} - -Script.scriptEnding.connect(scriptEnding); - -registerBasicMapping(); - -Script.setTimeout(function() { - if (previousSetting === true) { - disableMappings(); - } else { - enableMappings(); - } -}, 100) - - -HMD.displayModeChanged.connect(function(isHMDMode) { - if (isHMDMode) { - if (Controller.Hardware.Vive !== undefined || Controller.Hardware.OculusTouch !== undefined) { - if (isChecked === true) { - disableMappings(); - } else if (isChecked === false) { - enableMappings(); + previousFlyingState = flying; } + if (driving !== previousDrivingState) { + if (driving) { + Controller.disableMapping(DRIVING_MAPPING_NAME); + } else { + Controller.enableMapping(DRIVING_MAPPING_NAME); + } + previousDrivingState = driving; + } + } + Script.setTimeout(update, TWO_SECONDS_INTERVAL); + } + + Script.setTimeout(update, TWO_SECONDS_INTERVAL); + + var HIFI_ADVANCED_MOVEMENT_DISABLER_CHANNEL = 'Hifi-Advanced-Movement-Disabler'; + function handleMessage(channel, message, sender) { + if (channel === HIFI_ADVANCED_MOVEMENT_DISABLER_CHANNEL) { + if (message === 'disable') { + isDisabled = true; + } else if (message === 'enable') { + isDisabled = false; + } } } -}); - -var HIFI_ADVANCED_MOVEMENT_DISABLER_CHANNEL = 'Hifi-Advanced-Movement-Disabler'; -function handleMessage(channel, message, sender) { - if (channel === HIFI_ADVANCED_MOVEMENT_DISABLER_CHANNEL) { - if (message === 'disable') { - isDisabled = true; - } else if (message === 'enable') { - isDisabled = false; - } else if (message === 'enable_mappings') { - print("enable mappings") - enableMappings(); - } else if (message === 'disable_mappings') { - disableMappings(); - } - } -} - -Messages.subscribe(HIFI_ADVANCED_MOVEMENT_DISABLER_CHANNEL); -Messages.messageReceived.connect(handleMessage); + Messages.subscribe(HIFI_ADVANCED_MOVEMENT_DISABLER_CHANNEL); + Messages.messageReceived.connect(handleMessage); }()); // END LOCAL_SCOPE