Example #1
0
def get_bad_username(screen):
    app = gui.App(pygame.Surface(screen.get_size()))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    l = gui.Label(app, (-1, -1), "Label1", "User name already in use",
                  widget_pos="midbottom")

    inp = gui.TextInputBox(app, (-1, -1), "Input1",
                           "username", "pick new username",
                           widget_pos="midtop")
    inp.focused = True
    inp.make_text()

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.widget == gui.TextInputBox:
                    if event.name == "Input1":
                        if event.action == gui.GUI_EVENT_INPUT:
                            return event.string
            if event.type == QUIT:
                pygame.quit()
                return

        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #2
0
def MainMenu(screen, myConfig):
    app = gui.App(pygame.Surface(screen.get_size()))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    game_name_label = gui.Label(app, (-1, 0),
                              "GNL", "RoboWars",
                              widget_pos="midtop")
    game_name_label.theme.font["size"] = 60
    game_name_label.theme.label["text-color"] = (0, 255, 0)
    game_name_label.make_image()

    play_game = gui.Button(app, (-1, -1), "PlaySingle", "Start Single Player Game",
                           widget_pos="midbottom")
    play_game.theme.font["size"] = 25
    play_game.theme.button["text-color"] = (125, 255, 125)
    play_game.make_image()

    tutb = gui.Button(app, play_game.rect.midbottom, "TUT", "Instructions",
                           widget_pos="midtop")

    optionsb = gui.Button(app, tutb.rect.midbottom, "OB", "Options",
                           widget_pos="midtop")

    exit_game = gui.Button(app, optionsb.rect.midbottom, "Exit", "Exit",
                           widget_pos="midtop")

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.widget == gui.Button:
                    if myConfig.music:
                        sfx_select.play()
                if event.name == "PlaySingle":
                    if event.action == gui.GUI_EVENT_CLICK:
                        return "PlaySingle"
                if event.name == "OB":
                    if event.action == gui.GUI_EVENT_CLICK:
                        return "Options"
                if event.name == "Exit":
                    if event.action == gui.GUI_EVENT_CLICK:
                        return "QUIT"
                if event.name == "TUT":
                    return "Tut"

        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #3
0
def gain_troops(screen, player, myConfig):
    bg = screen.copy()
    app = gui.App(pygame.Surface(screen.get_size()).convert_alpha(), background_color=(0,0,0,0))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    main_win = gui.Window(app, (-1, -1), "MainWindow", "center", [300, 260],
                          caption="Gain Troops")

    p1_label1 = gui.Label(main_win, (-1, -1), "P1_LABEL1", "New Troops: ",
                          widget_pos="midright")
    p1_label2 = gui.Label(main_win, (-1, -1),
                          "P1_LABEL2", "%s"%player.get_terr_holding(),
                          widget_pos="midleft")
    p1_label1.theme.label["text-color"] = player.color
    p1_label2.theme.label["text-color"] = player.color
    p1_label1.make_image()
    p1_label2.make_image()

    cont_button = gui.Button(main_win, (-1, 260), "CONTINUE", "Continue",
                               widget_pos="midbottom")


    do_again = CheckBox(main_win, (300, 0), "CB1", "topright")
    dal = gui.Label(main_win, (300-do_again.button.over_width,
                               do_again.button.over_height),
                    "DALabel", "Don't show again: ",
                    widget_pos="bottomright")

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.name == "MainWindow":
                    event = event.subevent
                    do_again.event(event)
                    if event.widget == gui.Button:
                        if myConfig.music:
                            sfx_select.play()
                    if event.name == "CONTINUE" and event.action == gui.GUI_EVENT_CLICK:
                        return True, do_again.state

        screen.blit(bg, (0,0))
        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #4
