color picker behavior update

This commit is contained in:
Azgaar 2021-05-05 01:36:23 +03:00 committed by Peter
parent df1ee1b5a3
commit d0500f19d6
3 changed files with 24 additions and 7 deletions

View file

@ -469,7 +469,8 @@ function clearLegend() {
} }
// draw color (fill) picker // draw color (fill) picker
function createPicker() { function createPicker(hatching) {
const COLORS_IN_ROW = 14;
const pos = () => tip("Drag to change the picker position"); const pos = () => tip("Drag to change the picker position");
const cl = () => tip("Click to close the picker"); const cl = () => tip("Click to close the picker");
const closePicker = () => container.style("display", "none"); const closePicker = () => container.style("display", "none");
@ -672,10 +673,8 @@ function updatePickerColors() {
}); });
} }
function openPicker(fill, callback) { function openPicker(fill, callback, options = {allowHatching: true}) {
const picker = d3.select("#picker"); createPicker(options.allowHatching);
if (!picker.size()) createPicker();
d3.select("#pickerContainer").style("display", "block");
if (fill[0] === "#") { if (fill[0] === "#") {
const hsl = d3.hsl(fill); const hsl = d3.hsl(fill);

View file

@ -1942,10 +1942,12 @@ function drawResources() {
let resourcesHTML = ""; let resourcesHTML = "";
for (const i of pack.cells.i) { for (const i of pack.cells.i) {
if (!pack.cells.resource[i]) continue; if (!pack.cells.resource[i]) continue;
const resource = pack.resources.find(resource => resource.i === pack.cells.resource[i]); const resource = Resources.get(pack.cells.resource[i]);
const [x, y] = pack.cells.p[i]; const [x, y] = pack.cells.p[i];
const stroke = Resources.getStroke(resource.color);
resourcesHTML += `<g> resourcesHTML += `<g>
<circle data-i="${resource.i}" cx=${x} cy=${y} r="3" fill="${resource.color}" stroke="${resource.stroke}" /> <circle data-i="${resource.i}" cx=${x} cy=${y} r="3" fill="${resource.color}" stroke="${stroke}" />
<use href="#${resource.icon}" x="${x-3}" y="${y-3}" width="6" height="6"/> <use href="#${resource.icon}" x="${x-3}" y="${y-3}" width="6" height="6"/>
</g>`; </g>`;
} }

View file

@ -451,6 +451,22 @@ function editResources() {
confirmationDialog({title: 'Restore default resources', message, confirm: 'Restore', onConfirm}); confirmationDialog({title: 'Restore default resources', message, confirm: 'Restore', onConfirm});
} }
function resourceChangeColor() {
const circle = this.querySelector("circle");
const resource = Resources.get(+this.parentNode.dataset.id);
const callback = function(fill) {
const stroke = Resources.getStroke(fill);
circle.setAttribute("fill", fill);
circle.setAttribute("stroke", stroke);
resource.color = fill;
resource.stroke = stroke;
goods.selectAll(`circle[data-i='${resource.i}']`).attr("fill", fill).attr("stroke", stroke);
}
openPicker(resource.color, callback, {allowHatching: false});
}
function toggleLegend() { function toggleLegend() {
if (legend.selectAll('*').size()) { if (legend.selectAll('*').size()) {
clearLegend(); clearLegend();