Skip to content

Commit

Permalink
✨ Toggle UI sounds in the Main menu -> Settings
Browse files Browse the repository at this point in the history
Closes #212
  • Loading branch information
CosmoMyzrailGorynych committed Aug 11, 2020
1 parent f04ae70 commit b1a5a9c
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
1 change: 1 addition & 0 deletions app/data/i18n/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"codeFont": "Font for code",
"codeLigatures": "Ligatures",
"codeDense": "Dense layout",
"disableSounds": "Disable UI sounds",
"openIncludeFolder": "Open \"include\" folder",
"troubleshooting": "Troubleshooting",
"toggleDevTools": "Toggle Dev Tools",
Expand Down
61 changes: 28 additions & 33 deletions src/js/3rdparty/alertify.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/* eslint-disable func-names */
/* eslint-disable max-lines-per-function */
/* eslint-disable max-len */
/* eslint-disable id-length */
/* eslint {
'no-underscore-dangle': 'off',
max-params: 'off'
} */

(function() {

(function alertify() {
'use strict';

var TRANSITION_FALLBACK_DURATION = 500;
var hideElement = function(el) {

var hideElement = function (el) {
if (!el) {
return;
}

var removeThis = function() {
var removeThis = function () {
if (el && el.parentNode) {
el.parentNode.removeChild(el);
}
Expand All @@ -26,11 +28,9 @@

// Fallback for no transitions.
setTimeout(removeThis, TRANSITION_FALLBACK_DURATION);

};

var Alertify = function () {

var Alertify = function Alertify() {
/**
* Alertify private object
* @type {Object}
Expand Down Expand Up @@ -82,7 +82,6 @@
* @return {String} An HTML string of the message box
*/
build(item) {

var btnTxt = this.dialogs.buttons.ok;
var html = '<div class=\'dialog\'><div>' + this.dialogs.message.replace('{{message}}', item.message);

Expand All @@ -100,7 +99,6 @@
.replace('{{cancel}}', this.cancelLabel);

return html;

},

setCloseLogOnClick(bool) {
Expand All @@ -116,9 +114,8 @@
* @return {undefined}
*/
close(elem, wait) {

if (this.closeLogOnClick) {
elem.addEventListener('click', function() {
elem.addEventListener('click', function () {
hideElement(elem);
});
}
Expand All @@ -128,11 +125,10 @@
if (wait < 0) {
hideElement(elem);
} else if (wait > 0) {
setTimeout(function() {
setTimeout(function () {
hideElement(elem);
}, wait);
}

},

/**
Expand Down Expand Up @@ -164,7 +160,6 @@
* @return {void}
*/
log(message, type, click) {

var existing = document.querySelectorAll('.alertify-logs > div');
if (existing) {
var diff = existing.length - this.maxLogItems;
Expand All @@ -183,7 +178,6 @@
},

setupLogContainer() {

var elLog = document.querySelector('.alertify-logs');
var className = this.logContainerClass;
if (!elLog) {
Expand All @@ -198,7 +192,6 @@
}

return elLog;

},

/**
Expand All @@ -213,7 +206,6 @@
* @return {undefined}
*/
notify(message, type, click) {

var elLog = this.setupLogContainer();
var log = document.createElement('div');

Expand All @@ -230,12 +222,11 @@
}

elLog.appendChild(log);
setTimeout(function() {
setTimeout(function () {
log.className += ' show';
}, 10);

this.close(log, this.delay);

},

/**
Expand All @@ -246,14 +237,13 @@
* @return {undefined}
*/
setup(item) {

var el = document.createElement('div');
el.className = 'alertify hide';
el.innerHTML = this.build(item);

var btnOK = el.querySelector('.ok');
var btnCancel = el.querySelector('.cancel');
var input = item.type === 'prompt'? el.querySelector('input') : null;
var input = item.type === 'prompt' ? el.querySelector('input') : null;

// Set default value/placeholder of input
if (input) {
Expand All @@ -262,14 +252,16 @@
}
}

var setupHandlers = function(resolve) {
var setupHandlers = function (resolve) {
if (typeof resolve !== 'function') {
// promises are not available so resolve is a no-op
resolve = function () {void 0;};
resolve = function () {
void 0;
};
}

if (btnOK) {
btnOK.addEventListener('click', function(ev) {
btnOK.addEventListener('click', function (ev) {
if (item.onOkay && typeof item.onOkay === 'function') {
if (input) {
item.onOkay(input.value, ev);
Expand All @@ -296,7 +288,7 @@
}

if (btnCancel) {
btnCancel.addEventListener('click', function(ev) {
btnCancel.addEventListener('click', function (ev) {
if (item.onCancel && typeof item.onCancel === 'function') {
item.onCancel(ev);
}
Expand All @@ -311,7 +303,7 @@
}

if (input) {
input.addEventListener('keyup', function(ev) {
input.addEventListener('keyup', function (ev) {
if (ev.which === 13) {
btnOK.click();
}
Expand All @@ -328,14 +320,14 @@
}

this.parent.appendChild(el);
setTimeout(function() {
setTimeout(function () {
el.classList.remove('hide');
if (input && item.type && item.type === 'prompt') {
input.select();
input.focus();
} else if (btnOK) {
btnOK.focus();
}
btnOK.focus();
}
}, 100);

return promise;
Expand Down Expand Up @@ -431,12 +423,16 @@
},
success(message, click) {
_alertify.log(message, 'success', click);
soundbox.play('Success');
if (localStorage.disableSounds !== 'on') {
soundbox.play('Success');
}
return this;
},
error(message, click) {
_alertify.log(message, 'error', click);
soundbox.play('Failure');
if (localStorage.disableSounds !== 'on') {
soundbox.play('Failure');
}
return this;
},
cancelBtn(label) {
Expand Down Expand Up @@ -484,7 +480,6 @@
};

window.alertify = new Alertify();

}());

window.alertify.reset();
4 changes: 3 additions & 1 deletion src/riotTags/debugger/debugger-toolbar.tag
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ debugger-toolbar
const buff = new Buffer(shotBase64, 'base64');
const stream = fs.createWriteStream(fullPath);
stream.on('finish', () => {
window.soundbox.play('Success');
if (localStorage.disableSounds !== 'on') {
window.soundbox.play('Success');
}
// eslint-disable-next-line no-new
new Notification('Done!', {
body: `Saved to ${fullPath} 👌`,
Expand Down
9 changes: 9 additions & 0 deletions src/riotTags/main-menu.tag
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ main-menu.flexcol
}
}, {
type: 'separator'
}, {
label: window.languageJSON.menu.disableSounds,
type: 'checkbox',
checked: () => localStorage.disableSounds === 'on',
click: () => {
localStorage.disableSounds = (localStorage.disableSounds || 'off') === 'off' ? 'on' : 'off';
}
}, {
type: 'separator'
}, {
label: window.languageJSON.common.zoomIn,
icon: 'zoom-in',
Expand Down
4 changes: 3 additions & 1 deletion src/riotTags/rooms/room-editor.tag
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ room-editor.panel.view
if (this.nameTaken) {
// animate the error notice
require('./data/node_requires/jellify')(this.refs.errorNotice);
window.soundbox.play('Failure');
if (localStorage.disableSounds !== 'on') {
window.soundbox.play('Failure');
}
return false;
}
this.room.lastmod = Number(new Date());
Expand Down
4 changes: 3 additions & 1 deletion src/riotTags/style-editor.tag
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ style-editor.panel.view
if (this.nameTaken) {
// animate the error notice
require('./data/node_requires/jellify')(this.refs.errorNotice);
soundbox.play('Failure');
if (localStorage.disableSounds !== 'on') {
soundbox.play('Failure');
}
return false;
}
this.styleobj.lastmod = Number(new Date());
Expand Down
4 changes: 3 additions & 1 deletion src/riotTags/texture-editor.tag
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,9 @@ texture-editor.panel.view
if (this.nameTaken) {
// animate the error notice
require('./data/node_requires/jellify')(this.refs.errorNotice);
soundbox.play('Failure');
if (localStorage.disableSounds !== 'on') {
soundbox.play('Failure');
}
return false;
}
this.parent.fillTextureMap();
Expand Down
4 changes: 3 additions & 1 deletion src/riotTags/type-editor.tag
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ type-editor.panel.view.flexrow
if (this.nameTaken) {
// animate the error notice
require('./data/node_requires/jellify')(this.refs.errorNotice);
soundbox.play('Failure');
if (localStorage.disableSounds !== 'on') {
soundbox.play('Failure');
}
return false;
}
glob.modified = true;
Expand Down

0 comments on commit b1a5a9c

Please sign in to comment.