0
def Tutorial(screen, myConfig):
    i1 = pygame.transform.scale(pygame.image.load(os.path.join("data", "images", "tut1.png")),
                                screen.get_size())
    i2 = pygame.transform.scale(pygame.image.load(os.path.join("data", "images", "tut2.png")),
                                screen.get_size())
    cur = 0
    cim = i1
    app = gui.App(pygame.Surface(screen.get_size()).convert_alpha(), background_color=(0,0,0,0))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    next = gui.Button(app, screen.get_size(), "Next", "Next",
                           widget_pos="bottomright")
    next.theme.font["size"] = 25
    next.theme.button["text-color"] = (125, 255, 125)
    next.make_image()

    retb = gui.Button(app, (0, screen.get_height()), "Back", "Back",
                           widget_pos="bottomleft")

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.widget == gui.Button:
                    if myConfig.music:
                        sfx_select.play()
                if event.name == "Next":
                    if event.action == gui.GUI_EVENT_CLICK:
                        if cur == 0:
                            cur = 1
                            cim = i2
                        else:
                            cur = 0
                            cim = i1
                if event.name == "Back":
                    if event.action == gui.GUI_EVENT_CLICK:
                        return "MainMenu"

        screen.blit(cim, (0,0))
        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #5
0
def win_screen(screen, world, myConfig):
    bg = screen.copy()
    app = gui.App(pygame.Surface(screen.get_size()).convert_alpha(), background_color=(0,0,0,0))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    main_win = gui.Window(app, (-1, -1), "Menu", "center", [350,200],
                          caption="Game Over!")

    win = gui.Label(main_win, (-1, -1), "Label", "Player %s Won!"%(world.one_winner()[1]+1),
                           widget_pos="midbottom")
    win.theme.font["size"] = 35
    win.theme.button["text-color"] = world.players[world.one_winner()[1]].color
    win.make_image()

    leaveb = gui.Button(main_win, win.rect.midbottom, "LEAVE", "Return to main menu.",
                           widget_pos="midtop")
    leaveb.theme.font["size"] = 25
    leaveb.theme.button["text-color"] = (125, 255, 125)
    leaveb.make_image()

    exit_game = gui.Button(main_win, leaveb.rect.midbottom, "QUIT", "Exit Game",
                           widget_pos="midtop")

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.name == "Menu":
                    event = event.subevent
                    if event.widget == gui.Button:
                        if myConfig.music:
                            sfx_select.play()
                    if event.action == gui.GUI_EVENT_CLICK:
                        return event.name

        screen.blit(bg, (0,0))
        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #6
0
def map_loading(screen):
    app = gui.App(pygame.Surface(screen.get_size()))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    game_name_label = gui.Label(app, (-1, 0),
                              "GNL", "RoboWars",
                              widget_pos="midtop")
    game_name_label.theme.font["size"] = 60
    game_name_label.theme.label["text-color"] = (0, 255, 0)
    game_name_label.make_image()

    message = gui.Label(app, (-1, -1),
                              "GNL", "Map is loading... please wait...",
                              widget_pos="midtop")
    message.theme.font["size"] = 35
    message.theme.label["text-color"] = (255, 0, 0)
    message.make_image()

    screen.blit(app.render(), (0,0))
    pygame.display.flip()
Example #7
0
def escape_screen(screen, myConfig):
    bg = screen.copy()
    app = gui.App(pygame.Surface(screen.get_size()).convert_alpha(), background_color=(0,0,0,0))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    main_win = gui.Window(app, (-1, -1), "Menu", "center", [350,200],
                          caption="Menu")

    play_game = gui.Button(main_win, (-1, -1), "RETURN", "Return to game.",
                           widget_pos="midbottom")
    play_game.theme.font["size"] = 25
    play_game.theme.button["text-color"] = (125, 255, 125)
    play_game.make_image()

    optionsb = gui.Button(main_win, play_game.rect.midbottom, "LEAVE", "Return to main menu.",
                           widget_pos="midtop")

    exit_game = gui.Button(main_win, optionsb.rect.midbottom, "QUIT", "Exit Game",
                           widget_pos="midtop")

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.name == "Menu":
                    event = event.subevent
                    if event.widget == gui.Button:
                        if myConfig.music:
                            sfx_select.play()
                    if event.action == gui.GUI_EVENT_CLICK:
                        return event.name

        screen.blit(bg, (0,0))
        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #8
