Exemplo n.º 1
0
def load_game(path, user_callback=None):
    def out_callback(line):
        if 'Established control over the server. You have command access level' in line:
            ui.back(anim=False)
            start_button = ui.Dialog(ui.screen, ui.Button('Touch to start game', callback))
            start_button.back = callback
            ui.set(start_button, anim=False)
            sc_client.out_window_callback = None
    
    port = random.randint(1500, 12000)
    start_server(port, ('-f', path))
    
    sc_client = gamescreen.ScreenClient()
    sc_client.out_window_callback = out_callback
    try:
        sc_client.connect_to_server('player', localhost, port)
    except client.ConnectionError:
        ui.message('Failed to connect to game server, try again', type='error')
        return
    
    def callback():
        load_game_now(port, get_save_username(path))
        
        if user_callback:
            user_callback()
    
    ui.replace(client.client.ui)
    ui.message('Loading...')
Exemplo n.º 2
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    version = 'version %s' % features.get('app.version')
    if features.get('gold.status') != 'none':
        version += '+' + features.get('gold.status')
    if features.get('gold.session_warning'):
        version += ' WARNING! Login with Dropbox in options menu to save your purchases.'
    menu.add(ui.Label('civsync.com; ' + version + '     ' + get_renderer_label(),
                      color=(255, 0, 0, 150), font=ui.consolefont), (0, 0))

    new_game_button = MenuButton('New\ngame', new_game_menu)
    menu.left.add(new_game_button)

    load_game_button = MenuButton('Load\ngame', save.load_dialog)
    menu.left.add(load_game_button)

    if features.get('gold.enable'):
        gold_button = MenuButton(u'civsync\n  Gold', gold.menu)
        gold_button.fg = (255, 215, 0)
        gold_button.bg = (255, 215, 0, 100)
        menu.left.add(gold_button)

    if features.get('app.multiplayer'):
        menu.left.add(MenuButton('Connect', save.connect_dialog))

    menu.right.add(MenuButton('', options.show_options, image=ui.load_image('userdata/options.png')))
    menu.right.add(MenuButton('Exit', ui.back))
    menu.right.add(ui.Spacing(0, 0))

    ui.replace(menu)
Exemplo n.º 3
0
def load_game(path, user_callback=None, before_callback=None):
    def out_callback(line):
        if 'Established control over the server. You have command access level' in line:
            start_button = ui.Dialog(
                ui.get_screen(), ui.Button('Touch to start game', callback))
            start_button.back = callback
            ui.set(start_button, anim=False)

    sc_client = gamescreen.ScreenClient()

    port = random.randint(1500, 12000)
    start_server(port, ('-f', path),
                 line_callback=sc_client.server_line_callback)

    sc_client.out_window_callback = out_callback
    try:
        sc_client.connect_to_server('player', localhost, port)
    except client.ConnectionError:
        ui.message('Failed to connect to game server, try again', type='error')
        return

    def callback():
        if before_callback() if before_callback else True:
            load_game_now(port, get_save_username(path))

        if user_callback:
            user_callback()

    ui.replace(client.client.ui)
    ui.message('Loading...')
Exemplo n.º 4
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    version = 'version %s' % features.get('app.version')
    if features.get('gold.status') != 'none':
        version += '+' + features.get('gold.status')
    if features.get('gold.session_warning'):
        version += ' WARNING! Login with Dropbox in options menu to save your purchases.'
    menu.add(ui.Label('civsync.com; ' + version,
                      color=(255, 0, 0, 150), font=ui.consolefont), (0, 0))

    new_game_button = MenuButton('New\ngame', new_game_menu)
    menu.left.add(new_game_button)

    load_game_button = MenuButton('Load\ngame', save.load_dialog)
    menu.left.add(load_game_button)

    if features.get('gold.enable'):
        gold_button = MenuButton(u'civsync\n  Gold', gold.menu)
        gold_button.fg = (255, 215, 0)
        gold_button.bg = (255, 215, 0, 100)
        menu.left.add(gold_button)

    if features.get('app.multiplayer'):
        menu.left.add(MenuButton('Connect', save.connect_dialog))

    menu.right.add(MenuButton('', options.show_options, image=ui.load_image('data/user/options.png')))
    menu.right.add(MenuButton('Exit', ui.back))
    menu.right.add(ui.Spacing(0, 0))

    ui.replace(menu)
Exemplo n.º 5
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    menu.add(
        ui.Label('version %s' % features.get('app.version'),
                 color=(255, 0, 0, 150),
                 font=ui.consolefont), (0, 0))
    new_game_button = MenuButton('New\ngame', new_game_menu)
    menu.left.add(new_game_button)
    load_game_button = MenuButton('Load\ngame', save.load_dialog)
    menu.left.add(load_game_button)
    if features.get('app.multiplayer'):
        menu.left.add(MenuButton('Connect', save.connect_dialog))

    menu.right.add(MenuButton('Feed\nback', feedback))
    menu.right.add(
        MenuButton(
            '',
            options.show_options,
            image=ui.load_image('data/user/options.png').convert_alpha()))
    menu.right.add(MenuButton('Exit', ui.back))
    menu.right.add(ui.Spacing(0, 0))

    ui.replace(menu)
