mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
custom pictures for regiments (#1183)
* forms and ajustements * variable size for style as requested
This commit is contained in:
parent
5bb33311fb
commit
7b8ffd025f
7 changed files with 117 additions and 15 deletions
|
|
@ -960,6 +960,30 @@ function highlightElement(element, zoom) {
|
|||
}
|
||||
}
|
||||
|
||||
$('#addImage').click(function(){
|
||||
let icon = $('#imageInput').val();
|
||||
addImage(icon);
|
||||
});
|
||||
|
||||
function addImage(icon) {
|
||||
let row = "";
|
||||
let lastRowId = $('#iconTable').children('tbody').children('tr').length;
|
||||
let lastRow = $('#iconTable').children('tbody').children('tr:last-child');
|
||||
let countLastRow = lastRow.children().length;
|
||||
if(icon.includes("http")) {
|
||||
icon = '<img height="46" width="46" src="'+icon+'"/>';
|
||||
const table = byId("iconTable");
|
||||
if(countLastRow > 16) {
|
||||
row = table.insertRow(lastRowId);
|
||||
} else {
|
||||
row = table.rows[lastRowId-1];
|
||||
}
|
||||
|
||||
const cell = row.insertCell(lastRow % 17);
|
||||
cell.innerHTML = icon;
|
||||
}
|
||||
};
|
||||
|
||||
function selectIcon(initial, callback) {
|
||||
if (!callback) return;
|
||||
$("#iconSelector").dialog();
|
||||
|
|
@ -967,8 +991,11 @@ function selectIcon(initial, callback) {
|
|||
const table = byId("iconTable");
|
||||
const input = byId("iconInput");
|
||||
input.value = initial;
|
||||
|
||||
if (!table.innerHTML) {
|
||||
if(window.iconReload) {
|
||||
table.innerHTML = null;
|
||||
window.iconReload = false;
|
||||
}
|
||||
if (!table.innerHTML.includes('⚔️')) {
|
||||
const icons = [
|
||||
"⚔️",
|
||||
"🏹",
|
||||
|
|
@ -1156,26 +1183,40 @@ function selectIcon(initial, callback) {
|
|||
"🍻",
|
||||
"🍺",
|
||||
"🍲",
|
||||
"🍷"
|
||||
"🍷",
|
||||
];
|
||||
|
||||
if(window.uniquePictures) { //if a load has been load, we might get already installed pictures list
|
||||
window.uniquePictures.forEach((element) => icons.push(element));
|
||||
}
|
||||
let row = "";
|
||||
for (let i = 0; i < icons.length; i++) {
|
||||
if(icons[i].includes("http")) {
|
||||
icons[i] = '<img height="46" width="46" src="'+icons[i]+'"/>';
|
||||
}
|
||||
if (i % 17 === 0) row = table.insertRow((i / 17) | 0);
|
||||
const cell = row.insertCell(i % 17);
|
||||
cell.innerHTML = icons[i];
|
||||
}
|
||||
}
|
||||
|
||||
input.oninput = e => callback(input.value);
|
||||
|
||||
table.onclick = e => {
|
||||
if (e.target.tagName === "TD") {
|
||||
if (e.target.tagName === "TD" && e.target.textContent) {
|
||||
input.value = e.target.textContent;
|
||||
callback(input.value);
|
||||
}
|
||||
if (e.target.tagName === "IMG" && e.target.src) {
|
||||
input.value = e.target.src;
|
||||
}
|
||||
input.oninput = e => callback(input.value);
|
||||
callback(input.value || "⠀");
|
||||
};
|
||||
table.onmouseover = e => {
|
||||
if (e.target.tagName === "TD") tip(`Click to select ${e.target.textContent} icon`);
|
||||
if (e.target.tagName === "TD" && e.target.textContent) {
|
||||
tip(`Click to select ${e.target.textContent} icon`);
|
||||
}
|
||||
if (e.target.tagName === "IMG" && e.target.src) {
|
||||
tip(`Click to select ${e.target.src} icon`);
|
||||
}
|
||||
};
|
||||
|
||||
$("#iconSelector").dialog({
|
||||
|
|
|
|||
|
|
@ -45,7 +45,11 @@ function editRegiment(selector) {
|
|||
function updateRegimentData(regiment) {
|
||||
document.getElementById("regimentType").className = regiment.n ? "icon-anchor" : "icon-users";
|
||||
document.getElementById("regimentName").value = regiment.name;
|
||||
document.getElementById("regimentEmblem").value = regiment.icon;
|
||||
if(regiment.image) {
|
||||
document.getElementById("regimentEmblem").value = regiment.image;
|
||||
} else {
|
||||
document.getElementById("regimentEmblem").value = regiment.icon;
|
||||
}
|
||||
const composition = document.getElementById("regimentComposition");
|
||||
|
||||
composition.innerHTML = options.military
|
||||
|
|
@ -132,6 +136,7 @@ function editRegiment(selector) {
|
|||
const baseRect = elSelected.querySelectorAll("rect")[0];
|
||||
const iconRect = elSelected.querySelectorAll("rect")[1];
|
||||
const icon = elSelected.querySelector(".regimentIcon");
|
||||
const image = elSelected.querySelector(".regimentIcon");
|
||||
const x = reg.n ? reg.x - size * 2 : reg.x - size * 3;
|
||||
baseRect.setAttribute("x", x);
|
||||
baseRect.setAttribute("width", reg.n ? size * 4 : size * 6);
|
||||
|
|
@ -160,7 +165,13 @@ function editRegiment(selector) {
|
|||
|
||||
function changeEmblem() {
|
||||
const emblem = document.getElementById("regimentEmblem").value;
|
||||
getRegiment().icon = elSelected.querySelector(".regimentIcon").innerHTML = emblem;
|
||||
if(emblem.includes("http")) {
|
||||
elSelected.querySelector(".regimentImage").setAttribute("href", emblem);
|
||||
getRegiment().icon = elSelected.querySelector(".regimentIcon").innerHTML = "";
|
||||
} else {
|
||||
getRegiment().icon = elSelected.querySelector(".regimentIcon").innerHTML = emblem;
|
||||
elSelected.querySelector(".regimentImage").setAttribute("href", "");
|
||||
}
|
||||
}
|
||||
|
||||
function changeUnit() {
|
||||
|
|
@ -213,7 +224,7 @@ function editRegiment(selector) {
|
|||
bx: reg.bx,
|
||||
by: reg.by,
|
||||
state,
|
||||
icon: reg.icon
|
||||
icon: reg.icon,
|
||||
};
|
||||
newReg.name = Military.getName(newReg, military);
|
||||
military.push(newReg);
|
||||
|
|
@ -427,6 +438,7 @@ function editRegiment(selector) {
|
|||
const text = this.querySelector("text");
|
||||
const iconRect = this.querySelectorAll("rect")[1];
|
||||
const icon = this.querySelector(".regimentIcon");
|
||||
const image = this.querySelector(".regimentImage");
|
||||
|
||||
const self = elSelected === this;
|
||||
const baseLine = viewbox.select("g#regimentBase > line");
|
||||
|
|
@ -448,7 +460,9 @@ function editRegiment(selector) {
|
|||
iconRect.setAttribute("y", y1);
|
||||
icon.setAttribute("x", x1 - size);
|
||||
icon.setAttribute("y", y);
|
||||
if (self) {
|
||||
image.setAttribute("x", x1 - h);
|
||||
image.setAttribute("y", y1);
|
||||
if (self) {;
|
||||
baseLine.attr("x2", x).attr("y2", y);
|
||||
rotationControl
|
||||
.attr("cx", x1 + w)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue