summaryrefslogtreecommitdiff
path: root/test-client/visual.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test-client/visual.ts')
-rw-r--r--test-client/visual.ts46
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()
}