From: Christian Heller Date: Mon, 30 Nov 2020 21:42:51 +0000 (+0100) Subject: Add key control hints to web client buttons. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/cards/%7B%7Bcard_id%7D%7D/processes?a=commitdiff_plain;h=06e12644d7261a1f0a154db5f0cfb6336dca6079;p=plomrogue2 Add key control hints to web client buttons. --- diff --git a/rogue_chat.html b/rogue_chat.html index 3818254..9be1052 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -22,19 +22,19 @@ keyboard input/control:

button controls for mouse players

- - - + + + - + - + - - - + + +
move
@@ -57,14 +57,14 @@ keyboard input/control: - + @@ -127,7 +127,7 @@ let mode_helps = { 'long': 'This mode allows you to study the map and its tiles in detail. Move the question mark over a tile, and the right half of the screen will show detailed information on it. Toggle the map view to show or hide different information layers.'}, 'edit': { 'short': 'world edit', - 'long': 'This mode allows you to change the game world in various ways. Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view. You can edit a tile if you set the map edit password that matches its protection character. The character "." marks the absence of protection: Such tiles can always be edited.' + 'long': 'This mode allows you to change the game world in various ways. Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view. You can edit a tile if you set the world edit password that matches its protection character. The character "." marks the absence of protection: Such tiles can always be edited.' }, 'name_thing': { 'short': 'name thing', @@ -194,6 +194,28 @@ let mode_helps = { 'long': 'This mode allows you access to actions limited to administrators.' } } +let key_descriptions = { + 'help': 'help', + 'flatten': 'flatten surroundings', + 'teleport': 'teleport', + 'take_thing': 'pick up thing', + 'drop_thing': 'drop thing', + 'toggle_map_mode': 'toggle map view', + 'toggle_tile_draw': 'toggle protection character drawing', + 'hex_move_upleft': 'up-left', + 'hex_move_upright': 'up-right', + 'hex_move_right': 'right', + 'hex_move_left': 'left', + 'hex_move_downleft': 'down-left', + 'hex_move_downright': 'down-right', + 'square_move_right': 'right', + 'square_move_left': 'left', + 'square_move_up': 'up', + 'square_move_down': 'down', +}; +for (const mode_name of Object.keys(mode_helps)) { + key_descriptions['switch_to_' + mode_name] = mode_helps[mode_name].short; +}; let rows_selector = document.getElementById("n_rows"); let cols_selector = document.getElementById("n_cols"); @@ -216,6 +238,15 @@ for (let key_selector of key_selectors) { restore_selector_value(key_selector); } +function escapeHTML(str) { + return str. + replace(/&/g, '&'). + replace(//g, '>'). + replace(/'/g, '''). + replace(/"/g, '"'); +}; + let terminal = { foreground: 'white', background: 'black', @@ -249,14 +280,6 @@ let terminal = { }, 100); }, refresh: function() { - function escapeHTML(str) { - return str. - replace(/&/g, '&'). - replace(//g, '>'). - replace(/'/g, '''). - replace(/"/g, '"'); - }; let pre_content = ''; for (let y = 0; y < this.rows; y++) { let line = this.content[y].join(''); @@ -593,35 +616,29 @@ let tui = { for (let key_selector of key_selectors) { this.keys[key_selector.id.slice(4)] = key_selector.value; } - if (game.map_geometry == 'Square') { - this.movement_keys = { - [this.keys.square_move_up]: 'UP', - [this.keys.square_move_left]: 'LEFT', - [this.keys.square_move_down]: 'DOWN', - [this.keys.square_move_right]: 'RIGHT' - }; - document.getElementById("move_upright").hidden = true; - document.getElementById("move_upleft").hidden = true; - document.getElementById("move_downright").hidden = true; - document.getElementById("move_downleft").hidden = true; - document.getElementById("move_up").hidden = false; - document.getElementById("move_down").hidden = false; - } else if (game.map_geometry == 'Hex') { - document.getElementById("move_upright").hidden = false; - document.getElementById("move_upleft").hidden = false; - document.getElementById("move_downright").hidden = false; - document.getElementById("move_downleft").hidden = false; - document.getElementById("move_up").hidden = true; - document.getElementById("move_down").hidden = true; - this.movement_keys = { - [this.keys.hex_move_upleft]: 'UPLEFT', - [this.keys.hex_move_upright]: 'UPRIGHT', - [this.keys.hex_move_right]: 'RIGHT', - [this.keys.hex_move_downright]: 'DOWNRIGHT', - [this.keys.hex_move_downleft]: 'DOWNLEFT', - [this.keys.hex_move_left]: 'LEFT' - }; + this.movement_keys = {}; + if (!game.map_geometry) { + return; + } + let geometry_prefix = game.map_geometry.toLowerCase() + '_'; + for (const key_name of Object.keys(key_descriptions)) { + if (key_name.startsWith(geometry_prefix)) { + let direction = key_name.split('_')[2].toUpperCase(); + let key = this.keys[key_name]; + this.movement_keys[key] = direction; + } + }; + for (const move_button of document.querySelectorAll('[id*="_move_"]')) { + move_button.hidden = true; + }; + for (const move_button of document.querySelectorAll('[id^="' + geometry_prefix + 'move_"]')) { + move_button.hidden = false; }; + for (let el of document.getElementsByTagName("button")) { + let action_desc = key_descriptions[el.id]; + let action_key = '[' + this.keys[el.id] + ']'; + el.innerHTML = escapeHTML(action_desc) + '
' + escapeHTML(action_key) + ''; + } }, switch_mode: function(mode_name) { if (this.mode.name == 'control_tile_draw') { @@ -673,7 +690,7 @@ let tui = { } document.getElementById("help").disabled = false; if (this.mode.name == 'play' || this.mode.name == 'study' || this.mode.name == 'control_tile_draw' || this.mode.name == 'edit' || this.mode.name == 'admin') { - for (const move_key of document.querySelectorAll('[id^="move_"]')) { + for (const move_key of document.querySelectorAll('[id*="_move_"]')) { move_key.disabled = false; } } @@ -1036,7 +1053,7 @@ let tui = { content += '/nick NAME – re-name yourself to NAME\n'; content += '/' + this.keys.switch_to_play + ' or /play – switch to play mode\n'; content += '/' + this.keys.switch_to_study + ' or /study – switch to study mode\n'; - content += '/' + this.keys.switch_to_edit + ' or /edit – switch to map edit mode\n'; + content += '/' + this.keys.switch_to_edit + ' or /edit – switch to world edit mode\n'; content += '/' + this.keys.switch_to_admin_enter + ' or /admin – switch to admin mode\n'; } else if (this.mode.name == 'admin') { content += "Available actions:\n"; @@ -1475,12 +1492,17 @@ window.setInterval(function() { }, 5000); window.setInterval(function() { let val = "?"; + let span_decoration = "none"; if (document.activeElement == tui.inputEl) { val = "on (click outside terminal to change)"; } else { val = "off (click into terminal to change)"; + span_decoration = "line-through"; }; document.getElementById("keyboard_control").textContent = val; + for (const span of document.querySelectorAll('.keyboard_controlled')) { + span.style.textDecoration = span_decoration; + } }, 100); document.getElementById("terminal").onclick = function() { tui.inputEl.focus(); @@ -1515,60 +1537,14 @@ document.getElementById("flatten").onclick = function() { document.getElementById("teleport").onclick = function() { game.teleport(); }; -document.getElementById("move_upleft").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'UPLEFT']); - } else { - explorer.move('UPLEFT'); - }; -}; -document.getElementById("move_left").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'LEFT']); - } else { - explorer.move('LEFT'); - }; -}; -document.getElementById("move_downleft").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'DOWNLEFT']); - } else { - explorer.move('DOWNLEFT'); - }; -}; -document.getElementById("move_down").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'DOWN']); - } else { - explorer.move('DOWN'); - }; -}; -document.getElementById("move_up").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'UP']); - } else { - explorer.move('UP'); - }; -}; -document.getElementById("move_upright").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'UPRIGHT']); - } else { - explorer.move('UPRIGHT'); - }; -}; -document.getElementById("move_right").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'RIGHT']); - } else { - explorer.move('RIGHT'); - }; -}; -document.getElementById("move_downright").onclick = function() { - if (tui.mode.name == 'play' || tui.mode.name == 'edit') { - server.send(['TASK:MOVE', 'DOWNRIGHT']); - } else { - explorer.move('DOWNRIGHT'); +for (const move_button of document.querySelectorAll('[id*="_move_"]')) { + let direction = move_button.id.split('_')[2].toUpperCase(); + move_button.onclick = function() { + if (tui.mode.name == 'play' || tui.mode.name == 'edit') { + server.send(['TASK:MOVE', direction]); + } else { + explorer.move(direction); + }; }; };
- +