0
def game(screen, myConfig, nump, numai):
    screen_size = screen.get_size()
    world_height = round(screen_size[1]*0.666) # World uses 2/3 of the screen

    app = gui.App(screen, background_color=None)
    aapp = gui.App(screen, background_color = None)
    aapp.always_render = True
    app.theme = gui.make_theme(os.path.join("data", "gui"))
    app.always_render = True
    end_turn_button = gui.Button(app, (-1, screen_size[1]), "End Turn", "End Turn",
                                widget_pos="bottomleft")
    whos_turn_label = gui.Label(app, (-1, screen_size[1]), "WT Label", "It is player 1's turn",
                          widget_pos="bottomright")
    whos_turn_label.theme.label["text-color"] = [255,0,0]
    whos_turn_label.make_image()

    if myConfig.fps_counter:
        fps_label = gui.Label(app, (0, screen_size[1]), "FPS Label", "FPS: ",
                              widget_pos="bottomleft")
        fps_label.theme.label["text-color"] = [255,0,0]
        fps_label.make_image()

    mg = MapGrid(util.make_random_map())

    pad_up_button = gui.Button(app, (0, 0), "PAD_UP_BUTTON", "",
                               widget_pos="topleft")
    pad_up_button.over_width = screen_size[0]
    pad_up_button.over_height = 15
    pad_up_button.make_image()

    pad_down_button = gui.Button(app, (0, world_height), "PAD_DOWN_BUTTON", "",
                               widget_pos="bottomleft")
    pad_down_button.over_width = screen_size[0]
    pad_down_button.over_height = 15
    pad_down_button.make_image()


    pad_left_button = gui.Button(app, (0, pad_up_button.image.get_height()), "PAD_LEFT_BUTTON", "",
                               widget_pos="topleft")
    pad_left_button.over_width = 15
    pad_left_button.over_height = world_height - pad_up_button.image.get_height()*2
    pad_left_button.make_image()

    pad_right_button = gui.Button(app, (screen_size[0], pad_up_button.image.get_height()), "PAD_RIGHT_BUTTON", "",
                               widget_pos="topright")
    pad_right_button.over_width = 15
    pad_right_button.over_height = world_height - pad_up_button.image.get_height()*2
    pad_right_button.make_image()

    pad_height = pad_up_button.image.get_height()
    pad_width = pad_left_button.image.get_width()

    aleft = wui.Arrow(aapp, (1, int(world_height/2)), "ArrowLeft", "left")
    aright = wui.Arrow(aapp, (screen_size[0]-16, int(world_height/2)), "ArrowRight", "right")
    aup = wui.Arrow(aapp, (int(screen_size[0]/2), 1), "ArrowUp", "up")
    adown = wui.Arrow(aapp, (int(screen_size[0]/2), world_height-16), "ArrowDown", "down")


    world_screen = screen.subsurface((pad_width,
                                      pad_height,
                                      screen_size[0]-pad_width*2,
                                      world_height-pad_height*2))
    world = World(world_screen, map_grid=mg,
                  background=pygame.image.load(os.path.join("data", "images", "bg1.png")).convert())
    controllers = make_map_players(world, nump, numai)
    world_rect = world.display.get_rect()
    world_rect.topleft = world.display.get_offset()

    if myConfig.music:
        pygame.mixer.music.load(os.path.join('data','music','slowtheme.ogg'))
        pygame.mixer.music.play(-1)

        sfx_battle = [pygame.mixer.Sound(os.path.join("data", "sfx", "battle1.ogg")),
                      pygame.mixer.Sound(os.path.join("data", "sfx", "battle2.ogg")),
                      pygame.mixer.Sound(os.path.join("data", "sfx", "battle3.ogg"))]
        for i in sfx_battle:
            i.set_volume(myConfig.sound_volume*0.02)

        sfx_victory = pygame.mixer.Sound(os.path.join("data", "sfx", "victory.ogg"))
        sfx_defeat = pygame.mixer.Sound(os.path.join("data", "sfx", "defeat.ogg"))

        sfx_victory.set_volume(myConfig.sound_volume*0.02)
        sfx_defeat.set_volume(myConfig.sound_volume*0.02)

        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    picktwo = []
    whos_turn = 0

    keys_down = set()

    clock = pygame.time.Clock()

    zoom_states = [(10, 5), (20, 10), (40, 20), (80, 40)]
    zoom_state = 0
    world_zoom_once = True

    while 1:
        clock.tick(600)
        if myConfig.fps_counter:
            if not pygame.time.get_ticks() % 10:
                fps_label.text = "FPS: %i" % clock.get_fps()
                fps_label.make_image()

        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == KEYDOWN:
                if event.key == K_s:
                    a = time.localtime()
                    a = "%s-%s-%s-%s"%(a[1], a[2], a[3], a[4])
                    pygame.image.save(screen, os.path.join("data", "screenshots",
                                                           "screenie %s.jpg"%a))

                if event.key == K_ESCAPE:
                    a = wui.escape_screen(screen, myConfig)
                    if a == "QUIT" or a == "LEAVE":
                        return a
                    else:
                        pass#we returned to game!

                if event.key == K_LEFT or K_RIGHT or K_UP or K_DOWN:
                    keys_down.add(event.key)

            if event.type == KEYUP:
                try: # Ignore any attempts to remove non-existant keys
                    keys_down.remove(event.key)
                except KeyError:
                    continue

            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    x = world.get_mouse_terr()
                    if x:
                        if controllers[whos_turn] == "human":
                            picktwo.append(x)
                if event.button == 4:
                    if zoom_state < 3:
                        zoom_state += 1
                        world.tile_size = zoom_states[zoom_state]
                        world.update()
                if event.button == 5:
                    if zoom_state > 0:
                        zoom_state -= 1
                        world.tile_size = zoom_states[zoom_state]
                        world.update()

            if event.type == gui.GUI_EVENT:
                if event.widget == gui.Button:
                    if myConfig.music:
                        sfx_select.play()
                    if event.name == "End Turn":
                        if event.action == gui.GUI_EVENT_CLICK:
                            if controllers[whos_turn] == "human":
                                if myConfig.new_unit_dialog:
                                    a = wui.gain_troops(screen, world.players[whos_turn], myConfig)
                                    if a == "QUIT":
                                        return "QUIT"
                                    if a[1]: #don't do again!
                                        myConfig.new_unit_dialog = 0
                                        myConfig.save_settings()
                                world.players[whos_turn].end_turn()
                                whos_turn += 1
                                if whos_turn >= len(world.players):
                                    whos_turn = 0
                                whos_turn_label.text = "It is player %ss turn"%(whos_turn+1)
                                whos_turn_label.theme.label["text-color"] = world.players[whos_turn].color
                                whos_turn_label.make_image()
                                for i in picktwo:
                                    i[1].highlighted = False
                                picktwo = []
                                world.update()
            if event.type == MOUSEMOTION:
                if pygame.mouse.get_pressed()[0]:
                    if world_rect.collidepoint(pygame.mouse.get_pos()):
                        world.offset[0] -= event.rel[0]
                        world.offset[1] -= event.rel[1]

        if world.players[whos_turn].dead:
            whos_turn += 1
            if whos_turn >= len(world.players):
                whos_turn = 0
            whos_turn_label.text = "It is player %ss turn"%(whos_turn+1)
            whos_turn_label.theme.label["text-color"] = world.players[whos_turn].color
            whos_turn_label.make_image()

        if world.one_winner()[0]:
            finish_label = gui.Label(app, (-1, 375), "Finish Label", "Player %s WON!"%(world.one_winner()[1]+1),
                          widget_pos="center")
            finish_label.theme.label["text-color"] = world.players[world.one_winner()[1]].color
            finish_label.theme.label["font"] = pygame.font.Font(None, 45)
            world.update()
            world.render()
            return wui.win_screen(screen, world, myConfig)

        for i in picktwo:
            if not i[1].highlighted: # Don't force a re-render if already highlighted
                i[1].highlighted = True
                world.update()
                world.render()


        #BATTLES!
        if len(picktwo) == 1:
            if (picktwo[0][0] != whos_turn) or\
               (picktwo[0][1].units == 1) or\
               (not picktwo[0][1].can_move):
                picktwo[0][1].highlighted = False
                picktwo = []
                world.update()
        if len(picktwo) == 2:
            if picktwo[0][0] == whos_turn:
                if (not picktwo[0][1] == picktwo[1][1]) and \
                   util.connected_mass(picktwo[0][1].terr, picktwo[1][1].terr):
                    if not picktwo[0][0] == picktwo[1][0]:
                        if picktwo[0][1].can_move:
                            if myConfig.attack_dialog:
                                a = wui.do_battle(screen, picktwo, world, myConfig)
                                if a == "QUIT":
                                    return "QUIT"
                                if a[1]: #don't do again!
                                    myConfig.attack_dialog = 0
                                    myConfig.save_settings()
                                a = a[0]
                            else:
                                a = True
                            if a:
                                if myConfig.music:
                                    a = random.choice(sfx_battle)
                                    a.play()
                                    time.sleep(a.get_length()+0.1)
                                x, y = rules.perform_battle(picktwo[0][1], picktwo[1][1])
                                picktwo[0][1].units -= x
                                picktwo[1][1].units -= y

                                if x > y:
                                    if myConfig.music:
                                        sfx_defeat.play()
                                else:
                                    if myConfig.music:
                                        sfx_victory.play()
                                
                                if picktwo[1][1].units == 0:
                                    world.players[picktwo[1][0]].territories.remove(picktwo[1][1])
                                    world.players[picktwo[0][0]].territories.append(picktwo[1][1])
                                    picktwo[1][1].player = world.players[picktwo[0][0]]

                                    world.world_image = None #force rerender

                                    if picktwo[1][1].max_units > picktwo[0][1].units - 1:
                                        picktwo[1][1].units = picktwo[0][1].units - 1
                                        picktwo[0][1].units = 1
                                    else:
                                        picktwo[1][1].units = picktwo[1][1].max_units
                                        picktwo[0][1].units -= picktwo[1][1].units
                                picktwo[0][1].update()
                                picktwo[1][1].update()

                                print "casualties: %s, %s"%(x, y)
                            else:
                                print "attack canceled!"
                        else:
                            print "%s cannot move this turn!"%picktwo[0][1]
                    else:
                        print "player territories - moving units"
                        if picktwo[0][1].can_move:
                            if myConfig.move_dialog:
                                a = wui.move_troops(screen, picktwo, world, myConfig)
                                if a == "QUIT":
                                    return "QUIT"
                                if a[1]: #don't do again!
                                    myConfig.move_dialog = 0
                                    myConfig.save_settings()
                                a = a[0]
                            else:
                                a = True
                            if a:
                                x = picktwo[0][1].units - 1
                                if picktwo[1][1].max_units >= picktwo[1][1].units + x:
                                    pass
                                else:
                                    x = picktwo[1][1].max_units - picktwo[1][1].units
                                picktwo[0][1].units -= x
                                picktwo[1][1].units += x
                                picktwo[0][1].update()
                                picktwo[1][1].update()
                                picktwo[1][1].can_move = False
                            else:
                                pass
                        else:
                            print "%s cannot move this turn!"%picktwo[0][1]

                else:
                    print "not touching territories"
            else:
                print "it is player %ss turn!"%whos_turn
            for i in picktwo:
                i[1].highlighted = False
                world.update()
            picktwo = []

        if not controllers[whos_turn] == "human":
            end_turn_button.visible = False
            u = controllers[whos_turn]

            msg = u.update(whos_turn) # get messages from ai
            if msg[0] == "battle":
                u1, u2 = msg[1], msg[2]
                x, y = rules.perform_battle(u1, u2)
                u1.units -= x
                u2.units -= y
                
                if u2.units == 0:
                    u2.player.territories.remove(u2)
                    u1.player.territories.append(u2)
                    u2.player = u1.player

                    world.world_image = None #force rerender

                    if u2.max_units > u1.units - 1:
                        u2.units = u1.units - 1
                        u1.units = 1
                    else:
                        u2.units = u2.max_units
                        u1.units -= u2.units
                u1.update()
                u2.update()
            if msg[0] == "move":
                u1, u2 = msg[1], msg[2]
                x = u1.units - 1
                if u2.max_units >= u2.units + x:
                    pass
                else:
                    x = u2.max_units - u2.units
                u1.units -= x
                u2.units += x
                u1.update()
                u2.update()
                u1.can_move = False
            if msg[0] == "end_turn":
                controllers[whos_turn].mode = "attack"
                world.players[whos_turn].end_turn()
                whos_turn += 1
                if whos_turn >= len(world.players):
                    whos_turn = 0
                whos_turn_label.text = "It is player %ss turn"%(whos_turn+1)
                whos_turn_label.theme.label["text-color"] = world.players[whos_turn].color
                whos_turn_label.make_image()
                for i in picktwo:
                    i[1].highlighted = False
                picktwo = []
                world.update()
        else:
            end_turn_button.visible = True

        screen.fill((0,0,0))
        world.render()
        for i in world.players:
            if len(i.territories) == 0:
                i.dead = True

        if world_zoom_once:
            world_zoom_once = False
            world.tile_size = zoom_states[zoom_state]
            world.update()

        if pad_up_button.is_clicked():
            world.offset[1] -= SCROLL_SPEED
        if pad_down_button.is_clicked():
            world.offset[1] += SCROLL_SPEED
        if pad_left_button.is_clicked():
            world.offset[0] -= SCROLL_SPEED
        if pad_right_button.is_clicked():
            world.offset[0] += SCROLL_SPEED

        app.render()
        aapp.render()
        pygame.display.flip()
        if not controllers[whos_turn] == "human":
            time.sleep(0.1)
