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)
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') 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 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)
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 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 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 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.screen.tick() 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)) line.add(ui.Button(" - ", functools.partial(change, type, -1), font=font)) line.add(ui.Spacing(10, 0)) line.add(ui.Button(" + ", functools.partial(change, type, +1), font=font)) else: line.add(ui.Spacing(123, 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)
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 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