From cfee08934f860e646fb69fae8191dfeb1048399b Mon Sep 17 00:00:00 2001 From: Helder Silva Lopes Moraes Date: Thu, 27 Oct 2022 20:31:38 -0300 Subject: [PATCH] adding a way to manage stante relations in batch --- index.css | 7 +++++ index.html | 21 ++++++++++++++ modules/ui/diplomacy-editor.js | 53 ++++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/index.css b/index.css index 1cb69877..00e72ddc 100644 --- a/index.css +++ b/index.css @@ -2346,3 +2346,10 @@ svg.button { background: #25252a; } } +div.states > div.diploDivChk { + width: 1.5em; + display: inline-block; +} +input.diploChk { + display: block; +} diff --git a/index.html b/index.html index 946c53d1..717debf3 100644 --- a/index.html +++ b/index.html @@ -4428,6 +4428,9 @@ diff --git a/modules/ui/diplomacy-editor.js b/modules/ui/diplomacy-editor.js index 9ae32eb7..5a53b578 100644 --- a/modules/ui/diplomacy-editor.js +++ b/modules/ui/diplomacy-editor.js @@ -54,11 +54,20 @@ function editDiplomacy() { } }; + const selectOptions = Object.entries(relations) + .map( + ([relation, {color, inText, tip}]) => + `` + ) + .join(""); + diplomacyRelationSelect.innerHTML = selectOptions; + refreshDiplomacyEditor(); viewbox.style("cursor", "crosshair").on("click", selectStateOnMapClick); if (modules.editDiplomacy) return; modules.editDiplomacy = true; + modules.batchEditDiplomacy = false; $("#diplomacyEditor").dialog({ title: "Diplomacy Editor", @@ -76,6 +85,9 @@ function editDiplomacy() { document.getElementById("diplomacyShowMatrix").addEventListener("click", showRelationsMatrix); document.getElementById("diplomacyHistory").addEventListener("click", showRelationsHistory); document.getElementById("diplomacyExport").addEventListener("click", downloadDiplomacyData); + //document.getElementById("diplomacyImport").addEventListener("click", uploadDiplomacyData); + document.getElementById("diplomacyBatchEdit").addEventListener("click", toggleDiplomacyCheckbox); + document.getElementById("diplomacyBatchEditConfirm").addEventListener("click", ConfirmDiplomacyBatch); body.addEventListener("click", function (ev) { const el = ev.target; @@ -90,6 +102,9 @@ function editDiplomacy() { selectRelation(subjectId, objectId, currentRelation); return; } + + if (el.classList.contains("diploChk")) return; + if (el.classList.contains("diploDivChk")) return; // select state of clicked line body.querySelector("div.Self").classList.remove("Self"); @@ -106,11 +121,15 @@ function editDiplomacy() { function diplomacyEditorAddLines() { const states = pack.states; const selectedLine = body.querySelector("div.Self"); + const selectedId = selectedLine ? +selectedLine.dataset.id : states.find(s => s.i && !s.removed).i; const selectedName = states[selectedId].name; + const toggleState = modules.batchEditDiplomacy ? 'inline-block' : 'none'; + COArenderer.trigger("stateCOA" + selectedId, states[selectedId].coa); let lines = /* html */ `
+
${states[selectedId].fullName}
`; @@ -127,9 +146,12 @@ function editDiplomacy() { const name = state.fullName.length < 23 ? state.fullName : state.name; COArenderer.trigger("stateCOA" + state.i, state.coa); + + lines += /* html */ `
- -
${name}
+
+ +
${name}
${relation} @@ -444,6 +466,9 @@ function editDiplomacy() { downloadFile(data, name); } + function uploadDiplomacyData() { + } + function closeDiplomacyEditor() { restoreDefaultEvents(); clearMainTip(); @@ -453,4 +478,28 @@ function editDiplomacy() { else toggleStates(); debug.selectAll(".highlight").remove(); } + + function toggleDiplomacyCheckbox(){ + modules.batchEditDiplomacy = !modules.batchEditDiplomacy; + + diplomacyRelationSelect.style.display = (modules.batchEditDiplomacy?"inline-block":"none"); + diplomacyBatchEditConfirm.style.display = (modules.batchEditDiplomacy?"inline-block":"none"); + diplomacyHeader.style['grid-template-columns'] = (modules.batchEditDiplomacy?"1.5em 15em 6em":"15em 6em"); + document.querySelectorAll(".diploDivChk").forEach(el => (el.style.display = (modules.batchEditDiplomacy?"inline-block":"none"))); + document.querySelectorAll(".diploDivChk > input").forEach(el => (el.checked = false)); + } + + function ConfirmDiplomacyBatch() { + const states = pack.states; + //Apply relation changes for selected states + document.querySelectorAll(".diploDivChk > input.diploChk:checked").forEach(function(ipt){ + const objectId = +body.querySelector("div.Self").dataset.id; + const subjectId =ipt.value; + + changeRelation(subjectId, objectId, states[subjectId].diplomacy[objectId], diplomacyRelationSelect.value); + + }); + //Clear selection waiting for next batch + document.querySelectorAll(".diploDivChk").forEach(el => (el.checked = false)); + } }