示例#1
0
    def get_labels(self):
        panel = ui.HorizontalLayoutWidget(spacing=10)
        panel_a = ui.LinearLayoutWidget(spacing=0)
        panel_b = ui.LinearLayoutWidget(spacing=0)
        panel.add(panel_a)
        panel.add(panel_b)

        def add(a, b):
            font = ui.consolefont
            panel_a.add(ui.Label(a, font=font))
            panel_b.add(ui.Label(str(b), font=font))

        def plus(n):
            return '+%d' % n if n > 0 else '%s' % n

        def add_basic(title, name):
            surplus = plus(self.city.get_prod('surplus', name))
            add(title, '%s (%s)' % (self.city.get_prod('prod', name), surplus))

        add_basic('Food', 'food')
        add_basic('Production', 'shield')
        add_basic('Trade', 'trade')

        add('', '')

        add_basic('Gold', 'gold')
        add('Science', self.city.get_prod('prod', 'science'))
        add('Luxury', self.city.get_prod('prod', 'luxury'))

        add('', '')

        add('Corruption', self.city.get_prod('waste', 'trade'))

        return panel
示例#2
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()
示例#3
0
def change_zoom():
    menu = ui.LinearLayoutWidget()
    for size in [None, (320, 240), (480, 320), (640, 480), (1024, 800)]:
        menu.add(
            ui.Button(str(size or 'Disabled'),
                      functools.partial(change_screen_size, size)))
    ui.set_dialog(menu, scroll=True)
示例#4
0
def inputbox(text, default='', finish=None, cancel=None):
    def _finish():
        if text.label:
            graphics.stop_text_input()
            finish(text.label)
            ui.back(allow_override=False)
        else:
            _cancel()

    def reset():
        text.set_text('')

    def _cancel():
        graphics.stop_text_input()
        if cancel: cancel()
        ui.back(allow_override=False)

    graphics.start_text_input()
    container = ui.LinearLayoutWidget()
    container.back = _cancel
    container.add(ui.Label('%s' % text))
    text = InputBox(default)
    container.add(text)
    container.focus = text
    panel = ui.HorizontalLayoutWidget(spacing=10)
    panel.add(ui.Button('OK', _finish))
    panel.add(ui.Button('Reset', reset))
    container.add(panel)
    ui.set(container)
示例#5
0
    def add_condition(self):
        def ph(type):  # pact handler
            def handler():
                ui.back()
                self.meeting.pact(type)

            return handler

        panel = ui.LinearLayoutWidget()
        c = self.meeting.counterpart
        state = c.get_state()

        if state not in (DS_ARMISTICE, DS_CEASEFIRE, DS_PEACE, DS_ALLIANCE):
            panel.add(ui.Button('Ceasefire', ph(CLAUSE_CEASEFIRE)))

        if state not in (DS_PEACE, DS_ALLIANCE):
            panel.add(ui.Button('Peace', ph(CLAUSE_PEACE)))

        if state not in (DS_ALLIANCE, ):
            panel.add(ui.Button('Alliance', ph(CLAUSE_ALLIANCE)))

        if not c.gives_shared_vision():
            panel.add(ui.Button('Shared vision', ph(CLAUSE_VISION)))

        ui.set_dialog(panel)
示例#6
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))
示例#7
0
 def add(type, img):
     # spacing here are hard-coded so the layout breaks when font is changed
     img = img.scale((30, 45))
     line = ui.HorizontalLayoutWidget()
     img_l = ui.LinearLayoutWidget()
     img_l.add(ui.Image(img))
     img_l.add(ui.Spacing(0, 6))
     line.add(img_l)
     if type != 0:
         line.add(ui.Spacing(10, 0))
         w = 40
         line.add(
             ui.Button(' - ',
                       functools.partial(change, type, -1),
                       font=font,
                       force_width=w))
         line.add(ui.Spacing(10, 0))
         line.add(
             ui.Button(' + ',
                       functools.partial(change, type, +1),
                       font=font,
                       force_width=w))
     else:
         line.add(ui.Spacing(116, 0))
     line.add(ui.Spacing(10, 0))
     line.add(ui.Label('%d%%' % tpl[type], font=font))
     panel.add(line)