Example #9
0
def pre_single_game(screen, myConfig):
    app = gui.App(pygame.Surface(screen.get_size()))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    ol = gui.Label(app, (-1, 0),
                              "GNL", "Game Options:",
                              widget_pos="midtop")
    ol.theme.font["size"] = 45
    ol.theme.label["text-color"] = (0, 255, 0)
    ol.make_image()

    start = gui.Button(app, screen.get_size(), "SG", "Begin Game",
                           widget_pos="bottomright")
    start.theme.font["size"] = 25
    start.theme.button["text-color"] = (125, 255, 125)
    start.make_image()

    goback = gui.Button(app, start.rect.bottomleft, "GB", "Return",
                           widget_pos="bottomright")

    nump = gui.Label(app, (-1, -1),
                        "NumP", "players: 7",
                        widget_pos="midbottom")
    nbar = gui.ScrollBar(app, nump.rect.midright,
                         "NP_bar", widget_pos="midleft",
                         tot_size=[700, 10], view_size=[100, 10],
                         start_value=0, direction=0)
    nbar.current_value = 7 * 10#yields 7
    nbar.max_value = 70
    nbar.min_value = 20

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    num_ai = gui.Label(app, (-1, -1),
                       "AI", "ai players: 6", widget_pos="midtop")
    vbar = gui.ScrollBar(app, num_ai.rect.midright,
                         "NA_bar", widget_pos="midleft",
                         tot_size=[700, 10], view_size=[100, 10],
                         start_value=0, direction=0)
    vbar.current_value = 6 * 10

    while 1:
        a = int(nbar.current_value/10)
        b = int(vbar.current_value/10)
        if b > a:
            b = a
            vbar.current_value = b*10
        nump.text = "players: %s"%a
        num_ai.text = "ai players: %s"%b
        nump.make_image()
        num_ai.make_image()
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.widget == gui.Button:
                    if myConfig.music:
                        sfx_select.play()
                if event.name == "GB":
                    if event.action == gui.GUI_EVENT_CLICK:
                        return "MainMenu"
                if event.name == "SG":
                    if event.action == gui.GUI_EVENT_CLICK:
                        return "PlayGame", a, b

        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #10
