#include "GameState.h"

void GameState :: gamestateAbilityAfterDraw(uint8_t numButtonsToUse, uint8_t numListsToUse)
{
  vector <string> equippedAbilityNameList, learnedAbilityNameList;
  vector <int16_t> equippedAbilityQuantList, learnedAbilityQuantList;
  rulez.getPlayer().getEquippedAbilityList(equippedAbilityNameList, equippedAbilityQuantList);
  rulez.getPlayer().getAbilityList(learnedAbilityNameList, learnedAbilityQuantList);

  inputBufferIterator = inputBuffer.begin ();
  while (inputBufferIterator < inputBuffer.end ())
    {
      if (inputBufferIterator -> getInput () == INPUT_MOUSEUP)
        {
          clearButtons (numButtonsToUse);
          //Return to Intro Battle, New Level or Map.
          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[0], false))
            {
              if (rulez.getIntroBattle ())
                setNewGameState (GAMESTATE_BATTLE_SWOOSH);
              else if (rulez.getBetweenLevels ())
                setNewGameState (GAMESTATE_LEVEL_NEW);
              else
                setNewGameState (GAMESTATE_MAP);
            }

          //Look at inventory
          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[1], false))
            setNewGameState (GAMESTATE_INVENTORY);

          //Unequip the ability.
          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[2], false) &&
              listBoxVect[1].getElementHit () >= 0 && listBoxVect[1].getElementHit()<equippedAbilityNameList.size())
            {
              rulez.getPlayer().unequipAbility(equippedAbilityNameList[listBoxVect[1].getElementHit ()]);
            }

          //Equip the ability.
          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[3], false) &&
              listBoxVect[0].getElementHit () >= 0 && listBoxVect[0].getElementHit () < learnedAbilityNameList.size())
            {
              rulez.getPlayer().equipAbility(learnedAbilityNameList[listBoxVect[0].getElementHit ()], listBoxVect[1].getElementHit());
            }

          //player learns the ability.
          if (rulez.getBetweenLevels () && isMouseOnHotSpot((*inputBufferIterator), buttonVect[4], false) &&
              listBoxVect[2].getElementHit () >= 0)
            {
              rulez.getStore().teachAbility (rulez.getPlayer(), listBoxVect[2].getElementHit ());
            }

          //player forgets the ability.
          if (rulez.getBetweenLevels () && isMouseOnHotSpot((*inputBufferIterator), buttonVect[5], false) &&
              listBoxVect[0].getElementHit () >= 0 && listBoxVect[0].getElementHit () < learnedAbilityNameList.size())
            {
              rulez.getPlayer().forgetAbility (learnedAbilityNameList[listBoxVect[0].getElementHit ()],"","");
            }
        }

      if (inputBufferIterator -> getInput () == INPUT_MOUSEDOWN)
        {
          buttonUpdateClickStatus ((*inputBufferIterator), numButtonsToUse);
          //listBoxUpdateClickStatus ((*inputBufferIterator), numListsToUse);
          checkInputOnListBox (listBoxVect[0], tempStr, tempHelpStr,
                                   inputBufferIterator->getData()[0], inputBufferIterator->getData()[1], inputBufferIterator->getData()[2]);
          checkInputOnListBox (listBoxVect[1], tempStr, tempHelpStr,
                                   inputBufferIterator->getData()[0], inputBufferIterator->getData()[1], inputBufferIterator->getData()[2]);
          checkInputOnListBox (listBoxVect[2], tempStr, tempHelpStr,
                                   inputBufferIterator->getData()[0], inputBufferIterator->getData()[1], inputBufferIterator->getData()[2]);
        }
      if (inputBufferIterator -> getInput () == INPUT_QUITGAME)
        {
          addQuitCommand ();
        }
      inputBufferIterator ++;
    }
}
