/*
	Rogue Trader.
	Copyright (c) 2007, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   GuiScreen_InGameMenu
// Purpose:      In game menu GUI screen.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

#include "GuiScreen_InGameMenu.h"

/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Name:     GuiScreen_InGameMenu::GuiScreen_InGameMenu()
Purpose:  Constructor for this gui screen. populates the screen with widgets.
Params:   pointer to a game
Returns:  n/a

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

GuiScreen_InGameMenu::GuiScreen_InGameMenu( Game * game )
{
    //--------------------------------------------------------------------------
    // Create the event listeners for the gui screen
    //--------------------------------------------------------------------------

    eventMap                = new EventMap(this);
    eventShipInfo           = new EventShipInfo(this);
    eventCargoInfo          = new EventCargoInfo(this);
    eventCommanderInfo      = new EventCommanderInfo(this);
    eventReturn             = new EventReturn(this);
    eventQuit               = new EventQuit(this,game);

    //--------------------------------------------------------------------------
    // Create the main gui panel and set its attributes
    //--------------------------------------------------------------------------

    // Create panel

    GuiPanel * mainPanel = new GuiPanel();

    // Set panel size

    mainPanel->setSize( 750 , 550 );

    // center the panel in the middle of the window
    
    {
		// Get the effective or virtual resolution of the game:
		float effectiveResX = 0;
		float effectiveResY = 0;
		Game::getEffectiveResolution(effectiveResX, effectiveResY);

		// Center the panel within that 'effective' resolution
		mainPanel->setPosition
		(
			(int) effectiveResX / 2 - mainPanel->getSizeX() / 2,
			(int) effectiveResY / 2 - mainPanel->getSizeY() / 2
		);
    }

    // Add the main panel into the gui

    addWidget(mainPanel);

    //--------------------------------------------------------------------------
    // Create the side bar title panel: this is acually an image
    //--------------------------------------------------------------------------

    // Create panel

    GuiImage * sideTitlePanel = new GuiImage();

    // Set image for the panel:

    sideTitlePanel->setImage( const_cast<GLTexture*>(GLTextureManager::getTexMenuTitlePanel()) );

    // Set panel size

    sideTitlePanel->setSize( 256, 64 );

    // Set panel position

    sideTitlePanel->setPosition(8,8);

    // Add the main panel into the gui

    mainPanel->addWidget(sideTitlePanel);

    //--------------------------------------------------------------------------
    // Create a side bar panel to hold the buttons: again an image
    //--------------------------------------------------------------------------

    // Create panel

    GuiImage * sidePanel = new GuiImage();

    // Set image for the panel:

    sidePanel->setImage( const_cast<GLTexture*>(GLTextureManager::getTexMenuButtonPanel()) );

    // Set panel size

    sidePanel->setSize( 256, 512 );

    // Set panel position

    sidePanel->setPosition(8,58);

    // Add the main panel into the gui

    mainPanel->addWidget(sidePanel);

    //--------------------------------------------------------------------------
    // Create the side bar title
    //--------------------------------------------------------------------------

    // Create the label

    GuiLabel * sideTitle = new GuiLabel();

    // Set the label

    sideTitle->setLabel("Game menu");

    // Get the big font from the font manager

    GLFont * bigFont = GLFontManager::getFont_big();

    // Set the label font

    sideTitle->setFont(bigFont);

    // Set the label font size

    sideTitle->setFontSize(16);

    // Set the label position

    sideTitle->setPosition(32,20);

    // Add it into the side bar panel

    mainPanel->addWidget(sideTitle);

    //--------------------------------------------------------------------------
    // Create the map panel
    //--------------------------------------------------------------------------

    // Create panel

    panelMap = new GuiPanel();

    panelMap->setRaised(false);
    panelMap->setSize( 526, 534 );
    panelMap->setPosition(216,8);
    panelMap->setColor(0.3f,0.3f,0.3f);

    // Create the panel tiltle:

    GuiLabel * mapTitle = new GuiLabel();

    mapTitle->setFont(bigFont);
    mapTitle->setLabel("Galactic map");
    mapTitle->setFontSize(16);
    mapTitle->setPosition(20,15);
    mapTitle->setColor(1,1,1);

    panelMap->addWidget(mapTitle);

    // Create a horizontal rule to go under the title

    GuiHRule * mapRule = new GuiHRule();

    mapRule->setColor(1,1,1);
    mapRule->setSize(486,4);
    mapRule->setPosition(20,40);

    panelMap->addWidget(mapRule);

    // Create a panel to stick the actual galactic map widget in:

    GuiPanel * mapDisplayPanel = new GuiPanel();

    mapDisplayPanel->setRaised(false);
    mapDisplayPanel->setSize( 486, 320 );
    mapDisplayPanel->setPosition(20,60);
    mapDisplayPanel->setColor(0.3f,0.3f,0.3f);

    panelMap->addWidget(mapDisplayPanel);

    // Create a galaxy map and add it into this panel:

    GuiGalaxyMap * map = new GuiGalaxyMap(game,this,true);

    map->setPosition(2,2);
    map->setSize(482,316);
    map->centerView();

    mapDisplayPanel->addWidget(map);

    // Create a panel to hold the star information widget:

    GuiPanel * starInformationPanel = new GuiPanel();

    starInformationPanel->setRaised(false);
    starInformationPanel->setSize( 130, 140 );
    starInformationPanel->setPosition(20,384);
    starInformationPanel->setColor(0.3f,0.3f,0.3f);

    panelMap->addWidget(starInformationPanel);

    // Create the star information widget and add it to this panel

    GuiStarInfo * starInfo = new GuiStarInfo(map,game);

    starInfo->setSize( 128, 146 );
    starInfo->setPosition(0,0);

    starInformationPanel->addWidget(starInfo);

    // Create another panel to hold the market information widget

    GuiPanel * marketInformationPanel = new GuiPanel();

    marketInformationPanel->setRaised(false);
    marketInformationPanel->setSize( 350, 140 );
    marketInformationPanel->setPosition(156,384);
    marketInformationPanel->setColor(0.3f,0.3f,0.3f);

    panelMap->addWidget(marketInformationPanel);

    // Create the market information widget and add it to this panel:

    GuiMarketInfo * marketInfo = new GuiMarketInfo(game,map);

    marketInfo->setSize(348,138);
    marketInfo->setPosition(0,0);

    marketInformationPanel->addWidget(marketInfo);

    // Add the panel into the main gui panel

    mainPanel->addWidget(panelMap);

    //--------------------------------------------------------------------------
    // Create the cargo info panel
    //--------------------------------------------------------------------------

    // Create panel

    panelCargoInfo = new GuiPanel();

    panelCargoInfo->setRaised(false);         // Make a sunken panel
    panelCargoInfo->setSize( 526, 534 );      // Set panel size
    panelCargoInfo->setPosition(216,8);       // center the panel in the middle of the window
    panelCargoInfo->setColor(0.3f,0.3f,0.3f); // Set panel color

    // Create the panel tiltle:

    GuiLabel * cargoInfoTitle = new GuiLabel();

    cargoInfoTitle->setFont(bigFont);
    cargoInfoTitle->setLabel("Cargo information");
    cargoInfoTitle->setFontSize(16);
    cargoInfoTitle->setPosition(20,15);
    cargoInfoTitle->setColor(1,1,1);

    panelCargoInfo->addWidget(cargoInfoTitle);

    // Create a horizontal rule to go under the title

    GuiHRule * cargoInfoRule = new GuiHRule();

    cargoInfoRule->setColor(1,1,1);
    cargoInfoRule->setSize(486,4);
    cargoInfoRule->setPosition(20,40);

    panelCargoInfo->addWidget(cargoInfoRule);

    // Create a sub panel to hold the actual cargo information widget:

    GuiPanel * cargoInfoWidgetPanel = new GuiPanel();

    cargoInfoWidgetPanel->setRaised(false);
    cargoInfoWidgetPanel->setSize( 486, 464 );
    cargoInfoWidgetPanel->setPosition(20,60);
    cargoInfoWidgetPanel->setColor(0.3f,0.3f,0.3f);

    panelCargoInfo->addWidget(cargoInfoWidgetPanel);

    // Add the actual cargo information widget into this subpanel

    GuiCargoInfo * cargoInfo = new GuiCargoInfo(game);

    cargoInfo->setPosition(0,0);
    cargoInfo->setSize(484,462);

    cargoInfoWidgetPanel->addWidget(cargoInfo);

    // Add the panel into the main gui panel

    mainPanel->addWidget(panelCargoInfo);

    //--------------------------------------------------------------------------
    // Create the ship info panel
    //--------------------------------------------------------------------------

    // Create panel

    panelShipInfo = new GuiPanel();

    panelShipInfo->setRaised(false);         // Make a sunken panel
    panelShipInfo->setSize( 526, 534 );      // Set panel size
    panelShipInfo->setPosition(216,8);       // center the panel in the middle of the window
    panelShipInfo->setColor(0.3f,0.3f,0.3f); // Set panel color

    // Create the panel tiltle:

    GuiLabel * shipInfoTitle = new GuiLabel();

    shipInfoTitle->setFont(bigFont);
    shipInfoTitle->setLabel("Ship information");
    shipInfoTitle->setFontSize(16);
    shipInfoTitle->setPosition(20,15);
    shipInfoTitle->setColor(1,1,1);

    panelShipInfo->addWidget(shipInfoTitle);

    // Create a horizontal rule to go under the title

    GuiHRule * shipInfoRule = new GuiHRule();

    shipInfoRule->setColor(1,1,1);
    shipInfoRule->setSize(486,4);
    shipInfoRule->setPosition(20,40);

    panelShipInfo->addWidget(shipInfoRule);

    // Create a sub panel to hold the ship information widget

    GuiPanel * shipInfoWidgetPanel = new GuiPanel();

    shipInfoWidgetPanel->setRaised(false);
    shipInfoWidgetPanel->setSize( 486, 464 );
    shipInfoWidgetPanel->setPosition(20,60);
    shipInfoWidgetPanel->setColor(0.3f,0.3f,0.3f);

    panelShipInfo->addWidget(shipInfoWidgetPanel);

    // Create the actual ship information widget itself

    GuiShipInfo * shipInfo = new GuiShipInfo(game);

    shipInfo->setPosition(0,0);
    shipInfo->setSize(484,464);

    shipInfoWidgetPanel->addWidget(shipInfo);

    // Add the panel into the main gui panel

    mainPanel->addWidget(panelShipInfo);

    //--------------------------------------------------------------------------
    // Create the commander info panel
    //--------------------------------------------------------------------------

    // Create panel

    panelCommanderInfo = new GuiPanel();

    panelCommanderInfo->setRaised(false);
    panelCommanderInfo->setSize( 526, 534 );
    panelCommanderInfo->setPosition(216,8);
    panelCommanderInfo->setColor(0.3f,0.3f,0.3f);

    // Create the panel tiltle:

    GuiLabel * commanderInfoTitle = new GuiLabel();

    commanderInfoTitle->setFont(bigFont);
    commanderInfoTitle->setLabel("Commander information");
    commanderInfoTitle->setFontSize(16);
    commanderInfoTitle->setPosition(20,15);
    commanderInfoTitle->setColor(1,1,1);

    panelCommanderInfo->addWidget(commanderInfoTitle);

    // Create a horizontal rule to go under the title

    GuiHRule * commanderInfoRule = new GuiHRule();

    commanderInfoRule->setColor(1,1,1);
    commanderInfoRule->setSize(486,4);
    commanderInfoRule->setPosition(20,40);

    panelCommanderInfo->addWidget(commanderInfoRule);

    // Create a sub panel to hold the actual player information widget:

    GuiPanel * playerInfoWidgetPanel = new GuiPanel();

    playerInfoWidgetPanel->setRaised(false);
    playerInfoWidgetPanel->setSize( 486, 464 );
    playerInfoWidgetPanel->setPosition(20,60);
    playerInfoWidgetPanel->setColor(0.3f,0.3f,0.3f);

    panelCommanderInfo->addWidget(playerInfoWidgetPanel);

    // Add the actual player information widget into this subpanel

    GuiPlayerInfo * playerInfo = new GuiPlayerInfo(game);

    playerInfo->setPosition(0,0);
    playerInfo->setSize(484,462);

    playerInfoWidgetPanel->addWidget(playerInfo);

    // Add the panel into the main gui panel

    mainPanel->addWidget(panelCommanderInfo);

    //--------------------------------------------------------------------------
    // Create the buttons for this gui screen
    //--------------------------------------------------------------------------

    // Create the buttons

    GuiButton * btnMap              = new GuiButton();
    GuiButton * btnCargoInfo        = new GuiButton();
    GuiButton * btnShipInfo         = new GuiButton();
    GuiButton * btnCommanderInfo    = new GuiButton();
    GuiButton * btnReturn           = new GuiButton();
    GuiButton * btnQuit             = new GuiButton();

    // Set size of the buttons

    btnMap->setSize(180,35);
    btnShipInfo->setSize(180,35);
    btnCargoInfo->setSize(180,35);
    btnCommanderInfo->setSize(180,35);
    btnReturn->setSize(180,35);
    btnQuit->setSize(180,35);

    // Set position of the buttons

    btnMap->setPosition(18,80);
    btnCargoInfo->setPosition(18,120);
    btnShipInfo->setPosition(18,160);
    btnCommanderInfo->setPosition(18,200);
    btnReturn->setPosition(18,455);
    btnQuit->setPosition(18,495);

    // Set label of the buttons

    btnMap->setLabel("Galaxy map");
    btnCargoInfo->setLabel("Cargo info");
    btnShipInfo->setLabel("Ship info");
    btnCommanderInfo->setLabel("Commander info");
    btnReturn->setLabel("Return to game");
    btnQuit->setLabel("Quit game");

    // Set button event listeners

    btnMap->setEventListener(eventMap);
    btnCargoInfo->setEventListener(eventCargoInfo);
    btnShipInfo->setEventListener(eventShipInfo);
    btnCommanderInfo->setEventListener(eventCommanderInfo);
    btnReturn->setEventListener(eventReturn);
    btnQuit->setEventListener(eventQuit);

    // Add all four buttons into the main panel

    mainPanel->addWidget(btnMap);
    mainPanel->addWidget(btnShipInfo);
    mainPanel->addWidget(btnCargoInfo);
    mainPanel->addWidget(btnCommanderInfo);
    mainPanel->addWidget(btnReturn);
    mainPanel->addWidget(btnQuit);

    //--------------------------------------------------------------------------
    // Set the map panel as the current panel
    //--------------------------------------------------------------------------

    setCurrentPanel_map();
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Name:     GuiScreen_InGameMenu::~GuiScreen_InGameMenu()
Purpose:  Destructor for this gui screen. frees resources used.
Params:   n/a
Returns:  n/a

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

GuiScreen_InGameMenu::~GuiScreen_InGameMenu()
{
    // Delete the event listeners for the screen

    delete eventMap;
    delete eventShipInfo;
    delete eventCargoInfo;
    delete eventCommanderInfo;
    delete eventReturn;
    delete eventQuit;
}
