some refinements on the auto counting feature

This commit is contained in:
Raphaël Jakse 2020-11-22 11:11:59 +01:00
parent e9a1a3aa04
commit 54d46706b0
5 changed files with 77 additions and 33 deletions

View File

@ -196,8 +196,11 @@ msgstr "La vérification orthographique nécessite que Trivabble télécharge un
msgid "Spell checking is based on:"
msgstr "La vérification orthographique est basée sur :"
msgid "{0} points will be added to the following player"
msgstr "{0} points vont être ajouté au joueur"
msgid "{0} points will be added to:"
msgstr "{0} points vont être ajoutés à:"
msgid "There are no points to add."
msgstr "Il ny a pas de point à ajouter."
msgid "Settings"
msgstr "Paramètres"
@ -236,4 +239,4 @@ msgid "Spell checking is not available for this language."
msgstr "La vérification orthographique n'est pas disponible dans cette langue."
msgid "Score new words"
msgstr "Evaluer les points des mots nouveaux"
msgstr "Compter les points"

View File

@ -196,9 +196,12 @@ msgstr ""
msgid "Spell checking is based on:"
msgstr ""
msgid "{0} points will be added to the following player"
msgid "{0} points will be added to:"
msgstr ""
msgid "There are no points to add."
msgstr: ""
msgid "Settings"
msgstr ""

View File

@ -40,8 +40,8 @@
margin-top:1em;
}
.alert-content {
padding:1ex
.alert-content-and-input {
padding:1ex;
}
.alert input[type=text], .alert input[type=number], .alert input[type=password] {
@ -81,3 +81,18 @@
border-radius:3px
}
.alert-prompt-buttons {
display: none;
}
.alert.choice .alert-prompt-buttons {
display: block;
}
.alert.choice.choice-inline .alert-content, .choice.choice-inline .alert-prompt {
display:inline-block;
}
.alert.choice.choice-inline .alert-prompt {
padding-left: 1ex;
}

View File

@ -93,14 +93,19 @@
divAlertInput.appendChild(alertSelect);
divAlertInput.appendChild(document.createElement("div"));
divAlertInput.lastChild.className = "alert-prompt-buttons";
divAlertInput.lastChild.appendChild(document.createElement("button"));
divAlertInput.lastChild.lastChild.textContent = _("OK");
divAlertInput.lastChild.lastChild.onclick = promptOK;
divAlertInput.lastChild.appendChild(document.createElement("button"));
divAlertInput.lastChild.lastChild.textContent = _("Annuler");
divAlertInput.lastChild.lastChild.onclick = promptCancel;
const divAlertContentAndInput = document.createElement("div");
divAlertContentAndInput.className = "alert-content-and-input";
divAlertContentAndInput.appendChild(divAlertContent);
divAlertContentAndInput.appendChild(divAlertInput);
const divAlerPromptButton = document.createElement("div");
divAlerPromptButton.className = "alert-prompt-buttons";
divAlerPromptButton.appendChild(document.createElement("button"));
divAlerPromptButton.lastChild.textContent = _("OK");
divAlerPromptButton.lastChild.onclick = promptOK;
divAlerPromptButton.appendChild(document.createElement("button"));
divAlerPromptButton.lastChild.textContent = _("Annuler");
divAlerPromptButton.lastChild.onclick = promptCancel;
divAlertConfirm = document.createElement("div");
divAlertConfirm.className = _("alert-confirm");
@ -119,8 +124,8 @@
const divAlertOuter = document.createElement("div");
divAlertOuter.className = "alert-outer";
divAlertOuter.appendChild(divAlertContent);
divAlertOuter.appendChild(divAlertInput);
divAlertOuter.appendChild(divAlertContentAndInput);
divAlertOuter.appendChild(divAlerPromptButton);
divAlertOuter.appendChild(divAlertConfirm);
divAlertOuter.appendChild(divAlertButton);
divAlert.appendChild(divAlertOuter);
@ -139,6 +144,8 @@
}
divAlert.classList.remove("prompt");
divAlert.classList.remove('choice');
divAlert.classList.remove('choice-inline');
divAlertContent.textContent = msg;
divAlertInput.style.display = "none";
@ -157,6 +164,8 @@
}
divAlert.classList.add("prompt");
divAlert.classList.remove('choice');
divAlert.classList.remove('choice-inline');
divAlertContent.textContent = msg;
divAlertInput.style.display = "";
@ -180,6 +189,8 @@
}
divAlert.classList.remove("prompt");
divAlert.classList.remove('choice');
divAlert.classList.remove('choice-inline');
divAlertContent.textContent = msg;
divAlertInput.style.display = "none";
@ -197,10 +208,17 @@
}
divAlert.classList.remove("prompt");
divAlert.classList.add('choice');
if (options.dispositionInline) {
divAlert.classList.add('choice-inline');
} else {
divAlert.classList.remove('choice-inline');
}
alertSelect.options.length = 0;
for (let i = 0; i < options.length; i++) {
alertSelect.options[i] = new Option(options[i], options[i]);
for (const key of options.choices) {
[].push.call(alertSelect.options, new Option(key, key));
}
alertSelect.value = defaultValue;

View File

@ -917,6 +917,10 @@
refreshCurrentPlayer();
}
function getScoreCell(playerName) {
return tablePlayers[playerName].childNodes[2].childNodes[0];
}
function setPlayers(players) {
if (participantPlaceholder) {
participantPlaceholder.parentNode.removeChild(participantPlaceholder);
@ -1028,7 +1032,7 @@
}
if (Object.prototype.hasOwnProperty.call(player, "score")) {
const scoreCell = tablePlayers[playerName].childNodes[2].childNodes[0];
const scoreCell = getScoreCell(playerName);
scoreCell.textContent = player.score;
blink(scoreCell);
}
@ -1868,33 +1872,34 @@
totalScore += wordScore * wordFactor;
}
/* Check for trivabble */
if (!totalScore) {
myAlert(_("There are no points to add."));
return;
}
/* Check for trivabble (the premium score) */
if (Object.keys(currentTilePlayed).length === 7) {
totalScore += getSetting("PREMIUM_SEVEN_TILES");
}
/* Confirm score */
if ((currentPlayer === "") || (currentPlayer === null)) {
setCurrentPlayer(getSetting("PlayerName"));
}
myChoice(
format(_("{0} points will be added to the following player '{1}'"), totalScore, currentPlayer),
Object.getOwnPropertyNames(tablePlayers),
format(_("{0} points will be added to:"), totalScore), {
choices: Object.keys(tablePlayers),
dispositionInline: true
},
function (name) {
if ((currentPlayer === "") || (currentPlayer === null)) {
if (!name) {
return;
}
if (currentPlayer !== name) {
setCurrentPlayer(name);
}
const scoreCell = tablePlayers[currentPlayer].childNodes[2].childNodes[0];
sendCmds([{
cmd: "score",
player: currentPlayer,
score: parseInt(scoreCell.textContent) + totalScore
score: parseInt(getScoreCell(name).textContent) + totalScore
}]);
},
currentPlayer);
currentPlayer || getSetting("PlayerName")
);
}
function triggerFlashLight(cell) {