Exemple #1
0
def close(r):
    """This is a convenient function for closing for when the room is in your namespace"""
    if pygame.event.get(pygame.QUIT):
        print "Trying to quit properly..."
        game_progress.save_game(r)
        game_settings.save_settings()
        return True
    else:
        return False
Exemple #2
0
    def modify_setting(self):
        if self.setting in want_bools:
            settings[self.setting] = not settings[self.setting]
        elif self.setting in want_ints and self.setting in max_val and self.setting in min_val:
            settings[self.setting] += 1
            if settings[self.setting] > max_val[self.setting]:
                settings[self.setting] = min_val[self.setting]
        else:
            messages.colorBackground()
            # messages.say("Pick a new value", down = 4)

            allowed_keys = range(
                pygame.K_0, pygame.K_9 + 1)
            allowed_keys += [pygame.K_PERIOD]
            allowed_keys += [pygame.K_e]
            allowed_keys += [pygame.K_MINUS]

            '''loop is for error checking'''
            while True:
                # message = messages.smallfont.render("Set new value for '%s'" % toChange, 1, [255, 255, 255])
                # pygame.display.get_surface().blit(message, (600, 15 * (usedindex + 3)))
                m = "Set new value for '%s'" % self.setting
                position = pygame.Rect(0, 0, 290, 30)
                # position.x = 600 #Leaning right
                position.centerx = graphics.screen_w / 2
                # position.y = 15 * (usedindex + 4.3)
                # Leaning up
                position.centery = graphics.screen_h / 2
                out = getString(
                    allowed_keys, str(settings[self.setting]), textpos=position, message=m)
                # out = getString(allowed_keys, str(settings[toChange]))

                # quit
                if out == -1:
                    break

                # cancel
                elif out == 0:
                    break

                try:
                    val = 0
                    if "." in out:
                        val = float(out)
                    else:
                        val = int(out)

                    problems = problem_with_setting(
                        self.setting, val)
                    if problems:
                        messages.colorBackground()
                        messages.say(problems, down=4)
                        continue

                    settings[self.setting] = val
                    break

                except:
                    messages.colorBackground()
                    messages.say(
                        "Error. Pick a new value", down=4)

            save_settings()
        self.needs_update = True