From: Christian Heller Date: Sun, 27 Dec 2020 06:51:19 +0000 (+0100) Subject: Write out visible players' names in client map view. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/balance?a=commitdiff_plain;h=3c917821215f505322bef3720d6e1d3669a567a6;p=plomrogue2 Write out visible players' names in client map view. --- 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 = {}; diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 1d32772..9db7b44 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -1076,6 +1076,23 @@ class TUI: term_y += 1 map_y += 1 + def draw_names(): + players = [t for t in self.game.things if t.type_ == 'Player'] + players.sort(key=lambda t: len(t.name)) + players.reverse() + shrink_offset = max(0, (self.size.y - self.left_window_width // 2) // 2) + y = 0 + for t in players: + offset_y = y - shrink_offset + max_len = max(4, (self.left_window_width // 2) - (offset_y * 2) - 8) + name = t.name[:] + if len(name) > max_len: + name = name[:max_len] + '…' + safe_addstr(y, 0, '@%s:%s' % (t.thing_char, name)) + y += 1 + if y >= self.size.y: + break + def draw_face_popup(): t = self.game.get_thing(self.draw_face) if not t or not hasattr(t, 'face'): @@ -1148,8 +1165,10 @@ class TUI: draw_map() if self.show_help: draw_help() - if self.draw_face and self.mode.name in {'chat', 'play'}: - draw_face_popup() + if self.mode.name in {'chat', 'play'}: + draw_names() + if self.draw_face: + draw_face_popup() def pick_selectable(task_name): try: