From d590e5f2e5107084f35aefdf40b383aa564d3d62 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 1 Oct 2021 13:57:42 +0200 Subject: 300: Always show undo button. Help muscle memory by always showing the undo button in the same place. --- ui.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 5c95765..d37adf6 100644 --- a/ui.js +++ b/ui.js @@ -267,6 +267,26 @@ function show_marker(id, class_name, show = 1, enabled = 0) { elt.className = class_name; } +function show_undo_button(sel, action, use_label = false) { + let button = document.querySelector(sel); + if (game.actions) { + button.classList.remove("hide"); + if (game.actions && action in game.actions) { + if (game.actions[action]) { + if (use_label) + button.textContent = game.actions[action]; + button.disabled = false; + } else { + button.disabled = true; + } + } else { + button.disabled = true; + } + } else { + button.classList.add("hide"); + } +} + function on_update() { document.getElementById("greek_info").textContent = greek_info(); document.getElementById("persian_info").textContent = persian_info(); @@ -285,7 +305,7 @@ function on_update() { show_action_button("#button_draw", "draw"); show_action_button("#button_next", "next"); show_action_button("#button_pass", "pass"); - show_action_button("#button_undo", "undo"); + show_undo_button("#button_undo", "undo"); if (game.actions && game.actions.destroy) document.getElementById("bridge").className = "show destroy"; -- cgit v1.2.3