Ejemplo n.º 1
0
    def make_ui(self):
        self.items = []
        self.canvas = CityCanvas(self, self.city)
        self.info_label = self.get_labels()
        self.citypanel = ui.LinearLayoutWidget()
        self.prodpanel = ui.LinearLayoutWidget()
        self.units_in_city = ui.HorizontalLayoutWidget()
        self.setup_units_in_city()

        self.citypanel.add(ui.Label(self.city.get_name()))
        self.citypanel.add(self.get_citizen_icons())
        self.citypanel.add(self.canvas)
        self.citypanel.update_layout()
        self.citypanel.add(
            ui.ScrollWrapper(self.info_label,
                             height=ui.screen_height - self.citypanel.size[1] -
                             self.citypanel.spacing,
                             width=self.canvas.size[0]))

        self.ui = self  # ui.ScrollWrapper(self)

        self.add(self.citypanel)
        self.add(self.prodpanel)

        self.unit_img = ui.Image(self.city.get_production_image())
        self.prodpanel.add(
            ui.Label(self.city.get_production_name(), font=ui.smallfont))

        stock = self.city.get_shield_stock()
        cost = self.city.get_production_cost()
        turns = self.city.get_production_turns_to_build()
        if cost != 999:
            self.prodpanel.add(
                ui.Label('%d/%d (%d turns)' % (stock, cost, turns),
                         font=ui.smallfont))
        self.prodpanel.add(self.unit_img)
        prodbuttons = ui.HorizontalLayoutWidget(spacing=10)
        prodbuttons.add(ui.Label('Prod: '))
        prodbuttons.add(
            ui.Button('Change', lambda: self.change_prod(add=False)))
        prodbuttons.add(ui.Button('Buy', lambda: self.buy_prod()))
        #prodbuttons.add(ui.Button('Add', lambda: self.change_prod(add=False)))
        self.prodpanel.add(prodbuttons)
        self.prodpanel.add(
            ui.ScrollWrapper(self.units_in_city,
                             width=340,
                             height=120,
                             ways=ui.SCROLL_WIDTH))
        self.prodpanel.add(ui.Button('Buildings in city', self.show_buildings))

        #print self.city.get_buildable_improvements()
        #print self.city.get_buildable_units()

        self.citypanel.update_layout()
        self.update_layout()
Ejemplo n.º 2
0
def menu():
    layout = ui.LinearLayoutWidget(marginleft=10)
    buttons = ui.HorizontalLayoutWidget(spacing=10)
    text_label = help.LongTextWidget('Loading...', ui.screen_width,
                                     ui.smallfont)

    layout.add(buttons)
    layout.add(text_label)
    layout.add(buttons)

    ui. async (check_products)

    def text_fetched(text):
        data = json.loads(text)
        text_label.set_text(data['text'])
        for btn in data['buttons']:
            button = ui.Button(
                btn['text'],
                functools.partial(open_gold_link, btn['url'],
                                  btn.get('restart')))
            buttons.add(button)

    ui. async (lambda: sync.request_with_sid('/sale/gold_text'),
               then=text_fetched)
    ui.set(ui.ScrollWrapper(layout))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def load_scenario():
    menu = ui.LinearLayoutWidget()

    for name, path in get_scenarios():
        callback = functools.partial(load_game, path)
        menu.add(ui.Button(name, callback))

    ui.set(ui.ScrollWrapper(menu))
Ejemplo n.º 5
0
def except_dialog():
    type, value, tb = sys.exc_info()
    tb_str = traceback.format_exception(type, value, tb, limit=20)
    panel = ui.LinearLayoutWidget()
    panel.add(ui.Label('error!', font=ui.consolefont))
    panel.add(ui.Label(str(type) + ':\n' + str(value), font=ui.consolefont))
    panel.add(ui.Label(''.join(tb_str), font=ui.consolefont))
    ui.set_screen(ui.ScrollWrapper(panel))
