From: Christian Heller Date: Tue, 10 Nov 2020 05:35:08 +0000 (+0100) Subject: Improve help system. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/cards/%7B%7Bcard_id%7D%7D/edit?a=commitdiff_plain;h=72ed6e85260b57ab7ca7cd14363a9a9eb13e6461;p=plomrogue2 Improve help system. --- diff --git a/config.json b/config.json index be3072c..cc81fab 100644 --- a/config.json +++ b/config.json @@ -6,6 +6,7 @@ "switch_to_study": "?", "switch_to_edit": "m", "flatten": "F", + "help": "h", "toggle_map_mode": "M", "hex_move_upleft": "w", "hex_move_upright": "e", diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 7ce1496..67f3c05 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -111,7 +111,6 @@ def cmd_GAME_STATE_COMPLETE(game): game.info_db = {} if game.tui.mode.name == 'post_login_wait': game.tui.switch_mode('play') - game.tui.help() if game.tui.mode.shows_info: game.tui.query_info() player = game.get_thing(game.player_id, False) @@ -198,28 +197,29 @@ class TUI: class Mode: - def __init__(self, name, has_input_prompt=False, shows_info=False, - is_intro = False): + def __init__(self, name, help_intro, has_input_prompt=False, + shows_info=False, is_intro = False): self.name = name self.has_input_prompt = has_input_prompt self.shows_info = shows_info self.is_intro = is_intro + self.help_intro = help_intro def __init__(self, host): import os import json self.host = host - self.mode_play = self.Mode('play') - self.mode_study = self.Mode('study', shows_info=True) - self.mode_edit = self.Mode('edit') - self.mode_annotate = self.Mode('annotate', has_input_prompt=True, shows_info=True) - self.mode_portal = self.Mode('portal', has_input_prompt=True, shows_info=True) - self.mode_chat = self.Mode('chat', has_input_prompt=True) - self.mode_waiting_for_server = self.Mode('waiting_for_server', is_intro=True) - self.mode_login = self.Mode('login', has_input_prompt=True, is_intro=True) - self.mode_post_login_wait = self.Mode('post_login_wait', is_intro=True) - self.mode_teleport = self.Mode('teleport', has_input_prompt=True) - self.mode_password = self.Mode('password', has_input_prompt=True) + self.mode_play = self.Mode('play', 'This mode allows you to interact with the map.') + self.mode_study = self.Mode('study', '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 (unless obscured by this help screen here, which you can disappear with any key).', shows_info=True) + self.mode_edit = self.Mode('edit', 'This mode allows you to change the map tile you currently stand on (if your terrain editing password authorizes you so). Just enter any printable ASCII character to imprint it on the ground below you.') + self.mode_annotate = self.Mode('annotate', 'This mode allows you to add/edit a comment on the tile you are currently standing on. Hit Return to leave.', has_input_prompt=True, shows_info=True) + self.mode_portal = self.Mode('portal', 'This mode imprints/edits/removes a teleportation target on the ground you are currently standing on. Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target. Hit Return to leave.', has_input_prompt=True, shows_info=True) + self.mode_chat = self.Mode('chat', 'This mode allows you to engage in chit-chat with other users. Any line you enter into the input prompt that does not start with a "/" will be sent to all users. Lines that start with a "/" are used for commands like:', has_input_prompt=True) + self.mode_waiting_for_server = self.Mode('waiting_for_server', 'Waiting for a server response.', is_intro=True) + self.mode_login = self.Mode('login', 'Pick your player name.', has_input_prompt=True, is_intro=True) + self.mode_post_login_wait = self.Mode('post_login_wait', 'Waiting for a server response.', is_intro=True) + self.mode_teleport = self.Mode('teleport', 'Follow the instructions to re-connect and log-in to another server, or enter anything else to abort.', has_input_prompt=True) + self.mode_password = self.Mode('password', 'This mode allows you to change the password that you send to authorize yourself for editing password-protected tiles. Hit return to confirm and leave.', has_input_prompt=True) self.game = Game() self.game.tui = self self.parser = Parser(self.game) @@ -256,6 +256,7 @@ class TUI: keys_conf = json.loads(f.read()) for k in keys_conf: self.keys[k] = keys_conf[k] + self.show_help = False curses.wrapper(self.loop) def flash(self): @@ -286,6 +287,8 @@ class TUI: self.explorer = YX(player.position.y, player.position.x) if self.mode.name == 'waiting_for_server': self.log_msg('@ waiting for server …') + if self.mode.name == 'edit': + self.show_help = True elif self.mode.name == 'login': if self.login_name: self.send('LOGIN ' + quote(self.login_name)) @@ -303,32 +306,6 @@ class TUI: elif self.mode.name == 'password': self.input_ = self.password - def help(self): - self.log_msg("HELP:"); - self.log_msg("chat mode commands:"); - self.log_msg(" /nick NAME - re-name yourself to NAME"); - self.log_msg(" /msg USER TEXT - send TEXT to USER"); - self.log_msg(" /help - show this help"); - self.log_msg(" /%s or /play - switch to play mode" % self.keys['switch_to_play']); - self.log_msg(" /%s or /study - switch to study mode" % self.keys['switch_to_study']); - self.log_msg("commands common to study and play mode:"); - if 'MOVE' in self.game.tasks: - self.log_msg(" %s - move" % ','.join(self.movement_keys)); - self.log_msg(" %s - switch to chat mode" % self.keys['switch_to_chat']); - self.log_msg("commands specific to play mode:"); - self.log_msg(" %s - enter terrain password" % self.keys['switch_to_password']); - if 'WRITE' in self.game.tasks: - self.log_msg(" %s - write following ASCII character" % self.keys['switch_to_edit']); - if 'FLATTEN_SURROUNDINGS' in self.game.tasks: - self.log_msg(" %s - flatten surroundings" % self.keys['flatten']); - self.log_msg(" %s - switch to study mode" % self.keys['switch_to_study']); - self.log_msg("commands specific to study mode:"); - self.log_msg(" %s - switch to play mode" % self.keys['switch_to_play']); - if 'MOVE' not in self.game.tasks: - self.log_msg(" %s - move" % ','.join(self.movement_keys)); - self.log_msg(" %s - annotate terrain" % self.keys['switch_to_annotate']); - self.log_msg(" %s - toggle terrain/control view" % self.keys['toggle_map_mode']); - def loop(self, stdscr): import time import datetime @@ -464,7 +441,10 @@ class TUI: safe_addstr(0, self.window_width, 'TURN: ' + str(self.game.turn)) def draw_mode(): - safe_addstr(1, self.window_width, 'MODE: ' + self.mode.name) + help = "hit [%s] for help" % self.keys['help'] + if self.mode.has_input_prompt: + help = "enter /help for help" + safe_addstr(1, self.window_width, 'MODE: %s – %s' % (self.mode.name, help)) def draw_map(): if not self.game.turn_complete: @@ -511,10 +491,52 @@ class TUI: term_y += 1 map_y += 1 + def draw_help(): + content = "%s mode help (hit any key to disappear)\n\n%s\n\n" % (self.mode.name, + self.mode.help_intro) + if self.mode == self.mode_play: + content += "Available actions:\n" + if 'MOVE' in self.game.tasks: + content += "[%s] – move player\n" % ','.join(self.movement_keys) + if 'FLATTEN_SURROUNDINGS' in self.game.tasks: + content += "[%s] – flatten player's surroundings\n" % self.keys['flatten'] + content += 'Other modes available from here:\n' + content += '[%s] – terrain edit mode\n' % self.keys['switch_to_edit'] + content += '[%s] – terrain password edit mode\n' % self.keys['switch_to_password'] + content += '[%s] – chat mode\n' % self.keys['switch_to_chat'] + content += '[%s] – study mode\n' % self.keys['switch_to_study'] + elif self.mode == self.mode_study: + content += 'Available actions:\n' + content += '[%s] – move question mark\n' % ','.join(self.movement_keys) + content += '[%s] – toggle view between terrain, and password protection areas\n' % self.keys['toggle_map_mode'] + content += '\n\nOther modes available from here:' + content += '[%s] – chat mode\n' % self.keys['switch_to_chat'] + content += '[%s] – play mode\n' % self.keys['switch_to_play'] + content += '[%s] – portal mode\n' % self.keys['switch_to_portal'] + content += '[%s] – annotation mode\n' % self.keys['switch_to_annotate'] + elif self.mode == self.mode_chat: + content += '/nick NAME – re-name yourself to NAME\n' + content += '/msg USER TEXT – send TEXT to USER\n' + content += '/%s or /play – switch to play mode\n' % self.keys['switch_to_play'] + content += '/%s or /study – switch to study mode\n' % self.keys['switch_to_study'] + for i in range(self.size.y): + safe_addstr(i, + self.window_width * (not self.mode.has_input_prompt), + ' '*self.window_width) + lines = [] + for line in content.split('\n'): + lines += msg_into_lines_of_width(line, self.window_width) + for i in range(len(lines)): + if i >= self.size.y: + break + safe_addstr(i, + self.window_width * (not self.mode.has_input_prompt), + lines[i]) + def draw_screen(): stdscr.clear() - recalc_input_lines() if self.mode.has_input_prompt: + recalc_input_lines() draw_input() if self.mode.shows_info: draw_info() @@ -524,6 +546,8 @@ class TUI: if not self.mode.is_intro: draw_turn() draw_map() + if self.show_help: + draw_help() curses.curs_set(False) # hide cursor curses.use_default_colors(); @@ -554,15 +578,21 @@ class TUI: self.do_refresh = True except curses.error: continue + self.show_help = False if key == 'KEY_RESIZE': reset_screen_size() elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE': self.input_ = self.input_[:-1] + elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help': + self.show_help = True + self.input_ = "" elif self.mode.has_input_prompt and key != '\n': # Return key self.input_ += key max_length = self.window_width * self.size.y - len(input_prompt) - 1 if len(self.input_) > max_length: self.input_ = self.input_[:max_length] + elif key == self.keys['help'] and self.mode != self.mode_edit: + self.show_help = True elif self.mode == self.mode_login and key == '\n': self.login_name = self.input_ self.send('LOGIN ' + quote(self.input_)) @@ -579,8 +609,6 @@ class TUI: self.switch_mode('play') elif self.input_ in {'/' + self.keys['switch_to_study'], '/study'}: self.switch_mode('study') - elif self.input_ == '/help': - self.help() elif self.input_ == '/reconnect': reconnect() elif self.input_.startswith('/nick'): diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index 81c1e13..6041871 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -21,6 +21,7 @@ move right (hex grid):
move down-left (hex grid):
move left (hex grid):
+help:
flatten surroundings:
switch to chat mode:
switch to play mode:
@@ -220,7 +221,6 @@ let server = { explorer.empty_info_db(); if (tui.mode == mode_post_login_wait) { tui.switch_mode(mode_play); - tui.log_help(); } else if (tui.mode == mode_study) { explorer.query_info(); } @@ -286,24 +286,25 @@ let unparser = { } class Mode { - constructor(name, has_input_prompt=false, shows_info=false, is_intro=false) { + constructor(name, help_intro, has_input_prompt=false, shows_info=false, is_intro=false) { this.name = name; this.has_input_prompt = has_input_prompt; this.shows_info= shows_info; this.is_intro = is_intro; + this.help_intro = help_intro; } } -let mode_waiting_for_server = new Mode('waiting_for_server', false, false, true); -let mode_login = new Mode('login', true, false, true); -let mode_post_login_wait = new Mode('waiting for game world', false, false, true); -let mode_chat = new Mode('chat / write messages to players', true, false); -let mode_annotate = new Mode('add message to map tile', true, true); -let mode_play = new Mode('play / move around', false, false); -let mode_study = new Mode('check map tiles for messages', false, true); -let mode_edit = new Mode('write ASCII char to map tile', false, false); -let mode_teleport = new Mode('teleport away?', true); -let mode_portal = new Mode('add portal to map tile', true, true); -let mode_password = new Mode('enter terrain password', true, false, false); +let mode_waiting_for_server = new Mode('waiting_for_server', 'Waiting for a server response.', false, false, true); +let mode_login = new Mode('login', 'Pick your player name.', true, false, true); +let mode_post_login_wait = new Mode('waiting for game world', 'Waiting for a server response.', false, false, true); +let mode_chat = new Mode('chat', 'This mode allows you to engage in chit-chat with other users. Any line you enter into the input prompt that does not start with a "/" will be sent to all users. Lines that start with a "/" are used for commands like:', true, false); +let mode_annotate = new Mode('annotate', 'This mode allows you to add/edit a comment on the tile you are currently standing on. Hit Return to leave.', true, true); +let mode_play = new Mode('play', 'This mode allows you to interact with the map.', false, false); +let mode_study = new Mode('study', '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 (unless obscured by this help screen here, which you can disappear with any key).', false, true); +let mode_edit = new Mode('edit', 'This mode allows you to change the map tile you currently stand on (if your terrain editing password authorizes you so). Just enter any printable ASCII character to imprint it on the ground below you.', false, false); +let mode_teleport = new Mode('teleport', 'Follow the instructions to re-connect and log-in to another server, or enter anything else to abort.', true); +let mode_portal = new Mode('portal', 'This mode imprints/edits/removes a teleportation target on the ground you are currently standing on. Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target. Hit Return to leave.', true, true); +let mode_password = new Mode('password', 'This mode allows you to change the password that you send to authorize yourself for editing password-protected tiles. Hit return to confirm and leave.', true, false, false); let tui = { mode: mode_waiting_for_server, @@ -315,6 +316,7 @@ let tui = { height_mode_line: 1, height_input: 1, password: 'foo', + show_help: false, init: function() { this.inputEl = document.getElementById("input"); this.inputEl.focus(); @@ -328,14 +330,13 @@ 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' - }; - } else if (game.map_geometry == 'Hex') { + 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' + }; + if (game.map_geometry == 'Hex') { this.movement_keys = { [this.keys.hex_move_upleft]: 'UPLEFT', [this.keys.hex_move_upright]: 'UPRIGHT', @@ -347,6 +348,7 @@ let tui = { }; }, switch_mode: function(mode, keep_pos=false) { + this.show_help = false; this.map_mode = 'terrain'; if (mode == mode_study && !keep_pos && game.player_id in game.things) { explorer.position = game.things[game.player_id].position; @@ -359,13 +361,14 @@ let tui = { this.inputEl.value = info; this.recalc_input_lines(); } - } - if (mode == mode_login) { + } else if (mode == mode_login) { if (this.login_name) { server.send(['LOGIN', this.login_name]); } else { this.log_msg("? need login name"); } + } else if (mode == mode_edit) { + this.show_help = true; } else if (mode == mode_portal && explorer.position in game.portals) { let portal = game.portals[explorer.position] this.inputEl.value = portal; @@ -414,37 +417,6 @@ let tui = { }; this.full_refresh(); }, - log_help: function() { - let movement_keys_desc = Object.keys(this.movement_keys).join(','); - this.log_msg("HELP:"); - this.log_msg("chat mode commands:"); - this.log_msg(" /nick NAME - re-name yourself to NAME"); - this.log_msg(" /msg USER TEXT - send TEXT to USER"); - this.log_msg(" /help - show this help"); - this.log_msg(" /" + this.keys.switch_to_play + " or /play - switch to play mode"); - this.log_msg(" /" + this.keys.switch_to_study + " or /study - switch to study mode"); - this.log_msg("commands common to study and play mode:"); - if (game.tasks.includes('MOVE')) { - this.log_msg(" " + movement_keys_desc + " - move"); - } - this.log_msg(" " + this.keys.switch_to_chat + " - switch to chat mode"); - this.log_msg("commands specific to play mode:"); - this.log_msg(" " + this.keys.switch_to_password + " - enter terrain password"); - if (game.tasks.includes('WRITE')) { - this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character"); - } - if (game.tasks.includes('FLATTEN_SURROUNDINGS')) { - this.log_msg(" " + this.keys.flatten + " - flatten surroundings"); - } - this.log_msg(" " + this.keys.switch_to_study + " - switch to study mode"); - this.log_msg("commands specific to study mode:"); - this.log_msg(" " + this.keys.switch_to_play + " - switch to play mode"); - if (!game.tasks.includes('MOVE')) { - this.log_msg(" " + movement_keys_desc + " - move"); - } - this.log_msg(" " + this.keys.switch_to_annotate + " - annotate terrain"); - this.log_msg(" " + this.keys.toggle_map_mode + " - toggle terrain/control view"); - }, draw_map: function() { let map_lines_split = []; let line = []; @@ -508,7 +480,11 @@ let tui = { } }, draw_mode_line: function() { - terminal.write(0, this.window_width, 'MODE: ' + this.mode.name); + let help = 'hit [' + this.keys.help + '] for help'; + if (this.mode.has_input_prompt) { + help = 'enter /help for help'; + } + terminal.write(0, this.window_width, 'MODE: ' + this.mode.name + ' – ' + help); }, draw_turn_line: function(n) { terminal.write(1, this.window_width, 'TURN: ' + game.turn); @@ -538,6 +514,47 @@ let tui = { } } }, + draw_help: function() { + let movement_keys_desc = Object.keys(this.movement_keys).join(','); + let content = this.mode.name + " mode help (hit any key to disappear)\n\n" + this.mode.help_intro + "\n\n"; + if (this.mode == mode_play) { + content += "Available actions:\n"; + if (game.tasks.includes('MOVE')) { + content += "[" + movement_keys_desc + "] – move player\n"; + } + if (game.tasks.includes('FLATTEN_SURROUNDINGS')) { + content += "[" + tui.keys.flatten + "] – flatten player's surroundings\n"; + } + content += '\nOther modes available from here:\n'; + content += '[' + this.keys.switch_to_edit + '] – terrain edit mode\n'; + content += '[' + this.keys.switch_to_password + '] – terrain password edit mode\n'; + content += '[' + this.keys.switch_to_chat + '] – chat mode\n'; + content += '[' + this.keys.switch_to_study + '] – study mode\n'; + } else if (this.mode == mode_study) { + content += "Available actions:\n"; + content += '[' + movement_keys_desc + '] – move question mark\n'; + content += '[' + this.keys.toggle_map_mode + '] – toggle view between terrain, and password protection areas\n'; + content += '\nOther modes available from here:'; + content += '[' + this.keys.switch_to_chat + '] – chat mode\n'; + content += '[' + this.keys.switch_to_play + '] – play mode\n'; + content += '[' + this.keys.switch_to_portal + '] – portal mode\n'; + content += '[' + this.keys.switch_to_annotate + '] – annotation mode\n'; + } else if (this.mode == mode_chat) { + content += '/nick NAME – re-name yourself to NAME\n'; + content += '/msg USER TEXT – send TEXT to USER\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'; + } + let start_x = 0; + if (!this.mode.has_input_prompt) { + start_x = this.window_width + } + terminal.drawBox(0, start_x, terminal.rows, this.window_width); + let lines = this.msg_into_lines_of_width(content, this.window_width); + for (let y = 0, i = 0; y < terminal.rows && i < lines.length; y++, i++) { + terminal.write(y, start_x, lines[i]); + } + }, full_refresh: function() { terminal.drawBox(0, 0, terminal.rows, terminal.cols); if (this.mode.is_intro) { @@ -556,6 +573,9 @@ let tui = { } this.draw_input(); } + if (this.show_help) { + this.draw_help(); + } terminal.refresh(); } } @@ -716,10 +736,18 @@ tui.inputEl.addEventListener('input', (event) => { } }, false); tui.inputEl.addEventListener('keydown', (event) => { + tui.show_help = false; if (event.key == 'Enter') { event.preventDefault(); } - if (tui.mode == mode_login && event.key == 'Enter') { + if (tui.mode.has_input_prompt && event.key == 'Enter' && tui.inputEl.value == '/help') { + tui.show_help = true; + tui.empty_input(); + tui.full_refresh(); + } else if (!tui.mode.has_input_prompt && event.key == tui.keys.help) { + tui.show_help = true; + tui.full_refresh(); + } else if (tui.mode == mode_login && event.key == 'Enter') { tui.login_name = tui.inputEl.value; server.send(['LOGIN', tui.inputEl.value]); tui.empty_input(); @@ -750,8 +778,6 @@ tui.inputEl.addEventListener('keydown', (event) => { tui.switch_mode(mode_play); } else if (tokens[0].slice(1) == 'study' || tokens[0][1] == tui.keys.switch_to_study) { tui.switch_mode(mode_study); - } else if (tokens[0].slice(1) == 'help') { - tui.log_help(); } else if (tokens[0].slice(1) == 'nick') { if (tokens.length > 1) { server.send(['NICK', tokens[1]]);