Ticket #3994: t3994_gamesetup_GUI_rewrite_v2.patch
File t3994_gamesetup_GUI_rewrite_v2.patch, 41.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/gamesetup/gamesetup.js
1 1 const g_MatchSettings_SP = "config/matchsettings.json"; 2 2 const g_MatchSettings_MP = "config/matchsettings.mp.json"; 3 3 4 const g_PlayerArray = Array(g_MaxPlayers).fill(0).map((v, i) => i + 1); // 1, 2, ..., MaxPlayers 4 5 const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire); 5 6 const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly)); 6 7 const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); 7 8 const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); 8 9 const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); … … const g_FormatChatMessage = { 57 58 "username": user 58 59 }), 59 60 "clientlist": (msg, user) => getUsernameList() 60 61 }; 61 62 62 /** 63 * The dropdownlist items will appear in the order they are added. 64 */ 65 const g_MapFilters = [ 63 const g_MapFilters = prepareForDropdown([ 66 64 { 67 65 "id": "default", 68 66 "name": translate("Default"), 69 "filter": mapKeywords => mapKeywords.every(keyword => ["naval", "demo", "hidden"].indexOf(keyword) == -1) 67 "filter": mapKeywords => mapKeywords.every(keyword => ["naval", "demo", "hidden"].indexOf(keyword) == -1), 68 "Default": true 70 69 }, 71 70 { 72 71 "id": "naval", 73 72 "name": translate("Naval Maps"), 74 73 "filter": mapKeywords => mapKeywords.indexOf("naval") != -1 … … const g_MapFilters = [ 86 85 { 87 86 "id": "all", 88 87 "name": translate("All Maps"), 89 88 "filter": mapKeywords => true 90 89 } 91 ] ;90 ]); 92 91 93 92 /** 94 93 * Used for generating the botnames. 95 94 */ 96 95 const g_RomanNumbers = [undefined, "I", "II", "III", "IV", "V", "VI", "VII", "VIII"]; … … var g_DefaultPlayerData = []; 198 197 var g_GameAttributes = { "settings": {} }; 199 198 200 199 var g_ChatMessages = []; 201 200 202 201 /** 203 * Cache containing the mapsettings for scenario/skirmish maps. Just-in-time loading. 202 * Filename and translated title of all maps, given the currently selected 203 * maptype and filter. Sorted by title, shown in the dropdown. 204 */ 205 var g_MapList = []; 206 207 /** 208 * Cache containing the mapsettings. Just-in-time loading. 204 209 */ 205 210 var g_MapData = {}; 206 211 207 212 /** 208 213 * Wait one tick before initializing the GUI objects and … … var g_LastGameStanza; 219 224 * Remembers if the current player viewed the AI settings of some playerslot. 220 225 */ 221 226 var g_LastViewedAIPlayer = -1; 222 227 223 228 /** 229 * Contains the logic of all multiple-choice gamesettings. 230 * 231 * Hidden - if so, both label and dropdown won't be visible. 232 * Enabled - Only the label will be shown if it's disabled. 233 * Default - returns the index of the default value (not the value itself). 234 * 235 * NOTICE: The first three elements need to be initialized first. 236 * If the map is changed, missing values are supplemented with defaults. 237 */ 238 const g_Dropdowns = g_Settings && { 239 "mapType": { 240 "labels": () => g_MapTypes.Title, 241 "ids": () => g_MapTypes.Name, 242 "default": () => g_MapTypes.Default, 243 "defined": () => g_GameAttributes.mapType !== undefined, 244 "get": () => g_GameAttributes.mapType, 245 "select": idx => { 246 247 g_MapData = {}; 248 249 g_GameAttributes.mapType = g_MapTypes.Name[idx]; 250 g_GameAttributes.mapPath = g_MapPath[g_GameAttributes.mapType]; 251 delete g_GameAttributes.map; 252 253 if (g_GameAttributes.mapType != "scenario") 254 g_GameAttributes.settings = { 255 "PlayerData": g_DefaultPlayerData.slice(0, 4) 256 }; 257 258 reloadMapList(); 259 supplementDefaults(); 260 } 261 }, 262 "mapFilter": { 263 "labels": () => g_MapFilters.name, 264 "ids": () => g_MapFilters.id, 265 "default": () => g_MapFilters.Default, 266 "defined": () => g_GameAttributes.mapFilter !== undefined, 267 "get": () => g_GameAttributes.mapFilter, 268 "select": idx => { 269 g_GameAttributes.mapFilter = g_MapFilters.id[idx]; 270 delete g_GameAttributes.map; 271 reloadMapList(); 272 supplementDefaults(); 273 } 274 }, 275 "mapSelection": { 276 "labels": () => g_MapList.name, 277 "ids": () => g_MapList.file, 278 "default": () => 0, 279 "defined": () => g_GameAttributes.map !== undefined, 280 "get": () => g_GameAttributes.map, 281 "select": idx => { 282 selectMap(g_MapList.file[idx]); 283 supplementDefaults(); 284 } 285 }, 286 "mapSize": { 287 "labels": () => g_MapSizes.LongName, 288 "ids": () => g_MapSizes.Tiles, 289 "default": () => g_MapSizes.Default, 290 "defined": () => g_GameAttributes.settings.Size !== undefined, 291 "get": () => g_GameAttributes.settings.Size, 292 "select": idx => { 293 g_GameAttributes.settings.Size = g_MapSizes.Tiles[idx]; 294 }, 295 "enabled": () => g_GameAttributes.mapType == "random" 296 }, 297 "numPlayers": { 298 "labels": () => g_PlayerArray, 299 "ids": () => g_PlayerArray, 300 "default": () => g_MaxPlayers - 1, 301 "defined": () => g_GameAttributes.settings.PlayerData !== undefined, 302 "get": () => g_GameAttributes.settings.PlayerData.length, 303 "select": idx => { 304 selectNumPlayers(idx + 1); 305 }, 306 "enabled": () => g_GameAttributes.mapType == "random" 307 }, 308 "populationCap": { 309 "labels": () => g_PopulationCapacities.Title, 310 "ids": () => g_PopulationCapacities.Population, 311 "default": () => g_PopulationCapacities.Default, 312 "defined": () => g_GameAttributes.settings.PopulationCap !== undefined, 313 "get": () => g_GameAttributes.settings.PopulationCap, 314 "select": idx => { 315 g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[idx]; 316 }, 317 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 318 }, 319 "startingResources": { 320 "labels": () => g_StartingResources.Title, 321 "ids": () => g_StartingResources.Resources, 322 "default": () => g_StartingResources.Default, 323 "defined": () => g_GameAttributes.settings.StartingResources !== undefined, 324 "get": () => g_GameAttributes.settings.StartingResources, 325 "select": idx => { 326 g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[idx]; 327 }, 328 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 329 }, 330 "ceasefire": { 331 "labels": () => g_Ceasefire.Title, 332 "ids": () => g_Ceasefire.Duration, 333 "default": () => g_Ceasefire.Default, 334 "defined": () => g_GameAttributes.settings.Ceasefire !== undefined, 335 "get": () => g_GameAttributes.settings.Ceasefire, 336 "select": idx => { 337 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[idx]; 338 }, 339 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 340 }, 341 "victoryCondition": { 342 "labels": () => g_VictoryConditions.Title, 343 "ids": () => g_VictoryConditions.Name, 344 "default": () => g_VictoryConditions.Default, 345 "defined": () => g_GameAttributes.settings.GameType !== undefined, 346 "get": () => g_GameAttributes.settings.GameType, 347 "select": idx => { 348 g_GameAttributes.settings.GameType = g_VictoryConditions.Name[idx]; 349 g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[idx]; 350 }, 351 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 352 }, 353 "wonderDuration": { 354 "labels": () => g_WonderDurations.Title, 355 "ids": () => g_WonderDurations.Duration, 356 "default": () => g_WonderDurations.Default, 357 "defined": () => g_GameAttributes.settings.WonderDuration !== undefined, 358 "get": () => g_GameAttributes.settings.WonderDuration, 359 "select": idx => { 360 g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[idx]; 361 }, 362 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 363 }, 364 "gameSpeed": { 365 "labels": () => g_GameSpeeds.Title, 366 "ids": () => g_GameSpeeds.Speed, 367 "default": () => g_GameSpeeds.Default, 368 "defined": () => g_GameAttributes.gameSpeed !== undefined, 369 "get": () => g_GameAttributes.gameSpeed, 370 "select": idx => { 371 g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[idx]; 372 } 373 } 374 }; 375 376 /** 377 * Contains the logic of all boolean gamesettings. 378 */ 379 const g_Checkboxes = { 380 "revealMap": { 381 "default": () => false, 382 "defined": () => g_GameAttributes.settings.RevealMap !== undefined, 383 "get": () => g_GameAttributes.settings.RevealMap, 384 "set": checked => { 385 g_GameAttributes.settings.RevealMap = checked; 386 }, 387 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 388 }, 389 "exploreMap": { 390 "default": () => false, 391 "defined": () => g_GameAttributes.settings.ExploreMap !== undefined, 392 "get": () => g_GameAttributes.settings.ExploreMap, 393 "set": checked => { 394 g_GameAttributes.settings.ExploreMap = checked; 395 }, 396 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 397 }, 398 "disableTreasures": { 399 "default": () => false, 400 "defined": () => g_GameAttributes.settings.DisableTreasures !== undefined, 401 "get": () => g_GameAttributes.settings.DisableTreasures, 402 "set": checked => { 403 g_GameAttributes.settings.DisableTreasures = checked; 404 }, 405 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 406 }, 407 "lockTeams": { 408 "default": () => Engine.HasXmppClient(), 409 "defined": () => g_GameAttributes.settings.LockTeams !== undefined, 410 "get": () => g_GameAttributes.settings.LockTeams, 411 "set": checked => { 412 g_GameAttributes.settings.LockTeams = checked; 413 }, 414 "enabled": () => ["random", "skirmish"].indexOf(g_GameAttributes.mapType) != -1 && 415 !g_GameAttributes.settings.RatingEnabled, 416 }, 417 "enableCheats": { 418 "default": () => !g_IsNetworked, 419 "hidden": () => !g_IsNetworked, 420 "defined": () => g_GameAttributes.settings.CheatsEnabled !== undefined, 421 "get": () => g_GameAttributes.settings.CheatsEnabled, 422 "set": checked => { 423 g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked || 424 checked && !g_GameAttributes.settings.RatingEnabled; 425 }, 426 "enabled": () => !g_GameAttributes.settings.RatingEnabled 427 }, 428 "enableRating": { 429 "default": () => Engine.HasXmppClient(), 430 "defined": () => g_GameAttributes.settings.RatingEnabled !== undefined, 431 "get": () => !!g_GameAttributes.settings.RatingEnabled, 432 "set": checked => { 433 g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient() ? checked : undefined; 434 Engine.SetRankedGame(!!g_GameAttributes.settings.RatingEnabled); 435 } 436 } 437 }; 438 439 /** 440 * GUI objects in the order they should appear in the more options window. 441 */ 442 const g_MoreOptions = [ 443 "optionGameSpeed", 444 "optionVictoryCondition", 445 "optionWonderDuration", 446 "optionPopulationCap", 447 "optionStartingResources", 448 "optionCeasefire", 449 "optionRevealMap", 450 "optionExploreMap", 451 "optionDisableTreasures", 452 "optionLockTeams", 453 "optionCheats", 454 "optionRating", 455 "hideMoreOptions" 456 ]; 457 458 /** 459 * The size each GUI object in the more options dialog should have. 460 */ 461 const g_MoreOptionsEntryHeight = 30; 462 463 /** 464 * For setting up some additional GUI objects. 465 */ 466 const g_MiscControls = { 467 "chatPanel": { 468 "hidden": () => !g_IsNetworked 469 }, 470 "optionCheats": { 471 "hidden": () => !g_IsNetworked 472 }, 473 "optionRating": { 474 "hidden": () => !Engine.HasXmppClient() 475 }, 476 "optionWonderDuration": { 477 "hidden": () => g_GameAttributes.settings.GameType != "wonder" 478 }, 479 "cheatWarningText": { 480 "hidden": () => !g_IsNetworked || !g_GameAttributes.settings.CheatsEnabled 481 }, 482 "mapSize": { 483 "hidden": () => g_GameAttributes.mapType != "random" || !g_IsController 484 }, 485 "mapSizeText": { 486 "hidden": () => g_GameAttributes.mapType != "random" || g_IsController 487 }, 488 "mapSizeDesc": { 489 "hidden": () => g_GameAttributes.mapType != "random" 490 }, 491 "cancelGame": { 492 "tooltip": () => Engine.HasXmppClient() ? 493 translate("Return to the lobby.") : 494 translate("Return to the main menu.") 495 } 496 }; 497 498 /** 224 499 * Initializes some globals without touching the GUI. 225 500 * 226 501 * @param {Object} attribs - context data sent by the lobby / mainmenu 227 502 */ 228 503 function init(attribs) … … function init(attribs) 255 530 g_DefaultPlayerData = g_Settings.PlayerDefaults; 256 531 g_DefaultPlayerData.shift(); 257 532 for (let i in g_DefaultPlayerData) 258 533 g_DefaultPlayerData[i].Civ = "random"; 259 534 535 supplementDefaults(); 536 260 537 setTimeout(displayGamestateNotifications, 1000); 261 538 } 262 539 263 540 /** 541 * Sets default values for all g_GameAttribute settings which don't have a value set. 542 */ 543 function supplementDefaults() 544 { 545 for (let dropdown in g_Dropdowns) 546 if (!g_Dropdowns[dropdown].defined()) 547 g_Dropdowns[dropdown].select(g_Dropdowns[dropdown]["default"]()); 548 549 for (let checkbox in g_Checkboxes) 550 if (!g_Checkboxes[checkbox].defined()) 551 g_Checkboxes[checkbox].set(g_Checkboxes[checkbox]["default"]()); 552 } 553 554 /** 264 555 * Called after the first tick. 265 556 */ 266 557 function initGUIObjects() 267 558 { 268 Engine.GetGUIObjectByName("cancelGame").tooltip = Engine.HasXmppClient() ? translate("Return to the lobby.") : translate("Return to the main menu."); 559 for (let dropdown in g_Dropdowns) 560 initDropdown(dropdown); 269 561 270 initCivNameList(); 271 initMapTypes(); 272 initMapFilters(); 562 for (let checkbox in g_Checkboxes) 563 initCheckbox(checkbox); 273 564 274 if (g_IsController) 275 { 276 // Unique ID to be used for identifying the same game reports for the lobby 277 g_GameAttributes.matchID = Engine.GetMatchID(); 278 g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked; 279 g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined; 280 281 initMapNameList(); 282 initNumberOfPlayers(); 283 initGameSpeed(); 284 initPopulationCaps(); 285 initStartingResources(); 286 initCeasefire(); 287 initWonderDurations(); 288 initVictoryConditions(); 289 initMapSizes(); 290 initRadioButtons(); 291 } 292 else 293 hideControls(); 294 295 initMultiplayerSettings(); 565 // TODO: move to g_DropdownArrays 566 initCivNameList(); 296 567 initPlayerAssignments(); 568 // TODO unify with dupe calls and make dependent of g_DropdownArrays 569 Engine.GetGUIObjectByName("startGame").enabled = !g_IsController; 297 570 298 571 resizeMoreOptionsWindow(); 299 572 300 573 if (g_IsNetworked) 301 574 Engine.GetGUIObjectByName("chatInput").focus(); … … function initGUIObjects() 307 580 warn("initGUIObjects() called while in GUI update"); 308 581 updateGameAttributes(); 309 582 } 310 583 } 311 584 312 function init MapTypes()585 function initDropdown(name) 313 586 { 314 let mapTypes = Engine.GetGUIObjectByName("mapType"); 315 mapTypes.list = g_MapTypes.Title; 316 mapTypes.list_data = g_MapTypes.Name; 317 mapTypes.onSelectionChange = function() { 318 if (this.selected != -1) 319 selectMapType(this.list_data[this.selected]); 587 let ctrl = Engine.GetGUIObjectByName(name); 588 ctrl.list = g_Dropdowns[name].labels(); 589 ctrl.list_data = g_Dropdowns[name].ids(); 590 ctrl.onSelectionChange = function() { 591 592 if (!g_IsController || 593 g_IsInGuiUpdate || 594 !ctrl.list_data[this.selected] || 595 g_Dropdowns[this.name].enabled && !g_Dropdowns[this.name].enabled() || 596 g_Dropdowns[this.name].hidden && g_Dropdowns[this.name].hidden()) 597 return; 598 599 g_Dropdowns[this.name].select(this.selected); 600 updateGameAttributes(); 320 601 }; 321 if (g_IsController)322 mapTypes.selected = g_MapTypes.Default;323 602 } 324 603 325 function init MapFilters()604 function initCheckbox(name) 326 605 { 327 let mapFilters = Engine.GetGUIObjectByName("mapFilter"); 328 mapFilters.list = g_MapFilters.map(mapFilter => mapFilter.name); 329 mapFilters.list_data = g_MapFilters.map(mapFilter => mapFilter.id); 330 mapFilters.onSelectionChange = function() { 331 if (this.selected != -1) 332 selectMapFilter(this.list_data[this.selected]); 606 let ctrl = Engine.GetGUIObjectByName(name); 607 ctrl.onPress = function() { 608 609 if (!g_IsController || 610 g_IsInGuiUpdate || 611 g_Checkboxes[this.name].enabled && !g_Checkboxes[this.name].enabled() || 612 g_Checkboxes[this.name].hidden && g_Checkboxes[this.name].hidden()) 613 return; 614 615 g_Checkboxes[this.name].set(this.checked); 616 updateGameAttributes(); 333 617 }; 334 if (g_IsController)335 mapFilters.selected = 0;336 g_GameAttributes.mapFilter = "default";337 618 } 338 619 339 620 /** 340 621 * Remove empty space in case of hidden options (like cheats, rating or wonder duration) 341 622 */ 342 623 function resizeMoreOptionsWindow() 343 624 { 344 const elementHeight = 30;345 const elements = [346 "optionGameSpeed",347 "optionVictoryCondition",348 "optionWonderDuration",349 "optionPopulationCap",350 "optionStartingResources",351 "optionCeasefire",352 "optionRevealMap",353 "optionExploreMap",354 "optionDisableTreasures",355 "optionLockTeams",356 "optionCheats",357 "optionRating",358 "hideMoreOptions"359 ];360 361 625 let yPos = undefined; 362 for (let element of elements)626 for (let element of g_MoreOptions) 363 627 { 364 628 let guiOption = Engine.GetGUIObjectByName(element); 365 629 let gSize = guiOption.size; 366 630 yPos = yPos || gSize.top; 367 631 368 632 if (guiOption.hidden) 369 633 continue; 370 634 371 635 gSize.top = yPos; 372 gSize.bottom = yPos + elementHeight - 2;636 gSize.bottom = yPos + g_MoreOptionsEntryHeight - 2; 373 637 guiOption.size = gSize; 374 638 375 yPos += elementHeight;639 yPos += g_MoreOptionsEntryHeight; 376 640 } 377 641 378 642 // Resize the vertically centered window containing the options 379 643 let moreOptions = Engine.GetGUIObjectByName("moreOptions"); 380 644 let mSize = moreOptions.size; 381 645 mSize.bottom = mSize.top + yPos + 20; 382 646 moreOptions.size = mSize; 383 647 } 384 648 385 function initNumberOfPlayers()386 {387 let playersArray = Array(g_MaxPlayers).fill(0).map((v, i) => i + 1); // 1, 2, ..., MaxPlayers388 let numPlayers = Engine.GetGUIObjectByName("numPlayers");389 numPlayers.list = playersArray;390 numPlayers.list_data = playersArray;391 numPlayers.onSelectionChange = function() {392 if (this.selected != -1)393 selectNumPlayers(this.list_data[this.selected]);394 };395 numPlayers.selected = g_MaxPlayers - 1;396 }397 398 function initGameSpeed()399 {400 let gameSpeed = Engine.GetGUIObjectByName("gameSpeed");401 gameSpeed.hidden = false;402 Engine.GetGUIObjectByName("gameSpeedText").hidden = true;403 gameSpeed.list = g_GameSpeeds.Title;404 gameSpeed.list_data = g_GameSpeeds.Speed;405 gameSpeed.onSelectionChange = function() {406 if (this.selected != -1)407 g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected];408 409 updateGameAttributes();410 };411 gameSpeed.selected = g_GameSpeeds.Default;412 }413 414 function initPopulationCaps()415 {416 let populationCaps = Engine.GetGUIObjectByName("populationCap");417 populationCaps.list = g_PopulationCapacities.Title;418 populationCaps.list_data = g_PopulationCapacities.Population;419 populationCaps.selected = g_PopulationCapacities.Default;420 populationCaps.onSelectionChange = function() {421 if (this.selected != -1)422 g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[this.selected];423 424 updateGameAttributes();425 };426 }427 428 function initStartingResources()429 {430 let startingResourcesL = Engine.GetGUIObjectByName("startingResources");431 startingResourcesL.list = g_StartingResources.Title;432 startingResourcesL.list_data = g_StartingResources.Resources;433 startingResourcesL.selected = g_StartingResources.Default;434 startingResourcesL.onSelectionChange = function() {435 if (this.selected != -1)436 g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[this.selected];437 438 updateGameAttributes();439 };440 }441 442 function initCeasefire()443 {444 let ceasefireL = Engine.GetGUIObjectByName("ceasefire");445 ceasefireL.list = g_Ceasefire.Title;446 ceasefireL.list_data = g_Ceasefire.Duration;447 ceasefireL.selected = g_Ceasefire.Default;448 ceasefireL.onSelectionChange = function() {449 if (this.selected != -1)450 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected];451 452 updateGameAttributes();453 };454 }455 456 function initVictoryConditions()457 {458 let victoryConditions = Engine.GetGUIObjectByName("victoryCondition");459 victoryConditions.list = g_VictoryConditions.Title;460 victoryConditions.list_data = g_VictoryConditions.Name;461 victoryConditions.onSelectionChange = function() {462 if (this.selected != -1)463 {464 g_GameAttributes.settings.GameType = g_VictoryConditions.Name[this.selected];465 g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[this.selected];466 }467 468 updateGameAttributes();469 };470 victoryConditions.selected = g_VictoryConditions.Default;471 }472 473 function initWonderDurations()474 {475 let wonderConditions = Engine.GetGUIObjectByName("wonderDuration");476 wonderConditions.list = g_WonderDurations.Title;477 wonderConditions.list_data = g_WonderDurations.Duration;478 wonderConditions.onSelectionChange = function()479 {480 if (this.selected != -1)481 g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected];482 483 updateGameAttributes();484 };485 wonderConditions.selected = g_WonderDurations.Default;486 }487 488 function initMapSizes()489 {490 let mapSize = Engine.GetGUIObjectByName("mapSize");491 mapSize.list = g_MapSizes.LongName;492 mapSize.list_data = g_MapSizes.Tiles;493 mapSize.onSelectionChange = function() {494 if (this.selected != -1)495 g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected];496 updateGameAttributes();497 };498 mapSize.selected = 0;499 }500 501 /**502 * Assign update-functions to all checkboxes.503 */504 function initRadioButtons()505 {506 let options = {507 "RevealMap": "revealMap",508 "ExploreMap": "exploreMap",509 "DisableTreasures": "disableTreasures",510 "LockTeams": "lockTeams",511 "CheatsEnabled": "enableCheats"512 };513 514 Object.keys(options).forEach(attribute => {515 Engine.GetGUIObjectByName(options[attribute]).onPress = function() {516 g_GameAttributes.settings[attribute] = this.checked;517 updateGameAttributes();518 };519 });520 521 Engine.GetGUIObjectByName("enableRating").onPress = function() {522 g_GameAttributes.settings.RatingEnabled = this.checked;523 Engine.SetRankedGame(this.checked);524 Engine.GetGUIObjectByName("enableCheats").enabled = !this.checked;525 Engine.GetGUIObjectByName("lockTeams").enabled = !this.checked;526 updateGameAttributes();527 };528 }529 530 /**531 * If we're a network client, hide the controls and show the text instead.532 */533 function hideControls()534 {535 for (let ctrl of ["mapType", "mapFilter", "mapSelection", "victoryCondition", "gameSpeed", "numPlayers"])536 hideControl(ctrl, ctrl + "Text");537 538 // TODO: Shouldn't players be able to choose their own assignment?539 for (let i = 0; i < g_MaxPlayers; ++i)540 {541 Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true;542 Engine.GetGUIObjectByName("playerCiv["+i+"]").hidden = true;543 Engine.GetGUIObjectByName("playerTeam["+i+"]").hidden = true;544 }545 546 Engine.GetGUIObjectByName("startGame").enabled = true;547 }548 549 649 /** 550 650 * Hides the GUI controls for clients and shows the read-only label instead. 551 651 * 552 652 * @param {string} control - name of the GUI object able to change a setting 553 653 * @param {string} label - name of the GUI object displaying a setting … … function hideControl(control, label, all 557 657 { 558 658 Engine.GetGUIObjectByName(control).hidden = !allowControl; 559 659 Engine.GetGUIObjectByName(label).hidden = allowControl; 560 660 } 561 661 562 /** 563 * Checks a boolean checkbox for the host and sets the text of the label for the client. 564 * 565 * @param {string} control - name of the GUI object able to change a setting 566 * @param {string} label - name of the GUI object displaying a setting 567 * @param {boolean} checked - Whether the setting is active / enabled. 568 */ 569 function setGUIBoolean(control, label, checked) 570 { 571 Engine.GetGUIObjectByName(control).checked = checked; 572 Engine.GetGUIObjectByName(label).caption = checked ? translate("Yes") : translate("No"); 573 } 574 575 /** 576 * Hide and set some elements depending on whether we play single- or multiplayer. 577 */ 578 function initMultiplayerSettings() 579 { 580 Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked; 581 Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked; 582 Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient(); 583 584 Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame(); 585 Engine.GetGUIObjectByName("lockTeams").enabled = !Engine.IsRankedGame(); 586 587 Engine.GetGUIObjectByName("enableCheats").checked = g_GameAttributes.settings.CheatsEnabled; 588 Engine.GetGUIObjectByName("enableRating").checked = !!g_GameAttributes.settings.RatingEnabled; 589 590 for (let ctrl of ["enableCheats", "enableRating"]) 591 hideControl(ctrl, ctrl + "Text"); 592 } 593 662 // TODO: move to g_DropdownArrays 594 663 /** 595 664 * Populate team-, color- and civ-dropdowns. 596 665 */ 597 666 function initPlayerAssignments() 598 667 { … … function initPlayerAssignments() 625 694 colorPicker.list_data = g_PlayerColors.map((color, index) => index); 626 695 colorPicker.selected = -1; 627 696 colorPicker.onSelectionChange = function() { selectPlayerColor(playerSlot, this.selected); }; 628 697 629 698 Engine.GetGUIObjectByName("playerCiv["+i+"]").onSelectionChange = function() { 630 if ( (this.selected != -1)&&(g_GameAttributes.mapType !== "scenario"))699 if (this.selected != -1 && g_GameAttributes.mapType !== "scenario") 631 700 g_GameAttributes.settings.PlayerData[playerSlot].Civ = this.list_data[this.selected]; 632 701 633 702 updateGameAttributes(); 634 703 }; 635 704 } … … function handlePlayerAssignmentMessage(m 775 844 function getMapDisplayName(map) 776 845 { 777 846 let mapData = loadMapData(map); 778 847 if (!mapData || !mapData.settings || !mapData.settings.Name) 779 848 { 780 log("Map data missing in scenario'" + map + "' - likely unsupported format");849 log("Map data missing in map '" + map + "' - likely unsupported format"); 781 850 return map; 782 851 } 783 852 784 853 return mapData.settings.Name; 785 854 } … … function getSetting(settings, defaults, 808 877 } 809 878 810 879 /** 811 880 * Initialize the dropdowns containing all selectable civs (including random). 812 881 */ 882 // TODO: move to g_DropdownArrays 813 883 function initCivNameList() 814 884 { 815 885 let civList = Object.keys(g_CivData).filter(civ => g_CivData[civ].SelectableInGameSetup).map(civ => ({ "name": g_CivData[civ].Name, "code": civ })).sort(sortNameIgnoreCase); 816 886 let civListNames = [g_RandomCiv].concat(civList.map(civ => civ.name)); 817 887 let civListCodes = ["random"].concat(civList.map(civ => civ.code)); … … function initCivNameList() 824 894 civ.selected = 0; 825 895 } 826 896 } 827 897 828 898 /** 829 * Initialize the dropdown containing all maps for the selected maptype and mapfilter.899 * Called when the maptype or mapfilter changed. 830 900 */ 831 function initMapNameList()901 function reloadMapList() 832 902 { 833 903 if (!g_MapPath[g_GameAttributes.mapType]) 834 904 { 835 error(" initMapNameList: Unexpected map type " + g_GameAttributes.mapType);905 error("loadMaps: Unexpected map type " + g_GameAttributes.mapType); 836 906 return; 837 907 } 838 908 839 let mapFiles = g_GameAttributes.mapType == "random" ? getJSONFileList(g_GameAttributes.mapPath) : getXMLFileList(g_GameAttributes.mapPath); 909 let mapFiles = g_GameAttributes.mapType == "random" ? 910 getJSONFileList(g_GameAttributes.mapPath) : 911 getXMLFileList(g_GameAttributes.mapPath); 840 912 841 // Apply map filter, if any defined842 // TODO: Should verify these are valid maps before adding to list843 913 let mapList = []; 914 915 if (g_GameAttributes.mapType == "random") 916 mapList.push({ 917 "file": "random", 918 "name": g_RandomMap 919 }); 920 921 // TODO: Should verify these are valid maps before adding to list 844 922 for (let mapFile of mapFiles) 845 923 { 846 924 let file = g_GameAttributes.mapPath + mapFile; 847 925 let mapData = loadMapData(file); 848 let mapFilter = g_MapFilters.find(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "all")); 849 850 if (!!mapData.settings && mapFilter && mapFilter.filter(mapData.settings.Keywords || [])) 851 mapList.push({ "name": getMapDisplayName(file), "file": file }); 852 } 853 854 translateObjectKeys(mapList, ["name"]); 855 mapList.sort(sortNameIgnoreCase); 926 let mapFilter = g_MapFilters.id.find(filter => filter == g_GameAttributes.mapFilter); 856 927 857 let mapListNames = mapList.map(map => map.name);858 let mapListFiles = mapList.map(map => map.file);928 if (!mapData.settings || mapFilter && !mapFilter.filter(mapData.settings.Keywords || [])) 929 continue; 859 930 860 // Scenario/skirmish maps have a fixed playercount 861 if (g_GameAttributes.mapType == "random") 862 { 863 mapListNames.unshift(g_RandomMap); 864 mapListFiles.unshift("random"); 931 mapList.push({ 932 "file": file, 933 "name": translate(getMapDisplayName(file)) 934 }); 865 935 } 866 936 867 let mapSelectionBox = Engine.GetGUIObjectByName("mapSelection"); 868 mapSelectionBox.list = mapListNames; 869 mapSelectionBox.list_data = mapListFiles; 870 mapSelectionBox.onSelectionChange = function() { 871 if (this.selected != -1) 872 selectMap(this.list_data[this.selected]); 873 }; 874 mapSelectionBox.selected = Math.max(0, mapListFiles.indexOf(g_GameAttributes.map || "")); 937 g_MapList = prepareForDropdown(mapList.sort(sortNameIgnoreCase)); 938 initDropdown("mapSelection"); 875 939 } 876 940 877 941 function loadMapData(name) 878 942 { 879 943 if (!name || !g_MapPath[g_GameAttributes.mapType]) … … function loadMapData(name) 881 945 882 946 if (name == "random") 883 947 return { "settings": { "Name": "", "Description": "" } }; 884 948 885 949 if (!g_MapData[name]) 886 g_MapData[name] = g_GameAttributes.mapType == "random" ? Engine.ReadJSONFile(name + ".json") : Engine.LoadMapSettings(name); 950 g_MapData[name] = 951 g_GameAttributes.mapType == "random" ? 952 Engine.ReadJSONFile(name + ".json") : 953 Engine.LoadMapSettings(name); 887 954 888 955 return g_MapData[name]; 889 956 } 890 957 891 958 /** … … function loadPersistMatchSettings() 908 975 909 976 let mapName = attrs.map || ""; 910 977 let mapSettings = attrs.settings; 911 978 912 979 g_GameAttributes = attrs; 913 g_GameAttributes.matchID = Engine.GetMatchID();914 mapSettings.Seed = Math.floor(Math.random() * 65536);915 mapSettings.AISeed = Math.floor(Math.random() * 65536);916 980 917 981 if (!g_IsNetworked) 918 982 mapSettings.CheatsEnabled = true; 919 983 920 984 // Replace unselectable civs with random civ … … function loadPersistMatchSettings() 937 1001 938 1002 if (mapSettings.PlayerData) 939 1003 sanitizePlayerData(mapSettings.PlayerData); 940 1004 941 1005 // Reload, as the maptype or mapfilter might have changed 942 initMapNameList();1006 reloadMapList(); 943 1007 944 1008 g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); 945 1009 Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); 946 1010 947 1011 updateGUIObjects(); … … function onTick() 1039 1103 updateTimers(); 1040 1104 } 1041 1105 1042 1106 /** 1043 1107 * Called when the host choses the number of players on a random map. 1108 * 1044 1109 * @param {Number} num 1045 1110 */ 1046 1111 function selectNumPlayers(num) 1047 1112 { 1048 // Avoid recursion 1049 if (g_IsInGuiUpdate || !g_IsController || g_GameAttributes.mapType != "random") 1113 if (g_GameAttributes.mapType != "random") 1050 1114 return; 1051 1115 1052 1116 // Unassign players from nonexistent slots 1053 1117 if (g_IsNetworked) 1054 1118 { … … function selectNumPlayers(num) 1063 1127 if (num < pData.length) 1064 1128 g_GameAttributes.settings.PlayerData = pData.slice(0, num); 1065 1129 else 1066 1130 for (let i = pData.length; i < num; ++i) 1067 1131 g_GameAttributes.settings.PlayerData.push(g_DefaultPlayerData[i]); 1068 1069 updateGameAttributes();1070 1132 } 1071 1133 1072 1134 /** 1073 1135 * Assigns the given color to that player. 1074 1136 */ … … function ensureUniquePlayerColors(player 1100 1162 // If someone else has that color, assign an unused color 1101 1163 if (playerData.some((pData, j) => i != j && sameColor(playerData[i].Color, pData.Color))) 1102 1164 playerData[i].Color = g_PlayerColors.find(color => playerData.every(pData => !sameColor(color, pData.Color))); 1103 1165 } 1104 1166 1105 /**1106 * Called when the user selects a map type from the list.1107 *1108 * @param {string} type - scenario, skirmish or random1109 */1110 function selectMapType(type)1111 {1112 // Avoid recursion1113 if (g_IsInGuiUpdate || !g_IsController)1114 return;1115 1116 if (!g_MapPath[type])1117 {1118 error("selectMapType: Unexpected map type " + type);1119 return;1120 }1121 1122 g_MapData = {};1123 g_GameAttributes.map = "";1124 g_GameAttributes.mapType = type;1125 g_GameAttributes.mapPath = g_MapPath[type];1126 1127 if (type != "scenario")1128 g_GameAttributes.settings = {1129 "PlayerData": g_DefaultPlayerData.slice(0, 4),1130 "Seed": Math.floor(Math.random() * 65536),1131 "CheatsEnabled": g_GameAttributes.settings.CheatsEnabled1132 };1133 g_GameAttributes.settings.AISeed = Math.floor(Math.random() * 65536);1134 1135 initMapNameList();1136 1137 updateGameAttributes();1138 }1139 1140 function selectMapFilter(id)1141 {1142 // Avoid recursion1143 if (g_IsInGuiUpdate || !g_IsController)1144 return;1145 1146 g_GameAttributes.mapFilter = id;1147 1148 initMapNameList();1149 1150 updateGameAttributes();1151 }1152 1153 1167 function selectMap(name) 1154 1168 { 1155 // Avoid recursion1156 if (g_IsInGuiUpdate || !g_IsController || !name)1157 return;1158 1159 1169 // Reset some map specific properties which are not necessarily redefined on each map 1160 1170 for (let prop of ["TriggerScripts", "CircularMap", "Garrison"]) 1161 1171 g_GameAttributes.settings[prop] = undefined; 1162 1172 1163 1173 let mapData = loadMapData(name); … … function selectMap(name) 1185 1195 g_GameAttributes.settings[prop] = mapSettings[prop]; 1186 1196 1187 1197 // Use default AI if the map doesn't specify any explicitly 1188 1198 for (let i in g_GameAttributes.settings.PlayerData) 1189 1199 { 1190 if (! ('AI' in g_GameAttributes.settings.PlayerData[i]))1200 if (!g_GameAttributes.settings.PlayerData[i].AI) 1191 1201 g_GameAttributes.settings.PlayerData[i].AI = g_DefaultPlayerData[i].AI; 1192 if (!('AIDiff' in g_GameAttributes.settings.PlayerData[i])) 1202 1203 if (!g_GameAttributes.settings.PlayerData[i].AIDiff) 1193 1204 g_GameAttributes.settings.PlayerData[i].AIDiff = g_DefaultPlayerData[i].AIDiff; 1194 1205 } 1195 1206 1196 1207 // Reset player assignments on map change 1197 1208 if (!g_IsNetworked) 1198 1209 g_PlayerAssignments = { "local": { "name": singleplayerName(), "player": 1, "civ": "", "team": -1, "ready": 0 } }; 1199 1210 1200 1211 else 1201 1212 { 1202 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_GameAttributes.settings.PlayerData.length;1203 1204 1213 for (let guid in g_PlayerAssignments) 1205 1214 { // Unassign extra players 1206 1215 let player = g_PlayerAssignments[guid].player; 1207 if (player <= g_MaxPlayers && player > numPlayers)1216 if (player <= g_MaxPlayers && player > g_GameAttributes.settings.PlayerData.length) 1208 1217 Engine.AssignNetworkPlayer(player, ""); 1209 1218 } 1210 1219 } 1211 1212 updateGameAttributes();1213 1220 } 1214 1221 1215 1222 function launchGame() 1216 1223 { 1217 1224 if (!g_IsController) … … function launchGame() 1281 1288 let player = g_PlayerAssignments[guid]; 1282 1289 if (player.player > 0) // not observer or GAIA 1283 1290 g_GameAttributes.settings.PlayerData[player.player - 1].Name = player.name; 1284 1291 } 1285 1292 1293 g_GameAttributes.mapSettings.Seed = Math.floor(Math.random() * 65536); 1294 g_GameAttributes.mapSettings.AISeed = Math.floor(Math.random() * 65536); 1295 1296 // Unique ID to be used for identifying the same game reports for the lobby 1297 g_GameAttributes.matchID = Engine.GetMatchID(); 1298 1286 1299 if (g_IsNetworked) 1287 1300 { 1288 1301 Engine.SetNetworkGameAttributes(g_GameAttributes); 1289 1302 Engine.StartNetworkGame(); 1290 1303 } … … function launchGame() 1315 1328 */ 1316 1329 function updateGUIObjects() 1317 1330 { 1318 1331 g_IsInGuiUpdate = true; 1319 1332 1320 let mapSettings = g_GameAttributes.settings; 1333 for (let ctrl in g_Dropdowns) 1334 { 1335 let dropdown = Engine.GetGUIObjectByName(ctrl); 1321 1336 1322 // These dropdowns don't set values while g_IsInGuiUpdate 1323 let mapName = g_GameAttributes.map || ""; 1324 let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default")); 1325 let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default; 1326 let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; 1327 1328 // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) 1329 let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; 1330 let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; 1331 let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default; 1332 let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; 1333 let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1334 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1335 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1337 let idx = dropdown.list_data.indexOf("" + g_Dropdowns[ctrl].get()); 1338 let hidden = g_Dropdowns[ctrl].hidden && g_Dropdowns[ctrl].hidden(); 1339 let enabled = !g_Dropdowns[ctrl].enabled || g_Dropdowns[ctrl].enabled(); 1336 1340 1337 if (g_IsController) 1341 dropdown.selected = idx; 1342 dropdown.hidden = !g_IsController || hidden || !enabled; 1343 1344 let label = Engine.GetGUIObjectByName(ctrl + "Text"); 1345 label.caption = idx == -1 ? translate("Unknown") : dropdown.list[idx]; 1346 label.hidden = g_IsController && enabled || hidden; 1347 } 1348 1349 for (let ctrl in g_Checkboxes) 1338 1350 { 1339 Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; 1340 Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; 1341 Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); 1342 Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; 1343 Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; 1344 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1345 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1346 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1347 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1348 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1349 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1351 let obj = g_Checkboxes[ctrl]; 1352 1353 let hidden = obj.hidden && obj.hidden(); 1354 let enabled = !obj.enabled || obj.enabled(); 1355 1356 let checkbox = Engine.GetGUIObjectByName(ctrl); 1357 checkbox.checked = obj.get(); 1358 checkbox.enabled = enabled; 1359 checkbox.hidden = hidden || !g_IsController; 1360 1361 let label = Engine.GetGUIObjectByName(ctrl + "Text"); 1362 label.caption = obj.get() ? translate("Yes") : translate("No"); 1363 label.hidden = hidden || g_IsController; 1350 1364 } 1351 else 1365 1366 for (let ctrl in g_MiscControls) 1352 1367 { 1353 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; 1354 Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; 1355 Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); 1356 initMapNameList(); 1357 } 1358 1359 // Can be visible to both host and clients 1360 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); 1361 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1362 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1363 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1364 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1365 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1366 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; 1367 Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; 1368 1369 setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled); 1370 setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); 1371 setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap); 1372 setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); 1373 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1374 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1375 1376 Engine.GetGUIObjectByName("optionWonderDuration").hidden = 1377 g_GameAttributes.settings.GameType && 1378 g_GameAttributes.settings.GameType != "wonder"; 1379 1380 Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; 1381 1382 Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; 1383 Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; 1384 1385 // Mapsize completely hidden for non-random maps 1386 let isRandom = g_GameAttributes.mapType == "random"; 1387 Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom; 1388 Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController; 1389 Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; 1390 hideControl("numPlayers", "numPlayersText", isRandom && g_IsController); 1391 1392 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1393 1394 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1395 "startingResources", "ceasefire", "revealMap", 1396 "exploreMap", "disableTreasures", "lockTeams"]) 1397 hideControl(ctrl, ctrl + "Text", notScenario); 1368 let control = Engine.GetGUIObjectByName(ctrl); 1369 control.hidden = g_MiscControls[ctrl].hidden && g_MiscControls[ctrl].hidden(); 1398 1370 1371 if (g_MiscControls[ctrl].tooltip) 1372 control.tooltip = g_MiscControls[ctrl].tooltip(); 1373 } 1374 1375 // TODO: move to g_DropdownArrays 1376 let mapSettings = g_GameAttributes.settings; 1377 let notScenario = g_GameAttributes.mapType != "scenario"; 1399 1378 for (let i = 0; i < g_MaxPlayers; ++i) 1400 1379 { 1401 Engine.GetGUIObjectByName("playerBox["+i+"]").hidden = (i >= numPlayers);1380 Engine.GetGUIObjectByName("playerBox["+i+"]").hidden = (i >= mapSettings.PlayerData.length); 1402 1381 1403 if (i >= numPlayers)1382 if (i >= mapSettings.PlayerData.length) 1404 1383 continue; 1405 1384 1406 1385 let pName = Engine.GetGUIObjectByName("playerName["+i+"]"); 1407 1386 let pAssignment = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); 1408 1387 let pAssignmentText = Engine.GetGUIObjectByName("playerAssignmentText["+i+"]"); -
source/gui/IGUITextOwner.cpp
void IGUITextOwner::DrawText(size_t inde 73 73 { 74 74 SetupText(); 75 75 m_GeneratedTextsValid = true; 76 76 } 77 77 78 ENSURE(index < m_GeneratedTexts.size() && "Trying to draw a Text Index within a IGUITextOwner that doesn't exist"); 78 if (!m_GeneratedTexts[index]) 79 return; 79 80 80 81 if (GetGUI()) 81 82 GetGUI()->DrawText(*m_GeneratedTexts[index], color, pos, z, clipping); 82 83 } 83 84