ya2 · news · projects · code · about

automatic creation of buttons for scenes
authorFlavio Calva <f.calva@gmail.com>
Thu, 3 Feb 2022 18:08:02 +0000 (19:08 +0100)
committerFlavio Calva <f.calva@gmail.com>
Thu, 3 Feb 2022 18:08:02 +0000 (19:08 +0100)
pmachines/menu.py
prj.org

index a087b53f29279d6d8d506967d34c2693baf26ed3..103516fdbf4582d12f565e4fbed11e7b3c9860bd 100644 (file)
@@ -184,16 +184,13 @@ class Menu:
         cmn = self._common_btn.copy() | {
             'frameSize': (-2.4, 2.4, -2.4, 2.4),
             'frameColor': (1, 1, 1, .8)}
-        self._widgets += [DirectButton(
-            text=scene_classes[0].name(), pos=(-.4, 1, .1), command=self.start,
-            extraArgs=[scene_classes[0]],
-            frameTexture='assets/images/scenes/%s.png' % scene_classes[0].__name__,
-            **cmn)]
-        self._widgets += [DirectButton(
-            text=scene_classes[1].name(), pos=(.4, 1, .1), command=self.start,
-            extraArgs=[scene_classes[1]],
-            frameTexture='assets/images/scenes/%s.png' % scene_classes[1].__name__,
-            **cmn)]
+        left = - (dx := .8) * (len(scene_classes) - 1) / 2
+        for i, cls in enumerate(scene_classes):
+            self._widgets += [DirectButton(
+                text=cls.name(), pos=(left + dx * i, 1, .1), command=self.start,
+                extraArgs=[cls],
+                frameTexture='assets/images/scenes/%s.png' % cls.__name__,
+                **cmn)]
         self._widgets += [DirectButton(
             text=_('Back'), pos=(0, 1, -.8), command=self.on_back,
             **self._common_btn)]
diff --git a/prj.org b/prj.org
index fdd9cce7bebbdd5d52a446c8e5cec0b6651b6e9d..70ebb524306b540803ca853dbc49d3a6c07c0811 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -1,6 +1,5 @@
 * issues
 * todo
-** automatic creation of scene buttons
 ** frame for the end of the level (back, replay, next level)
 ** create one level per item, then levels with more items
 *** e.g. item1, item2, item1+2, item3, item1+2+3, ...