2014-04-22 08:35:51 +02:00
const PAUSE = translate ( "Pause" ) ;
const RESUME = translate ( "Resume" ) ;
2014-01-02 17:22:03 +01:00
/ *
* MENU POSITION CONSTANTS
* /
// Menu / panel border size
const MARGIN = 4 ;
// Includes the main menu button
const NUM _BUTTONS = 8 ;
// Regular menu buttons
const BUTTON _HEIGHT = 32 ;
// The position where the bottom of the menu will end up (currently 228)
const END _MENU _POSITION = ( BUTTON _HEIGHT * NUM _BUTTONS ) + MARGIN ;
// Menu starting position: bottom
const MENU _BOTTOM = 0 ;
// Menu starting position: top
const MENU _TOP = MENU _BOTTOM - END _MENU _POSITION ;
// Menu starting position: overall
const INITIAL _MENU _POSITION = "100%-164 " + MENU _TOP + " 100% " + MENU _BOTTOM ;
// Number of pixels per millisecond to move
const MENU _SPEED = 1.2 ;
// Trade menu: available resources and step for probability changes
const RESOURCES = [ "food" , "wood" , "stone" , "metal" ] ;
const STEP = 5 ;
var isMenuOpen = false ;
var menu ;
var isDiplomacyOpen = false ;
var isTradeOpen = false ;
// Redefined every time someone makes a tribute (so we can save some data in a closure). Called in input.js handleInputBeforeGui.
var flushTributing = function ( ) { } ;
// Ignore size defined in XML and set the actual menu size here
function initMenuPosition ( )
{
2014-01-04 11:14:53 +01:00
menu = Engine . GetGUIObjectByName ( "menu" ) ;
2014-01-02 17:22:03 +01:00
menu . size = INITIAL _MENU _POSITION ;
}
// =============================================================================
// Overall Menu
// =============================================================================
//
// Slide menu
function updateMenuPosition ( dt )
{
if ( isMenuOpen )
{
var maxOffset = END _MENU _POSITION - menu . size . bottom ;
if ( maxOffset > 0 )
{
var offset = Math . min ( MENU _SPEED * dt , maxOffset ) ;
var size = menu . size ;
size . top += offset ;
size . bottom += offset ;
menu . size = size ;
}
}
else
{
var maxOffset = menu . size . top - MENU _TOP ;
if ( maxOffset > 0 )
{
var offset = Math . min ( MENU _SPEED * dt , maxOffset ) ;
var size = menu . size ;
size . top -= offset ;
size . bottom -= offset ;
menu . size = size ;
}
}
}
// Opens the menu by revealing the screen which contains the menu
function openMenu ( )
{
isMenuOpen = true ;
}
// Closes the menu and resets position
function closeMenu ( )
{
isMenuOpen = false ;
}
function toggleMenu ( )
{
if ( isMenuOpen == true )
closeMenu ( ) ;
else
openMenu ( ) ;
}
// Menu buttons
// =============================================================================
2014-10-27 02:32:11 +01:00
function optionsMenuButton ( )
2014-01-02 17:22:03 +01:00
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
2014-10-27 02:32:11 +01:00
openOptions ( ) ;
2014-01-02 17:22:03 +01:00
}
function chatMenuButton ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
openChat ( ) ;
}
function diplomacyMenuButton ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
openDiplomacy ( ) ;
}
function pauseMenuButton ( )
{
togglePause ( ) ;
}
function resignMenuButton ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
pauseGame ( ) ;
2014-05-08 05:43:03 +02:00
var btCaptions = [ translate ( "Yes" ) , translate ( "No" ) ] ;
var btCode = [ resignGame , resumeGame ] ;
2014-04-20 22:51:48 +02:00
messageBox ( 400 , 200 , translate ( "Are you sure you want to resign?" ) , translate ( "Confirmation" ) , 0 , btCaptions , btCode ) ;
2014-01-02 17:22:03 +01:00
}
function exitMenuButton ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
pauseGame ( ) ;
2014-02-21 21:02:23 +01:00
if ( g _IsNetworked && g _IsController )
{
2014-11-16 23:21:57 +01:00
var btCode = [ resumeGame , leaveGame ] ;
2014-04-20 22:51:48 +02:00
var message = translate ( "Are you sure you want to quit? Leaving will disconnect all other players." ) ;
2014-02-21 21:02:23 +01:00
}
2014-03-17 00:29:27 +01:00
else if ( g _IsNetworked && ! g _GameEnded && ! g _IsObserver )
2014-02-21 21:02:23 +01:00
{
2014-11-16 23:21:57 +01:00
var btCode = [ resumeGame , networkReturnQuestion ] ;
2014-04-20 22:51:48 +02:00
var message = translate ( "Are you sure you want to quit?" ) ;
2014-02-21 21:02:23 +01:00
}
else
{
2014-11-16 23:21:57 +01:00
var btCode = [ resumeGame , leaveGame ] ;
2014-04-20 22:51:48 +02:00
var message = translate ( "Are you sure you want to quit?" ) ;
2014-02-21 21:02:23 +01:00
}
2014-11-16 23:21:57 +01:00
messageBox ( 400 , 200 , message , translate ( "Confirmation" ) , 0 , [ translate ( "No" ) , translate ( "Yes" ) ] , btCode ) ;
2014-01-02 17:22:03 +01:00
}
2014-02-21 21:02:23 +01:00
function networkReturnQuestion ( )
{
2014-05-08 05:43:03 +02:00
var btCaptions = [ translate ( "I will return" ) , translate ( "I resign" ) ] ;
var btCode = [ leaveGame , resignGame ] ;
var btArgs = [ true , false ] ;
2014-04-20 22:51:48 +02:00
messageBox ( 400 , 200 , translate ( "Do you want to resign or will you return soon?" ) , translate ( "Confirmation" ) , 0 , btCaptions , btCode , btArgs ) ;
2014-02-21 21:02:23 +01:00
}
2014-01-04 11:14:53 +01:00
2014-01-02 17:22:03 +01:00
function openDeleteDialog ( selection )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
2014-01-04 11:14:53 +01:00
var deleteSelectedEntities = function ( selectionArg )
2014-01-02 17:22:03 +01:00
{
2014-01-04 11:14:53 +01:00
Engine . PostNetworkCommand ( { "type" : "delete-entities" , "entities" : selectionArg } ) ;
2014-01-02 17:22:03 +01:00
} ;
2014-05-08 05:43:03 +02:00
var btCaptions = [ translate ( "Yes" ) , translate ( "No" ) ] ;
var btCode = [ deleteSelectedEntities , resumeGame ] ;
2014-05-08 10:21:20 +02:00
var btArgs = [ selection , null ] ;
2014-01-02 17:22:03 +01:00
2014-05-08 10:21:20 +02:00
messageBox ( 400 , 200 , translate ( "Destroy everything currently selected?" ) , translate ( "Delete" ) , 0 , btCaptions , btCode , btArgs ) ;
2014-01-02 17:22:03 +01:00
}
// Menu functions
// =============================================================================
function openSave ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
pauseGame ( ) ;
2014-01-04 11:14:53 +01:00
var savedGameData = getSavedGameData ( ) ;
2014-04-30 07:31:44 +02:00
Engine . PushGuiPage ( "page_savegame.xml" , { "savedGameData" : savedGameData , "callback" : "resumeGame" } ) ;
2014-01-02 17:22:03 +01:00
}
2014-10-27 02:32:11 +01:00
function openOptions ( )
2014-01-02 17:22:03 +01:00
{
2014-01-02 17:30:24 +01:00
pauseGame ( ) ;
2014-04-30 07:31:44 +02:00
Engine . PushGuiPage ( "page_options.xml" , { "callback" : "resumeGame" } ) ;
2014-01-02 17:22:03 +01:00
}
function openChat ( )
{
2015-01-21 22:18:55 +01:00
updateTeamCheckbox ( false ) ;
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "chatInput" ) . focus ( ) ; // Grant focus to the input area
Engine . GetGUIObjectByName ( "chatDialogPanel" ) . hidden = false ;
2014-01-02 17:22:03 +01:00
}
function closeChat ( )
{
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "chatInput" ) . caption = "" ; // Clear chat input
Engine . GetGUIObjectByName ( "chatInput" ) . blur ( ) ; // Remove focus
Engine . GetGUIObjectByName ( "chatDialogPanel" ) . hidden = true ;
2014-01-02 17:22:03 +01:00
}
2015-01-21 22:18:55 +01:00
function updateTeamCheckbox ( check )
{
Engine . GetGUIObjectByName ( "toggleTeamChatLabel" ) . hidden = g _IsObserver ;
let toggleTeamChat = Engine . GetGUIObjectByName ( "toggleTeamChat" ) ;
toggleTeamChat . hidden = g _IsObserver ;
toggleTeamChat . checked = ! g _IsObserver && check ;
}
2014-01-02 17:22:03 +01:00
function toggleChatWindow ( teamChat )
{
2014-01-04 11:14:53 +01:00
var chatWindow = Engine . GetGUIObjectByName ( "chatDialogPanel" ) ;
var chatInput = Engine . GetGUIObjectByName ( "chatInput" ) ;
2014-01-02 17:22:03 +01:00
if ( chatWindow . hidden )
chatInput . focus ( ) ; // Grant focus to the input area
else
{
if ( chatInput . caption . length )
{
submitChatInput ( ) ;
return ;
}
chatInput . caption = "" ; // Clear chat input
}
2015-01-21 22:18:55 +01:00
updateTeamCheckbox ( teamChat ) ;
2014-01-02 17:22:03 +01:00
chatWindow . hidden = ! chatWindow . hidden ;
}
function setDiplomacy ( data )
{
Engine . PostNetworkCommand ( { "type" : "diplomacy" , "to" : data . to , "player" : data . player } ) ;
}
function tributeResource ( data )
{
Engine . PostNetworkCommand ( { "type" : "tribute" , "player" : data . player , "amounts" : data . amounts } ) ;
}
function openDiplomacy ( )
{
if ( isTradeOpen )
closeTrade ( ) ;
isDiplomacyOpen = true ;
2014-11-13 02:26:36 +01:00
let we = Engine . GetPlayerID ( ) ;
2014-01-02 17:22:03 +01:00
// Get offset for one line
2014-11-13 02:26:36 +01:00
let onesize = Engine . GetGUIObjectByName ( "diplomacyPlayer[0]" ) . size ;
let rowsize = onesize . bottom - onesize . top ;
2014-01-02 17:22:03 +01:00
// We don't include gaia
2015-02-08 18:37:15 +01:00
for ( let i = 1 ; i < g _Players . length ; ++ i )
2014-01-02 17:22:03 +01:00
{
// Apply offset
2014-11-13 02:26:36 +01:00
let row = Engine . GetGUIObjectByName ( "diplomacyPlayer[" + ( i - 1 ) + "]" ) ;
let size = row . size ;
2014-01-02 17:22:03 +01:00
size . top = rowsize * ( i - 1 ) ;
size . bottom = rowsize * i ;
row . size = size ;
2015-03-16 00:59:48 +01:00
// Set background color
2015-02-08 18:37:15 +01:00
let playerColor = rgbToGuiColor ( g _Players [ i ] . color ) ;
2015-03-16 00:59:48 +01:00
row . sprite = "color: " + playerColor + " 32" ;
2014-01-02 17:22:03 +01:00
2015-02-08 18:37:15 +01:00
Engine . GetGUIObjectByName ( "diplomacyPlayerName[" + ( i - 1 ) + "]" ) . caption = "[color=\"" + playerColor + "\"]" + g _Players [ i ] . name + "[/color]" ;
Engine . GetGUIObjectByName ( "diplomacyPlayerCiv[" + ( i - 1 ) + "]" ) . caption = g _CivData [ g _Players [ i ] . civ ] . Name ;
2014-01-02 17:22:03 +01:00
2015-02-08 18:37:15 +01:00
Engine . GetGUIObjectByName ( "diplomacyPlayerTeam[" + ( i - 1 ) + "]" ) . caption = ( g _Players [ i ] . team < 0 ) ? translateWithContext ( "team" , "None" ) : g _Players [ i ] . team + 1 ;
2014-01-02 17:22:03 +01:00
if ( i != we )
2015-02-08 18:37:15 +01:00
Engine . GetGUIObjectByName ( "diplomacyPlayerTheirs[" + ( i - 1 ) + "]" ) . caption = ( g _Players [ i ] . isAlly [ we ] ? translate ( "Ally" ) : ( g _Players [ i ] . isNeutral [ we ] ? translate ( "Neutral" ) : translate ( "Enemy" ) ) ) ;
2014-01-02 17:22:03 +01:00
// Don't display the options for ourself, or if we or the other player aren't active anymore
2015-02-08 18:37:15 +01:00
if ( i == we || g _Players [ we ] . state != "active" || g _Players [ i ] . state != "active" )
2014-01-02 17:22:03 +01:00
{
// Hide the unused/unselectable options
2014-11-13 02:26:36 +01:00
for each ( let a in [ "TributeFood" , "TributeWood" , "TributeStone" , "TributeMetal" , "Ally" , "Neutral" , "Enemy" ] )
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "diplomacyPlayer" + a + "[" + ( i - 1 ) + "]" ) . hidden = true ;
2015-04-11 20:46:05 +02:00
Engine . GetGUIObjectByName ( "diplomacyAttackRequest[" + ( i - 1 ) + "]" ) . hidden = true ;
2014-01-02 17:22:03 +01:00
continue ;
}
// Tribute
2014-11-13 02:26:36 +01:00
for each ( let resource in [ "food" , "wood" , "stone" , "metal" ] )
2014-01-02 17:22:03 +01:00
{
2014-11-13 02:26:36 +01:00
let button = Engine . GetGUIObjectByName ( "diplomacyPlayerTribute" + resource [ 0 ] . toUpperCase ( ) + resource . substring ( 1 ) + "[" + ( i - 1 ) + "]" ) ;
2014-01-02 17:22:03 +01:00
button . onpress = ( function ( player , resource , button ) {
// Implement something like how unit batch training works. Shift+click to send 500, shift+click+click to send 1000, etc.
// Also see input.js (searching for "INPUT_MASSTRIBUTING" should get all the relevant parts).
2014-11-13 02:26:36 +01:00
let multiplier = 1 ;
2014-01-02 17:22:03 +01:00
return function ( ) {
2014-11-13 02:26:36 +01:00
let isBatchTrainPressed = Engine . HotkeyIsPressed ( "session.masstribute" ) ;
2014-01-02 17:22:03 +01:00
if ( isBatchTrainPressed )
{
inputState = INPUT _MASSTRIBUTING ;
multiplier += multiplier == 1 ? 4 : 5 ;
}
2014-11-13 02:26:36 +01:00
let amounts = {
2014-01-02 17:22:03 +01:00
"food" : ( resource == "food" ? 100 : 0 ) * multiplier ,
"wood" : ( resource == "wood" ? 100 : 0 ) * multiplier ,
"stone" : ( resource == "stone" ? 100 : 0 ) * multiplier ,
"metal" : ( resource == "metal" ? 100 : 0 ) * multiplier ,
} ;
2015-02-08 18:37:15 +01:00
button . tooltip = formatTributeTooltip ( g _Players [ player ] , resource , amounts [ resource ] ) ;
2014-01-02 17:22:03 +01:00
// This is in a closure so that we have access to `player`, `amounts`, and `multiplier` without some
// evil global variable hackery.
flushTributing = function ( ) {
tributeResource ( { "player" : player , "amounts" : amounts } ) ;
multiplier = 1 ;
2015-02-08 18:37:15 +01:00
button . tooltip = formatTributeTooltip ( g _Players [ player ] , resource , 100 ) ;
2014-01-02 17:22:03 +01:00
} ;
if ( ! isBatchTrainPressed )
flushTributing ( ) ;
} ;
} ) ( i , resource , button ) ;
button . hidden = false ;
2015-02-08 18:37:15 +01:00
button . tooltip = formatTributeTooltip ( g _Players [ i ] , resource , 100 ) ;
2014-01-02 17:22:03 +01:00
}
2015-04-11 20:46:05 +02:00
// Attack Request
let button = Engine . GetGUIObjectByName ( "diplomacyAttackRequest[" + ( i - 1 ) + "]" ) ;
button . hidden = ! ( g _Players [ i ] . isEnemy [ we ] ) ;
button . tooltip = translate ( "request for your allies to attack this enemy" ) ;
button . onpress = ( function ( i , we ) { return function ( ) {
Engine . PostNetworkCommand ( { "type" : "attack-request" , "source" : we , "target" : i } ) ;
} } ) ( i , we ) ;
2014-01-02 17:22:03 +01:00
// Skip our own teams on teams locked
2015-02-08 18:37:15 +01:00
if ( g _Players [ we ] . teamsLocked && g _Players [ we ] . team != - 1 && g _Players [ we ] . team == g _Players [ i ] . team )
2014-01-02 17:22:03 +01:00
continue ;
// Diplomacy settings
// Set up the buttons
2014-11-13 02:26:36 +01:00
for each ( let setting in [ "Ally" , "Neutral" , "Enemy" ] )
2014-01-02 17:22:03 +01:00
{
2014-11-13 02:26:36 +01:00
let button = Engine . GetGUIObjectByName ( "diplomacyPlayer" + setting + "[" + ( i - 1 ) + "]" ) ;
2014-01-02 17:22:03 +01:00
2015-02-08 18:37:15 +01:00
button . caption = g _Players [ we ] [ "is" + setting ] [ i ] ? translate ( "x" ) : "" ;
2014-11-13 02:26:36 +01:00
button . onpress = ( function ( e ) { return function ( ) { setDiplomacy ( e ) } } ) ( { "player" : i , "to" : setting . toLowerCase ( ) } ) ;
2014-01-02 17:22:03 +01:00
button . hidden = false ;
}
}
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "diplomacyDialogPanel" ) . hidden = false ;
2014-01-02 17:22:03 +01:00
}
function closeDiplomacy ( )
{
isDiplomacyOpen = false ;
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "diplomacyDialogPanel" ) . hidden = true ;
2014-01-02 17:22:03 +01:00
}
function toggleDiplomacy ( )
{
if ( isDiplomacyOpen )
closeDiplomacy ( ) ;
else
openDiplomacy ( ) ;
2014-04-20 22:51:48 +02:00
}
2014-01-02 17:22:03 +01:00
function openTrade ( )
{
if ( isDiplomacyOpen )
closeDiplomacy ( ) ;
isTradeOpen = true ;
var updateButtons = function ( )
{
for ( var res in button )
{
button [ res ] . label . caption = proba [ res ] + "%" ;
if ( res == selec )
{
button [ res ] . sel . hidden = false ;
button [ res ] . up . hidden = true ;
button [ res ] . dn . hidden = true ;
}
else
{
button [ res ] . sel . hidden = true ;
button [ res ] . up . hidden = ( proba [ res ] == 100 || proba [ selec ] == 0 ) ;
button [ res ] . dn . hidden = ( proba [ res ] == 0 || proba [ selec ] == 100 ) ;
}
}
}
var proba = Engine . GuiInterfaceCall ( "GetTradingGoods" ) ;
var button = { } ;
var selec = RESOURCES [ 0 ] ;
for ( var i = 0 ; i < RESOURCES . length ; ++ i )
{
2014-01-04 11:14:53 +01:00
var buttonResource = Engine . GetGUIObjectByName ( "tradeResource[" + i + "]" ) ;
2014-01-02 17:22:03 +01:00
if ( i > 0 )
{
2014-01-04 11:14:53 +01:00
var size = Engine . GetGUIObjectByName ( "tradeResource[" + ( i - 1 ) + "]" ) . size ;
2014-01-02 17:22:03 +01:00
var width = size . right - size . left ;
size . left += width ;
size . right += width ;
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "tradeResource[" + i + "]" ) . size = size ;
2014-01-02 17:22:03 +01:00
}
var resource = RESOURCES [ i ] ;
proba [ resource ] = ( proba [ resource ] ? proba [ resource ] : 0 ) ;
2014-01-04 11:14:53 +01:00
var buttonResource = Engine . GetGUIObjectByName ( "tradeResourceButton[" + i + "]" ) ;
var icon = Engine . GetGUIObjectByName ( "tradeResourceIcon[" + i + "]" ) ;
2014-01-02 17:22:03 +01:00
icon . sprite = "stretched:session/icons/resources/" + resource + ".png" ;
2014-01-04 11:14:53 +01:00
var label = Engine . GetGUIObjectByName ( "tradeResourceText[" + i + "]" ) ;
var buttonUp = Engine . GetGUIObjectByName ( "tradeArrowUp[" + i + "]" ) ;
var buttonDn = Engine . GetGUIObjectByName ( "tradeArrowDn[" + i + "]" ) ;
var iconSel = Engine . GetGUIObjectByName ( "tradeResourceSelection[" + i + "]" ) ;
2014-05-24 18:23:11 +02:00
button [ resource ] = { "up" : buttonUp , "dn" : buttonDn , "label" : label , "sel" : iconSel } ;
2014-01-02 17:22:03 +01:00
buttonResource . onpress = ( function ( resource ) {
return function ( ) {
2014-05-24 17:37:19 +02:00
if ( Engine . HotkeyIsPressed ( "session.fulltradeswap" ) )
{
for ( var ress of RESOURCES )
proba [ ress ] = 0 ;
proba [ resource ] = 100 ;
Engine . PostNetworkCommand ( { "type" : "set-trading-goods" , "tradingGoods" : proba } ) ;
}
2014-01-02 17:22:03 +01:00
selec = resource ;
updateButtons ( ) ;
}
} ) ( resource ) ;
buttonUp . onpress = ( function ( resource ) {
return function ( ) {
proba [ resource ] += Math . min ( STEP , proba [ selec ] ) ;
proba [ selec ] -= Math . min ( STEP , proba [ selec ] ) ;
Engine . PostNetworkCommand ( { "type" : "set-trading-goods" , "tradingGoods" : proba } ) ;
updateButtons ( ) ;
}
} ) ( resource ) ;
buttonDn . onpress = ( function ( resource ) {
return function ( ) {
proba [ selec ] += Math . min ( STEP , proba [ resource ] ) ;
proba [ resource ] -= Math . min ( STEP , proba [ resource ] ) ;
Engine . PostNetworkCommand ( { "type" : "set-trading-goods" , "tradingGoods" : proba } ) ;
updateButtons ( ) ;
}
} ) ( resource ) ;
}
updateButtons ( ) ;
var traderNumber = Engine . GuiInterfaceCall ( "GetTraderNumber" ) ;
var caption = "" ;
if ( traderNumber . landTrader . total == 0 )
2014-04-20 22:51:48 +02:00
caption = translate ( "There are no land traders." ) ;
2014-01-02 17:22:03 +01:00
else
{
2014-04-20 22:51:48 +02:00
var inactive = traderNumber . landTrader . total - traderNumber . landTrader . trading - traderNumber . landTrader . garrisoned ;
var inactiveString = "" ;
if ( inactive > 0 )
inactiveString = "[color=\"orange\"]" + sprintf ( translatePlural ( "%(numberOfLandTraders)s inactive" , "%(numberOfLandTraders)s inactive" , inactive ) , { numberOfLandTraders : inactive } ) + "[/color]" ;
2014-01-02 17:22:03 +01:00
if ( traderNumber . landTrader . trading > 0 )
{
2014-04-20 22:51:48 +02:00
var openingTradingString = sprintf ( translatePlural ( "There is %(numberTrading)s land trader trading" , "There are %(numberTrading)s land traders trading" , traderNumber . landTrader . trading ) , { numberTrading : traderNumber . landTrader . trading } ) ;
if ( traderNumber . landTrader . garrisoned > 0 )
{
var garrisonedString = sprintf ( translatePlural ( "%(numberGarrisoned)s garrisoned on a trading merchant ship" , "%(numberGarrisoned)s garrisoned on a trading merchant ship" , traderNumber . landTrader . garrisoned ) , { numberGarrisoned : traderNumber . landTrader . garrisoned } ) ;
if ( inactive > 0 )
{
caption = sprintf ( translate ( "%(openingTradingString)s, %(garrisonedString)s, and %(inactiveString)s." ) , {
openingTradingString : openingTradingString ,
garrisonedString : garrisonedString ,
inactiveString : inactiveString
} ) ;
}
else
{
caption = sprintf ( translate ( "%(openingTradingString)s, and %(garrisonedString)s." ) , {
openingTradingString : openingTradingString ,
garrisonedString : garrisonedString
} ) ;
}
}
else
{
if ( inactive > 0 )
{
caption = sprintf ( translate ( "%(openingTradingString)s, and %(inactiveString)s." ) , {
openingTradingString : openingTradingString ,
inactiveString : inactiveString
} ) ;
}
else
{
caption = sprintf ( translate ( "%(openingTradingString)s." ) , {
openingTradingString : openingTradingString ,
} ) ;
}
}
2014-01-02 17:22:03 +01:00
}
2014-04-20 22:51:48 +02:00
else
2014-01-02 17:22:03 +01:00
{
2014-04-20 22:51:48 +02:00
if ( traderNumber . landTrader . garrisoned > 0 )
{
var openingGarrisonedString = sprintf ( translatePlural ( "There is %(numberGarrisoned)s land trader garrisoned on a trading merchant ship" , "There are %(numberGarrisoned)s land traders garrisoned on a trading merchant ship" , traderNumber . landTrader . garrisoned ) , { numberGarrisoned : traderNumber . landTrader . garrisoned } ) ;
if ( inactive > 0 )
{
caption = sprintf ( translate ( "%(openingGarrisonedString)s, and %(inactiveString)s." ) , {
openingGarrisonedString : openingGarrisonedString ,
inactiveString : inactiveString
} ) ;
}
else
{
caption = sprintf ( translate ( "%(openingGarrisonedString)s." ) , {
openingGarrisonedString : openingGarrisonedString
} ) ;
}
}
else
{
if ( inactive > 0 )
{
inactiveString = "[color=\"orange\"]" + sprintf ( translatePlural ( "%(numberOfLandTraders)s land trader inactive" , "%(numberOfLandTraders)s land traders inactive" , inactive ) , { numberOfLandTraders : inactive } ) + "[/color]" ;
caption = sprintf ( translatePlural ( "There is %(inactiveString)s." , "There are %(inactiveString)s." , inactive ) , {
inactiveString : inactiveString
} ) ;
}
// The “else” here is already handled by “if (traderNumber.landTrader.total == 0)” above.
}
2014-01-02 17:22:03 +01:00
}
}
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "landTraders" ) . caption = caption ;
2014-01-02 17:22:03 +01:00
caption = "" ;
if ( traderNumber . shipTrader . total == 0 )
2014-04-20 22:51:48 +02:00
caption = translate ( "There are no merchant ships." ) ;
2014-01-02 17:22:03 +01:00
else
{
2014-04-20 22:51:48 +02:00
var inactive = traderNumber . shipTrader . total - traderNumber . shipTrader . trading ;
var inactiveString = "" ;
if ( inactive > 0 )
inactiveString = "[color=\"orange\"]" + sprintf ( translatePlural ( "%(numberOfShipTraders)s inactive" , "%(numberOfShipTraders)s inactive" , inactive ) , { numberOfShipTraders : inactive } ) + "[/color]" ;
2014-01-02 17:22:03 +01:00
if ( traderNumber . shipTrader . trading > 0 )
{
2014-04-20 22:51:48 +02:00
var openingTradingString = sprintf ( translatePlural ( "There is %(numberTrading)s merchant ship trading" , "There are %(numberTrading)s merchant ships trading" , traderNumber . shipTrader . trading ) , { numberTrading : traderNumber . shipTrader . trading } ) ;
if ( inactive > 0 )
{
caption = sprintf ( translate ( "%(openingTradingString)s, and %(inactiveString)s." ) , {
openingTradingString : openingTradingString ,
inactiveString : inactiveString
} ) ;
}
else
{
caption = sprintf ( translate ( "%(openingTradingString)s." ) , {
openingTradingString : openingTradingString ,
} ) ;
}
}
else
{
if ( inactive > 0 )
{
inactiveString = "[color=\"orange\"]" + sprintf ( translatePlural ( "%(numberOfShipTraders)s merchant ship inactive" , "%(numberOfShipTraders)s merchant ships inactive" , inactive ) , { numberOfShipTraders : inactive } ) + "[/color]" ;
caption = sprintf ( translatePlural ( "There is %(inactiveString)s." , "There are %(inactiveString)s." , inactive ) , {
inactiveString : inactiveString
} ) ;
}
// The “else” here is already handled by “if (traderNumber.shipTrader.total == 0)” above.
2014-01-02 17:22:03 +01:00
}
}
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "shipTraders" ) . caption = caption ;
2014-01-02 17:22:03 +01:00
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "tradeDialogPanel" ) . hidden = false ;
2014-01-02 17:22:03 +01:00
}
function closeTrade ( )
{
isTradeOpen = false ;
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "tradeDialogPanel" ) . hidden = true ;
2014-01-02 17:22:03 +01:00
}
function toggleTrade ( )
{
if ( isTradeOpen )
closeTrade ( ) ;
else
openTrade ( ) ;
2014-04-20 22:51:48 +02:00
}
2014-01-02 17:22:03 +01:00
function toggleGameSpeed ( )
{
2014-01-04 11:14:53 +01:00
var gameSpeed = Engine . GetGUIObjectByName ( "gameSpeed" ) ;
2014-01-02 17:22:03 +01:00
gameSpeed . hidden = ! gameSpeed . hidden ;
}
2014-01-02 17:30:24 +01:00
/ * *
* Pause the game in single player mode .
* /
2014-01-02 17:22:03 +01:00
function pauseGame ( )
{
2014-01-02 17:30:24 +01:00
if ( g _IsNetworked )
return ;
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "pauseButtonText" ) . caption = RESUME ;
Engine . GetGUIObjectByName ( "pauseOverlay" ) . hidden = false ;
Engine . SetPaused ( true ) ;
2014-01-02 17:22:03 +01:00
}
function resumeGame ( )
{
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "pauseButtonText" ) . caption = PAUSE ;
Engine . GetGUIObjectByName ( "pauseOverlay" ) . hidden = true ;
Engine . SetPaused ( false ) ;
2014-01-02 17:22:03 +01:00
}
function togglePause ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
2014-01-04 11:14:53 +01:00
var pauseOverlay = Engine . GetGUIObjectByName ( "pauseOverlay" ) ;
2014-01-02 17:22:03 +01:00
if ( pauseOverlay . hidden )
{
2014-01-04 11:14:53 +01:00
Engine . GetGUIObjectByName ( "pauseButtonText" ) . caption = RESUME ;
Engine . SetPaused ( true ) ;
2014-01-02 17:22:03 +01:00
}
else
{
2014-01-04 11:14:53 +01:00
Engine . SetPaused ( false ) ;
Engine . GetGUIObjectByName ( "pauseButtonText" ) . caption = PAUSE ;
2014-01-02 17:22:03 +01:00
}
pauseOverlay . hidden = ! pauseOverlay . hidden ;
}
function openManual ( )
{
closeMenu ( ) ;
closeOpenDialogs ( ) ;
pauseGame ( ) ;
2014-05-03 10:53:06 +02:00
Engine . PushGuiPage ( "page_manual.xml" , { "page" : "manual/intro" , "title" : translate ( "Manual" ) , "url" : "http://trac.wildfiregames.com/wiki/0adManual" , "callback" : "resumeGame" } ) ;
2014-01-02 17:22:03 +01:00
}
function toggleDeveloperOverlay ( )
{
2014-05-23 02:18:16 +02:00
// The developer overlay is disabled in ranked games
2014-01-02 17:22:03 +01:00
if ( Engine . HasXmppClient ( ) && Engine . IsRankedGame ( ) )
return ;
2014-01-04 11:14:53 +01:00
var devCommands = Engine . GetGUIObjectByName ( "devCommands" ) ;
2014-04-20 22:51:48 +02:00
if ( devCommands . hidden )
submitChatDirectly ( translate ( "The Developer Overlay was opened." ) ) ;
else
submitChatDirectly ( translate ( "The Developer Overlay was closed." ) ) ;
2014-05-23 02:18:16 +02:00
// Toggle the overlay
2014-01-02 17:22:03 +01:00
devCommands . hidden = ! devCommands . hidden ;
}
function closeOpenDialogs ( )
{
closeMenu ( ) ;
closeChat ( ) ;
closeDiplomacy ( ) ;
closeTrade ( ) ;
}
function formatTributeTooltip ( player , resource , amount )
{
2014-11-13 02:26:36 +01:00
let playerColor = rgbToGuiColor ( player . color ) ;
2014-04-20 22:51:48 +02:00
return sprintf ( translate ( "Tribute %(resourceAmount)s %(resourceType)s to %(playerName)s. Shift-click to tribute %(greaterAmount)s." ) , {
resourceAmount : amount ,
2014-04-24 07:48:23 +02:00
resourceType : getLocalizedResourceName ( resource , "withinSentence" ) ,
2014-04-20 22:51:48 +02:00
playerName : "[color=\"" + playerColor + "\"]" + player . name + "[/color]" ,
greaterAmount : ( amount < 500 ? 500 : amount + 500 )
} ) ;
2014-01-02 17:22:03 +01:00
}