示例#1
0
def isslidevisible(slide):
    if slide == None:
        #If the slide is none, of course it is not displayed. Return 0
        return 0
    current_slide = SlideManager.getCurrentSlide()
    if current_slide == slide and slide.isvisible():
        #If the slide is the current slide, current UI slide and that slide is visible, return 1
        return 1
    else:
        #otherwise return 0
        return 0
示例#2
0
 def _handleevent(self, event):
     if event.type == 'mouseenter':
         #If enter, update rect to full size
         self._currentrect = self._rect
     elif event.type == 'mouseexit':
         #If exit, update rect to small size
         self._currentrect = self._minrect
     elif event.type == pygame.MOUSEBUTTONDOWN:
         #If click display menu
         #If menu is already displayed, do nothing
         if SlideManager.getCurrentSlide().gettype() != 'menu':
             #If any non looping movies playing do nothing
             if not len([item for item in globals.playing if not item.islooping()]):
                 SlideManager.pushMenu(self._menuslide)
示例#3
0
def quitmenuexit():
    nbHotspots=menumain.gethotspotsize()
    for j in range((nbHotspots-1),-1,-1):
        menumain.detachhotspot(j)
    menumain.attachhotspot((500, 300, 200, 40), 'grab', {'dest' :'return_root','zip':0}) #append a hotspot to this slide
    menumain.attachhotspot((500, 340, 200, 40), 'grab', {'dest' :'return','zip':0}) #append a hotspot to this slide
    menumain.attachhotspot((500, 380, 200, 40), 'grab', {'dest' : 'loadmenu','zip':0, 'push':1})
    menumain.attachhotspot((500, 420, 200, 40), 'grab', {'action' : 'optionmenuenter','zip':0, 'push':1})
    if (SlideManager.getCurrentSlide().getrealname()=="intro"):
        # The save menu should not be reachable when no age has been played
        menumain.detachhotspotById('save')
    else:
        menumain.attachhotspot((500, 460, 200, 40), 'grab', {'dest' : 'savemenu','zip':0, 'push':1},'save')
    menumain.attachhotspot((500, 500, 200, 40), 'grab', {'action' : 'quitmenumainenter','zip':0})
    quitmenumain.update(visible = 0)
