From 613610c0502aed05ae43a2ae31c8b644ecd2e69f Mon Sep 17 00:00:00 2001 From: matzman666 Date: Wed, 21 Dec 2016 20:10:58 +0100 Subject: [PATCH] New chaperone/audio profile now replaces an already existing one with the same name. --- src/tabcontrollers/AudioTabController.cpp | 43 +++++++----- src/tabcontrollers/ChaperoneTabController.cpp | 65 +++++++++++-------- 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index 112dab1..bdbcedd 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -450,23 +450,32 @@ namespace advsettings { } void AudioTabController::addPttProfile(QString name) { - auto i = pttProfiles.size(); - pttProfiles.emplace_back(); - auto& profile = pttProfiles[i]; - profile.profileName = name.toStdString(); - profile.showNotification = m_pttShowNotification; - profile.leftControllerEnabled = m_pttLeftControllerEnabled; - profile.rightControllerEnabled = m_pttRightControllerEnabled; - profile.controllerConfigs[0].digitalButtons = m_pttControllerConfigs[0].digitalButtons; - profile.controllerConfigs[0].digitalButtonMask = m_pttControllerConfigs[0].digitalButtonMask; - profile.controllerConfigs[0].triggerMode = m_pttControllerConfigs[0].triggerMode; - profile.controllerConfigs[0].touchpadMode = m_pttControllerConfigs[0].touchpadMode; - profile.controllerConfigs[0].touchpadAreas = m_pttControllerConfigs[0].touchpadAreas; - profile.controllerConfigs[1].digitalButtons = m_pttControllerConfigs[1].digitalButtons; - profile.controllerConfigs[1].digitalButtonMask = m_pttControllerConfigs[1].digitalButtonMask; - profile.controllerConfigs[1].triggerMode = m_pttControllerConfigs[1].triggerMode; - profile.controllerConfigs[1].touchpadMode = m_pttControllerConfigs[1].touchpadMode; - profile.controllerConfigs[1].touchpadAreas = m_pttControllerConfigs[1].touchpadAreas; + PttProfile* profile = nullptr; + for (auto& p : pttProfiles) { + if (p.profileName.compare(name.toStdString()) == 0) { + profile = &p; + break; + } + } + if (!profile) { + auto i = pttProfiles.size(); + pttProfiles.emplace_back(); + profile = &pttProfiles[i]; + } + profile->profileName = name.toStdString(); + profile->showNotification = m_pttShowNotification; + profile->leftControllerEnabled = m_pttLeftControllerEnabled; + profile->rightControllerEnabled = m_pttRightControllerEnabled; + profile->controllerConfigs[0].digitalButtons = m_pttControllerConfigs[0].digitalButtons; + profile->controllerConfigs[0].digitalButtonMask = m_pttControllerConfigs[0].digitalButtonMask; + profile->controllerConfigs[0].triggerMode = m_pttControllerConfigs[0].triggerMode; + profile->controllerConfigs[0].touchpadMode = m_pttControllerConfigs[0].touchpadMode; + profile->controllerConfigs[0].touchpadAreas = m_pttControllerConfigs[0].touchpadAreas; + profile->controllerConfigs[1].digitalButtons = m_pttControllerConfigs[1].digitalButtons; + profile->controllerConfigs[1].digitalButtonMask = m_pttControllerConfigs[1].digitalButtonMask; + profile->controllerConfigs[1].triggerMode = m_pttControllerConfigs[1].triggerMode; + profile->controllerConfigs[1].touchpadMode = m_pttControllerConfigs[1].touchpadMode; + profile->controllerConfigs[1].touchpadAreas = m_pttControllerConfigs[1].touchpadAreas; savePttProfiles(); OverlayController::appSettings()->sync(); emit pttProfilesUpdated(); diff --git a/src/tabcontrollers/ChaperoneTabController.cpp b/src/tabcontrollers/ChaperoneTabController.cpp index 152a1c4..f0981b9 100644 --- a/src/tabcontrollers/ChaperoneTabController.cpp +++ b/src/tabcontrollers/ChaperoneTabController.cpp @@ -352,69 +352,78 @@ void ChaperoneTabController::reloadFromDisk() { void ChaperoneTabController::addChaperoneProfile(QString name, bool includeGeometry, bool includeVisbility, bool includeFadeDistance, bool includeCenterMarker, bool includePlaySpaceMarker, bool includeFloorBounds, bool includeBoundsColor, bool includeChaperoneStyle, bool includeForceBounds) { vr::EVRSettingsError vrSettingsError; - auto i = chaperoneProfiles.size(); - chaperoneProfiles.emplace_back(); - auto& profile = chaperoneProfiles[i]; - profile.profileName = name.toStdString(); - profile.includesChaperoneGeometry = includeGeometry; + ChaperoneProfile* profile = nullptr; + for (auto& p : chaperoneProfiles) { + if (p.profileName.compare(name.toStdString()) == 0) { + profile = &p; + break; + } + } + if (!profile) { + auto i = chaperoneProfiles.size(); + chaperoneProfiles.emplace_back(); + profile = &chaperoneProfiles[i]; + } + profile->profileName = name.toStdString(); + profile->includesChaperoneGeometry = includeGeometry; if (includeGeometry) { vr::VRChaperoneSetup()->RevertWorkingCopy(); uint32_t quadCount = 0; vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo(nullptr, &quadCount); - profile.chaperoneGeometryQuadCount = quadCount; - profile.chaperoneGeometryQuads.reset(new vr::HmdQuad_t[quadCount]); - vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo(profile.chaperoneGeometryQuads.get(), &quadCount); - vr::VRChaperoneSetup()->GetWorkingStandingZeroPoseToRawTrackingPose(&profile.standingCenter); - vr::VRChaperoneSetup()->GetWorkingPlayAreaSize(&profile.playSpaceAreaX, &profile.playSpaceAreaZ); + profile->chaperoneGeometryQuadCount = quadCount; + profile->chaperoneGeometryQuads.reset(new vr::HmdQuad_t[quadCount]); + vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo(profile->chaperoneGeometryQuads.get(), &quadCount); + vr::VRChaperoneSetup()->GetWorkingStandingZeroPoseToRawTrackingPose(&profile->standingCenter); + vr::VRChaperoneSetup()->GetWorkingPlayAreaSize(&profile->playSpaceAreaX, &profile->playSpaceAreaZ); } - profile.includesVisibility = includeVisbility; + profile->includesVisibility = includeVisbility; if (includeVisbility) { - profile.visibility = m_visibility; + profile->visibility = m_visibility; } - profile.includesFadeDistance = includeFadeDistance; + profile->includesFadeDistance = includeFadeDistance; if (includeFadeDistance) { - profile.fadeDistance = m_fadeDistance; + profile->fadeDistance = m_fadeDistance; } - profile.includesCenterMarker = includeCenterMarker; + profile->includesCenterMarker = includeCenterMarker; if (includeCenterMarker) { - profile.centerMarker = m_centerMarker; + profile->centerMarker = m_centerMarker; } - profile.includesPlaySpaceMarker = includePlaySpaceMarker; + profile->includesPlaySpaceMarker = includePlaySpaceMarker; if (includePlaySpaceMarker) { - profile.playSpaceMarker = m_playSpaceMarker; + profile->playSpaceMarker = m_playSpaceMarker; } - profile.includesFloorBoundsMarker = includeFloorBounds; + profile->includesFloorBoundsMarker = includeFloorBounds; if (includeFloorBounds) { - profile.floorBoundsMarker = vr::VRSettings()->GetBool(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_GroundPerimeterOn_Bool, &vrSettingsError); + profile->floorBoundsMarker = vr::VRSettings()->GetBool(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_GroundPerimeterOn_Bool, &vrSettingsError); if (vrSettingsError != vr::VRSettingsError_None) { LOG(WARNING) << "Could not read \"" << vr::k_pch_CollisionBounds_GroundPerimeterOn_Bool << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); } } - profile.includesBoundsColor = includeBoundsColor; + profile->includesBoundsColor = includeBoundsColor; if (includeBoundsColor) { - profile.boundsColor[0] = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_ColorGammaR_Int32, &vrSettingsError); + profile->boundsColor[0] = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_ColorGammaR_Int32, &vrSettingsError); if (vrSettingsError != vr::VRSettingsError_None) { LOG(WARNING) << "Could not read \"" << vr::k_pch_CollisionBounds_ColorGammaR_Int32 << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); } - profile.boundsColor[1] = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_ColorGammaG_Int32, &vrSettingsError); + profile->boundsColor[1] = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_ColorGammaG_Int32, &vrSettingsError); if (vrSettingsError != vr::VRSettingsError_None) { LOG(WARNING) << "Could not read \"" << vr::k_pch_CollisionBounds_ColorGammaG_Int32 << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); } - profile.boundsColor[2] = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_ColorGammaB_Int32, &vrSettingsError); + profile->boundsColor[2] = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_ColorGammaB_Int32, &vrSettingsError); if (vrSettingsError != vr::VRSettingsError_None) { LOG(WARNING) << "Could not read \"" << vr::k_pch_CollisionBounds_ColorGammaB_Int32 << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); } } - profile.includesChaperoneStyle = includeChaperoneStyle; + profile->includesChaperoneStyle = includeChaperoneStyle; if (includeChaperoneStyle) { - profile.chaperoneStyle = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_Style_Int32, &vrSettingsError); + profile->chaperoneStyle = vr::VRSettings()->GetInt32(vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_Style_Int32, &vrSettingsError); if (vrSettingsError != vr::VRSettingsError_None) { LOG(WARNING) << "Could not read \"" << vr::k_pch_CollisionBounds_Style_Int32 << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); } } - profile.includesForceBounds = includeForceBounds; + profile->includesForceBounds = includeForceBounds; if (includeForceBounds) { - profile.forceBounds = m_forceBounds; + profile->forceBounds = m_forceBounds; } saveChaperoneProfiles(); OverlayController::appSettings()->sync();