Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/core/input_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,21 @@ def handle_mouse(self, x, y):
self.last_mouse_pos = (x, y)
self.last_mouse_time = now

# Проверка "поглаживания"
# Проверка "поглаживания" (радиус и мазок мыши масштабируются от размера питомца)
pet_pos = self.window.get_cached_pos()
center_x = pet_pos.x() + self.window.width() // 2
center_y = pet_pos.y() + self.window.height() // 2
pet_w = self.window.width()
pet_h = self.window.height()
center_x = pet_pos.x() + pet_w // 2
center_y = pet_pos.y() + pet_h // 2
dx_pet = x - center_x
dy_pet = y - center_y
dist_sq_pet = dx_pet * dx_pet + dy_pet * dy_pet

# Оптимизация: сравнение квадрата расстояния (порог 60px -> 3600)
if dist_sq_pet < 3600:
# Динамический радиус поглаживания (0.6 от размера, по умолчанию 60px)
pet_radius = max(pet_w, pet_h) * 0.6
pet_radius_sq = pet_radius * pet_radius

if dist_sq_pet < pet_radius_sq:
# Исключаем пассивный фарм (требуем активное поглаживание: активное движение мыши и кулдаун)
if self.last_pet_time == 0:
self.last_pet_mouse_pos = (x, y)
Expand All @@ -421,8 +426,12 @@ def handle_mouse(self, x, y):
dy_stroke = y - self.last_pet_mouse_pos[1]
stroke_dist_sq = dx_stroke * dx_stroke + dy_stroke * dy_stroke

# Кулдаун 500мс и требование к длине мазка движения (30px -> 900)
if now - self.last_pet_time >= 0.5 and stroke_dist_sq >= 900:
# Динамический порог мазка мыши (0.3 от размера, по умолчанию 30px -> 900)
min_stroke = max(pet_w, pet_h) * 0.3
min_stroke_sq = min_stroke * min_stroke

# Кулдаун 500мс и требование к длине мазка движения
if now - self.last_pet_time >= 0.5 and stroke_dist_sq >= min_stroke_sq:
# Если активно другое форсированное состояние (например, eating), не сбиваем его
is_another_forced_active = self.forced_state_name is not None and self.forced_state_name != "playing" and now < self.forced_state_expires
if not is_another_forced_active:
Expand Down
16 changes: 13 additions & 3 deletions src/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def __init__(self, config_manager=None):
self.is_dragging = False
self.shake_count = 0
self.last_shake_time = 0
self.original_size = QSize(100, 100)
pet_size = self.config.get("pet_size") if self.config else 100
self.original_size = QSize(pet_size, pet_size)

# Начальный размер
self.resize(self.original_size)
Expand Down Expand Up @@ -91,6 +92,14 @@ def set_opacity(self, value):
"""Устанавливает прозрачность окна (0-100)"""
self.setWindowOpacity(value / 100.0)

def set_pet_size(self, size):
"""Устанавливает базовый размер питомца и обновляет окно."""
if self.config:
self.config.set("pet_size", size)
self.original_size = QSize(size, size)
self.resize(self.original_size)
self.animation_manager.update_size(self.size())

def set_always_on_top(self, enabled):
"""Включает или выключает режим 'Поверх всех окон' динамически"""
if self.config:
Expand Down Expand Up @@ -172,12 +181,13 @@ def start_hunting(self, target_x, target_y):
if self.pos_animation.state() == QPropertyAnimation.Running and self.pos_animation.endValue() == dest_point:
return

