show same value even when highlight disabled

This commit is contained in:
Adrien MALINGREY 2020-11-16 03:45:37 +01:00
parent 5836f53a24
commit cd22ded40e
4 changed files with 36 additions and 54 deletions

View File

@ -84,20 +84,6 @@
}
}
function containsDuplicates() {
foreach(array_merge($this->rows, $this->columns, $this->regions) as $area) {
$knownBoxes = array_filter($area, "isKnown");
foreach($knownBoxes as $box1) {
foreach($knownBoxes as $box2) {
if (($box1 != $box2) && ($box1->value == $box2->value)) {
return true;
}
}
}
}
return false;
}
function generate() {
// Init with a shuffle row
$values = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
@ -140,9 +126,21 @@
}
}
function containsDuplicates() {
foreach(array_merge($this->rows, $this->columns, $this->regions) as $area) {
$knownBoxes = array_filter($area, "isKnown");
foreach($knownBoxes as $box1) {
foreach($knownBoxes as $box2) {
if (($box1 != $box2) && ($box1->value == $box2->value)) {
return true;
}
}
}
}
return false;
}
function countSolutions($max=2) {
if ($this->containsDuplicates())
return 0;
$solutions = $this->solutionsGenerator(false);
$solutionsWithoutDuplicates = array();
$nbSolutions = 0;

View File

@ -112,16 +112,16 @@ input[type="number"]::-webkit-calendar-picker-indicator {
.grid input:disabled {
color: white;
background: #6666ff;
}
.grid input:disabled,
.grid input.forbidden {
cursor: not-allowed !important;
}
.grid input:disabled,
.grid input.forbidden:enabled {
background: #ffffaa;
cursor: not-allowed !important;
}
.grid input.same-value:enabled {
background: #ffff33;
cursor: not-allowed !important;
}
.grid input.forbidden:disabled {
color: #ffffaa;

View File

@ -114,9 +114,8 @@ function onclick() {
if (this.value == "" && this.candidates.size == 1) {
valueToInsert = this.candidates.values().next().value
document.getElementById("insertRadio" + valueToInsert).checked = true
this.value = valueToInsert
this.oninput()
} else if (inkPenRadio.checked) {
}
if (inkPenRadio.checked) {
if (valueToInsert) {
this.value = valueToInsert
this.oninput()
@ -216,41 +215,26 @@ function refreshUI() {
}
function highlight() {
if (valueToInsert) {
if (highlighterCheckbox.checked) {
boxes.forEach(box => {
if (box.value == valueToInsert) {
if (valueToInsert && box.value == valueToInsert) {
box.classList.add("same-value")
box.tabIndex = -1
}
else {
box.classList.remove("same-value")
if (box.candidates.has(valueToInsert) && !box.disabled) {
box.classList.remove("forbidden")
box.tabIndex = 0
} else {
box.classList.add("forbidden")
box.tabIndex = -1
}
}
})
} else {
boxes.forEach(box => {
box.classList.remove("same-value")
if (box.disabled) {
box.classList.add("forbidden")
} else {
box.classList.remove("forbidden")
}
box.tabIndex = 0
})
}
if (valueToInsert && highlighterCheckbox.checked && !box.candidates.has(valueToInsert)) {
box.classList.add("forbidden")
box.tabIndex = -1
} else {
boxes.forEach(box => {
box.classList.remove("same-value", "forbidden")
box.classList.remove("forbidden")
box.tabIndex = 0
})
}
}
}
})
highlighterCheckbox.nextElementSibling.title = "Surligner les lignes, colonnes et régions contenant déjà " + (valueToInsert? "un " + valueToInsert: "le chiffre sélectionné")
}
function onblur() {

View File

@ -97,11 +97,11 @@
</div>
<div>
<input id='highlighterCheckbox' type="checkbox" onclick='highlight()'/>
<label for='highlighterCheckbox' title='Surligner les cases interdites'><img src='img/highlighter.svg' alt='Surligneur'></label>
<label for='highlighterCheckbox' title='Surligner les lignes, colonnes et régions contenant déjà le chiffre sélectionné'><img src='img/highlighter.svg' alt='Surligneur'></label>
<input type='radio' id='inkPenRadio' name='tool' onclick='grid.style.cursor = "url(img/ink-pen.svg) 2 22, auto"' checked/>
<label for='inkPenRadio' title='Écrire au stylo'><img src='img/ink-pen.svg' alt='Stylo indélébile'/></label>
<label for='inkPenRadio' title='Écrire un chiffre'><img src='img/ink-pen.svg' alt='Stylo indélébile'/></label>
<input type='radio' id='pencilRadio' name='tool' onclick='grid.style.cursor = "url(img/pencil.svg) 2 22, auto"'/>
<label for='pencilRadio' title='Écrire au crayon'><img src='img/pencil.svg' alt='Crayon'/></label>
<label for='pencilRadio' title='Prendre des notes'><img src='img/pencil.svg' alt='Crayon'/></label>
<input type='radio' id='eraserRadio' name='tool' onclick='grid.style.cursor = "url(img/eraser.svg) 2 22, auto"'/>
<label for='eraserRadio' title='Effacer une case'><img src='img/eraser.svg' alt='Gomme'/></label>
<button type='button' class='warning' onclick='restart()' title='Recommencer'>