ya2 · news · projects · code · about

in-game mouse position
authorFlavio Calva <f.calva@gmail.com>
Tue, 19 Jul 2022 17:52:03 +0000 (18:52 +0100)
committerFlavio Calva <f.calva@gmail.com>
Tue, 19 Jul 2022 17:52:03 +0000 (18:52 +0100)
pmachines/app.py
pmachines/scene.py
prj.org

index 8adb7659f98aa48eaf81f3bcfaebe58a2332fa3b..521a063e63ee8ccd1d3b793b06eea729fd2d2e33 100755 (executable)
@@ -142,7 +142,8 @@ class PmachinesApp:
             self.reload,
             self.scenes,
             self._pos_mgr,
-            self._args.functional_test or self._args.functional_ref)
+            self._args.functional_test or self._args.functional_ref,
+            self._options['development']['mouse_coords'])
 
     def on_scene_exit(self):
         self._unset_physics()
index 939fa05954ea0d138040e4d75a48fb99c9341af5..de479e263e0e567e45a0ff31adcf518fd92e56d6 100644 (file)
@@ -21,11 +21,12 @@ from ya2.p3d.p3d import LibP3d
 
 class Scene(DirectObject):
 
-    def __init__(self, world, exit_cb, auto_close_instr, dbg_items, reload_cb, scenes, pos_mgr, testing):
+    def __init__(self, world, exit_cb, auto_close_instr, dbg_items, reload_cb, scenes, pos_mgr, testing, mouse_coords):
         super().__init__()
         self._world = world
         self._exit_cb = exit_cb
         self._testing = testing
+        self._mouse_coords = mouse_coords
         self._dbg_items = dbg_items
         self._reload_cb = reload_cb
         self._pos_mgr = pos_mgr
@@ -191,6 +192,21 @@ class Scene(DirectObject):
             self._info_txt = OnscreenText(
                 '', parent=base.a2dTopRight, scale=0.04,
                 pos=(-.03, -.06), fg=(.9, .9, .9, 1), align=TextNode.A_right)
+        if self._mouse_coords:
+            self._coords_txt = OnscreenText(
+                '', parent=base.a2dTopRight, scale=0.04,
+                pos=(-.03, -.12), fg=(.9, .9, .9, 1), align=TextNode.A_right)
+            def update_coords(task):
+                pos = None
+                for hit in self._get_hits():
+                    if hit.get_node() == self._mouse_plane_node:
+                        pos = hit.get_hit_pos()
+                if pos:
+                    txt = '%s %s' % (round(pos.x, 3),
+                                     round(pos.z, 3))
+                    self._coords_txt['text'] = txt
+                return task.cont
+            self._coords_tsk = taskMgr.add(update_coords, 'update_coords')
 
     def _unset_gui(self):
         btns = [
@@ -200,6 +216,9 @@ class Scene(DirectObject):
         [btn.destroy() for btn in btns]
         if self._dbg_items:
             self._info_txt.destroy()
+        if self._mouse_coords:
+            taskMgr.remove(self._coords_tsk)
+            self._coords_txt.destroy()
 
     def _set_spotlight(self, name, pos, look_at, color, shadows=False):
         light = Spotlight(name)
diff --git a/prj.org b/prj.org
index 9c1366c5c33bc2f0d8d9fbf8f554c743290cf82e..259e2aa904ee4dd2015e0813aee119e6b1b3a612 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -4,6 +4,7 @@
 #+TAGS: bug(b) calendar(c) waiting(w)
 
 * CODE drag and drop positions in the scene files as empty nodes
+* READY create builds, update website and itch.io
 * READY refactoring (recurring task)
 * BACKLOG intro animation (from target item to start position)
 * BACKLOG buttons of the scenes enabled sequentially