diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-10-21 13:27:27 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-10-21 13:58:46 +0200 |
commit | ffa0c03be39f18dcc121553ae52c95764904886e (patch) | |
tree | 2e9d6587736340b175b1b97465e8cd0a0792eceb | |
parent | 3a7fcae37064b743f4c223fae9e3fc5f4bbf3dad (diff) | |
download | crusader-rex-ffa0c03be39f18dcc121553ae52c95764904886e.tar.gz |
Show battle box near battle site.
-rw-r--r-- | play.css | 6 | ||||
-rw-r--r-- | play.html | 14 | ||||
-rw-r--r-- | play.js | 74 |
3 files changed, 69 insertions, 25 deletions
@@ -296,8 +296,6 @@ body.shift .block.known:hover { #battle { background-color: tan; - left: calc(90px + max(0px, calc(50% - (1275px + 48px) / 2))); - top: 320px; } #battle_message { background-color: gainsboro; @@ -353,8 +351,8 @@ body.shift .block.known:hover { @media (min-width: 2000px) { #battle { - top: 745px; - left: calc(500px + max(0px, calc(50% - 2475px / 2))); + transform-origin: top left; + transform: rotate(90deg); } .hand { width: 2475px; @@ -32,7 +32,7 @@ <li class="resign" onclick="confirm_resign()">Resign </menu> </details> - <div class="icon_button" onclick="toggle_blocks()"><img src="/images/earth-africa-europe.svg"></div> + <button onclick="toggle_blocks()"><img src="/images/earth-africa-europe.svg"></button> </div> </header> @@ -61,8 +61,11 @@ <main data-min-zoom="1" data-max-zoom="2" data-map-width="1323" data-map-height="1323"> -<div id="battle"> -<div id="battle_header"></div> +<div id="padmap"> +<div id="map"> + +<details id="battle"> +<summary id="battle_header"></summary> <div id="ER"></div> <div id="EC"></div> <div id="EF"></div> @@ -70,10 +73,7 @@ <div id="FC"></div> <div id="FR"></div> <div id="battle_message"></div> -</div> - -<div id="padmap"> -<div id="map"> +</details> <svg id="svgmap" width="1275px" height="2475px" viewBox="0 0 1275 2475"> <path id="sea" d="M30 1201v1170l2-1c1 0 4-1 5-3 2-1 4-2 5-2 2 0 5-1 7-2 3-2 7-4 11-6 3-2 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-2s-2-2-4-3l-3-1 7-2c3 0 9-1 12-2 7-1 12-3 18-7 5-4 7-8 7-15 0-5 1-7 10-14 1-1 2-3 2-4 0-3 5-14 9-18s5-6 4-9c0-2 0-3 4-5 6-2 6-4-1-9-6-4-9-7-14-13-2-1-5-4-7-6-3-2-7-5-8-7-2-1-6-3-9-4-2-1-5-2-6-3-2-1-13-6-15-6s-11-4-11-5c-1-1-9-5-18-10-18-8-30-15-35-18-2-2-12-5-31-10-7-3-12-7-12-11 0-2 1-4 5-7 4-4 6-7 7-10l2-5 9-5c10-4 12-6 12-12s1-7 8-10c10-5 11-7 11-12-1-4-1-5 4-9 4-5 9-8 21-12 4-1 11-4 15-7 9-4 10-5 11-9 2-8 8-13 18-16 8-2 11-6 12-13v-5H30v1171z"/> @@ -1,11 +1,5 @@ "use strict" -function scroll_into_view_if_mobile(e) { - // if ("ontouchstart" in window) - if (window.innerWidth <= 800) - e.scrollIntoView({ block: "center", inline: "center", behavior: "smooth" }) -} - function set_has(set, item) { let a = 0 let b = set.length - 1 @@ -166,7 +160,7 @@ function on_blur_space_tip(x) { } function on_click_space_tip(x) { - ui.towns[x].scrollIntoView({ block:"center", inline:"center", behavior:"smooth" }) + scroll_into_view(ui.towns[x]) } function sub_space_name(match, p1, offset, string) { @@ -788,6 +782,59 @@ function insert_battle_block(root, node, block) { root.appendChild(node) } +function show_battle() { + let box = document.getElementById("battle") + let space = TOWNS[view.battle.town].layout + let rotate = false + + // reset position + box.classList.add("show") + box.style.top = null + box.style.left = null + box.style.bottom = null + box.style.right = null + box.setAttribute("open", true) + + // calculate size + let w = box.clientWidth + let h = box.clientHeight + + /* LANDSCAPE selector */ + if (window.matchMedia("(min-width: 2000px)").matches) { + let x = space.y - w / 2 + if (x < 80) + x = 80 + if (x > 2475 - w - 80) + x = 2475 - w - 80 + + //let y = space.x - h - 120 if (y < 80) y = space.x + 120 + let y = space.x + h + 120 + if (y > 1275) + y = space.x - 120 + + box.style.top = x + "px" + box.style.left = y + "px" + } else { + // place above town if possible, else below + let y = space.y - h - 120 + if (y < 80) + y = space.y + 120 + + // place centered above town if possible, clamp to edges + let x = space.x - w / 2 + console.log("XY", space.x, w, x) + if (x < 80) + x = 80 + if (x > 1275 - w - 80) + x = 1275 - w - 80 + + box.style.top = y + "px" + box.style.left = x + "px" + } + + scroll_into_view_if_mobile(box) +} + function update_battle() { function fill_cell(name, list, show) { let cell = document.getElementById(name) @@ -926,11 +973,8 @@ function on_update() { document.getElementById("battle_message").textContent = view.battle.flash if (view.flash_next) start_flash() - if (!document.getElementById("battle").classList.contains("show")) { - document.getElementById("battle").classList.add("show") - scroll_into_view_if_mobile(document.getElementById("battle")) - } update_battle() + show_battle() } else { document.getElementById("battle").classList.remove("show") } @@ -939,7 +983,9 @@ function on_update() { animate_position(ui.cards[c]) } -build_map() +window.addEventListener("resize", function (evt) { + if (view && view.battle) + setTimeout(show_battle, 1) +}) -drag_element_with_mouse("#battle", "#battle_header") -scroll_with_middle_mouse("main", 3) +build_map() |