2011-02-16 21:40:15 +01:00
var userReportEnabledText ; // contains the original version with "$status" placeholder
2011-09-02 02:33:19 +02:00
var currentSubmenuType ; // contains submenu type
const MARGIN = 4 ; // menu border size
2011-12-22 18:55:00 +01:00
const background = "hellenes1" ; // Background type. Currently: 'hellenes1', 'persians1'.
2011-02-16 21:40:15 +01:00
2013-07-26 03:35:01 +02:00
var g _ShowSplashScreens ;
function init ( initData , hotloadData )
2009-07-16 12:20:51 +02:00
{
2011-09-11 05:30:41 +02:00
initMusic ( ) ;
// Play main menu music
global . music . setState ( global . music . states . MENU ) ;
2011-02-16 21:40:15 +01:00
2014-01-04 11:14:53 +01:00
userReportEnabledText = Engine . GetGUIObjectByName ( "userReportEnabledText" ) . caption ;
2011-09-02 02:33:19 +02:00
2011-09-06 20:15:27 +02:00
// initialize currentSubmenuType with placeholder to avoid null when switching
currentSubmenuType = "submenuSinglePlayer" ;
2012-04-09 14:30:56 +02:00
EnableUserReport ( Engine . IsUserReportEnabled ( ) ) ;
2012-10-17 22:33:50 +02:00
2013-07-26 03:35:01 +02:00
// Only show splash screen(s) once at startup, but not again after hotloading
g _ShowSplashScreens = hotloadData ? hotloadData . showSplashScreens : initData && initData . isStartup ;
}
2013-02-09 23:55:42 +01:00
2013-07-26 03:35:01 +02:00
function getHotloadData ( )
{
return { "showSplashScreens" : g _ShowSplashScreens } ;
2011-02-16 21:40:15 +01:00
}
2011-08-20 19:17:53 +02:00
var t0 = new Date ;
2011-12-22 18:54:33 +01:00
function scrollBackgrounds ( background )
2011-08-20 19:17:53 +02:00
{
2011-12-22 18:54:33 +01:00
if ( background == "hellenes1" )
{
2014-01-04 11:14:53 +01:00
var layer1 = Engine . GetGUIObjectByName ( "backgroundHele1-1" ) ;
var layer2 = Engine . GetGUIObjectByName ( "backgroundHele1-2" ) ;
var layer3 = Engine . GetGUIObjectByName ( "backgroundHele1-3" ) ;
2011-12-22 18:54:33 +01:00
layer1 . hidden = false ;
layer2 . hidden = false ;
layer3 . hidden = false ;
var screen = layer1 . parent . getComputedSize ( ) ;
var h = screen . bottom - screen . top ; // height of screen
var w = h * 16 / 9 ; // width of background image
// Offset the layers by oscillating amounts
2012-01-21 00:21:27 +01:00
var t = ( t0 - new Date ) / 700 ;
2011-12-22 18:54:33 +01:00
var speed = 1 / 20 ;
var off1 = 0.02 * w * ( 1 + Math . cos ( t * speed ) ) ;
var off2 = 0.12 * w * ( 1 + Math . cos ( t * speed ) ) - h * 6 / 9 ;
var off3 = 0.16 * w * ( 1 + Math . cos ( t * speed ) ) ;
var left = screen . right - w * ( 1 + Math . ceil ( screen . right / w ) ) ;
layer1 . size = new GUISize ( left + off1 , screen . top , screen . right + off1 , screen . bottom ) ;
layer2 . size = new GUISize ( screen . right / 2 - h + off2 , screen . top , screen . right / 2 + h + off2 , screen . bottom ) ;
layer3 . size = new GUISize ( screen . right - h + off3 , screen . top , screen . right + off3 , screen . bottom ) ;
}
if ( background == "persians1" )
{
2014-01-04 11:14:53 +01:00
var layer1 = Engine . GetGUIObjectByName ( "backgroundPers1-1" ) ;
var layer2 = Engine . GetGUIObjectByName ( "backgroundPers1-2" ) ;
var layer3 = Engine . GetGUIObjectByName ( "backgroundPers1-3" ) ;
var layer4 = Engine . GetGUIObjectByName ( "backgroundPers1-4" ) ;
2011-12-22 18:54:33 +01:00
layer1 . hidden = false ;
layer2 . hidden = false ;
layer3 . hidden = false ;
layer4 . hidden = false ;
var screen = layer1 . parent . getComputedSize ( ) ;
var h = screen . bottom - screen . top ; // height of screen
var screenWidth = screen . right - screen . left ;
var w = h * 16 / 9 ;
var t = ( t0 - new Date ) / 1000 ;
var speed = 1 / 20 ;
var off1 = 0.01 * w * ( Math . cos ( t * speed ) ) ;
var off2 = 0.03 * w * ( Math . cos ( t * speed ) ) ;
var off3 = 0.07 * w * ( 1 + Math . cos ( t * speed ) ) + 0.5 * screenWidth - h * 1.1 ;
var off4 = 0.16 * w * ( 1 + Math . cos ( t * speed ) ) - h * 6 / 9 ;
var left = screen . right - w * ( 1 + Math . ceil ( screen . right / w ) ) - 0.5 * screenWidth + h ;
layer1 . size = new GUISize ( left + off1 , screen . top , screen . right + off1 + h , screen . bottom ) ;
layer2 . size = new GUISize ( left + off2 , screen . top , screen . right + off2 + h , screen . bottom ) ;
layer3 . size = new GUISize ( screen . left + off3 , screen . top , screen . left + 2 * h + off3 , screen . bottom ) ;
layer4 . size = new GUISize ( screen . left + off4 , screen . top , screen . left + 2 * h + off4 , screen . bottom ) ;
}
2011-08-20 19:17:53 +02:00
}
2011-02-16 21:40:15 +01:00
function submitUserReportMessage ( )
{
2014-01-04 11:14:53 +01:00
var input = Engine . GetGUIObjectByName ( "userReportMessageInput" ) ;
2011-02-16 21:40:15 +01:00
var msg = input . caption ;
if ( msg . length )
Engine . SubmitUserReport ( "message" , 1 , msg ) ;
input . caption = "" ;
}
function formatUserReportStatus ( status )
{
var d = status . split ( /:/ , 3 ) ;
if ( d [ 0 ] == "disabled" )
2014-04-20 22:51:48 +02:00
return translate ( "disabled" ) ;
2011-02-16 21:40:15 +01:00
if ( d [ 0 ] == "connecting" )
2014-04-20 22:51:48 +02:00
return translate ( "connecting to server" ) ;
2011-02-16 21:40:15 +01:00
if ( d [ 0 ] == "sending" )
{
var done = d [ 1 ] ;
2014-04-20 22:51:48 +02:00
return sprintf ( translate ( "uploading (%f%%)" ) , Math . floor ( 100 * done ) ) ;
2011-02-16 21:40:15 +01:00
}
if ( d [ 0 ] == "completed" )
{
var httpCode = d [ 1 ] ;
if ( httpCode == 200 )
2014-04-20 22:51:48 +02:00
return translate ( "upload succeeded" ) ;
2011-02-16 21:40:15 +01:00
else
2014-04-20 22:51:48 +02:00
return sprintf ( translate ( "upload failed (%(errorCode)s)" ) , { errorCode : httpCode } ) ;
2011-02-16 21:40:15 +01:00
}
if ( d [ 0 ] == "failed" )
{
var errCode = d [ 1 ] ;
var errMessage = d [ 2 ] ;
2014-04-20 22:51:48 +02:00
return sprintf ( translate ( "upload failed (%(errorMessage)s)" ) , { errorMessage : errMessage } ) ;
2011-02-16 21:40:15 +01:00
}
2014-04-20 22:51:48 +02:00
return translate ( "unknown" ) ;
2011-02-16 21:40:15 +01:00
}
2011-10-30 02:07:28 +02:00
var lastTickTime = new Date ;
2011-02-16 21:40:15 +01:00
function onTick ( )
{
2011-10-30 02:07:28 +02:00
var now = new Date ;
var tickLength = new Date - lastTickTime ;
lastTickTime = now ;
2011-09-06 20:15:27 +02:00
// Animate backgrounds
2011-12-22 18:54:33 +01:00
scrollBackgrounds ( background ) ;
2011-08-20 19:17:53 +02:00
2011-09-06 20:15:27 +02:00
// Animate submenu
2011-10-30 02:07:28 +02:00
updateMenuPosition ( tickLength ) ;
2011-08-31 04:41:21 +02:00
2011-02-16 21:40:15 +01:00
if ( Engine . IsUserReportEnabled ( ) )
{
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "userReportEnabledText" ) . caption =
2011-02-16 21:40:15 +01:00
userReportEnabledText . replace ( /\$status/ ,
formatUserReportStatus ( Engine . GetUserReportStatus ( ) ) ) ;
}
2013-07-26 03:35:01 +02:00
// Show splash screens here, so we don't interfere with main menu hotloading
if ( g _ShowSplashScreens )
{
g _ShowSplashScreens = false ;
2013-12-30 00:56:18 +01:00
if ( Engine . ConfigDB _GetValue ( "user" , "splashscreenenable" ) !== "false" )
2014-01-04 11:14:53 +01:00
Engine . PushGuiPage ( "page_splashscreen.xml" , { "page" : "splashscreen" , callback : "SplashScreenClosedCallback" } ) ;
else
ShowRenderPathMessage ( ) ;
2013-07-26 03:35:01 +02:00
}
2012-04-09 14:30:56 +02:00
}
2014-01-04 11:14:53 +01:00
function ShowRenderPathMessage ( )
{
// Warn about removing fixed render path
if ( Engine . Renderer _GetRenderPath ( ) == "fixed" )
messageBox (
600 ,
300 ,
2014-04-24 15:33:15 +02:00
"[font=\"sans-bold-16\"]" +
2014-04-20 22:51:48 +02:00
sprintf ( translate ( "%(startWarning)sWarning:%(endWarning)s You appear to be using non-shader (fixed function) graphics. This option will be removed in a future 0 A.D. release, to allow for more advanced graphics features. We advise upgrading your graphics card to a more recent, shader-compatible model." ) , { startWarning : "[color=\"200 20 20\"]" , endWarning : "[/color]" } ) +
"\n\n" +
// Translation: This is the second paragraph of a warning. The
// warning explains that the user is using “non-shader“ graphics,
// and that in the future this will not be supported by the game, so
// the user will need a better graphics card.
translate ( "Please press \"Read More\" for more information or \"OK\" to continue." ) ,
translate ( "WARNING!" ) ,
2014-01-04 11:14:53 +01:00
0 ,
2014-04-20 22:51:48 +02:00
[ translate ( "OK" ) , translate ( "Read More" ) ] ,
2014-01-04 11:14:53 +01:00
[ null , function ( ) { Engine . OpenURL ( "http://www.wildfiregames.com/forum/index.php?showtopic=16734" ) ; } ]
) ;
}
function SplashScreenClosedCallback ( )
{
ShowRenderPathMessage ( ) ;
}
2012-04-09 14:30:56 +02:00
function EnableUserReport ( Enabled )
{
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "userReportDisabled" ) . hidden = Enabled ;
Engine . GetGUIObjectByName ( "userReportEnabled" ) . hidden = ! Enabled ;
2012-04-09 14:30:56 +02:00
Engine . SetUserReportEnabled ( Enabled ) ;
2009-07-16 12:20:51 +02:00
}
2011-08-31 04:41:21 +02:00
/ *
* MENU FUNCTIONS
* /
2011-09-11 05:30:41 +02:00
// Temporarily adding this here
//const BUTTON_SOUND = "audio/interface/ui/ui_button_longclick.ogg";
//function playButtonSound()
//{
// var buttonSound = new Sound(BUTTON_SOUND);
// buttonSound.play();
//}
2011-08-31 04:41:21 +02:00
// Slide menu
2011-10-30 02:07:28 +02:00
function updateMenuPosition ( dt )
2011-08-28 03:28:50 +02:00
{
2014-01-04 11:14:53 +01:00
var submenu = Engine . GetGUIObjectByName ( "submenu" ) ;
2011-09-06 20:15:27 +02:00
if ( submenu . hidden == false )
{
2011-10-30 02:07:28 +02:00
// Number of pixels per millisecond to move
const SPEED = 1.2 ;
2014-01-04 11:14:53 +01:00
var maxOffset = Engine . GetGUIObjectByName ( "mainMenu" ) . size . right - submenu . size . left ;
2011-10-30 02:07:28 +02:00
if ( maxOffset > 0 )
2011-09-06 20:15:27 +02:00
{
2011-10-30 02:07:28 +02:00
var offset = Math . min ( SPEED * dt , maxOffset ) ;
var size = submenu . size ;
size . left += offset ;
size . right += offset ;
submenu . size = size ;
2011-09-06 20:15:27 +02:00
}
}
2011-08-28 03:28:50 +02:00
}
2011-08-31 04:41:21 +02:00
// Opens the menu by revealing the screen which contains the menu
function openMenu ( newSubmenu , position , buttonHeight , numButtons )
2011-08-26 06:25:41 +02:00
{
2011-09-06 20:15:27 +02:00
// switch to new submenu type
currentSubmenuType = newSubmenu ;
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( currentSubmenuType ) . hidden = false ;
2011-08-31 04:41:21 +02:00
2011-09-06 20:15:27 +02:00
// set position of new submenu
2014-01-04 11:14:53 +01:00
var submenu = Engine . GetGUIObjectByName ( "submenu" ) ;
2011-09-06 20:15:27 +02:00
var top = position - MARGIN ;
var bottom = position + ( ( buttonHeight + MARGIN ) * numButtons ) ;
submenu . size = submenu . size . left + " " + top + " " + submenu . size . right + " " + bottom ;
2011-08-27 17:21:12 +02:00
2011-09-06 20:15:27 +02:00
// Blend in right border of main menu into the left border of the submenu
blendSubmenuIntoMain ( top , bottom ) ;
2011-08-31 04:41:21 +02:00
2011-09-06 20:15:27 +02:00
// Reveal submenu
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "submenu" ) . hidden = false ;
2011-08-31 04:41:21 +02:00
}
// Closes the menu and resets position
function closeMenu ( )
{
2011-09-11 05:30:41 +02:00
// playButtonSound();
2011-09-06 20:15:27 +02:00
// remove old submenu type
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( currentSubmenuType ) . hidden = true ;
2011-09-01 04:36:38 +02:00
2011-09-06 20:15:27 +02:00
// hide submenu and reset position
2014-01-04 11:14:53 +01:00
var submenu = Engine . GetGUIObjectByName ( "submenu" ) ;
2011-09-06 20:15:27 +02:00
submenu . hidden = true ;
2014-01-04 11:14:53 +01:00
submenu . size = Engine . GetGUIObjectByName ( "mainMenu" ) . size ;
2011-09-01 04:36:38 +02:00
2011-09-06 20:15:27 +02:00
// reset main menu panel right border
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "MainMenuPanelRightBorderTop" ) . size = "100%-2 0 100% 100%" ;
2011-08-31 04:41:21 +02:00
}
// Sizes right border on main menu panel to match the submenu
function blendSubmenuIntoMain ( topPosition , bottomPosition )
{
2014-01-04 11:14:53 +01:00
var topSprite = Engine . GetGUIObjectByName ( "MainMenuPanelRightBorderTop" ) ;
2011-09-06 20:15:27 +02:00
topSprite . size = "100%-2 0 100% " + ( topPosition + MARGIN ) ;
2011-08-31 04:41:21 +02:00
2014-01-04 11:14:53 +01:00
var bottomSprite = Engine . GetGUIObjectByName ( "MainMenuPanelRightBorderBottom" ) ;
2011-09-06 20:15:27 +02:00
bottomSprite . size = "100%-2 " + ( bottomPosition ) + " 100% 100%" ;
2011-08-26 06:25:41 +02:00
}
2014-04-20 22:51:48 +02:00
function getBuildString ( )
{
return sprintf ( translate ( "Build: %(buildDate)s (%(revision)s)" ) , { buildDate : Engine . GetBuildTimestamp ( 0 ) , revision : Engine . GetBuildTimestamp ( 2 ) } ) ;
}
2011-08-31 04:41:21 +02:00
/ *
* FUNCTIONS BELOW DO NOT WORK YET
* /
2011-09-06 20:15:27 +02:00
//// Switch to a given options tab window.
//function openOptionsTab(tabName)
//{
// // Hide the other tabs.
2013-05-13 00:28:02 +02:00
// for (var i = 1; i <= 3; i++)
2011-09-06 20:15:27 +02:00
// {
// switch (i)
// {
// case 1:
// var tmpName = "pgOptionsAudio";
// break;
// case 2:
// var tmpName = "pgOptionsVideo";
// break;
// case 3:
// var tmpName = "pgOptionsGame";
// break;
// default:
// break;
// }
//
// if (tmpName != tabName)
// {
2014-01-04 11:14:53 +01:00
// Engine.GetGUIObjectByName (tmpName + "Window").hidden = true;
// Engine.GetGUIObjectByName (tmpName + "Button").enabled = true;
2011-09-06 20:15:27 +02:00
// }
// }
//
// // Make given tab visible.
2014-01-04 11:14:53 +01:00
// Engine.GetGUIObjectByName (tabName + "Window").hidden = false;
// Engine.GetGUIObjectByName (tabName + "Button").enabled = false;
2011-09-06 20:15:27 +02:00
//}
//
//// Move the credits up the screen.
//function updateCredits()
//{
// // If there are still credit lines to remove, remove them.
// if (getNumItems("pgCredits") > 0)
// removeItem ("pgCredits", 0);
// else
// {
// // When we've run out of credit,
//
// // Stop the increment timer if it's still active.
// cancelInterval();
//
// // Close the credits screen and return.
// closeMainMenuSubWindow ("pgCredits");
// guiUnHide ("pg");
// }
//}
2014-04-20 22:51:48 +02:00
function exitGamePressed ( )
{
closeMenu ( ) ;
var btCaptions = [ translate ( "Yes" ) , translate ( "No" ) ] ;
var btCode = [ Engine . Exit , null ] ;
messageBox ( 400 , 200 , translate ( "Are you sure you want to quit 0 A.D.?" ) , translate ( "Confirmation" ) , 0 , btCaptions , btCode ) ;
}
function pressedScenarioEditorButton ( )
{
closeMenu ( ) ;
// Start Atlas
if ( Engine . AtlasIsAvailable ( ) )
Engine . RestartInAtlas ( ) ;
else
messageBox ( 400 , 200 , translate ( "The scenario editor is not available or failed to load." ) , translate ( "Error" ) , 2 ) ;
}
function getLobbyDisabledByBuild ( )
{
return translate ( "Launch the multiplayer lobby. [DISABLED BY BUILD]" ) ;
}