示例#4
0
def mainloop():
    pygame.init()
    globals.init()
    pygame.mouse.set_visible(0)
    parameters.setcursorpath(os.path.join('engine', 'enginedata', 'cursors'))
    parameters.settextpath(os.path.join('engine', 'enginedata', 'text'))
    initcursors()
    globals.curcursor = globals.cursors['forward']

    filemanager.push_dir(os.path.join('data', 'menu'))

    for curitem in globals.userareasordered:
        curitem._handleevent(fakeevent('init'))
        if curitem.isvisible():
            curitem._draw()
            
    menubar = menubararea((0, 0, parameters.getscreensize()[0], 40),
                          (0, 0, parameters.getscreensize()[0], 5), menumain, 1)
    
    defaultui = None
    startslides = parameters.getfirstslides()
    
    if not startslides[1]:
        print "==> Slide 1 is nul!! Will use bg.bmp"
        defaultui = slide('bg.bmp', type = 'ui')
        defaultui._bmpbuffer = pygame.Surface(globals.screenrect.size)
        defaultui._bmpbuffer.fill(parameters.getbackgroundcolor())
        startslides[1] = defaultui
        startslides[0]=defaultui
    
    # for the start, init the state manager manually... (FIXME)
    SlideManager._slide_stack.append(startslides[0])
    startslides[0].enter(None)
    
    globals.quit = 0
    drag = None
    
    # The area the cursor is currently in
    uha = None
    
    lastpos = (0,0)
    
    defaultui = None
    startslides = parameters.getfirstslides()
    if not startslides[1]:
        defaultui = slide('background','bg.bmp', type = 'ui')
        defaultui._bmpbuffer = pygame.Surface(globals.screenrect.size)
        defaultui._bmpbuffer.fill(parameters.getbackgroundcolor())
        uislide = defaultui
        startslides[1] = uislide
    
    #globals.transoverride = 'initfade'

    WIDTH = parameters.getscreensize()[0]
    HEIGHT = parameters.getscreensize()[1]
    
    previous_time = pygame.time.get_ticks()
    
    while not globals.quit:        
        new_time = pygame.time.get_ticks() 
        dt = new_time - previous_time
        
        # 16 milliseconds is roughly 60 FPS. Cap after that.
        if dt < 16:
            pygame.time.wait(16 - dt)
            new_time = pygame.time.get_ticks() 
            dt = new_time - previous_time
            
        previous_time = new_time
        
        for event in pygame.event.get():
            if globals.eventhandlers.has_key(event.type):
                globals.eventhandlers[event.type](event)
            elif event.type == pygame.USEREVENT:
                #print "event.type==USEREVENT"
                globals.timers[event.timerid].trigger()
            elif event.type == pygame.MOUSEMOTION and globals.curcursor.isenabled():
                if event.pos != lastpos:
                    lastpos = event.pos
                    #print event.pos
                    if uha != None:
                        if not uha.getrect().collidepoint(event.pos):
                            tmpevent = fakeevent('mouseexit')
                            uha._handleevent(tmpevent)
                            uha = None
                    #Route mouse event to proper object
                    if drag != None:
                        update = drag(event)
                        if update:
                            globals.curcursor._hide()
                            #Update mouse cursor with new location
                            globals.curcursor._handlemousemove(event)
                            globals.curcursor._show()
                    else:
                        #Mouse movement
                        #Hide mouse cursor
                        globals.curcursor._hide()
                        #Update mouse cursor with new location
                        globals.curcursor._handlemousemove(event)
                        uhatrapped = 0
                        for area in [item for item in globals.userareasordered if item.isenabled()]:
                            if area.getrect().collidepoint(event.pos):
                                if uha != None:
                                    if area != uha:
                                        tmpevent = fakeevent('mouseexit')
                                        uha._handleevent(tmpevent)
                                        uha = area
                                        tmpevent = fakeevent('mouseenter')
                                        uha._handleevent(tmpevent)
                                else:
                                    uha = area
                                    tmpevent = fakeevent('mouseenter')
                                    uha._handleevent(tmpevent)
                                uhatrapped = uha._handleevent(event)
                                break
                        if not uhatrapped:
                            current_slide = SlideManager.getCurrentSlide()
                            if current_slide.gettype() == 'menu':
                                if globals.screenrect.collidepoint(event.pos):
                                    if current_slide.isvisible():
                                        #print "MOUSE MOVE1 slide._currentuislide.name ",slide._currentuislide._realname
                                        current_slide._mousemove(event.pos)
                            else:
                                if globals.screenrect.collidepoint(event.pos):
                                    #print "if globals"
                                    if current_slide.isvisible():
                                        #print "if slide._currenslide"
                                        current_slide._mousemove(event.pos)
                        globals.curcursor._show()
            elif event.type == pygame.MOUSEBUTTONDOWN and globals.curcursor.isenabled():
                drag = None
                uhatrapped = 0
                for area in [item for item in globals.userareasordered if item.isenabled()]:
                    if area.getrect().collidepoint(event.pos):
                        uhatrapped = area._handleevent(event)
                        break
                if not uhatrapped:
                    current_slide = SlideManager.getCurrentSlide()
                    if current_slide.gettype() == 'menu':
                        if globals.screenrect.collidepoint(event.pos):
                            if current_slide.isvisible():
                                (drag, transitionOccurred) = current_slide.processClick()
                    else:
                        if globals.screenrect.collidepoint(event.pos):
                            if current_slide.isvisible():
                                (drag, transitionOccurred) = current_slide.processClick()
                    if drag:
                        update = drag(event)
                        if update:
                            globals.curcursor._hide()
                            #Update mouse cursor with new location
                            globals.curcursor._handlemousemove(event)
                            globals.curcursor._show()
                    # Ignore mouse movement that may have occurred during the transition
                    if transitionOccurred:
                        if mode == CENTER_MOUSE:
                            pygame.mouse.set_pos([WIDTH/2, HEIGHT/2])
            elif event.type == pygame.MOUSEBUTTONUP and globals.curcursor.isenabled():
                #print "event.type == pygame.MOUSEBUTTONUP and globals.curcursor.isenabled()"
                if drag != None:
                    drag(event)
                    drag = None
                uhatrapped = 0
                for area in [item for item in globals.userareasordered if item.isenabled()]:
                    if area.getrect().collidepoint(event.pos):
                        uhatrapped = area._handleevent(event)
                        break
            elif event.type == pygame.KEYDOWN:
                uhatrapped = 0
                for area in [item for item in globals.userareasordered if item.isenabled()]:
                    uhatrapped = area._handleevent(event)
                    if uhatrapped:
                        break
                if not uhatrapped:
                    if event.key == pygame.K_q:
                        globals.quit = 1
                if event.key == pygame.K_ESCAPE:
                    globals.stopallsound()
                    music.stopmusic()
                    
                    current_slide = SlideManager.getCurrentSlide()
                    if current_slide.gettype() == 'menu':
                        SlideManager.popSlide()
                    else:
                        SlideManager.pushSlide(menumain)
            elif event.type == pygame.QUIT:
                globals.quit = 1
               
        # == Rendering
        s =  SlideManager.getCurrentSlide()
        if s.is3D():
            globals.prepare3DViewport()
            
            (mx, my) = pygame.mouse.get_pos()
            
            if mode == CENTER_MOUSE:
                dx = mx - WIDTH/2
                dy = my - HEIGHT/2
                pygame.mouse.set_pos([WIDTH/2, HEIGHT/2])
                
                if is_in_3d_slide: # avoid jump when entering slide by calculating delta the 2nd time only
                    s.yaw_angle += dt*0.006 * dx
                    if s.yaw_angle < 0: s.yaw_angle += 360
                    elif s.yaw_angle > 360: s.yaw_angle -= 360
                    
                    s.pitch_angle += dt*0.006 * dy
                    if s.pitch_angle < -60:s. pitch_angle = -60
                    elif s.pitch_angle > 60: s.pitch_angle = 60
            else:
                if my < MOVE_MARGIN:
                    s.pitch_angle -= dt*0.1 * float(MOVE_MARGIN - my)/float(MOVE_MARGIN)
                    if s.pitch_angle < -60: s.pitch_angle = -60
                elif my > HEIGHT - MOVE_MARGIN:
                    s.pitch_angle += dt*0.1 * (1.0 - float(HEIGHT - my)/float(MOVE_MARGIN))
                    if s.pitch_angle > 60: s.pitch_angle = 60
                    
                if mx < MOVE_MARGIN:
                    s.yaw_angle -= dt*0.1 * float(MOVE_MARGIN - mx)/float(MOVE_MARGIN)
                    if s.yaw_angle < 0: s.yaw_angle += 360
                elif mx > WIDTH - MOVE_MARGIN:
                    s.yaw_angle += dt*0.1 * (1.0 - float(WIDTH - mx)/float(MOVE_MARGIN))
                    if s.yaw_angle > 359: s.yaw_angle -= 360
            
            # rotate camera
            glRotatef(s.pitch_angle, 1, 0, 0)
            glRotatef(s.yaw_angle, 0, 1, 0)
            
            is_in_3d_slide = True
        else:
            is_in_3d_slide = False
            globals.prepare2DViewport()
        
        # No need for transparency to render slides (don't move this class into Slide.render because
        # transitions still need it enabled)
        glDisable(GL_BLEND)
        
        if s.is3D():
            s.render()
        else:
            s.render()
        
        if s.is3D():
            s.pickHotSpot(mx, my)
            
            # back to 2D for the rest
            globals.prepare2DViewport()
        
        if globals.curcursor is not None:
            glEnable(GL_BLEND)
            
            if s.is3D() and mode == CENTER_MOUSE:
                globals.curcursor.renderAt(WIDTH/2, HEIGHT/2)
            else:  
                globals.curcursor.render()
        
        pygame.display.flip()
         
    for curtimer in globals.timers.values():
        curtimer.stop()
