Commit af9c4513 authored by Abhinav Singh's avatar Abhinav Singh
Browse files

ui: Add ControllerPopover

Shows the user the current ControllerSet and allows them to reassign the
controller using ControllerReassigner.

https://bugzilla.gnome.org/show_bug.cgi?id=780756
parent e869e889
......@@ -41,6 +41,7 @@ EXTRA_DIST = \
ui/gamepad-mapper.ui \
ui/gamepad-tester.ui \
ui/game-icon-view.ui \
ui/controller-popover.ui \
ui/controller-reassigner.ui \
ui/media-menu-button.ui \
ui/media-selector.ui \
......
......@@ -20,6 +20,7 @@
<file preprocess="xml-stripblanks">ui/gamepad-mapper.ui</file>
<file preprocess="xml-stripblanks">ui/gamepad-tester.ui</file>
<file preprocess="xml-stripblanks">ui/game-icon-view.ui</file>
<file preprocess="xml-stripblanks">ui/controller-popover.ui</file>
<file preprocess="xml-stripblanks">ui/controller-reassigner.ui</file>
<file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
<file preprocess="xml-stripblanks">ui/media-selector.ui</file>
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.16"/>
<template class="GamesControllerPopover" parent="GtkPopover">
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin">6</property>
<property name="spacing">12</property>
<property name="visible">True</property>
<child>
<object class="GtkListBox" id="controllers_list_box">
<property name="visible">True</property>
<property name="selection_mode">none</property>
</object>
</child>
<child>
<object class="GtkButton" id="reassign_button">
<property name="visible">True</property>
<property name="label" translatable="yes">Reassign</property>
<signal name="clicked" handler="on_reassign_clicked"/>
</object>
</child>
</object>
</child>
</template>
</interface>
......@@ -154,6 +154,7 @@ gnome_games_SOURCES = \
ui/game-icon-view.vala \
ui/game-thumbnail.vala \
ui/gamepad-view-configuration.vala \
ui/controller-popover.vala \
ui/controller-reassigner.vala \
ui/media-selector.vala \
ui/media-menu-button.vala \
......
// This file is part of GNOME Games. License: GPL-3.0+.
[GtkTemplate (ui = "/org/gnome/Games/ui/controller-popover.ui")]
private class Games.ControllerPopover : Gtk.Popover {
[GtkChild]
private Gtk.ListBox controllers_list_box;
[GtkChild]
private Gtk.Button reassign_button;
private ControllerSet _controller_set;
public ControllerSet controller_set {
set {
_controller_set = value;
reset_controllers ();
if (controller_set != null)
controller_set.changed.connect (reset_controllers);
}
get { return _controller_set; }
}
private void reset_controllers () {
reassign_button.sensitive = controller_set != null && controller_set.has_multiple_controllers;
remove_controllers ();
update_controllers ();
}
private void update_controllers () {
if (controller_set == null)
return;
if (controller_set.has_gamepads) {
controller_set.gamepads.foreach ((port, gamepad) => {
add_controller (gamepad.name, port);
});
}
if (controller_set.has_keyboard)
add_controller (_("Keyboard"), controller_set.keyboard_port);
}
private void add_controller (string label, uint port) {
var position = (int) port;
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
box.pack_start (new Gtk.Label (position.to_string ()), false, false);
box.pack_end (new Gtk.Label (label), false, false);
box.spacing = 6;
box.margin = 6;
box.show_all ();
controllers_list_box.insert (box, position);
}
private void remove_controllers () {
controllers_list_box.foreach ((child) => child.destroy ());
}
[GtkCallback]
private void on_reassign_clicked () {
popdown ();
int width, height;
var window = (Gtk.Window) get_toplevel ();
window.get_size (out width, out height);
var controller_reassigner = new ControllerReassigner ();
controller_reassigner.set_transient_for (window);
controller_reassigner.set_default_size (width / 2, height / 2);
controller_reassigner.response.connect ((response) => {
switch (response) {
case Gtk.ResponseType.APPLY:
controller_set.gamepads = controller_reassigner.controller_set.gamepads;
controller_set.keyboard_port = controller_reassigner.controller_set.keyboard_port;
controller_set.reset ();
break;
default:
break;
}
controller_reassigner.destroy ();
});
controller_reassigner.show ();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment