#include "GameState.h"

void GameState :: gamestateMainMenuStartup()
{
  //load resources
  /*
    if (sdlRE -> getMusicIndex () != 1)
    {
    sdlRE -> loadMusic (1);
    sdlRE -> playMusic (-1);
    }
  */
  rander.loadResourceDebug ("all");
  rander.startupMainMenu ();
}

void GameState :: gamestateMainMenuAfterDraw(uint8_t numberOfButtonsToHandle)
{
  //apply input
  inputBufferIterator = inputBuffer.begin ();
  while (inputBufferIterator < inputBuffer.end ())
    {
      if (inputBufferIterator -> getInput () == INPUT_MOUSEUP)
        {
          clearButtons (4);

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[0], false))
            setNewGameState (GAMESTATE_CREDITS);

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[1], false))
            setNewGameState (GAMESTATE_NEW_GAME);

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[2], false))
            {
              rulez.newPlayer (1); //class choice here

              rulez.getPlayer().addNewItem ("Equipment", "Equipment");
              rulez.getPlayer().equipEquipment ("Equipment");
              rulez.getPlayer().addNewItem ("ConsumeThis", "Consumable");
              rulez.getPlayer().addMoney (100);

              rulez.newStore ();
              rulez.newLevel ();

              //load the map here
              rander.clearResourceMap ();
              rander.loadResourceMap (rulez.getMap (), rulez.getPlayerMapUnit(), rulez.getEnemyMapUnits());
              rander.clearResourceMapEnemy ();
              rander.loadResourceMapEnemy ();

              setNewGameState (GAMESTATE_CONTINUE_GAME);
            }

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[3], false))
            {
              addQuitCommand ();
            }
        }
      if (inputBufferIterator -> getInput () == INPUT_MOUSEDOWN)
        {
          buttonUpdateClickStatus ((*inputBufferIterator), 4);
        }
      if (inputBufferIterator -> getInput () == INPUT_QUITGAME)
        {
          addQuitCommand ();
        }

      inputBufferIterator ++;
    }
}
