Skip to content

Commit

Permalink
Version 1.13.1 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVG207 authored Mar 26, 2024
2 parents 554cae8 + 100ea31 commit d1ef03c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion umalauncher/screenstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def screenshot_to_clipboard(self):
win32clipboard.CloseClipboard()

def check_game(self):
game_handle = util.get_window_handle("umamusume", type=util.EXACT)
game_handle = util.get_game_handle()
if game_handle:
self.game_handle = game_handle
self.game_seen = True
Expand Down
4 changes: 3 additions & 1 deletion umalauncher/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,10 @@ def save_game_position(self, pos, portrait):
if util.is_minimized(self.threader.screenstate.game_handle):
# logger.warning(f"Game minimized, cannot save {constants.ORIENTATION_DICT[portrait]}: {pos}")
return

orientation_key = constants.ORIENTATION_DICT[portrait]

if (pos[0] == -32000 and pos[1] == -32000):
if pos is not None and pos[0] == -32000 and pos[1] == -32000:
# logger.warning(f"Game minimized, cannot save {constants.ORIENTATION_DICT[portrait]}: {pos}")
return

Expand Down
10 changes: 6 additions & 4 deletions umalauncher/settings_elements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import copy
from loguru import logger

class SettingType(enum.Enum):
Expand Down Expand Up @@ -67,7 +68,7 @@ class NewSettings():

def __init__(self):
for key, value in self._settings.items():
self.__setattr__(key, value)
self.__setattr__(key, copy.deepcopy(value))

def keys(self):
return list(self._settings.keys())
Expand All @@ -77,7 +78,8 @@ def to_dict(self):
for key, value in self._settings.items():
if value.type in (SettingType.MESSAGE, SettingType.DIVIDER, SettingType.COMMANDBUTTON):
continue
ret_dict[key] = value.value
attr = getattr(self, key)
ret_dict[key] = attr.value
return ret_dict

def from_dict(self, settings_dict, keep_undefined=False):
Expand Down Expand Up @@ -116,12 +118,12 @@ def __contains__(self, key):
def __getitem__(self, key):
if not key in self._settings:
raise KeyError(f"Setting {key} not found in settings.")
return self._settings[key]
return getattr(self, key)

def __setitem__(self, key, value):
if not key in self._settings:
raise KeyError(f"Setting {key} not found in settings.")
self._settings[key].value = value
getattr(self, key).value = value

def __repr__(self):
return str(self.to_dict())
Expand Down
3 changes: 3 additions & 0 deletions umalauncher/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ def get_window_handle(query: str, type=LAZY) -> str:
win32gui.EnumWindows(type, query)
return window_handle

def get_game_handle():
return get_window_handle("umamusume", type=EXACT)


def get_position_rgb(image: Image.Image, position: tuple[float,float]) -> tuple[int,int,int]:
pixel_color = None
Expand Down
2 changes: 1 addition & 1 deletion umalauncher/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import gui
import glob

VERSION = "1.13.0"
VERSION = "1.13.1"

def parse_version(version_string: str):
"""Convert version string to tuple."""
Expand Down
35 changes: 27 additions & 8 deletions umalauncher/windowmover.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from loguru import logger
import util
import win32gui


class GameWindow():
Expand All @@ -18,23 +19,40 @@ def get_rect(self):
return None, None
return rect, rect_is_portrait(rect)

def set_pos(self, pos):
def set_pos(self, pos, is_portrait):
if pos[2] < 1 or pos[3] < 1:
logger.error(f"Trying to set window to invalid size: {pos}")
logger.error("Skipping")
logger.error("Resetting to defaults.")
self.threader.settings.save_game_position(None, is_portrait)
return False

prev_rect = util.get_window_rect(self.handle)
success = util.move_window(self.handle, pos[0], pos[1], pos[2], pos[3], True)
if not success:
logger.error(f"Could not move window. {self.handle}")

workspace = self.get_workspace_rect()
if not workspace:
if not win32gui.IsWindow(self.handle):
return False

logger.error("Could not get workspace rect after setting position.")
logger.error("Resetting to defaults.")
util.move_window(self.handle, prev_rect[0], prev_rect[1], prev_rect[2], prev_rect[3], True)
self.threader.settings.save_game_position(None, is_portrait)
return False

return success

def get_workspace_rect(self):
monitor = util.monitor_from_window(self.handle)
if not monitor:
raise Exception("Cannot determine monitor used by game window.")
# raise Exception("Cannot determine monitor used by game window.")
return None
monitor_info = util.get_monitor_info(monitor)
if not monitor_info:
raise Exception("Cannot get monitor info.")
# raise Exception("Cannot get monitor info.")
return None
return monitor_info.get("Work")

def calc_max_and_center_pos(self):
Expand Down Expand Up @@ -95,7 +113,8 @@ def calc_max_and_center_pos(self):
return new_game_pos, is_portrait

def maximize_and_center(self):
self.set_pos(self.calc_max_and_center_pos()[0])
new_game_pos, is_portrait = self.calc_max_and_center_pos()
self.set_pos(new_game_pos, is_portrait)
return


Expand Down Expand Up @@ -141,7 +160,7 @@ def try_maximize(self):
if self.window:
new_pos, is_portrait = self.window.calc_max_and_center_pos()
self.threader.settings.save_game_position(new_pos, is_portrait)
self.window.set_pos(new_pos)
self.window.set_pos(new_pos, is_portrait)
# self.threader.carrotjuicer.reset_browser = True

def stop(self):
Expand Down Expand Up @@ -187,11 +206,11 @@ def run(self):
# If None: maximize.
new_pos = self.threader.settings.load_game_position(portrait=is_portrait)
if new_pos:
self.window.set_pos(new_pos)
self.window.set_pos(new_pos, is_portrait)
else:
new_pos, is_portrait = self.window.calc_max_and_center_pos()
self.threader.settings.save_game_position(new_pos, is_portrait)
self.window.set_pos(new_pos)
self.window.set_pos(new_pos, is_portrait)

# Position may have changed: update variables.
game_rect, is_portrait = self.window.get_rect()
Expand Down

0 comments on commit d1ef03c

Please sign in to comment.