Ejemplo n.º 6
0
    def __init__(self):
        def format_name(name):
            space_count = len(name) - len(name.lstrip(' '))
            return ('   ' * space_count) + name

        super(HelpPanel, self).__init__()
        topics_width = 150
        list = ui.LinearLayoutWidget()
        self.labels = {}
        for name in help_topics:
            label = ui.Label(format_name(name), functools.partial(self.open_topic, name), font=ui.consolefont)
            self.labels[name] = label
            list.add(label)
        self.add(ui.ScrollWrapper(list, width=topics_width))
        self.text = LongTextWidget('', ui.screen_width - topics_width, ui.consolefont)
        self.text_scroll = ui.ScrollWrapper(self.text)
        self.add(self.text_scroll)
        self.last_open = None
Ejemplo n.º 7
0
    def __init__(self, no_quit=False):
        super(ServerGUI, self).__init__()
        gamescreen.ScreenClient(no_quit=no_quit)
        self.ui = ui.ScrollWrapper(self)
        self.has_ui = False
        self.setup_loading_ui()

        self.server_lines = []
        self.server_console = None
Ejemplo n.º 8
0
def load_dialog():
    menu = ui.LinearLayoutWidget(marginleft=10)
    was_any = False
    menu.add(dropbox.DBButton('Show saves in Dropbox', dropbox.load_from_dropbox))
    for name, path in get_saves():
        callback = functools.partial(load_game, path)
        menu.add(ui.Button(name, callback))
        was_any = True
    if not was_any:
        menu.add(ui.Label('No saved games yet...'))
    ui.set(ui.ScrollWrapper(menu))
Ejemplo n.º 9
0
def set_dialog(new_screen, scroll=False, no_stack=False):
    if scroll:
        item = ui.ScrollWrapper(new_screen,
                                height=ui.screen_height * 0.7,
                                width=ui.screen_width * 0.7,
                                ways=ui.SCROLL_HEIGHT | ui.SCROLL_WIDTH)
    else:
        item = new_screen
    dialog = Dialog(ui.get_screen(), item)
    ui.set(dialog, anim=False, no_stack=no_stack)
    return dialog
Ejemplo n.º 10
0
def load_dialog():
    menu = ui.LinearLayoutWidget()
    was_any = False
    if features.get('civsync.enable'):
        menu.add(ui.Button('Show CivSync saves', sync.show_load))
    for name, path in get_saves():
        callback = functools.partial(load_game, path)
        menu.add(ui.Button(name, callback))
        was_any = True
    if not was_any:
        menu.add(ui.Label('No saved games yet...'))
    ui.set(ui.ScrollWrapper(menu))
Ejemplo n.º 11
0
def load_dialog(entries):
    print entries

    menu = ui.LinearLayoutWidget()
    menu.add(
        ui.Label(
            'Save your games to folder /Applications/Freeciv in your Dropbox.')
    )
    for entry in entries:
        name = DropboxHelper.getPath(entry).strip('/')
        menu.add(ui.Button(name, functools.partial(load_dropbox_save, name)))
    ui.set(ui.ScrollWrapper(menu))
Ejemplo n.º 12
0
    def setup_ui(self):
        self.add(ui.Label('Select a nation'))

        nationSet_panel = ui.HorizontalLayoutWidget(spacing=self.spacing)
        self.nationSet_label = ui.Label('')
        nationSet_panel.add(self.nationSet_label)
        self.nationSet_button = ui.Button('', self.change_nationSet)
        nationSet_panel.add(self.nationSet_button)
        self.add(nationSet_panel)

        self.add(ui.Label('Nation Groups:'))

        self.update_layout()
        y = self.spacing
        for item in self.items:
            y += item.size[1] + self.spacing

        nations_panel = ui.HorizontalLayoutWidget(spacing=self.spacing)
        self.nationGroups = ui.LinearLayoutWidget()
        nations_panel.add(
            ui.ScrollWrapper(self.nationGroups,
                             height=ui.screen_height - y - self.spacing,
                             width=ui.screen_width * 0.5,
                             ways=ui.SCROLL_HEIGHT))
        self.nations = ui.LinearLayoutWidget()
        nations_panel.add(
            ui.ScrollWrapper(self.nations,
                             height=ui.screen_height - y - self.spacing,
                             width=ui.screen_width * 0.5,
                             ways=ui.SCROLL_HEIGHT))
        self.set_nation_group()
        self.set_nationSet(False)
        for id, name in enumerate(client.get_nations_groups()):
            self.nationGroups.add(
                ui.Button(name, functools.partial(self.set_nation_group, id)))
        self.add(nations_panel)

        self.update_layout()
