def __init__(self, game, yaml_values=None, yaml_file=None):
        super(AssetManager, self).__init__()
        self.logger = logging.getLogger('game.assets')
        self.game = game
        self.dmd_path = game.dmd_path
        
        
        # self.screen=game.desktop.screen
        # pygame.font.init()
        # p = pygame.font.match_font('Arial')
        # if(p==None):
        #   raise ValueError, "Specific font could not be found on your system.  Please install '" + fontname + "'."
        ### josh prog par
        # self.pygF = pygame.font.Font(p,32)
        self.screen_height = sdl2_DisplayManager.inst().window_h
        self.screen_width = sdl2_DisplayManager.inst().window_w

        if(yaml_values is not None):
            self.values = yaml_values
        else:
            self.loadConfig(game.curr_file_path,yaml_file)

        splash_file = self.value_for_key_path('UserInterface.splash_screen', None)
        self.single_line = self.value_for_key_path('UserInterface.single_line', False)
        self.rect_color = self.value_for_key_path('UserInterface.progress_bar.border', (120,120,120,255))
        self.inner_rect_color = self.value_for_key_path('UserInterface.progress_bar.fill',(255,84,84,255))
        self.bar_x = self.value_for_key_path('UserInterface.progress_bar.x_center', 0.5)
        self.bar_y = self.value_for_key_path('UserInterface.progress_bar.y_center', 0.25)

        bar_w = self.value_for_key_path('UserInterface.progress_bar.width', 0.8)
        bar_h = self.value_for_key_path('UserInterface.progress_bar.height', 0.15)

        text_y = self.value_for_key_path('UserInterface.text.y_center', 0.15)
        # self.text_font = self.value_for_key_path('UserInterface.text.font', 0.15)
        # self.text_size = self.value_for_key_path('UserInterface.text.size', 0.15)
        self.text_color = self.value_for_key_path('UserInterface.text.color', (255,255,0,255))

        self.prog_bar_width = int(bar_w * self.screen_width)
        self.prog_bar_height = int(bar_h * self.screen_height)

        self.prog_bar_x = int((self.screen_width * self.bar_x) - (self.prog_bar_width/2))
        self.prog_bar_y = int((self.screen_height * self.bar_y) - (self.prog_bar_height/2))

        self.text_y = int(text_y * self.screen_height)

        if(splash_file is not None):
            s = sdl2_DisplayManager.inst().load_surface(game.dmd_path + splash_file)
            self.splash_image = sdl2_DisplayManager.inst().texture_from_surface(s)
            del s
        else:
            self.splash_image = None

        self.load()
Exemple #2
0
    def updateProgressBar(self, displayType, fname):
        if (self.splash_image is not None):
            sdl2_DisplayManager.inst().screen_blit(self.splash_image,
                                                   expand_to_fill=True)
        else:
            sdl2_DisplayManager.inst().clear((0, 0, 0, 0))

        sdl2_DisplayManager.inst().draw_rect(
            self.rect_color, (self.prog_bar_x, self.prog_bar_y,
                              self.prog_bar_width, self.prog_bar_height),
            False)
        percent = int(
            float(self.numLoaded + 1) / float(self.total) *
            self.prog_bar_width)

        sdl2_DisplayManager.inst().draw_rect(
            self.inner_rect_color, (self.prog_bar_x + 2, self.prog_bar_y + 2,
                                    percent, self.prog_bar_height - 4), True)

        s = "Loading %s: [%06d] of [%06d]:" % (displayType, self.numLoaded + 1,
                                               self.total)
        tx = sdl2_DisplayManager.inst().font_render_text(s,
                                                         font_alias=None,
                                                         size=None,
                                                         width=300,
                                                         color=self.text_color,
                                                         bg_color=None)
        sdl2_DisplayManager.inst().screen_blit(tx,
                                               x=60,
                                               y=self.text_y,
                                               expand_to_fill=False)

        tx = sdl2_DisplayManager.inst().font_render_text(fname,
                                                         font_alias=None,
                                                         size=None,
                                                         width=300,
                                                         color=self.text_color,
                                                         bg_color=None)
        sdl2_DisplayManager.inst().screen_blit(tx,
                                               x=80,
                                               y=self.text_y + 35,
                                               expand_to_fill=False)

        #   self.screen.blit(surf,(self.prog_bar_x,self.prog_bar_y + (1.1 * self.prog_bar_height)) )
        sdl2_DisplayManager.inst().flip()

        for event in sdl2.ext.get_events():
            #print("Key: %s" % event.key.keysym.sym)
            if event.type == sdl2.SDL_KEYDOWN:
                if event.key.keysym.sym == sdl2.SDLK_ESCAPE:
                    self.game.end_run_loop()
                    sys.exit()
    def updateProgressBar(self, displayType,fname):
        if(self.splash_image is not None):
            sdl2_DisplayManager.inst().screen_blit(self.splash_image, expand_to_fill=True)
        else:
            sdl2_DisplayManager.inst().clear((0,0,0,0))


        sdl2_DisplayManager.inst().draw_rect(self.rect_color, (self.prog_bar_x,self.prog_bar_y,self.prog_bar_width,self.prog_bar_height), False)
        percent = int (float(self.numLoaded + 1)/float(self.total) * self.prog_bar_width)

        sdl2_DisplayManager.inst().draw_rect(self.inner_rect_color, (self.prog_bar_x + 2,self.prog_bar_y + 2,percent,self.prog_bar_height-4), True) 

        if (self.single_line):
            s = "Loading %s: [%06d] of [%06d]: %s" % (displayType, self.numLoaded+1,self.total, fname)
            tx = sdl2_DisplayManager.inst().font_render_text(s, font_alias=None, size=None, width=300, color=self.text_color, bg_color=None)
            sdl2_DisplayManager.inst().screen_blit(tx, x=60, y=self.text_y, expand_to_fill=False)
        else:
            s = "Loading %s: [%06d] of [%06d]:" % (displayType, self.numLoaded+1,self.total)
            tx = sdl2_DisplayManager.inst().font_render_text(s, font_alias=None, size=None, width=300, color=self.text_color, bg_color=None)
            sdl2_DisplayManager.inst().screen_blit(tx, x=60, y=self.text_y, expand_to_fill=False)
    
            tx = sdl2_DisplayManager.inst().font_render_text(fname, font_alias=None, size=None, width=300, color=self.text_color, bg_color=None)
            sdl2_DisplayManager.inst().screen_blit(tx, x=80, y=self.text_y+35, expand_to_fill=False)


    #   self.screen.blit(surf,(self.prog_bar_x,self.prog_bar_y + (1.1 * self.prog_bar_height)) )
        sdl2_DisplayManager.inst().flip()

        for event in sdl2.ext.get_events():
            #print("Key: %s" % event.key.keysym.sym)
            if event.type == sdl2.SDL_KEYDOWN:
                if event.key.keysym.sym == sdl2.SDLK_ESCAPE:
                    self.game.end_run_loop()
                    sys.exit()