From ea2485f71d4d070cbca1d1d5193e1a28a4e00277 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Tue, 17 Nov 2020 22:50:57 +0100 Subject: [PATCH] add a selector to choice player --- l10n/po/fr/trivabble.po | 4 ++-- l10n/pot/trivabble.pot | 2 +- public/alert.js | 34 ++++++++++++++++++++++++++++++++++ public/trivabble.js | 21 ++++++++++++++------- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/l10n/po/fr/trivabble.po b/l10n/po/fr/trivabble.po index 33efba2..816cb17 100644 --- a/l10n/po/fr/trivabble.po +++ b/l10n/po/fr/trivabble.po @@ -196,8 +196,8 @@ 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 '{1}'" -msgstr "{0} points vont être ajouté au joueur '{1}'" +msgid "{0} points will be added to the following player" +msgstr "{0} points vont être ajouté au joueur" msgid "Settings" msgstr "Paramètres" diff --git a/l10n/pot/trivabble.pot b/l10n/pot/trivabble.pot index adb996f..03f04fa 100644 --- a/l10n/pot/trivabble.pot +++ b/l10n/pot/trivabble.pot @@ -196,7 +196,7 @@ msgstr "" msgid "Spell checking is based on:" msgstr "" -msgid "{0} points will be added to the following player '{1}'" +msgid "{0} points will be added to the following player" msgstr "" msgid "Settings" diff --git a/public/alert.js b/public/alert.js index b0d5995..1a85bf3 100644 --- a/public/alert.js +++ b/public/alert.js @@ -12,6 +12,7 @@ let divAlertCallbackYes; let divAlertCallbackNo; let alertInput; + let alertSelect; let divAlertContent; const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) { @@ -85,6 +86,13 @@ divAlertInput.appendChild(alertInput); + alertSelect = document.createElement("select"); + alertSelect.onchange = function () { + alertInput.value = alertSelect.value; + }; + + divAlertInput.appendChild(alertSelect); + divAlertInput.appendChild(document.createElement("div")); divAlertInput.lastChild.className = "alert-prompt-buttons"; divAlertInput.lastChild.appendChild(document.createElement("button")); @@ -152,8 +160,10 @@ divAlertContent.textContent = msg; divAlertInput.style.display = ""; + alertInput.style.display = ""; alertInput.value = defaultText || ""; alertInput.type = (options && options.type) || "text"; + alertSelect.style.display = "none"; divAlertConfirm.style.display = "none"; divAlertButton.style.display = "none"; divAlertCallback = callback; @@ -180,4 +190,28 @@ divAlert.style.display = ""; divAlertConfirm.getElementsByTagName("button")[0].focus(); }; + + global.myChoice = function (msg, options, callback, defaultValue) { + if (!divAlert) { + prepare(); + } + + divAlert.classList.remove("prompt"); + + alertSelect.options.length = 0; + for (let i = 0; i < options.length; i++) { + alertSelect.options[i] = new Option(options[i], options[i]); + } + alertSelect.value = defaultValue; + + divAlertContent.textContent = msg; + divAlertInput.style.display = ""; + alertInput.style.display = "none"; + alertSelect.style.display = ""; + divAlertConfirm.style.display = "none"; + divAlertButton.style.display = "none"; + divAlertCallback = callback; + divAlert.style.display = ""; + divAlertConfirm.getElementsByTagName("button")[0].focus(); + }; }(this)); diff --git a/public/trivabble.js b/public/trivabble.js index b2b9f5b..5409941 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -22,7 +22,7 @@ * @source: https://gitlab.com/raphj/trivabble/ */ -/*global libD, myConfirm, myAlert, myPrompt*/ +/*global libD, myConfirm, myAlert, myPrompt, myChoice*/ (function () { "use strict"; @@ -1878,20 +1878,27 @@ } /* Confirm score */ - if (currentPlayer === "") { - setCurrentPlayer( getSetting("PlayerName")); + if ((currentPlayer === "") || (currentPlayer === null)) { + setCurrentPlayer(getSetting("PlayerName")); } - myConfirm( + myChoice( format(_("{0} points will be added to the following player '{1}'"), totalScore, currentPlayer), - function () { + Object.getOwnPropertyNames(tablePlayers), + function (name) { + if (currentPlayer === "") { + return; + } + if (currentPlayer !== name) { + setCurrentPlayer(name); + } const scoreCell = tablePlayers[currentPlayer].childNodes[2].childNodes[0]; sendCmds([{ cmd: "score", player: currentPlayer, score: parseInt(scoreCell.textContent) + totalScore }]); - } - ); + }, + currentPlayer); } function triggerFlashLight(cell) { -- 2.30.2