示例#8
0
def show_list_dialog(items,
                     callback=None,
                     get_text_func=None,
                     title=None,
                     titlefont=None,
                     scroll=False):
    def default_get_text_func(it):
        if isinstance(it, tuple):
            label, action = it
            return label
        else:
            return it

    def default_callback(it):
        return it[1]()

    def clicked(it):
        ui.back(anim=False)
        (callback or default_callback)(it)

    gui = ui.LinearLayoutWidget()

    if title:
        gui.add(ui.Label(title, font=titlefont))

    for item in items:
        label = (get_text_func or default_get_text_func)(item)
        gui.add(ui.Button(label, functools.partial(clicked, item)))
    set_dialog(gui, scroll=scroll)
示例#9
0
    def __init__(self, client):
        super(ScreenWidget, self).__init__()
        self.client = client

        self.map = MapWidget(client)
        self.overview = OverviewWidget(client)
        self.console = ConsoleWidget(client)
        self.menu = gamemenu.Menu(client)
        self.end_turn_button = ui.Button('End turn', self.client.end_turn)
        self.empire_button = ui.Button('Empire', self.empire_dialog)
        self.taxes_panel = TaxesPanel(client)

        self.left_panel = ui.LinearLayoutWidget(spacing=0, center=True)
        self.map_wrapper = ui.AbsoluteLayoutWidget()

        self.add(self.left_panel)
        self.add(self.map_wrapper)

        self.map_wrapper.add(self.map, (0, 0))
        self.map_wrapper.add(self.menu, (0, 0), align=ui.BOTTOM)

        self.left_panel.add(self.overview)
        self.left_panel.add(self.console.scroll)
        self.left_panel.add(self.end_turn_button)
        self.left_panel.add(self.taxes_panel)
        self.left_panel.add(ui.Spacing(0, 10))
        self.left_panel.add(self.empire_button)

        if features.get('app.full_label_toggle_button'):
            full_label_toggle_button = ui.Button('city labels', client.toggle_full_labels, font=ui.consolefont)
            self.left_panel.add(full_label_toggle_button)

        # key_end_turn()

        self.focus = self.map
示例#10
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))
示例#11
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))
示例#12
0
    def change_goverment(self):
        def commit_government_change(gov):
            gov.change_to()
            ui.back()

        panel = ui.LinearLayoutWidget()
        for gov in self.client.get_governments():
            panel.add(ui.Label(gov.name, functools.partial(commit_government_change, gov)))
        ui.set_dialog(panel, scroll=True)
示例#13
0
    def get_labels(self):
        panel = ui.HorizontalLayoutWidget(spacing=10)
        panel_a = ui.LinearLayoutWidget(spacing=0)
        panel_b = ui.LinearLayoutWidget(spacing=0)
        panel.add(panel_a)
        panel.add(panel_b)

        def add(a, b):
            font = ui.consolefont
            panel_a.add(ui.Label(a, font=font))
            panel_b.add(ui.Label(str(b), font=font))

        def plus(n):
            return '+%d' % n if n > 0 else '%s' % n

        def add_basic(title, name):
            surplus = plus(self.city.get_prod('surplus', name))
            prod_and_waste = self.city.get_prod(
                'prod', name) + self.city.get_prod('waste', name)
            add(title, '%s (%s)' % (prod_and_waste, surplus))

        add_basic('Food', 'food')
        add_basic('Production', 'shield')
        add_basic('Trade', 'trade')

        add('', '')

        gold_surplus = plus(self.city.get_prod('surplus', 'gold'))
        add('Gold',
            '%s (%s)' % (self.city.get_prod('prod', 'gold'), gold_surplus))
        add('Science', self.city.get_prod('prod', 'science'))
        add('Luxury', self.city.get_prod('prod', 'luxury'))

        add('', '')

        add('Corruption', self.city.get_prod('waste', 'trade'))
        add('Waste', self.city.get_prod('waste', 'shield'))
        add('Pollution risk', '%d %%' % self.city.get_pollution())
        illness = self.city.get_illness()
        if illness >= 0:  # illness is on
            add('Plague risk', '%0.1f %%' % illness)

        return panel
