Esempio n. 1
0
def Render(text, size, colour, hcolour):
   
    i = text.find('&')
    if ( i < 0 ):
        # not found, do normal render
        return stats.Get_Font(size).render(text, True, colour)

    f = stats.Get_Font(size)
    # do normal render up to &.
    s1 = f.render(text[ : i ], True, colour)
    
    i += 1
    s2 = f.render(text[ i ], True, hcolour)

    i += 1
    s3 = f.render(text[ i : ], True, colour)

    total_width = sum([ s.get_rect().width for s in [ s1, s2, s3 ] ])
    s = pygame.Surface((total_width, s3.get_rect().height))
    s.set_colorkey((0,0,0))

    x = 0
    s.blit(s1,(x,0))
    x += s1.get_rect().width
    s.blit(s2,(x,0))
    x += s2.get_rect().width
    s.blit(s3,(x,0))
    return s
Esempio n. 2
0
    def Message(msg_list):
        screen.blit(menu_image, (0, 0))

        y = screen.get_rect().centery
        for msg in msg_list:
            img_1 = stats.Get_Font(24).render(msg, True, (255, 255, 255))
            img_2 = stats.Get_Font(24).render(msg, True, (0, 0, 0))
            img_r = img_1.get_rect()
            img_r.centerx = screen.get_rect().centerx
            img_r.centery = y
            screen.blit(img_2, img_r.topleft)
            screen.blit(img_1, img_r.move(2, -2).topleft)
            y += img_r.height
        pygame.display.flip()
    def Draw_Mini(self, output, xxx_todo_changeme4 ):
        (x,y) = xxx_todo_changeme4
        (x1,y1) = Grid_To_Scr(self.n1.pos)
        (x2,y2) = Grid_To_Scr(self.n2.pos)
        x1 -= x ; x2 -= x
        y1 -= y ; y2 -= y

        if ( self.Needs_Work() ):
            c = (255,0,0)
        else:
            c = self.Get_Diagram_Colour()

        pygame.draw.line(output, c, (x1,y1), (x2,y2), 2)

        if ( not self.Needs_Work() ):
            mx = ( x1 + x2 ) / 2
            my = ( y1 + y2 ) / 2
            if ( output.get_rect().collidepoint((mx,my)) ):
                info_text = "%1.1f U" % abs(self.current_n1_to_n2)
                info_surf = stats.Get_Font(12).render(info_text, True, c)
                r2 = info_surf.get_rect()
                r2.center = (mx,my)
                r = Rect(r2)
                r.width += 4
                r.center = (mx,my)
                pygame.draw.rect(output, (0, 40, 0), r)
                output.blit(info_surf, r2.topleft)
Esempio n. 4
0
    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
Esempio n. 5
0
def Review():

    g = game.game
    historian = game.game.historian
    (width, height) = screen.surface.get_rect().size
    extra.Tile_Texture(screen.surface, "006metal.jpg",
                       screen.surface.get_rect())

    def Text(str, size, (x, y), justify):
        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.surface.blit(img, (x, y))
        y += img.get_rect().height
        return y + 5
Esempio n. 6
0
    def __Draw_H(self, title, text, height):
        width = self.width
        margin = 10
        fs1 = 12
        fs2 = 14
        newline_gap = 12

        surf = pygame.Surface((width, height))
        bbox = surf.get_rect()
        extra.Tile_Texture(surf, "006metal.jpg", bbox)
        
        tsurf = stats.Get_Font(fs1).render(title, True, (250,250,200))
        tsurf_r = tsurf.get_rect()
        tsurf_r.center = bbox.center
        tsurf_r.top = margin

        surf.blit(tsurf, tsurf_r.topleft)

        y = tsurf_r.bottom + margin
        # line edging for title
        extra.Line_Edging(surf, Rect(0,0,width,y), True)

        y += margin
        x = margin
        height = y
        
        while ( len(text) != 0 ):
            newline = False
            i = text.find(' ')
            j = text.find("\n")

            if (( j >= 0 ) and ( j < i )):
                i = j
                newline = True

            if ( i < 0 ):
                i = len(text)

            word = text[ : i ] + " "
            text = text[ i + 1 : ].lstrip()

            tsurf = stats.Get_Font(fs2).render(word, True, (250,200,250))
            tsurf_r = tsurf.get_rect()
            tsurf_r.topleft = (x,y)
            if ( tsurf_r.right > ( width - 5 )):
                # Wrap.
                y += tsurf_r.height
                x = margin
                tsurf_r.topleft = (x,y)

            surf.blit(tsurf, tsurf_r.topleft)
            x = tsurf_r.right
            height = tsurf_r.bottom + margin

            if ( newline ):
                x = margin
                y = tsurf_r.bottom + newline_gap

        # line edging for rest of box
        extra.Line_Edging(surf, bbox, True)

        return (surf, height)
Esempio n. 7
0
def New_Mail(text, colour=(128, 128, 128)):
    global __messages, __day, __change
    text = ("Day %u: " % __day) + text
    __messages.append((time.time() + MSG_EXPIRY_TIME,
                       stats.Get_Font(20).render(text, True, colour)))
    __change = True
Esempio n. 8
0
    hr.num_pipes = len([ p for p in g.net.pipe_list if not p.Is_Destroyed() ])
    hr.tech_level = g.net.hub.tech_level
    hr.work_units_used = g.work_units_used
    hr.work_units_avail = g.net.hub.Get_Avail_Work_Units()
    hr.city_pressure = g.net.hub.Get_Pressure()

    return hr

# Called at the end of the game, to display statistics:
def Review(screen, (width, height), game_object, historian):

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

    def Text(str, size, (x,y), justify):
        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) 
Esempio n. 9
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
Esempio n. 10
0
    # 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