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):
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)
-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
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)
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