From 1b3c3d9acf5127f0451acffc6c85f64d36473ba5 Mon Sep 17 00:00:00 2001 From: cidoku Date: Fri, 7 Mar 2025 00:55:49 -0300 Subject: [PATCH] beta timers support (only global for now) --- gameview.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 8 deletions(-) diff --git a/gameview.py b/gameview.py index 9e5a7c8..3a1120c 100644 --- a/gameview.py +++ b/gameview.py @@ -83,6 +83,7 @@ def delay(msec): def decode_ao_str(text): return text.replace("", "%").replace("", "#").replace("", "#").replace("", "&").replace("", "$") + def encode_ao_str(text): return text.replace("%", "").replace("#", "").replace("&", "").replace("$", "") @@ -739,7 +740,6 @@ class AOMovie(QtGui.QLabel): self.pillow_label.setPixmap(f_pixmap) class ZoomLines(QtGui.QLabel): - def __init__(self, parent): super(ZoomLines, self).__init__(parent) self.resize(VIEWPORT_W, VIEWPORT_H) @@ -763,9 +763,7 @@ class ZoomLines(QtGui.QLabel): self.movie.setFileName(AO2XPpath + 'themes/default/prosecution_speedlines.gif') self.movie.start() - class WTCE_View(QtGui.QLabel): - def __init__(self, parent): super(WTCE_View, self).__init__(parent) self.movie = QtGui.QMovie() @@ -974,7 +972,24 @@ class gui(QtGui.QWidget): self.screenshake = QtCore.QTimer() self.screenshake.timeout.connect(self.screenShakeTick) self.shakes_remaining = 0 + + self.onscreen_timer_labels = [] + self.onscreen_timer_times = [0, 0, 0, 0, 0] + self.onscreen_timer_paused = [True, True, True, True, True] + self.onscreen_timer = QtCore.QTimer(self) + self.onscreen_timer.timeout.connect(self.update_timers) + self.timer_tick = 1000 + for i in range(len(self.onscreen_timer_times)): + label = QtGui.QLabel(self) + label.setFont(name_font) + label.hide() + label.setText("00:00:00") + label.resize(VIEWPORT_W, label.sizeHint().height()) + label.setAlignment(QtCore.Qt.AlignCenter) + label.setStyleSheet('color: white;') + self.onscreen_timer_labels.append(label) + self.ooclog = ChatLogs(self, 1) self.ooclog.setReadOnly(True) self.ooclog.textChanged.connect(self.ooclog_update) @@ -3535,6 +3550,7 @@ class gui(QtGui.QWidget): self.tcpthread.allEvidence.connect(self.allEvidence) self.tcpthread.updatePlayerList.connect(self.updatePlayerList) self.tcpthread.rainbowColor.connect(self.text.setStyleSheet) + self.tcpthread.timerUpdate.connect(self.start_pause_timers) self.tcpthread.start() self.icchatinput.setFocus() @@ -3597,7 +3613,43 @@ class gui(QtGui.QWidget): if name: text += " %s" % name item[0].setText(text) - pass + + def start_pause_timers(self, command, timer_id, timer_ms): + if command == 0: + if not self.onscreen_timer.isActive(): + self.onscreen_timer.start(self.timer_tick) + self.onscreen_timer_times[timer_id] = timer_ms + self.onscreen_timer_paused[timer_id] = False + self.update_timers() + elif command == 1: + self.onscreen_timer_paused[timer_id] = True + elif command == 2: + # Don't show the other timers until they're implemented + if timer_id: + return + self.onscreen_timer_labels[timer_id].show() + elif command == 3: + self.onscreen_timer_labels[timer_id].hide() + + def update_timers(self): + for timer_id, label in enumerate(self.onscreen_timer_labels): + time_ms = self.onscreen_timer_times[timer_id] + if not time_ms or self.onscreen_timer_paused[timer_id]: + continue + + secs = time_ms / 1000 + mins = secs / 60 + hours = mins / 60 + label.setText("%02d:%02d:%02d" % (hours, mins % 60, secs % 60)) + + self.onscreen_timer_times[timer_id] -= self.timer_tick + if self.onscreen_timer_times[timer_id] <= 0: + label.hide() + self.onscreen_timer_times[timer_id] = 0 + self.onscreen_timer_paused[timer_id] = True + + if self.onscreen_timer_times == [0, 0, 0, 0, 0]: + self.onscreen_timer.stop() class PresentButton(QtGui.QLabel): @@ -3617,7 +3669,6 @@ class PresentButton(QtGui.QLabel): self.setPixmap(self.button_off) self.gamegui.icchat_focus() - class EditEvidenceDialog(QtGui.QDialog): def __init__(self, gamegui): super(EditEvidenceDialog, self).__init__() @@ -3796,7 +3847,6 @@ class EmoteButton(QtGui.QLabel): self.gamewindow.changeEmote(False, self.emoteid) self.clicked.emit() - class BackEmoteButton(QtGui.QLabel): def __init__(self, gamewindow, x, y): @@ -3810,7 +3860,6 @@ class BackEmoteButton(QtGui.QLabel): self.gamewindow.current_emote_page -= 1 self.gamewindow.set_emote_page() - class NextEmoteButton(QtGui.QLabel): def __init__(self, gamewindow, x, y): @@ -3824,7 +3873,6 @@ class NextEmoteButton(QtGui.QLabel): self.gamewindow.current_emote_page += 1 self.gamewindow.set_emote_page() - class TCP_Thread(QtCore.QThread): connectionError = QtCore.pyqtSignal(str, str, str) MS_Chat = QtCore.pyqtSignal(list) @@ -3837,6 +3885,7 @@ class TCP_Thread(QtCore.QThread): allEvidence = QtCore.pyqtSignal(list) rainbowColor = QtCore.pyqtSignal(str) updatePlayerList = QtCore.pyqtSignal(str, int, int, str) + timerUpdate = QtCore.pyqtSignal(int, int, int) send_attempts = 0 max_attempts = 5 @@ -4053,3 +4102,14 @@ class TCP_Thread(QtCore.QThread): self.parent.areaitems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "house.png")) except: pass + + elif header == 'TI': + del network[0] + timer_id = int(network[0]) + command = int(network[1]) + time_ms = 0 + if len(network) == 3: + time_ms = int(network[2]) + + + self.timerUpdate.emit(command, timer_id, time_ms) \ No newline at end of file