def __init__(self, client): self.hidden = False spacing = 10 super(TileJoystick, self).__init__(spacing=spacing) self.client = client b = functools.partial(TileButton, self, client.client) top = ui.HorizontalLayoutWidget(spacing=spacing) top.add(b(freeciv.const.DIR8_NORTHWEST)) top.add(b(freeciv.const.DIR8_NORTH)) top.add(b(freeciv.const.DIR8_NORTHEAST)) self.add(top) center = ui.HorizontalLayoutWidget(spacing=spacing) center.add(b(freeciv.const.DIR8_WEST)) center.add(b(None)) center.add(b(freeciv.const.DIR8_EAST)) self.add(center) bottom = ui.HorizontalLayoutWidget(spacing=spacing) bottom.add(b(freeciv.const.DIR8_SOUTHWEST)) bottom.add(b(freeciv.const.DIR8_SOUTH)) bottom.add(b(freeciv.const.DIR8_SOUTHEAST)) self.add(bottom) self.update_layout()
def __init__(self, meeting): super(MeetingDialog, self).__init__() self.meeting = meeting self.left = ConditionsWidget(meeting.client.get_playing()) self.right = ConditionsWidget(meeting.counterpart) c = meeting.counterpart self.top = ui.HorizontalLayoutWidget() # Sir!, the %s ambassador has arrived \nWhat are your wishes? self.top.add(ui.Label('Meeting with ')) self.top.add(ui.Label(' ', image=c.get_flag())) self.top.add(ui.Label(' %s (%s)' % (c.get_nation_pl(), c.get_name()))) self.add(self.top) self.middle = ui.HorizontalLayoutWidget(spacing=10) w = 200 self.middle.add(ui.Bordered(self.left, force_width=w)) self.middle.add(ui.Bordered(self.right, force_width=w)) self.add(self.middle) self.add(ui.Button('Add condition', self.add_condition)) self.bottom = ui.HorizontalLayoutWidget(spacing=10) self.bottom.add(ui.Button('Cancel treaty', self.cancel_treaty)) self.bottom.add(ui.Button('Accept treaty', self.accept_treaty)) self.add(self.bottom)
def __init__(self): ui.AbsoluteLayoutWidget.__init__(self) self.load_background() self.left = ui.HorizontalLayoutWidget(spacing=10) self.left.add(ui.Spacing(0, 0)) self.right = ui.HorizontalLayoutWidget(spacing=10) self.cont = SpacingLayoutWidget(self.left, self.right, (ui.screen_width, 0)) self.add(create_aligned_widget(self.cont, ui.BOTTOM, (0, ui.screen_height - 10)), (0,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()
def __init__(self, client): ui.LinearLayoutWidget.__init__(self) 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)))
def setup_ui(self): self.items = [] self.tech_label = ui.Label('') self.add(self.tech_label) self.tech_goal_label = ui.Label('') self.add(self.tech_goal_label) self.tech_progress_label = ui.Label('', font=ui.consolefont) self.add(self.tech_progress_label) tech_panel = ui.HorizontalLayoutWidget(spacing=10) tech_panel.add(ui.Button('Change tech goal', self.research_goal_dialog)) tech_panel.add( ui.Button('Change current tech', self.research_current_dialog)) tech_panel.add( ui.Button('Technology tree', self.technology_tree_dialog)) self.add(tech_panel) self.add(ui.Label('Players')) self.add(ui.Button('Player list', self.player_list)) self.add( ui.Button( 'Taxes & Government', lambda: ui.set_dialog(gamescreen.TaxesDialog(self.client)))) self.add( ui.Button('More empire informations', self.get_info_label_text_popup)) self.update_layout()
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)
def add(handle, type, name, turns, stock, cost, ops, image): c = ui.HorizontalLayoutWidget() c.add(ui.Label(' ', image=image)) c.add( ui.Label('%s %s/%s %s' % (name, stock, cost, ops), functools.partial(change, type, handle))) panel.add(c)
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
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)
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))
def no_account(): def do_register(): login = login_field.get_value() passwd = passwd_field.get_value() mail = mail_field.get_value() if not login or not passwd or not mail: ui.message('Fill all fields.') elif passwd != passwd_repeat_field.get_value(): ui.message('Passwords don\'t match.') else: request(logged, 'register', login, passwd, mail) panel = ui.LinearLayoutWidget() login = ui.HorizontalLayoutWidget() login.add(ui.Label('Login:'******'Password:'******'*') passwd.add(passwd_field) panel.add(passwd) passwd_repeat = ui.HorizontalLayoutWidget() passwd_repeat.add(ui.Label('Repeat password:'******'*') passwd_repeat.add(passwd_repeat_field) panel.add(passwd_repeat) mail = ui.HorizontalLayoutWidget() mail.add(ui.Label('Mail:')) mail_field = ui.EditField() mail.add(mail_field) panel.add(mail) butts = ui.HorizontalLayoutWidget(spacing=10) butts.add(ui.Button('Register', do_register)) butts.add(ui.Button('Cancel', ui.back)) panel.add(butts) ui.set(panel)
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()
def get_citizen_icons(self): def rotate_specialist(i): self.city.rotate_specialist(i) # self.refresh() citizens = self.city.get_citizens() total = 0 for name, count in citizens: total += count panel1 = ui.HorizontalLayoutWidget(spacing=0) panel2 = None if total >= 14: panel2 = ui.HorizontalLayoutWidget(spacing=0) index = 0 for name, count in citizens: for i in xrange(count): try: suffix = index % 2 if panel2 is not None: suffix = ((index + 1) / 2) % 2 icon = icons.get_small_image( '%s-%d' % (name, suffix)) # man and woman except KeyError: icon = icons.get_small_image( name) # elvis, taxman, scientist w, h = icon.get_size() icon = icon.scale( (ui.scale_for_device(w * 2), ui.scale_for_device(h * 2))) if panel2 is None or index % 2 == 0: panel1.add( ui.Image(icon, functools.partial(rotate_specialist, index))) else: panel2.add( ui.Image(icon, functools.partial(rotate_specialist, index))) index += 1 if panel2 is None: return panel1 panel = ui.LinearLayoutWidget(spacing=0) panel.add(panel1) panel.add(panel2) return panel
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)
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)
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)
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()
def popup_unit_select_dialog(self, units): def focus(unit): unit.focus() ui.back() panel = ui.LinearLayoutWidget() for unit in units: name = unit.get_name() callback = functools.partial(focus, unit) p = ui.HorizontalLayoutWidget() p.add(ui.Image(unit.get_image(), callback)) # Label(' ' * 10, callback, image= p.add(ui.Button(name, callback)) panel.add(p) ui.set_dialog(panel, scroll=True)
def show_action_list(self, unit): def fcallback(action_ident): self.client.get_unit_in_focus().perform_activity(action_ident) ui.back() panel = ui.LinearLayoutWidget() for action_ident, action_name, action_length in unit.get_actions(): callback = functools.partial(fcallback, action_ident) hor = ui.HorizontalLayoutWidget() hor.add(ui.Image(get_order_sprite(action_name), callback)) hor.add(ui.Label('%s' % (action_name, ), callback)) panel.add(hor) ui.set_dialog(panel, scroll=True)
def update_tax(self): panel = ui.HorizontalLayoutWidget() tax, lux, science = 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') def add(value, img): for i in xrange(int(value / 10)): panel.add(ui.Image(img)) add(tax, tax_img) add(lux, lux_img) add(science, science_img) self.add(panel)
def player_list(self): def meet(player): ui.back() ui.back() player.meet() def do_break_treaty(player, type): player.cancel_pact(type) ui.back() ui.back() def break_treaty(player, type, ask): ui.ask(ask % dict(name=player.get_name()), lambda: do_break_treaty(player, type)) players = ui.LinearLayoutWidget() for player in self.client.get_players(): p = ui.HorizontalLayoutWidget() if player.can_meet(): p.add(ui.Button('Meet', functools.partial(meet, player))) p.add(ui.Label(' ', image=player.get_flag())) p.add( ui.Label('%s (%s)' % (player.get_name(), player.get_nation_adj()))) if player.gives_shared_vision(): p.add( ui.Button( 'Withdraw vision', functools.partial(break_treaty, player, CLAUSE_VISION, 'Withdraw vision?'))) if player.get_state() in (DS_CEASEFIRE, DS_PEACE, DS_ALLIANCE, DS_ARMISTICE): p.add( ui.Button( 'Break treaty', functools.partial(break_treaty, player, CLAUSE_CEASEFIRE, 'Break treaty with %(name)s?'))) players.add(p) ui.set_dialog(players, scroll=True)
def setup_ui(self): self.items = [] self.tech_label = ui.Label('') self.add(self.tech_label) tech_panel = ui.HorizontalLayoutWidget(spacing=10) tech_panel.add(ui.Button('Change tech goal', self.research_goal_dialog)) tech_panel.add( ui.Button('Change current tech', self.research_current_dialog)) self.add(tech_panel) self.add(ui.Label('Players')) self.add(ui.Button('Player list', self.player_list)) self.add( ui.Button( 'Taxes & Government', lambda: ui.set_dialog(gamescreen.TaxesDialog(self.client)))) self.update_layout()
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
def get_citizen_icons(self): def rotate_specialist(i): self.city.rotate_specialist(i) # self.refresh() panel = ui.HorizontalLayoutWidget(spacing=0) index = 0 for name, count in self.city.get_citizens(): for i in xrange(count): try: icon = icons.get_small_image( '%s-%d' % (name, i % 2)) # man and woman except KeyError: icon = icons.get_small_image( name) # elvis, taxman, scientist panel.add( ui.Image(icon, functools.partial(rotate_specialist, index))) index += 1 return panel
def update_tax(self): panel = ui.HorizontalLayoutWidget() tax, lux, science = self.client.get_tax_values() science_img = icons.get_small_image('scientist') w, h = science_img.get_size() science_img = science_img.scale( (ui.scale_for_device(w), ui.scale_for_device(h))) tax_img = icons.get_small_image('taxman').scale( (ui.scale_for_device(w), ui.scale_for_device(h))) lux_img = icons.get_small_image('elvis').scale( (ui.scale_for_device(w), ui.scale_for_device(h))) def add(value, img): for i in xrange(int(value / 10)): panel.add(ui.Image(img)) add(tax, tax_img) add(lux, lux_img) add(science, science_img) self.add(panel)
def show_marketnotice(): def never(): features.set_perm('app.marketnotice', False) ui.back() def okay(): osutil.open_market() never() msg = ''' If you enjoy playing Freeciv, please take a moment to rate the app. Thank you for your support!'''.strip() dialog = ui.LinearLayoutWidget() panel = ui.HorizontalLayoutWidget(spacing=10) panel.add(ui.Button('Okay', okay)) panel.add(ui.Button('Not now', ui.back)) panel.add(ui.Button('Never', never)) dialog.add(ui.Label(msg)) dialog.add(panel) ui.set_dialog(dialog)
def ask_if_sharing_allowed(then): def notokay(): features.set_perm('civsync.allow_sharing', 'false') ui.back() then() def okay(): features.set_perm('civsync.allow_sharing', 'true') ui.back() then() msg = \ 'civsync.com may put saves you upload to Dropbox on a public list, for others to play.' \ '\n\n' \ 'By clicking "I agree" you share your saves on CC0 license (public domain) ' \ 'and allow Freeciv to upload them to civsync.com.'.strip() dialog = ui.LinearLayoutWidget() panel = ui.HorizontalLayoutWidget(spacing=10) panel.add(ui.Button('I agree', okay)) panel.add(ui.Button('I don\'t agree', notokay)) dialog.add(help.LongTextWidget(msg, ui.screen_width / 3, ui.smallfont)) dialog.add(panel) ui.set_dialog(dialog)
def unit_select_dialog_popup(self, units): def focus(unit): unit.focus() ui.back() panel = ui.LinearLayoutWidget( spacing=0 ) #No vertical spacing because Images already contains margins. for unit in units: name = unit.get_name() callback = functools.partial(focus, unit) p = ui.HorizontalLayoutWidget(spacing=10) surf = unit.get_image() w, h = surf.get_size() image = surf.scale( (ui.scale_for_device(w), ui.scale_for_device(h))) surf.destroy() p.add(ui.Image(image, callback)) container = ui.LinearLayoutWidget(spacing=0) container.add(ui.Spacing(0, ui.scale_for_device(8))) container.add(ui.Button(name, callback)) p.add(container) panel.add(p) ui.set_dialog(panel, scroll=True)
def show_login_form(callback, msg=None): def logged(result): print 'Login successful' with open(save.get_save_dir() + '/civsync.sessid.txt', 'w') as f: f.write(session.sessid) callback() def do_login(): ui.back(anim=False) request(logged, 'login', login_field.get_value(), passwd_field.get_value()) def no_account(): def do_register(): login = login_field.get_value() passwd = passwd_field.get_value() mail = mail_field.get_value() if not login or not passwd or not mail: ui.message('Fill all fields.') elif passwd != passwd_repeat_field.get_value(): ui.message('Passwords don\'t match.') else: request(logged, 'register', login, passwd, mail) panel = ui.LinearLayoutWidget() login = ui.HorizontalLayoutWidget() login.add(ui.Label('Login:'******'Password:'******'*') passwd.add(passwd_field) panel.add(passwd) passwd_repeat = ui.HorizontalLayoutWidget() passwd_repeat.add(ui.Label('Repeat password:'******'*') passwd_repeat.add(passwd_repeat_field) panel.add(passwd_repeat) mail = ui.HorizontalLayoutWidget() mail.add(ui.Label('Mail:')) mail_field = ui.EditField() mail.add(mail_field) panel.add(mail) butts = ui.HorizontalLayoutWidget(spacing=10) butts.add(ui.Button('Register', do_register)) butts.add(ui.Button('Cancel', ui.back)) panel.add(butts) ui.set(panel) panel = ui.LinearLayoutWidget() login = ui.HorizontalLayoutWidget() login.add(ui.Label('Login:'******'Password:'******'*') passwd.add(passwd_field) panel.add(passwd) butts = ui.HorizontalLayoutWidget(spacing=10) butts.add(ui.Button('Login', do_login)) butts.add(ui.Button('No account?', no_account)) butts.add(ui.Button('Cancel', ui.back)) panel.add(butts) ui.set(panel, anim=False) if msg and msg != 'Not logged': ui.message(msg)