Beispiel #1
0
    Regraph(available_graphs[ 0 ])
    graph_num = 0

    # then...
    
    proceed = menu.Menu( 
                [(None, None, []),
                (MENU_PREV, "Previous Graph", []),
                (MENU_NEXT, "Next Graph", []),
                (None, None, []),
                (MENU_MENU, "Continue", [ K_ESCAPE ])])

    quit = False
    while ( not quit ):
        (quit, cmd) = extra.Simple_Menu_Loop(screen, 
                    proceed, (( width * 3 ) / 4, height / 2 ))

        if ( cmd == MENU_MENU ):
            quit = True
        elif ( cmd == MENU_PREV ):
            graph_num = (( graph_num + len(available_graphs) - 1 )
                                % len(available_graphs))
            Regraph(available_graphs[ graph_num ])
        elif ( cmd == MENU_NEXT ):
            graph_num = ( graph_num + 1 ) % len(available_graphs)
            Regraph(available_graphs[ graph_num ])


    return

Beispiel #2
0
def Main_Menu_Loop(name, clock, screen, xxx_todo_changeme):
    # Further initialisation
    (width, height) = xxx_todo_changeme
    menu_image = resource.Load_Image("mainmenu.jpg")

    if (menu_image.get_rect().width != width):
        menu_image = pygame.transform.scale(menu_image, (width, height))

    stats.Set_Font_Scale(config.cfg.font_scale)

    main_menu = current_menu = menu.Menu([
        (None, None, []), (MENU_TUTORIAL, "Play Tutorial", []),
        (MENU_NEW_GAME, "Play New Game", []), (MENU_LOAD, "Restore Game", []),
        (None, None, []), (MENU_RES, "Set Graphics Resolution", []),
        (MENU_MUTE, "Toggle Sound", []), (MENU_MANUAL, "View Manual", []),
        (MENU_UPDATES, "Check for Updates", []), (None, None, []),
        (MENU_QUIT, "Exit to " + extra.Get_OS(), [K_ESCAPE, K_F10])
    ])
    resolution_menu = menu.Menu([(None, None, [])] +
                                [(w, "%u x %u" % (w, h), [])
                                 for (w, h, fs) in RESOLUTIONS] +
                                [(None, None, []), (-1, "Cancel", [])])
    difficulty_menu = menu.Menu([(None, None, []),
                                 (MENU_TUTORIAL, "Tutorial", []),
                                 (None, None, []),
                                 (MENU_BEGINNER, "Beginner", []),
                                 (MENU_INTERMEDIATE, "Intermediate", []),
                                 (MENU_EXPERT, "Expert", []), (None, None, []),
                                 (MENU_PEACEFUL, "Peaceful", []),
                                 (None, None, []), (-1, "Cancel", [])])

    copyright = [
        name, "Copyright (C) Jack Whitham 2006-11 - website: www.jwhitham.org",
        None, "Game version " + config.CFG_VERSION
    ]

    # off we go.

    quit = False
    while (not quit):
        # Main menu
        screen.fill((0, 0, 0))
        screen.blit(menu_image, (0, 0))

        y = 5
        sz = 11
        for text in copyright:
            if (text == None):
                sz = 7
                continue
            img = stats.Get_Font(sz).render(text, True, (200, 200, 128))
            img_r = img.get_rect()
            img_r.center = ((width * 3) / 4, 0)
            img_r.clamp_ip(screen.get_rect())
            img_r.top = y
            screen.blit(img, img_r.topleft)
            y += img_r.height

        (quit,
         cmd) = extra.Simple_Menu_Loop(screen, current_menu,
                                       ((width * 3) / 4, 10 + (height / 2)))

        if (current_menu == main_menu):
            if (cmd == MENU_NEW_GAME):
                current_menu = difficulty_menu

            elif (cmd == MENU_TUTORIAL):
                quit = game.Main_Loop(screen, clock, (width, height), None,
                                      MENU_TUTORIAL)

            elif (cmd == MENU_LOAD):
                current_menu = save_menu.Save_Menu(False)

            elif (cmd == MENU_QUIT):
                quit = True

            elif (cmd == MENU_MUTE):
                config.cfg.mute = not config.cfg.mute
                return False  # update menu

            elif (cmd == MENU_RES):
                current_menu = resolution_menu

            elif (cmd == MENU_UPDATES):
                if Update_Feature(screen, menu_image):
                    url = (CGISCRIPT + "v=" + startup.Get_Game_Version())

                    pygame.display.iconify()
                    try:
                        webbrowser.open(url, True, True)
                    except:
                        pass

            elif (cmd == MENU_MANUAL):
                pygame.display.iconify()
                if os.path.isfile(DEB_MANUAL):
                    # Debian manual present
                    url = 'file://' + DEB_MANUAL
                else:
                    base = os.path.abspath(
                        resource.Path(
                            os.path.join("..", "manual", "index.html")))
                    if os.path.isfile(base):
                        # Upstream package manual present
                        url = 'file://' + base
                    else:
                        # No manual? Redirect to website.
                        url = 'http://www.jwhitham.org/20kly/'

                try:
                    webbrowser.open(url, True, True)
                except:
                    pass

        elif (cmd != None):
            if (current_menu == resolution_menu):
                for (w, h, fs) in RESOLUTIONS:
                    if (w == cmd):
                        config.cfg.resolution = (w, h)
                        config.cfg.font_scale = fs
                        # change res - don't quit
                        return False

            elif (current_menu == difficulty_menu):
                if (cmd >= 0):
                    quit = game.Main_Loop(screen, clock, (width, height), None,
                                          cmd)

            else:  # Load menu
                if (cmd >= 0):
                    # Start game from saved position
                    quit = game.Main_Loop(screen, clock, (width, height), cmd,
                                          None)

            current_menu = main_menu

    return True