示例#14
0
    def __init__(self, client, width=0):
        ui.LinearLayoutWidget.__init__(self)
        self.width = width or ui.screen_width
        self.client = client
        self.zoom_panel = ui.HorizontalLayoutWidget(spacing=4)
        self.zoom_panel.add(ui.Button('+', self.incr_zoom, force_width=20))
        self.zoom_panel.add(ui.Button(' - ', self.decr_zoom, force_width=20))
        self.zoom_level = ZOOM_LEVELS.index(1)
        self.panel = ui.HorizontalLayoutWidget(spacing=4)
        self.add(self.zoom_panel)
        self.add(self.panel)
        self.panel.add(ui.Label('loading...', color=(0, 255, 0)))

        self.activity_label = ui.Label('', font=ui.consolefont)

        self.left_widget = ui.LinearLayoutWidget()
        self.left_widget.add(self.activity_label)

        self.joystick_layout = ui.LinearLayoutWidget()
示例#15
0
 def update_joystick(self):
     joystick_layout = ui.LinearLayoutWidget()
     j_type = get_joystick_type()
     if j_type == 'new':
         joystick = NewJoystick(client)
         joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 50
     else:
         joystick = TileJoystick(client)
         joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 20
     joystick_layout.add(joystick)
     self.items.insert(0, joystick_layout)
示例#16
0
    def pick_nation(self):
        def set_nation(style, id):
            self.city_style = style
            self.nation_id = id
            self.set_nation_settings()
            ui.back()
        nations = ui.LinearLayoutWidget()
        for name, style, id in client.get_nations():
            nations.add(ui.Button(name, functools.partial(set_nation, style, id)))

        ui.set_dialog(nations, scroll=True)
示例#17
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))
示例#18
0
 def __init__(self, player):
     super(ConditionsWidget, self).__init__()
     p = ui.HorizontalLayoutWidget()
     p.add(ui.Spacing(10, 0))
     p.add(ui.Label('   ', image=player.get_flag()))
     p.add(ui.Spacing(10, 0))
     self.accepting = ui.Label('?')
     p.add(self.accepting)
     self.add(p)
     self.panel = ui.LinearLayoutWidget()
     self.add(self.panel)
示例#19
0
    def show_units(self):
        def focus(unit):
            unit.focus()
            ui.back()
            ui.back()

        panel = ui.LinearLayoutWidget()
        for unit in self.city.get_units():
            name = unit.get_name()
            callback = functools.partial(focus, unit)
            panel.add(ui.Button(name, callback))
        ui.set_dialog(panel, scroll=True)
示例#20
0
def change_joystick():
    def set_type(name):
        features.set_perm('app.joystick', name)
        ui.back()

    types = ['new', 'tile']
    panel = ui.LinearLayoutWidget()

    for type in types:
        panel.add(ui.Button(type.capitalize(), functools.partial(set_type, type)))

    ui.set_dialog(panel)
示例#21
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))
示例#22
0
def ask(msg, callback):
    def call_callback():
        callback()
        ui.back()

    gui = ui.LinearLayoutWidget()
    gui.add(ui.Label(msg))
    hor = ui.HorizontalLayoutWidget(spacing=10)
    hor.add(ui.Button('Yes', call_callback))
    hor.add(ui.Button('No', ui.back))
    gui.add(hor)
    set_dialog(gui)
示例#23
0
def change_ruleset():
    def set_ruleset(name):
        features.set_perm('app.ruleset', name)
        ui.back()

    rulesets = ['default', 'civ1', 'civ2']
    panel = ui.LinearLayoutWidget()

    for ruleset in rulesets:
        panel.add(ui.Button(ruleset, functools.partial(set_ruleset, ruleset)))

    ui.set_dialog(panel)
示例#24
0
    def show_buildings(self):
        buildings = self.city.get_built_improvements()

        panel = ui.LinearLayoutWidget()
        for handle, name in buildings:
            callback = functools.partial(lambda info: self.sell_dialog(*info),
                                         (name, handle))
            p = ui.HorizontalLayoutWidget()
            p.add(ui.Label(name))
            p.add(ui.Button('Sell', callback))
            panel.add(p)
        ui.set_dialog(panel, scroll=True)
