Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
Merge branch 'Fix-Toufool#110-offer-manual-override' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/Avasam/Auto-Split into github-actions
  • Loading branch information
Avasam committed Nov 30, 2021
2 parents 17ca001 + 192798a commit 9e075da
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
46 changes: 40 additions & 6 deletions res/design.ui
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@
<property name="geometry">
<rect>
<x>450</x>
<y>50</y>
<y>38</y>
<width>102</width>
<height>16</height>
</rect>
Expand Down Expand Up @@ -705,7 +705,7 @@
<property name="geometry">
<rect>
<x>200</x>
<y>50</y>
<y>38</y>
<width>82</width>
<height>16</height>
</rect>
Expand Down Expand Up @@ -759,7 +759,7 @@
<property name="geometry">
<rect>
<x>380</x>
<y>270</y>
<y>50</y>
<width>241</width>
<height>20</height>
</rect>
Expand Down Expand Up @@ -1076,10 +1076,10 @@
<widget class="QLabel" name="startImageLabel">
<property name="geometry">
<rect>
<x>120</x>
<x>440</x>
<y>270</y>
<width>241</width>
<height>16</height>
<width>181</width>
<height>20</height>
</rect>
</property>
<property name="text">
Expand Down Expand Up @@ -1112,6 +1112,38 @@
<string/>
</property>
</widget>
<widget class="QLabel" name="captureregionwindowLabel">
<property name="geometry">
<rect>
<x>120</x>
<y>50</y>
<width>241</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QCheckBox" name="forcePrintWindowCheckBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>120</x>
<y>270</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Force Full Content Rendering (slower)</string>
</property>
</widget>
<zorder>splitimagefolderLabel</zorder>
<zorder>splitimagefolderLineEdit</zorder>
<zorder>browseButton</zorder>
Expand Down Expand Up @@ -1178,6 +1210,8 @@
<zorder>startImageLabel</zorder>
<zorder>currentsimilaritythresholdLabel</zorder>
<zorder>currentsimilaritythresholdnumberLabel</zorder>
<zorder>captureregionwindowLabel</zorder>
<zorder>forcePrintWindowCheckBox</zorder>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
Expand Down
14 changes: 8 additions & 6 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,18 @@ def checkLiveImage(self):

def liveImageFunction(self):
try:
if not win32gui.GetWindowText(self.hwnd):
windowText = win32gui.GetWindowText(self.hwnd)
self.captureregionwindowLabel.setText(windowText)
if not windowText:
self.timerLiveImage.stop()
self.liveImage.clear()
if self.live_image_function_on_open:
self.live_image_function_on_open = False
else:
self.liveImage.clear()
error_messages.regionError()
return

capture = capture_region(self.hwnd, self.selection)
capture = capture_region(self.hwnd, self.selection, self.forcePrintWindowCheckBox.isChecked())
capture = cv2.resize(capture, DISPLAY_RESIZE, interpolation=cv2.INTER_NEAREST)

capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2RGB)
Expand Down Expand Up @@ -490,7 +492,7 @@ def takeScreenshot(self):
i += 1

# grab screenshot of capture region
capture = capture_region(self.hwnd, self.selection)
capture = capture_region(self.hwnd, self.selection, self.forcePrintWindowCheckBox.isChecked())
capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2BGR)

# save and open image
Expand Down Expand Up @@ -522,7 +524,7 @@ def checkFPS(self):
count = 0
t0 = time()
while count < 10:
capture = capture_region(self.hwnd, self.selection)
capture = capture_region(self.hwnd, self.selection, self.forcePrintWindowCheckBox.isChecked())
capture = cv2.resize(capture, COMPARISON_RESIZE, interpolation=cv2.INTER_NEAREST)
capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2RGB)
compareImage(self.comparisonmethodComboBox.currentIndex(), split_image, capture)
Expand Down Expand Up @@ -966,7 +968,7 @@ def guiChangesOnReset(self):

def getCaptureForComparison(self):
# grab screenshot of capture region
capture = capture_region(self.hwnd, self.selection)
capture = capture_region(self.hwnd, self.selection, self.forcePrintWindowCheckBox.isChecked())
capture = cv2.resize(capture, COMPARISON_RESIZE, interpolation=cv2.INTER_NEAREST)
# convert to BGR
return cv2.cvtColor(capture, cv2.COLOR_BGRA2BGR)
Expand Down
4 changes: 2 additions & 2 deletions src/capture_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Rect(ctypes.wintypes.RECT):
bottom: int = -1 # type: ignore