0
def Options(screen, myConfig):
    app = gui.App(pygame.Surface(screen.get_size()))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    ol = gui.Label(app, (-1, 0),
                              "GNL", "Options:",
                              widget_pos="midtop")
    ol.theme.font["size"] = 45
    ol.theme.label["text-color"] = (0, 255, 0)
    ol.make_image()

    goback = gui.Button(app, screen.get_size(), "GB", "Return",
                           widget_pos="bottomright")
    goback.theme.font["size"] = 25
    goback.theme.button["text-color"] = (125, 255, 125)
    goback.make_image()

    #make entries...
    entries = []
    boxes = []
    for i in ["fullscreen", "music", "fps_counter",
              "attack_dialog", "move_dialog", "new_unit_dialog"]:
        if not entries:
            if i.find("dialog") != -1:
                x = "disable " + i
            else:
                x = i
            new = gui.Label(app, (15, 60), i, x,
                            widget_pos="topleft")
            entries.append(new)
            do_again = CheckBox(app, (375, 55), i, "topright")
            do_again.set_state(getattr(myConfig, i))
            boxes.append(do_again)
        else:
            if i.find("dialog") != -1:
                x = "disable " + i
            else:
                x = i
            new = gui.Label(app, (15, entries[-1].rect.bottom+15), i, x,
                            widget_pos="topleft")
            entries.append(new)
            do_again = CheckBox(app, (375, entries[-2].rect.bottom+10), i, "topright")
            do_again.set_state(getattr(myConfig, i))
            boxes.append(do_again)

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    sdlabel = gui.Label(app, (screen.get_width(), 60),
                        "SDLabel", "display: ",
                        widget_pos="topright")
    screendim = gui.MenuList(app, sdlabel.rect.bottomright, "ScreenDim",
                         ["640x480", "800x600", "1024x768"],
                         widget_pos="topright")

    vlabel = gui.Label(app, (screen.get_width(), screendim.rect.bottom + 15),
                       "sound_volume", "sound_volume: ", widget_pos="topright")
    vbar = gui.ScrollBar(app, vlabel.rect.bottomright,
                         "SV_bar", widget_pos="topright",
                         tot_size=[10000, 10], view_size=[100, 10],
                         start_value=0, direction=0)
    vbar.current_value = myConfig.sound_volume * 0.7

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                for i in boxes:
                    i.event(event)
                if event.widget == gui.Button:
                    if myConfig.music:
                        sfx_select.play()
                if event.name == "GB":
                    if event.action == gui.GUI_EVENT_CLICK:
                        #prepare config
                        for i in boxes:
                            s = 0
                            if i.state:
                                s = 1
                            setattr(myConfig, i.name, s)
                        setattr(myConfig, "sound_volume", int(vbar.current_value * 1.4))
                        myConfig.save_settings()
                        return "MainMenu"
                if event.name == "ScreenDim":
                    if event.action == gui.GUI_EVENT_CLICK:
                        a = event.entry.split("x")
                        myConfig.screen_width = int(a[0])
                        myConfig.screen_height = int(a[1])

        screen.blit(app.render(), (0,0))
        pygame.display.flip()
