2020-07-20 13:59:04 +03:00
|
|
|
let modes = {
|
|
|
|
'Basic' : {
|
|
|
|
description: 'Basic mode is perfect if you want to create simple sprites or try out palettes.'
|
|
|
|
},
|
|
|
|
'Advanced' : {
|
2020-12-31 18:47:56 +03:00
|
|
|
description: 'Choose advanced mode to gain access to more advanced features such as layers.'
|
2020-07-20 13:59:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let infoBox = document.getElementById('editor-mode-info');
|
2021-04-25 13:41:36 +03:00
|
|
|
let currentSplashButton = document.getElementById("sp-mode-palette").children[0].children[1];
|
2020-07-20 13:59:04 +03:00
|
|
|
|
2021-02-19 00:28:52 +03:00
|
|
|
function splashMode(mouseEvent, mode) {
|
2021-04-25 13:41:36 +03:00
|
|
|
console.log("UE");
|
2021-02-19 00:28:52 +03:00
|
|
|
if (currentSplashButton == undefined) {
|
2021-04-25 13:41:36 +03:00
|
|
|
currentSplashButton = mouseEvent.target.parentElement;
|
2021-02-19 00:28:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mode !== pixelEditorMode) {
|
|
|
|
console.log("Mode target: " + mouseEvent.target);
|
|
|
|
// Remove selected class to old button
|
|
|
|
currentSplashButton.classList.remove("sp-interface-selected");
|
|
|
|
// Add selected class to new button
|
2021-04-25 13:41:36 +03:00
|
|
|
mouseEvent.target.parentElement.classList.add("sp-interface-selected");
|
|
|
|
|
|
|
|
// Setting the new mode
|
|
|
|
pixelEditorMode = mode;
|
2021-02-19 00:28:52 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 13:41:36 +03:00
|
|
|
// Setting the new selected button
|
|
|
|
currentSplashButton = mouseEvent.target.parentElement;
|
2021-02-19 00:28:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function switchMode(mustConfirm = true) {
|
2020-09-09 07:15:22 +03:00
|
|
|
|
|
|
|
//switch to advanced mode
|
2021-02-19 00:28:52 +03:00
|
|
|
if (pixelEditorMode == 'Basic') {
|
2020-07-21 00:33:17 +03:00
|
|
|
// Switch to advanced ez pez lemon squez
|
|
|
|
document.getElementById('switch-mode-button').innerHTML = 'Switch to basic mode';
|
|
|
|
// Show the layer menus
|
|
|
|
layerList.style.display = "inline-block";
|
|
|
|
document.getElementById('layer-button').style.display = 'inline-block';
|
2021-01-04 01:59:11 +03:00
|
|
|
// Hide the palette menu
|
|
|
|
document.getElementById('colors-menu').style.right = '200px'
|
2020-09-09 07:15:22 +03:00
|
|
|
|
2020-07-21 00:33:17 +03:00
|
|
|
pixelEditorMode = 'Advanced';
|
|
|
|
}
|
2020-09-09 07:15:22 +03:00
|
|
|
//switch to basic mode
|
2020-07-21 00:33:17 +03:00
|
|
|
else {
|
2020-09-09 07:15:22 +03:00
|
|
|
//if there is a current layer (a document is active)
|
|
|
|
if (currentLayer) {
|
|
|
|
//confirm with user before flattening image
|
|
|
|
if (mustConfirm ) {
|
|
|
|
if (!confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selecting the current layer
|
|
|
|
currentLayer.selectLayer();
|
|
|
|
// Flatten the layers
|
|
|
|
flatten(true);
|
2020-07-21 00:33:17 +03:00
|
|
|
}
|
|
|
|
|
2020-09-09 07:15:22 +03:00
|
|
|
//change menu text
|
2020-07-21 00:33:17 +03:00
|
|
|
document.getElementById('switch-mode-button').innerHTML = 'Switch to advanced mode';
|
2020-09-09 07:15:22 +03:00
|
|
|
|
2020-07-21 00:33:17 +03:00
|
|
|
// Hide the layer menus
|
|
|
|
layerList.style.display = 'none';
|
|
|
|
document.getElementById('layer-button').style.display = 'none';
|
2021-01-04 01:59:11 +03:00
|
|
|
// Show the palette menu
|
|
|
|
document.getElementById('colors-menu').style.display = 'flex';
|
|
|
|
// Move the palette menu
|
|
|
|
document.getElementById('colors-menu').style.right = '0px';
|
2020-07-21 00:33:17 +03:00
|
|
|
|
|
|
|
pixelEditorMode = 'Basic';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
on('click', 'switch-mode-button', function (e) {
|
2021-02-19 00:28:52 +03:00
|
|
|
switchMode();
|
2020-07-21 00:33:17 +03:00
|
|
|
});
|
|
|
|
|
2020-07-20 13:59:04 +03:00
|
|
|
// Makes the menu open
|
|
|
|
on('click', 'editor-mode-button', function (e){
|
|
|
|
//open or close the preset menu
|
|
|
|
toggle('editor-mode-button');
|
|
|
|
toggle('editor-mode-menu');
|
|
|
|
|
|
|
|
//close the palette menu
|
|
|
|
deselect('palette-button');
|
|
|
|
deselect('palette-menu');
|
|
|
|
|
|
|
|
//close the preset menu
|
|
|
|
deselect('preset-button');
|
|
|
|
deselect('preset-menu');
|
|
|
|
|
|
|
|
//stop the click from propogating to the parent element
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
//populate preset list in new pixel menu
|
|
|
|
Object.keys(modes).forEach(function(modeName,index) {
|
|
|
|
var editorModeMenu = document.getElementById('editor-mode-menu');
|
|
|
|
|
|
|
|
//create button
|
|
|
|
var button = document.createElement('button');
|
|
|
|
button.appendChild(document.createTextNode(modeName));
|
|
|
|
|
|
|
|
//insert new element
|
|
|
|
editorModeMenu.appendChild(button);
|
|
|
|
|
|
|
|
//add click event listener
|
|
|
|
on('click', button, function() {
|
|
|
|
|
|
|
|
//change mode on new pixel
|
|
|
|
setValue('editor-mode', modeName);
|
|
|
|
// Change description
|
|
|
|
infoBox.innerHTML = modes[modeName].description;
|
|
|
|
|
|
|
|
//hide the dropdown menu
|
|
|
|
deselect('editor-mode-menu');
|
|
|
|
deselect('editor-mode-button');
|
|
|
|
|
|
|
|
//set the text of the dropdown to the newly selected mode
|
|
|
|
setText('editor-mode-button', modeName);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|