From: Flavio Calva Date: Tue, 19 Jul 2022 17:52:03 +0000 (+0100) Subject: in-game mouse position X-Git-Url: http://git.ya2.it/?p=pmachines.git;a=commitdiff_plain;h=7fa5864023f03d5e8e1b59260750d46f85595b2c in-game mouse position --- diff --git a/pmachines/app.py b/pmachines/app.py index 8adb765..521a063 100755 --- a/pmachines/app.py +++ b/pmachines/app.py @@ -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() diff --git a/pmachines/scene.py b/pmachines/scene.py index 939fa05..de479e2 100644 --- a/pmachines/scene.py +++ b/pmachines/scene.py @@ -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 9c1366c..259e2aa 100644 --- 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