Example #11
0
def move_troops(screen, picktwo, world, myConfig):
    bg = screen.copy()
    app = gui.App(pygame.Surface(screen.get_size()).convert_alpha(), background_color=(0,0,0,0))
    app.theme = gui.make_theme(os.path.join("data", "gui"))

    main_win = gui.Window(app, (-1, -1), "MainWindow", "center", [300, 260],
                          caption="transfer Forces")

    p1_label1 = gui.Label(main_win, (-1, -1), "P1_LABEL1", "Troops:  -",
                          widget_pos="bottomright")
    p1_label2 = gui.Label(main_win, (-1, -1),
                          "P1_LABEL2", "%s/%s   "%(picktwo[0][1].units, picktwo[0][1].max_units),
                          widget_pos="topright")
    p1_label1.theme.label["text-color"] = world.players[picktwo[0][0]].color
    p1_label2.theme.label["text-color"] = world.players[picktwo[0][0]].color
    p1_label1.make_image()
    p1_label2.make_image()

    p2_label1 = gui.Label(main_win, (-1, -1), "P2_LABEL1", ">  Troops:",
                          widget_pos="bottomleft")
    p2_label2 = gui.Label(main_win, (-1, -1), "P2_LABEL2",
                          "   %s/%s"%(picktwo[1][1].units, picktwo[1][1].max_units),
                          widget_pos="topleft")
    p2_label1.theme.label["text-color"] = world.players[picktwo[1][0]].color
    p2_label2.theme.label["text-color"] = world.players[picktwo[1][0]].color
    p2_label1.make_image()
    p2_label2.make_image()


    attack_button = gui.Button(main_win, (-1, 260), "TRANSFER", "Move!",
                               widget_pos="bottomright")
    cancel_button = gui.Button(main_win, (-1, 260), "CANCEL", "Cancel",
                               widget_pos="bottomleft")

    do_again = CheckBox(main_win, (300, 0), "CB1", "topright")
    dal = gui.Label(main_win, (300-do_again.button.over_width,
                               do_again.button.over_height),
                    "DALabel", "Don't show again: ",
                    widget_pos="bottomright")

    if myConfig.music:
        sfx_select = pygame.mixer.Sound(os.path.join("data", "sfx", "select.ogg"))

        sfx_select.set_volume(myConfig.sound_volume*0.02) 

    while 1:
        for event in app.get_events():
            if event.type == QUIT:
                return "QUIT"
            if event.type == gui.GUI_EVENT:
                if event.name == "MainWindow":
                    event = event.subevent
                    do_again.event(event)
                    if event.widget == gui.Button:
                        if myConfig.music:
                            sfx_select.play()
                    if event.name == "TRANSFER" and event.action == gui.GUI_EVENT_CLICK:
                        return True, do_again.state
                    if event.name == "CANCEL" and event.action == gui.GUI_EVENT_CLICK:
                        return False, do_again.state

        screen.blit(bg, (0,0))
        screen.blit(app.render(), (0,0))
        pygame.display.flip()