-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.py
113 lines (88 loc) · 4.2 KB
/
intro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# intro.py
from utilities import load_text
from PySide6.QtWidgets import QLabel, QWidget
from PySide6.QtGui import QFont, QPalette, QColor
from PySide6.QtCore import QTimer, Qt, Signal
class IntroAnimation(QWidget):
animationComplete = Signal()
def __init__(self, parent=None):
super(IntroAnimation, self).__init__(parent)
self.init_ui()
self.title_timer = QTimer(self)
self.intro_timer = QTimer(self)
# Connect signals to slots
self.title_timer.timeout.connect(self.show_intro_text)
self.intro_timer.timeout.connect(self.scroll_text)
# Start the title display
self.title_timer.start(2000) # Adjust length of title display as necessary
# Enable mouse click event to skip the intro
self.setMouseTracking(True)
self.mousePressEvent = self.skip_intro
def init_ui(self):
# Set geometry for the widget to match the parent's size
self.setGeometry(0, 0, self.parent().width(), self.parent().height())
# Create the title label and center it
self.intro_title_label = QLabel("Welcome to Odyssey...", self)
self.intro_title_label.setFont(QFont("Courier New", 24, QFont.Bold))
self.intro_title_label.setAlignment(Qt.AlignCenter)
self.intro_title_label.setPalette(self.get_palette_for_crawl())
self.intro_title_label.setGeometry(0, (self.height() - 100) / 2, self.width(), 100)
self.intro_title_label.show()
def get_palette_for_crawl(self):
palette = QPalette()
palette.setColor(QPalette.WindowText, QColor(255, 255, 0))
return palette
def scroll_title(self):
current_y = self.intro_title_label.y()
new_y = current_y - 2
if new_y < -self.intro_title_label.height():
self.title_timer.stop()
self.intro_title_label.deleteLater()
self.animate_intro_text()
else:
self.intro_title_label.move(self.intro_title_label.x(), new_y)
def load_game_ui(self):
self.animationComplete.emit()
def animate_intro_text(self):
intro_text_data = load_text('intro_text')
intro_text = intro_text_data.get('opening_crawl', 'Default opening crawl text if not found.')
self.intro_text_label = QLabel(intro_text, self)
self.intro_text_label.setFont(QFont("Courier New", 14))
self.intro_text_label.setAlignment(Qt.AlignCenter)
self.intro_text_label.setWordWrap(True)
self.intro_text_label.setPalette(self.get_palette_for_crawl())
self.intro_text_label.setGeometry(0, self.height(), self.width(), self.height()*.5)
self.intro_text_label.show()
self.create_skip_label()
self.intro_timer.start(30) # Adjust speed of scroll as necessary
def scroll_text(self):
scroll_amount = 1
new_y = self.intro_text_label.y() - scroll_amount
# Check if the new_y position is less than the negative height of the label
if new_y < -self.intro_text_label.height():
self.intro_timer.stop()
self.intro_text_label.deleteLater()
self.load_game_ui()
else:
self.intro_text_label.move(self.intro_text_label.x(), new_y)
def start_intro_crawl(self):
self.intro_title_label.deleteLater()
self.animate_intro_text()
def show_intro_text(self):
# This function replaces the title with the scrolling intro text
self.title_timer.stop()
self.intro_title_label.deleteLater()
self.animate_intro_text()
def skip_intro(self, event):
self.intro_timer.stop()
if hasattr(self, 'intro_text_label') and self.intro_text_label.isVisible():
self.intro_text_label.deleteLater()
self.animationComplete.emit()
def create_skip_label(self):
self.skip_label = QLabel("Click to Skip", self)
self.skip_label.setFont(QFont("Arial", 10, QFont.Bold))
self.skip_label.setStyleSheet("color: rgba(255, 255, 255, 150);")
self.skip_label.setAlignment(Qt.AlignRight | Qt.AlignBottom)
self.skip_label.setGeometry(self.width() - 120, self.height() - 30, 110, 20)
self.skip_label.show()
self.skip_label.raise_()