From c5dceaa7c359f878d1bec42793de0a0cae65bc0a Mon Sep 17 00:00:00 2001 From: cidoku Date: Wed, 26 Feb 2025 18:20:08 -0300 Subject: [PATCH] first implementation of delayed messages, no option to change delay yet --- gameview.py | 90 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 29 deletions(-) diff --git a/gameview.py b/gameview.py index d98e448..c19f4d0 100644 --- a/gameview.py +++ b/gameview.py @@ -757,6 +757,10 @@ class gui(QtGui.QWidget): self.sfx_delay_timer.setSingleShot(True) self.sfx_delay_timer.timeout.connect(self.play_sfx) + self.inbox_timer = QtCore.QTimer(self) + self.inbox_timer.setSingleShot(True) + self.inbox_timer.timeout.connect(self.inbox_timer_timeout) + self.modcall = None self.healthbars.connect(self.netmsg_hp) @@ -1200,6 +1204,7 @@ class gui(QtGui.QWidget): self.charside = 'def' self.lastmsg = '' self.msgqueue = [] + self.inboxqueue = [] self.selectedmsg = -1 self.evidence = [] self.privateevidence = [] @@ -2173,60 +2178,53 @@ class gui(QtGui.QWidget): if int(p_contents[CHAR_ID]) in self.muted: # skip the self.chatmessage copy line below return + + m_chatmessage = {} for n_string in range(self.chatmessage_size): if n_string < len(p_contents) and (n_string < 16 or AO2chat): - self.m_chatmessage[n_string] = p_contents[n_string] + m_chatmessage[n_string] = p_contents[n_string] else: - self.m_chatmessage[n_string] = "" + m_chatmessage[n_string] = "" - f_char_id = int(self.m_chatmessage[CHAR_ID]) + f_char_id = int(m_chatmessage[CHAR_ID]) if f_char_id < 0 or f_char_id >= len(self.charlist): return f_showname = "" - if not self.m_chatmessage[SHOWNAME]: - f_showname = self.m_chatmessage[CHARNAME] + if not m_chatmessage[SHOWNAME]: + f_showname = m_chatmessage[CHARNAME] else: - f_showname = self.m_chatmessage[SHOWNAME] - - self.text_state = 0 - self.anim_state = 0 - self.objectionview.stop() - self.char.stop() - self.chat_tick_timer.stop() - self.presentedevi.hide() - - self.chatmessage_is_empty = self.m_chatmessage[CHATMSG] == " " or self.m_chatmessage[CHATMSG] == "" + f_showname = m_chatmessage[SHOWNAME] if self.msgqueue: chatmsgcomp = (self.msgqueue[0].split('#')[5]).replace('', '$').replace('', '%').replace('', '&').replace('', '#') examine = chatmsgcomp == ">" or chatmsgcomp == "<" special = not chatmsgcomp or chatmsgcomp.isspace() - if examine or (f_char_id == self.mychar and (special or self.m_chatmessage[CHATMSG] == chatmsgcomp)): # our message showed up + if examine or (f_char_id == self.mychar and (special or m_chatmessage[CHATMSG] == chatmsgcomp)): # our message showed up del self.msgqueue[0] self.msgqueueList.takeItem(0) if self.additivebtn.isChecked(): self.icchatinput.insert(" ") - self.m_chatmessage[CHARNAME] = self.m_chatmessage[CHARNAME].decode("utf-8") - self.m_chatmessage[SHOWNAME] = self.m_chatmessage[SHOWNAME].decode('utf-8') + m_chatmessage[CHARNAME] = m_chatmessage[CHARNAME].decode("utf-8") + m_chatmessage[SHOWNAME] = m_chatmessage[SHOWNAME].decode('utf-8') - f_char = self.m_chatmessage[CHARNAME] - evidence = int(self.m_chatmessage[EVIDENCE])-1 + f_char = m_chatmessage[CHARNAME] + evidence = int(m_chatmessage[EVIDENCE])-1 t = time.localtime() logcharname = f_char - #TODO: UnicodeWarning: Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal + if f_char.lower() != self.charlist[f_char_id][0].lower(): logcharname = self.charlist[f_char_id][0] + ' (' + f_char.decode("utf-8") + ')' - chatmsg = self.m_chatmessage[CHATMSG] + chatmsg = m_chatmessage[CHATMSG] - if self.m_chatmessage[SHOWNAME] and self.m_chatmessage[SHOWNAME].lower() != f_char.lower(): + if m_chatmessage[SHOWNAME] and m_chatmessage[SHOWNAME].lower() != f_char.lower(): try: - logcharname += " ("+self.m_chatmessage[SHOWNAME]+")" + logcharname += " (" + m_chatmessage[SHOWNAME]+")" except: logcharname += " (???)" @@ -2241,18 +2239,23 @@ class gui(QtGui.QWidget): self.icLog.append('[%d:%.2d] %s: %s\n%s presented an evidence: %s' % (t[3], t[4], logcharname, chatmsg, f_char, eviname)) - self.is_additive = (self.m_chatmessage[ADDITIVE] == "1") + self.is_additive = (m_chatmessage[ADDITIVE] == "1") custom_objection = "custom" - try: objection_mod = int(self.m_chatmessage[SHOUT_MOD]) + try: objection_mod = int(m_chatmessage[SHOUT_MOD]) except: - if "4&" in self.m_chatmessage[SHOUT_MOD]: # custom objection name + if "4&" in m_chatmessage[SHOUT_MOD]: # custom objection name objection_mod = 4 - custom_objection = self.m_chatmessage[SHOUT_MOD].split("4&")[1] # get the name + custom_objection = m_chatmessage[SHOUT_MOD].split("4&")[1] # get the name else: # just in case of mindfuckery objection_mod = 0 if objection_mod <= 4 and objection_mod >= 1: + # Skip everything in the queue, show message immediately + self.inboxqueue = [] + self.inboxqueue.append(m_chatmessage) + self.m_chatmessage = m_chatmessage + objections = ["holdit", "objection", "takethat", "custom_objections/"+custom_objection if custom_objection != "custom" else "custom"] self.objectionview.play(objections[objection_mod-1], f_char.lower()) self.playObjectionSnd(f_char.lower(), objection_mod) @@ -2261,7 +2264,15 @@ class gui(QtGui.QWidget): if emote_mod == 0: self.m_chatmessage[EMOTE_MOD] = 1 else: - self.handle_chatmessage_2() + # Add message to queue and wait, unless queue empty + self.inboxqueue.append(m_chatmessage) + if len(self.inboxqueue) == 1: + self.m_chatmessage = m_chatmessage + self.handle_chatmessage_2() + + # Old behavior + #self.m_chatmessage = m_chatmessage + #self.handle_chatmessage_2() def set_text_color(self): textcolor = int(self.m_chatmessage[TEXT_COLOR]) @@ -2357,6 +2368,15 @@ class gui(QtGui.QWidget): self.zoom.setZoom(False) self.char.stop() self.effectview.stop() + + self.text_state = 0 + self.anim_state = 0 + self.objectionview.stop() + self.char.stop() + self.chat_tick_timer.stop() + self.presentedevi.hide() + + self.chatmessage_is_empty = self.m_chatmessage[CHATMSG] == " " or self.m_chatmessage[CHATMSG] == "" if not self.m_chatmessage[SHOWNAME]: self.name.setText(self.m_chatmessage[CHARNAME]) @@ -2649,6 +2669,7 @@ class gui(QtGui.QWidget): if self.chatmessage_is_empty: self.text_state = 2 + self.inbox_timer.start(1000) return self.inline_color_stack = [] @@ -2663,6 +2684,8 @@ class gui(QtGui.QWidget): self.chat_tick_timer.start(self.message_display_speed[self.current_display_speed]) self.blip = self.charlist[charid][2] + if not self.blip: + self.blip = self.m_chatmessage[BLIPS] if exists(AOpath+"sounds/general/sfx-blip"+self.blip+".wav"): self.blipsnd = audio.loadhandle(False, AOpath+"sounds/general/sfx-blip"+self.blip+".wav", 0, 0, 0) @@ -2698,6 +2721,8 @@ class gui(QtGui.QWidget): if self.anim_state != 4: self.anim_state = 3 self.char.play_idle(self.m_chatmessage[CHARNAME], self.m_chatmessage[ANIM], self.scaling[0]) + self.inbox_timer.start(1000) + else: f_character2 = f_message[self.tick_pos] f_character = QtCore.QString(f_character2) @@ -2870,6 +2895,13 @@ class gui(QtGui.QWidget): self.chat_tick_timer.start(1) else: self.chat_tick_timer.start(self.message_display_speed[self.current_display_speed]) + + def inbox_timer_timeout(self): + if len(self.inboxqueue) > 0: + del self.inboxqueue[0] + if len(self.inboxqueue) > 0: + self.m_chatmessage = self.inboxqueue[0] + self.handle_chatmessage_2() def playRealization(self): audio.playhandle(self.realizationsnd, True)