Ejemplo n.º 13
0
def show_list(entries):
    panel = ui.LinearLayoutWidget()
    panel.add(ui.Label('Saves from %s' % civsync.HOST))
    for entry in entries:
        panel.add(
            ui.Button('%s - %dkB' % (entry.name, entry.size / 1024),
                      functools.partial(download_sync, entry.sha1)))
    if not entries:
        panel.add(ui.Label('You have not synced any saves...'))
        panel.add(
            ui.Label('Install Freeciv Sync for Desktop from %s' %
                     civsync.HOST))
        panel.add(ui.Label('or save game with \'Save & Sync\''))
    panel.add(ui.Button('Logout', logout))
    ui.set(ui.ScrollWrapper(panel))
Ejemplo n.º 14
0
def debug_menu():
    def fake_screen_size(size):
        import main
        main.main(size, init=False)

    def fake_screen_size_menu():
        menu = ui.Menu(center=False)
        for size in [(320, 240), (480, 320), (640, 480), (1024, 800),
                     (1280, 800)]:
            menu.add(str(size), functools.partial(fake_screen_size, size))
        ui.set_dialog(menu, scroll=True)

    def change_feature():
        arg = uidialog.inputbox('name=key')
        try:
            features._parse_arg(arg)
        except Exception as e:
            traceback.print_exc()
            ui.message(str(e))

    def pernament_feature():
        arg = uidialog.inputbox('name=key')
        try:
            k, v = arg.split('=', 1)
            features.set_perm(k, v)
        except Exception as e:
            traceback.print_exc()
            ui.message(str(e))

    def show_features():
        s = '\n'.join('%s=%s' % (k, v)
                      for k, v in sorted(features.features.items()))
        ui.set_dialog(ui.Label(s), scroll=True)

    menu = ui.Menu()

    menu.add('Fake screen size', fake_screen_size_menu)
    menu.add('Get screen size',
             lambda: ui.set_dialog(ui.Label(str(ui.screen_size))))
    menu.add('Change feature', change_feature)
    menu.add('Pernament feature', pernament_feature)
    menu.add('Show features', show_features)
    menu.add('Cause exception', lambda: 1 / 0)
    menu.add(
        'Test Market URL', lambda: uidialog.open_url(
            'market://details?id=pl.org.zielinscy.freeciv'))

    ui.set(ui.ScrollWrapper(menu))
Ejemplo n.º 15
0
def show(client):
    widget = TechTreeWidget()
    widget = ui.ScrollWrapper(widget, ways=ui.SCROLL_WIDTH | ui.SCROLL_HEIGHT)
    ui.set(widget)
Ejemplo n.º 16
0
 def show(self):
     ui.set(ui.ScrollWrapper(self))
Ejemplo n.º 17
0
def load_dialog(entries):
    menu = ui.LinearLayoutWidget()
    menu.add(ui.Label('Save your games to folder /Applications/Freeciv in your Dropbox.'))
    for entry in entries:
        menu.add(ui.Button(entry, functools.partial(load_dropbox_save, entry)))
    ui.set(ui.ScrollWrapper(menu))