示例#25
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))
示例#26
0
    def update_tax(self):
        panel = ui.LinearLayoutWidget()
        tpl = list(self.client.get_tax_values())

        science_img = icons.get_small_image('scientist')
        tax_img = icons.get_small_image('taxman')
        lux_img = icons.get_small_image('elvis')

        font = ui.bigfont

        def change(type, val):
            tpl[type] += val * 10
            tpl[0] -= val * 10
            a, b, c = map(lambda x: max(0, min(100, x)), tpl)
            self.client.set_tax_values(a, b, c)
            ui.get_screen().tick()
            self.update()
            ui.execute_later(self.update)

        def add(type, img):
            # spacing here are hard-coded so the layout breaks when font is changed
            img = img.scale((30, 45))
            line = ui.HorizontalLayoutWidget()
            img_l = ui.LinearLayoutWidget()
            img_l.add(ui.Image(img))
            img_l.add(ui.Spacing(0, 6))
            line.add(img_l)
            if type != 0:
                line.add(ui.Spacing(10, 0))
                w = 40
                line.add(
                    ui.Button(' - ',
                              functools.partial(change, type, -1),
                              font=font,
                              force_width=w))
                line.add(ui.Spacing(10, 0))
                line.add(
                    ui.Button(' + ',
                              functools.partial(change, type, +1),
                              font=font,
                              force_width=w))
            else:
                line.add(ui.Spacing(116, 0))
            line.add(ui.Spacing(10, 0))
            line.add(ui.Label('%d%%' % tpl[type], font=font))
            panel.add(line)

        add(0, tax_img)
        add(1, lux_img)
        add(2, science_img)

        self.add(panel)
示例#27
0
def feedback():
    panel = ui.LinearLayoutWidget()
    panel.add(
        ui.Label(
            'Leaving comments with logs will help me diagnose\npotential problems with game speed and\nunexpected behaviour.'
        ))
    panel.add(
        ui.Button('Leave a comment with a log (preferred)',
                  lambda: sync.comment(sync.get_install_time(), True)))
    panel.add(
        ui.Button('Leave a comment without a log',
                  lambda: sync.comment(sync.get_install_time(), False)))
    ui.set(panel)
示例#28
0
    def research_list_dialog(self, func, level):
        def set_goal(tech):
            getattr(tech, func)()
            self.setup_ui()
            ui.back()

        techs = ui.LinearLayoutWidget()

        techs.add(ui.Label(', '.join(self.client.get_current_tech())))
        for tech in self.client.get_techs(level):
            techs.add(ui.Button(tech.name, functools.partial(set_goal, tech)))

        ui.set_dialog(techs, scroll=True)
示例#29
0
def change_difficulty(difficulty_button):
    def set_difficulty(name):
        features.set_perm('app.difficulty', name)
        difficulty_button.set_text('Default difficulty for new games: ' + name)
        ui.back()

    difficulties = ['handicapped', 'novice', 'easy', 'normal', 'hard', 'cheating']
    panel = ui.LinearLayoutWidget()

    for difficulty in difficulties:
        panel.add(ui.Button(difficulty, functools.partial(set_difficulty, difficulty)))

    ui.set_dialog(panel)
示例#30
0
    def __init__(self, client):
        super(ScreenWidget, self).__init__()
        width = 150

        def make_button(name, func):
            return ui.Button(name,
                             func,
                             force_width=ui.scale_for_device(width - 15),
                             padding=1)

        self.client = client

        if features.get('app.map_tiles'):
            import maptiles
            self.map = maptiles.MapWidget(client)
        else:
            self.map = mapdrawer.MapWidget(client, ui.init_zoom_levels())
        self.overview = OverviewWidget(client)
        self.console = ConsoleWidget(client)
        self.menu = gamemenu.Menu(client, ui.screen_width - width)
        self.end_turn_button = make_button('End turn', self.client.end_turn)
        self.empire_button = make_button('Empire', self.empire_dialog)
        self.taxes_panel = TaxesPanel(client)

        self.left_panel = ui.LinearLayoutWidget(spacing=0,
                                                center=True,
                                                marginleft=0)
        self.left_panel.widget_background = (190, 160, 110, 170)

        self.add(self.map, (0, 0))
        self.add(self.menu, (width, 0), align=ui.BOTTOM)
        self.add(self.left_panel, (0, 0), align=ui.LEFT)
        self.update_layout()

        self.left_panel.add(self.overview)
        self.left_panel.add(self.console.scroll)
        self.left_panel.add(self.end_turn_button)
        self.left_panel.add(self.taxes_panel)
        self.left_panel.add(ui.Spacing(0, 10))
        self.left_panel.add(self.empire_button)
        self.left_panel.add(self.menu.left_widget)

        if features.get('app.full_label_toggle_button'):
            full_label_toggle_button = ui.Button('city labels',
                                                 client.toggle_full_labels,
                                                 font=ui.consolefont)
            self.left_panel.add(full_label_toggle_button)

        # key_end_turn()

        self.focus = self.map