示例#5
0
 def enter(self, oldslide, enter = 1):
     print "slide.py Enter BEGIN :",self._realname, self._type
     
     
     #Display the proper way for the new slide
     if self._type == 'menu':
         #Set transition type to fade
         slide._currenttrans = 'fade'
         if enter:
             #Stop timers
             for timer in [timer for timer in globals.timers.values() if timer.isrunning()]:
                 timer.pause()
                 self._pausedtimers.append(timer)
     elif self._type == 'ui':
         slide._currenttrans = 'fade'
     elif self._type == 'object':
         #Set transition type to fade
         slide._currenttrans = 'fade'
         #Append the last slide to the list of slides that can be "return"ed to
         if enter:
             #Stop timers
             for timer in [timer for timer in globals.timers.values() if timer.isrunning()]:
                 timer.pause()
                 self._pausedtimers.append(timer)
     else:
         #Std slide
         print "slide.py :display STD SlideManager.getCurrentSlide() =", SlideManager.getCurrentSlide().getrealname()
         
         #If this is the first Std slide displayed, no transition (UI will do it for us)
         if len(SlideManager._slide_stack) == 0:
             slide._currenttrans = 'none'
         else:
             #Otherwise Get the current hotspots transition or 'fade' if there is none
             if slide._currenthotspot != None:
                 if slide._currenthotspot.has_key('transover'):
                     #Hotspot is overriding the default transition
                     slide._currenttrans = slide._currenthotspot['transover']
                 else:
                     #Use the default transition
                     slide._currenttrans = globals.cursors[slide._currenthotspot['cursor']].gettransition()
             else:
                 slide._currenttrans = 'fade'
                 
         print "slide.py :display STD NOW after change _currentslide name=", self._realname
         
     
     #Perform the transition between the last slide and this one
     globals.dotrans(self, oldslide)
     
     
     #For all slide types:
     #Clear the current hotspot
     slide._currenthotspot = None
     #Set this slide to be visible
     self._visible = 1
     #If entering this slide run it's entrance functions
     if enter:
         if self._onenterfn:
             if globals.functions.has_key(self._onenterfn):
                 globals.functions[self._onenterfn]()
             else:
                 #print "slide.py :onenterfct",self._onenterfn
                 self._onenterfn()
     
     pos = pygame.mouse.get_pos()
     pygame.mouse.set_pos((pos[0] + 1, pos[1]))
     #If this is a delay slide, count down the delay and display the dest of the first hotspot
     if self._delay > 0:
         pygame.time.delay(self._delay * 1000)
         nextslide = self._state[0]
         nextslide.enter(oldslide, self)
         
     print "slide.py : END of slide.display"