Ejemplo n.º 18
0
    def make_ui(self):
        self.items = []
        self.canvas = CityCanvas(self, self.city, ui.scale_for_device(320))
        self.info_label = self.get_labels()
        self.citypanel = ui.LinearLayoutWidget()
        self.prodpanel = ui.LinearLayoutWidget()
        self.supported_units = ui.HorizontalLayoutWidget()
        self.setup_units_in_city(self.supported_units,
                                 self.city.get_supported_units())
        self.units_in_city = ui.HorizontalLayoutWidget()
        self.setup_units_in_city(self.units_in_city, self.city.get_units())

        self.citypanel.add(ui.Label(self.city.get_name()))
        self.citypanel.add(self.get_citizen_icons())
        self.citypanel.add(self.canvas)
        self.citypanel.update_layout()
        self.citypanel.add(
            ui.ScrollWrapper(self.info_label,
                             height=ui.screen_height - self.citypanel.size[1] -
                             self.citypanel.spacing,
                             width=self.canvas.size[0]))

        self.ui = self  # ui.ScrollWrapper(self)

        self.add(self.citypanel)
        self.add(self.prodpanel)

        showbuttons = ui.HorizontalLayoutWidget(spacing=10)
        showbuttons.add(ui.Button('Buildings in city', self.show_buildings))
        if self.city.count_trade_routes() > 0:
            showbuttons.add(ui.Button('Trade routes', self.show_trade_routes))
        self.prodpanel.add(showbuttons)
        self.prodpanel.add(
            ui.Label('Prod: ' + self.city.get_production_name(),
                     font=ui.smallfont))
        prodbuttons = ui.HorizontalLayoutWidget(spacing=10)
        prod_img_sprite = self.city.get_production_image()
        if prod_img_sprite is not None:
            prodbuttons.add(ui.Image(prod_img_sprite))
        prodbuttons.add(
            ui.Button('Change', lambda: self.change_prod(add=False)))
        prodbuttons.add(ui.Button('Buy', lambda: self.buy_prod()))
        stock = self.city.get_shield_stock()
        cost = self.city.get_production_cost()
        turns = self.city.get_production_turns_to_build()
        if cost != 999:
            prodbuttons.add(
                ui.Label('%d/%d (%d turns)' % (stock, cost, turns),
                         font=ui.smallfont))
        self.prodpanel.add(prodbuttons)

        self.update_layout()  # to get updated position of self.prodpanel
        width = ui.screen_width - self.get_position_of(self.prodpanel)[0]
        self.prodpanel.add(ui.Label('Supported units', font=ui.smallfont))
        self.prodpanel.add(
            ui.ScrollWrapper(self.supported_units,
                             width=width,
                             height=ui.scale_for_device(100),
                             ways=ui.SCROLL_WIDTH))
        self.prodpanel.add(ui.Label('Present units', font=ui.smallfont))
        self.prodpanel.add(
            ui.ScrollWrapper(self.units_in_city,
                             width=width,
                             height=ui.scale_for_device(100),
                             ways=ui.SCROLL_WIDTH))

        #print self.city.get_buildable_improvements()
        #print self.city.get_buildable_units()

        self.citypanel.update_layout()
        self.update_layout()
Ejemplo n.º 19
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()
Ejemplo n.º 20
0
def debug_menu():
    def fake_screen_size(size):
        import main
        main.main(size, init=False)

    def fake_screen_size_menu():
        menu = ui.Menu(center=False)
        for size in [(320, 240), (480, 320), (640, 480), (1024, 800),
                     (1280, 800)]:
            menu.add(str(size), functools.partial(fake_screen_size, size))
        ui.set_dialog(menu, scroll=True)

    def change_feature():
        def finish(arg):
            try:
                features._parse_arg(arg)
            except Exception as e:
                traceback.print_exc()
                ui.message(str(e))

        uidialog.inputbox('name=key', finish=finish)

    def pernament_feature():
        def finish(arg):
            try:
                k, v = arg.split('=', 1)
                features.set_perm(k, v)
            except Exception as e:
                traceback.print_exc()
                ui.message(str(e))

        uidialog.inputbox('name=key', finish=finish)

    def show_features():
        s = '\n'.join('%s=%s' % (k, v)
                      for k, v in sorted(features.features.items()))
        ui.set_dialog(ui.Label(s), scroll=True)

    def test_inputbox():
        import uidialog

        def finish(text):
            print 'got', text

        def cancel():
            print 'cancel'

        uidialog.inputbox('Query?', 'defaultval', finish=finish, cancel=cancel)

    def test_eval():
        import uidialog

        def finish(text):
            exec text

        uidialog.inputbox('Expr to exec?', '', finish=finish)

    menu = ui.Menu()

    menu.add('Fake screen size', fake_screen_size_menu)
    menu.add('Get screen size',
             lambda: ui.set_dialog(ui.Label(str(ui.screen_size))))
    menu.add('Change feature', change_feature)
    menu.add('Pernament feature', pernament_feature)
    menu.add('Show features', show_features)
    menu.add('Cause exception', lambda: 1 / 0)
    menu.add('Test Market URL', osutil.open_market)
    menu.add('Test inputbox', test_inputbox)
    menu.add('Eval', test_eval)

    ui.set(ui.ScrollWrapper(menu))