diff --git a/scripts/system/assets/sounds/sound-print-photo.wav b/scripts/system/assets/sounds/sound-print-photo.wav new file mode 100644 index 0000000000..ecc5169968 Binary files /dev/null and b/scripts/system/assets/sounds/sound-print-photo.wav differ diff --git a/scripts/system/html/SnapshotReview.html b/scripts/system/html/SnapshotReview.html index fb40c04d05..f080cd204a 100644 --- a/scripts/system/html/SnapshotReview.html +++ b/scripts/system/html/SnapshotReview.html @@ -28,7 +28,11 @@ -
+
+ +
diff --git a/scripts/system/html/css/SnapshotReview.css b/scripts/system/html/css/SnapshotReview.css index 218eb8c9a5..54d39aaad3 100644 --- a/scripts/system/html/css/SnapshotReview.css +++ b/scripts/system/html/css/SnapshotReview.css @@ -286,6 +286,43 @@ input[type=button].naked:active { // END styling of snapshot controls (bottom panel) and its contents */ + +/* +// START polaroid styling +*/ + +#print-button { + width: 72px; + height: 72px; + margin-left: 30px; + margin-top: -10px; + box-sizing: content-box; + display: inline; + outline:none; +} + +.print-icon { + margin: auto; +} + +.print-icon-default { + background: url(../img/button-snap-print.svg) no-repeat; + margin-right: -1px; + width: 64px; + height: 64px; +} + +.print-icon-loading { + background: url(../img/loader.gif) no-repeat; + width: 32px; + height: 32px; +} + +/* +// END polaroid styling +*/ + + /* // START misc styling */ diff --git a/scripts/system/html/img/button-snap-print.svg b/scripts/system/html/img/button-snap-print.svg new file mode 100644 index 0000000000..d1570711d7 --- /dev/null +++ b/scripts/system/html/img/button-snap-print.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/system/html/js/SnapshotReview.js b/scripts/system/html/js/SnapshotReview.js index 36f7124f93..a3d1923aa9 100644 --- a/scripts/system/html/js/SnapshotReview.js +++ b/scripts/system/html/js/SnapshotReview.js @@ -311,10 +311,17 @@ function addImage(image_data, isLoggedIn, canShare, isGifLoading, isShowingPrevi if (isShowingPreviousImages && isLoggedIn && image_data.story_id) { updateShareInfo(id, image_data.story_id); } + if (isShowingPreviousImages) { + requestPrintButtonUpdate(); + } }; img.onerror = function () { img.onload = null; img.src = image_data.errorPath; + EventBridge.emitWebEvent(JSON.stringify({ + type: "snapshot", + action: "alertSnapshotLoadFailed" + })); }; } function showConfirmationMessage(selectedID, destination) { @@ -670,10 +677,22 @@ window.onload = function () { break; case 'captureSettings': handleCaptureSetting(message.setting); + break; + case 'setPrintButtonEnabled': + setPrintButtonEnabled(); + break; + case 'setPrintButtonLoading': + setPrintButtonLoading(); + break; + case 'setPrintButtonDisabled': + setPrintButtonDisabled(); break; case 'snapshotUploadComplete': var isGif = fileExtensionMatches(message.image_url, "gif"); updateShareInfo(isGif ? "p1" : "p0", message.story_id); + if (isPrintProcessing()) { + setPrintButtonEnabled(); + } break; default: console.log("Unknown message action received in SnapshotReview.js."); @@ -703,6 +722,59 @@ function takeSnapshot() { } } +function isPrintDisabled() { + var printElement = document.getElementById('print-icon'); + + return printElement.classList.contains("print-icon") && + printElement.classList.contains("print-icon-default") && + document.getElementById('print-button').disabled; +} +function isPrintProcessing() { + var printElement = document.getElementById('print-icon'); + + return printElement.classList.contains("print-icon") && + printElement.classList.contains("print-icon-loading") && + document.getElementById('print-button').disabled; +} +function isPrintEnabled() { + var printElement = document.getElementById('print-icon'); + + return printElement.classList.contains("print-icon") && + printElement.classList.contains("print-icon-default") && + !document.getElementById('print-button').disabled; +} + +function setPrintButtonLoading() { + document.getElementById('print-icon').className = "print-icon print-icon-loading"; + document.getElementById('print-button').disabled = true; +} +function setPrintButtonDisabled() { + document.getElementById('print-icon').className = "print-icon print-icon-default"; + document.getElementById('print-button').disabled = true; +} +function setPrintButtonEnabled() { + document.getElementById('print-button').disabled = false; + document.getElementById('print-icon').className = "print-icon print-icon-default"; +} + +function requestPrintButtonUpdate() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "snapshot", + action: "requestPrintButtonUpdate" + })); +} + +function printToPolaroid() { + if (isPrintEnabled()) { + EventBridge.emitWebEvent(JSON.stringify({ + type: "snapshot", + action: "printToPolaroid" + })); + } else { + setPrintButtonLoading(); + } +} + function testInBrowser(test) { if (test === 0) { showSetupInstructions(); diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index 2d3aaffdbf..4e3fb95140 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -99,11 +99,13 @@ function onMessage(message) { Settings.setValue("previousStillSnapStoryID", ""); Settings.setValue("previousStillSnapBlastingDisabled", false); Settings.setValue("previousStillSnapHifiSharingDisabled", false); + Settings.setValue("previousStillSnapUrl", ""); Settings.setValue("previousAnimatedSnapPath", ""); Settings.setValue("previousAnimatedSnapStoryID", ""); Settings.setValue("previousAnimatedSnapBlastingDisabled", false); Settings.setValue("previousAnimatedSnapHifiSharingDisabled", false); } + updatePrintPermissions(); break; case 'login': openLoginWindow(); @@ -140,12 +142,13 @@ function onMessage(message) { break; case 'shareSnapshotForUrl': isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) { - if (canShare) { - isLoggedIn = Account.isLoggedIn(); + var isGif = fileExtensionMatches(message.data, "gif"); + isLoggedIn = Account.isLoggedIn(); + isUploadingPrintableStill = canShare && Account.isLoggedIn() && !isGif; + if (canShare) { if (isLoggedIn) { print('Sharing snapshot with audience "for_url":', message.data); - Window.shareSnapshot(message.data, Settings.getValue("previousSnapshotHref")); - var isGif = fileExtensionMatches(message.data, "gif"); + Window.shareSnapshot(message.data, Settings.getValue("previousSnapshotHref")); if (isGif) { numGifSnapshotUploadsPending++; } else { @@ -156,6 +159,7 @@ function onMessage(message) { snapshotToShareAfterLogin.push({ path: message.data, href: Settings.getValue("previousSnapshotHref") }); } } + updatePrintPermissions(); }); break; case 'blastToConnections': @@ -215,6 +219,18 @@ function onMessage(message) { }); } break; + case 'requestPrintButtonUpdate': + updatePrintPermissions(); + break; + case 'printToPolaroid': + if (Entities.canRez() || Entities.canRezTmp()) { + printToPolaroid(Settings.getValue("previousStillSnapUrl")); + removeFromStoryIDsToMaybeDelete(Settings.getValue("previousStillSnapStoryID")); + } + break; + case 'alertSnapshotLoadFailed': + snapshotFailedToLoad = true; + break; case 'shareSnapshotWithEveryone': isLoggedIn = Account.isLoggedIn(); if (isLoggedIn) { @@ -262,6 +278,54 @@ function onMessage(message) { } } +var POLAROID_PRINT_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/sound-print-photo.wav")); +var POLAROID_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/alan/dev/Test/snapshot.fbx'; + +function printToPolaroid(image_url) { + var polaroid_url = image_url; + + var model_pos = Vec3.sum(MyAvatar.position, Vec3.multiply(1.25, Quat.getForward(MyAvatar.orientation))); + + var model_q1 = MyAvatar.orientation; + var model_q2 = Quat.angleAxis(90, Quat.getRight(model_q1)); + var model_rot = Quat.multiply(model_q2, model_q1); + + var properties = { + "type": 'Model', + "shapeType": 'box', + + "name": "New Snapshot", + "description": "Printed from Snaps", + "modelURL": POLAROID_MODEL_URL, + + "position": model_pos, + "rotation": model_rot, + + "textures": JSON.stringify( { "tex.picture": polaroid_url } ), + + "density": 200, + "restitution": 0.15, + "gravity": { "x": 0, "y": -4.5, "z": 0 }, + + "velocity": { "x": 0, "y": 3.5, "z": 0 }, + "angularVelocity": { "x": -1.0, "y": 0, "z": -1.3 }, + + "dynamic": true, + "collisionsWillMove": true, + + "userData": { + "grabbableKey": { "grabbable" : true } + } + }; + + var polaroid = Entities.addEntity(properties); + Audio.playSound(POLAROID_PRINT_SOUND, { + position: model_pos, + localOnly: false, + volume: 0.2 + }); +} + function fillImageDataFromPrevious() { isLoggedIn = Account.isLoggedIn(); var previousStillSnapPath = Settings.getValue("previousStillSnapPath"); @@ -349,6 +413,7 @@ function snapshotUploaded(isError, reply) { Settings.setValue("previousAnimatedSnapStoryID", storyID); } else { Settings.setValue("previousStillSnapStoryID", storyID); + Settings.setValue("previousStillSnapUrl", imageURL); } } else { print('Ignoring snapshotUploaded() callback for stale ' + (isGif ? 'GIF' : 'Still' ) + ' snapshot. Stale story ID:', storyID); @@ -356,6 +421,7 @@ function snapshotUploaded(isError, reply) { } else { print(reply); } + isUploadingPrintableStill = false; } var href, domainId; function takeSnapshot() { @@ -367,10 +433,16 @@ function takeSnapshot() { Settings.setValue("previousStillSnapStoryID", ""); Settings.setValue("previousStillSnapBlastingDisabled", false); Settings.setValue("previousStillSnapHifiSharingDisabled", false); + Settings.setValue("previousStillSnapUrl", ""); Settings.setValue("previousAnimatedSnapPath", ""); Settings.setValue("previousAnimatedSnapStoryID", ""); Settings.setValue("previousAnimatedSnapBlastingDisabled", false); Settings.setValue("previousAnimatedSnapHifiSharingDisabled", false); + + // Since we are taking a snapshot, we should make the print button appear to be loading/processing + snapshotFailedToLoad = false; + isUploadingPrintableStill = true; + updatePrintPermissions(); // Raising the desktop for the share dialog at end will interact badly with clearOverlayWhenMoving. // Turn it off now, before we start futzing with things (and possibly moving). @@ -612,6 +684,8 @@ function onUsernameChanged() { } }); } + isUploadingPrintableStill = canShare; + updatePrintPermissions(); }); shareAfterLogin = false; @@ -619,6 +693,7 @@ function onUsernameChanged() { } } } + function snapshotLocationSet(location) { if (location !== "") { tablet.emitScriptEvent(JSON.stringify({ @@ -628,12 +703,44 @@ function snapshotLocationSet(location) { } } +function updatePrintPermissions() { + processRezPermissionChange(Entities.canRez() || Entities.canRezTmp()); +} + +var snapshotFailedToLoad = false; +var isUploadingPrintableStill = false; +function processRezPermissionChange(canRez) { + var action = ""; + + if (canRez && !snapshotFailedToLoad) { + if (Settings.getValue("previousStillSnapUrl")) { + action = 'setPrintButtonEnabled'; + } else if (isUploadingPrintableStill) { + action = 'setPrintButtonLoading'; + } else { + action = 'setPrintButtonDisabled'; + } + } else { + action = 'setPrintButtonDisabled'; + } + + tablet.emitScriptEvent(JSON.stringify({ + type: "snapshot", + action : action + })); +} + button.clicked.connect(onButtonClicked); buttonConnected = true; + Window.snapshotShared.connect(snapshotUploaded); tablet.screenChanged.connect(onTabletScreenChanged); GlobalServices.myUsernameChanged.connect(onUsernameChanged); Snapshot.snapshotLocationSet.connect(snapshotLocationSet); + +Entities.canRezChanged.connect(updatePrintPermissions); +Entities.canRezTmpChanged.connect(updatePrintPermissions); + Script.scriptEnding.connect(function () { if (buttonConnected) { button.clicked.disconnect(onButtonClicked); @@ -645,6 +752,9 @@ Script.scriptEnding.connect(function () { Window.snapshotShared.disconnect(snapshotUploaded); tablet.screenChanged.disconnect(onTabletScreenChanged); Snapshot.snapshotLocationSet.disconnect(snapshotLocationSet); + + Entities.canRezChanged.disconnect(processRezPermissionChange); + Entities.canRezTmpChanged.disconnect(processRezPermissionChange); }); }()); // END LOCAL_SCOPE