home · contact · privacy
Improve help system.
[plomrogue2] / rogue_chat_nocanvas_monochrome.html
index 81c1e13ab713b92575e503cea011d661d4992933..60418718fb57b9fb8a2535b85f6a46ce70c1cf8b 100644 (file)
@@ -21,6 +21,7 @@ move right (hex grid): <input id="key_hex_move_right" type="text" value="d" /><b
 move down-right (hex grid): <input id="key_hex_move_downright" type="text" value="x" /><br />
 move down-left (hex grid): <input id="key_hex_move_downleft" type="text" value="y" /><br />
 move left (hex grid): <input id="key_hex_move_left" type="text" value="a" /><br />
+help: <input id="key_help" type="text" value="h" /><br />
 flatten surroundings: <input id="key_flatten" type="text" value="F" /><br />
 switch to chat mode: <input id="key_switch_to_chat" type="text" value="t" /><br />
 switch to play mode: <input id="key_switch_to_play" type="text" value="p" /><br />
@@ -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]]);