1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
|
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "sys/platform.h"
#include "idlib/LangDict.h"
#include "framework/async/AsyncNetwork.h"
#include "framework/FileSystem.h"
#include "framework/Console.h"
#include "framework/Game.h"
#include "sound/sound.h"
#include "ui/UserInterface.h"
#include "framework/Session_local.h"
idCVar idSessionLocal::gui_configServerRate( "gui_configServerRate", "0", CVAR_GUI | CVAR_ARCHIVE | CVAR_ROM | CVAR_INTEGER, "" );
// implements the setup for, and commands from, the main menu
/*
==============
idSessionLocal::GetActiveMenu
==============
*/
idUserInterface *idSessionLocal::GetActiveMenu( void ) {
return guiActive;
}
/*
==============
idSessionLocal::StartMainMenu
==============
*/
void idSessionLocal::StartMenu( bool playIntro ) {
if ( guiActive == guiMainMenu ) {
return;
}
if ( readDemo ) {
// if we're playing a demo, esc kills it
UnloadMap();
}
// pause the game sound world
if ( sw != NULL && !sw->IsPaused() ) {
sw->Pause();
}
// start playing the menu sounds
soundSystem->SetPlayingSoundWorld( menuSoundWorld );
SetGUI( guiMainMenu, NULL );
guiMainMenu->HandleNamedEvent( playIntro ? "playIntro" : "noIntro" );
if(fileSystem->HasD3XP()) {
guiMainMenu->SetStateString("game_list", common->GetLanguageDict()->GetString( "#str_07202" ));
} else {
guiMainMenu->SetStateString("game_list", common->GetLanguageDict()->GetString( "#str_07212" ));
}
console->Close();
}
/*
=================
idSessionLocal::SetGUI
=================
*/
void idSessionLocal::SetGUI( idUserInterface *gui, HandleGuiCommand_t handle ) {
guiActive = gui;
guiHandle = handle;
if ( guiMsgRestore ) {
common->DPrintf( "idSessionLocal::SetGUI: cleared an active message box\n" );
guiMsgRestore = NULL;
}
if ( !guiActive ) {
return;
}
if ( guiActive == guiMainMenu ) {
SetSaveGameGuiVars();
SetMainMenuGuiVars();
} else if ( guiActive == guiRestartMenu ) {
SetSaveGameGuiVars();
}
sysEvent_t ev;
memset( &ev, 0, sizeof( ev ) );
ev.evType = SE_NONE;
guiActive->HandleEvent( &ev, com_frameTime );
guiActive->Activate( true, com_frameTime );
}
/*
===============
idSessionLocal::ExitMenu
===============
*/
void idSessionLocal::ExitMenu( void ) {
guiActive = NULL;
// go back to the game sounds
soundSystem->SetPlayingSoundWorld( sw );
// unpause the game sound world
if ( sw != NULL && sw->IsPaused() ) {
sw->UnPause();
}
}
/*
===============
idListSaveGameCompare
===============
*/
ID_INLINE int idListSaveGameCompare( const fileTIME_T *a, const fileTIME_T *b ) {
return b->timeStamp - a->timeStamp;
}
/*
===============
idSessionLocal::GetSaveGameList
===============
*/
void idSessionLocal::GetSaveGameList( idStrList &fileList, idList<fileTIME_T> &fileTimes ) {
int i;
idFileList *files;
// NOTE: no fs_game_base for savegames
idStr game = cvarSystem->GetCVarString( "fs_game" );
if( game.Length() ) {
files = fileSystem->ListFiles( "savegames", ".save", false, false, game );
} else {
files = fileSystem->ListFiles( "savegames", ".save" );
}
fileList = files->GetList();
fileSystem->FreeFileList( files );
for ( i = 0; i < fileList.Num(); i++ ) {
ID_TIME_T timeStamp;
fileSystem->ReadFile( "savegames/" + fileList[i], NULL, &timeStamp );
fileList[i].StripLeading( '/' );
fileList[i].StripFileExtension();
fileTIME_T ft;
ft.index = i;
ft.timeStamp = timeStamp;
fileTimes.Append( ft );
}
fileTimes.Sort( idListSaveGameCompare );
}
/*
===============
idSessionLocal::SetSaveGameGuiVars
===============
*/
void idSessionLocal::SetSaveGameGuiVars( void ) {
int i;
idStr name;
idStrList fileList;
idList<fileTIME_T> fileTimes;
loadGameList.Clear();
fileList.Clear();
fileTimes.Clear();
GetSaveGameList( fileList, fileTimes );
loadGameList.SetNum( fileList.Num() );
for ( i = 0; i < fileList.Num(); i++ ) {
loadGameList[i] = fileList[fileTimes[i].index];
idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT);
if ( src.LoadFile( va("savegames/%s.txt", loadGameList[i].c_str()) ) ) {
idToken tok;
src.ReadToken( &tok );
name = tok;
} else {
name = loadGameList[i];
}
name += "\t";
idStr date = Sys_TimeStampToStr( fileTimes[i].timeStamp );
name += date;
guiActive->SetStateString( va("loadgame_item_%i", i), name);
}
guiActive->DeleteStateVar( va("loadgame_item_%i", fileList.Num()) );
guiActive->SetStateString( "loadgame_sel_0", "-1" );
guiActive->SetStateString( "loadgame_shot", "guis/assets/blankLevelShot" );
}
/*
===============
idSessionLocal::SetModsMenuGuiVars
===============
*/
void idSessionLocal::SetModsMenuGuiVars( void ) {
int i;
idModList *list = fileSystem->ListMods();
modsList.SetNum( list->GetNumMods() );
// Build the gui list
for ( i = 0; i < list->GetNumMods(); i++ ) {
guiActive->SetStateString( va("modsList_item_%i", i), list->GetDescription( i ) );
modsList[i] = list->GetMod( i );
}
guiActive->DeleteStateVar( va("modsList_item_%i", list->GetNumMods()) );
guiActive->SetStateString( "modsList_sel_0", "-1" );
fileSystem->FreeModList( list );
}
/*
===============
idSessionLocal::SetMainMenuSkin
===============
*/
void idSessionLocal::SetMainMenuSkin( void ) {
// skins
idStr str = cvarSystem->GetCVarString( "mod_validSkins" );
idStr uiSkin = cvarSystem->GetCVarString( "ui_skin" );
idStr skin;
int skinId = 1;
int count = 1;
while ( str.Length() ) {
int n = str.Find( ";" );
if ( n >= 0 ) {
skin = str.Left( n );
str = str.Right( str.Length() - n - 1 );
} else {
skin = str;
str = "";
}
if ( skin.Icmp( uiSkin ) == 0 ) {
skinId = count;
}
count++;
}
for ( int i = 0; i < count; i++ ) {
guiMainMenu->SetStateInt( va( "skin%i", i+1 ), 0 );
}
guiMainMenu->SetStateInt( va( "skin%i", skinId ), 1 );
}
/*
===============
idSessionLocal::SetPbMenuGuiVars
===============
*/
void idSessionLocal::SetPbMenuGuiVars( void ) {
}
/*
===============
idSessionLocal::SetMainMenuGuiVars
===============
*/
void idSessionLocal::SetMainMenuGuiVars( void ) {
guiMainMenu->SetStateString( "serverlist_sel_0", "-1" );
guiMainMenu->SetStateString( "serverlist_selid_0", "-1" );
guiMainMenu->SetStateInt( "com_machineSpec", com_machineSpec.GetInteger() );
// "inetGame" will hold a hand-typed inet address, which is not archived to a cvar
guiMainMenu->SetStateString( "inetGame", "" );
// key bind names
guiMainMenu->SetKeyBindingNames();
// flag for in-game menu
if ( mapSpawned ) {
guiMainMenu->SetStateString( "inGame", IsMultiplayer() ? "2" : "1" );
} else {
guiMainMenu->SetStateString( "inGame", "0" );
}
SetCDKeyGuiVars( );
guiMainMenu->SetStateString( "nightmare", cvarSystem->GetCVarBool( "g_nightmare" ) ? "1" : "0" );
guiMainMenu->SetStateString( "browser_levelshot", "guis/assets/splash/pdtempa" );
SetMainMenuSkin();
// Mods Menu
SetModsMenuGuiVars();
guiMsg->SetStateString( "visible_hasxp", fileSystem->HasD3XP() ? "1" : "0" );
guiMainMenu->SetStateString( "driver_prompt", "0" );
SetPbMenuGuiVars();
}
/*
==============
idSessionLocal::HandleSaveGameMenuCommands
==============
*/
bool idSessionLocal::HandleSaveGameMenuCommand( idCmdArgs &args, int &icmd ) {
const char *cmd = args.Argv(icmd-1);
if ( !idStr::Icmp( cmd, "loadGame" ) ) {
int choice = guiActive->State().GetInt("loadgame_sel_0");
if ( choice >= 0 && choice < loadGameList.Num() ) {
sessLocal.LoadGame( loadGameList[choice] );
}
return true;
}
if ( !idStr::Icmp( cmd, "saveGame" ) ) {
const char *saveGameName = guiActive->State().GetString("saveGameName");
if ( saveGameName && saveGameName[0] ) {
// First see if the file already exists unless they pass '1' to authorize the overwrite
if ( icmd == args.Argc() || atoi(args.Argv( icmd++ )) == 0 ) {
idStr saveFileName = saveGameName;
sessLocal.ScrubSaveGameFileName( saveFileName );
saveFileName = "savegames/" + saveFileName;
saveFileName.SetFileExtension(".save");
idStr game = cvarSystem->GetCVarString( "fs_game" );
idFile *file;
if(game.Length()) {
file = fileSystem->OpenFileRead( saveFileName, true, game );
} else {
file = fileSystem->OpenFileRead( saveFileName );
}
if ( file != NULL ) {
fileSystem->CloseFile( file );
// The file exists, see if it's an autosave
saveFileName.SetFileExtension(".txt");
idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT);
if ( src.LoadFile( saveFileName ) ) {
idToken tok;
src.ReadToken( &tok ); // Name
src.ReadToken( &tok ); // Map
src.ReadToken( &tok ); // Screenshot
if ( !tok.IsEmpty() ) {
// NOTE: base/ gui doesn't handle that one
guiActive->HandleNamedEvent( "autosaveOverwriteError" );
return true;
}
}
guiActive->HandleNamedEvent( "saveGameOverwrite" );
return true;
}
}
sessLocal.SaveGame( saveGameName );
SetSaveGameGuiVars( );
guiActive->StateChanged( com_frameTime );
}
return true;
}
if ( !idStr::Icmp( cmd, "deleteGame" ) ) {
int choice = guiActive->State().GetInt( "loadgame_sel_0" );
if ( choice >= 0 && choice < loadGameList.Num() ) {
fileSystem->RemoveFile( va("savegames/%s.save", loadGameList[choice].c_str()) );
fileSystem->RemoveFile( va("savegames/%s.tga", loadGameList[choice].c_str()) );
fileSystem->RemoveFile( va("savegames/%s.txt", loadGameList[choice].c_str()) );
SetSaveGameGuiVars( );
guiActive->StateChanged( com_frameTime );
}
return true;
}
if ( !idStr::Icmp( cmd, "updateSaveGameInfo" ) ) {
int choice = guiActive->State().GetInt( "loadgame_sel_0" );
if ( choice >= 0 && choice < loadGameList.Num() ) {
const idMaterial *material;
idStr saveName, description, screenshot;
idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT);
if ( src.LoadFile( va("savegames/%s.txt", loadGameList[choice].c_str()) ) ) {
idToken tok;
src.ReadToken( &tok );
saveName = tok;
src.ReadToken( &tok );
description = tok;
src.ReadToken( &tok );
screenshot = tok;
} else {
saveName = loadGameList[choice];
description = loadGameList[choice];
screenshot = "";
}
if ( screenshot.Length() == 0 ) {
screenshot = va("savegames/%s.tga", loadGameList[choice].c_str());
}
material = declManager->FindMaterial( screenshot );
if ( material ) {
material->ReloadImages( false );
}
guiActive->SetStateString( "loadgame_shot", screenshot );
saveName.RemoveColors();
guiActive->SetStateString( "saveGameName", saveName );
guiActive->SetStateString( "saveGameDescription", description );
ID_TIME_T timeStamp;
fileSystem->ReadFile( va("savegames/%s.save", loadGameList[choice].c_str()), NULL, &timeStamp );
idStr date = Sys_TimeStampToStr(timeStamp);
int tab = date.Find( '\t' );
idStr time = date.Right( date.Length() - tab - 1);
guiActive->SetStateString( "saveGameDate", date.Left( tab ) );
guiActive->SetStateString( "saveGameTime", time );
}
return true;
}
return false;
}
/*
==============
idSessionLocal::HandleRestartMenuCommands
Executes any commands returned by the gui
==============
*/
void idSessionLocal::HandleRestartMenuCommands( const char *menuCommand ) {
// execute the command from the menu
int icmd;
idCmdArgs args;
args.TokenizeString( menuCommand, false );
for( icmd = 0; icmd < args.Argc(); ) {
const char *cmd = args.Argv( icmd++ );
if ( HandleSaveGameMenuCommand( args, icmd ) ) {
continue;
}
if ( !idStr::Icmp( cmd, "restart" ) ) {
if ( !LoadGame( GetAutoSaveName( mapSpawnData.serverInfo.GetString("si_map") ) ) ) {
// If we can't load the autosave then just restart the map
MoveToNewMap( mapSpawnData.serverInfo.GetString("si_map") );
}
continue;
}
if ( !idStr::Icmp( cmd, "quit" ) ) {
ExitMenu();
common->Quit();
return;
}
if ( !idStr::Icmp ( cmd, "exec" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, args.Argv( icmd++ ) );
continue;
}
if ( !idStr::Icmp( cmd, "play" ) ) {
if ( args.Argc() - icmd >= 1 ) {
idStr snd = args.Argv(icmd++);
sw->PlayShaderDirectly(snd);
}
continue;
}
}
}
/*
==============
idSessionLocal::HandleIntroMenuCommands
Executes any commands returned by the gui
==============
*/
void idSessionLocal::HandleIntroMenuCommands( const char *menuCommand ) {
// execute the command from the menu
int i;
idCmdArgs args;
args.TokenizeString( menuCommand, false );
for( i = 0; i < args.Argc(); ) {
const char *cmd = args.Argv( i++ );
if ( !idStr::Icmp( cmd, "startGame" ) ) {
menuSoundWorld->ClearAllSoundEmitters();
ExitMenu();
continue;
}
if ( !idStr::Icmp( cmd, "play" ) ) {
if ( args.Argc() - i >= 1 ) {
idStr snd = args.Argv(i++);
menuSoundWorld->PlayShaderDirectly(snd);
}
continue;
}
}
}
/*
==============
idSessionLocal::UpdateMPLevelShot
==============
*/
void idSessionLocal::UpdateMPLevelShot( void ) {
char screenshot[ MAX_STRING_CHARS ];
fileSystem->FindMapScreenshot( cvarSystem->GetCVarString( "si_map" ), screenshot, MAX_STRING_CHARS );
guiMainMenu->SetStateString( "current_levelshot", screenshot );
}
/*
==============
idSessionLocal::HandleMainMenuCommands
Executes any commands returned by the gui
==============
*/
void idSessionLocal::HandleMainMenuCommands( const char *menuCommand ) {
// execute the command from the menu
int icmd;
idCmdArgs args;
args.TokenizeString( menuCommand, false );
for( icmd = 0; icmd < args.Argc(); ) {
const char *cmd = args.Argv( icmd++ );
if ( HandleSaveGameMenuCommand( args, icmd ) ) {
continue;
}
// always let the game know the command is being run
if ( game ) {
game->HandleMainMenuCommands( cmd, guiActive );
}
if ( !idStr::Icmp( cmd, "startGame" ) ) {
cvarSystem->SetCVarInteger( "g_skill", guiMainMenu->State().GetInt( "skill" ) );
if ( icmd < args.Argc() ) {
StartNewGame( args.Argv( icmd++ ) );
} else {
StartNewGame( "game/mars_city1" );
}
// need to do this here to make sure com_frameTime is correct or the gui activates with a time that
// is "however long map load took" time in the past
common->GUIFrame( false, false );
SetGUI( guiIntro, NULL );
guiIntro->StateChanged( com_frameTime, true );
// stop playing the game sounds
soundSystem->SetPlayingSoundWorld( menuSoundWorld );
continue;
}
if ( !idStr::Icmp( cmd, "quit" ) ) {
ExitMenu();
common->Quit();
return;
}
if ( !idStr::Icmp( cmd, "loadMod" ) ) {
int choice = guiActive->State().GetInt( "modsList_sel_0" );
if ( choice >= 0 && choice < modsList.Num() ) {
cvarSystem->SetCVarString( "fs_game", modsList[ choice ] );
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "reloadEngine menu\n" );
}
}
if ( !idStr::Icmp( cmd, "UpdateServers" ) ) {
if ( guiActive->State().GetBool( "lanSet" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "LANScan" );
} else {
idAsyncNetwork::GetNETServers();
}
continue;
}
if ( !idStr::Icmp( cmd, "RefreshServers" ) ) {
if ( guiActive->State().GetBool( "lanSet" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "LANScan" );
} else {
idAsyncNetwork::client.serverList.NetScan( );
}
continue;
}
if ( !idStr::Icmp( cmd, "FilterServers" ) ) {
idAsyncNetwork::client.serverList.ApplyFilter( );
continue;
}
if ( !idStr::Icmp( cmd, "sortServerName" ) ) {
idAsyncNetwork::client.serverList.SetSorting( SORT_SERVERNAME );
continue;
}
if ( !idStr::Icmp( cmd, "sortGame" ) ) {
idAsyncNetwork::client.serverList.SetSorting( SORT_GAME );
continue;
}
if ( !idStr::Icmp( cmd, "sortPlayers" ) ) {
idAsyncNetwork::client.serverList.SetSorting( SORT_PLAYERS );
continue;
}
if ( !idStr::Icmp( cmd, "sortPing" ) ) {
idAsyncNetwork::client.serverList.SetSorting( SORT_PING );
continue;
}
if ( !idStr::Icmp( cmd, "sortGameType" ) ) {
idAsyncNetwork::client.serverList.SetSorting( SORT_GAMETYPE );
continue;
}
if ( !idStr::Icmp( cmd, "sortMap" ) ) {
idAsyncNetwork::client.serverList.SetSorting( SORT_MAP );
continue;
}
if ( !idStr::Icmp( cmd, "serverList" ) ) {
idAsyncNetwork::client.serverList.GUIUpdateSelected();
continue;
}
if ( !idStr::Icmp( cmd, "LANConnect" ) ) {
int sel = guiActive->State().GetInt( "serverList_selid_0" );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "Connect %d\n", sel ) );
return;
}
if ( !idStr::Icmp( cmd, "MAPScan" ) ) {
const char *gametype = cvarSystem->GetCVarString( "si_gameType" );
if ( gametype == NULL || *gametype == 0 || idStr::Icmp( gametype, "singleplayer" ) == 0 ) {
gametype = "Deathmatch";
}
int i, num;
idStr si_map = cvarSystem->GetCVarString("si_map");
const idDict *dict;
guiMainMenu_MapList->Clear();
guiMainMenu_MapList->SetSelection( 0 );
num = fileSystem->GetNumMaps();
for ( i = 0; i < num; i++ ) {
dict = fileSystem->GetMapDecl( i );
if ( dict && dict->GetBool( gametype ) ) {
const char *mapName = dict->GetString( "name" );
if ( mapName[ 0 ] == '\0' ) {
mapName = dict->GetString( "path" );
}
mapName = common->GetLanguageDict()->GetString( mapName );
guiMainMenu_MapList->Add( i, mapName );
if ( !si_map.Icmp( dict->GetString( "path" ) ) ) {
guiMainMenu_MapList->SetSelection( guiMainMenu_MapList->Num() - 1 );
}
}
}
i = guiMainMenu_MapList->GetSelection( NULL, 0 );
if ( i >= 0 ) {
dict = fileSystem->GetMapDecl( i);
} else {
dict = NULL;
}
cvarSystem->SetCVarString( "si_map", ( dict ? dict->GetString( "path" ) : "" ) );
// set the current level shot
UpdateMPLevelShot();
continue;
}
if ( !idStr::Icmp( cmd, "click_mapList" ) ) {
int mapNum = guiMainMenu_MapList->GetSelection( NULL, 0 );
const idDict *dict = fileSystem->GetMapDecl( mapNum );
if ( dict ) {
cvarSystem->SetCVarString( "si_map", dict->GetString( "path" ) );
}
UpdateMPLevelShot();
continue;
}
if ( !idStr::Icmp( cmd, "inetConnect" ) ) {
const char *s = guiMainMenu->State().GetString( "inetGame" );
if ( !s || s[0] == 0 ) {
// don't put the menu away if there isn't a valid selection
continue;
}
cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "connect %s", s ) );
return;
}
if ( !idStr::Icmp( cmd, "startMultiplayer" ) ) {
int dedicated = guiActive->State().GetInt( "dedicated" );
cvarSystem->SetCVarBool( "net_LANServer", guiActive->State().GetBool( "server_type" ) );
if ( gui_configServerRate.GetInteger() > 0 ) {
// guess the best rate for upstream, number of internet clients
if ( gui_configServerRate.GetInteger() == 5 || cvarSystem->GetCVarBool( "net_LANServer" ) ) {
cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 25600 );
} else {
// internet players
int n_clients = cvarSystem->GetCVarInteger( "si_maxPlayers" );
if ( !dedicated ) {
n_clients--;
}
int maxclients = 0;
switch ( gui_configServerRate.GetInteger() ) {
case 1:
// 128 kbits
cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 8000 );
maxclients = 2;
break;
case 2:
// 256 kbits
cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 9500 );
maxclients = 3;
break;
case 3:
// 384 kbits
cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 10500 );
maxclients = 4;
break;
case 4:
// 512 and above..
cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 14000 );
maxclients = 4;
break;
}
if ( n_clients > maxclients ) {
if ( MessageBox( MSG_OKCANCEL, va( common->GetLanguageDict()->GetString( "#str_04315" ), dedicated ? maxclients : Min( 8, maxclients + 1 ) ), common->GetLanguageDict()->GetString( "#str_04316" ), true, "OK" )[ 0 ] == '\0' ) {
continue;
}
cvarSystem->SetCVarInteger( "si_maxPlayers", dedicated ? maxclients : Min( 8, maxclients + 1 ) );
}
}
}
if ( !dedicated && !cvarSystem->GetCVarBool( "net_LANServer" ) && cvarSystem->GetCVarInteger("si_maxPlayers") > 4 ) {
// "Dedicated server mode is recommended for internet servers with more than 4 players. Continue in listen mode?"
if ( !MessageBox( MSG_YESNO, common->GetLanguageDict()->GetString ( "#str_00100625" ), common->GetLanguageDict()->GetString ( "#str_00100626" ), true, "yes" )[ 0 ] ) {
continue;
}
}
if ( dedicated ) {
cvarSystem->SetCVarInteger( "net_serverDedicated", 1 );
} else {
cvarSystem->SetCVarInteger( "net_serverDedicated", 0 );
}
ExitMenu();
// may trigger a reloadEngine - APPEND
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "SpawnServer\n" );
return;
}
if ( !idStr::Icmp( cmd, "mpSkin")) {
idStr skin;
if ( args.Argc() - icmd >= 1 ) {
skin = args.Argv( icmd++ );
cvarSystem->SetCVarString( "ui_skin", skin );
SetMainMenuSkin();
}
continue;
}
if ( !idStr::Icmp( cmd, "close" ) ) {
// if we aren't in a game, the menu can't be closed
if ( mapSpawned ) {
ExitMenu();
}
continue;
}
if ( !idStr::Icmp( cmd, "resetdefaults" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "exec default.cfg" );
guiMainMenu->SetKeyBindingNames();
continue;
}
if ( !idStr::Icmp( cmd, "bind" ) ) {
if ( args.Argc() - icmd >= 2 ) {
int key = atoi( args.Argv( icmd++ ) );
idStr bind = args.Argv( icmd++ );
if ( idKeyInput::NumBinds( bind ) >= 2 && !idKeyInput::KeyIsBoundTo( key, bind ) ) {
idKeyInput::UnbindBinding( bind );
}
idKeyInput::SetBinding( key, bind );
guiMainMenu->SetKeyBindingNames();
}
continue;
}
if ( !idStr::Icmp( cmd, "play" ) ) {
if ( args.Argc() - icmd >= 1 ) {
idStr snd = args.Argv( icmd++ );
int channel = 1;
if ( snd.Length() == 1 ) {
channel = atoi( snd );
snd = args.Argv( icmd++ );
}
menuSoundWorld->PlayShaderDirectly( snd, channel );
}
continue;
}
if ( !idStr::Icmp( cmd, "music" ) ) {
if ( args.Argc() - icmd >= 1 ) {
idStr snd = args.Argv( icmd++ );
menuSoundWorld->PlayShaderDirectly( snd, 2 );
}
continue;
}
// triggered from mainmenu or mpmain
if ( !idStr::Icmp( cmd, "sound" ) ) {
idStr vcmd;
if ( args.Argc() - icmd >= 1 ) {
vcmd = args.Argv( icmd++ );
}
if ( !vcmd.Length() || !vcmd.Icmp( "speakers" ) ) {
int old = cvarSystem->GetCVarInteger( "s_numberOfSpeakers" );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "s_restart\n" );
if ( old != cvarSystem->GetCVarInteger( "s_numberOfSpeakers" ) ) {
#ifdef _WIN32
MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04142" ), common->GetLanguageDict()->GetString( "#str_04141" ), true );
#else
// a message that doesn't mention the windows control panel
MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07230" ), common->GetLanguageDict()->GetString( "#str_04141" ), true );
#endif
}
}
if ( !vcmd.Icmp( "eax" ) ) {
if ( cvarSystem->GetCVarBool( "s_useEAXReverb" ) ) {
int efx = soundSystem->IsEFXAvailable();
switch ( efx ) {
case 1:
// when you restart
MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04137" ), common->GetLanguageDict()->GetString( "#str_07231" ), true );
break;
case -1:
cvarSystem->SetCVarBool( "s_useEAXReverb", false );
// disabled
MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07233" ), common->GetLanguageDict()->GetString( "#str_07231" ), true );
break;
case 0:
cvarSystem->SetCVarBool( "s_useEAXReverb", false );
// not available
MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07232" ), common->GetLanguageDict()->GetString( "#str_07231" ), true );
break;
}
} else {
// when you restart
MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04137" ), common->GetLanguageDict()->GetString( "#str_07231" ), true );
}
}
if ( !vcmd.Icmp( "drivar" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "s_restart\n" );
}
continue;
}
if ( !idStr::Icmp( cmd, "video" ) ) {
idStr vcmd;
if ( args.Argc() - icmd >= 1 ) {
vcmd = args.Argv( icmd++ );
}
int oldSpec = com_machineSpec.GetInteger();
if ( idStr::Icmp( vcmd, "low" ) == 0 ) {
com_machineSpec.SetInteger( 0 );
} else if ( idStr::Icmp( vcmd, "medium" ) == 0 ) {
com_machineSpec.SetInteger( 1 );
} else if ( idStr::Icmp( vcmd, "high" ) == 0 ) {
com_machineSpec.SetInteger( 2 );
} else if ( idStr::Icmp( vcmd, "ultra" ) == 0 ) {
com_machineSpec.SetInteger( 3 );
} else if ( idStr::Icmp( vcmd, "recommended" ) == 0 ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "setMachineSpec\n" );
}
if ( oldSpec != com_machineSpec.GetInteger() ) {
guiActive->SetStateInt( "com_machineSpec", com_machineSpec.GetInteger() );
guiActive->StateChanged( com_frameTime );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "execMachineSpec\n" );
}
if ( idStr::Icmp( vcmd, "restart" ) == 0) {
guiActive->HandleNamedEvent( "cvar write render" );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "vid_restart\n" );
}
continue;
}
if ( !idStr::Icmp( cmd, "clearBind" ) ) {
if ( args.Argc() - icmd >= 1 ) {
idKeyInput::UnbindBinding( args.Argv( icmd++ ) );
guiMainMenu->SetKeyBindingNames();
}
continue;
}
// FIXME: obsolete
if ( !idStr::Icmp( cmd, "chatdone" ) ) {
idStr temp = guiActive->State().GetString( "chattext" );
temp += "\r";
guiActive->SetStateString( "chattext", "" );
continue;
}
if ( !idStr::Icmp ( cmd, "exec" ) ) {
//Backup the language so we can restore it after defaults.
idStr lang = cvarSystem->GetCVarString("sys_lang");
cmdSystem->BufferCommandText( CMD_EXEC_NOW, args.Argv( icmd++ ) );
if ( idStr::Icmp( "cvar_restart", args.Argv( icmd - 1 ) ) == 0 ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "exec default.cfg" );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "setMachineSpec\n" );
//Make sure that any r_brightness changes take effect
float bright = cvarSystem->GetCVarFloat("r_brightness");
cvarSystem->SetCVarFloat("r_brightness", 0.0f);
cvarSystem->SetCVarFloat("r_brightness", bright);
//Force user info modified after a reset to defaults
cvarSystem->SetModifiedFlags(CVAR_USERINFO);
guiActive->SetStateInt( "com_machineSpec", com_machineSpec.GetInteger() );
//Restore the language
cvarSystem->SetCVarString("sys_lang", lang);
}
continue;
}
if ( !idStr::Icmp ( cmd, "loadBinds" ) ) {
guiMainMenu->SetKeyBindingNames();
continue;
}
if ( !idStr::Icmp( cmd, "systemCvars" ) ) {
guiActive->HandleNamedEvent( "cvar read render" );
guiActive->HandleNamedEvent( "cvar read sound" );
continue;
}
if ( !idStr::Icmp( cmd, "SetCDKey" ) ) {
// we can't do this from inside the HandleMainMenuCommands code, otherwise the message box stuff gets confused
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "promptKey\n" );
continue;
}
if ( !idStr::Icmp( cmd, "CheckUpdate" ) ) {
idAsyncNetwork::client.SendVersionCheck();
continue;
}
if ( !idStr::Icmp( cmd, "CheckUpdate2" ) ) {
idAsyncNetwork::client.SendVersionCheck( true );
continue;
}
if ( !idStr::Icmp( cmd, "checkKeys" ) ) {
#if ID_ENFORCE_KEY
// not a strict check so you silently auth in the background without bugging the user
if ( !session->CDKeysAreValid( false ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "promptKey force" );
cmdSystem->ExecuteCommandBuffer();
}
#endif
continue;
}
// triggered from mainmenu or mpmain
if ( !idStr::Icmp( cmd, "punkbuster" ) ) {
idStr vcmd;
if ( args.Argc() - icmd >= 1 ) {
vcmd = args.Argv( icmd++ );
}
// filtering PB based on enabled/disabled
idAsyncNetwork::client.serverList.ApplyFilter( );
SetPbMenuGuiVars();
continue;
}
}
}
/*
==============
idSessionLocal::HandleChatMenuCommands
Executes any commands returned by the gui
==============
*/
void idSessionLocal::HandleChatMenuCommands( const char *menuCommand ) {
// execute the command from the menu
int i;
idCmdArgs args;
args.TokenizeString( menuCommand, false );
for ( i = 0; i < args.Argc(); ) {
const char *cmd = args.Argv( i++ );
if ( idStr::Icmp( cmd, "chatactive" ) == 0 ) {
//chat.chatMode = CHAT_GLOBAL;
continue;
}
if ( idStr::Icmp( cmd, "chatabort" ) == 0 ) {
//chat.chatMode = CHAT_NONE;
continue;
}
if ( idStr::Icmp( cmd, "netready" ) == 0 ) {
bool b = cvarSystem->GetCVarBool( "ui_ready" );
cvarSystem->SetCVarBool( "ui_ready", !b );
continue;
}
if ( idStr::Icmp( cmd, "netstart" ) == 0 ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "netcommand start\n" );
continue;
}
}
}
/*
==============
idSessionLocal::HandleInGameCommands
Executes any commands returned by the gui
==============
*/
void idSessionLocal::HandleInGameCommands( const char *menuCommand ) {
// execute the command from the menu
idCmdArgs args;
args.TokenizeString( menuCommand, false );
const char *cmd = args.Argv( 0 );
if ( !idStr::Icmp( cmd, "close" ) ) {
if ( guiActive ) {
sysEvent_t ev;
ev.evType = SE_NONE;
guiActive->HandleEvent( &ev, com_frameTime );
guiActive->Activate( false, com_frameTime );
guiActive = NULL;
}
}
}
/*
==============
idSessionLocal::DispatchCommand
==============
*/
void idSessionLocal::DispatchCommand( idUserInterface *gui, const char *menuCommand, bool doIngame ) {
if ( !gui ) {
gui = guiActive;
}
if ( gui == guiMainMenu ) {
HandleMainMenuCommands( menuCommand );
return;
} else if ( gui == guiIntro) {
HandleIntroMenuCommands( menuCommand );
} else if ( gui == guiMsg ) {
HandleMsgCommands( menuCommand );
} else if ( gui == guiTakeNotes ) {
HandleNoteCommands( menuCommand );
} else if ( gui == guiRestartMenu ) {
HandleRestartMenuCommands( menuCommand );
} else if ( game && guiActive && guiActive->State().GetBool( "gameDraw" ) ) {
const char *cmd = game->HandleGuiCommands( menuCommand );
if ( !cmd ) {
guiActive = NULL;
} else if ( idStr::Icmp( cmd, "main" ) == 0 ) {
StartMenu();
} else if ( strstr( cmd, "sound " ) == cmd ) {
// pipe the GUI sound commands not handled by the game to the main menu code
HandleMainMenuCommands( cmd );
}
} else if ( guiHandle ) {
if ( (*guiHandle)( menuCommand ) ) {
return;
}
} else if ( !doIngame ) {
common->DPrintf( "idSessionLocal::DispatchCommand: no dispatch found for command '%s'\n", menuCommand );
}
if ( doIngame ) {
HandleInGameCommands( menuCommand );
}
}
/*
==============
idSessionLocal::MenuEvent
Executes any commands returned by the gui
==============
*/
void idSessionLocal::MenuEvent( const sysEvent_t *event ) {
const char *menuCommand;
if ( guiActive == NULL ) {
return;
}
menuCommand = guiActive->HandleEvent( event, com_frameTime );
if ( !menuCommand || !menuCommand[0] ) {
// If the menu didn't handle the event, and it's a key down event for an F key, run the bind
if ( event->evType == SE_KEY && event->evValue2 == 1 && event->evValue >= K_F1 && event->evValue <= K_F12 ) {
idKeyInput::ExecKeyBinding( event->evValue );
}
return;
}
DispatchCommand( guiActive, menuCommand );
}
/*
=================
idSessionLocal::GuiFrameEvents
=================
*/
void idSessionLocal::GuiFrameEvents() {
const char *cmd;
sysEvent_t ev;
idUserInterface *gui;
// stop generating move and button commands when a local console or menu is active
// running here so SP, async networking and no game all go through it
if ( console->Active() || guiActive ) {
usercmdGen->InhibitUsercmd( INHIBIT_SESSION, true );
} else {
usercmdGen->InhibitUsercmd( INHIBIT_SESSION, false );
}
if ( guiTest ) {
gui = guiTest;
} else if ( guiActive ) {
gui = guiActive;
} else {
return;
}
memset( &ev, 0, sizeof( ev ) );
ev.evType = SE_NONE;
cmd = gui->HandleEvent( &ev, com_frameTime );
if ( cmd && cmd[0] ) {
DispatchCommand( guiActive, cmd );
}
}
/*
=================
idSessionLocal::BoxDialogSanityCheck
=================
*/
bool idSessionLocal::BoxDialogSanityCheck( void ) {
if ( !common->IsInitialized() ) {
common->DPrintf( "message box sanity check: !common->IsInitialized()\n" );
return false;
}
if ( !guiMsg ) {
return false;
}
if ( guiMsgRestore ) {
common->DPrintf( "message box sanity check: recursed\n" );
return false;
}
if ( cvarSystem->GetCVarInteger( "net_serverDedicated" ) ) {
common->DPrintf( "message box sanity check: not compatible with dedicated server\n" );
return false;
}
return true;
}
/*
=================
idSessionLocal::MessageBox
=================
*/
const char* idSessionLocal::MessageBox( msgBoxType_t type, const char *message, const char *title, bool wait, const char *fire_yes, const char *fire_no, bool network ) {
common->DPrintf( "MessageBox: %s - %s\n", title ? title : "", message ? message : "" );
if ( !BoxDialogSanityCheck() ) {
return NULL;
}
guiMsg->SetStateString( "title", title ? title : "" );
guiMsg->SetStateString( "message", message ? message : "" );
if ( type == MSG_WAIT ) {
guiMsg->SetStateString( "visible_msgbox", "0" );
guiMsg->SetStateString( "visible_waitbox", "1" );
} else {
guiMsg->SetStateString( "visible_msgbox", "1" );
guiMsg->SetStateString( "visible_waitbox", "0" );
}
guiMsg->SetStateString( "visible_entry", "0" );
guiMsg->SetStateString( "visible_cdkey", "0" );
switch ( type ) {
case MSG_INFO:
guiMsg->SetStateString( "mid", "" );
guiMsg->SetStateString( "visible_mid", "0" );
guiMsg->SetStateString( "visible_left", "0" );
guiMsg->SetStateString( "visible_right", "0" );
break;
case MSG_OK:
guiMsg->SetStateString( "mid", common->GetLanguageDict()->GetString( "#str_04339" ) );
guiMsg->SetStateString( "visible_mid", "1" );
guiMsg->SetStateString( "visible_left", "0" );
guiMsg->SetStateString( "visible_right", "0" );
break;
case MSG_ABORT:
guiMsg->SetStateString( "mid", common->GetLanguageDict()->GetString( "#str_04340" ) );
guiMsg->SetStateString( "visible_mid", "1" );
guiMsg->SetStateString( "visible_left", "0" );
guiMsg->SetStateString( "visible_right", "0" );
break;
case MSG_OKCANCEL:
guiMsg->SetStateString( "left", common->GetLanguageDict()->GetString( "#str_04339" ) );
guiMsg->SetStateString( "right", common->GetLanguageDict()->GetString( "#str_04340" ) );
guiMsg->SetStateString( "visible_mid", "0" );
guiMsg->SetStateString( "visible_left", "1" );
guiMsg->SetStateString( "visible_right", "1" );
break;
case MSG_YESNO:
guiMsg->SetStateString( "left", common->GetLanguageDict()->GetString( "#str_04341" ) );
guiMsg->SetStateString( "right", common->GetLanguageDict()->GetString( "#str_04342" ) );
guiMsg->SetStateString( "visible_mid", "0" );
guiMsg->SetStateString( "visible_left", "1" );
guiMsg->SetStateString( "visible_right", "1" );
break;
case MSG_PROMPT:
guiMsg->SetStateString( "left", common->GetLanguageDict()->GetString( "#str_04339" ) );
guiMsg->SetStateString( "right", common->GetLanguageDict()->GetString( "#str_04340" ) );
guiMsg->SetStateString( "visible_mid", "0" );
guiMsg->SetStateString( "visible_left", "1" );
guiMsg->SetStateString( "visible_right", "1" );
guiMsg->SetStateString( "visible_entry", "1" );
guiMsg->HandleNamedEvent( "Prompt" );
break;
case MSG_CDKEY:
guiMsg->SetStateString( "left", common->GetLanguageDict()->GetString( "#str_04339" ) );
guiMsg->SetStateString( "right", common->GetLanguageDict()->GetString( "#str_04340" ) );
guiMsg->SetStateString( "visible_msgbox", "0" );
guiMsg->SetStateString( "visible_cdkey", "1" );
guiMsg->SetStateString( "visible_hasxp", fileSystem->HasD3XP() ? "1" : "0" );
// the current cdkey / xpkey values may have bad/random data in them
// it's best to avoid printing them completely, unless the key is good
if ( cdkey_state == CDKEY_OK ) {
guiMsg->SetStateString( "str_cdkey", cdkey );
guiMsg->SetStateString( "visible_cdchk", "0" );
} else {
guiMsg->SetStateString( "str_cdkey", "" );
guiMsg->SetStateString( "visible_cdchk", "1" );
}
guiMsg->SetStateString( "str_cdchk", "" );
if ( xpkey_state == CDKEY_OK ) {
guiMsg->SetStateString( "str_xpkey", xpkey );
guiMsg->SetStateString( "visible_xpchk", "0" );
} else {
guiMsg->SetStateString( "str_xpkey", "" );
guiMsg->SetStateString( "visible_xpchk", "1" );
}
guiMsg->SetStateString( "str_xpchk", "" );
guiMsg->HandleNamedEvent( "CDKey" );
break;
case MSG_WAIT:
break;
default:
common->Printf( "idSessionLocal::MessageBox: unknown msg box type\n" );
}
msgFireBack[ 0 ] = fire_yes ? fire_yes : "";
msgFireBack[ 1 ] = fire_no ? fire_no : "";
guiMsgRestore = guiActive;
guiActive = guiMsg;
guiMsg->SetCursor( 325, 290 );
guiActive->Activate( true, com_frameTime );
msgRunning = true;
msgRetIndex = -1;
if ( wait ) {
// play one frame ignoring events so we don't get confused by parasite button releases
msgIgnoreButtons = true;
common->GUIFrame( true, network );
msgIgnoreButtons = false;
while ( msgRunning ) {
common->GUIFrame( true, network );
}
if ( msgRetIndex < 0 ) {
// MSG_WAIT and other StopBox calls
return NULL;
}
if ( type == MSG_PROMPT ) {
if ( msgRetIndex == 0 ) {
guiMsg->State().GetString( "str_entry", "", msgFireBack[ 0 ] );
return msgFireBack[ 0 ].c_str();
} else {
return NULL;
}
} else if ( type == MSG_CDKEY ) {
if ( msgRetIndex == 0 ) {
// the visible_ values distinguish looking at a valid key, or editing it
sprintf( msgFireBack[ 0 ], "%1s;%16s;%2s;%1s;%16s;%2s",
guiMsg->State().GetString( "visible_cdchk" ),
guiMsg->State().GetString( "str_cdkey" ),
guiMsg->State().GetString( "str_cdchk" ),
guiMsg->State().GetString( "visible_xpchk" ),
guiMsg->State().GetString( "str_xpkey" ),
guiMsg->State().GetString( "str_xpchk" ) );
return msgFireBack[ 0 ].c_str();
} else {
return NULL;
}
} else {
return msgFireBack[ msgRetIndex ].c_str();
}
}
return NULL;
}
/*
=================
idSessionLocal::DownloadProgressBox
=================
*/
void idSessionLocal::DownloadProgressBox( backgroundDownload_t *bgl, const char *title, int progress_start, int progress_end ) {
int dlnow = 0, dltotal = 0;
int startTime = Sys_Milliseconds();
int lapsed;
idStr sNow, sTotal, sBW, sETA, sMsg;
if ( !BoxDialogSanityCheck() ) {
return;
}
guiMsg->SetStateString( "visible_msgbox", "1" );
guiMsg->SetStateString( "visible_waitbox", "0" );
guiMsg->SetStateString( "visible_entry", "0" );
guiMsg->SetStateString( "visible_cdkey", "0" );
guiMsg->SetStateString( "mid", "Cancel" );
guiMsg->SetStateString( "visible_mid", "1" );
guiMsg->SetStateString( "visible_left", "0" );
guiMsg->SetStateString( "visible_right", "0" );
guiMsg->SetStateString( "title", title );
guiMsg->SetStateString( "message", "Connecting.." );
guiMsgRestore = guiActive;
guiActive = guiMsg;
msgRunning = true;
while ( 1 ) {
while ( msgRunning ) {
common->GUIFrame( true, false );
if ( bgl->completed ) {
guiActive = guiMsgRestore;
guiMsgRestore = NULL;
return;
} else if ( bgl->url.dltotal != dltotal || bgl->url.dlnow != dlnow ) {
dltotal = bgl->url.dltotal;
dlnow = bgl->url.dlnow;
lapsed = Sys_Milliseconds() - startTime;
sNow.BestUnit( "%.2f", dlnow, MEASURE_SIZE );
if ( lapsed > 2000 ) {
sBW.BestUnit( "%.1f", ( 1000.0f * dlnow ) / lapsed, MEASURE_BANDWIDTH );
} else {
sBW = "-- KB/s";
}
if ( dltotal ) {
sTotal.BestUnit( "%.2f", dltotal, MEASURE_SIZE );
if ( lapsed < 2000 ) {
sprintf( sMsg, "%s / %s", sNow.c_str(), sTotal.c_str() );
} else {
sprintf( sETA, "%.0f sec", ( (float)dltotal / (float)dlnow - 1.0f ) * lapsed / 1000 );
sprintf( sMsg, "%s / %s ( %s - %s )", sNow.c_str(), sTotal.c_str(), sBW.c_str(), sETA.c_str() );
}
} else {
if ( lapsed < 2000 ) {
sMsg = sNow;
} else {
sprintf( sMsg, "%s - %s", sNow.c_str(), sBW.c_str() );
}
}
if ( dltotal ) {
guiMsg->SetStateString( "progress", va( "%d", progress_start + dlnow * ( progress_end - progress_start ) / dltotal ) );
} else {
guiMsg->SetStateString( "progress", "0" );
}
guiMsg->SetStateString( "message", sMsg.c_str() );
}
}
// abort was used - tell the downloader and wait till final stop
bgl->url.status = DL_ABORTING;
guiMsg->SetStateString( "title", "Aborting.." );
guiMsg->SetStateString( "visible_mid", "0" );
// continue looping
guiMsgRestore = guiActive;
guiActive = guiMsg;
msgRunning = true;
}
}
/*
=================
idSessionLocal::StopBox
=================
*/
void idSessionLocal::StopBox() {
if ( guiActive == guiMsg ) {
HandleMsgCommands( "stop" );
}
}
/*
=================
idSessionLocal::HandleMsgCommands
=================
*/
void idSessionLocal::HandleMsgCommands( const char *menuCommand ) {
assert( guiActive == guiMsg );
// "stop" works even on first frame
if ( idStr::Icmp( menuCommand, "stop" ) == 0 ) {
// force hiding the current dialog
guiActive = guiMsgRestore;
guiMsgRestore = NULL;
msgRunning = false;
msgRetIndex = -1;
}
if ( msgIgnoreButtons ) {
common->DPrintf( "MessageBox HandleMsgCommands 1st frame ignore\n" );
return;
}
if ( idStr::Icmp( menuCommand, "mid" ) == 0 || idStr::Icmp( menuCommand, "left" ) == 0 ) {
guiActive = guiMsgRestore;
guiMsgRestore = NULL;
msgRunning = false;
msgRetIndex = 0;
DispatchCommand( guiActive, msgFireBack[ 0 ].c_str() );
} else if ( idStr::Icmp( menuCommand, "right" ) == 0 ) {
guiActive = guiMsgRestore;
guiMsgRestore = NULL;
msgRunning = false;
msgRetIndex = 1;
DispatchCommand( guiActive, msgFireBack[ 1 ].c_str() );
}
}
/*
=================
idSessionLocal::HandleNoteCommands
=================
*/
#define NOTEDATFILE "C:/notenumber.dat"
void idSessionLocal::HandleNoteCommands( const char *menuCommand ) {
guiActive = NULL;
if ( idStr::Icmp( menuCommand, "note" ) == 0 && mapSpawned ) {
idFile *file = NULL;
for ( int tries = 0; tries < 10; tries++ ) {
file = fileSystem->OpenExplicitFileRead( NOTEDATFILE );
if ( file != NULL ) {
break;
}
Sys_Sleep( 500 );
}
int noteNumber = 1000;
if ( file ) {
file->Read( ¬eNumber, 4 );
fileSystem->CloseFile( file );
}
int i;
idStr str, noteNum, shotName, workName, fileName = "viewnotes/";
idStrList fileList;
const char *severity = NULL;
const char *p = guiTakeNotes->State().GetString( "notefile" );
if ( p == NULL || *p == '\0' ) {
p = cvarSystem->GetCVarString( "ui_name" );
}
bool extended = guiTakeNotes->State().GetBool( "extended" );
if ( extended ) {
if ( guiTakeNotes->State().GetInt( "severity" ) == 1 ) {
severity = "WishList_Viewnotes/";
} else {
severity = "MustFix_Viewnotes/";
}
fileName += severity;
const idDecl *mapDecl = declManager->FindType(DECL_ENTITYDEF, mapSpawnData.serverInfo.GetString( "si_map" ), false );
const idDeclEntityDef *mapInfo = static_cast<const idDeclEntityDef *>(mapDecl);
if ( mapInfo ) {
fileName += mapInfo->dict.GetString( "devname" );
} else {
fileName += mapSpawnData.serverInfo.GetString( "si_map" );
fileName.StripFileExtension();
}
int count = guiTakeNotes->State().GetInt( "person_numsel" );
if ( count == 0 ) {
fileList.Append( fileName + "/Nobody" );
} else {
for ( i = 0; i < count; i++ ) {
int person = guiTakeNotes->State().GetInt( va( "person_sel_%i", i ) );
workName = fileName + "/";
workName += guiTakeNotes->State().GetString( va( "person_item_%i", person ), "Nobody" );
fileList.Append( workName );
}
}
} else {
fileName += "maps/";
fileName += mapSpawnData.serverInfo.GetString( "si_map" );
fileName.StripFileExtension();
fileList.Append( fileName );
}
bool bCon = cvarSystem->GetCVarBool( "con_noPrint" );
cvarSystem->SetCVarBool( "con_noPrint", true );
for ( i = 0; i < fileList.Num(); i++ ) {
workName = fileList[i];
workName += "/";
workName += p;
int workNote = noteNumber;
R_ScreenshotFilename( workNote, workName, shotName );
noteNum = shotName;
noteNum.StripPath();
noteNum.StripFileExtension();
if ( severity && *severity ) {
workName = severity;
workName += "viewNotes";
}
sprintf( str, "recordViewNotes \"%s\" \"%s\" \"%s\"\n", workName.c_str(), noteNum.c_str(), guiTakeNotes->State().GetString( "note" ) );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, str );
cmdSystem->ExecuteCommandBuffer();
UpdateScreen();
renderSystem->TakeScreenshot( renderSystem->GetScreenWidth(), renderSystem->GetScreenHeight(), shotName, 1, NULL );
}
noteNumber++;
for ( int tries = 0; tries < 10; tries++ ) {
file = fileSystem->OpenExplicitFileWrite( "p:/viewnotes/notenumber.dat" );
if ( file != NULL ) {
break;
}
Sys_Sleep( 500 );
}
if ( file ) {
file->Write( ¬eNumber, 4 );
fileSystem->CloseFile( file );
}
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "closeViewNotes\n" );
cvarSystem->SetCVarBool( "con_noPrint", bCon );
}
}
/*
===============
idSessionLocal::SetCDKeyGuiVars
===============
*/
void idSessionLocal::SetCDKeyGuiVars( void ) {
if ( !guiMainMenu ) {
return;
}
guiMainMenu->SetStateString( "str_d3key_state", common->GetLanguageDict()->GetString( va( "#str_071%d", 86 + cdkey_state ) ) );
guiMainMenu->SetStateString( "str_xpkey_state", common->GetLanguageDict()->GetString( va( "#str_071%d", 86 + xpkey_state ) ) );
}
|