From: Raphaël Jakse Date: Sun, 22 Nov 2020 10:11:59 +0000 (+0100) Subject: some refinements on the auto counting feature X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=54d46706b01343e4c5ce5f2681a2ad6c34f68fe5;p=trivabble.git some refinements on the auto counting feature --- diff --git a/l10n/po/fr/trivabble.po b/l10n/po/fr/trivabble.po index 816cb17..571bc21 100644 --- a/l10n/po/fr/trivabble.po +++ b/l10n/po/fr/trivabble.po @@ -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 n’y 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" diff --git a/l10n/pot/trivabble.pot b/l10n/pot/trivabble.pot index 03f04fa..7b04271 100644 --- a/l10n/pot/trivabble.pot +++ b/l10n/pot/trivabble.pot @@ -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 "" diff --git a/public/alert.css b/public/alert.css index 656de45..c2e8962 100644 --- a/public/alert.css +++ b/public/alert.css @@ -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; +} diff --git a/public/alert.js b/public/alert.js index 1a85bf3..b831465 100644 --- a/public/alert.js +++ b/public/alert.js @@ -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; diff --git a/public/trivabble.js b/public/trivabble.js index a66696b..62a9d52 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -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) {