Exemplo n.º 6
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    menu.add(ui.Label('version %s' % features.get('app.version'), color=(255, 0, 0, 150), font=ui.consolefont), (0, 0))
    new_game_button = MenuButton('New\ngame', new_game_menu)
    menu.left.add(new_game_button)
    load_game_button = MenuButton('Load\ngame', save.load_dialog)
    menu.left.add(load_game_button)
    if features.get('app.multiplayer'):
        menu.left.add(MenuButton('Connect', save.connect_dialog))

    menu.right.add(MenuButton('', options.show_options, image=ui.load_image('data/user/options.png')))
    menu.right.add(MenuButton('Exit', ui.back))
    menu.right.add(ui.Spacing(0, 0))

    ui.replace(menu)
Exemplo n.º 7
0
def load_game(path):
    def out_callback(line):
        if 'Established control over the server. You have command access level' in line:
            ui.back(anim=False)
            ui.set_dialog(ui.Button('Touch to start game', callback))
            sc_client.out_window_callback = None
    
    port = random.randint(1500, 12000)
    start_server(port, "-f '%s'" % path)
    
    sc_client = gamescreen.ScreenClient()
    sc_client.out_window_callback = out_callback
    try:
        sc_client.connect_to_server('player', 'localhost', port)
    except client.ConnectionError:
        ui.message('Failed to connect to game server', type='error')
        return
    
    callback = lambda: load_game_now(port, get_save_username(path))
    
    ui.replace(client.client.ui)
    ui.message('Loading...')
Exemplo n.º 8
0
def load_game(path, user_callback=None, before_callback=None):
    def out_callback(line):
        if 'Established control over the server. You have command access level' in line:
            start_button = ui.Dialog(ui.get_screen(), ui.Button('Touch to start game', callback))
            start_button.back = callback
            ui.set(start_button, anim=False)

    sc_client = gamescreen.ScreenClient()

    port = random.randint(1500, 12000)
    start_server(port, ('-f', path), line_callback=sc_client.server_line_callback)

    sc_client.out_window_callback = out_callback
    sc_client.connect_to_server('player', localhost, port)

    def callback():
        if before_callback() if before_callback else True:
            load_game_now(port, get_save_username(path))

        if user_callback:
            user_callback()

    ui.replace(client.client.ui)
    ui.message('Loading...')
Exemplo n.º 9
0
 def tick(self):
     self.frame += 1
     if self.frame == self.duration:
         ui.replace(self.dest)
Exemplo n.º 10
0
 def tick(self):
     if not self.start:
         self.start = time.time()
     self.frame = time.time() - self.start
     if self.frame >= self.duration:
         ui.replace(self.dest)
Exemplo n.º 11
0
    model = TechtreeClientModel(client)
    widget = TechTreeWidget(model, *tree)
    widget = ui.ScrollWrapper(widget, ways=ui.SCROLL_WIDTH | ui.SCROLL_HEIGHT)
    ui.set(widget)


if __name__ == '__main__':
    tree = load_techtree('data/techtree.index')

    class ExampleModel:
        def is_researched(self, name):
            name = name.strip("'")
            return name in [
                'Alphabet', 'Masonry', 'Currency', 'Bronze Working',
                'Mathematics'
            ]

        def is_available(self, name):
            return False

    model = ExampleModel()

    graphics.init()
    ui.init()
    wnd = graphics.create_window((800, 600))
    ui.screen_width, ui.screen_height = ui.screen_size = wnd.get_size()
    widget = TechTreeWidget(model, *tree)
    widget = ui.ScrollWrapper(widget, ways=ui.SCROLL_WIDTH | ui.SCROLL_HEIGHT)
    ui.replace(widget)
    ui.main()
Exemplo n.º 12
0
def show(client):
    tree = load_techtree('data/techtree.index')

    model = TechtreeClientModel(client)
    widget = TechTreeWidget(model, *tree)
    widget = ui.ScrollWrapper(widget, ways=ui.SCROLL_WIDTH | ui.SCROLL_HEIGHT)
    ui.set(widget)

if __name__ == '__main__':
    tree = load_techtree('data/techtree.index')

    class ExampleModel:
        def is_researched(self, name):
            name = name.strip("'")
            return name in ['Alphabet', 'Masonry', 'Currency', 'Bronze Working', 'Mathematics']

        def is_available(self, name):
            return False


    model = ExampleModel()

    graphics.init()
    ui.init()
    wnd = graphics.create_window((800, 600))
    ui.screen_width, ui.screen_height = ui.screen_size = wnd.get_size()
    widget = TechTreeWidget(model, *tree)
    widget = ui.ScrollWrapper(widget, ways=ui.SCROLL_WIDTH | ui.SCROLL_HEIGHT)
    ui.replace(widget)
    ui.main()
Exemplo n.º 13
0
 def tick(self):
     if not self.start:
         self.start = time.time()
     self.frame = time.time() - self.start
     if self.frame >= self.duration:
         ui.replace(self.dest)