#include <d3d8.h>

#include ".\gsmenu.h"
#include ".\GSStars.h"
#include ".\GSPlanet.h"
#include ".\LD.h"



CGSMenu::CGSMenu()
{

  theApp.m_Universe.CreateFromSeed( 17 );
  m_ButtonReleased = false;

}



CGSMenu::~CGSMenu(void)
{
}



void CGSMenu::Display( IDirect3DDevice8* pDevice )
{

  theApp.m_Universe.DisplayStars( pDevice, 0 );

  theApp.m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );

  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

  theApp.PrintNiceCentered( 321, 21, "UNIVERSAL CONQUEST", 0xff000000 );
  theApp.PrintNiceCentered( 320, 20, "UNIVERSAL CONQUEST" );

  theApp.PrintNiceCentered( 320, 60, "Ludum Dare #19" );
  theApp.PrintNiceCentered( 320, 90, "Georg \"Endurion\" Rottensteiner" );

  theApp.PrintNiceCentered( 320, 150, "http://www.georg-rottensteiner.de" );

  theApp.Print( 30, 200, "Travel to other stars. Search for ore or technology to sell at home. Buy better equipment to access" );
  theApp.Print( 30, 220, "farther away star systems and more planets. Can you discover an alien lifeform?" );

  theApp.Print( 30, 260, "Use mouse to select, cursor keys to move and Q or A to shoot." );

  theApp.RenderButton( 190, 410, 120, 40, LD::TEX_BUTTON_1, LD::TEX_BUTTON_2, LD::TEX_BUTTON_3, "PLAY" );
  theApp.RenderButton( 330, 410, 120, 40, LD::TEX_BUTTON_1, LD::TEX_BUTTON_2, LD::TEX_BUTTON_3, "QUIT" );

  theApp.Print( 3, 465, "V1.0" );

}



void CGSMenu::UpdateFrame( const float fElapsedTime )
{

}



void CGSMenu::InitUniverse()
{

  theApp.m_Universe.CreateFromSeed();
  theApp.m_PlayerData.Init();

}



void CGSMenu::OnMouse( int X, int Y, int Buttons )
{

  if ( HandleButton( X, Y, Buttons, 190, 410, 120, 40, 1 ) )
  {
    InitUniverse();
    theApp.NextState( new CGSStars() );
    return;
  }
  if ( HandleButton( X, Y, Buttons, 330, 410, 120, 40, 2 ) )
  {
    OnChar( 27 );
    return;
  }

  if ( !( Buttons & 1 ) )
  {
    m_ButtonReleased = true;
  }

}



void CGSMenu::OnChar( int iChar )
{

  if ( iChar == 'p' )
  {
    m_ButtonReleased = false;
    InitUniverse();
    theApp.NextState( new CGSStars() );
  }
  else if ( iChar == 27 )
  {
    PostMessage( theApp.m_hWnd, WM_CLOSE, 0, 0 );
  }

}



void CGSMenu::OnKeyDown( int iChar )
{

}





