/*
	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.
*/

#ifndef GUISCREEN_STARTUP_H
#define GUISCREEN_STARTUP_H

//##############################################################################
// Foward references
//##############################################################################

class GuiLabel;
class GuiImage;
class GuiHRule;
class GuiLoadGame;
class GLFontManager;
class Game;

//##############################################################################
// Stuff that can't be forward referenced
//##############################################################################

#include "Game.h"
#include "GuiScreen.h"
#include "GuiButton.h"
#include "GuiPanel.h"
#include "GuiSlider.h"
#include "IntroScreen.h"
#include "SoundSystem.h"

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   GuiScreen_Startup
// Purpose:      Startup GUI screen. Displays when the game starts.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class GuiScreen_Startup : public GuiScreen
{

 public:

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Constructor:

        GuiScreen_Startup();

        // Destructor:

        ~GuiScreen_Startup();

        // Re-center the main panel after a resolution change:

        void centerPanels();

        // Make one of the panels visible and the others invisible:

        void setCurrentPanel_intro()
        {
            // Disable and make all other panels invisble

            panelNewGame->setVisible(false);
            panelLoadGame->setVisible(false);
            panelSettings->setVisible(false);

            panelNewGame->setEnabled(false);
            panelLoadGame->setEnabled(false);
            panelSettings->setEnabled(false);

            // Make this panel visible

            panelIntro->setVisible(true);
            panelIntro->setEnabled(true);
        }

        void setCurrentPanel_newGame()
        {
            // Disable and make all other panels invisble

            panelIntro->setVisible(false);
            panelLoadGame->setVisible(false);
            panelSettings->setVisible(false);

            panelIntro->setEnabled(false);
            panelLoadGame->setEnabled(false);
            panelSettings->setEnabled(false);

            // Make this panel visible

            panelNewGame->setVisible(true);
            panelNewGame->setEnabled(true);
        }

        void setCurrentPanel_loadGame()
        {
            // Disable and make all other panels invisble

            panelIntro->setVisible(false);
            panelNewGame->setVisible(false);
            panelSettings->setVisible(false);

            panelIntro->setEnabled(false);
            panelNewGame->setEnabled(false);
            panelSettings->setEnabled(false);

            // Make this panel visible

            panelLoadGame->setVisible(true);
            panelLoadGame->setEnabled(true);
        }

        void setCurrentPanel_settings()
        {
            // Disable and make all other panels invisble

            panelIntro->setVisible(false);
            panelNewGame->setVisible(false);
            panelLoadGame->setVisible(false);

            panelIntro->setEnabled(false);
            panelNewGame->setEnabled(false);
            panelLoadGame->setEnabled(false);

            // Make this panel visible

            panelSettings->setVisible(true);
            panelSettings->setEnabled(true);
        }

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

 private:

        //----------------------------------------------------------------------
        // The main panel for the screen:
        //----------------------------------------------------------------------

        GuiPanel * mainPanel;

        //----------------------------------------------------------------------
        // The separate panels for the screen: only one is shown at a time
        //----------------------------------------------------------------------

        GuiPanel * panelIntro;
        GuiPanel * panelNewGame;
        GuiPanel * panelLoadGame;
        GuiPanel * panelSettings;

        //----------------------------------------------------------------------
        // Event listener class definitions and event implementations:
        //----------------------------------------------------------------------

        class EventNewGame : public GLWindowEventListener
        {
            public: EventNewGame( GuiScreen_Startup * screen ) : guiScreen( screen ) { ; }
        
			// No unreferenced param warning
	        
			#pragma warning(disable:4100)    

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Get the users name:

                const char * userName = GuiScreen::showInputDialog
                (
                    "Enter commander name",
                    "Please enter your commander name:"
                );

                if ( userName[0] == 0 )
                {
                    // If the user entered no name then give an error message:

                    GuiScreen::showMessageDialog
                    (
                        "Enter commnader name",
                        "You must enter a name before proceeding."
                    );

                    // Proceed no further:

                    return;
                }

                // Process any window messages first to get rid of keypress messages:

                GLWindow::run();

                // Show the intro screen- in all its star wars geeky glory :)

                IntroScreen::run
                (
                    "Rogue Trader",                                     // Main title

                    "A long time ago in a galaxy far far away.."        // Main text
                    "\n"
                    "\n"
                    "\n"
                    "\nIn a time of uncertainty and unrest,"
                    "\ngreat spacefarers roamed the galaxy in"
                    "\nsearch of fame and fortune. These people"
                    "\nwere pioneers of the great unknown,"
                    "\nboldly going were nobody had ever gone"
                    "\nbefore.."
                    "\n"
                    "\nMany tales were told of epic battles,"
                    "\nand heroic deeds. Their names became"
                    "\nimortalised in the history books forever,"
                    "\nfounding civilisation as we know it today."
                    "\n"
                    "\nNow you must follow in their footsteps,"
                    "\nand reach for the stars in search of"
                    "\nglory and greatness.."
                    "\n"
                    "\nDo you have what it takes ?" ,

                    5       ,   // Time the title text is on the screen for
                    60      ,   // Time the main text is on the screen for
                    15          // Speed at which the main text scrolls
                );

                // Run the game if the window still exists:

                if ( GLWindow::exists() )
                {
                    // Show the loading screen:

                    Game::drawLoadingScreen();

                    // Create a new game:

                    Game * game = new Game(userName);

                    // Run the game

                    game->run();

                    // Delete the game when finished

                    delete game;

                    // Switch back to the intro panel:

                    guiScreen->setCurrentPanel_intro();
                }
            }
            
			// Restore this to normal
	            
			#pragma warning(default:4100)              

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventLoadGame : public GLWindowEventListener
        {
            public: EventLoadGame( GuiScreen_Startup * screen ) : guiScreen( screen ) { ; }

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)   

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set the load game panel as the current gui panel

                guiScreen->setCurrentPanel_loadGame();
            }
            
			// Restore this to normal
	            
			#pragma warning(default:4100)                          

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventSettings : public GLWindowEventListener
        {
            public: EventSettings( GuiScreen_Startup * screen ) : guiScreen( screen ) { ; }

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)  

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Change the current panel

                guiScreen->setCurrentPanel_settings();
            }
            
			// Restore this to normal
	            
			#pragma warning(default:4100)             

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventQuit : public GLWindowEventListener
        {
            public:

            // Constructor: takes guiscreen the listener belongs to

            EventQuit( GuiScreen_Startup * screen ) : guiScreen( screen ) { ; }

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)  

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Exit the gui screen this widget belongs to

                guiScreen->exit();
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)                    

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventResolution800x600_windowed : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution800x600_windowed(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)  

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 800x600 windowed

                GLWindow::setFullscreen(false,800,600);

				// Wait for the window to adjust
				
				GLWindow::run();                

                // Recenter the panels in the screen

                guiScreen->centerPanels();
            }
            
			// Restore this to normal
	            
			#pragma warning(default:4100)                

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventResolution800x600_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution800x600_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)  

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;
                
                // Set resolution to 800x600 fullscreen
                
                if ( GLWindow::testFullscreen(800,600) )
                {
					GLWindow::setFullscreen(true,800,600);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}      
				
				// Wait for the window to adjust
				
				GLWindow::run();				

                // Recenter the panels in the screen

                guiScreen->centerPanels();
            }
            
			// Restore this to normal
	            
			#pragma warning(default:4100)                

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventResolution1024x768_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution1024x768_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)  

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 1024x768 fullscreen
                
                if ( GLWindow::testFullscreen(1024,768) )
                {
					GLWindow::setFullscreen(true,1024,768);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}         
				
				// Wait for the window to adjust
				
				GLWindow::run();				              

                // Recenter the panels in the screen

                guiScreen->centerPanels();
            }
            
			// Restore this to normal
	            
			#pragma warning(default:4100)                

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventResolution1280x1024_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution1280x1024_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 1280x1024 fullscreen
                
                if ( GLWindow::testFullscreen(1280,1024) )
                {
					GLWindow::setFullscreen(true,1280,1024);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}         
				
				// Wait for the window to adjust
				
				GLWindow::run();				       

                // Recenter the panels in the screen

                guiScreen->centerPanels();
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };
        
        //======================================================================

        class EventResolution1600x1200_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution1600x1200_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 1600x1200 fullscreen
                
                if ( GLWindow::testFullscreen(1600,1200) )
                {
					GLWindow::setFullscreen(true,1600,1200);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}         
				
				// Wait for the window to adjust
				
				GLWindow::run();				       

                // Recenter the panels in the screen

                guiScreen->centerPanels();
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };        
        
        //======================================================================

        class EventResolution1440x900_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution1440x900_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 1440x900 fullscreen
                
                if ( GLWindow::testFullscreen(1440,900) )
                {
					GLWindow::setFullscreen(true,1440,900);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}
				
				// Wait for the window to adjust
				
				GLWindow::run();

                // Recenter the panels in the screen

                guiScreen->centerPanels();
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };        
        
        //======================================================================

        class EventResolution1680x1050_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution1680x1050_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 1680x1050 fullscreen
                
                if ( GLWindow::testFullscreen(1680,1050) )
                {
					GLWindow::setFullscreen(true,1680,1050);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}

				// Wait for the window to adjust
				
				GLWindow::run();

                // Recenter the panels in the screen

                guiScreen->centerPanels();         
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };
        
        //======================================================================

        class EventResolution1920x1080_fullscreen : public GLWindowEventListener
        {
            public:

            // Constructor

            EventResolution1920x1080_fullscreen(GuiScreen_Startup * guiScreen) : guiScreen(guiScreen){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

                // Set resolution to 1920x1080 fullscreen
                
                if ( GLWindow::testFullscreen(1920,1080) )
                {
					GLWindow::setFullscreen(true,1920,1080);
				}
				else
				{
					GuiScreen::showMessageDialog("Unable to change display mode","Requested display mode is not supported.");
				}
				
				// Wait for the window to adjust
				
				GLWindow::run();

                // Recenter the panels in the screen

                guiScreen->centerPanels();               
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // GuiScreen the listener belgons to

            GuiScreen_Startup * guiScreen;
        };

        //======================================================================

        class EventGammaChange : public GLWindowEventListener
        {
            public:

            // Set the slider used by the gamma change event:

            inline void setSlider( GuiSlider * slider ){ this->slider = slider; }

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Mouse moved event : called when slider dragged

            void mouseMoved ( int x , int y )
            {
                // Change the gamma setting to that of the slider:

                GLWindow::setGamma( slider->getValue() );
            }

			// Restore this to normal
	            
			#pragma warning(default:4100) 

            // Slider which controls the gamma setting

            GuiSlider * slider;
        };
        
        //======================================================================

        class EventSoundOnOff : public GLWindowEventListener
        {
            public:

            // Constructor

            EventSoundOnOff(GuiButton * soundButton) : soundButton(soundButton){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

				// Enable / disable sound
				
				SoundSystem::setSoundEnabled(!SoundSystem::isSoundEnabled());
				
				// Set button label accordingly
				
				if (SoundSystem::isSoundEnabled())
				{
					soundButton->setLabel("Enabled");
				}
				else
				{
					soundButton->setLabel("Disabled");
				}
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // The sound button that this corresponds to

            GuiButton * soundButton;
        };
        
        //======================================================================

        class EventMusicOnOff : public GLWindowEventListener
        {
            public:

            // Constructor

            EventMusicOnOff(GuiButton * musicButton) : musicButton(musicButton){;}

			// No unreferenced param warning
	        
			#pragma warning(disable:4100)

            // Implements button released event

            void mouseReleased
            (
                int x ,
                int y ,
                GLWindow::MouseButton button
            )
            {
                // Make sure button is lmb

                if ( button != GLWindow::MOUSE_BUTTON_LEFT ) return;

				// Enable / disable music
				
				MusicSystem::setMusicEnabled(!MusicSystem::isMusicEnabled());
				
				// Set button label accordingly
				
				if (MusicSystem::isMusicEnabled())
				{
					musicButton->setLabel("Enabled");
				}
				else
				{
					musicButton->setLabel("Disabled");
				}
            }

			// Restore this to normal
	            
			#pragma warning(default:4100)  

            // The music button that this corresponds to

            GuiButton * musicButton;
        };        

        //----------------------------------------------------------------------
        // Actual event listener objects:
        //----------------------------------------------------------------------

        EventNewGame                            *   eventNewGame;
        EventLoadGame                           *   eventLoadGame;
        EventSettings                           *   eventSettings;
        EventQuit                               *   eventQuit;
        EventResolution800x600_windowed         *   eventResolution800x600_windowed;
        EventResolution800x600_fullscreen       *   eventResolution800x600_fullscreen;
        EventResolution1024x768_fullscreen      *   eventResolution1024x768_fullscreen;
        EventResolution1280x1024_fullscreen     *   eventResolution1280x1024_fullscreen;
        EventResolution1600x1200_fullscreen     *   eventResolution1600x1200_fullscreen;
        EventResolution1440x900_fullscreen      *   eventResolution1440x900_fullscreen;
        EventResolution1680x1050_fullscreen     *   eventResolution1680x1050_fullscreen;
        EventResolution1920x1080_fullscreen     *   eventResolution1920x1080_fullscreen;
        EventGammaChange                        *   eventGammaChange;
        EventSoundOnOff                         *   eventSoundOnOff;
        EventMusicOnOff                         *   eventMusicOnOff;

}; // end of: class GuiScreen_Startup{}

//##############################################################################
// C++ Includes
//##############################################################################

#include "GuiButton.h"
#include "GuiLabel.h"
#include "GuiImage.h"
#include "GuiHRule.h"
#include "GuiLoadGame.h"
#include "GLFontManager.h"
#include "Game.h"

#endif  // ifndef GUISCREEN_STARTUP_H