# Проверка "поимки"
# Проверка "поимки" (порог масштабируется в зависимости от размера окна)
curr_pos = self.get_cached_pos()
dx = curr_pos.x() - dest_x
dy = curr_pos.y() - dest_y
dist_sq = dx * dx + dy * dy
if dist_sq < 100: # 10 пикселей
catch_threshold_sq = (self.width() * 0.1) ** 2
if dist_sq < catch_threshold_sq:
if self.animation_manager.current_state == "hunting":
self.animation_manager.play_state("happy")
self.show_message("Поймал! 🐾")
Expand Down
16 changes: 16 additions & 0 deletions src/ui/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ def __init__(self, config, parent=None):
self.opacity_slider.valueChanged.connect(lambda v: self.opacity_val_label.setText(f"{v}%"))
layout.addWidget(self.opacity_slider)

# Размер питомца
size_header_layout = QHBoxLayout()
size_header_layout.addWidget(QLabel("Размер питомца:"))
self.size_val_label = QLabel(f"{self.config.get('pet_size')}px")
self.size_val_label.setStyleSheet("font-weight: bold; color: #555;")
size_header_layout.addStretch()
size_header_layout.addWidget(self.size_val_label)
layout.addLayout(size_header_layout)

self.size_slider = QSlider(Qt.Horizontal)
self.size_slider.setRange(50, 250)
self.size_slider.setValue(self.config.get("pet_size"))
self.size_slider.valueChanged.connect(lambda v: self.size_val_label.setText(f"{v}px"))
layout.addWidget(self.size_slider)

# Интервал растяжки
layout.addWidget(QLabel("Интервал растяжки (мин):"))
self.stretch_spin = QSpinBox()
Expand Down Expand Up @@ -168,6 +183,7 @@ def save_settings(self):
self.config.set("always_on_top", self.always_on_top_check.isChecked())
self.config.set("volume", self.volume_slider.value())
self.config.set("opacity", self.opacity_slider.value())
self.config.set("pet_size", self.size_slider.value())
self.config.set("stretch_interval", self.stretch_spin.value())
self.config.set("pomodoro_work", self.pomodoro_work_spin.value())
self.config.set("pomodoro_break", self.pomodoro_break_spin.value())
Expand Down
3 changes: 2 additions & 1 deletion src/ui/tray_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ def start_break_timer(self, checked=False):
def show_settings(self, checked=False):
dialog = SettingsDialog(self.window.config, self.window)
if dialog.exec():
# Обновляем скин и прозрачность в реальном времени
# Обновляем скин, прозрачность и размер питомца в реальном времени
self.window.animation_manager.set_skin(self.window.config.get("skin"))
self.window.set_opacity(self.window.config.get("opacity"))
self.window.set_pet_size(self.window.config.get("pet_size"))
# Обновляем меню скинов
self.update_skin_menu()
# Обновляем режим "Поверх всех окон" в реальном времени
Expand Down
3 changes: 2 additions & 1 deletion src/utils/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ConfigManager:
"volume": 70,
"language": "ru",
"skin": "default",
"opacity": 100
"opacity": 100,
"pet_size": 100
}

def __init__(self, config_path="settings.json"):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ def tearDown(self):
if os.path.exists(self.db_path):
os.remove(self.db_path)

def test_pet_size_logic(self):
os.environ["QT_QPA_PLATFORM"] = "offscreen"
from PySide6.QtWidgets import QApplication
app = QApplication.instance() or QApplication([])

config = ConfigManager(self.config_path)

# 1. Проверяем значение по умолчанию (100)
self.assertEqual(config.get("pet_size"), 100)

# 2. Перезапись и сохранение
config.set("pet_size", 150)
self.assertEqual(config.get("pet_size"), 150)

# 3. Применение размера к PetWindow
window = PetWindow(config)
self.assertEqual(window.width(), 150)
self.assertEqual(window.height(), 150)

# 4. Динамическое изменение через set_pet_size
window.set_pet_size(200)
self.assertEqual(window.width(), 200)
self.assertEqual(window.height(), 200)
self.assertEqual(config.get("pet_size"), 200)

def test_always_on_top_logic(self):
os.environ["QT_QPA_PLATFORM"] = "offscreen"
from PySide6.QtWidgets import QApplication
Expand Down
Binary file modified verification/screenshots/stats_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.