Skip to content

Commit

Permalink
Fix crash when Star Rail is minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
kel-z committed May 28, 2023
1 parent ea07f93 commit 331f3c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def open_output_location(self):

def start_scan(self):
self.disable_start_scan_button()
self.labelLightConeCount.setText("0")
self.labelRelicCount.setText("0")
self.labelCharacterCount.setText("0")
for label in [self.labelLightConeCount, self.labelRelicCount, self.labelCharacterCount, self.labelLightConeProcessed, self.labelRelicProcessed, self.labelCharacterProcessed]:
label.setText("0")
self.textEditLog.clear()

scanner = HSRScanner(self.get_config())
Expand Down
2 changes: 1 addition & 1 deletion src/ui/hsr_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def retranslateUi(self, MainWindow):
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"><br /></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600; text-decoration: underline;\">NOTES</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; color:#ff0000;\">- Character scanning is </span><span style=\" font-size:12pt; font-weight:600; text-decoration: underline; color:#ff0000;\">not</span><span style=\" font-size:12pt; color:#ff0000;\"> implemented yet</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt; font-weight:600; color:#ff0000;\">- </span><span style=\" font-size:8pt; color:#ff0000;\">The inventory screen is translucent and accuracy can be influenced by poor text contrast. </span><span style=\" font-size:8pt; font-weight:600; color:#ff0000;\">Make sure you\'re not looking at anything bright before starting the scan.</span></p></body></html>"))
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt; font-weight:600; color:#ff0000;\">- </span><span style=\" font-size:8pt; color:#ff0000;\">The inventory screen is translucent and overall accuracy can be influenced by poor text contrast. </span><span style=\" font-size:8pt; font-weight:600; color:#ff0000;\">Make sure you\'re not looking at anything bright before starting the scan.</span></p></body></html>"))
self.label.setText(_translate("MainWindow", "Press ENTER to cancel"))
self.groupBox_5.setTitle(_translate("MainWindow", "Log"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Scan"))
Expand Down
2 changes: 1 addition & 1 deletion src/ui/hsr_scanner.ui
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-weight:600; text-decoration: underline;&quot;&gt;NOTES&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; color:#ff0000;&quot;&gt;- Character scanning is &lt;/span&gt;&lt;span style=&quot; font-size:12pt; font-weight:600; text-decoration: underline; color:#ff0000;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot; font-size:12pt; color:#ff0000;&quot;&gt; implemented yet&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; color:#ff0000;&quot;&gt;- &lt;/span&gt;&lt;span style=&quot; font-size:8pt; color:#ff0000;&quot;&gt;The inventory screen is translucent and accuracy can be influenced by poor text contrast. &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; color:#ff0000;&quot;&gt;Make sure you're not looking at anything bright before starting the scan.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; color:#ff0000;&quot;&gt;- &lt;/span&gt;&lt;span style=&quot; font-size:8pt; color:#ff0000;&quot;&gt;The inventory screen is translucent and overall accuracy can be influenced by poor text contrast. &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; color:#ff0000;&quot;&gt;Make sure you're not looking at anything bright before starting the scan.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</widget>
Expand Down
9 changes: 6 additions & 3 deletions src/utils/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ class Navigation:
def __init__(self, hwnd):
self._hwnd = hwnd
self._width, self._height = win32gui.GetClientRect(self._hwnd)[2:]
if self._width == 0 or self._height == 0:
self.bring_window_to_foreground(9)
self._width, self._height = win32gui.GetClientRect(self._hwnd)[2:]
self._left, self._top = win32gui.ClientToScreen(self._hwnd, (0, 0))

self._mouse = mouse.Controller()
self._keyboard = keyboard.Controller()

def bring_window_to_foreground(self):
win32gui.ShowWindow(self._hwnd, 5)
def bring_window_to_foreground(self, cmd_show=5):
win32gui.ShowWindow(self._hwnd, cmd_show)
win32gui.SetForegroundWindow(self._hwnd)

def move_cursor_to(self, x_percent, y_percent):
Expand Down Expand Up @@ -57,7 +60,7 @@ def get_mouse_position(self):
return x_percent, y_percent

def get_aspect_ratio(self):
x, y = win32gui.GetClientRect(self._hwnd)[2:]
x, y = self._width, self._height
gcd = self.gcd(x, y)
return f"{x // gcd}:{y // gcd}"

Expand Down

0 comments on commit 331f3c7

Please sign in to comment.