#include "GameState.h"

void GameState :: gamestateInventoryAfterDraw(uint8_t numButtonsToUse)
{
  vector <string> nameList;
  vector <bool> equippedList;
  rulez.getPlayer().getInventoryList(nameList, equippedList);

  inputBufferIterator = inputBuffer.begin ();
  while (inputBufferIterator < inputBuffer.end ())
    {
      if (inputBufferIterator -> getInput () == INPUT_MOUSEUP)
        {
          clearButtons (numButtonsToUse);

          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);
            }

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[1], false) && listBoxVect[0].getElementHit () >= 0)
            rulez.getPlayer().equipEquipment (listBoxVect[0].getElementHit ());

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[2], false) && listBoxVect[0].getElementHit () >= 0)
            rulez.getPlayer().unequipEquipment (listBoxVect[0].getElementHit ());

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[3], false) && listBoxVect[0].getElementHit () >= 0)
            rulez.getPlayer().sellItem (listBoxVect[0].getElementHit ());

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[4], false))
            setNewGameState (GAMESTATE_ABILITY);

          if (rulez.getBetweenLevels () && isMouseOnHotSpot((*inputBufferIterator), buttonVect[5], false) && listBoxVect[1].getElementHit () >= 0)
            {
              //player buys the item.
              rulez.getStore().buyItem (rulez.getPlayer (), listBoxVect[1].getElementHit ());
            }
        }

      if (inputBufferIterator -> getInput () == INPUT_MOUSEDOWN)
        {
          buttonUpdateClickStatus ((*inputBufferIterator), numButtonsToUse);

          checkInputOnListBox (listBoxVect[0], tempStr, tempHelpStr,
                               inputBufferIterator->getData()[0], inputBufferIterator->getData()[1], inputBufferIterator->getData()[2]);

          if (rulez.getBetweenLevels ())
            {
              checkInputOnListBox (listBoxVect[1], tempStr, tempHelpStr,
                                   inputBufferIterator->getData()[0], inputBufferIterator->getData()[1], inputBufferIterator->getData()[2]);
            }
        }
      if (inputBufferIterator -> getInput () == INPUT_QUITGAME)
        {
          addQuitCommand ();
        }
      inputBufferIterator ++;
    }
}
