Add option to launch games by clicking cover

This commit is contained in:
kramo
2023-03-26 11:03:23 +02:00
parent 2cc9f638a7
commit 228db1b2f0
6 changed files with 70 additions and 25 deletions

View File

@@ -66,10 +66,16 @@ class game(Gtk.Box): # pylint: disable=invalid-name
self.add_controller(self.event_contoller_motion)
self.overlay.set_measure_overlay(self.play_revealer, True)
self.button_play.connect("clicked", self.launch_game)
self.set_play_label()
self.cover_button.connect("clicked", self.cover_button_clicked)
self.button_play.connect("clicked", self.button_play_clicked)
self.event_contoller_motion.connect("enter", self.show_play)
self.event_contoller_motion.connect("leave", self.hide_play)
self.parent_widget.schema.connect("changed", self.schema_changed)
if self.hidden:
self.menu_button.set_menu_model(self.hidden_game_options)
else:
@@ -146,6 +152,28 @@ class game(Gtk.Box): # pylint: disable=invalid-name
self.play_revealer.set_reveal_child(False)
self.title_revealer.set_reveal_child(True)
def launch_game(self, _widget):
def launch_game(self, _widget, *_unused):
self.parent_widget.set_active_game(None, None, self.game_id)
self.parent_widget.get_application().on_launch_game_action(None)
def cover_button_clicked(self, _widget):
if self.parent_widget.schema.get_boolean("cover-launches-game"):
self.launch_game(None)
else:
self.parent_widget.show_overview(None, self.game_id)
def button_play_clicked(self, _widget):
if self.parent_widget.schema.get_boolean("cover-launches-game"):
self.parent_widget.show_overview(None, self.game_id)
else:
self.launch_game(None)
def set_play_label(self):
if self.parent_widget.schema.get_boolean("cover-launches-game"):
self.button_play.set_label(_("Details"))
else:
self.button_play.set_label(_("Play"))
def schema_changed(self, _settings, key):
if key == "cover-launches-game":
self.set_play_label()

View File

@@ -29,6 +29,8 @@ class PreferencesWindow(Adw.PreferencesWindow):
page = Gtk.Template.Child()
exit_after_launch_switch = Gtk.Template.Child()
cover_launches_game_switch = Gtk.Template.Child()
high_quality_images_switch = Gtk.Template.Child()
steam_file_chooser_button = Gtk.Template.Child()
steam_extra_file_chooser_button = Gtk.Template.Child()
@@ -43,8 +45,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
bottles_group = Gtk.Template.Child()
bottles_file_chooser_button = Gtk.Template.Child()
high_quality_images_switch = Gtk.Template.Child()
def __init__(self, parent_widget, **kwargs):
super().__init__(**kwargs)
@@ -56,6 +56,18 @@ class PreferencesWindow(Adw.PreferencesWindow):
"active",
Gio.SettingsBindFlags.DEFAULT,
)
schema.bind(
"cover-launches-game",
self.cover_launches_game_switch,
"active",
Gio.SettingsBindFlags.DEFAULT,
)
schema.bind(
"high-quality-images",
self.high_quality_images_switch,
"active",
Gio.SettingsBindFlags.DEFAULT,
)
schema.bind(
"heroic-import-epic",
self.heroic_epic_switch,
@@ -74,12 +86,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
"active",
Gio.SettingsBindFlags.DEFAULT,
)
schema.bind(
"high-quality-images",
self.high_quality_images_switch,
"active",
Gio.SettingsBindFlags.DEFAULT,
)
filechooser = Gtk.FileDialog()

View File

@@ -153,7 +153,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.hidden_widgets[game_id] = entry
self.hidden_library.append(entry)
entry.cover_button.connect("clicked", self.show_overview, game_id)
entry.menu_button.get_popover().connect(
"notify::visible", self.set_active_game, game_id
)