def capture_region(hwnd: int, selection: Rect):
def capture_region(hwnd: int, selection: Rect, forcePrintWindow: bool):
"""
Captures an image of the region for a window matching the given
parameters of the bounding box
Expand All @@ -42,7 +42,7 @@ def capture_region(hwnd: int, selection: Rect):

# Windows 11 has some jank, and we're not ready to fully investigate it
# for now let's ensure it works at the cost of performance
is_accelerated_window = is_windows_11 or accelerated_windows.get(hwnd)
is_accelerated_window = forcePrintWindow or is_windows_11 or accelerated_windows.get(hwnd)

# The window type is not yet known, let's find out!
if is_accelerated_window is None:
Expand Down
5 changes: 4 additions & 1 deletion src/screen_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ def alignRegion(autosplit: AutoSplit):

# Obtaining the capture of a region which contains the
# subregion being searched for to align the image.
capture = capture_windows.capture_region(autosplit.hwnd, autosplit.selection)
capture = capture_windows.capture_region(
autosplit.hwnd,
autosplit.selection,
autosplit.forcePrintWindowCheckBox.isChecked())
capture = cv2.cvtColor(capture, cv2.COLOR_BGRA2BGR)

# Obtain the best matching point for the template within the
Expand Down
25 changes: 17 additions & 8 deletions src/settings_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def haveSettingsChanged(autosplit: AutoSplit):
0,
autosplit.group_dummy_splits_undo_skip_setting,
autosplit.loop_setting,
autosplit.auto_start_on_reset_setting]
autosplit.auto_start_on_reset_setting,
autosplit.forcePrintWindowCheckBox.isChecked()]

# One small caveat in this: if you load a settings file from an old version, but dont change settings,
# the current save settings and last load settings will have different # of elements and it will ask
Expand Down Expand Up @@ -126,7 +127,8 @@ def saveSettings(autosplit: AutoSplit):
0,
autosplit.group_dummy_splits_undo_skip_setting,
autosplit.loop_setting,
autosplit.auto_start_on_reset_setting]
autosplit.auto_start_on_reset_setting,
autosplit.forcePrintWindowCheckBox.isChecked()]
# save settings to a .pkl file
with open(autosplit.last_successfully_loaded_settings_file_path, "wb") as f:
pickle.dump(autosplit.last_saved_settings, f)
Expand Down Expand Up @@ -165,7 +167,8 @@ def saveSettingsAs(autosplit: AutoSplit):
0,
autosplit.group_dummy_splits_undo_skip_setting,
autosplit.loop_setting,
autosplit.auto_start_on_reset_setting]
autosplit.auto_start_on_reset_setting,
autosplit.forcePrintWindowCheckBox.isChecked()]

# save settings to a .pkl file
with open(autosplit.save_settings_file_path, "wb") as f:
Expand Down Expand Up @@ -223,8 +226,12 @@ def loadSettings(autosplit: AutoSplit, load_settings_on_open: bool = False, load
settings.insert(9, "")
settings.insert(20, 0)
# v1.5 settings
elif settings_count != 20:
autosplit.showErrorSignal.emit(error_messages.invalidSettingsError)
if settings_count == 20:
settings.insert(21, False)
# v1.6.X settings
elif settings_count != 21:
if not load_settings_from_livesplit:
autosplit.showErrorSignal.emit(error_messages.invalidSettingsError)
return
autosplit.last_loaded_settings = [
autosplit.split_image_directory,
Expand All @@ -246,9 +253,11 @@ def loadSettings(autosplit: AutoSplit, load_settings_on_open: bool = False, load
_,
autosplit.group_dummy_splits_undo_skip_setting,
autosplit.loop_setting,
autosplit.auto_start_on_reset_setting] = settings
except (FileNotFoundError, MemoryError, pickle.UnpicklingError) as e:
print(e)
autosplit.auto_start_on_reset_setting,
forcePrintWindowCheckBox] = settings

autosplit.forcePrintWindowCheckBox.setChecked(forcePrintWindowCheckBox)
except (FileNotFoundError, MemoryError, pickle.UnpicklingError):
autosplit.showErrorSignal.emit(error_messages.invalidSettingsError)
return

Expand Down

0 comments on commit 9e075da

Please sign in to comment.