Beispiel #3
0
        y = 5
        sz = 11
        for text in copyright:
            if (text == None):
                sz = 7
                continue
            img = stats.Get_Font(sz).render(text, True, (200, 200, 128))
            img_r = img.get_rect()
            img_r.center = ((width * 3) / 4, 0)
            img_r.clamp_ip(screen.get_rect())
            img_r.top = y
            screen.blit(img, img_r.topleft)
            y += img_r.height

        (quit,
         cmd) = extra.Simple_Menu_Loop(screen, current_menu,
                                       ((width * 3) / 4, 10 + (height / 2)))

        if (current_menu == main_menu):
            if (cmd == MENU_NEW_GAME):
                current_menu = difficulty_menu

            elif (cmd == MENU_TUTORIAL):
                quit = game.Main_Loop(screen, clock, (width, height), None,
                                      MENU_TUTORIAL)

            elif (cmd == MENU_LOAD):
                current_menu = save_menu.Save_Menu(False)

            elif (cmd == MENU_QUIT):
                quit = True
Beispiel #4
0
def Review(screen, xxx_todo_changeme2, game_object, historian):

    (width, height) = xxx_todo_changeme2
    g = game_object
    extra.Tile_Texture(screen, "006metal.jpg", screen.get_rect())

    def Text(str, size, xxx_todo_changeme, justify):
        (x, y) = xxx_todo_changeme
        img = stats.Get_Font(size).render(str, True, (255, 255, 255))

        if (justify == 0):  # centre
            x -= (img.get_rect().width) / 2
        elif (justify < 0):  # right
            x -= img.get_rect().width

        screen.blit(img, (x, y))
        y += img.get_rect().height
        return y + 5

    if (g.win):
        y = Text("You have won the game!", 36, (width / 2, 10), 0)
    else:
        y = Text("You have lost the game!", 36, (width / 2, 10), 0)

    Text("Thankyou for playing!", 15, (width / 2, y), 0)

    y += height / 10

    lev = dict()
    lev[MENU_TUTORIAL] = lev[MENU_BEGINNER] = "Beginner"
    lev[MENU_INTERMEDIATE] = "Intermediate"
    lev[MENU_EXPERT] = "Expert"
    lev[MENU_PEACEFUL] = "Peaceful"
    if (g.challenge not in lev):
        level = "??"
    else:
        level = lev[g.challenge]

    score = float(g.net.hub.total_steam) / float(g.game_time.Get_Day())
    if (g.win):
        score *= 8

    score = int(score)

    l = [("Game length", "%u days" % g.game_time.Get_Day()),
         ("Steam used", "%1.1f U" % g.net.hub.total_steam),
         ("Unused work units", "%u" % g.wu_integral), ("Game level", level),
         ("Your " + level + " Score", "%u" % score)]

    r = Rect(25, y, width / 2, 1)
    y = Text("Summary", 18, r.center, 0)

    for (key, data) in l:
        Text(key, 18, (r.left, y), 1)
        y = Text(data, 18, (r.right, y), -1)

    r.height = y - r.top
    r = r.inflate(10, 10)
    pygame.draw.rect(screen, (128, 128, 128), r, 2)

    y = r.bottom + (height / 10)

    graph_window = Rect(r.left, y, r.width, (height - y) - 25)

    available_graphs = [("Steam Supply", "supply", (0, 255, 0)),
                        ("Steam Demand", "demand", (255, 0, 0)),
                        ("Number of Nodes", "num_nodes", (128, 128, 0)),
                        ("Number of Pipes", "num_pipes", (0, 128, 0)),
                        ("City Technology Level", "tech_level", (255, 255, 0)),
                        ("Work Unit Usage", "work_units_used", (255, 0, 255)),
                        ("Work Unit Availability", "work_units_avail", (0, 255,
                                                                        255)),
                        ("City Steam Pressure", "city_pressure", (0, 0, 255))]

    def Regraph(xxx_todo_changeme1):
        (heading, attribute, colour) = xxx_todo_changeme1
        pygame.draw.rect(screen, (0, 0, 0), graph_window)
        pygame.draw.rect(screen, (128, 128, 128), graph_window, 2)

        graph_subwin = graph_window.inflate(-25, -25)
        (x, y) = graph_subwin.center
        y = graph_window.top + 5
        Text(heading, 18, (x, y), 0)

        text_margin = 30

        graph_subwin.height -= text_margin
        graph_subwin.top += text_margin

        if (len(historian) == 0):
            print("Historian has no data - no graph available")
            return

        max_gt = max_gy = 0
        values = []
        for hr in historian:
            try:
                gy = getattr(hr, attribute)
            except Attribute_Error:
                print("Attribute", attribute, "not present")
                return

            if (gy < 0):
                gy = 0  # This should not happen
            gt = hr.day

            values.append((gt, gy))

            if (gt > max_gt):
                max_gt = gt
            if (gy > max_gy):
                max_gy = gy

        if ((max_gt <= 0) or (max_gy <= 0)):
            print("Graph not available (/0)")
            return

        def Calc_Step_Max(maximum, number_of_steps):
            step = int((float(maximum) / float(number_of_steps)) + 1)
            if (step < 1):
                step = 1

            return (step, int(step * number_of_steps))

        (step_gt, max_gt) = Calc_Step_Max(max_gt, 20)
        (step_gy, max_gy) = Calc_Step_Max(max_gy, 10)

        t_scale = float(graph_subwin.width) / float(max_gt)
        y_scale = -1.0 * (float(graph_subwin.height) / float(max_gy))

        # Vertical divisions
        for gt in range(0, max_gt, step_gt):
            x = int(gt * t_scale) + graph_subwin.left
            pygame.draw.line(screen, (55, 55, 55), (x, graph_subwin.bottom),
                             (x, graph_subwin.top))
            pygame.draw.line(screen, (255, 255, 255), (x, graph_subwin.bottom),
                             (x, graph_subwin.bottom - 2))

        # Horizontal divisions
        for gy in range(0, max_gy, step_gy):
            y = int(gy * y_scale) + graph_subwin.bottom
            pygame.draw.line(screen, (75, 75, 75), (graph_subwin.left, y),
                             (graph_subwin.right, y))
            pygame.draw.line(screen, (75, 75, 75), (graph_subwin.left, y),
                             (graph_subwin.left + 2, y))

        # Graph line
        (x1, y1) = graph_subwin.bottomleft
        for (gt, gy) in values:
            x = int(gt * t_scale) + graph_subwin.left
            y = int(gy * y_scale) + graph_subwin.bottom
            pygame.draw.line(screen, colour, (x1, y1), (x, y))
            (x1, y1) = (x, y)

        # Graph border
        pygame.draw.line(screen, (255, 255, 255), graph_subwin.topleft,
                         graph_subwin.bottomleft)
        pygame.draw.line(screen, (255, 255, 255), graph_subwin.bottomright,
                         graph_subwin.bottomleft)

    Regraph(available_graphs[0])
    graph_num = 0

    # then...

    proceed = menu.Menu([(None, None, []), (MENU_PREV, "Previous Graph", []),
                         (MENU_NEXT, "Next Graph", []), (None, None, []),
                         (MENU_MENU, "Continue", [K_ESCAPE])])

    quit = False
    while (not quit):
        (quit, cmd) = extra.Simple_Menu_Loop(screen, proceed,
                                             ((width * 3) / 4, height / 2))

        if (cmd == MENU_MENU):
            quit = True
        elif (cmd == MENU_PREV):
            graph_num = ((graph_num + len(available_graphs) - 1) %
                         len(available_graphs))
            Regraph(available_graphs[graph_num])
        elif (cmd == MENU_NEXT):
            graph_num = (graph_num + 1) % len(available_graphs)
            Regraph(available_graphs[graph_num])

    return
