def __init__(self, project): QtGui.QWidget.__init__(self) self.project = project ### coordinates ### self.coords = Label("Cursor coordinates") self.coords.setText("x\ny"); ### tools buttons ### self.penB = Button("pen (1)", "icons/tool_pen.png", self.penClicked, True) self.penB.setChecked(True) self.project.toolSetPenSign.connect(self.penClicked) self.pipetteB = Button("pipette (2)", "icons/tool_pipette.png", self.pipetteClicked, True) self.fillB = Button("fill (3)", "icons/tool_fill.png", self.fillClicked, True) self.moveB = Button("move (4)", "icons/tool_move.png", self.moveClicked, True) self.selectB = Button("select (5)", "icons/tool_select.png", self.selectClicked, True) ### Layout ### layout = QtGui.QVBoxLayout() layout.setSpacing(0) layout.addWidget(self.coords) layout.addWidget(self.penB) layout.addWidget(self.pipetteB) layout.addWidget(self.fillB) layout.addWidget(self.moveB) layout.addWidget(self.selectB) layout.addStretch() layout.setContentsMargins(6, 0, 6, 0) self.setLayout(layout)
def setup_creature_role(self): self.is_creature = True gamecard = self.gamecard self.power = 0 #gamecard.power self.toughness = 0 #gamecard.toughness self.damage = 0 #gamecard.currentDamage() #dispatcher.connect(self.change_value, signal=PowerToughnessModifiedEvent(), sender=gamecard) # XXX This will lead to a lot of events each time priority is passed # but I'm not sure how to do it otherwise for cards like "Coat of Arms", which use a lambda function # or for damage self.text = Label("", size=34, background=True, shadow=False, halign="center", valign="center") #self.text._scale = anim.animate(0, 2.0, dt=0.25, method="sine") self.text.scale = 2.0 #self.text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") self.text.orig_pos = euclid.Vector3(0, -self.height * 0.25, 0.001) self.text.zoom_pos = euclid.Vector3(self.width * 1.375, -self.height * 0.454, 0.01) self.text.pos = self.text.orig_pos #self.damage_text = Label("", size=34, background=True, shadow=False, halign="center", valign="center", color=(1., 0., 0., 1.)) #self.damage_text._scale = anim.animate(0.0, 0.0, dt=0.25, method="sine") #self.damage_text.scale = 0.4 #self.damage_text.visible = 0 #self.damage_text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") #self.damage_text.zoom_pos = euclid.Vector3(self.width*(1-.375),-self.height*0.454, 0.01) #self.damage_text.pos = self.damage_text.zoom_pos self.change_value() self.draw = self.draw_creature dispatcher.connect(self.change_value, signal=TimestepEvent())
def add_number_spark(self, number, start_pos, end_pos, dt=1.0, color=None, dim=2): random_offset = euclid.Vector3(self.randomizer.random() * 50 - 25, self.randomizer.random() * 30, 0) start_pos += random_offset end_pos += random_offset if color == None: color = (1., 1., 1., 1) elif isinstance(color, str): color = self.COLORS.get(color) else: color = color spark = Label(str(number), size=40, color=color, shadow=False, halign="center", valign="center", pos=start_pos) spark._pos.set_transition(dt=dt, method="ease_out_circ") #ease_out_back") spark.pos = end_pos spark.visible = anim.animate(1., 0., dt=dt) spark.scale = anim.animate(1.0, 1.3, dt=dt, method="sine") if dim == 2: self.active_sparks.append(spark) else: self.active_sparks_3d.append(spark)
def add_number_spark(self, number, start_pos, end_pos, dt=1.0, color=None, dim=2): random_offset = euclid.Vector3(self.randomizer.random()*50-25,self.randomizer.random()*30,0) start_pos += random_offset end_pos += random_offset if color == None: color=(1.,1.,1.,1) elif isinstance(color, str): color = self.COLORS.get(color) else: color = color spark = Label(str(number), size=40, color=color, shadow=False, halign="center", valign="center", pos=start_pos) spark._pos.set_transition(dt=dt, method="ease_out_circ") #ease_out_back") spark.pos = end_pos spark.visible = anim.animate(1., 0., dt=dt) spark.scale = anim.animate(1.0, 1.3, dt=dt, method="sine") if dim == 2: self.active_sparks.append(spark) else: self.active_sparks_3d.append(spark)
def __init__(self, pos=zero): super(SelectionList, self).__init__(pos) #self.options = [] #self.alpha = anim.animate(0, 0.9, dt=1.0, method="sine") self.border = 20 self.visible = anim.constant(0) #self.focus_idx = 0 self.large_size = 17 self.max_width = 700 #self.small_scale = 0.35 #self.intermediate_scale = 0.55 #self.layout = self.layout_normal self.prompt = Label("", size=self.large_size, halign="center", shadow=False)
def setup_creature_role(self): self.is_creature = True gamecard = self.gamecard self.power = 0 #gamecard.power self.toughness = 0 #gamecard.toughness self.damage = 0 #gamecard.currentDamage() #dispatcher.connect(self.change_value, signal=PowerToughnessModifiedEvent(), sender=gamecard) # XXX This will lead to a lot of events each time priority is passed # but I'm not sure how to do it otherwise for cards like "Coat of Arms", which use a lambda function # or for damage self.text = Label("", size=34, background=True, shadow=False, halign="center", valign="center") #self.text._scale = anim.animate(0, 2.0, dt=0.25, method="sine") self.text.scale = 2.0 #self.text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") self.text.orig_pos = euclid.Vector3(0,-self.height*0.25,0.001) self.text.zoom_pos = euclid.Vector3(self.width*1.375,-self.height*0.454, 0.01) self.text.pos = self.text.orig_pos #self.damage_text = Label("", size=34, background=True, shadow=False, halign="center", valign="center", color=(1., 0., 0., 1.)) #self.damage_text._scale = anim.animate(0.0, 0.0, dt=0.25, method="sine") #self.damage_text.scale = 0.4 #self.damage_text.visible = 0 #self.damage_text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") #self.damage_text.zoom_pos = euclid.Vector3(self.width*(1-.375),-self.height*0.454, 0.01) #self.damage_text.pos = self.damage_text.zoom_pos self.change_value() self.draw = self.draw_creature dispatcher.connect(self.change_value, signal=TimestepEvent())
def __init__(self, pos=zero, is_opponent=False): super(StatusView,self).__init__(pos) self._toggled = False self._spacing = 10 self._reveal_library = False self.color = (0.5, 0.5, 0.5) self.is_opponent = is_opponent #self._pos.set_transition(dt=0.1, method="linear") #symbols = ["life", "library", "hand", "graveyard", "exile"] symbols = ["life", "hand", "library", "graveyard", "exile"] self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip(symbols, [Image, Image, Image, Image, Image])]) for symbol in self.symbols.values(): symbol.alpha = 0.8 self.player_name = Label("", 11, halign="left", fontname = "Arial Bold", valign="center", shadow=False) #sizes = [20, 16, 14, 14, 14] sizes = [20, 14, 14, 14, 14] self.values = dict([(symbol, Label('', size, fontname = "Arial Bold", halign="center", valign="center", shadow=False)) for symbol, size in zip(symbols, sizes)]) #for val in self.values.values(): self.avatar = Image(pyglet.image.Texture.create(80,80)) self.avatar.shaking = 0 self.avatar.alpha = anim.animate(1., 1., dt=0.25) self.alpha = anim.animate(1., 1., dt=0.25) self.manapool = ManaPool(is_opponent) self.zone_view = ZoneView() self._library = LibraryImage(is_opponent) self.width, self.height = 145,135
def __init__(self, pos=zero): super(ManaView, self).__init__(pos) self._pos.set_transition(dt=1.0, method="ease_out_circ") self.colors = ["white", "blue", "black", "red", "green", "colorless"] self.colormap = dict(zip(self.colors, "WUBRG")) self.nummana = len(self.colors) self.symbols = [ManaImage(color) for color in self.colors] self.pool = [Label("", size=20) for i in range(self.nummana)] self.values = dict([(c, v) for c, v in zip(self.colors, self.pool)]) self.spend = [Label("0", size=30) for i in range(self.nummana)] self.spend_values = dict([(c, v) for c, v in zip(self.colors, self.spend)]) for p, s in zip(self.pool, self.spend): p.visible = anim.constant(1) s.visible = anim.constant(1) self.cost = Label("0", size=40, halign="center", background=True) self.select_mana = self.select_x = False self.layout()
def __init__(self, pos=zero): super(GameStatus, self).__init__(pos) self.screen_width = self.screen_height = 0 self._pos.set_transition(dt=0.5, method="ease_out_back") self.prompt = Label("", size=20, shadow=False, halign="center", valign="top", background=True) self.prompt.border = 3 self.prompt._pos.set_transition(dt=0.5, method="sine") self.show_log = False self.width = 400 self.gamelog = [ Label('', size=14, halign="left", width=self.width) for i in range(15) ] self.logger = []
def __init__(self, pos=zero): super(PhaseStatus, self).__init__(pos) self.visible = anim.constant(0) states = [('Untap', 'Untap'), ('Upkeep', 'Upkeep'), ('Draw', 'Draw'), ('Main1', 'Main 1'), ('BeginCombat', 'Beginning of combat'), ('Attack', 'Declare attackers'), ('Block', 'Declare blockers'), ('Damage', 'Combat damage'), ('EndCombat', 'End of combat'), ('Main2', 'Main 2'), ('EndStep', 'End Step'), ('Cleanup', 'Cleanup')] self.state_list = [s.lower() for s, t in states] self.grouping = [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0] self.state_map = dict([(key, (i, val)) for i, (key, val) in enumerate(states)]) self.states = [Image(key) for key, val in states] self.state_labels = [ Label(val, size=20, valign="center", shadow=False) for key, val in states ] self.state_text = None for state in self.states: state.visible = anim.constant(1.0) state.alpha = anim.animate(1.0, 1.0, dt=0.5, method="ease_out_circ") ##sine") state.scale = anim.animate(1.0, 1.0, dt=0.5, method="sine") state._pos.set_transition(dt=0.5, method="sine") for label in self.state_labels: label.scale = 0.8 label._pos.y = anim.constant( -100) # This is just a hack to hide it self.width = state.width self.current = 0 self.select = False self.curr_player = None self.turn_label = Label("", size=24, halign="center", valign="top", shadow=False) self.render_after_transform = self.render_game self.set_stops()
def __init__(self, pos=zero): super(GameStatus,self).__init__(pos) self.screen_width = self.screen_height = 0 self._pos.set_transition(dt=0.5, method="ease_out_back") self.prompt = Label("", size=20, shadow=False, halign="center", valign="top", background=True) self.prompt.border = 3 self.prompt._pos.set_transition(dt=0.5, method="sine") self.show_log = False self.width = 400 self.gamelog = [Label('', size=14, halign="left", width=self.width) for i in range(15)] self.logger = []
def info(string): from widget import WidgetState class InfoState(WidgetState): pass state = InfoState() from widget import Label Label(string, (None, None)).draw() update() state.quit()
def __init__(self, pos=zero, is_opponent=False): super(StatusView, self).__init__(pos) self._toggled = False self._spacing = 10 self._reveal_library = False self.color = (0.5, 0.5, 0.5) self.is_opponent = is_opponent #self._pos.set_transition(dt=0.1, method="linear") #symbols = ["life", "library", "hand", "graveyard", "exile"] symbols = ["life", "hand", "library", "graveyard", "exile"] self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip( symbols, [Image, Image, Image, Image, Image])]) for symbol in self.symbols.values(): symbol.alpha = 0.8 self.player_name = Label("", 11, halign="left", fontname="Arial Bold", valign="center", shadow=False) #sizes = [20, 16, 14, 14, 14] sizes = [20, 14, 14, 14, 14] self.values = dict([(symbol, Label('', size, fontname="Arial Bold", halign="center", valign="center", shadow=False)) for symbol, size in zip(symbols, sizes)]) #for val in self.values.values(): self.avatar = Image(pyglet.image.Texture.create(80, 80)) self.avatar.shaking = 0 self.avatar.alpha = anim.animate(1., 1., dt=0.25) self.alpha = anim.animate(1., 1., dt=0.25) self.manapool = ManaPool(is_opponent) self.zone_view = ZoneView() self._library = LibraryImage(is_opponent) self.width, self.height = 145, 135
def __init__(self, pos=zero): super(SelectionList,self).__init__(pos) #self.options = [] #self.alpha = anim.animate(0, 0.9, dt=1.0, method="sine") self.border = 20 self.visible = anim.constant(0) #self.focus_idx = 0 self.large_size = 17 self.max_width = 700 #self.small_scale = 0.35 #self.intermediate_scale = 0.55 #self.layout = self.layout_normal self.prompt = Label("", size=self.large_size, halign="center", shadow=False)
class GameStatus(Widget): def __init__(self, pos=zero): super(GameStatus,self).__init__(pos) self.screen_width = self.screen_height = 0 self._pos.set_transition(dt=0.5, method="ease_out_back") self.prompt = Label("", size=20, shadow=False, halign="center", valign="top", background=True) self.prompt.border = 3 self.prompt._pos.set_transition(dt=0.5, method="sine") self.show_log = False self.width = 400 self.gamelog = [Label('', size=14, halign="left", width=self.width) for i in range(15)] self.logger = [] def clear(self): self.prompt.set_text("") def resize(self, width, height, avail_width): self.screen_width = width self.screen_height = height self.pos = euclid.Vector3(width/2, height/2, 0) self.prompt.pos = euclid.Vector3(avail_width/2, 125-height/2, 0) def log(self, prompt): self.prompt.set_text(prompt) self.layout() def log_event(self, sender, msg): self.logger.append((len(self.logger)+1, sender, msg)) if self.show_log: self.construct_gamelog() def layout(self): pass def toggle_gamelog(self): self.show_log = not self.show_log self.construct_gamelog() def construct_gamelog(self): height = 0 for text, (i, sender, line) in zip(self.gamelog, self.logger[-len(self.gamelog):]): text.set_text("%d. %s"%(i, line)) height += text.height text.pos = euclid.Vector3(0, -height, 0) self.height = height def render_after_transform(self): self.prompt.render() if self.show_log: border = 10 w = border+self.width/2; h=border+self.height/2 glDisable(GL_TEXTURE_2D) glBegin(GL_LINE_LOOP) glVertex2f(-w, -h) glVertex2f(w, -h) glVertex2f(w,h) glVertex2f(-w, h) glEnd() glColor4f(0.1, 0.1, 0.1, 0.9) glBegin(GL_QUADS) glVertex2f(-w, -h) glVertex2f(w, -h) glVertex2f(w,h) glVertex2f(-w, h) glEnd() glEnable(GL_TEXTURE_2D) glTranslatef(-self.width/2,self.height/2,0) for item in self.gamelog: item.render()
def __init__(self, pos=zero): super(ManaView,self).__init__(pos) self._pos.set_transition(dt=1.0, method="ease_out_circ") self.colors = ["white", "blue", "black", "red", "green", "colorless"] self.colormap = dict(zip(self.colors, "WUBRG")) self.nummana = len(self.colors) self.symbols = [ManaImage(color) for color in self.colors] self.pool = [Label("", size=20) for i in range(self.nummana)] self.values = dict([(c,v) for c, v in zip(self.colors, self.pool)]) self.spend = [Label("0", size=30) for i in range(self.nummana)] self.spend_values = dict([(c,v) for c, v in zip(self.colors, self.spend)]) for p, s in zip(self.pool, self.spend): p.visible = anim.constant(1) s.visible = anim.constant(1) self.cost = Label("0", size=40, halign="center", background=True) self.select_mana = self.select_x = False self.layout()
def __init__(self, pos=zero): super(PhaseStatus,self).__init__(pos) self.visible = anim.constant(0) states = [('Untap','Untap'), ('Upkeep','Upkeep'), ('Draw','Draw'), ('Main1','Main 1'), ('BeginCombat','Beginning of combat'), ('Attack','Declare attackers'), ('Block','Declare blockers'), ('Damage','Combat damage'), ('EndCombat','End of combat'), ('Main2','Main 2'), ('EndStep','End Step'), ('Cleanup','Cleanup')] self.state_list = [s.lower() for s, t in states] self.grouping = [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0] self.state_map = dict([(key, (i, val)) for i,(key,val) in enumerate(states)]) self.states = [Image(key) for key, val in states] self.state_labels = [Label(val, size=20, valign="center", shadow=False) for key, val in states] self.state_text = None for state in self.states: state.visible = anim.constant(1.0) state.alpha = anim.animate(1.0, 1.0, dt=0.5, method="ease_out_circ") ##sine") state.scale = anim.animate(1.0, 1.0, dt=0.5, method="sine") state._pos.set_transition(dt=0.5, method="sine") for label in self.state_labels: label.scale = 0.8 label._pos.y = anim.constant(-100) # This is just a hack to hide it self.width = state.width self.current = 0 self.select = False self.curr_player = None self.turn_label = Label("", size=24, halign="center", valign="top", shadow=False) self.render_after_transform = self.render_game self.set_stops()
def __init__(self): from widget import Label WidgetState.__init__(self) Label("Waiting for Players to join", (None, None))
class StatusView(Widget): alpha = anim.Animatable() def __init__(self, pos=zero, is_opponent=False): super(StatusView, self).__init__(pos) self._toggled = False self._spacing = 10 self._reveal_library = False self.color = (0.5, 0.5, 0.5) self.is_opponent = is_opponent #self._pos.set_transition(dt=0.1, method="linear") #symbols = ["life", "library", "hand", "graveyard", "exile"] symbols = ["life", "hand", "library", "graveyard", "exile"] self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip( symbols, [Image, Image, Image, Image, Image])]) for symbol in self.symbols.values(): symbol.alpha = 0.8 self.player_name = Label("", 11, halign="left", fontname="Arial Bold", valign="center", shadow=False) #sizes = [20, 16, 14, 14, 14] sizes = [20, 14, 14, 14, 14] self.values = dict([(symbol, Label('', size, fontname="Arial Bold", halign="center", valign="center", shadow=False)) for symbol, size in zip(symbols, sizes)]) #for val in self.values.values(): self.avatar = Image(pyglet.image.Texture.create(80, 80)) self.avatar.shaking = 0 self.avatar.alpha = anim.animate(1., 1., dt=0.25) self.alpha = anim.animate(1., 1., dt=0.25) self.manapool = ManaPool(is_opponent) self.zone_view = ZoneView() self._library = LibraryImage(is_opponent) self.width, self.height = 145, 135 # self.layout() def resize(self, width, height): self.layout() # offset = 5 # if self.is_opponent: # pos = euclid.Vector3(offset, height-self.height-offset, 0) # else: # pos = euclid.Vector3(offset, offset, 0) # self._pos.set(pos) self._orig_pos = self.pos def clear(self): self.symbols['life'].rotatey = anim.constant(0) status = self.values counters = ["life", "hand", "library", "graveyard", "exile"] for c in counters: status[c].set_text(0) def toggle(self): if not self._toggled: x = self.width - self.values['life'].width - self._spacing * 1.5 self.pos += euclid.Vector3(-x, 0, 0) else: self.pos = self._orig_pos self._toggled = not self._toggled def toggle_library(self): self._reveal_library = not self._reveal_library def animate(self, status): symbol = self.symbols[status] symbol.scale = anim.animate(symbol.scale, 1.15 * symbol.scale, dt=1.0, method=lambda t: anim.oscillate_n(t, 3)) def handle_click(self, x, y): x -= self.pos.x y -= self.pos.y for status, item in self.symbols.items(): sx, sy, sw, sh = item.pos.x, item.pos.y, item.width / 2., item.height / 2. if x > sx - sw and x < sx + sw and y >= sy - sh and y <= sy + sh: return status else: return (0 < x <= self.width and 0 < y <= self.height) def setup_player(self, player, color, avatar): self.player = player self.color = color self.avatar.img = avatar.get_texture() self.player_name.set_text(player.name) self.update_life() for zone in ["library", "hand", "graveyard", "exile"]: self.update_zone(getattr(player, zone)) def new_turn(self, player): return life = self.symbols["life"] if self.player == player: life.rotatey = anim.animate(0, 360, dt=5, method='linear', extend='repeat') else: life.rotatey = anim.constant(0) def pass_priority(self, player): alpha = 1.0 if self.player == player else 0.6 self.alpha = self.avatar.alpha = alpha def animate_life(self, amount): symbol = self.symbols["life"] curr_scale = symbol._final_scale if amount > 0: final_scale = curr_scale * 1.5 else: final_scale = curr_scale * 0.5 symbol._scale = anim.animate(curr_scale, final_scale, dt=0.75, method="oscillate") symbol.alpha = anim.animate(symbol.alpha, 0.7, dt=0.75, method="oscillate") self.update_life() def update_life(self): status = self.values player = self.player counters = ["life"] #, "poison"] for c in counters: status[c].set_text(getattr(player, c)) def update_zone(self, zone): val = len(zone) status = self.values[str(zone)] if val > 0: # self.symbols[str(zone)].alpha = 0.8 status.set_text(val) else: # self.symbols[str(zone)].alpha = 0.4 status.set_text('0') if str(zone) == "library": self._library.update(zone) def layout(self): life_img, life = self.symbols["life"], self.values["life"] life_img.alpha = anim.constant(0.3) life_img._final_scale = 0.25 life_img._scale = anim.constant(life_img._final_scale) #life_img.visible = anim.constant(0) avatar = self.avatar spacing = self._spacing if self.is_opponent: x, y = spacing, life.height / 2. self.player_name.pos = euclid.Vector3(x, y, 0) self.manapool.pos = euclid.Vector3(self.width, 0, 0) x = self.width - life.width / 2 - spacing life.pos = life_img.pos = euclid.Vector3(x, y, 0) for i, status in enumerate(["graveyard", "library", "hand"]): symbol, value = self.symbols[status], self.values[status] #symbol.scale = 0.3 #symbol.pos = value.pos = euclid.Vector3(x, life.height+spacing+symbol.height/2+0.7*i*(symbol.height), 0) symbol.pos = value.pos = euclid.Vector3( x, life.height + spacing / 2 + symbol.height / 2 + i * (symbol.height), 0) library, lib = self._library, self.symbols["library"] library.scale = 0.5 library.pos = euclid.Vector3( self.width, life.height + spacing / 2 + 1.5 * lib.height, 0) #status = "library" #library, value = self.symbols["library"], self.values["library"] #library.scale = 0.3 #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, life.height+library.height/2+spacing,0) avatar.pos = euclid.Vector3( spacing + avatar.width / 2, life.height + avatar.height / 2 + spacing, 0) else: x, y = spacing, self.height - life.height / 2. self.player_name.pos = euclid.Vector3(x, y, 0) self.manapool.pos = euclid.Vector3(self.width, self.height, 0) x = self.width - life.width / 2 - spacing life.pos = life_img.pos = euclid.Vector3(x, y, 0) for i, status in enumerate(["graveyard", "library", "hand"][::-1]): symbol, value = self.symbols[status], self.values[status] #symbol.scale = 0.3 #symbol.pos = value.pos = euclid.Vector3(x, self.height-life.height-symbol.height/2-0.7*i*(symbol.height), 0) symbol.pos = value.pos = euclid.Vector3( x, self.height - life.height - symbol.height / 2 - i * (symbol.height) - spacing / 2, 0) library, lib = self._library, self.symbols["library"] library.scale = 0.5 library.pos = euclid.Vector3(self.width, 1.5 * lib.height, 0) #status = "library" #library, value = self.symbols["library"], self.values["library"] #library.scale = 0.3 #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, self.height-life.height-library.height/2-spacing,0) avatar.pos = euclid.Vector3( spacing + avatar.width / 2, self.height - life.height - avatar.height / 2 - spacing, 0) def render_after_transform(self): ac = self.color glColor4f(ac[0], ac[1], ac[2], self.alpha) life_height = self.values['life'].height h1, h2 = self.height - life_height, life_height if self.is_opponent: h1, h2 = h2, h1 render_9_part("box4", self.width, h1, x=0, y=0) render_9_part("box4", self.width, h2, x=0, y=h1) self.avatar.render() self.player_name.render() for status in ["life", "library", "hand", "graveyard"]: #, "exile"]: symbol, value = self.symbols[status], self.values[status] symbol.render() value.render() self.manapool.render() self.zone_view.render() if self._reveal_library: self._library.render()
class SelectionList(Widget): alpha = anim.Animatable() def __init__(self, pos=zero): super(SelectionList,self).__init__(pos) #self.options = [] #self.alpha = anim.animate(0, 0.9, dt=1.0, method="sine") self.border = 20 self.visible = anim.constant(0) #self.focus_idx = 0 self.large_size = 17 self.max_width = 700 #self.small_scale = 0.35 #self.intermediate_scale = 0.55 #self.layout = self.layout_normal self.prompt = Label("", size=self.large_size, halign="center", shadow=False) #def move_up(self): # if self.visible == 1 and self.focus_idx > 0: # self.focus_dir = -1 # self.options[self.focus_idx], self.options[self.focus_idx+self.focus_dir] = self.options[self.focus_idx+self.focus_dir], self.options[self.focus_idx] # self.focus_idx += self.focus_dir # self.layout() #def move_down(self): # if self.visible == 1 and self.focus_idx < len(self.options)-1: # self.focus_dir = 1 # self.options[self.focus_idx], self.options[self.focus_idx+self.focus_dir] = self.options[self.focus_idx+self.focus_dir], self.options[self.focus_idx] # self.focus_idx += self.focus_dir # self.layout() #def focus_previous(self): # if self.visible == 1 and self.focus_idx > 0: # self.focus_dir = -1 # self.focus_idx += self.focus_dir # self.layout() #def focus_next(self): # if self.visible == 1 and self.focus_idx < len(self.options)-1: # self.focus_dir = 1 # self.focus_idx += self.focus_dir # self.layout() #def hide(self): # for item, val in self.options: # item.pos = zero # self.visible = anim.animate(1., 0.0, dt=0.1) def construct(self, prompt, sellist): self.prompt.set_text(prompt) max_width = self.max_width document = mtg_decoder.decode_text(u'\u2028'.join([str(val[0]) for val in sellist])) choice_list = pyglet.text.DocumentLabel(document, multiline=True, width=max_width, anchor_x = "center", anchor_y="center") choice_list.set_style("color", (255,255,255,255)) choice_list.set_style("font_name", "Arial") choice_list.set_style("font_size", 13.5) choice_list.set_style("halign", "center") self.choice_list = choice_list self.choices = [val[1] for val in sellist] #self.options = [(Label(str(val[0]), size=13.5, halign="center", shadow=False), val[1]) for val in sellist] #y = 0 #for item, val in self.options: # item._scale = anim.animate(1.0, 1.0, dt=dt, method=method) #self.focus_idx = len(self.options)/2 #self.layout() #self.width = max([item[0].width for item in self.options]+[self.prompt.width]) #self.height = sum([item[0].height for item in self.options]+[self.prompt.height]) #self.scroll = self.height/len(self.options) self.width = max(self.prompt.width, choice_list.content_width) self.height = choice_list.content_height+self.prompt.height self.prompt._pos.set(euclid.Vector3(0,(self.height-self.prompt.height)/2, 0)) choice_list.x = (max_width-self.width)/2 #def layout_normal(self): # x = y = 0 # self.prompt.scale = 0.7 # y -= self.prompt.height # self.prompt.pos = euclid.Vector3(0, y, 0) # for option, val in self.options: # #option.scale = 0.45 # y -= option.height # option.pos = euclid.Vector3(0, y, 0) #def layout_resize(self): # x = y = 0 # idx = self.focus_idx # self.prompt.scale = 0.7 # y -= self.prompt.height # self.prompt.pos = euclid.Vector3(0, y, 0) # count = 0 # for option, val in self.options[:idx]: # if count == idx - 1: option.scale = self.intermediate_scale # else: option.scale = self.small_scale # y -= option.height # option.pos = euclid.Vector3(0,y,0) # count += 1 # option, val = self.options[idx] # option.scale = 1.0 # y -= option.height # option.pos = euclid.Vector3(0,y,0) # count += 1 # for option, val in self.options[idx+1:]: # if count == idx + 1: option.scale = self.intermediate_scale # else: option.scale = self.small_scale # y -= option.height # option.pos = euclid.Vector3(0,y,0) # count += 1 def selection(self, indices, all): if not all: sel = [self.choices[i] for i in indices] if len(sel) == 1: sel = sel[0] return sel else: return [self.choices[i] for i in range(len(self.choices)-1,-1,-1)] def handle_click(self, x, y): choice_list = self.choice_list xpos, ypos, cwidth, cheight = choice_list.x, choice_list.y, choice_list.content_width, choice_list.content_height y += ypos + cheight/2 if 0 < y <= cheight: num_choices = len(self.choices) return num_choices - int(y // (cheight/num_choices)) - 1 else: return -1 def render_after_transform(self): w, h = self.border*2+self.width, self.border*2+self.height render_9_part("box4", w, h, x = -w/2, y = -h/2) self.prompt.render() self.choice_list.draw()
class PhaseStatus(Widget): def __init__(self, pos=zero): super(PhaseStatus,self).__init__(pos) self.visible = anim.constant(0) states = [('Untap','Untap'), ('Upkeep','Upkeep'), ('Draw','Draw'), ('Main1','Main 1'), ('BeginCombat','Beginning of combat'), ('Attack','Declare attackers'), ('Block','Declare blockers'), ('Damage','Combat damage'), ('EndCombat','End of combat'), ('Main2','Main 2'), ('EndStep','End Step'), ('Cleanup','Cleanup')] self.state_list = [s.lower() for s, t in states] self.grouping = [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0] self.state_map = dict([(key, (i, val)) for i,(key,val) in enumerate(states)]) self.states = [Image(key) for key, val in states] self.state_labels = [Label(val, size=20, valign="center", shadow=False) for key, val in states] self.state_text = None for state in self.states: state.visible = anim.constant(1.0) state.alpha = anim.animate(1.0, 1.0, dt=0.5, method="ease_out_circ") ##sine") state.scale = anim.animate(1.0, 1.0, dt=0.5, method="sine") state._pos.set_transition(dt=0.5, method="sine") for label in self.state_labels: label.scale = 0.8 label._pos.y = anim.constant(-100) # This is just a hack to hide it self.width = state.width self.current = 0 self.select = False self.curr_player = None self.turn_label = Label("", size=24, halign="center", valign="top", shadow=False) self.render_after_transform = self.render_game self.set_stops() def set_stops(self): self.my_turn_stops = set([state for state, val in config.items("my stops") if val == "No"]) self.opponent_turn_stops = set([state for state, val in config.items("opponent stops") if val == "No"]) def toggle_select(self, other=False): self.select = not self.select if self.select: self.old_dir = self.dir self.old_align = self.state_labels[0].main_text.halign if other: self.turn_label.set_text("Opponent's turn") self.dir = -1 else: self.turn_label.set_text("Your turn") self.dir = 1 self.layout_big() self.old_pos = self.pos self.pos = euclid.Vector3(self.screen_width/2, (self.screen_height+self.height)/2, 0) self.render_after_transform = self.render_select else: self.dir = self.old_dir for label in self.state_labels: label.main_text.halign = self.old_align self.layout() self.pos = self.old_pos self.render_after_transform = self.render_game def resize(self, width, height): self.screen_width = width self.screen_height = height if self.select: self.pos = euclid.Vector3(self.screen_width/2, (self.screen_height+self.height)/2, 0) if self.curr_player == self.player: self.old_pos = euclid.Vector3(0, (self.screen_height+self.height)/2, 0) else: self.old_pos = euclid.Vector3(self.screen_width, (self.screen_height+self.height)/2, 0) elif self.curr_player: if self.curr_player == self.player: self.pos = euclid.Vector3(0, (self.screen_height+self.height)/2, 0) else: self.pos = euclid.Vector3(self.screen_width, (self.screen_height+self.height)/2, 0) def handle_click(self, x, y): x -= self.pos.x y -= self.pos.y for key, (i, val) in self.state_map.items(): #state in self.states: state = self.states[i] if state.visible == 0: continue sx, sy, sw, sh = state.pos.x, state.pos.y, state.width/2., state.height/2. if x > sx-sw and x < sx+sw and y >= sy-sh and y <= sy+sh: return key, state, self.state_labels[i] else: return None def layout_big(self): y = 0 i = 0 for symbol, label in zip(self.states, self.state_labels): symbol.alpha = 1.0 symbol.scale = 1.0 symbol.color = (1, 1, 1) hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh*.5 y -= hh x = self.dir*symbol.width symbol.pos = euclid.Vector3(0, y, 0) label.pos = euclid.Vector3(1.1*x/2, y, 0) label.scale = 0.8 y -= hh i += 1 self.height = -y self.turn_label.pos = zero # This is because the untap symbol is hidden def layout_small(self): y = 0 i = 0 for symbol in self.states: symbol.alpha = 0.75 symbol.scale = 0.75 hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh*.5 y -= hh symbol.pos = euclid.Vector3(-symbol.width/2, y, 0) y -= hh i += 1 self.height = -y def layout(self): y = 0 dir = self.dir i = 0 def stop_incr(state): if dir == 1: stops = self.my_turn_stops else: stops = self.opponent_turn_stops if state in stops: return 0 else: return dir*3 incr = [stop_incr(state) for state in self.state_list[::-1]] for symbol in self.states[:self.current]: symbol.alpha = 0.75 symbol.scale = 0.75 symbol.color = (1, 1, 1) hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh*.75 y -= hh symbol.pos = euclid.Vector3(dir*symbol.width/2+incr.pop(), y, 0) y -= hh i += 1 incr.pop() curr_state = self.states[self.current] curr_state.alpha = 1.0 curr_state.scale = 1.25 curr_state.color = self.marker_color nhh = curr_state.height/2 if self.grouping[i] == 1: y -= nhh*.75 i += 1 y -= nhh x = dir*curr_state.width curr_state.pos = euclid.Vector3(x/2, y, 0) self.state_text.pos = euclid.Vector3(1.1*x, y, 0) y -= nhh for symbol in self.states[self.current+1:]: symbol.alpha = 0.75 symbol.scale = 0.75 hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh*.75 y -= hh symbol.pos = euclid.Vector3(dir*symbol.width/2+incr.pop(), y, 0) symbol.color = (1, 1, 1) y -= hh i += 1 self.height = -y def render_game(self): for state in self.states: state.render() self.state_text.render() def render_select(self): glColor4f(0.1, 0.1, 0.1, .9) glDisable(GL_TEXTURE_2D) glBegin(GL_QUADS) w = self.screen_width/2; h = (self.screen_height+self.height)/2 glVertex2f(-w, -h) glVertex2f(w, -h) glVertex2f(w,h) glVertex2f(-w, h) glEnd() glEnable(GL_TEXTURE_2D) for state, label in zip(self.states, self.state_labels): state.render() label.render() self.turn_label.render() def clear(self): self.dir = 1 self.current_state = self.states[0] self.state_text = self.state_labels[0] self.marker_color = (1.0, 1.0, 1.0) self.layout() def setup_player_colors(self, player, self_color, other_color): self.player = player self.self_color = self_color self.other_color = other_color self.marker_color = self_color def check_my_stop(self): return self.current_state in self.my_turn_stops def check_opponent_stop(self): return self.current_state in self.opponent_turn_stops def change_focus(self, sender): if sender == self.player: self.marker_color = self.self_color if not self.select: self.states[self.current].color = self.marker_color else: self.marker_color = self.other_color if not self.select: self.states[self.current].color = self.marker_color def pass_priority(self, player=None): if player == self.player: self.marker_color = self.self_color if not self.select: self.states[self.current].color = self.marker_color else: self.marker_color = self.other_color if not self.select: self.states[self.current].color = self.marker_color def new_turn(self, player=None): self.curr_player = player if player == self.player: if not self.select: self.dir = 1 self.pos = euclid.Vector3(0, (self.screen_height+self.height)/2, 0) for label in self.state_labels: label.main_text.halign = "left" else: self.old_dir = 1 self.old_align = "left" self.old_pos = euclid.Vector3(0, (self.screen_height+self.height)/2, 0) else: if not self.select: self.dir = -1 self.pos = euclid.Vector3(self.screen_width, (self.screen_height+self.height)/2, 0) for label in self.state_labels: label.main_text.halign = "right" else: self.old_dir = -1 self.old_align = "right" self.old_pos = euclid.Vector3(self.screen_width, (self.screen_height+self.height)/2, 0) def set_phase(self, state): self.current_state = state.lower() if state in self.state_map: self.current, txt = self.state_map[state] self.state_text = self.state_labels[self.current] if not self.select: self.state_text._pos.x = anim.animate(0, 0, dt=0.5, method="ease_out_circ") #sine") self.layout()
class PhaseStatus(Widget): def __init__(self, pos=zero): super(PhaseStatus, self).__init__(pos) self.visible = anim.constant(0) states = [('Untap', 'Untap'), ('Upkeep', 'Upkeep'), ('Draw', 'Draw'), ('Main1', 'Main 1'), ('BeginCombat', 'Beginning of combat'), ('Attack', 'Declare attackers'), ('Block', 'Declare blockers'), ('Damage', 'Combat damage'), ('EndCombat', 'End of combat'), ('Main2', 'Main 2'), ('EndStep', 'End Step'), ('Cleanup', 'Cleanup')] self.state_list = [s.lower() for s, t in states] self.grouping = [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0] self.state_map = dict([(key, (i, val)) for i, (key, val) in enumerate(states)]) self.states = [Image(key) for key, val in states] self.state_labels = [ Label(val, size=20, valign="center", shadow=False) for key, val in states ] self.state_text = None for state in self.states: state.visible = anim.constant(1.0) state.alpha = anim.animate(1.0, 1.0, dt=0.5, method="ease_out_circ") ##sine") state.scale = anim.animate(1.0, 1.0, dt=0.5, method="sine") state._pos.set_transition(dt=0.5, method="sine") for label in self.state_labels: label.scale = 0.8 label._pos.y = anim.constant( -100) # This is just a hack to hide it self.width = state.width self.current = 0 self.select = False self.curr_player = None self.turn_label = Label("", size=24, halign="center", valign="top", shadow=False) self.render_after_transform = self.render_game self.set_stops() def set_stops(self): self.my_turn_stops = set( [state for state, val in config.items("my stops") if val == "No"]) self.opponent_turn_stops = set([ state for state, val in config.items("opponent stops") if val == "No" ]) def toggle_select(self, other=False): self.select = not self.select if self.select: self.old_dir = self.dir self.old_align = self.state_labels[0].main_text.halign if other: self.turn_label.set_text("Opponent's turn") self.dir = -1 else: self.turn_label.set_text("Your turn") self.dir = 1 self.layout_big() self.old_pos = self.pos self.pos = euclid.Vector3(self.screen_width / 2, (self.screen_height + self.height) / 2, 0) self.render_after_transform = self.render_select else: self.dir = self.old_dir for label in self.state_labels: label.main_text.halign = self.old_align self.layout() self.pos = self.old_pos self.render_after_transform = self.render_game def resize(self, width, height): self.screen_width = width self.screen_height = height if self.select: self.pos = euclid.Vector3(self.screen_width / 2, (self.screen_height + self.height) / 2, 0) if self.curr_player == self.player: self.old_pos = euclid.Vector3( 0, (self.screen_height + self.height) / 2, 0) else: self.old_pos = euclid.Vector3( self.screen_width, (self.screen_height + self.height) / 2, 0) elif self.curr_player: if self.curr_player == self.player: self.pos = euclid.Vector3( 0, (self.screen_height + self.height) / 2, 0) else: self.pos = euclid.Vector3( self.screen_width, (self.screen_height + self.height) / 2, 0) def handle_click(self, x, y): x -= self.pos.x y -= self.pos.y for key, (i, val) in self.state_map.items(): #state in self.states: state = self.states[i] if state.visible == 0: continue sx, sy, sw, sh = state.pos.x, state.pos.y, state.width / 2., state.height / 2. if x > sx - sw and x < sx + sw and y >= sy - sh and y <= sy + sh: return key, state, self.state_labels[i] else: return None def layout_big(self): y = 0 i = 0 for symbol, label in zip(self.states, self.state_labels): symbol.alpha = 1.0 symbol.scale = 1.0 symbol.color = (1, 1, 1) hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh * .5 y -= hh x = self.dir * symbol.width symbol.pos = euclid.Vector3(0, y, 0) label.pos = euclid.Vector3(1.1 * x / 2, y, 0) label.scale = 0.8 y -= hh i += 1 self.height = -y self.turn_label.pos = zero # This is because the untap symbol is hidden def layout_small(self): y = 0 i = 0 for symbol in self.states: symbol.alpha = 0.75 symbol.scale = 0.75 hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh * .5 y -= hh symbol.pos = euclid.Vector3(-symbol.width / 2, y, 0) y -= hh i += 1 self.height = -y def layout(self): y = 0 dir = self.dir i = 0 def stop_incr(state): if dir == 1: stops = self.my_turn_stops else: stops = self.opponent_turn_stops if state in stops: return 0 else: return dir * 3 incr = [stop_incr(state) for state in self.state_list[::-1]] for symbol in self.states[:self.current]: symbol.alpha = 0.75 symbol.scale = 0.75 symbol.color = (1, 1, 1) hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh * .75 y -= hh symbol.pos = euclid.Vector3(dir * symbol.width / 2 + incr.pop(), y, 0) y -= hh i += 1 incr.pop() curr_state = self.states[self.current] curr_state.alpha = 1.0 curr_state.scale = 1.25 curr_state.color = self.marker_color nhh = curr_state.height / 2 if self.grouping[i] == 1: y -= nhh * .75 i += 1 y -= nhh x = dir * curr_state.width curr_state.pos = euclid.Vector3(x / 2, y, 0) self.state_text.pos = euclid.Vector3(1.1 * x, y, 0) y -= nhh for symbol in self.states[self.current + 1:]: symbol.alpha = 0.75 symbol.scale = 0.75 hh = symbol.height / 2 if self.grouping[i] == 1: y -= hh * .75 y -= hh symbol.pos = euclid.Vector3(dir * symbol.width / 2 + incr.pop(), y, 0) symbol.color = (1, 1, 1) y -= hh i += 1 self.height = -y def render_game(self): for state in self.states: state.render() self.state_text.render() def render_select(self): glColor4f(0.1, 0.1, 0.1, .9) glDisable(GL_TEXTURE_2D) glBegin(GL_QUADS) w = self.screen_width / 2 h = (self.screen_height + self.height) / 2 glVertex2f(-w, -h) glVertex2f(w, -h) glVertex2f(w, h) glVertex2f(-w, h) glEnd() glEnable(GL_TEXTURE_2D) for state, label in zip(self.states, self.state_labels): state.render() label.render() self.turn_label.render() def clear(self): self.dir = 1 self.current_state = self.states[0] self.state_text = self.state_labels[0] self.marker_color = (1.0, 1.0, 1.0) self.layout() def setup_player_colors(self, player, self_color, other_color): self.player = player self.self_color = self_color self.other_color = other_color self.marker_color = self_color def check_my_stop(self): return self.current_state in self.my_turn_stops def check_opponent_stop(self): return self.current_state in self.opponent_turn_stops def change_focus(self, sender): if sender == self.player: self.marker_color = self.self_color if not self.select: self.states[self.current].color = self.marker_color else: self.marker_color = self.other_color if not self.select: self.states[self.current].color = self.marker_color def pass_priority(self, player=None): if player == self.player: self.marker_color = self.self_color if not self.select: self.states[self.current].color = self.marker_color else: self.marker_color = self.other_color if not self.select: self.states[self.current].color = self.marker_color def new_turn(self, player=None): self.curr_player = player if player == self.player: if not self.select: self.dir = 1 self.pos = euclid.Vector3( 0, (self.screen_height + self.height) / 2, 0) for label in self.state_labels: label.main_text.halign = "left" else: self.old_dir = 1 self.old_align = "left" self.old_pos = euclid.Vector3( 0, (self.screen_height + self.height) / 2, 0) else: if not self.select: self.dir = -1 self.pos = euclid.Vector3( self.screen_width, (self.screen_height + self.height) / 2, 0) for label in self.state_labels: label.main_text.halign = "right" else: self.old_dir = -1 self.old_align = "right" self.old_pos = euclid.Vector3( self.screen_width, (self.screen_height + self.height) / 2, 0) def set_phase(self, state): self.current_state = state.lower() if state in self.state_map: self.current, txt = self.state_map[state] self.state_text = self.state_labels[self.current] if not self.select: self.state_text._pos.x = anim.animate( 0, 0, dt=0.5, method="ease_out_circ") #sine") self.layout()
class StatusView(Widget): alpha = anim.Animatable() def __init__(self, pos=zero, is_opponent=False): super(StatusView,self).__init__(pos) self._toggled = False self._spacing = 10 self._reveal_library = False self.color = (0.5, 0.5, 0.5) self.is_opponent = is_opponent #self._pos.set_transition(dt=0.1, method="linear") #symbols = ["life", "library", "hand", "graveyard", "exile"] symbols = ["life", "hand", "library", "graveyard", "exile"] self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip(symbols, [Image, Image, Image, Image, Image])]) for symbol in self.symbols.values(): symbol.alpha = 0.8 self.player_name = Label("", 11, halign="left", fontname = "Arial Bold", valign="center", shadow=False) #sizes = [20, 16, 14, 14, 14] sizes = [20, 14, 14, 14, 14] self.values = dict([(symbol, Label('', size, fontname = "Arial Bold", halign="center", valign="center", shadow=False)) for symbol, size in zip(symbols, sizes)]) #for val in self.values.values(): self.avatar = Image(pyglet.image.Texture.create(80,80)) self.avatar.shaking = 0 self.avatar.alpha = anim.animate(1., 1., dt=0.25) self.alpha = anim.animate(1., 1., dt=0.25) self.manapool = ManaPool(is_opponent) self.zone_view = ZoneView() self._library = LibraryImage(is_opponent) self.width, self.height = 145,135 # self.layout() def resize(self, width, height): self.layout() # offset = 5 # if self.is_opponent: # pos = euclid.Vector3(offset, height-self.height-offset, 0) # else: # pos = euclid.Vector3(offset, offset, 0) # self._pos.set(pos) self._orig_pos = self.pos def clear(self): self.symbols['life'].rotatey = anim.constant(0) status = self.values counters = ["life", "hand", "library", "graveyard", "exile"] for c in counters: status[c].set_text(0) def toggle(self): if not self._toggled: x = self.width - self.values['life'].width-self._spacing*1.5 self.pos += euclid.Vector3(-x, 0, 0) else: self.pos = self._orig_pos self._toggled = not self._toggled def toggle_library(self): self._reveal_library = not self._reveal_library def animate(self, status): symbol = self.symbols[status] symbol.scale = anim.animate(symbol.scale, 1.15*symbol.scale, dt=1.0, method=lambda t: anim.oscillate_n(t, 3)) def handle_click(self, x, y): x -= self.pos.x y -= self.pos.y for status, item in self.symbols.items(): sx, sy, sw, sh = item.pos.x, item.pos.y, item.width/2., item.height/2. if x > sx-sw and x < sx+sw and y >= sy-sh and y <= sy+sh: return status else: return (0 < x <= self.width and 0 < y <= self.height) def setup_player(self, player, color, avatar): self.player = player self.color = color self.avatar.img = avatar.get_texture() self.player_name.set_text(player.name) self.update_life() for zone in ["library", "hand", "graveyard", "exile"]: self.update_zone(getattr(player, zone)) def new_turn(self, player): return life = self.symbols["life"] if self.player == player: life.rotatey = anim.animate(0,360,dt=5,method='linear',extend='repeat') else: life.rotatey = anim.constant(0) def pass_priority(self, player): alpha = 1.0 if self.player == player else 0.6 self.alpha = self.avatar.alpha = alpha def animate_life(self, amount): symbol = self.symbols["life"] curr_scale = symbol._final_scale if amount > 0: final_scale = curr_scale*1.5 else: final_scale = curr_scale*0.5 symbol._scale = anim.animate(curr_scale, final_scale,dt=0.75, method="oscillate") symbol.alpha = anim.animate(symbol.alpha, 0.7,dt=0.75, method="oscillate") self.update_life() def update_life(self): status = self.values player = self.player counters = ["life"] #, "poison"] for c in counters: status[c].set_text(getattr(player, c)) def update_zone(self, zone): val = len(zone) status = self.values[str(zone)] if val > 0: # self.symbols[str(zone)].alpha = 0.8 status.set_text(val) else: # self.symbols[str(zone)].alpha = 0.4 status.set_text('0') if str(zone) == "library": self._library.update(zone) def layout(self): life_img, life = self.symbols["life"], self.values["life"] life_img.alpha = anim.constant(0.3) life_img._final_scale = 0.25 life_img._scale = anim.constant(life_img._final_scale) #life_img.visible = anim.constant(0) avatar = self.avatar spacing = self._spacing if self.is_opponent: x, y = spacing, life.height / 2. self.player_name.pos = euclid.Vector3(x, y, 0) self.manapool.pos = euclid.Vector3(self.width, 0, 0) x = self.width - life.width/2 - spacing life.pos = life_img.pos = euclid.Vector3(x, y, 0) for i, status in enumerate(["graveyard", "library", "hand"]): symbol, value = self.symbols[status], self.values[status] #symbol.scale = 0.3 #symbol.pos = value.pos = euclid.Vector3(x, life.height+spacing+symbol.height/2+0.7*i*(symbol.height), 0) symbol.pos = value.pos = euclid.Vector3(x, life.height+spacing/2+symbol.height/2+i*(symbol.height), 0) library, lib = self._library, self.symbols["library"] library.scale = 0.5 library.pos = euclid.Vector3(self.width, life.height+spacing/2+1.5*lib.height, 0) #status = "library" #library, value = self.symbols["library"], self.values["library"] #library.scale = 0.3 #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, life.height+library.height/2+spacing,0) avatar.pos = euclid.Vector3(spacing + avatar.width/2, life.height+avatar.height/2+spacing,0) else: x, y = spacing, self.height - life.height / 2. self.player_name.pos = euclid.Vector3(x, y, 0) self.manapool.pos = euclid.Vector3(self.width, self.height, 0) x = self.width - life.width/2 - spacing life.pos = life_img.pos = euclid.Vector3(x, y, 0) for i, status in enumerate(["graveyard", "library", "hand"][::-1]): symbol, value = self.symbols[status], self.values[status] #symbol.scale = 0.3 #symbol.pos = value.pos = euclid.Vector3(x, self.height-life.height-symbol.height/2-0.7*i*(symbol.height), 0) symbol.pos = value.pos = euclid.Vector3(x, self.height-life.height-symbol.height/2-i*(symbol.height)-spacing/2, 0) library, lib = self._library, self.symbols["library"] library.scale = 0.5 library.pos = euclid.Vector3(self.width, 1.5*lib.height, 0) #status = "library" #library, value = self.symbols["library"], self.values["library"] #library.scale = 0.3 #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, self.height-life.height-library.height/2-spacing,0) avatar.pos = euclid.Vector3(spacing + avatar.width/2, self.height-life.height-avatar.height/2-spacing,0) def render_after_transform(self): ac = self.color glColor4f(ac[0], ac[1], ac[2], self.alpha) life_height = self.values['life'].height h1, h2 = self.height - life_height, life_height if self.is_opponent: h1, h2 = h2, h1 render_9_part("box4", self.width, h1, x=0, y=0) render_9_part("box4", self.width, h2, x=0, y=h1) self.avatar.render() self.player_name.render() for status in ["life", "library", "hand", "graveyard"]: #, "exile"]: symbol, value = self.symbols[status], self.values[status] symbol.render() value.render() self.manapool.render() self.zone_view.render() if self._reveal_library: self._library.render()
class ManaView(Widget): def __init__(self, pos=zero): super(ManaView,self).__init__(pos) self._pos.set_transition(dt=1.0, method="ease_out_circ") self.colors = ["white", "blue", "black", "red", "green", "colorless"] self.colormap = dict(zip(self.colors, "WUBRG")) self.nummana = len(self.colors) self.symbols = [ManaImage(color) for color in self.colors] self.pool = [Label("", size=20) for i in range(self.nummana)] self.values = dict([(c,v) for c, v in zip(self.colors, self.pool)]) self.spend = [Label("0", size=30) for i in range(self.nummana)] self.spend_values = dict([(c,v) for c, v in zip(self.colors, self.spend)]) for p, s in zip(self.pool, self.spend): p.visible = anim.constant(1) s.visible = anim.constant(1) self.cost = Label("0", size=40, halign="center", background=True) self.select_mana = self.select_x = False self.layout() def resize(self, width, height, flip=False): if flip: flip=-1 else: flip=1 self.select_pos = euclid.Vector3(flip*width/2, flip*height/2, 0) if self.select_mana or self.select_x: self.pos = self.select_pos+euclid.Vector3(-self.width/2, 0, 0) def clear_mana(self, sender): status = self.values for idx, c in enumerate(self.colors): if not status[c].value == '': status[c].set_text('') self.symbols[idx].animate(pain=True) self.symbols[idx].alpha = 0.4 self.layout() def update_mana(self, sender, amount): status = self.values for idx, c in enumerate(self.colors): amt = amount[idx] if amt > 0: self.symbols[idx].animate() if status[c].value == '': new_value = amt else: new_value = int(status[c].value)+amt if new_value > 0: status[c].set_text(new_value) self.symbols[idx].alpha = 0.8 else: status[c].set_text('') self.symbols[idx].alpha = 0.4 self.layout() def handle_click(self, x, y): for color, symbol in zip(self.colors, self.symbols): if not symbol.visible: continue sx, sy = symbol.pos.x, symbol.pos.y rad = symbol.width/2 if (x-sx)**2+(y-sy)**2 <= rad*rad: return symbol, self.values[color], self.spend_values[color] else: return None def select(self, x=False): self.select_mana = not self.select_mana self.select_x = x self.layout() def layout(self): x = 0 if not self.select_mana: self.pos = self.orig_pos for symbol, current in zip(self.symbols, self.pool): symbol.visible = current.visible = 1 symbol.scale = 0.25 #0.4 hw = symbol.width/2 spacer = 0.1*hw x += hw symbol.pos = euclid.Vector3(x, 0, 0) current.pos = euclid.Vector3(x-current.width/2, -current.height/2, 0) x += hw+spacer self.width = len(self.symbols)*(symbol.width*1.1) else: if not self.select_x: for symbol, current, pay in zip(self.symbols, self.pool, self.spend): symbol.visible = current.visible = pay.visible = 1 symbol.pos = euclid.Vector3(x,0,0) symbol.scale = 1.0 spacer = 10 #symbol.width*0.1 pay.pos = euclid.Vector3(x-pay.width/2, symbol.height/2, 0) current.pos = euclid.Vector3(x-current.width/2, -current.height-symbol.height/2, 0) if current.value == 0: symbol.alpha = 0.75 else: symbol.alpha = 1.0 x += symbol.width + spacer self.cost.pos = euclid.Vector3((x-symbol.width)/2, symbol.height*1.1, 0) else: y = self.symbols[0].height cost_y = y+self.cost.height symbol = self.symbols[-1] symbol.scale = 1.0 symbol.alpha = 1.0 symbol.pos = euclid.Vector3(-symbol.width/2, 0, 0) spacer = symbol.width*0.1 amount = self.spend[-1] amount.pos = euclid.Vector3(x+spacer, -amount.height/2, 0) self.spend[-1].visible = 1.0 self.pool[-1].visible = 0 for symb, current, pay in zip(self.symbols, self.pool, self.spend)[:-1]: symb.visible = 0 pay.visible = 0 current.visible = 0 self.cost.pos = euclid.Vector3((x-symbol.width)/2, symbol.height*0.7, 0) self.width = x - symbol.width - spacer self.pos = self.select_pos-euclid.Vector3(self.width/2, 0, 0) self.height = symbol.height def render_after_transform(self): for symbol, text in zip(self.symbols, self.pool): symbol.render() text.render() if self.select_mana: for pay in self.spend: pay.render() self.cost.render()
class GameStatus(Widget): def __init__(self, pos=zero): super(GameStatus, self).__init__(pos) self.screen_width = self.screen_height = 0 self._pos.set_transition(dt=0.5, method="ease_out_back") self.prompt = Label("", size=20, shadow=False, halign="center", valign="top", background=True) self.prompt.border = 3 self.prompt._pos.set_transition(dt=0.5, method="sine") self.show_log = False self.width = 400 self.gamelog = [ Label('', size=14, halign="left", width=self.width) for i in range(15) ] self.logger = [] def clear(self): self.prompt.set_text("") def resize(self, width, height, avail_width): self.screen_width = width self.screen_height = height self.pos = euclid.Vector3(width / 2, height / 2, 0) self.prompt.pos = euclid.Vector3(avail_width / 2, 125 - height / 2, 0) def log(self, prompt): self.prompt.set_text(prompt) self.layout() def log_event(self, sender, msg): self.logger.append((len(self.logger) + 1, sender, msg)) if self.show_log: self.construct_gamelog() def layout(self): pass def toggle_gamelog(self): self.show_log = not self.show_log self.construct_gamelog() def construct_gamelog(self): height = 0 for text, (i, sender, line) in zip(self.gamelog, self.logger[-len(self.gamelog):]): text.set_text("%d. %s" % (i, line)) height += text.height text.pos = euclid.Vector3(0, -height, 0) self.height = height def render_after_transform(self): self.prompt.render() if self.show_log: border = 10 w = border + self.width / 2 h = border + self.height / 2 glDisable(GL_TEXTURE_2D) glBegin(GL_LINE_LOOP) glVertex2f(-w, -h) glVertex2f(w, -h) glVertex2f(w, h) glVertex2f(-w, h) glEnd() glColor4f(0.1, 0.1, 0.1, 0.9) glBegin(GL_QUADS) glVertex2f(-w, -h) glVertex2f(w, -h) glVertex2f(w, h) glVertex2f(-w, h) glEnd() glEnable(GL_TEXTURE_2D) glTranslatef(-self.width / 2, self.height / 2, 0) for item in self.gamelog: item.render()
class ManaView(Widget): def __init__(self, pos=zero): super(ManaView, self).__init__(pos) self._pos.set_transition(dt=1.0, method="ease_out_circ") self.colors = ["white", "blue", "black", "red", "green", "colorless"] self.colormap = dict(zip(self.colors, "WUBRG")) self.nummana = len(self.colors) self.symbols = [ManaImage(color) for color in self.colors] self.pool = [Label("", size=20) for i in range(self.nummana)] self.values = dict([(c, v) for c, v in zip(self.colors, self.pool)]) self.spend = [Label("0", size=30) for i in range(self.nummana)] self.spend_values = dict([(c, v) for c, v in zip(self.colors, self.spend)]) for p, s in zip(self.pool, self.spend): p.visible = anim.constant(1) s.visible = anim.constant(1) self.cost = Label("0", size=40, halign="center", background=True) self.select_mana = self.select_x = False self.layout() def resize(self, width, height, flip=False): if flip: flip = -1 else: flip = 1 self.select_pos = euclid.Vector3(flip * width / 2, flip * height / 2, 0) if self.select_mana or self.select_x: self.pos = self.select_pos + euclid.Vector3(-self.width / 2, 0, 0) def clear_mana(self, sender): status = self.values for idx, c in enumerate(self.colors): if not status[c].value == '': status[c].set_text('') self.symbols[idx].animate(pain=True) self.symbols[idx].alpha = 0.4 self.layout() def update_mana(self, sender, amount): status = self.values for idx, c in enumerate(self.colors): amt = amount[idx] if amt > 0: self.symbols[idx].animate() if status[c].value == '': new_value = amt else: new_value = int(status[c].value) + amt if new_value > 0: status[c].set_text(new_value) self.symbols[idx].alpha = 0.8 else: status[c].set_text('') self.symbols[idx].alpha = 0.4 self.layout() def handle_click(self, x, y): for color, symbol in zip(self.colors, self.symbols): if not symbol.visible: continue sx, sy = symbol.pos.x, symbol.pos.y rad = symbol.width / 2 if (x - sx)**2 + (y - sy)**2 <= rad * rad: return symbol, self.values[color], self.spend_values[color] else: return None def select(self, x=False): self.select_mana = not self.select_mana self.select_x = x self.layout() def layout(self): x = 0 if not self.select_mana: self.pos = self.orig_pos for symbol, current in zip(self.symbols, self.pool): symbol.visible = current.visible = 1 symbol.scale = 0.25 #0.4 hw = symbol.width / 2 spacer = 0.1 * hw x += hw symbol.pos = euclid.Vector3(x, 0, 0) current.pos = euclid.Vector3(x - current.width / 2, -current.height / 2, 0) x += hw + spacer self.width = len(self.symbols) * (symbol.width * 1.1) else: if not self.select_x: for symbol, current, pay in zip(self.symbols, self.pool, self.spend): symbol.visible = current.visible = pay.visible = 1 symbol.pos = euclid.Vector3(x, 0, 0) symbol.scale = 1.0 spacer = 10 #symbol.width*0.1 pay.pos = euclid.Vector3(x - pay.width / 2, symbol.height / 2, 0) current.pos = euclid.Vector3( x - current.width / 2, -current.height - symbol.height / 2, 0) if current.value == 0: symbol.alpha = 0.75 else: symbol.alpha = 1.0 x += symbol.width + spacer self.cost.pos = euclid.Vector3((x - symbol.width) / 2, symbol.height * 1.1, 0) else: y = self.symbols[0].height cost_y = y + self.cost.height symbol = self.symbols[-1] symbol.scale = 1.0 symbol.alpha = 1.0 symbol.pos = euclid.Vector3(-symbol.width / 2, 0, 0) spacer = symbol.width * 0.1 amount = self.spend[-1] amount.pos = euclid.Vector3(x + spacer, -amount.height / 2, 0) self.spend[-1].visible = 1.0 self.pool[-1].visible = 0 for symb, current, pay in zip(self.symbols, self.pool, self.spend)[:-1]: symb.visible = 0 pay.visible = 0 current.visible = 0 self.cost.pos = euclid.Vector3((x - symbol.width) / 2, symbol.height * 0.7, 0) self.width = x - symbol.width - spacer self.pos = self.select_pos - euclid.Vector3(self.width / 2, 0, 0) self.height = symbol.height def render_after_transform(self): for symbol, text in zip(self.symbols, self.pool): symbol.render() text.render() if self.select_mana: for pay in self.spend: pay.render() self.cost.render()
class SelectionList(Widget): alpha = anim.Animatable() def __init__(self, pos=zero): super(SelectionList, self).__init__(pos) #self.options = [] #self.alpha = anim.animate(0, 0.9, dt=1.0, method="sine") self.border = 20 self.visible = anim.constant(0) #self.focus_idx = 0 self.large_size = 17 self.max_width = 700 #self.small_scale = 0.35 #self.intermediate_scale = 0.55 #self.layout = self.layout_normal self.prompt = Label("", size=self.large_size, halign="center", shadow=False) #def move_up(self): # if self.visible == 1 and self.focus_idx > 0: # self.focus_dir = -1 # self.options[self.focus_idx], self.options[self.focus_idx+self.focus_dir] = self.options[self.focus_idx+self.focus_dir], self.options[self.focus_idx] # self.focus_idx += self.focus_dir # self.layout() #def move_down(self): # if self.visible == 1 and self.focus_idx < len(self.options)-1: # self.focus_dir = 1 # self.options[self.focus_idx], self.options[self.focus_idx+self.focus_dir] = self.options[self.focus_idx+self.focus_dir], self.options[self.focus_idx] # self.focus_idx += self.focus_dir # self.layout() #def focus_previous(self): # if self.visible == 1 and self.focus_idx > 0: # self.focus_dir = -1 # self.focus_idx += self.focus_dir # self.layout() #def focus_next(self): # if self.visible == 1 and self.focus_idx < len(self.options)-1: # self.focus_dir = 1 # self.focus_idx += self.focus_dir # self.layout() #def hide(self): # for item, val in self.options: # item.pos = zero # self.visible = anim.animate(1., 0.0, dt=0.1) def construct(self, prompt, sellist): self.prompt.set_text(prompt) max_width = self.max_width document = mtg_decoder.decode_text(u'\u2028'.join( [str(val[0]) for val in sellist])) choice_list = pyglet.text.DocumentLabel(document, multiline=True, width=max_width, anchor_x="center", anchor_y="center") choice_list.set_style("color", (255, 255, 255, 255)) choice_list.set_style("font_name", "Arial") choice_list.set_style("font_size", 13.5) choice_list.set_style("halign", "center") self.choice_list = choice_list self.choices = [val[1] for val in sellist] #self.options = [(Label(str(val[0]), size=13.5, halign="center", shadow=False), val[1]) for val in sellist] #y = 0 #for item, val in self.options: # item._scale = anim.animate(1.0, 1.0, dt=dt, method=method) #self.focus_idx = len(self.options)/2 #self.layout() #self.width = max([item[0].width for item in self.options]+[self.prompt.width]) #self.height = sum([item[0].height for item in self.options]+[self.prompt.height]) #self.scroll = self.height/len(self.options) self.width = max(self.prompt.width, choice_list.content_width) self.height = choice_list.content_height + self.prompt.height self.prompt._pos.set( euclid.Vector3(0, (self.height - self.prompt.height) / 2, 0)) choice_list.x = (max_width - self.width) / 2 #def layout_normal(self): # x = y = 0 # self.prompt.scale = 0.7 # y -= self.prompt.height # self.prompt.pos = euclid.Vector3(0, y, 0) # for option, val in self.options: # #option.scale = 0.45 # y -= option.height # option.pos = euclid.Vector3(0, y, 0) #def layout_resize(self): # x = y = 0 # idx = self.focus_idx # self.prompt.scale = 0.7 # y -= self.prompt.height # self.prompt.pos = euclid.Vector3(0, y, 0) # count = 0 # for option, val in self.options[:idx]: # if count == idx - 1: option.scale = self.intermediate_scale # else: option.scale = self.small_scale # y -= option.height # option.pos = euclid.Vector3(0,y,0) # count += 1 # option, val = self.options[idx] # option.scale = 1.0 # y -= option.height # option.pos = euclid.Vector3(0,y,0) # count += 1 # for option, val in self.options[idx+1:]: # if count == idx + 1: option.scale = self.intermediate_scale # else: option.scale = self.small_scale # y -= option.height # option.pos = euclid.Vector3(0,y,0) # count += 1 def selection(self, indices, all): if not all: sel = [self.choices[i] for i in indices] if len(sel) == 1: sel = sel[0] return sel else: return [ self.choices[i] for i in range(len(self.choices) - 1, -1, -1) ] def handle_click(self, x, y): choice_list = self.choice_list xpos, ypos, cwidth, cheight = choice_list.x, choice_list.y, choice_list.content_width, choice_list.content_height y += ypos + cheight / 2 if 0 < y <= cheight: num_choices = len(self.choices) return num_choices - int(y // (cheight / num_choices)) - 1 else: return -1 def render_after_transform(self): w, h = self.border * 2 + self.width, self.border * 2 + self.height render_9_part("box4", w, h, x=-w / 2, y=-h / 2) self.prompt.render() self.choice_list.draw()
class PlayCard(Card): tapping = anim.Animatable() zooming = anim.Animatable() highlighting = anim.Animatable() def spacing(): def fget(self): if self.is_tapped: return self.height else: return self.width return locals() spacing = property(**spacing()) def __init__(self, gamecard, front, back): super(PlayCard, self).__init__(gamecard, front, back) self.is_creature = False self.draw = self.draw_permanent #self.info_box = Label("", size=12, background=True, shadow=False, valign="top") #self.info_box._pos.set_transition(dt=0.4, method="sine") #self.info_box.pos = euclid.Vector3(self.width/2+self.info_box.border, self.height/2-self.info_box.border, 0.005) #self.info_box.visible = False def type_modified(self, sender): is_creature = self.gamecard.types == Creature if is_creature and not self.is_creature: self.setup_creature_role() elif not is_creature and self.is_creature: self.remove_creature_role() def setup_creature_role(self): self.is_creature = True gamecard = self.gamecard self.power = 0 #gamecard.power self.toughness = 0 #gamecard.toughness self.damage = 0 #gamecard.currentDamage() #dispatcher.connect(self.change_value, signal=PowerToughnessModifiedEvent(), sender=gamecard) # XXX This will lead to a lot of events each time priority is passed # but I'm not sure how to do it otherwise for cards like "Coat of Arms", which use a lambda function # or for damage self.text = Label("", size=34, background=True, shadow=False, halign="center", valign="center") #self.text._scale = anim.animate(0, 2.0, dt=0.25, method="sine") self.text.scale = 2.0 #self.text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") self.text.orig_pos = euclid.Vector3(0, -self.height * 0.25, 0.001) self.text.zoom_pos = euclid.Vector3(self.width * 1.375, -self.height * 0.454, 0.01) self.text.pos = self.text.orig_pos #self.damage_text = Label("", size=34, background=True, shadow=False, halign="center", valign="center", color=(1., 0., 0., 1.)) #self.damage_text._scale = anim.animate(0.0, 0.0, dt=0.25, method="sine") #self.damage_text.scale = 0.4 #self.damage_text.visible = 0 #self.damage_text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") #self.damage_text.zoom_pos = euclid.Vector3(self.width*(1-.375),-self.height*0.454, 0.01) #self.damage_text.pos = self.damage_text.zoom_pos self.change_value() self.draw = self.draw_creature dispatcher.connect(self.change_value, signal=TimestepEvent()) def remove_creature_role(self): self.is_creature = False self.draw = self.draw_permanent dispatcher.disconnect(self.change_value, signal=TimestepEvent()) def entering_play(self): self.is_tapped = False self.tapping = anim.animate(0, 0, dt=0.3) self.highlighting = anim.animate(0, 0, dt=0.2) self.zooming = anim.animate(0, 0, dt=0.2) self.pos_transition = "ease_out_circ" #"ease_out_back" self._pos.set_transition(dt=0.4, method=self.pos_transition) #self._pos.y = anim.animate(guicard._pos.y, guicard._pos.y, dt=0.4, method="ease_out") self._orientation.set_transition(dt=0.3, method="sine") self.can_layout = True if self.gamecard.types == Creature: self.setup_creature_role() # Check for counters dispatcher.connect(self.add_counter, signal=CounterAddedEvent(), sender=self.gamecard) dispatcher.connect(self.remove_counter, signal=CounterRemovedEvent(), sender=self.gamecard) dispatcher.connect(self.type_modified, signal=TypesModifiedEvent(), sender=self.gamecard) self.counters = [ Counter(counter.ctype) for counter in self.gamecard.counters ] self.layout_counters() def leaving_play(self): if self.is_creature: self.remove_creature_role() dispatcher.disconnect(self.add_counter, signal=CounterAddedEvent(), sender=self.gamecard) dispatcher.disconnect(self.remove_counter, signal=CounterRemovedEvent(), sender=self.gamecard) dispatcher.disconnect(self.type_modified, signal=TypesModifiedEvent(), sender=self.gamecard) def layout_counters(self): numc = len(self.counters) if numc > 0: spacing = self.counters[0].radius * 2.2 y = self.height / 4 max_per_row = int(self.width / spacing) num_rows = int(math.ceil(float(numc) / max_per_row)) x = -spacing * (max_per_row - 1) * 0.5 row = j = 0 for counter in self.counters: counter.pos = euclid.Vector3(x + j * spacing, y - row * spacing, counter.height / 2) j += 1 if j == max_per_row: j = 0 row += 1 if row == num_rows - 1: num_per_row = numc % max_per_row if num_per_row == 0: num_per_row = max_per_row x = -spacing * (num_per_row - 1) * 0.5 def add_counter(self, counter): self.counters.append(Counter(counter.ctype)) self.layout_counters() def remove_counter(self, counter): for c in self.counters: if c.ctype == counter.ctype: break else: raise Exception self.counters.remove(c) self.layout_counters() def change_value(self): p, t = self.gamecard.power, self.gamecard.toughness d = self.gamecard.currentDamage() if not (self.power == p and self.toughness == t and self.damage == d): self.power, self.toughness, self.damage = p, t, d self.text.set_text("%d/%d" % (p, t - d)) #if d > 0: self.damage_text.set_text("-%d"%d) #else: self.damage_text.set_text("") def tap(self): if self.tapping == 0.0: self.is_tapped = True self.tapping = 1.0 #anim.animate(0, 1, dt=0.3) self.untapped_orientation = self.orientation self.orientation *= euclid.Quaternion.new_rotate_axis( math.pi / 2, euclid.Vector3(0, 0, -1)) def untap(self): self.is_tapped = False self.orientation = self.untapped_orientation self.tapping = 0.0 def flash(self): self.highlighting = anim.animate(1, 0, dt=0.75, method="step") self.highlight_alpha = anim.animate(0.0, 0.8, dt=0.75, method="oscillate") def select(self): self.highlighting = 1.0 self.highlight_alpha = anim.animate(0., 1., dt=0.2, method="linear") def deselect(self): self.highlighting = 0.0 def highlight(self): if self.highlighting == 0: self.highlighting = anim.animate(0, 1, dt=0.75) self.old_pos = self.pos self.pos += euclid.Vector3(0, 3, 0) self.highlight_alpha = anim.animate(0.0, 0.8, dt=1, method="oscillate", extend="repeat") #self.old_size = self.size #self.size = anim.animate(self.size,1.05*self.size,dt=2.0,method="oscillate", extend="repeat") def unhighlight(self): self.highlighting = 0.0 self.pos = self.old_pos #self.size = anim.animate(self.old_size, self.old_size, dt=0.2, method="sine") def shake(self): self._pos.set_transition(dt=0.25, method=lambda t: anim.oscillate_n(t, 3)) self.pos += euclid.Vector3(0.05, 0, 0) def unshake(self): # XXX Need to reset position transition - this is a bit hacky - I need to be able to layer animations self._pos.set_transition(dt=0.4, method=self.pos_transition) def zoom_to_camera(self, camera, z, size=0.02, show_info=True, offset=euclid.Vector3(0, 0, 0)): if self.zooming == 0.0: self._texture = self._img self._old_list, self.cardlist = self.cardlist, self.renderlist self.zooming = 1.0 self.old_pos = self.pos self._pos.set_transition(dt=0.2, method="ease_out") #self.pos_transition) #self._pos.y = anim.animate(self._pos.y, self._pos.y, dt=0.4, method="sine") #self._orientation.set_transition(dt=0.5, method="sine") if show_info: offset = offset + euclid.Vector3(-self.width * size / 2, 0, 0) self.pos = camera.pos - camera.orientation * euclid.Vector3( 0, 0, camera.vis_distance) - euclid.Vector3(0, 0, z) + offset self.orig_orientation = self.orientation new_orient = camera.orientation if self.is_tapped: new_orient *= euclid.Quaternion.new_rotate_axis( math.pi / 10, euclid.Vector3(0, 0, -1)) self.orientation = new_orient self.old_size = self.size self.size = size * 0.7 if self.is_creature: self.text.visible = False self.text.set_text("%d/%d" % (self.power, self.toughness)) self.text.pos = self.text.zoom_pos self.text.scale = 0.4 #self.damage_text.visible = True #if show_info: # self.info_box.visible = True # self.info_box.set_text('\n'.join(self.gamecard.info.split("\n")[:17]), width=self.width) # self.info_box._height = self.height-self.info_box.border #else: self.info_box.visible = False def restore_pos(self): self.zooming = 0.0 #anim.animate(self.zooming, 0.0, dt=0.2) self._texture = self.front self.cardlist = self._old_list self._pos.set_transition(dt=0.4, method=self.pos_transition) #self._pos.y = anim.animate(self._pos.y, self._pos.y, dt=0.4, method="sine") # XXX old self._pos.set_transition(dt=0.2, method="ease_out_circ") #self._orientation.set_transition(dt=0.3, method="sine") self.pos = self.old_pos self.orientation = self.orig_orientation self.size = self.old_size if self.is_creature: self.text.visible = True self.text.set_text("%d/%d" % (self.power, self.toughness - self.damage)) self.text.pos = self.text.orig_pos self.text.scale = 2.0 #self.damage_text.scale = 0.4 #self.damage_text.pos = self.damage_text.zoom_pos #self.damage_text.visible = 0.0 #self.info_box.visible = False def render_extra(self, width, height): if hasattr(self, "damage") and self.damage != 0: ImageCache.get_texture("overlays/damage.png").blit( 0.59 * width, -0.01 * height) pyglet.text.Label( "%d" % self.damage, #font_name="MPlantin", font_size=0.073 * width, x=0.69 * width, y=0.073 * height, anchor_x="center", anchor_y="center").draw() def draw_permanent(self): if self.visible > 0: size = self.size glPushMatrix() if self.highlighting != 0: glPushMatrix() glTranslatef(self.pos.x, self.pos.y - 0.0005, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) glScalef(size * 1.1, size * 1.1, size * 1.1) glColor4f(1.0, 1.0, 1.0, self.highlight_alpha.get()) glCallList(self.cardlist) glPopMatrix() glTranslatef(self.pos.x, self.pos.y, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) #glScalef(size, size, size) glScalef(size, size, 1) glEnable(self._texture.target) glBindTexture(self._texture.target, self._texture.id) glColor4f(self.alpha, self.alpha, self.alpha, self.alpha) #foil.install() glCallList(self.cardlist) #foil.uninstall() #self.info_box.render() glDisable(self._texture.target) for c in self.counters: c.draw() glPopMatrix() def draw_creature(self): if self.visible > 0: size = self.size glPushMatrix() if self.highlighting: glPushMatrix() glTranslatef(self.pos.x, self.pos.y - 0.0005, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) glScalef(size * 1.1, size * 1.1, size * 1.1) #glScalef(size*1.1, size*1.1, 1) glColor4f(1.0, 1.0, 1.0, self.highlight_alpha.get()) glCallList(self.cardlist) glPopMatrix() glTranslatef(self.pos.x, self.pos.y, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) #glScalef(size, size, size) glScalef(size, size, 1) glEnable(self._texture.target) glBindTexture(self._texture.target, self._texture.id) glColor4f(self.alpha, self.alpha, self.alpha, self.alpha) glCallList(self.cardlist) #self.info_box.render() #self.text.render() #self.damage_text.render() glDisable(self._texture.target) for c in self.counters: c.draw() glPopMatrix()
class PlayCard(Card): tapping = anim.Animatable() zooming = anim.Animatable() highlighting = anim.Animatable() def spacing(): def fget(self): if self.is_tapped: return self.height else: return self.width return locals() spacing = property(**spacing()) def __init__(self, gamecard, front, back): super(PlayCard, self).__init__(gamecard, front, back) self.is_creature = False self.draw = self.draw_permanent #self.info_box = Label("", size=12, background=True, shadow=False, valign="top") #self.info_box._pos.set_transition(dt=0.4, method="sine") #self.info_box.pos = euclid.Vector3(self.width/2+self.info_box.border, self.height/2-self.info_box.border, 0.005) #self.info_box.visible = False def type_modified(self, sender): is_creature = self.gamecard.types == Creature if is_creature and not self.is_creature: self.setup_creature_role() elif not is_creature and self.is_creature: self.remove_creature_role() def setup_creature_role(self): self.is_creature = True gamecard = self.gamecard self.power = 0 #gamecard.power self.toughness = 0 #gamecard.toughness self.damage = 0 #gamecard.currentDamage() #dispatcher.connect(self.change_value, signal=PowerToughnessModifiedEvent(), sender=gamecard) # XXX This will lead to a lot of events each time priority is passed # but I'm not sure how to do it otherwise for cards like "Coat of Arms", which use a lambda function # or for damage self.text = Label("", size=34, background=True, shadow=False, halign="center", valign="center") #self.text._scale = anim.animate(0, 2.0, dt=0.25, method="sine") self.text.scale = 2.0 #self.text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") self.text.orig_pos = euclid.Vector3(0,-self.height*0.25,0.001) self.text.zoom_pos = euclid.Vector3(self.width*1.375,-self.height*0.454, 0.01) self.text.pos = self.text.orig_pos #self.damage_text = Label("", size=34, background=True, shadow=False, halign="center", valign="center", color=(1., 0., 0., 1.)) #self.damage_text._scale = anim.animate(0.0, 0.0, dt=0.25, method="sine") #self.damage_text.scale = 0.4 #self.damage_text.visible = 0 #self.damage_text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") #self.damage_text.zoom_pos = euclid.Vector3(self.width*(1-.375),-self.height*0.454, 0.01) #self.damage_text.pos = self.damage_text.zoom_pos self.change_value() self.draw = self.draw_creature dispatcher.connect(self.change_value, signal=TimestepEvent()) def remove_creature_role(self): self.is_creature = False self.draw = self.draw_permanent dispatcher.disconnect(self.change_value, signal=TimestepEvent()) def entering_play(self): self.is_tapped = False self.tapping = anim.animate(0, 0, dt=0.3) self.highlighting = anim.animate(0, 0, dt=0.2) self.zooming = anim.animate(0, 0, dt=0.2) self.pos_transition = "ease_out_circ" #"ease_out_back" self._pos.set_transition(dt=0.4, method=self.pos_transition) #self._pos.y = anim.animate(guicard._pos.y, guicard._pos.y, dt=0.4, method="ease_out") self._orientation.set_transition(dt=0.3, method="sine") self.can_layout = True if self.gamecard.types == Creature: self.setup_creature_role() # Check for counters dispatcher.connect(self.add_counter, signal=CounterAddedEvent(), sender=self.gamecard) dispatcher.connect(self.remove_counter, signal=CounterRemovedEvent(), sender=self.gamecard) dispatcher.connect(self.type_modified, signal=TypesModifiedEvent(), sender=self.gamecard) self.counters = [Counter(counter.ctype) for counter in self.gamecard.counters] self.layout_counters() def leaving_play(self): if self.is_creature: self.remove_creature_role() dispatcher.disconnect(self.add_counter, signal=CounterAddedEvent(), sender=self.gamecard) dispatcher.disconnect(self.remove_counter, signal=CounterRemovedEvent(), sender=self.gamecard) dispatcher.disconnect(self.type_modified, signal=TypesModifiedEvent(), sender=self.gamecard) def layout_counters(self): numc = len(self.counters) if numc > 0: spacing = self.counters[0].radius*2.2 y = self.height/4 max_per_row = int(self.width/spacing) num_rows = int(math.ceil(float(numc)/max_per_row)) x = -spacing*(max_per_row-1)*0.5 row = j = 0 for counter in self.counters: counter.pos = euclid.Vector3(x+j*spacing, y-row*spacing, counter.height/2) j += 1 if j == max_per_row: j = 0 row += 1 if row == num_rows-1: num_per_row = numc%max_per_row if num_per_row ==0: num_per_row = max_per_row x = -spacing*(num_per_row-1)*0.5 def add_counter(self, counter): self.counters.append(Counter(counter.ctype)) self.layout_counters() def remove_counter(self, counter): for c in self.counters: if c.ctype == counter.ctype: break else: raise Exception self.counters.remove(c) self.layout_counters() def change_value(self): p, t = self.gamecard.power, self.gamecard.toughness d = self.gamecard.currentDamage() if not (self.power == p and self.toughness == t and self.damage == d): self.power, self.toughness, self.damage = p, t, d self.text.set_text("%d/%d"%(p, t-d)) #if d > 0: self.damage_text.set_text("-%d"%d) #else: self.damage_text.set_text("") def tap(self): if self.tapping == 0.0: self.is_tapped = True self.tapping = 1.0 #anim.animate(0, 1, dt=0.3) self.untapped_orientation = self.orientation self.orientation *= euclid.Quaternion.new_rotate_axis(math.pi/2, euclid.Vector3(0,0,-1)) def untap(self): self.is_tapped = False self.orientation = self.untapped_orientation self.tapping = 0.0 def flash(self): self.highlighting = anim.animate(1,0,dt=0.75, method="step") self.highlight_alpha = anim.animate(0.0, 0.8, dt=0.75, method="oscillate") def select(self): self.highlighting = 1.0 self.highlight_alpha = anim.animate(0., 1., dt=0.2, method="linear") def deselect(self): self.highlighting = 0.0 def highlight(self): if self.highlighting == 0: self.highlighting = anim.animate(0,1,dt=0.75) self.old_pos = self.pos self.pos += euclid.Vector3(0,3,0) self.highlight_alpha = anim.animate(0.0, 0.8, dt=1, method="oscillate", extend="repeat") #self.old_size = self.size #self.size = anim.animate(self.size,1.05*self.size,dt=2.0,method="oscillate", extend="repeat") def unhighlight(self): self.highlighting = 0.0 self.pos = self.old_pos #self.size = anim.animate(self.old_size, self.old_size, dt=0.2, method="sine") def shake(self): self._pos.set_transition(dt=0.25, method=lambda t: anim.oscillate_n(t, 3)) self.pos += euclid.Vector3(0.05, 0, 0) def unshake(self): # XXX Need to reset position transition - this is a bit hacky - I need to be able to layer animations self._pos.set_transition(dt=0.4, method=self.pos_transition) def zoom_to_camera(self, camera, z, size=0.02, show_info = True, offset = euclid.Vector3(0,0,0)): if self.zooming == 0.0: self._texture = self._img self._old_list, self.cardlist = self.cardlist, self.renderlist self.zooming = 1.0 self.old_pos = self.pos self._pos.set_transition(dt=0.2, method="ease_out") #self.pos_transition) #self._pos.y = anim.animate(self._pos.y, self._pos.y, dt=0.4, method="sine") #self._orientation.set_transition(dt=0.5, method="sine") if show_info: offset = offset + euclid.Vector3(-self.width*size/2, 0, 0) self.pos = camera.pos - camera.orientation*euclid.Vector3(0,0,camera.vis_distance) - euclid.Vector3(0,0,z) + offset self.orig_orientation = self.orientation new_orient = camera.orientation if self.is_tapped: new_orient *= euclid.Quaternion.new_rotate_axis(math.pi/10, euclid.Vector3(0,0,-1)) self.orientation = new_orient self.old_size = self.size self.size = size*0.7 if self.is_creature: self.text.visible = False self.text.set_text("%d/%d"%(self.power, self.toughness)) self.text.pos = self.text.zoom_pos self.text.scale = 0.4 #self.damage_text.visible = True #if show_info: # self.info_box.visible = True # self.info_box.set_text('\n'.join(self.gamecard.info.split("\n")[:17]), width=self.width) # self.info_box._height = self.height-self.info_box.border #else: self.info_box.visible = False def restore_pos(self): self.zooming = 0.0 #anim.animate(self.zooming, 0.0, dt=0.2) self._texture = self.front self.cardlist = self._old_list self._pos.set_transition(dt=0.4, method=self.pos_transition) #self._pos.y = anim.animate(self._pos.y, self._pos.y, dt=0.4, method="sine") # XXX old self._pos.set_transition(dt=0.2, method="ease_out_circ") #self._orientation.set_transition(dt=0.3, method="sine") self.pos = self.old_pos self.orientation = self.orig_orientation self.size = self.old_size if self.is_creature: self.text.visible = True self.text.set_text("%d/%d"%(self.power, self.toughness - self.damage)) self.text.pos = self.text.orig_pos self.text.scale = 2.0 #self.damage_text.scale = 0.4 #self.damage_text.pos = self.damage_text.zoom_pos #self.damage_text.visible = 0.0 #self.info_box.visible = False def render_extra(self, width, height): if hasattr(self, "damage") and self.damage != 0: ImageCache.get_texture("overlays/damage.png").blit(0.59*width,-0.01*height) pyglet.text.Label("%d"%self.damage, #font_name="MPlantin", font_size=0.073*width, x = 0.69*width, y = 0.073*height, anchor_x="center", anchor_y="center").draw() def draw_permanent(self): if self.visible > 0: size = self.size glPushMatrix() if self.highlighting != 0: glPushMatrix() glTranslatef(self.pos.x, self.pos.y-0.0005, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) glScalef(size*1.1, size*1.1, size*1.1) glColor4f(1.0, 1.0, 1.0, self.highlight_alpha.get()) glCallList(self.cardlist) glPopMatrix() glTranslatef(self.pos.x, self.pos.y, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) #glScalef(size, size, size) glScalef(size, size, 1) glEnable(self._texture.target) glBindTexture(self._texture.target, self._texture.id) glColor4f(self.alpha, self.alpha, self.alpha, self.alpha) #foil.install() glCallList(self.cardlist) #foil.uninstall() #self.info_box.render() glDisable(self._texture.target) for c in self.counters: c.draw() glPopMatrix() def draw_creature(self): if self.visible > 0: size = self.size glPushMatrix() if self.highlighting: glPushMatrix() glTranslatef(self.pos.x, self.pos.y-0.0005, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) glScalef(size*1.1, size*1.1, size*1.1) #glScalef(size*1.1, size*1.1, 1) glColor4f(1.0, 1.0, 1.0, self.highlight_alpha.get()) glCallList(self.cardlist) glPopMatrix() glTranslatef(self.pos.x, self.pos.y, self.pos.z) glMultMatrixf(sixteenfv(*tuple(self.orientation.get_matrix()))) #glScalef(size, size, size) glScalef(size, size, 1) glEnable(self._texture.target) glBindTexture(self._texture.target, self._texture.id) glColor4f(self.alpha, self.alpha, self.alpha, self.alpha) glCallList(self.cardlist) #self.info_box.render() #self.text.render() #self.damage_text.render() glDisable(self._texture.target) for c in self.counters: c.draw() glPopMatrix()
def __init__(self): from widget import Label WidgetState.__init__(self) Label("Connecting to server", (None, None))