diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-29 20:05:12 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-29 20:05:12 +0200 |
commit | d5b943056f3a8fbe6b6d9a8bca5b0e94de55eff8 (patch) | |
tree | 17255a40a5f55ac33801c9f59ec3c9455bae1cd4 /test-client/visual.ts | |
parent | fd2c907274095031917e6279db436186d95d74fc (diff) | |
download | hurrycurry-d5b943056f3a8fbe6b6d9a8bca5b0e94de55eff8.tar hurrycurry-d5b943056f3a8fbe6b6d9a8bca5b0e94de55eff8.tar.bz2 hurrycurry-d5b943056f3a8fbe6b6d9a8bca5b0e94de55eff8.tar.zst |
message visuals in test-client
Diffstat (limited to 'test-client/visual.ts')
-rw-r--r-- | test-client/visual.ts | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/test-client/visual.ts b/test-client/visual.ts index 19866710..a26bab6c 100644 --- a/test-client/visual.ts +++ b/test-client/visual.ts @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { ItemData, MessageData, PlayerData, TileData, camera, camera_scale, canvas, ctx, data, demands_completed, demands_failed, get_interact_target, interact_active_anim, interact_possible_anim, interact_target_anim, items_removed, keys_down, my_id, players, points, tiles } from "./main.ts"; +import { ItemData, MessageData, PlayerData, TileData, camera, camera_scale, canvas, ctx, data, demands_completed, demands_failed, get_interact_target, global_message, interact_active_anim, interact_possible_anim, interact_target_anim, items_removed, keys_down, my_id, players, points, tiles } from "./main.ts"; import { PLAYER_SIZE } from "./movement.ts"; import { FALLBACK_TILE, ITEMS, TILES, FALLBACK_ITEM } from "./tiles.ts"; import { V2, ceil_v2, floor_v2 } from "./util.ts"; @@ -74,6 +74,8 @@ export function draw_ingame() { ctx.restore() + draw_global_message() + ctx.fillStyle = "white" ctx.textAlign = "left" ctx.textBaseline = "bottom" @@ -200,6 +202,48 @@ function draw_message(m: MessageData) { for (const c of comps) c(ctx) ctx.translate(0, 1) } + if ("text" in m.inner) { + ctx.translate(0, -1) + + ctx.textAlign = "center" + ctx.font = "15px sans-serif" + ctx.scale(2 / camera_scale, 2 / camera_scale) + const w = ctx.measureText(m.inner.text).width + 30 + + ctx.fillStyle = "#fffa" + ctx.beginPath() + ctx.roundRect(-w / 2, -15, w, 30, 5) + ctx.fill() + + ctx.fillStyle = "black" + ctx.textBaseline = "middle" + ctx.fillText(m.inner.text, 0, 0) + + ctx.translate(0, 1) + } + ctx.restore() +} + +function draw_global_message() { + if (!global_message) return + ctx.save() + ctx.translate(canvas.width / 2, canvas.height / 6) + if ("text" in global_message.inner) { + ctx.font = "20px monospace" + const lines = global_message.inner.text.split("\n") + const w = lines.reduce((a, v) => Math.max(a, ctx.measureText(v).width), 0) + 20 + + ctx.fillStyle = "#fffa" + ctx.beginPath() + ctx.roundRect(-w / 2, -20, w, lines.length * 25 + 20, 5) + ctx.fill() + + ctx.fillStyle = "black" + ctx.textAlign = "left" + ctx.textBaseline = "middle" + for (let i = 0; i < lines.length; i++) + ctx.fillText(lines[i], -w / 2 + 10, i * 25) + } ctx.restore() } |