Beispiel #1
0
void SSHowTo::Startup()
{
	g_GUI.BringWindowToFront( "DebugWindow" );

	glm::ivec2 windowSize = g_GUI.GetWindowSize( "RootWindow" );
	g_GUI.AddWindow( m_WindowName, GUI::Rectangle( 0, 0, windowSize.x, windowSize.y ), "RootWindow" );
	//g_GUI.OpenWindow( m_WindowName );

	g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, windowSize.x, windowSize.y, glm::vec4( 0.05f, 0.05f, 0.1f, 1.0f ) ), m_WindowName );

	LoadTextures();

	m_Image = g_GUI.AddSprite( "", GUI::SpriteDefinition( "", ( windowSize.x / 2 ) - (m_BackgroundSize.x / 2), ( windowSize.y / 2 ) - (m_BackgroundSize.y / 2), 
		m_BackgroundSize.x, m_BackgroundSize.y ), m_WindowName );
	
	if( m_Textures.size() > 0 )
		m_Image->GetSpriteDefinitionRef().TextureHandle = m_Textures[0]->GetHandle();

	g_GUI.UseFont( FONT_ID_LEKTON_20 );
	GUI::Button* back = g_GUI.AddButton( "", GUI::Rectangle( 5, windowSize.y - 64 - 5, 256, 64 ), m_WindowName );
	
	m_ButtonPrevious = g_GUI.AddButton( "", GUI::Rectangle( (windowSize.x / 2) - 256, windowSize.y - 64 - 5, 256, 64 ), m_WindowName );
	m_ButtonNext = g_GUI.AddButton( "", GUI::Rectangle( (windowSize.x / 2) , windowSize.y - 64 - 5, 256, 64 ), m_WindowName );

	back->SetClickScript( "GE_BackFromHowTo()" );
	m_ButtonPrevious->SetClickScript( "GE_PreviousImage()" );
	m_ButtonNext->SetClickScript( "GE_NextImage()" );

	back->SetText( "Back");
	m_ButtonPrevious->SetText( "Previous");
	m_ButtonNext->SetText( "Next");

	back->SetBackgroundImage( "Button.png" );
	m_ButtonPrevious->SetBackgroundImage( "Button.png" );
	m_ButtonNext->SetBackgroundImage( "Button.png" );

	
	//Script functions that are to be called by buttons
	g_Script.Register( "GE_BackFromHowTo", [this] ( IScriptEngine* ) -> int 
	{
		//g_GameModeSelector.SwitchToGameMode( GameModeType::MainMenu );
		g_Script.Perform( "CloseWindow('HowTo'); OpenWindow('MainMenu')" );

		return 0; 
	} );
	g_Script.Register( "GE_PreviousImage", [this] ( IScriptEngine* ) -> int 
	{ 
		m_HowToIndex--;
		if( m_HowToIndex < 0 )
			m_HowToIndex = 0;
		return 0; 
	
	} );

	g_Script.Register( "GE_NextImage", [this] ( IScriptEngine* ) -> int 
	{ 
		m_HowToIndex++;
		if( m_HowToIndex >= m_Textures.size() )
			m_HowToIndex = static_cast<int>( m_Textures.size() ) - 1;
		return 0; 
	
	} );
	
	
}
Beispiel #2
0
void SSMainMenu::Startup()
{
	g_GUI.BringWindowToFront( "DebugWindow" );

	glm::ivec2 windowSize = g_GUI.GetWindowSize( "RootWindow" );
	g_GUI.AddWindow( "MainMenu", GUI::Rectangle( 0, 0, windowSize.x, windowSize.y ), "RootWindow" );
	g_GUI.OpenWindow( "MainMenu" );

	//g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, windowSize.x, windowSize.y, glm::vec4( 0.05f, 0.05f, 0.17f, 1.0f ) ), "MainMenu" );
	g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, windowSize.x, windowSize.y, glm::vec4( 0.05f, 0.05f, 0.1f, 1.0f ) ), "MainMenu" );

	int btnWidth = 256;
	int btnHeight = 64;
	int btnSpacing = btnHeight + 10;
	int numButtons = 6;
	
	int x = m_LeftOffset; //( windowSize.x / 2 ) - ( btnWidth / 2 );
	int y = ( windowSize.y / 2 ) - ( ( btnSpacing * numButtons ) - 10 ) / 2;

	g_GUI.AddSprite( "", GUI::SpriteDefinition( "Menu_bg.png", x + btnWidth + m_LeftOffset, ( windowSize.y / 2) - ( m_BackgroundSize.y / 2 ), m_BackgroundSize.x, m_BackgroundSize.y, glm::vec4( 1.0f ) ), "MainMenu" );
	g_GUI.AddSprite( "", GUI::SpriteDefinition( "Menu_logo.png", 0, y - m_LogoSize.y, m_LogoSize.x, m_LogoSize.y, glm::vec4( 1.0f ) ), "MainMenu" );
	
	g_GUI.UseFont( FONT_ID_LEKTON_20 );
	auto setButtonDesign = [] ( GUI::Button* btn )
	{
		btn->SetBackgroundImage( "Button.png" );
		btn->SetColour( glm::vec4( 1.0f ) ); 
		btn->SetHighLightColour( glm::vec4( 0.8f, 1.0f, 1.0f, 1.0f ) );
		btn->GetBackgroundRef().BorderSize = 0;
	};

	auto addMenuButton =[x, y, btnWidth, btnHeight, btnSpacing, setButtonDesign] ( const rString& text, const rString& script ) mutable -> GUI::Button*
	{
		GUI::Button* btn = g_GUI.AddButton( text, GUI::Rectangle( x, y, btnWidth, btnHeight ), "MainMenu" );
		btn->SetClickScript( script );
		btn->SetText( text );
		btn->DisableClickEffect();
		setButtonDesign( btn );
		y += btnSpacing;

		return btn;
	};

	//Add the menu buttons here
	m_SinglePlayerButton	= addMenuButton( "Singleplayer", "SwitchGameMode( 'singleplayerlobby' )" );
	m_MultiPlayerButton		= addMenuButton( "Multiplayer", "SwitchGameMode( 'netlob' )" );
	m_ReplayButton			= addMenuButton( "Replay", "OpenWindow('ReplaySelectWindow'); CloseWindow( 'MainMenu' )" );
	m_OptionsButton			= addMenuButton( "How to play", "OpenWindow('HowTo'); CloseWindow( 'MainMenu' )" );
	m_OptionsButton			= addMenuButton( "Options", "OpenWindow('Options'); CloseWindow( 'MainMenu' )" );
	m_ExitButton			= addMenuButton( "Exit", "GE_Exit()" );
	
	//Script functions that are to be called by buttons
	g_Script.Register( "GE_Exit", [] ( IScriptEngine* ) -> int { SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent( &event ); return 0; } );
	
	//Debug stuff
	//g_Script.Perform( "OpenWindow('Options'); CloseWindow( 'MainMenu' )" );

	if ( !g_SSReplaySelectMenu.HasReplays() )
		m_ReplayButton->SetEnabled( false );

	if(g_SSMusicManager.LoadSceneMusic("../../../asset/audio/script/MainMenu.lua"))
		g_SSMusicManager.Activate();
}