Beispiel #5
0
def Main_Menu_Loop():
    # Update resolution
    (width, height) = screen.Update_Resolution()

    # Further initialisation
    menu_image = resource.Load_Image("mainmenu.jpg")
    menu_rect = menu_image.get_rect()
    sr = screen.surface.get_rect()

    if menu_rect.size != sr.size:
        menu_rect = menu_rect.fit(sr)
        menu_image = pygame.transform.scale(menu_image, menu_rect.size)

    font.Scale_Font(height)

    main_menu = current_menu = menu.Menu([
        (None, None, []),
        #(MENU_TUTORIAL, "Play Tutorial", []),
        (MENU_NEW_GAME, "Play New Game", []),
        (MENU_LOAD, "Restore Game", []),
        (None, None, []),
        (MENU_MUTE, "Toggle Sound", []),
        (MENU_MANUAL, "View Manual", []),
        (MENU_UPDATES, "Check for Updates", []),
        (None, None, []),
        (MENU_QUIT, "Exit to " + extra.Get_OS(), [K_ESCAPE, K_F10])
    ])
    difficulty_menu = menu.Menu([
        (None, None, []),
        #(MENU_TUTORIAL, "Tutorial", []),
        #(None, None, []),
        (MENU_BEGINNER, "Beginner", []),
        (MENU_INTERMEDIATE, "Intermediate", []),
        (MENU_EXPERT, "Expert", []),
        (None, None, []),
        (-1, "Cancel", [])
    ])

    copyright = [
        NAME, "Copyright (C) Jack Whitham 2006-11 - website: www.jwhitham.org",
        None, "Game version " + startup.Get_Game_Version()
    ]

    # off we go.

    while True:
        # Main menu loop
        screen.surface.fill(BLACK)
        screen.surface.blit(menu_image, menu_rect.topleft)

        y = 5
        sz = 11
        for text in copyright:
            if (text == None):
                sz = 7
                continue
            img = font.Get_Font(sz).render(text, True, COPYRIGHT)
            img_r = img.get_rect()
            img_r.center = ((width * 3) / 4, 0)
            img_r.clamp_ip(screen.surface.get_rect())
            img_r.top = y
            screen.surface.blit(img, img_r.topleft)
            y += img_r.height

        (quit,
         cmd) = extra.Simple_Menu_Loop(current_menu,
                                       ((width * 3) / 4, 10 + (height / 2)))

        if (quit):
            return MENU_QUIT

        if (cmd == MENU_RESIZE_EVENT):
            # Sent to outer loop, reinitialisation will be required
            return MENU_RESIZE_EVENT

        elif (current_menu == main_menu):
            if (cmd == MENU_NEW_GAME):
                current_menu = difficulty_menu

            elif (cmd == MENU_TUTORIAL):
                return MENU_TUTORIAL

            elif (cmd == MENU_LOAD):
                current_menu = save_menu.Save_Menu(False)

            elif (cmd == MENU_QUIT):
                return MENU_QUIT

            elif (cmd == MENU_MUTE):
                config.cfg.mute = not config.cfg.mute

            elif (cmd == MENU_UPDATES):
                if Update_Feature(screen, menu_image):
                    url = (CGISCRIPT + "v=" + startup.Get_Game_Version())

                    pygame.display.iconify()
                    try:
                        webbrowser.open(url, True, True)
                    except:
                        pass

            elif (cmd == MENU_MANUAL):
                if os.path.isfile(DEB_MANUAL):
                    # Debian manual present
                    url = 'file://' + DEB_MANUAL
                else:
                    base = os.path.abspath(
                        resource.Path(
                            os.path.join("..", "manual", "index.html")))
                    if os.path.isfile(base):
                        # Upstream package manual present
                        url = 'file://' + base
                    else:
                        # No manual? Redirect to website.
                        url = 'http://www.jwhitham.org/20kly/'

                pygame.display.iconify()
                try:
                    webbrowser.open(url, True, True)
                except:
                    pass

        elif (cmd != None):
            if (current_menu == difficulty_menu):
                if (cmd >= 0):
                    # Start game at specified difficulty
                    return cmd

            else:  # Load menu
                if (cmd >= 0):
                    # Start game from saved position
                    return cmd

            current_menu = main_menu