Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 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()
Exemple #5
0
 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
Exemple #6
0
 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
Exemple #7
0
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