From: Flavio Calva Date: Sat, 8 Jan 2022 10:38:34 +0000 (+0100) Subject: buttons X-Git-Url: http://git.ya2.it/?p=pmachines.git;a=commitdiff_plain;h=36099535c6d9ee66aff5e952fe64fe7273c8eb88 buttons --- diff --git a/pmachines/scene.py b/pmachines/scene.py index dbc6282..490ec32 100644 --- a/pmachines/scene.py +++ b/pmachines/scene.py @@ -1,5 +1,8 @@ from panda3d.core import AmbientLight, DirectionalLight, Point3 -from panda3d.bullet import BulletPlaneShape, BulletGhostNode# BulletRigidBodyNode +from panda3d.bullet import BulletPlaneShape, BulletGhostNode +from direct.gui.OnscreenImage import OnscreenImage +from direct.gui.DirectGui import DirectButton +from direct.gui.DirectGuiGlobals import FLAT, DISABLED, NORMAL from direct.showbase.DirectObject import DirectObject from pmachines.items.background import Background from pmachines.items.box import Box @@ -11,6 +14,7 @@ class Scene(DirectObject): super().__init__() self._world = world self._set_camera() + self._set_gui() self._set_lights() self._set_input() self._set_mouse_plane() @@ -22,6 +26,44 @@ class Scene(DirectObject): base.camera.set_pos(0, -20, 0) base.camera.look_at(0, 0, 0) + def _set_gui(self): + def load_img_btn(path, col): + img = OnscreenImage('assets/buttons/%s.png' % path) + img.set_transparency(True) + img.set_color(col) + img.detach_node() + return img + def load_images_btn(path): + colors = [ + (.6, .6, .6, 1), # ready + (1, 1, 1, 1), # press + (.8, .8, .8, 1), # rollover + (.4, .4, .4, .4)] # disabled + return [load_img_btn(path, col) for col in colors] + abl, abr = base.a2dBottomLeft, base.a2dBottomRight + btn_info = [ + ('home', self.on_home, DISABLED, abl), + ('information', self.on_information, DISABLED, abl), + ('right', self.on_play, NORMAL, abr), + ('next', self.on_next, DISABLED, abr), + ('previous', self.on_prev, DISABLED, abr), + ('rewind', self.on_rewind, DISABLED, abr)] + num_l = num_r = 0 + for binfo in btn_info: + imgs = load_images_btn(binfo[0]) + if binfo[3] == base.a2dBottomLeft: + sign, num = 1, num_l + num_l += 1 + else: + sign, num = -1, num_r + num_r += 1 + fcols = (.4, .4, .4, .14), (.3, .3, .3, .05) + btn = DirectButton( + image=imgs, scale=.05, pos=(sign * (.06 + .11 * num), 1, .06), + parent=binfo[3], command=binfo[1], state=binfo[2], relief=FLAT, + frameColor=fcols[0] if binfo[2] == NORMAL else fcols[1]) + btn.set_transparency(True) + def _set_directional_light(self, name, hpr, color): light = DirectionalLight(name) light_np = render.attach_new_node(light) @@ -45,7 +87,6 @@ class Scene(DirectObject): self.accept('mouse1-up', self.on_release) self.accept('mouse3', self.on_click_r) self.accept('mouse3-up', self.on_release) - self.accept('p-up', self.on_play) def _set_mouse_plane(self): shape = BulletPlaneShape((0, -1, 0), 1) @@ -99,3 +140,18 @@ class Scene(DirectObject): def on_play(self): [itm.play() for itm in self.items] + + def on_next(self): + print('on_next') + + def on_prev(self): + print('on_prev') + + def on_rewind(self): + print('on_rewind') + + def on_home(self): + print('on_home') + + def on_information(self): + print('on_information') diff --git a/prj.org b/prj.org index a10e4f2..b4213b6 100644 --- a/prj.org +++ b/prj.org @@ -1,8 +1,13 @@ * issues * todo -** buttons ** mouse cursor +** music and sfx +** instructions ** main menu +** configuration (physics debug) +** rotation with vectors/quaternions (fixes some glitches) +** implement the operations of the buttons +** build pipeline ** magnet * waiting ** version 0.0.yymmdd