From e91b81396b4ee95bfd6381a8985e9771e4844bf3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Jan 2021 23:16:08 +0000 Subject: [PATCH] infopane: Pane switching machinery Signed-off-by: Ian Jackson --- templates/macros.tera | 14 ++++++++++++-- templates/script.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/templates/macros.tera b/templates/macros.tera index 71659c3f..099c7696 100644 --- a/templates/macros.tera +++ b/templates/macros.tera @@ -86,15 +86,25 @@ Hi {{nick | escape}} {% macro infopane() %}
-
+ +
Mouse select/deselect/drag
shift multiple selection
+
Show + H this help + U players +
-
+
+ + +
{% endmacro infopane %} diff --git a/templates/script.ts b/templates/script.ts index e5497ae7..75612cf4 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -124,6 +124,12 @@ var zoom_btn : HTMLInputElement; var links_elem : HTMLElement; var wresting: boolean; +type PaneName = string; +const pane_keys : { [key: string]: PaneName } = { + "H" : "help", + "U" : "players", +}; + const uo_kind_prec : { [kind: string]: number } = { 'GlobalExtra' : 50, 'Client' : 70, @@ -357,6 +363,11 @@ function some_keydown(e: KeyboardEvent) { // my tsc says this isComposing thing doesn't exist. wat. if ((e as any).isComposing /* || e.keyCode === 229 */) return; + let pane = pane_keys[e.key]; + if (pane) { + return pane_switch(pane); + } + let uo = uo_map[e.key]; if (uo === undefined || uo === null) return; @@ -381,6 +392,22 @@ function some_keydown(e: KeyboardEvent) { } } +function pane_switch(newpane: PaneName) { + let new_e; + for (;;) { + new_e = document.getElementById('pane_' + newpane)!; + let style = new_e.getAttribute('style'); + if (style || newpane == 'help') break; + newpane = 'help'; + } + for (let old_e = new_e.parentElement!.firstElementChild; + old_e; + old_e = old_e.nextElementSibling) { + old_e.setAttribute('style','display: none;'); + } + new_e.removeAttribute('style'); +} + keyops_local['left' ] = function (uo: UoRecord) { rotate_targets(uo, +1); } keyops_local['right'] = function (uo: UoRecord) { rotate_targets(uo, -1); } -- 2.30.2