[gnome-games/wip/abhinavsingh/gamepad-reassign: 11/12] ui: Add ControllerPopover
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-reassign: 11/12] ui: Add ControllerPopover
- Date: Sat, 26 Aug 2017 10:41:13 +0000 (UTC)
commit 403ae0d19b0fe8a4bad8f84b4fa855405d3d0961
Author: theawless <theawless gmail com>
Date: Sat Aug 12 00:30:10 2017 +0530
ui: Add ControllerPopover
Shows the user the current ControllerSet and allows them to reassign the
controller using ControllerReassigner.
data/Makefile.am | 1 +
data/org.gnome.Games.gresource.xml | 1 +
data/ui/controller-popover.ui | 31 +++++++++++++
src/Makefile.am | 1 +
src/ui/controller-popover.vala | 84 ++++++++++++++++++++++++++++++++++++
5 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 1e1fc40..a48c201 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -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 \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index dfd9e2d..06a29ab 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -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>
diff --git a/data/ui/controller-popover.ui b/data/ui/controller-popover.ui
new file mode 100644
index 0000000..762f57f
--- /dev/null
+++ b/data/ui/controller-popover.ui
@@ -0,0 +1,31 @@
+<?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>
diff --git a/src/Makefile.am b/src/Makefile.am
index f77d066..edab034 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/ui/controller-popover.vala b/src/ui/controller-popover.vala
new file mode 100644
index 0000000..49f27ed
--- /dev/null
+++ b/src/ui/controller-popover.vala
@@ -0,0 +1,84 @@
+// 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_inputs ();
+ if (controller_set != null)
+ controller_set.changed.connect (reset_inputs);
+ }
+ get { return _controller_set; }
+ }
+
+ private void reset_inputs () {
+ reassign_button.sensitive = controller_set != null && controller_set.has_multiple_inputs;
+
+ remove_inputs ();
+ update_inputs ();
+ }
+
+ private void update_inputs () {
+ if (controller_set == null)
+ return;
+
+ if (controller_set.has_gamepads) {
+ controller_set.gamepads.foreach ((port, gamepad) => {
+ add_input (gamepad.name, port);
+ });
+ }
+ if (controller_set.has_keyboard)
+ add_input (_("Keyboard"), controller_set.keyboard_port);
+ }
+
+ private void add_input (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_inputs () {
+ 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 ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]