class ActionMenu(Screen):
    def __init__(self, **kwargs):
        super(ActionMenu, self).__init__(**kwargs)

        self.root = Accordion(orientation='vertical')
        self.targItem = AccordionItem(title='Target')
        self.root.add_widget(self.targItem)
        self.conItem = AccordionItem(title='Confirm')
        self.root.add_widget(self.conItem)
        B = Button(text='Confirm')
        B2 = Button(text='Cancel')
        B.bind(on_press=self.confirmTarget)
        B2.bind(on_press=self.cancel)
        self.conItem.add_widget(B)
        self.conItem.add_widget(B2)
        self.add_widget(self.root)

    def populate(self):
        self.ComButtons = []
        for c in Combatants.retList():
            btn = ToggleButton(text=c.name, group='targets')
            self.targItem.add_widget(btn)
            self.ComButtons.append(btn)

    def confirmTarget(self, obj):
        hasTarget = False
        i = 0
        for b in self.ComButtons:
            if b.state == 'down':
                hasTarget = True
                Screens[2].Target = Combatants.get(i)
            i += 1
        if hasTarget == True:
            hasTarget = False
            self.targItem.clear_widgets(children=self.ComButtons)
            self.ComButtons.clear()
            Combatants.get(0).hasActed = True
            Screens[2].AttackButton.disabled = True
            self.manager.current = 'Battle Screen'
            Screens[2].Attack()

    def cancel(self, obj):
        self.targItem.clear_widgets(children=self.ComButtons)
        self.ComButtons.clear()
        self.manager.current = 'Battle Screen'
class AbilityMenu(Screen):
    def __init__(self, **kwargs):
        super(AbilityMenu, self).__init__(**kwargs)

        self.root = Accordion(orientation='vertical')
        self.invItem = AccordionItem(title='Item')
        self.root.add_widget(self.invItem)
        self.targItem = AccordionItem(title='Target')
        self.root.add_widget(self.targItem)
        self.conItem = AccordionItem(title='Confirm')
        self.root.add_widget(self.conItem)
        B = Button(text='Confirm')
        B2 = Button(text='Cancel')
        B.bind(on_press=self.confirmTarget)
        B2.bind(on_press=self.cancel)
        self.conItem.add_widget(B)
        self.conItem.add_widget(B2)
        self.add_widget(self.root)

    def populateItems(self):
        self.ItemButtons = []
        for item in Combatants.get(0).inventory:
            if item.quantity > 0:
                btn = ToggleButton(text=item.name, group='items')
                self.invItem.add_widget(btn)
                self.ItemButtons.append(btn)

    def populateTargs(self):
        self.ComButtons = []
        for c in Combatants.retList():
            btn = ToggleButton(text=c.name, group='targets')
            self.targItem.add_widget(btn)
            self.ComButtons.append(btn)

    def confirmTarget(self, obj):
        hasTarget = False
        hasItem = False
        itemNum = None
        i = 0
        for a in self.ItemButtons:
            if a.state == 'down':
                hasItem = True
                itemNum = i
            i += 1
        i = 0
        for b in self.ComButtons:
            if b.state == 'down':
                hasTarget = True
                Screens[2].Target = Combatants.get(i)
            i += 1
        if hasTarget == True and hasItem == True:
            hasTarget = False
            hasItem = False
            self.targItem.clear_widgets(children=self.ComButtons)
            self.ComButtons.clear()
            self.invItem.clear_widgets(children=self.ItemButtons)
            self.ItemButtons.clear()
            Combatants.get(0).abilitiesUsed = Combatants.get(0).abilitiesUsed + 1
            Screens[2].AbilityButton.disabled = True
            self.manager.current = 'Battle Screen'
            Screens[2].UseItem(itemNum)

    def cancel(self, obj):
        self.targItem.clear_widgets(children=self.ComButtons)
        self.ComButtons.clear()
        self.invItem.clear_widgets(children=self.ItemButtons)
        self.ItemButtons.clear()
        self.manager.current = 'Battle Screen'