Browse Source

Add key hint management in the foot_bar

Godzil 5 years ago
parent
commit
1e3aa2bffb
2 changed files with 48 additions and 1 deletions
  1. 2 1
      skin/cpi_default/config.cfg
  2. 46 0
      sys.py/interface/foot_bar.py

+ 2 - 1
skin/cpi_default/config.cfg

@@ -11,4 +11,5 @@ otocjk=NotoSansCJK-Regular.ttf
 
 [Images]
 blank_icon=sys.py/gameshell/blank.png
-corners_tiles=sys.py/gameshell/icons/roundcorners.png
+corners_tiles=sys.py/gameshell/icons/roundcorners.png
+buttons=sys.py/gameshell/footbar_icons/footbar.png

+ 46 - 0
sys.py/interface/foot_bar.py

@@ -16,6 +16,52 @@ class FootBar(UI.FlowContainer):
 
         self.add_child(self._topline)
 
+        self.set_margin(2)
+        self.set_top_margin(1)
+
+        self._Buttons = {"dpad": UI.Image(image=UI.ImageManager.get_sprite("buttons", 18, 18, 1)),
+                         "a_key": UI.Image(image=UI.ImageManager.get_sprite("buttons", 18, 18, 4)),
+                         "b_key": UI.Image(image=UI.ImageManager.get_sprite("buttons", 18, 18, 5)),
+                         "x_key": UI.Image(image=UI.ImageManager.get_sprite("buttons", 18, 18, 2)),
+                         "y_key": UI.Image(image=UI.ImageManager.get_sprite("buttons", 18, 18, 3))}
+
+        self._Labels = {"dpad": UI.Label(text="", font_obj=UI.FontManager.get_font("veramono_12")),
+                        "a_key": UI.Label(text="", font_obj=UI.FontManager.get_font("veramono_12")),
+                        "b_key": UI.Label(text="", font_obj=UI.FontManager.get_font("veramono_12")),
+                        "x_key": UI.Label(text="", font_obj=UI.FontManager.get_font("veramono_12")),
+                        "y_key": UI.Label(text="", font_obj=UI.FontManager.get_font("veramono_12"))}
+
+    def set_keyhint(self, dpad=None, a_key=None, b_key=None, x_key=None, y_key=None):
+        # First clear current lists
+        self.clear_left_childs()
+        self.clear_right_childs()
+
+        self._Labels["dpad"].set_text(dpad)
+        self._Labels["a_key"].set_text(a_key)
+        self._Labels["b_key"].set_text(b_key)
+        self._Labels["x_key"].set_text(x_key)
+        self._Labels["y_key"].set_text(y_key)
+
+        if dpad is not None:
+            self.add_left_child(self._Buttons["dpad"])
+            self.add_left_child(self._Labels["dpad"])
+
+        if a_key is not None:
+            self.add_right_child(self._Buttons["a_key"])
+            self.add_right_child(self._Labels["a_key"])
+
+        if b_key is not None:
+            self.add_right_child(self._Buttons["b_key"])
+            self.add_right_child(self._Labels["b_key"])
+
+        if x_key is not None:
+            self.add_right_child(self._Buttons["x_key"])
+            self.add_right_child(self._Labels["x_key"])
+
+        if y_key is not None:
+            self.add_right_child(self._Buttons["y_key"])
+            self.add_right_child(self._Labels["y_key"])
+
     def reload(self):
         # Do nothing for now, later reload info from skinmanager
         pass