diff game/js/ui.js @ 24:3f2811aebb3d 0.9.0

splash screen buttons, help button, info screen
author ark
date 2026-10-20 15:58 +0200
parents 2f555a54c332
children 75deda08db90
line wrap: on
line diff
--- a/game/js/ui.js	Tue Oct 20 12:04:42 2026 +0200
+++ b/game/js/ui.js	Tue Oct 20 15:58:17 2026 +0200
@@ -1,5 +1,5 @@
 // screen layout, top bar, tower shop, tower menu, splash and end screens,
-// drawn from the supplied icons and drawings (art.md). numbers use the
+// help popup, drawn from the supplied icons and drawings (art.md). numbers use the
 // hand-drawn digits.
 
 window.MM = window.MM || {};
@@ -34,6 +34,12 @@
         game_lost: { image: "game_lost_button", id: "retry" },
         game_won: { image: "game_won_button", id: "restart" }
     };
+    // the extra buttons of the splash screen beside the play button, placed
+    // by [art.screen] in the config
+    var SPLASH_EXTRA = [
+        { image: "wobbly_logo", id: "logo", at: "splash_logo" },
+        { image: "help_splash", id: "help", at: "splash_help" }
+    ];
 
     // digit variants from the sprite table: character -> sprite names
     var DIGITS = {};
@@ -66,7 +72,7 @@
     // width of the top bar buttons, the early start button included
     function buttonsWidth() {
         var s = cfg.sprites.next_wave;
-        return 3 * (BUTTON + 8) + BUTTON * s[0] / s[1];
+        return 4 * (BUTTON + 8) + BUTTON * s[0] / s[1];
     }
 
     // positions of everything on screen for a window of w x h css pixels.
@@ -95,18 +101,49 @@
 
     // the screen shown over the map, or null during play
     function screenName(game) {
+        if (game.help) return "help_info";
         if (game.splash) return "splash";
         if (game.result === "lost") return "game_lost";
         if (game.result) return game.lastMap() ? "game_won" : "map_won";
         return null;
     }
 
-    // the drawing of a screen centred in the window, and its button
+    // the help popup centred in the window, scaled on its own to fit 96 %
+    // of the window, at most 1. its buttons are the email address, when
+    // there is one, and the whole window, which closes the popup. they are
+    // not drawn
+    function helpRects(L) {
+        var s = cfg.sprites.help_info, e = cfg.art.screen.help_email;
+        var k = Math.min(1, 0.96 * L.w / s[0], 0.96 * L.h / s[1]);
+        var p = { x: (L.w - s[0] * k) / 2, y: (L.h - s[1] * k) / 2, w: s[0] * k, h: s[1] * k };
+        var list = [];
+        if (cfg.links.email) {
+            list.push({ id: "email", x: p.x + e[0] * k, y: p.y + e[1] * k, w: e[2] * k, h: e[3] * k });
+        }
+        list.push({ id: "close_help", x: 0, y: 0, w: L.w, h: L.h });
+        return { panel: p, buttons: list };
+    }
+
+    // the drawing of a screen centred in the window, and its buttons: the
+    // screen's own button, and on the splash screen the extra buttons. each
+    // button is {id, image, screen, x, y, w, h}
     function screenRects(name, L) {
+        if (name === "help_info") return helpRects(L);
         var k = L.screen, s = cfg.sprites[name];
         var bs = cfg.sprites[SCREENS[name].image], at = cfg.art.screen[name];
         var p = { x: (L.w - s[0] * k) / 2, y: (L.h - s[1] * k) / 2, w: s[0] * k, h: s[1] * k };
-        return { panel: p, button: { x: p.x + at[0] * k, y: p.y + at[1] * k, w: bs[0] * k, h: bs[1] * k } };
+        var list = [{ id: SCREENS[name].id, image: SCREENS[name].image, screen: name,
+                      x: p.x + at[0] * k, y: p.y + at[1] * k, w: bs[0] * k, h: bs[1] * k }];
+        if (name === "splash") {
+            // these are placed by height; the width follows the drawing
+            SPLASH_EXTRA.forEach(function (e) {
+                var es = cfg.sprites[e.image], ea = cfg.art.screen[e.at];
+                var h = ea[2] * k;
+                list.push({ id: e.id, image: e.image, screen: name,
+                            x: p.x + ea[0] * k, y: p.y + ea[1] * k, w: h * es[0] / es[1], h: h });
+            });
+        }
+        return { panel: p, buttons: list };
     }
 
     // the tower menu: a bubble above the selected tower, or below it when
@@ -135,16 +172,10 @@
     function buttons(game, L) {
         var out = [];
         var name = screenName(game);
-        if (name) {
-            var b = screenRects(name, L).button;
-            b.id = SCREENS[name].id;
-            b.screen = name;
-            out.push(b);
-            return out;
-        }
+        if (name) return screenRects(name, L).buttons;
         // top bar, right to left
         var y = L.buttonRow + (TOP - BUTTON) / 2, x = L.w - 8;
-        ["pause", "speed", "sound"].forEach(function (id) {
+        ["help", "pause", "speed", "sound"].forEach(function (id) {
             x -= BUTTON;
             out.push({ id: id, x: x, y: y, w: BUTTON, h: BUTTON });
             x -= 8;
@@ -263,7 +294,7 @@
             ctx.shadowBlur = 12;
             ctx.shadowOffsetY = 3;
         }
-        ctx.drawImage(A.img(SCREENS[b.screen].image), cx - w / 2, cy - h / 2, w, h);
+        ctx.drawImage(A.img(b.image), cx - w / 2, cy - h / 2, w, h);
         ctx.restore();
     }
 
@@ -271,6 +302,8 @@
         var cx = b.x + b.w / 2, cy = b.y + b.h / 2;
         if (b.screen) {
             screenButton(ctx, b, view);
+        } else if (b.id === "help") {
+            fit(ctx, "help_button", cx, cy, b.w, b.h);
         } else if (b.id === "pause") {
             // shows what a tap does: pause while running, play while paused
             fit(ctx, game.paused ? "play_button" : "pause_button", cx, cy, b.w, b.h);
@@ -355,7 +388,10 @@
             ctx.fillStyle = game.splash ? "rgba(246, 241, 230, 0.55)" : "rgba(40, 35, 30, 0.45)";
             ctx.fillRect(0, 0, L.w, L.h);
             var p = screenRects(screen, L).panel;
+            // the help drawing is shrunk a lot on small screens
+            ctx.imageSmoothingQuality = "high";
             ctx.drawImage(A.img(screen), p.x, p.y, p.w, p.h);
+            ctx.imageSmoothingQuality = "low";
         } else if (game.selected) {
             var bub = list[list.length - 1].bubble;
             ctx.drawImage(A.img("tower_popup"), bub.x, bub.y, bub.w, bub.h);