def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: selection = [card.gamecard for card in self.zone_view.selected] if len(selection) == 0 and len( self.zone_view.cards) == self.number: if self.actionable: self.window.process_action( Action.MultipleCardsSelected( [card.gamecard for card in self.zone_view.cards])) self.deactivate() else: if (self.number == -1) or (len(selection) == self.number) or ( len(self.zone_view.cards) == 0 and len(selection) < self.number ) or (len(selection) < self.number and not self.required): if self.actionable: self.window.process_action( Action.MultipleCardsSelected(selection)) self.deactivate() return True elif symbol == key.ESCAPE: if not self.required: if self.actionable: self.window.process_action(Action.CancelAction()) self.deactivate() return True elif symbol == key.LEFT: self.zone_view.focus_previous() return True elif symbol == key.RIGHT: self.zone_view.focus_next() return True elif symbol == key.UP: self.zone_view.toggle_sort() return True
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: amount = int(self.mana.spend_values["colorless"].value) self.window.process_action(Action.XSelected(amount)) self.deactivate() return True elif symbol == key.ESCAPE: self.window.process_action(Action.CancelAction()) self.colorless.set_text(self.orig_colorless) self.deactivate() return True
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: if self.do_action: self.window.process_action(Action.OKAction()) self.deactivate() return True elif symbol == key.ESCAPE: if self.do_action: self.window.process_action(Action.CancelAction()) self.deactivate() return True elif symbol in [key.F2, key.F3]: return True else: return False
def on_mouse_press(self, x, y, button, modifiers): for status in [self.mainstatus, self.otherstatus]: value = status.handle_click(x, y) if value: if modifiers & key.MOD_CTRL: self.mainstatus.toggle() self.otherstatus.toggle() elif value == True or value == "life": self.window.process_action( Action.PlayerSelected(status.player)) elif value in self.observable_zones: zone = getattr(status.player, value) self.zone_view = status.zone_view if not self.zone_view.visible: if len(zone): self.clicked = True self.tmp_dx = 0 #self.zone_view.pos = euclid.Vector3(x, y, 0) #self.zone_view.pos = status.pos + status.symbols[value].pos #pos = status.pos + status.symbols[value].pos #self.zone_view.pos = euclid.Vector3(status.pos.x+status.width+10+self.zone_view.padding, pos.y, pos.z) pos = status.symbols[value].pos self.zone_view.pos = euclid.Vector3( status.width + 10 + self.zone_view.padding, pos.y, pos.z) self.zone_view.build(zone, status.is_opponent) self.zone_view.show() else: self.zone_view.hide() elif value == "library": status.toggle_library() return True
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: mana = [self.mana.pay[c] for c in self.mana.colors] manastr = ''.join([ color * int(mana[i]) for i, color in enumerate("WUBRG") if mana[i] != '' ]) if mana[-1] > 0: manastr += str(mana[-1]) if manastr == '': manastr = '0' if Mana.compare_mana(self.required_str, manastr): self.window.process_action(Action.ManaSelected(manastr)) self.deactivate() return True elif symbol == key.ESCAPE: self.window.process_action(Action.CancelAction()) self.deactivate() return True
def on_mouse_release(self, x, y, button, modifiers): if self.click: x -= self.dialog.pos.x y -= self.dialog.pos.y item, result = self.dialog.handle_click(x, y) if item == self.click: if self.do_action: if result == True: self.window.process_action(Action.OKAction()) else: self.window.process_action(Action.CancelAction()) self.deactivate() self.click.toggled = False self.click = None return True else: return False
def on_mouse_release(self, x, y, button, modifiers): if self.selected is not None: if self.zooming: self.selected.restore_pos() self.zooming = False elif button == mouse.LEFT: #self.selected.flash() self.window.process_action( Action.CardSelected(self.selected.gamecard)) if modifiers & key.MOD_CTRL: self.window.keep_priority() self.selected = None
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: # Check damage assignment if self.amount == 0: assn = {} for target in self.targets: amt = int(target.damage_text.value) assn[target.gamecard] = amt self.window.user_action = Action.DistributionAssignment(assn) self.deactivate() return True
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: if self.numselections == -1 or len( self.indices) == self.numselections: self.return_selections() return True elif symbol == key.ESCAPE: if not self.required: self.window.process_action(Action.CancelAction()) self.deactivate() return True elif symbol == key.UP: self.listview.focus_previous() elif symbol == key.DOWN: self.listview.focus_next()
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: # Check damage assignment #dmg = {} dmg = [] total = self.attacker.gamecard.combatDamage() valid = True for blocker in self.blockers: damage = int(blocker.damage_text.value) #dmg[blocker.gamecard] = damage dmg.append((blocker.gamecard, damage)) total -= damage if (damage < blocker.gamecard.lethalDamage() and total > 0): valid = False if ((self.deathtouch or valid) and ((self.trample and valid and total > 0) or total == 0)): self.window.process_action(Action.DistributionAssignment(dmg)) self.deactivate() return True
def on_mouse_release(self, x, y, button, modifiers): if self.player_hand.visible == 0: return False if self.mouse_down: self.mouse_down = False if self.card_clicked: if self.zooming: self.zooming = False self.player_hand.restore_card(self.card_clicked) elif self.dragged: # Move the card self.dragged = False self.player_hand.layout() else: self.window.process_action( Action.CardSelected(self.card_clicked.gamecard)) if modifiers & key.MOD_CTRL: self.window.keep_priority() self.card_clicked = None return True else: return False
def playerInput(context, prompt=''): print_header() printer(prompt) process = context['process'] action = False if context.get("get_ability", False): while action == False: txt = text_input( "What would you like to do\n(Enter to pass priority): ") if not txt: action = process(Action.PassPriority()) else: try: cardnum = int(txt) card = card_map.get(cardnum, None) if card: action = process(Action.CardSelected(card)) printer("You selected %s in %s" % (card, card.zone)) except: pass if action == False: printer("Invalid action") elif context.get("get_target", False): while action == False: txt = text_input("Select target (P# for player): ").upper() if not txt: action = process(Action.PassPriority()) elif txt == "/": action = process(Action.CancelAction()) else: if txt[0] == "P": try: pnum = int(txt[1:]) if pnum < len(Keeper.players): action = process( Action.PlayerSelected(Keeper.players[pnum])) except: pass else: try: cardnum = int(txt) card = card_map.get(cardnum, None) if card: action = process(Action.CardSelected(card)) printer("You selected %s in %s" % (card, card.zone)) except: pass if action == False: printer("Invalid target") elif context.get("get_cards", False): sellist = context['list'] numselections = context['numselections'] required = context['required'] from_zone = context['from_zone'] from_player = context['from_player'] check_card = context['check_card'] printer("Choose from %s" % ', '.join(map(str, sellist))) elif context.get("reveal_card", False): sellist = context['cards'] from_zone = context['from_zone'] from_player = context['from_player'] printer.indent() printer("%s reveals: %s" % (from_player, ', '.join(map(str, sellist)))) printer.unindent() action = True elif context.get("get_selection", False): sellist = context['list'] numselections = context['numselections'] required = context['required'] msg = context['msg'] printer.indent() while action is False: map(printer, ["%d) %s" % (o[1], o[0]) for o in sellist]) txt = text_input(msg + ":") if txt: try: num = int(txt) if num < len(sellist): action = process(Action.SingleSelected(num)) except: pass printer.unindent() elif context.get("get_choice", False): msg = context['msg'] notify = context['notify'] if notify: msg += " (Hit enter to continue)" else: msg += "([Y]/N):" text = text_input(msg).upper() if notify: action = Action.OKAction() elif not text or text == "Y": action = Action.OKAction() else: action = Action.CancelAction() elif context.get("get_mana_choice", False): required = context['required'] manapool = context['manapool'] from_player = context['from_player'] while action == False: manastr = text_input("(Required: %s) Mana to use: " % required).upper() if not manastr: action = process(Action.CancelAction()) else: # Make sure it's a valid string try: Mana.convert_mana_string(manastr) if (Mana.compare_mana(required, manastr) and Mana.subset_in_pool(manapool, manastr)): action = process(Action.ManaSelected(manastr)) except: pass elif context.get("get_X", False): from_player = context['from_player'] prompt = "Enter X: " while action == False: text = text_input(prompt) if not text: action = Action.CancelAction() else: try: amount = int(text) if amount >= 0: action = Action.XSelected(amount) else: prompt = "Invalid input. Enter X: " except: prompt = "Invalid input. Enter X: " action = process(action) elif context.get("get_distribution", False): amount = context['amount'] targets = context['targets'] elif context.get("get_damage_assign", False): blocking_list = context['blocking_list'] trample = context['trample'] dump_to_replay.write(action) return action