mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
generic confirmationDialog
This commit is contained in:
parent
a6f1fbd5e1
commit
5464e0a34b
3 changed files with 594 additions and 285 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
"semi": true,
|
"semi": true,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"useTabs": false,
|
"useTabs": false,
|
||||||
"printWidth": 220,
|
"printWidth": 200,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"endOfLine": "lf"
|
"endOfLine": "lf"
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -20,7 +20,7 @@ function editResources() {
|
||||||
|
|
||||||
// add listeners
|
// add listeners
|
||||||
document.getElementById('resourcesEditorRefresh').addEventListener('click', resourcesEditorAddLines);
|
document.getElementById('resourcesEditorRefresh').addEventListener('click', resourcesEditorAddLines);
|
||||||
document.getElementById('resourcesRegenerate').addEventListener('click', regenerateResources);
|
document.getElementById('resourcesRegenerate').addEventListener('click', regenerateCurrentResources);
|
||||||
document.getElementById('resourcesLegend').addEventListener('click', toggleLegend);
|
document.getElementById('resourcesLegend').addEventListener('click', toggleLegend);
|
||||||
document.getElementById('resourcesPercentage').addEventListener('click', togglePercentageMode);
|
document.getElementById('resourcesPercentage').addEventListener('click', togglePercentageMode);
|
||||||
document.getElementById('resourcesAssign').addEventListener('click', enterResourceAssignMode);
|
document.getElementById('resourcesAssign').addEventListener('click', enterResourceAssignMode);
|
||||||
|
|
@ -32,14 +32,13 @@ function editResources() {
|
||||||
body.addEventListener('click', function (ev) {
|
body.addEventListener('click', function (ev) {
|
||||||
const el = ev.target,
|
const el = ev.target,
|
||||||
cl = el.classList,
|
cl = el.classList,
|
||||||
line = el.parentNode,
|
line = el.parentNode;
|
||||||
i = +line.dataset.id;
|
|
||||||
const resource = Resources.get(+line.dataset.id);
|
const resource = Resources.get(+line.dataset.id);
|
||||||
if (cl.contains('resourceCategory')) return changeCategory(resource, line, el);
|
if (cl.contains('resourceCategory')) return changeCategory(resource, line, el);
|
||||||
if (cl.contains('resourceModel')) return changeModel(resource, line, el);
|
if (cl.contains('resourceModel')) return changeModel(resource, line, el);
|
||||||
if (cl.contains('resourceBonus')) return changeBonus(resource, line, el);
|
if (cl.contains('resourceBonus')) return changeBonus(resource, line, el);
|
||||||
if (cl.contains('icon-pin')) return pinResource(resource, el);
|
if (cl.contains('icon-pin')) return pinResource(resource, el);
|
||||||
if (cl.contains('icon-trash-empty')) return removeResourcePrompt(resource, line);
|
if (cl.contains('icon-trash-empty')) return removeResource(resource, line);
|
||||||
});
|
});
|
||||||
|
|
||||||
body.addEventListener('change', function (ev) {
|
body.addEventListener('change', function (ev) {
|
||||||
|
|
@ -320,9 +319,19 @@ function editResources() {
|
||||||
openPicker(resource.color, callback, {allowHatching: false});
|
openPicker(resource.color, callback, {allowHatching: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function regenerateCurrentResources() {
|
||||||
|
const message = 'Are you sure you want to regenerate resources? <br>This action cannot be reverted';
|
||||||
|
const onConfirm = () => regenerateResources();
|
||||||
|
confirmationDialog({title: 'Regenerate resources', message, confirm: 'Regenerate', onConfirm});
|
||||||
|
}
|
||||||
|
|
||||||
function resourcesRestoreDefaults() {
|
function resourcesRestoreDefaults() {
|
||||||
|
const message = 'Are you sure you want to restore default resources? <br>This action cannot be reverted';
|
||||||
|
const onConfirm = () => {
|
||||||
delete pack.resources;
|
delete pack.resources;
|
||||||
regenerateResources();
|
regenerateResources();
|
||||||
|
};
|
||||||
|
confirmationDialog({title: 'Restore default resources', message, confirm: 'Restore', onConfirm});
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleLegend() {
|
function toggleLegend() {
|
||||||
|
|
@ -417,6 +426,7 @@ function editResources() {
|
||||||
if (layerIsOn('toggleCells')) {
|
if (layerIsOn('toggleCells')) {
|
||||||
const toggler = document.getElementById('toggleCells');
|
const toggler = document.getElementById('toggleCells');
|
||||||
if (toggler.dataset.forced) toggleCells();
|
if (toggler.dataset.forced) toggleCells();
|
||||||
|
delete toggler.dataset.forced;
|
||||||
}
|
}
|
||||||
|
|
||||||
document
|
document
|
||||||
|
|
@ -479,26 +489,11 @@ function editResources() {
|
||||||
body.querySelectorAll(':scope > div > span.icon-pin').forEach((el) => el.classList.add('inactive'));
|
body.querySelectorAll(':scope > div > span.icon-pin').forEach((el) => el.classList.add('inactive'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeResourcePrompt(resource, line) {
|
function removeResource(res, line) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
||||||
alertMessage.innerHTML = 'Are you sure you want to remove the resource? <br>This action cannot be reverted';
|
const message = 'Are you sure you want to remove the resource? <br>This action cannot be reverted';
|
||||||
$('#alert').dialog({
|
const onConfirm = () => {
|
||||||
resizable: false,
|
|
||||||
title: 'Remove resource',
|
|
||||||
buttons: {
|
|
||||||
Remove: function () {
|
|
||||||
$(this).dialog('close');
|
|
||||||
removeResource(resource, line);
|
|
||||||
},
|
|
||||||
Cancel: function () {
|
|
||||||
$(this).dialog('close');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeResource(res, line) {
|
|
||||||
for (const i of pack.cells.i) {
|
for (const i of pack.cells.i) {
|
||||||
if (pack.cells.resource[i] === res.i) {
|
if (pack.cells.resource[i] === res.i) {
|
||||||
pack.cells.resource[i] = 0;
|
pack.cells.resource[i] = 0;
|
||||||
|
|
@ -510,6 +505,8 @@ function editResources() {
|
||||||
|
|
||||||
goods.selectAll('*').remove();
|
goods.selectAll('*').remove();
|
||||||
drawResources();
|
drawResources();
|
||||||
|
};
|
||||||
|
confirmationDialog({title: 'Remove resource', message, confirm: 'Remove', onConfirm});
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeResourcesEditor() {
|
function closeResourcesEditor() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue