From: Christian Heller Date: Fri, 11 Dec 2020 03:37:23 +0000 (+0100) Subject: Add player faces/hats popping up n their chat messages, if in FOV. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/edit?a=commitdiff_plain;h=01b6b1da2a94fe26d1ad44348afb133edcd2a273;p=plomrogue2 Add player faces/hats popping up n their chat messages, if in FOV. --- diff --git a/plomrogue/things.py b/plomrogue/things.py index 9bf03b2..0195a62 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -94,6 +94,8 @@ class Thing(ThingBase): lowered_nick, lowered_msg)), c_id) + if listener.fov_test(self.position[0], self.position[1]): + self.game.io.send('CHATFACE %s' % self.id_) diff --git a/rogue_chat.html b/rogue_chat.html index 16a27ba..5a55f3b 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -539,6 +539,8 @@ let server = { } } else if (tokens[0] === 'CHAT') { tui.log_msg('# ' + tokens[1], 1); + } else if (tokens[0] === 'CHATFACE') { + tui.draw_face = tokens[1]; } else if (tokens[0] === 'REPLY') { tui.log_msg('#MUSICPLAYER: ' + tokens[1], 1); } else if (tokens[0] === 'PLAYER_ID') { @@ -701,6 +703,7 @@ let tui = { offset: [0,0], map_lines: [], selectables: [], + draw_face: false, init: function() { this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter", "command_thing", "take_thing", "drop_thing"] @@ -1127,6 +1130,27 @@ let tui = { terminal.write(term_y, term_x, to_draw); } }, + draw_face_popup: function() { + const t = game.things[this.draw_face]; + if (!t) { + this.draw_face = false; + return; + } + function draw_body_part(body_part, end_y) { + const start_x = tui.window_width - 10; + terminal.write(end_y - 4, start_x, '+--------+'); + terminal.write(end_y - 3, start_x, '| |'); + terminal.write(end_y - 2, start_x, '| ' + body_part.slice(0, 6) + ' |'); + terminal.write(end_y - 1, start_x, '| ' + body_part.slice(6, 12) + ' |'); + terminal.write(end_y, start_x, '| ' + body_part.slice(12, 18) + ' |'); + } + if (t.face) { + draw_body_part(t.face, terminal.rows - 1); + } + if (t.hat) { + draw_body_part(t.hat, terminal.rows - 4); + } + }, draw_mode_line: function() { let help = 'hit [' + this.keys.help + '] for help'; if (this.mode.has_input_prompt) { @@ -1264,6 +1288,9 @@ let tui = { if (this.show_help) { this.draw_help(); } + if (this.draw_face && ['chat', 'play'].includes(this.mode.name)) { + this.draw_face_popup(); + } if (!this.draw_links) { this.links = {}; } @@ -1475,6 +1502,7 @@ document.onclick = function() { }; tui.inputEl.addEventListener('keydown', (event) => { tui.show_help = false; + tui.draw_face = false; if (event.key == 'Enter') { event.preventDefault(); } diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 5046de1..7d2a3b1 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -200,6 +200,10 @@ def cmd_CHAT(game, msg): game.tui.do_refresh = True cmd_CHAT.argtypes = 'string' +def cmd_CHATFACE(game, thing_id): + game.tui.draw_face = thing_id +cmd_CHATFACE.argtypes = 'int:pos' + def cmd_PLAYER_ID(game, player_id): game.player_id = player_id cmd_PLAYER_ID.argtypes = 'int:nonneg' @@ -348,6 +352,7 @@ class Game(GameBase): self.register_command(cmd_ADMIN_OK) self.register_command(cmd_PONG) self.register_command(cmd_CHAT) + self.register_command(cmd_CHATFACE) self.register_command(cmd_REPLY) self.register_command(cmd_PLAYER_ID) self.register_command(cmd_TURN) @@ -543,6 +548,7 @@ class TUI: self.fov = '' self.flash = False self.map_lines = [] + self.draw_face = False self.offset = YX(0,0) curses.wrapper(self.loop) @@ -957,6 +963,25 @@ class TUI: term_y += 1 map_y += 1 + def draw_face_popup(): + t = self.game.get_thing(self.draw_face) + if not t: + self.draw_face = False + return + + def draw_body_part(body_part, end_y): + start_x = self.window_width - 10 + safe_addstr(end_y - 4, start_x, '+--------+') + safe_addstr(end_y - 3, start_x, '| |') + safe_addstr(end_y - 2, start_x, '| ' + body_part[0:6] + ' |') + safe_addstr(end_y - 1, start_x, '| ' + body_part[6:12] + ' |') + safe_addstr(end_y, start_x, '| ' + body_part[12:18] + ' |') + + if hasattr(t, 'face'): + draw_body_part(t.face, self.size.y - 1) + if hasattr(t, 'hat'): + draw_body_part(t.hat, self.size.y - 4) + def draw_help(): content = "%s help\n\n%s\n\n" % (self.mode.short_desc, self.mode.help_intro) @@ -1005,6 +1030,8 @@ class TUI: draw_map() if self.show_help: draw_help() + if self.draw_face and self.mode.name in {'chat', 'play'}: + draw_face_popup() def pick_selectable(task_name): try: @@ -1089,6 +1116,7 @@ class TUI: if len(key) == 1: keycode = ord(key) self.show_help = False + self.draw_face = False if key == 'KEY_RESIZE': reset_screen_size() elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE':