ya2 · news · projects · support us · follow us · lists · code · about

instructions
authorFlavio Calva <f.calva@gmail.com>
Fri, 14 Jan 2022 18:50:18 +0000 (19:50 +0100)
committerFlavio Calva <f.calva@gmail.com>
Fri, 14 Jan 2022 18:50:18 +0000 (19:50 +0100)
assets/buttons/mouse.png
assets/buttons/mouse_l.png [new file with mode: 0644]
assets/buttons/mouse_r.png [new file with mode: 0644]
lib/engine/lang.py
pmachines/pmachines.py
pmachines/scene.py
prj.org

index 46042c21c875a8e6a3d532500d3fdd95517131b5..27cd9f033d80d6cb8d65b7b2d7d37e61ae4c3e04 100644 (file)
Binary files a/assets/buttons/mouse.png and b/assets/buttons/mouse.png differ
diff --git a/assets/buttons/mouse_l.png b/assets/buttons/mouse_l.png
new file mode 100644 (file)
index 0000000..8998861
Binary files /dev/null and b/assets/buttons/mouse_l.png differ
diff --git a/assets/buttons/mouse_r.png b/assets/buttons/mouse_r.png
new file mode 100644 (file)
index 0000000..4f6f68d
Binary files /dev/null and b/assets/buttons/mouse_r.png differ
index e8ebb11bacc63431e19936bb0e30d9e8f7e4a406..09adde4ffc616e13e489adc4a441eb8bd2b80991 100644 (file)
@@ -1,7 +1,36 @@
 from logging import info
-from os.path import join
+from os.path import join, exists, dirname
 from gettext import translation
+from pathlib import Path
 from lib.gameobject import GameObject
+import sys
+
+
+def is_runtime(): return not exists('main.py')
+
+
+def is_appimage():
+    par_path = str(Path(__file__).parent.absolute())
+    is_appimage = par_path.startswith('/tmp/.mount_Pmachines')
+    return is_appimage and par_path.endswith('/usr/bin')
+
+
+def curr_path():
+    if not is_runtime(): return ''
+    if sys.platform == 'darwin':
+        return dirname(__file__) + '/../Resources/'
+    # return dirname(__file__)
+    par_path = str(Path(__file__).parent.absolute())
+    if is_appimage():
+        return str(Path(par_path).absolute())
+    is_snap = par_path.startswith('/snap/')
+    is_snap = is_snap and par_path.endswith('/x1')
+    if is_snap:
+        return str(Path(par_path).absolute())
+    #return getcwd()
+    curr_path = dirname(__file__)
+    info('current path: %s' % curr_path)
+    return curr_path + '/'
 
 
 class LangMgr(GameObject):
@@ -10,7 +39,7 @@ class LangMgr(GameObject):
         GameObject.__init__(self)
         self.lang = lang
         self.domain = domain
-        self.dpath = join(self.eng.curr_path, dpath)
+        self.dpath = join(curr_path(), dpath)
         info('language: %s, %s' % (self.domain, self.dpath))
         self.set_lang(lang)
 
index fdd1fa097b25c96f3ca5e00357fe811065c59b29..ddf4c7d2634010d2ac28886631bf1408b5dc19c3 100755 (executable)
@@ -12,6 +12,7 @@ from pmachines.scene import Scene
 from pmachines.music import MusicMgr
 from lib.dictfile import DctFile
 from lib.lib.p3d.p3d import LibP3d
+from lib.engine.lang import LangMgr
 
 
 class Pmachines:
@@ -28,6 +29,9 @@ class Pmachines:
         if args.update:
             return
         MusicMgr(self._options['settings']['volume'])
+        self.lang_mgr = LangMgr('en',
+                                'pmachines',
+                                'assets/locale/')
         self._set_physics()
         self._scene = Scene(self.world)
 
index 7ad90be1dad417210055d9e184d45c6859da919e..72dc4237103a198437442672c40987069f546529 100644 (file)
@@ -1,7 +1,9 @@
-from panda3d.core import AmbientLight, DirectionalLight, Point3
+from panda3d.core import AmbientLight, DirectionalLight, Point3, Texture, \
+    TextPropertiesManager, TextNode
 from panda3d.bullet import BulletPlaneShape, BulletGhostNode
 from direct.gui.OnscreenImage import OnscreenImage
-from direct.gui.DirectGui import DirectButton
+from direct.gui.OnscreenText import OnscreenText
+from direct.gui.DirectGui import DirectButton, DirectFrame
 from direct.gui.DirectGuiGlobals import FLAT, DISABLED, NORMAL
 from direct.showbase.DirectObject import DirectObject
 from pmachines.items.background import Background
@@ -24,6 +26,7 @@ class Scene(DirectObject):
         self._set_lights()
         self._set_input()
         self._set_mouse_plane()
+        self._set_instructions()
         Background()
         self.items = [Box(world, self._mouse_plane_node, 3, self.cb_inst)]
         self._side_panel = SidePanel(world, self._mouse_plane_node, (-5, 4), (-3, 1), 1)
@@ -176,3 +179,37 @@ class Scene(DirectObject):
 
     def on_information(self):
         print('on_information')
+
+    def _set_instructions(self):
+        mgr = TextPropertiesManager.get_global_ptr()
+        for name in ['mouse_l', 'mouse_r']:
+            graphic = OnscreenImage('assets/buttons/%s.png' % name)
+            graphic.set_scale(.5)
+            graphic.get_texture().set_minfilter(Texture.FTLinearMipmapLinear)
+            graphic.get_texture().set_anisotropic_degree(2)
+            mgr.set_graphic(name, graphic)
+            graphic.set_z(-.2)
+            graphic.set_transparency(True)
+            graphic.detach_node()
+        frm = DirectFrame(frameColor=(.4, .4, .4, .06),
+                          frameSize=(-.6, .6, -.3, .3))
+        font = base.loader.load_font('assets/fonts/Hanken-Book.ttf')
+        font.clear()
+        font.set_pixels_per_unit(60)
+        font.set_minfilter(Texture.FTLinearMipmapLinear)
+        font.set_outline((0, 0, 0, 1), .8, .2)
+        txt = _('keep \5mouse_l\5 pressed to drag an item\n\n'
+                'keep \5mouse_r\5 pressed to rotate an item')
+        self._txt = OnscreenText(
+            txt, parent=frm, font=font, scale=0.06, fg=(.9, .9, .9, 1),
+            align=TextNode.A_left)
+        u_l = self._txt.textNode.get_upper_left_3d()
+        l_r = self._txt.textNode.get_lower_right_3d()
+        w, h = l_r[0] - u_l[0], u_l[2] - l_r[2]
+        z = h / 2 - font.get_line_height() * self._txt['scale'][1]
+        self._txt['pos'] = -w / 2, z
+        u_l = self._txt.textNode.get_upper_left_3d()
+        l_r = self._txt.textNode.get_lower_right_3d()
+        mar = .06  # margin
+        fsz = u_l[0] - mar, l_r[0] + mar, l_r[2] - mar, u_l[2] + mar
+        frm['frameSize'] = fsz
diff --git a/prj.org b/prj.org
index 85e8a4628bfe0a5965a94586fc2f88069826dfe9..83bec887c7fdcdb249efcedeae856dc460939480 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -1,6 +1,6 @@
 * issues
 * todo
-** instructions
+** l10n
 ** main menu
 ** implement the operations of the buttons
 ** create one level per item, then levels with more items