Add alert volume slider, add cancel buttons to alert sound/map dialogs

master
Skylar Ittner 5 years ago
parent 6b6e387d19
commit 4c5a999f34

@ -10,18 +10,38 @@ function initSFX() {
if (localStorage.getItem("alertsound") == null) { if (localStorage.getItem("alertsound") == null) {
localStorage.setItem("alertsound", "sonar"); localStorage.setItem("alertsound", "sonar");
} }
if (localStorage.getItem("alertvolume") == null) {
localStorage.setItem("alertvolume", 100);
}
var alertNoiseName = localStorage.getItem("alertsound"); var alertNoiseName = localStorage.getItem("alertsound");
var alertVolume = localStorage.getItem("alertvolume");
sfx = { sfx = {
"alert": new Audio("assets/audio/alert." + alertNoiseName + ".mp3"), "alert": new Audio("assets/audio/alert." + alertNoiseName + ".mp3"),
"ok": new Audio("assets/audio/ok.mp3"), "ok": new Audio("assets/audio/ok.mp3"),
"error": new Audio("assets/audio/error.mp3") "error": new Audio("assets/audio/error.mp3")
}; };
setVolume("alert", alertVolume);
} }
/**
* Play a sound.
* @param string sound Name of the sound to play (alert, ok, error)
* @returns {undefined}
*/
function playSound(sound) { function playSound(sound) {
sfx[sound].play(); sfx[sound].play();
} }
/**
* Set sound volume
* @param string sound The name of the sound to set volume of
* @param number volume Number in range 0 to 100
*/
function setVolume(sound, volume) {
sfx[sound].volume = volume / 100.0;
}
initSFX(); initSFX();

@ -62,6 +62,11 @@ if (localStorage.getItem("alertradius") == null) {
localStorage.setItem("alertradius", 100); localStorage.setItem("alertradius", 100);
} }
// Set default alert sound volume
if (localStorage.getItem("alertvolume") == null) {
localStorage.setItem("alertvolume", 100);
}
if (localStorage.getItem("darktheme") == "true") { if (localStorage.getItem("darktheme") == "true") {
$("#app").addClass("theme-dark"); $("#app").addClass("theme-dark");
} }

@ -46,6 +46,13 @@ $('.item-content[data-setting=wakelock] .toggle input').on("change", function ()
} }
}); });
$('.item-content[data-setting=alertvolume] .range-slider').on('range:changed', function (e, range) {
var val = app.range.get(".item-content[data-setting=alertvolume] .range-slider").getValue();
localStorage.setItem("alertvolume", val);
setVolume("alert", val);
playSound("alert");
});
function pickAlertSound() { function pickAlertSound() {
var currentalertsound = localStorage.getItem("alertsound"); var currentalertsound = localStorage.getItem("alertsound");
app.dialog.create({ app.dialog.create({
@ -62,12 +69,19 @@ function pickAlertSound() {
}, },
{ {
text: 'Jump' + (currentalertsound == "jump" ? " (current)" : ""), text: 'Jump' + (currentalertsound == "jump" ? " (current)" : ""),
},
{
text: 'Cancel',
color: 'red'
} }
], ],
verticalButtons: true, verticalButtons: true,
onClick: function (dialog, index) { onClick: function (dialog, index) {
var alertsound = "sonar"; var alertsound = "sonar";
switch (index) { switch (index) {
case 0:
alertsound = "sonar";
break;
case 1: case 1:
alertsound = "robot"; alertsound = "robot";
break; break;
@ -77,9 +91,8 @@ function pickAlertSound() {
case 3: case 3:
alertsound = "jump"; alertsound = "jump";
break; break;
case 0:
default: default:
alertsound = "sonar"; return;
} }
localStorage.setItem("alertsound", alertsound); localStorage.setItem("alertsound", alertsound);
// Reload sound effect stuff to apply new sound // Reload sound effect stuff to apply new sound
@ -103,24 +116,34 @@ function pickMapSource() {
}, },
{ {
text: 'Terrain' + (currentmapsource == "terrain" ? " (current)" : ""), text: 'Terrain' + (currentmapsource == "terrain" ? " (current)" : ""),
},
{
text: 'Cancel',
color: 'red'
} }
], ],
verticalButtons: true, verticalButtons: true,
onClick: function (dialog, index) { onClick: function (dialog, index) {
var mapsource = "offline"; var mapsource = "offline";
switch (index) { switch (index) {
case 0:
mapsource = "offline";
break;
case 1: case 1:
mapsource = "liberty"; mapsource = "liberty";
break; break;
case 2: case 2:
mapsource = "terrain"; mapsource = "terrain";
break; break;
case 0:
default: default:
mapsource = "offline"; return;
} }
localStorage.setItem("mapsource", mapsource); localStorage.setItem("mapsource", mapsource);
} }
}).open(); }).open();
}
function formatPercentLabel(value) {
return value + "%";
} }

@ -39,6 +39,20 @@
</div> </div>
</div> </div>
{{else}} {{else}}
{{#if slider}}
<div class="item-content" data-setting="{{setting}}">
<div class="item-inner">
<div class="item-title">
{{title}}
</div>
<div class="item-subtitle padding-horizontal-half">
<div class="range-slider range-slider-init">
<input type="range" min="{{min}}" max="{{max}}" step="{{step}}" label="true" formatLabel="formatPercentLabel(value)" value="{{value}}">
</div>
</div>
</div>
</div>
{{else}}
<div class="item-content" data-setting="{{setting}}" onclick="{{onclick}}"> <div class="item-content" data-setting="{{setting}}" onclick="{{onclick}}">
<div class="item-inner"> <div class="item-inner">
<div class="item-title-row"> <div class="item-title-row">
@ -48,6 +62,7 @@
</div> </div>
</div> </div>
{{/if}} {{/if}}
{{/if}}
</li> </li>
{{/each}} {{/each}}
</ul> </ul>
@ -56,4 +71,4 @@
<script src="assets/js/settings.js"></script> <script src="assets/js/settings.js"></script>
</div> </div>

@ -81,6 +81,15 @@ var routes = [
text: "Select which sound to play when a package is nearby.", text: "Select which sound to play when a package is nearby.",
onclick: "pickAlertSound()" onclick: "pickAlertSound()"
}, },
{
setting: "alertvolume",
title: "Alert Volume",
min: 0,
max: 100,
step: 5,
value: localStorage.getItem("alertvolume"),
slider: true
},
{ {
setting: "wakelock", setting: "wakelock",
title: "Keep screen on", title: "Keep screen on",

Loading…
Cancel
Save