X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=rogue_chat.html;fp=rogue_chat.html;h=8c3229cf09b1d4ba64594932a9ee08e01389701a;hb=3c917821215f505322bef3720d6e1d3669a567a6;hp=1ace4c3d40c59a68b6be65d9ed34390f6e6f02d1;hpb=2a7e3040d58b1d7dcddf64378bfd1abd8d7ded7c;p=plomrogue2 diff --git a/rogue_chat.html b/rogue_chat.html index 1ace4c3..8c3229c 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -1238,6 +1238,40 @@ let tui = { terminal.write(term_y, term_x, to_draw); } }, + draw_names: function() { + let players = []; + for (const thing_id in game.things) { + let t = game.things[thing_id]; + if (t.type_ == 'Player') { + players.push(t); + } + }; + function compare(a, b) { + if (a.name_.length > b.name_.length) { + return -1; + } else if (a.name_.length < b.name_.length) { + return 1; + } else { + return 0; + } + } + players.sort(compare); + const shrink_offset = Math.max(0, (terminal.rows - tui.left_window_width / 2) / 2); + let y = 0; + for (const player of players) { + let name = player.name_; + const offset_y = y - shrink_offset; + const max_len = Math.max(4, (tui.left_window_width / 2) - (offset_y * 2) - 8); + if (name.length > max_len) { + name = name.slice(0, max_len) + '…'; + } + terminal.write(y, 0, '@' + player.thing_char + ':' + name); + y += 1; + if (y >= terminal.rows) { + break; + } + } + }, draw_face_popup: function() { const t = game.things[this.draw_face]; if (!t || !t.face) { @@ -1407,8 +1441,11 @@ let tui = { if (this.show_help) { this.draw_help(); } - if (this.draw_face && ['chat', 'play'].includes(this.mode.name)) { - this.draw_face_popup(); + if (['chat', 'play'].includes(this.mode.name)) { + this.draw_names(); + if (this.draw_face) { + this.draw_face_popup(); + } } if (!this.draw_links) { this.links = {};