mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
config generate markers dialog
This commit is contained in:
parent
60057c52ed
commit
0c0e37d69b
4 changed files with 80 additions and 3 deletions
|
|
@ -1227,7 +1227,7 @@ i.resetButton:active {
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui-dialog input[type="number"] {
|
.ui-dialog input[type="number"] {
|
||||||
width: 3.5em;
|
width: 4.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui-dialog .disabled {
|
.ui-dialog .disabled {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ window.Markers = (function () {
|
||||||
{type: "pirates", icon: "🏴☠️", multiplier: 1, fn: addPirates},
|
{type: "pirates", icon: "🏴☠️", multiplier: 1, fn: addPirates},
|
||||||
{type: "statues", icon: "🗿", multiplier: 1, fn: addStatues},
|
{type: "statues", icon: "🗿", multiplier: 1, fn: addStatues},
|
||||||
{type: "ruines", icon: "🏺", multiplier: 1, fn: addRuines},
|
{type: "ruines", icon: "🏺", multiplier: 1, fn: addRuines},
|
||||||
{type: "portals", icon: "🌀", multiplier: isFantasy, fn: addPortals}
|
{type: "portals", icon: "🌀", multiplier: +isFantasy, fn: addPortals}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ toolsContent.addEventListener("click", function (event) {
|
||||||
tip("Please exit the customization mode first", false, "warning");
|
tip("Please exit the customization mode first", false, "warning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.target.tagName !== "BUTTON") return;
|
if (!["BUTTON", "I"].includes(event.target.tagName)) return;
|
||||||
const button = event.target.id;
|
const button = event.target.id;
|
||||||
|
|
||||||
// click on open Editor buttons
|
// click on open Editor buttons
|
||||||
|
|
@ -64,6 +64,80 @@ toolsContent.addEventListener("click", function (event) {
|
||||||
|
|
||||||
// click on Configure regenerate buttons
|
// click on Configure regenerate buttons
|
||||||
if (button === "configRegenerateMarkers") {
|
if (button === "configRegenerateMarkers") {
|
||||||
|
const {markers} = pack;
|
||||||
|
const config = Markers.getConfig();
|
||||||
|
|
||||||
|
const headers = `<thead style='font-weight:bold'><tr>
|
||||||
|
<td data-tip="Marker type name">Type</td>
|
||||||
|
<td data-tip="Marker icon">Icon</td>
|
||||||
|
<td data-tip="Marker number multiplier">Multiplier</td>
|
||||||
|
<td data-tip="Number of markers of that type on the current map">Number</td>
|
||||||
|
</tr></thead>`;
|
||||||
|
const lines = config.map(({type, icon, multiplier}, index) => {
|
||||||
|
const inputId = `markerIconInput${index}`;
|
||||||
|
return `<tr>
|
||||||
|
<td><input value="${type}" /></td>
|
||||||
|
<td>
|
||||||
|
<input id="${inputId}" style="width: 5em" value="${icon}" />
|
||||||
|
<i class="icon-edit pointer" style="position: absolute; margin:.4em 0 0 -1.4em; font-size:.85em"></i>
|
||||||
|
</td>
|
||||||
|
<td><input type="number" min="0" max="100" step="0.1" value="${multiplier}" /></td>
|
||||||
|
<td style="text-align:center">${markers.filter(marker => marker.type === type).length}</td>
|
||||||
|
</tr>`;
|
||||||
|
});
|
||||||
|
const table = `<table class="table">${headers}<tbody>${lines.join("")}</tbody></table>`;
|
||||||
|
alertMessage.innerHTML = table;
|
||||||
|
|
||||||
|
alertMessage.querySelectorAll("i").forEach(selectIconButton => {
|
||||||
|
selectIconButton.addEventListener("click", function () {
|
||||||
|
const input = this.previousElementSibling;
|
||||||
|
selectIcon(input.value, icon => (input.value = icon));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const applyChanges = () => {
|
||||||
|
const rows = alertMessage.querySelectorAll("tbody > tr");
|
||||||
|
const rowsData = Array.from(rows).map(row => {
|
||||||
|
const inputs = row.querySelectorAll("input");
|
||||||
|
return {
|
||||||
|
type: inputs[0].value,
|
||||||
|
icon: inputs[1].value,
|
||||||
|
multiplier: parseFloat(inputs[2].value)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const newConfig = config.map((markerType, index) => {
|
||||||
|
const {type, icon, multiplier} = rowsData[index];
|
||||||
|
return {...markerType, type, icon, multiplier};
|
||||||
|
});
|
||||||
|
Markers.setConfig(newConfig);
|
||||||
|
|
||||||
|
Markers.regenerate();
|
||||||
|
turnButtonOn("toggleMarkers");
|
||||||
|
drawMarkers();
|
||||||
|
|
||||||
|
$("#alert").dialog("close");
|
||||||
|
};
|
||||||
|
|
||||||
|
$("#alert").dialog({
|
||||||
|
resizable: false,
|
||||||
|
title: "Markers generation settings",
|
||||||
|
position: {my: "left top", at: "left+10 top+10", of: "svg", collision: "fit"},
|
||||||
|
buttons: {
|
||||||
|
Apply: applyChanges,
|
||||||
|
Cancel: function () {
|
||||||
|
$(this).dialog("close");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
open: function () {
|
||||||
|
const buttons = $(this).dialog("widget").find(".ui-dialog-buttonset > button");
|
||||||
|
buttons[0].addEventListener("mousemove", () => tip("Apply changes and regenerate markers"));
|
||||||
|
buttons[1].addEventListener("mousemove", () => tip("Cancel changes"));
|
||||||
|
},
|
||||||
|
close: function () {
|
||||||
|
$(this).dialog("destroy");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// click on Add buttons
|
// click on Add buttons
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ function editWorld() {
|
||||||
buttons[2].addEventListener("mousemove", () => tip("Click to set map size to cover the Tropical latitudes"));
|
buttons[2].addEventListener("mousemove", () => tip("Click to set map size to cover the Tropical latitudes"));
|
||||||
buttons[3].addEventListener("mousemove", () => tip("Click to set map size to cover the Southern latitudes"));
|
buttons[3].addEventListener("mousemove", () => tip("Click to set map size to cover the Southern latitudes"));
|
||||||
buttons[4].addEventListener("mousemove", () => tip("Click to restore default wind directions"));
|
buttons[4].addEventListener("mousemove", () => tip("Click to restore default wind directions"));
|
||||||
|
},
|
||||||
|
close: function () {
|
||||||
|
$(this).dialog("destroy");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue