예제 #1
0
def run(screen):
  # here's the signature for dance.play from dance.py
  # def play(screen, playlist, configs, songconf, playmode):

  # playlist is a list of (song_filename, song_diff)
  filename = os.path.join(sound_path, "calibration/calibrate.dance")
  mode = "SINGLE"
  diff = "BASIC"
  
  # store some configurations that we need to temporarily subvert...
  temp = { 'judge': game_config['judge'],
           'secret': game_config['secret'],
           'grading': mainconfig['grading'] }
  
  # use CalibrationJudge, make hidden arrows invisible, and don't show the grading screen
  game_config.update({ 'judge': 2, 'secret': 1 })
  mainconfig['grading'] = False
  
  mainconfig['masteroffset'] = 0
  
  dance.play(screen, [(filename, [diff])], [player_config], game_config, mode)
  
  print "New master offset: " + str(mainconfig['masteroffset'])
  
  # restore original settings
  mainconfig['grading'] = temp['grading']
  for x in [ 'secret', 'judge' ]:
    game_config[x] = temp[x]
예제 #2
0
파일: pydance.py 프로젝트: selukov/pydance
def play_and_quit(fn, mode, difficulty):
    print _("Entering debug (play-and-quit) mode.")
    screen = set_display_mode()
    pygame.display.set_caption("pydance " + VERSION)
    pygame.mouse.set_visible(0)
    pc = games.GAMES[mode].players
    dance.play(screen, [(fn, [difficulty] * pc)], [player_config] * pc, game_config, mode)
    raise SystemExit
예제 #3
0
파일: pydance.py 프로젝트: cpina/pydance
def play_and_quit(fn, mode, difficulty):
  print(_("Entering debug (play-and-quit) mode."))
  screen = set_display_mode()  
  pygame.display.set_caption("pydance " + VERSION)
  pygame.mouse.set_visible(0)
  pc = games.GAMES[mode].players
  dance.play(screen, [(fn, [difficulty] * pc)],
             [player_config] * pc, game_config, mode)
  raise SystemExit
예제 #4
0
파일: songselect.py 프로젝트: asb/pydance
  def loop(self):
    pid, ev = ui.ui.poll()
    self._list.set_index(self._index)
    self._title.set_text(self._base_text + " - %d/%d" % (self._index + 1,
                                                         len(self._songitems)))
    while not (ev == ui.CANCEL and (not self._folders or self._song.isfolder)):
      # Inactive player. If the event isn't set to ui.PASS, we try to use
      # the pid later, which will be bad.
      if pid >= len(self._diff_names): ev = ui.PASS
      
      elif ev == ui.UP: self._index -= 1
      elif ev == ui.DOWN: self._index += 1
      elif ev == ui.PGUP:
        self._index -= 7
        ev = ui.UP
      elif ev == ui.PGDN:
        self._index += 7
        ev = ui.DOWN

      elif ev == ui.LEFT:
        if not self._song.isfolder:
          namei = self._song.diff_list.index(self._diff_names[pid])
          namei = (namei -1) % len(self._song.diff_list)
          name = self._song.diff_list[namei]
          self._diff_names[pid] = name
          self._pref_diff_names[pid] = name
          self._last_player = pid

      elif ev == ui.RIGHT:
        if not self._song.isfolder:
          namei = self._song.diff_list.index(self._diff_names[pid])
          namei = (namei + 1) % len(self._song.diff_list)
          name = self._song.diff_list[namei]
          self._diff_names[pid] = name
          self._pref_diff_names[pid] = name
          self._last_player = pid

      elif ev == ui.SELECT:
        if self._song.isfolder:
          if len(self._all_valid_songitems) > 0:
            self._song = random.choice(self._all_valid_songitems)
            fol = self._song.folder[SORT_NAMES[mainconfig["sortmode"]]]
            self._create_song_list(fol)
            self._index = self._songitems.index(self._song)      
          else:
            error.ErrorMessage(screen,
                               _("You don't have any songs that are marked ") +
                               _("\"valid\" for random selection."))
        else:
          valid_songs = [s for s in self._songitems if s.info["valid"]]
          if len(valid_songs) > 0:
            self._song = random.choice(valid_songs)
            self._index = self._songitems.index(self._song)
          else:
            error.ErrorMessage(screen, _("You don't have any songs here that ") +
                               _("are marked \"valid\" for random selection."))
      elif ev == ui.START:
        options.OptionScreen(self._configs, self._config, self._screen)
        self._screen.blit(self._bg, [0, 0])
        self.update()
        pygame.display.update()

      elif ev == ui.SORT:
        s = self._songitems[self._index]
        mainconfig["sortmode"] = (mainconfig["sortmode"] + 1) % NUM_SORTS
        sort_name = self._update_songitems()
        if self._folders:
          if s.isfolder:
            self._create_folder_list()
          else:
            s = self._find_resorted()
            self._create_song_list(s.folder[sort_name])
            self._index = self._songitems.index(s)
        else:
          s = self._find_resorted()
          self._base_text = _(sort_name).upper()
          self._songitems.sort(key=SORTS[sort_name])
          self._index = self._songitems.index(s)
          self._list.set_items([s.info["title"] for s in self._songitems])

      elif ev == ui.CONFIRM:
        if self._song.isfolder:
          self._create_song_list(self._song.name)
          self._index = 0
        else:
          music.fadeout(500)
          dance.play(self._screen, [(self._song.filename, self._diff_names)],
                     self._configs, self._config, self._game)
          music.fadeout(500) # The just-played song
          self._screen.blit(self._bg, [0, 0])
          pygame.display.update()
          ui.ui.clear()

      elif ev == ui.CANCEL:
        # first: get the parent folder of the active song
        sort_name = SORT_NAMES[mainconfig["sortmode"]]
        fol = folder_name(self._song.folder[sort_name], sort_name)
        # next: change folder
        self._create_folder_list()
        for d in self._diff_widgets:
          d.set("None", [127, 127, 127], 0, "?")

        lst = [s.info["title"] for s in self._songitems]
        self._index = lst.index(fol)

      elif ev == ui.FULLSCREEN:
        mainconfig["fullscreen"] ^= 1
        pygame.display.toggle_fullscreen()

      self._index %= len(self._songitems)
      self._song = self._songitems[self._index]

      if self._locked and ev in [ui.LEFT, ui.RIGHT]:
        for i, sd in enumerate(self._diff_names):
          self._diff_names[i] = self._diff_names[pid]
          self._pref_diff_names[i] = self._diff_names[pid]

      if ev in [ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT]:
        self._preview.preview(self._song)
        self._banner.set_song(self._song)

      if ev in [ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT]:
        if ev == ui.UP: self._list.set_index(self._index, -1)
        elif ev == ui.DOWN: self._list.set_index(self._index, 1)
        else: self._list.set_index(self._index, 0) # don't animate
        self._title.set_text(self._base_text + " - %d/%d" % (self._index + 1,
                                                             len(self._songitems)))

      if ev in [ui.UP, ui.DOWN, ui.SELECT, ui.SORT, ui.CONFIRM]:
        if not self._song.isfolder:
          for pl, dname in enumerate(self._diff_names):
            name = self._pref_diff_names[pl]
            if name in self._song.diff_list:
               self._diff_names[pl] = name
            elif self._unify_difficulties(name) in self._song.diff_list:
               self._diff_names[pl] = self._unify_difficulties(name)
            else: 
              # if both name and the song's difficulty list can be indexed:
              # find the nearest defined difficulty
              if  (name in util.DIFFICULTY_LIST or
                  self._unify_difficulties(name) in util.DIFFICULTY_LIST) and \
                  reduce(lambda a,b: a and b in util.DIFFICULTY_LIST, 
                         self._song.diff_list , True ):
                name = self._unify_difficulties(name)
                namei = util.DIFFICULTY_LIST.index(name)
                diffi = [util.DIFFICULTY_LIST.index(d) for 
                                        d in self._song.diff_list]
                dds = [abs(d - namei) for d in diffi]
                self._diff_names[pl] = self._song.diff_list\
                                                          [dds.index(min(dds))]
              else: # no sensible way to resolve this: jump to middle of list
                difflen = len(self._song.diff_list)
                self._diff_names[pl] = self._song.diff_list[difflen/2]
          
      if ev in [ui.UP, ui.DOWN, ui.LEFT, ui.RIGHT, ui.SELECT, ui.CONFIRM]:
        if not self._song.isfolder:
          for i, name in enumerate(self._diff_names):
            rank = records.get(self._song.info["recordkey"],
                               name, self._game)[0]
            grade = grades.grades[self._config["grade"]].grade_by_rank(rank)
            self._diff_widgets[i].set(name,
                                      DIFF_COLORS.get(name, [127,127,127]),
                                      self._song.difficulty[name],
                                    grade)
      
      self.update()
      pid, ev = ui.ui.poll()
예제 #5
0
    def loop(self):
        pid, ev = ui.ui.poll()
        self._list.set_index(self._index)
        self._title.set_text(self._base_text + " - %d/%d" %
                             (self._index + 1, len(self._songitems)))
        while not (ev == ui.CANCEL and
                   (not self._folders or self._song.isfolder)):
            # Inactive player. If the event isn't set to ui.PASS, we try to use
            # the pid later, which will be bad.
            if pid >= len(self._diff_names):
                ev = ui.PASS
            elif pid >= 0 and ev in (ui.UP,
                                     ui.DOWN):  # Only use menuing UP/DOWN
                ev = ui.PASS
            elif pid < 0 and ev in (
                    ui.LEFT, ui.RIGHT):  # Need LEFT/RIGHT player-specific
                ev = ui.PASS
            elif ev == ui.UP:
                self._index -= 1
            elif ev == ui.DOWN:
                self._index += 1
            elif ev == ui.PGUP:
                self._index -= 7
                ev = ui.UP
            elif ev == ui.PGDN:
                self._index += 7
                ev = ui.DOWN

            elif ev == ui.LEFT:
                if not self._song.isfolder:
                    namei = self._song.diff_list.index(self._diff_names[pid])
                    namei = (namei - 1) % len(self._song.diff_list)
                    name = self._song.diff_list[namei]
                    self._diff_names[pid] = name
                    self._pref_diff_names[pid] = name
                    self._last_player = pid

            elif ev == ui.RIGHT:
                if not self._song.isfolder:
                    namei = self._song.diff_list.index(self._diff_names[pid])
                    namei = (namei + 1) % len(self._song.diff_list)
                    name = self._song.diff_list[namei]
                    self._diff_names[pid] = name
                    self._pref_diff_names[pid] = name
                    self._last_player = pid

            elif ev == ui.RANDOM:
                if self._song.isfolder:
                    if len(self._all_valid_songitems) > 0:
                        self._song = random.choice(self._all_valid_songitems)
                        fol = self._song.folder[SORT_NAMES[
                            mainconfig["sortmode"]]]
                        self._create_song_list(fol)
                        self._index = self._songitems.index(self._song)
                    else:
                        error.ErrorMessage(
                            screen,
                            _("You don't have any songs that are marked ") +
                            _("\"valid\" for random selection."))
                else:
                    valid_songs = [
                        s for s in self._songitems if s.info["valid"]
                    ]
                    if len(valid_songs) > 0:
                        self._song = random.choice(valid_songs)
                        self._index = self._songitems.index(self._song)
                    else:
                        error.ErrorMessage(
                            screen,
                            _("You don't have any songs here that ") +
                            _("are marked \"valid\" for random selection."))
            elif ev == ui.OPTIONS:
                opts = options.OptionScreen(self._configs, self._config,
                                            self._screen)
                self._screen.blit(self._bg, [0, 0])
                self.update()
                pygame.display.update()
                if opts.start_dancing:
                    ev = ui.CONFIRM
                    continue

            elif ev == ui.SORT:
                s = self._songitems[self._index]
                mainconfig["sortmode"] = (mainconfig["sortmode"] +
                                          1) % NUM_SORTS
                sort_name = self._update_songitems()
                if self._folders:
                    if s.isfolder:
                        self._create_folder_list()
                    else:
                        s = self._find_resorted()
                        self._create_song_list(s.folder[sort_name])
                        self._index = self._songitems.index(s)
                else:
                    s = self._find_resorted()
                    self._base_text = _(sort_name).upper()
                    self._songitems.sort(key=SORTS[sort_name])
                    self._index = self._songitems.index(s)
                    self._list.set_items(
                        [s.info["title"] for s in self._songitems])

            elif ev == ui.CONFIRM:
                if self._song.isfolder:
                    self._create_song_list(self._song.name)
                    self._index = 0
                else:
                    music.fadeout(500)
                    dance.play(self._screen,
                               [(self._song.filename, self._diff_names)],
                               self._configs, self._config, self._game)
                    music.fadeout(500)  # The just-played song
                    self._screen.blit(self._bg, [0, 0])
                    pygame.display.update()
                    ui.ui.clear()

            elif ev == ui.CANCEL:
                # first: get the parent folder of the active song
                sort_name = SORT_NAMES[mainconfig["sortmode"]]
                fol = folder_name(self._song.folder[sort_name], sort_name)
                # next: change folder
                self._create_folder_list()
                for d in self._diff_widgets:
                    d.set("None", [127, 127, 127], 0, "?")

                lst = [s.info["title"] for s in self._songitems]
                self._index = lst.index(fol)

            elif ev == ui.FULLSCREEN:
                mainconfig["fullscreen"] ^= 1
                pygame.display.toggle_fullscreen()

            self._index %= len(self._songitems)
            self._song = self._songitems[self._index]

            if self._locked and ev in [ui.LEFT, ui.RIGHT]:
                for i, sd in enumerate(self._diff_names):
                    self._diff_names[i] = self._diff_names[pid]
                    self._pref_diff_names[i] = self._diff_names[pid]

            if ev in [
                    ui.CANCEL, ui.UP, ui.DOWN, ui.RANDOM, ui.CONFIRM, ui.SORT
            ]:
                self._preview.preview(self._song)
                self._banner.set_song(self._song)

            if ev in [
                    ui.CANCEL, ui.UP, ui.DOWN, ui.RANDOM, ui.CONFIRM, ui.SORT
            ]:
                if ev == ui.UP: self._list.set_index(self._index, -1)
                elif ev == ui.DOWN: self._list.set_index(self._index, 1)
                else: self._list.set_index(self._index, 0)  # don't animate
                self._title.set_text(self._base_text + " - %d/%d" %
                                     (self._index + 1, len(self._songitems)))

            if ev in [ui.UP, ui.DOWN, ui.RANDOM, ui.SORT, ui.CONFIRM]:
                if not self._song.isfolder:
                    for pl, dname in enumerate(self._diff_names):
                        name = self._pref_diff_names[pl]
                        if name in self._song.diff_list:
                            self._diff_names[pl] = name
                        elif self._unify_difficulties(
                                name) in self._song.diff_list:
                            self._diff_names[pl] = self._unify_difficulties(
                                name)
                        else:
                            # if both name and the song's difficulty list can be indexed:
                            # find the nearest defined difficulty
                            if  (name in util.DIFFICULTY_LIST or
                                self._unify_difficulties(name) in util.DIFFICULTY_LIST) and \
                                reduce(lambda a,b: a and b in util.DIFFICULTY_LIST,
                                       self._song.diff_list , True ):
                                name = self._unify_difficulties(name)
                                namei = util.DIFFICULTY_LIST.index(name)
                                diffi = [
                                    util.DIFFICULTY_LIST.index(d)
                                    for d in self._song.diff_list
                                ]
                                dds = [abs(d - namei) for d in diffi]
                                self._diff_names[pl] = self._song.diff_list\
                                                                          [dds.index(min(dds))]
                            else:  # no sensible way to resolve this: jump to middle of list
                                difflen = len(self._song.diff_list)
                                self._diff_names[pl] = self._song.diff_list[
                                    difflen / 2]

            if ev in [
                    ui.UP, ui.DOWN, ui.LEFT, ui.RIGHT, ui.RANDOM, ui.CONFIRM
            ]:
                if not self._song.isfolder:
                    for i, name in enumerate(self._diff_names):
                        rank = records.get(self._song.info["recordkey"], name,
                                           self._game)[0]
                        grade = grades.grades[
                            self._config["grade"]].grade_by_rank(rank)
                        self._diff_widgets[i].set(
                            name, DIFF_COLORS.get(name, [127, 127, 127]),
                            self._song.difficulty[name], grade)

            self.update()
            pid, ev = ui.ui.poll()
예제 #6
0
  def loop(self):
    pid, ev = ui.ui.poll()
    root_idx = 0
    self._list.set_index(self._index)
    self._title.set_text(self._base_text + " - %d/%d" % (self._index + 1,
                                                         len(self._courses)))
    while not (ev == ui.CANCEL and
               (not self._folders or self._course.isfolder)):
      # Inactive player. If the event isn't set to ui.PASS, we try to use
      # the pid later, which will be bad.
      if pid >= len(self._configs): ev = ui.PASS
      
      elif ev == ui.UP: self._index -= 1
      elif ev == ui.DOWN: self._index += 1
      elif ev == ui.PGUP:
        self._index -= 4
        ev = ui.UP
      elif ev == ui.PGDN:
        self._index += 4
        ev = ui.DOWN

      elif ev == ui.SELECT:
        if self._course.isfolder:
          self._course = random.choice(self._all_courses)
          root_idx = [fol.name for fol in self._courses].index(self._course.folder[SORT_NAMES[mainconfig["sortmode"]]])
            
          fol = self._course.folder[SORT_NAMES[mainconfig["sortmode"]]]
          self._create_course_list(fol)
          self._index = self._courses.index(self._course)
        else:
          self._course = random.choice(self._courses)
          self._index = self._courses.index(self._course)

      elif ev == ui.SORT:
        s = self._courses[self._index]
        mainconfig["sortmode"] = (mainconfig["sortmode"] + 1) % NUM_SORTS
        if self._folders:
          if s.isfolder:
            self._create_folder_list()
          else:
            self._create_course_list(s.folder[SORT_NAMES[mainconfig["sortmode"]]])
            self._index = self._courses.index(s)
        else:
          self._courses.sort(SORTS[SORT_NAMES[mainconfig["sortmode"]]])
          self._index = self._courses.index(s)
          self._list.set_items([s.name for s in self._courses])

      elif ev == ui.START:
        options.OptionScreen(self._configs, self._config, self._screen)
        self._screen.blit(self._bg, [0, 0])
        self.update()
        pygame.display.update()

      elif ev == ui.CONFIRM:
        if self._course.isfolder:
          self._create_course_list(self._course.name)
          root_idx = self._index
          self._index = 0
        else:
          music.fadeout(500)
          course = self._course.course
          course.setup(self._screen, self._configs, self._config, self._game)
          dance.play(self._screen, course, self._configs,
                     self._config, self._game)
          course.done()
          music.fadeout(500) # The just-played song
          self._screen.blit(self._bg, [0, 0])
          pygame.display.update()
          ui.ui.empty()
          ui.ui.clear()

      elif ev == ui.CANCEL:
        self._create_folder_list()
        self._index = root_idx

      elif ev == ui.FULLSCREEN:
        mainconfig["fullscreen"] ^= 1
        pygame.display.toggle_fullscreen()

      self._index %= len(self._courses)
      self._course = self._courses[self._index]

      if ev in [ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT]:
        if ev == ui.UP: self._list.set_index(self._index, -1)
        elif ev == ui.DOWN: self._list.set_index(self._index, 1)
        else: self._list.set_index(self._index, 0) # don't animate
        self._course.render()
        self._coursetitle.set_text(self._course.name)
        self._banner.set_image(self._course.banner)
        self._list_gfx.set_image(self._course.image)
        self._title.set_text(self._base_text +
                             " - %d/%d" % (self._index + 1,
                                           len(self._courses)))
      self.update()
      pid, ev = ui.ui.poll()
예제 #7
0
    def loop(self):
        pid, ev = ui.ui.poll()
        root_idx = 0
        self._list.set_index(self._index)
        self._title.set_text(self._base_text + " - %d/%d" %
                             (self._index + 1, len(self._courses)))
        while not (ev == ui.CANCEL and
                   (not self._folders or self._course.isfolder)):
            # Inactive player. If the event isn't set to ui.PASS, we try to use
            # the pid later, which will be bad.
            if pid >= len(self._configs): ev = ui.PASS

            elif ev == ui.UP: self._index -= 1
            elif ev == ui.DOWN: self._index += 1
            elif ev == ui.PGUP:
                self._index -= 4
                ev = ui.UP
            elif ev == ui.PGDN:
                self._index += 4
                ev = ui.DOWN

            elif ev == ui.SELECT:
                if self._course.isfolder:
                    self._course = random.choice(self._all_courses)
                    root_idx = [fol.name for fol in self._courses
                                ].index(self._course.folder[SORT_NAMES[
                                    mainconfig["sortmode"]]])

                    fol = self._course.folder[SORT_NAMES[
                        mainconfig["sortmode"]]]
                    self._create_course_list(fol)
                    self._index = self._courses.index(self._course)
                else:
                    self._course = random.choice(self._courses)
                    self._index = self._courses.index(self._course)

            elif ev == ui.SORT:
                s = self._courses[self._index]
                mainconfig["sortmode"] = (mainconfig["sortmode"] +
                                          1) % NUM_SORTS
                if self._folders:
                    if s.isfolder:
                        self._create_folder_list()
                    else:
                        self._create_course_list(
                            s.folder[SORT_NAMES[mainconfig["sortmode"]]])
                        self._index = self._courses.index(s)
                else:
                    self._courses.sort(
                        SORTS[SORT_NAMES[mainconfig["sortmode"]]])
                    self._index = self._courses.index(s)
                    self._list.set_items([s.name for s in self._courses])

            elif ev == ui.START:
                options.OptionScreen(self._configs, self._config, self._screen)
                self._screen.blit(self._bg, [0, 0])
                self.update()
                pygame.display.update()

            elif ev == ui.CONFIRM:
                if self._course.isfolder:
                    self._create_course_list(self._course.name)
                    root_idx = self._index
                    self._index = 0
                else:
                    music.fadeout(500)
                    course = self._course.course
                    course.setup(self._screen, self._configs, self._config,
                                 self._game)
                    dance.play(self._screen, course, self._configs,
                               self._config, self._game)
                    course.done()
                    music.fadeout(500)  # The just-played song
                    self._screen.blit(self._bg, [0, 0])
                    pygame.display.update()
                    ui.ui.empty()
                    ui.ui.clear()

            elif ev == ui.CANCEL:
                self._create_folder_list()
                self._index = root_idx

            elif ev == ui.FULLSCREEN:
                mainconfig["fullscreen"] ^= 1
                pygame.display.toggle_fullscreen()

            self._index %= len(self._courses)
            self._course = self._courses[self._index]

            if ev in [
                    ui.CANCEL, ui.UP, ui.DOWN, ui.SELECT, ui.CONFIRM, ui.SORT
            ]:
                if ev == ui.UP: self._list.set_index(self._index, -1)
                elif ev == ui.DOWN: self._list.set_index(self._index, 1)
                else: self._list.set_index(self._index, 0)  # don't animate
                self._course.render()
                self._coursetitle.set_text(self._course.name)
                self._banner.set_image(self._course.banner)
                self._list_gfx.set_image(self._course.image)
                self._title.set_text(self._base_text + " - %d/%d" %
                                     (self._index + 1, len(self._courses)))
            self.update()
            pid, ev = ui.ui.poll()
예제 #8
0
    def __init__(self, songitems, courses, screen, gametype):
        InterfaceWindow.__init__(self, screen, "endless-bg.png")
        pygame.display.update()

        self.player_configs = [dict(player_config)]

        if games.GAMES[gametype].players == 2:
            self.player_configs.append(dict(player_config))

        self.game_config = dict(game_config)
        songitems = [s for s in songitems if s.difficulty.has_key(gametype)]
        # Autofail always has to be on for endless, so back up the old value.
        oldaf = mainconfig["autofail"]
        diffs = []
        diff_count = {}  # if we see a difficulty 2 times or more, use it
        for song in songitems:
            if song.difficulty.has_key(gametype):
                for d in song.difficulty[gametype]:
                    if diff_count.has_key(d) and d not in diffs:
                        diffs.append(d)
                    else:
                        diff_count[d] = True

        diffs.sort(util.difficulty_sort)

        if len(diffs) == 0:
            error.ErrorMessage(
                screen,
                _("You need more songs to play Endless Mode. ") +
                _("Otherwise, it's just really boring."))
            return

        mainconfig["autofail"] = 1

        self.constraints = [
            Constraint("name", songitems[0].difficulty[gametype].keys()[0])
        ]

        if games.GAMES[gametype].players == 2:
            if games.GAMES[gametype].couple == True:
                # Lock both players to the same constraints in couple modes.
                self.constraints.append(self.constraints[0])
            else:
                c = Constraint("name",
                               songitems[0].difficulty[gametype].keys()[0])
                self.constraints.append(c)

        for i, c in enumerate(self.constraints):
            EndlessDiffDisplay(i, c).add(self._sprites)

        self._sprites.add(
            HelpText(ENDLESS_HELP, [255, 255, 255], [0, 0, 0], FontTheme.help,
                     [320, 20]))

        music.load(os.path.join(sound_path, "menu.ogg"))
        music.play(4, 0.0)

        pid, ev = 0, ui.PASS

        while ev != ui.QUIT:
            pid, ev = ui.ui.poll()

            if ev == ui.START:
                options.OptionScreen(self.player_configs, self.game_config,
                                     screen)
                self._screen.blit(self._bg, [0, 0])
                pygame.display.update()

            # Start game
            elif ev == ui.CONFIRM:
                dance.play(
                    screen,
                    FakePlaylist(songitems, self.constraints, screen,
                                 gametype), self.player_configs,
                    self.game_config, gametype)

                self._screen.blit(self._bg, [0, 0])
                pygame.display.update()
                music.load(os.path.join(sound_path, "menu.ogg"))
                music.play(4, 0.0)
                ui.ui.clear()

            # Ignore unknown events
            elif pid >= len(self.constraints):
                pass

            elif ev == ui.DOWN and self.constraints[pid].kind != "name":
                self.constraints[pid].kind = "name"
                self.constraints[pid].value = diffs[0]
            elif ev == ui.UP and self.constraints[pid].kind != "number":
                self.constraints[pid].kind = "number"
                self.constraints[pid].value = (1, 3)
            elif ev == ui.LEFT:  # easier
                if self.constraints[pid].kind == "name":
                    newi = max(0, diffs.index(self.constraints[pid].value) - 1)
                    self.constraints[pid].value = diffs[newi]
                elif self.constraints[pid].kind == "number":
                    newmin = max(self.constraints[pid].value[0] - 1, 1)
                    self.constraints[pid].value = (newmin, newmin + 2)

            elif ev == ui.RIGHT:  # harder
                if self.constraints[pid].kind == "name":
                    newi = min(
                        len(diffs) - 1,
                        diffs.index(self.constraints[pid].value) + 1)
                    self.constraints[pid].value = diffs[newi]
                elif self.constraints[pid].kind == "number":
                    newmin = min(self.constraints[pid].value[0] + 1, 9)
                    self.constraints[pid].value = (newmin, newmin + 2)

            elif ev == ui.FULLSCREEN:
                mainconfig["fullscreen"] ^= 1
                pygame.display.toggle_fullscreen()

            self.update()

        mainconfig["autofail"] = oldaf
        player_config.update(self.player_configs[0])
예제 #9
0
파일: endless.py 프로젝트: EvilDrW/pydance
  def __init__(self, songitems, courses, screen, gametype):
    InterfaceWindow.__init__(self, screen, "endless-bg.png");
    pygame.display.update()

    self.player_configs = [dict(player_config)]

    if games.GAMES[gametype].players == 2:
      self.player_configs.append(dict(player_config))

    self.game_config = dict(game_config)
    songitems = [s for s in songitems if s.difficulty.has_key(gametype)]
    # Autofail always has to be on for endless, so back up the old value.
    oldaf = mainconfig["autofail"]
    diffs = []
    diff_count = {} # if we see a difficulty 2 times or more, use it
    for song in songitems:
      if song.difficulty.has_key(gametype):
        for d in song.difficulty[gametype]:
          if diff_count.has_key(d) and d not in diffs : diffs.append(d)
          else: diff_count[d] = True

    diffs.sort(util.difficulty_sort)

    if len(diffs) == 0:
      error.ErrorMessage(screen, _("You need more songs to play Endless Mode. ") +
                         _("Otherwise, it's just really boring."))
      return

    mainconfig["autofail"] = 1

    self.constraints = [Constraint("name", songitems[0].difficulty[gametype].keys()[0])]

    if games.GAMES[gametype].players == 2:
      if games.GAMES[gametype].couple == True:
        # Lock both players to the same constraints in couple modes.
        self.constraints.append(self.constraints[0])
      else:
        c = Constraint("name", songitems[0].difficulty[gametype].keys()[0])
        self.constraints.append(c)

    for i, c in enumerate(self.constraints):
      EndlessDiffDisplay(i, c).add(self._sprites)

    self._sprites.add(HelpText(ENDLESS_HELP, [255, 255, 255], [0, 0, 0],
                               FontTheme.help, [320, 20]))

    music.load(os.path.join(sound_path, "menu.ogg"))
    music.play(4, 0.0)

    pid, ev = 0, ui.PASS

    while ev != ui.QUIT:
      pid, ev = ui.ui.poll()

      if ev == ui.START:
        options.OptionScreen(self.player_configs, self.game_config, screen)
        self._screen.blit(self._bg, [0, 0])
        pygame.display.update()

      # Start game
      elif ev == ui.CONFIRM:
        dance.play(screen, FakePlaylist(songitems, self.constraints,
                                        screen, gametype),
                   self.player_configs, self.game_config, gametype)

        self._screen.blit(self._bg, [0, 0])
        pygame.display.update()
        music.load(os.path.join(sound_path, "menu.ogg"))
        music.play(4, 0.0)
        ui.ui.clear()

      # Ignore unknown events
      elif pid >= len(self.constraints): pass

      elif ev == ui.DOWN and self.constraints[pid].kind != "name":
        self.constraints[pid].kind = "name"
        self.constraints[pid].value = diffs[0]
      elif ev == ui.UP and self.constraints[pid].kind != "number":
        self.constraints[pid].kind = "number"
        self.constraints[pid].value = (1, 3)
      elif ev == ui.LEFT: # easier
        if self.constraints[pid].kind == "name":
          newi = max(0, diffs.index(self.constraints[pid].value) - 1)
          self.constraints[pid].value = diffs[newi]
        elif self.constraints[pid].kind == "number":
          newmin = max(self.constraints[pid].value[0] - 1, 1)
          self.constraints[pid].value = (newmin, newmin + 2)

      elif ev == ui.RIGHT: # harder
        if self.constraints[pid].kind == "name":
          newi = min(len(diffs) - 1,
                     diffs.index(self.constraints[pid].value) + 1)
          self.constraints[pid].value = diffs[newi]
        elif self.constraints[pid].kind == "number":
          newmin = min(self.constraints[pid].value[0] + 1, 9)
          self.constraints[pid].value = (newmin, newmin + 2)

      elif ev == ui.FULLSCREEN:
        mainconfig["fullscreen"] ^= 1
        pygame.display.toggle_fullscreen()

      self.update()

    mainconfig["autofail"] = oldaf
    player_config.update(self.player_configs[0])