diff --git a/portprotonqt/main_window.py b/portprotonqt/main_window.py index e5ffb38..fc2fcbc 100644 --- a/portprotonqt/main_window.py +++ b/portprotonqt/main_window.py @@ -199,9 +199,15 @@ class MainWindow(QMainWindow): self.createPortProtonTab() # вкладка 4 self.createThemeTab() # вкладка 5 + self.controlHintsWidget = self.createControlHintsWidget() + mainLayout.addWidget(self.controlHintsWidget) + self.restore_state() self.input_manager = InputManager(self) + # Connect InputManager gamepad connection/disconnection signals + self.input_manager.button_pressed.connect(self.updateControlHints) + self.input_manager.dpad_moved.connect(self.updateControlHints) self.detail_animations = DetailPageAnimations(self, self.theme) QTimer.singleShot(0, self.loadGames) @@ -213,6 +219,98 @@ class MainWindow(QMainWindow): self.resize(width, height) else: self.showNormal() + + def createControlHintsWidget(self) -> QWidget: + from portprotonqt.localization import _ + """Creates a widget displaying control hints for gamepad and keyboard.""" + logger.debug("Creating control hints widget") + hintsWidget = QWidget() + hintsWidget.setStyleSheet(self.theme.STATUS_BAR_STYLE) + + hintsLayout = QHBoxLayout(hintsWidget) + + gamepad_hints = [ + ("button_a", _("Select")), + ("button_b", _("Back")), + ("button_x", _("Add Game")), + ("button_y", _("Previous Directory")), + ("button_lb", _("Previous Tab")), + ("button_rb", _("Next Tab")), + ("button_start", _("Context Menu")), + ("button_select", _("Toggle Fullscreen")), + ("button_guide", _("System Overlay")), + ("button_rt", _("Increase Size")), + ("button_lt", _("Decrease Size")), + ] + + keyboard_hints = [ + ("key_enter", _("Select")), + ("key_esc", _("Back")), + ("key_e", _("Add Game")), + ("key_left", _("Previous Tab")), + ("key_right", _("Next Tab")), + ("key_context", _("Context Menu")), + ("key_insert", _("System Overlay")), + ("key_f11", _("Toggle Fullscreen")), + ] + + self.hintsLabels = [] + + def makeHint(icon_name: str, action: str, visible: bool): + container = QWidget() + layout = QHBoxLayout(container) + layout.setContentsMargins(0, 0, 0, 0) + layout.setSpacing(10) + + # иконка + icon_label = QLabel() + icon_label.setFixedSize(48, 48) + icon_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + + pixmap = QPixmap() + icon_path = self.theme_manager.get_theme_image(icon_name, self.current_theme_name) + if not icon_path: + icon_path = self.theme_manager.get_theme_image("placeholder", self.current_theme_name) + + if icon_path: + pixmap.load(str(icon_path)) + + if not pixmap.isNull(): + icon_label.setPixmap(pixmap.scaled(48, 48, Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation)) + + layout.addWidget(icon_label) + + # текст + text_label = QLabel(action) + text_label.setStyleSheet(self.theme.LAST_LAUNCH_VALUE_STYLE) + text_label.setAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignLeft) + layout.addWidget(text_label) + + container.setVisible(visible) + self.hintsLabels.append((container, icon_name)) + hintsLayout.addWidget(container) + + for icon, action in gamepad_hints: + makeHint(icon, action, visible=False) + + for icon, action in keyboard_hints: + makeHint(icon, action, visible=True) + + hintsLayout.addStretch() # чтобы всё разъехалось на всю ширину + return hintsWidget + + def updateControlHints(self, *args) -> None: + """Updates control hints based on gamepad connection status.""" + is_gamepad_connected = self.input_manager.gamepad is not None + logger.debug("Updating control hints, gamepad connected: %s", is_gamepad_connected) + + for container, icon_name in self.hintsLabels: + if icon_name.startswith("button_"): # это геймпад + container.setVisible(is_gamepad_connected) + else: # это клавиатура + container.setVisible(not is_gamepad_connected) + @Slot(list) def on_games_loaded(self, games: list[tuple]): self.games = games diff --git a/portprotonqt/themes/standart/images/button_a.png b/portprotonqt/themes/standart/images/button_a.png new file mode 100644 index 0000000..e22bb29 Binary files /dev/null and b/portprotonqt/themes/standart/images/button_a.png differ diff --git a/portprotonqt/themes/standart/images/button_b.png b/portprotonqt/themes/standart/images/button_b.png new file mode 100644 index 0000000..9312c26 Binary files /dev/null and b/portprotonqt/themes/standart/images/button_b.png differ diff --git a/portprotonqt/themes/standart/images/button_lb.png b/portprotonqt/themes/standart/images/button_lb.png new file mode 100644 index 0000000..f6c414b Binary files /dev/null and b/portprotonqt/themes/standart/images/button_lb.png differ diff --git a/portprotonqt/themes/standart/images/button_lt.png b/portprotonqt/themes/standart/images/button_lt.png new file mode 100644 index 0000000..526816c Binary files /dev/null and b/portprotonqt/themes/standart/images/button_lt.png differ diff --git a/portprotonqt/themes/standart/images/button_rb.png b/portprotonqt/themes/standart/images/button_rb.png new file mode 100644 index 0000000..5dcfc6d Binary files /dev/null and b/portprotonqt/themes/standart/images/button_rb.png differ diff --git a/portprotonqt/themes/standart/images/button_rt.png b/portprotonqt/themes/standart/images/button_rt.png new file mode 100644 index 0000000..8004286 Binary files /dev/null and b/portprotonqt/themes/standart/images/button_rt.png differ diff --git a/portprotonqt/themes/standart/images/button_select.png b/portprotonqt/themes/standart/images/button_select.png new file mode 100644 index 0000000..066086a Binary files /dev/null and b/portprotonqt/themes/standart/images/button_select.png differ diff --git a/portprotonqt/themes/standart/images/button_start.png b/portprotonqt/themes/standart/images/button_start.png new file mode 100644 index 0000000..190780e Binary files /dev/null and b/portprotonqt/themes/standart/images/button_start.png differ diff --git a/portprotonqt/themes/standart/images/button_x.png b/portprotonqt/themes/standart/images/button_x.png new file mode 100644 index 0000000..e944b3e Binary files /dev/null and b/portprotonqt/themes/standart/images/button_x.png differ diff --git a/portprotonqt/themes/standart/images/button_y.png b/portprotonqt/themes/standart/images/button_y.png new file mode 100644 index 0000000..cf4a997 Binary files /dev/null and b/portprotonqt/themes/standart/images/button_y.png differ diff --git a/portprotonqt/themes/standart/images/key_context.png b/portprotonqt/themes/standart/images/key_context.png new file mode 100644 index 0000000..cc24f92 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_context.png differ diff --git a/portprotonqt/themes/standart/images/key_e.png b/portprotonqt/themes/standart/images/key_e.png new file mode 100644 index 0000000..34b7be1 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_e.png differ diff --git a/portprotonqt/themes/standart/images/key_enter.png b/portprotonqt/themes/standart/images/key_enter.png new file mode 100644 index 0000000..1f144f5 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_enter.png differ diff --git a/portprotonqt/themes/standart/images/key_f11.png b/portprotonqt/themes/standart/images/key_f11.png new file mode 100644 index 0000000..18001d0 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_f11.png differ diff --git a/portprotonqt/themes/standart/images/key_insert.png b/portprotonqt/themes/standart/images/key_insert.png new file mode 100644 index 0000000..d0ae4d5 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_insert.png differ diff --git a/portprotonqt/themes/standart/images/key_left.png b/portprotonqt/themes/standart/images/key_left.png new file mode 100644 index 0000000..3425005 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_left.png differ diff --git a/portprotonqt/themes/standart/images/key_right.png b/portprotonqt/themes/standart/images/key_right.png new file mode 100644 index 0000000..929cb35 Binary files /dev/null and b/portprotonqt/themes/standart/images/key_right.png differ