def _create_one_ui(self, child): s = None if child.tag == "h1": s = ui.String(self.parent, unicode(child.text)) s.set_size(self.sizes["h1"]) s.set_padding(*self.padding["h1"]) align = child.get("align") if align is not None: if align == "center": # x = self.width/2.0 - s._get_width()/2.0 # print "SET PADDING", x # s.set_padding(x, x, 0, x) # s.set_margin(x, x, x, x) pass elif child.tag == "h2": s = ui.String(self.parent, unicode(child.text)) s.set_size(self.sizes["h2"]) s.set_padding(*self.padding["h2"]) elif child.tag == "h3": s = ui.String(self.parent, unicode(child.text)) s.set_size(self.sizes["h3"]) s.set_padding(*self.padding["h3"]) elif child.tag == "p": # BUG split s = ui.MultiLineString(self.parent, unicode(child.text)) s.set_size(self.sizes["p"]) s.set_padding(*self.padding["p"])
def __init__ (self, parent = None, model = None, zoom = 1., *a, **k): assert parent assert model super (RegionComponent, self).__init__ (parent = parent, radius = region_radius, *a, **k) self.on_click = signal.Signal () self.signal_click.add (lambda ev: self.on_click (self)) self.set_enable_hitting (True) self.model = model model.connect (self) self._outline_width = 2.0 self._outline_color = sf.Color (0, 0, 0) self._fill_color = region_free_color self._rebuild_sprite () self._txt_troops = ui.String (self, u"0") self._txt_used = ui.String (self, u"0/0") self._txt_troops.set_size (25) self._txt_troops.set_center_rel (0.5, 0.5) self._txt_troops.set_position_rel (0.5, 0.45) self._txt_troops.set_color (sf.Color (255, 255, 255)) self._txt_troops._sprite.SetStyle (sf.String.Bold) self._txt_used.set_size (20) self._txt_used.set_center_rel (0.5, 0.5) self._txt_used.set_position_rel (0.5, 0.45) self._txt_used.set_color (sf.Color (255, 255, 255)) self._txt_used.set_visible (False) self._txt_name = widget.String (self, model.definition.name.title ()) self._txt_name.set_center_rel (.5, -1.3) self._txt_name.set_position_rel (.5, .45) self._txt_name.set_color (sf.Color (255, 255, 255, 128)) self._txt_name.set_size (15) self.set_scale (zoom, zoom) self.set_center_rel (.5, .5) self._update_troops () self._update_owner ()
def create_language_switcher(parent, lcn, stringparams = None, colors={}): us = [] for lang in lcn.get_language_support().get_supported_language_strings(): lname = all_languages[lang]["name"] u = ui.String(None, lname, **stringparams) u._name = lang us.append(u) ch = Changer( parent, us, None, colors["active"], colors["inactive"], colors["border"], 1.0) ch.signal_click.add(\ lambda e: lcn.set_language_string(e.active._name)) def switch_language(lang): try: lang = lang.language except: pass obj = [i for i in ch.objs if i._name == lang][0] ch.set_active(obj) lcn.set_language_string(obj._name) ch.switch_language = switch_language deflang = lcn.get_language_string() ch.switch_language(deflang) return ch
def do_setup(self, *a, **k): system = self.manager.system layer = ui.Layer(system.view) system.keys.get_key(key.escape).connect(self.manager.leave_state) cfg = ConfNode({ 'player-0': { 'name': 'jp', 'color': 1, 'position': 2, 'enabled': True }, 'player-2': { 'name': 'pj', 'color': 3, 'position': 4, 'enabled': True }, 'map': 'doc/map/worldmap.xml' }) world = create_game(cfg) comp = WorldComponent(layer, world) but = ui2.Button(layer, ui.String(layer, unicode('Testttt')), THEME) but.activate()
def game_hud_text(parent, string): frame = Frame(parent) frame.set_margin(7) frame.margin_top = 48 text = ui.String(frame, unicode(string)) text.set_size(18) text.set_position(14, 7) return text
def _build_continents (self): world = self.model self._continents = [] for c in world.map.continents.itervalues (): px, py = 0, 0 for r in c.regions: px += (r.shape.center.x + region_radius) * world.map.zoom py += (r.shape.center.y + region_radius) * world.map.zoom total = float (len (c.regions)) px /= total py /= total continent = ui.String (self, c.name.title () + " (%i)" % c.troops) continent.set_size (60) continent.set_color (sf.Color (255, 255, 255, 50)) continent.set_center_rel (.5, .5) continent.set_position (px, py) continent._sprite.SetStyle (sf.String.Bold) self._continents.append (continent)
def __init__(self, parent, theme=None): ui.FreeformContainer.__init__(self, parent) self.width = 750 self.height = 300 self.set_position_rel(ui.CENTER) self.set_center_rel(ui.CENTER) # In letters -- not anymore, now in pixels :D self.maxlength = 260 blackbox = ui.RoundedRectangle(None, 0, 0, self.width, self.height, theme.blackbox.radius, theme.blackbox.color, theme.blackbox.border, theme.blackbox.thickness) self.set_enable_hitting(True) self.add_back_child(blackbox) whitestr = ui.String(None, u"") whitebox = ui.RoundedRectangle(None, 170, 30, 300, whitestr._get_height() + 45, theme.whitebox.radius, theme.whitebox.color, theme.whitebox.border, theme.whitebox.thickness) whitestr.SetPosition(15, 7) whitestr.set_size(25) self.add_child(whitebox) whitebox.add_child(whitestr) self.whitestr = whitestr self.kconfig = _KeyboardConfig(self, theme) self.signal_text_entered = signalslot.Signal("text_entered") self.signal_text_failed = signalslot.Signal("text_failed") uiactions.move_out(self, 200)
def __init__(self, parent, theme=None): self.keys = set() self.is_shifted = False dir = theme.directory if theme else get_dir_of_python_file(__file__) start_x = 30 start_y = 90 x = start_x y = start_y key_unit_width = 50 key_unit_height = 50 for i in [ #{ "key": "!", "pos": (0.0, 0.0) }, #{ "key": "?", }, #{ "key": ".", }, #{ "key": ",", }, #{ "key": ":", }, #{ "key": ";", }, #{ "key": "+", }, #{ "key": "-", }, #{ "key": "_", }, #{ "key": "\"", }, #{ "key": "#", }, #{ "key": "$", }, #{ "key": "%", }, #{ "key": "&", }, #{ "key": "/", }, #{ "key": "(", }, #{ "key": ")", }, #{ "key": "=", }, #{ "key": "<", "pos": (0.0, 0.0) }, #{ "key": ">", }, #{ "key": "{", }, #{ "key": "}", }, #{ "key": "[", }, #{ "key": "]", }, #{ "key": "", }, #{ "key": "", }, #{ "key": "", }, #{ "key": "", }, # + accented chars # + Other european chars # + others? { "key": "1", "shift": "!", "pos": (1.0, 0.0) }, { "key": "2", "shift": "\"" }, { "key": "3", "shift": "#" }, { "key": "5", "shift": "%" }, { "key": "6", "shift": "&" }, { "key": "7", "shift": "/" }, { "key": "8", "shift": "(" }, { "key": "9", "shift": ")" }, { "key": "0", "shift": "=" }, { "key": "<-", "extra": "DEL", "pos": (13, 0) }, { "key": "q", "shift": "Q", "pos": (1.5, 1.0) }, { "key": "w", "shift": "W" }, { "key": "e", "shift": "E" }, { "key": "r", "shift": "R" }, { "key": "t", "shift": "T" }, { "key": "y", "shift": "Y" }, { "key": "u", "shift": "U" }, { "key": "i", "shift": "I" }, { "key": "o", "shift": "O" }, { "key": "p", "shift": "P" }, { "key": "a", "shift": "A", "pos": (2, 2.0) }, { "key": "s", "shift": "S" }, { "key": "d", "shift": "D" }, { "key": "f", "shift": "F" }, { "key": "g", "shift": "G" }, { "key": "h", "shift": "H" }, { "key": "j", "shift": "J" }, { "key": "k", "shift": "K" }, { "key": "l", "shift": "L" }, { "key": "<-/", "extra": "ENTER", "pos": (13, 1) }, { "key": "=^=", "extra": "SHIFTLEFT", "pos": (0.5, 3.0) }, { "key": "<", "shift": ">" }, { "key": "z", "shift": "Z" }, { "key": "x", "shift": "X" }, { "key": "c", "shift": "C" }, { "key": "v", "shift": "V" }, { "key": "b", "shift": "B" }, { "key": "n", "shift": "N" }, { "key": "m", "shift": "M" }, { "key": "=^=", "extra": "SHIFTRIGHT" }, ]: i["key"] = unicode(i["key"], "UTF-8") if "shift" in i: i["shift"] = unicode(i["shift"], "UTF-8") fname = None if "extra" in i: e = i["extra"] if False: pass elif e == "DEL": fname = dir + os.sep + "key_del.png" elif e == "ENTER": fname = dir + os.sep + "key_return.png" elif e == "SHIFTLEFT": fname = dir + os.sep + "key_shift_left.png" elif e == "SHIFTRIGHT": fname = dir + os.sep + "key_shift_right.png" else: # Key not supported print "KEY", e assert 0 else: fname = dir + os.sep + "one_key.png" u = _Key(None, fname, i) if "pos" in i: x = i["pos"][0] * key_unit_width + start_x y = i["pos"][1] * key_unit_height + start_y u.SetPosition(x, y) # XXX render this to the blackbox instead... parent.add_back_child(u) self.keys.add(u) if "extra" not in i: k = ui.String(None, i["key"]) yfuzz = -4 xfuzz = 0 k.SetPosition(u.GetPosition()[0] + u._get_width()/2.0 - \ k._get_width()/2.0 + xfuzz, u.GetPosition()[1] + u._get_height()/2.0 - \ k._get_height()/2.0 + yfuzz) parent.add_child(k) u.keysprite = k x += key_unit_width if x > parent.width - key_unit_width: x = start_x y += key_unit_height
def title_text(parent, text): txt = ui.String(parent, unicode(text)) txt.set_size(25) txt.set_color(sf.Color(255, 255, 255, 70)) txt._sprite.SetStyle(sf.String.Bold) return txt
def __init__(self, parent=None, player=None, *a, **k): super(PlayerComponent, self).__init__(parent, center=True, *a, **k) self.player = player self._can_change_cards = False self._menu_enabled = False move_to_player_position(self, player) # Area for windows self._menu_area = ui.FreeformContainer(self) self._menu_area.width = 1024 # HACK self._menu_area.height = 768 # The main button self._but_theme = theme.copy_button_theme(theme.small_button) pc = theme.player_color[player.color] self._but_theme.active.color = pc if (pc.r + pc.g + pc.b) / 3. > 64: self._but_theme.active.border = sf.Color(pc.r * .4, pc.g * .4, pc.b * .4) else: self._but_theme.active.border = sf.Color(pc.r + 40, pc.g + 40, pc.b + 40) self._but_main = widget.Button(self, None, 'data/icon/small.png', theme=self._but_theme) self._but_main.on_click += lambda ev: self.on_toggle_menu(self) self._txt_troops = ui.String(self._but_main, player.troops or '') self._txt_troops.set_center_rel(0.5, 0.5) self._txt_troops.set_position(28, 26) self._txt_troops.set_size(20) self._txt_troops._sprite.SetStyle(sf.String.Bold) player.on_set_player_troops += self._on_set_player_troops player.on_add_player_card += self._on_cards_change player.on_del_player_card += self._on_cards_change # The main menu self._menu_main = widget.VBox(self._menu_area) self._but_pass = widget.SmallButton(self._menu_main, None, 'data/icon/next-small.png') self._but_cards = widget.SmallButton(self._menu_main, None, 'data/icon/troops-small.png') self._but_mission = widget.SmallButton(self._menu_main, None, 'data/icon/world-small.png') # self._but_undo = widget.SmallButton ( # self._menu_main, None, 'data/icon/undo-small.png') self.padding_bottom = 0 self._menu_main.padding_bottom = 6 self._menu_main.set_visible(self._menu_enabled) self._position_menu(self._menu_main) self._but_mission.on_click += self._on_show_mission self._but_cards.on_click += self._on_show_cards self._but_pass.deactivate() self._but_pass.on_click += self.on_toggle_menu self._current_menu = self._menu_main
def __init__(self, parent=None, attacker=None, defender=None, audio=None, use_on_attack=True, *a, **k): super(AttackComponent, self).__init__(parent, *a, **k) self.on_attack = signal.Signal() self.on_retreat = signal.Signal() self.on_continue = signal.Signal() self.width = 1024 self.height = 768 self.audio = audio self.use_on_attack = use_on_attack self._dice_enabled = False self._sprite = None self.attacker = attacker self.defender = defender self._attacker_dices = DiceBox(self, 'data/icon/rdice%i.png', .58) self._defender_dices = DiceBox(self, 'data/icon/bdice%i.png', .42) if self.use_on_attack: self.attacker.used += 1 self.attacker.troops -= 1 self._but_continue = widget.Button(self, 'Continue', 'data/icon/next.png') self._but_continue.set_center_rel(.5, .5) self._but_continue.set_position_rel(.9, .5) self._but_continue.set_visible(False) self._but_continue.on_click += self._dispatch_continue self._box_attacker = widget.VBox(self) if use_on_attack: self._txt_attacker = ui.String( self._box_attacker, unicode(self.attacker.definition.name.title() + ": %i/%i" % (self.attacker.troops, self.attacker.used))) else: self._txt_attacker = ui.String( self._box_attacker, unicode(self.attacker.definition.name.title() + ": %i" % (self.attacker.troops))) set_attacker_text_style(self._txt_attacker) self._box_attacker_a = widget.HBox(self._box_attacker) self._box_attacker_b = widget.HBox(self._box_attacker) self._box_attacker.padding_bottom = 10 self._box_attacker_a.padding_right = 10 self._box_attacker_b.padding_right = 10 self._box_defender = widget.VBox(self) self._box_defender_txt = widget.HBox(self._box_defender) self._box_defender_txt.padding_left = 10 # DIRTY HACK, bugs in TF self._txt_defender = ui.String( self._box_defender_txt, unicode(self.defender.definition.name.title() + ": %i" % self.defender.troops)) set_defender_text_style(self._txt_defender) self._box_defender_a = widget.HBox(self._box_defender) self._box_defender_b = widget.HBox(self._box_defender) self._box_defender.padding_bottom = 10 self._box_defender_a.padding_left = 10 self._box_defender_b.padding_left = 10 self._box_defender_b.set_center_rel(-0.5, 0) self._box_defender_b.set_position_rel(0.5, 0) move_to_player_position(self._box_attacker, self.attacker.owner) move_to_player_position(self._box_defender, self.defender.owner) self._but_attacker_troops_inc = widget.SmallButton( self._box_attacker_a, None, 'data/icon/attacker-more.png') self._but_attacker_troops_dec = widget.SmallButton( self._box_attacker_a, None, 'data/icon/attacker-less.png') self._but_attacker_attack = widget.SmallButton(self._box_attacker_b, None, 'data/icon/attack.png') self._but_attacker_retreat = widget.SmallButton( self._box_attacker_b, None, 'data/icon/retreat.png') self._but_defender_troops_inc = widget.SmallButton( self._box_defender_a, None, 'data/icon/defender-more.png') self._but_defender_troops_dec = widget.SmallButton( self._box_defender_a, None, 'data/icon/defender-less.png') self._but_defender_attack = widget.SmallButton(self._box_defender_b, None, 'data/icon/attack.png') self._but_attacker_troops_inc.on_click += self._attacker_troops_inc self._but_attacker_troops_dec.on_click += self._attacker_troops_dec self._but_defender_troops_dec.on_click += self._defender_troops_dec self._but_defender_troops_inc.on_click += self._defender_troops_inc self._but_attacker_attack.on_click += self._on_attack_attacker self._but_defender_attack.on_click += self._on_attack_defender self._but_attacker_retreat.on_click += self._on_attack_retreat self.attacker.on_set_region_troops += self._on_change_attacker_txt self.attacker.on_set_region_used += self._on_change_attacker_txt self.defender.on_set_region_troops += self._on_change_defender_txt