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
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "crafting_panel.h"
#include "vgui/ISurface.h"
#include "vgui/ISystem.h"
#include "c_tf_player.h"
#include "gamestringpool.h"
#include "iclientmode.h"
#include "tf_item_inventory.h"
#include "ienginevgui.h"
#include <vgui/ILocalize.h>
#include "vgui_controls/TextImage.h"
#include "vgui_controls/CheckButton.h"
#include "vgui_controls/ComboBox.h"
#include <vgui_controls/TextEntry.h>
#include "vgui/IInput.h"
#include "gcsdk/gcclient.h"
#include "gcsdk/gcclientjob.h"
#include "character_info_panel.h"
#include "charinfo_loadout_subpanel.h"
#include "econ_item_system.h"
#include "econ_item_constants.h"
#include "tf_hud_notification_panel.h"
#include "tf_hud_chat.h"
#include "c_tf_gamestats.h"
#include "confirm_dialog.h"
#include "econ_notifications.h"
#include "gc_clientsystem.h"
#include "charinfo_loadout_subpanel.h"
#include "item_selection_criteria.h"
#include "rtime.h"
#include "c_tf_freeaccount.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
ConVar tf_explanations_craftingpanel( "tf_explanations_craftingpanel", "0", FCVAR_ARCHIVE, "Whether the user has seen explanations for this panel." );
struct recipefilter_data_t
{
const char *pszTooltipString;
const char *pszButtonImage;
const char *pszButtonImageMouseover;
};
recipefilter_data_t g_RecipeFilters[NUM_RECIPE_CATEGORIES] =
{
{ "#RecipeFilter_Crafting", "crafticon_crafting_items", "crafticon_crafting_items_over" }, // RECIPE_CATEGORY_CRAFTINGITEMS,
{ "#RecipeFilter_CommonItems", "crafticon_common_items", "crafticon_common_items_over" }, // RECIPE_CATEGORY_COMMONITEMS,
{ "#RecipeFilter_RareItems", "crafticon_rare_items", "crafticon_rare_items_over" }, // RECIPE_CATEGORY_RAREITEMS,
{ "#RecipeFilter_Special", "crafticon_special_blueprints", "crafticon_special_blueprints_over" } // RECIPE_CATEGORY_SPECIAL,
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
wchar_t *LocalizeRecipeStringPiece( const char *pszString, wchar_t *pszConverted, int nConvertedSizeInBytes )
{
if ( !pszString )
return L"";
if ( pszString[0] == '#' )
return g_pVGuiLocalize->Find( pszString );
g_pVGuiLocalize->ConvertANSIToUnicode( pszString, pszConverted, nConvertedSizeInBytes );
return pszConverted;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void SetItemPanelToRecipe( CItemModelPanel *pPanel, const CEconCraftingRecipeDefinition *pRecipeDef, bool bShowName )
{
wchar_t wcTmpName[512];
wchar_t wcTmpDesc[512];
int iNegAttribsBegin = 0;
if ( !pRecipeDef )
{
Q_wcsncpy( wcTmpName, g_pVGuiLocalize->Find( "#Craft_Recipe_Custom" ), sizeof( wcTmpName ) );
Q_wcsncpy( wcTmpDesc, g_pVGuiLocalize->Find( "#Craft_Recipe_CustomDesc" ), sizeof( wcTmpDesc ) );
iNegAttribsBegin = Q_wcslen( wcTmpDesc );
}
else
{
if ( bShowName )
{
wchar_t *pName_A = g_pVGuiLocalize->Find( pRecipeDef->GetName_A() );
g_pVGuiLocalize->ConstructString_safe( wcTmpName, g_pVGuiLocalize->Find( pRecipeDef->GetName() ), 1, pName_A );
}
else
{
wcTmpName[0] = '\0';
}
wchar_t wcTmpA[32];
wchar_t wcTmpB[32];
wchar_t wcTmpC[32];
wchar_t wcTmp[512];
// Build the input string
wchar_t *pInp_A = LocalizeRecipeStringPiece( pRecipeDef->GetDescI_A(), wcTmpA, sizeof( wcTmpA ) );
wchar_t *pInp_B = LocalizeRecipeStringPiece( pRecipeDef->GetDescI_B(), wcTmpB, sizeof( wcTmpB ) );
wchar_t *pInp_C = LocalizeRecipeStringPiece( pRecipeDef->GetDescI_C(), wcTmpC, sizeof( wcTmpC ) );
g_pVGuiLocalize->ConstructString_safe( wcTmpDesc, g_pVGuiLocalize->Find( pRecipeDef->GetDescInputs() ), 3, pInp_A, pInp_B, pInp_C );
iNegAttribsBegin = Q_wcslen(wcTmpDesc);
// Build the output string
wchar_t *pOut_A = LocalizeRecipeStringPiece( pRecipeDef->GetDescO_A(), wcTmpA, sizeof( wcTmpA ) );
wchar_t *pOut_B = LocalizeRecipeStringPiece( pRecipeDef->GetDescO_B(), wcTmpB, sizeof( wcTmpB ) );
wchar_t *pOut_C = LocalizeRecipeStringPiece( pRecipeDef->GetDescO_C(), wcTmpC, sizeof( wcTmpC ) );
g_pVGuiLocalize->ConstructString_safe( wcTmp, g_pVGuiLocalize->Find( pRecipeDef->GetDescOutputs() ), 3, pOut_A, pOut_B, pOut_C );
// Concatenate, and mark the text changes
V_wcscat_safe( wcTmpDesc, L"\n" );
V_wcscat_safe( wcTmpDesc, wcTmp );
}
pPanel->SetAttribOnly( !bShowName );
pPanel->SetTextYPos( 0 );
pPanel->SetItem( NULL );
pPanel->SetNoItemText( wcTmpName, wcTmpDesc, iNegAttribsBegin );
pPanel->InvalidateLayout(true);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void PositionMouseOverPanelForRecipe( vgui::Panel *pScissorPanel, vgui::Panel *pRecipePanel, vgui::ScrollableEditablePanel *pRecipeScroller, CItemModelPanel *pMouseOverItemPanel )
{
int x,y;
vgui::ipanel()->GetAbsPos( pRecipePanel->GetVPanel(), x, y );
int xs,ys;
vgui::ipanel()->GetAbsPos( pMouseOverItemPanel->GetParent()->GetVPanel(), xs, ys );
x -= xs;
y -= ys;
int iXPos = (x + (pRecipePanel->GetWide() * 0.5)) - (pMouseOverItemPanel->GetWide() * 0.5);
int iYPos = (y + pRecipePanel->GetTall());
// Make sure the popup stays onscreen.
if ( iXPos < 0 )
{
iXPos = 0;
}
else if ( (iXPos + pMouseOverItemPanel->GetWide()) > pMouseOverItemPanel->GetParent()->GetWide() )
{
iXPos = pMouseOverItemPanel->GetParent()->GetWide() - pMouseOverItemPanel->GetWide();
}
if ( iYPos < 0 )
{
iYPos = 0;
}
else if ( (iYPos + pMouseOverItemPanel->GetTall() + YRES(32)) > pMouseOverItemPanel->GetParent()->GetTall() )
{
// Move it up above our item
iYPos = y - pMouseOverItemPanel->GetTall() - YRES(4);
}
pMouseOverItemPanel->SetPos( iXPos, iYPos );
pMouseOverItemPanel->SetVisible( true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCraftingPanel::CCraftingPanel( vgui::Panel *parent, const char *panelName ) : CBaseLoadoutPanel( parent, panelName )
{
m_pRecipeListContainer = new vgui::EditablePanel( this, "recipecontainer" );
m_pRecipeListContainerScroller = new vgui::ScrollableEditablePanel( this, m_pRecipeListContainer, "recipecontainerscroller" );
m_pSelectedRecipeContainer = new vgui::EditablePanel( this, "selectedrecipecontainer" );
m_pRecipeButtonsKV = NULL;
m_pRecipeFilterButtonsKV = NULL;
m_bEventLogging = false;
m_iCraftingAttempts = 0;
m_iRecipeCategoryFilter = RECIPE_CATEGORY_CRAFTINGITEMS;
m_iCurrentlySelectedRecipe = -1;
CleanupPostCraft( true );
m_pToolTip = new CTFTextToolTip( this );
m_pToolTipEmbeddedPanel = new vgui::EditablePanel( this, "TooltipPanel" );
m_pToolTipEmbeddedPanel->SetKeyBoardInputEnabled( false );
m_pToolTipEmbeddedPanel->SetMouseInputEnabled( false );
m_pToolTip->SetEmbeddedPanel( m_pToolTipEmbeddedPanel );
m_pToolTip->SetTooltipDelay( 0 );
m_pSelectionPanel = NULL;
m_iSelectingForSlot = 0;
m_pCraftButton = NULL;
m_pUpgradeButton = NULL;
m_pFreeAccountLabel = NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCraftingPanel::~CCraftingPanel( void )
{
if ( m_pRecipeButtonsKV )
{
m_pRecipeButtonsKV->deleteThis();
m_pRecipeButtonsKV = NULL;
}
if ( m_pRecipeFilterButtonsKV )
{
m_pRecipeFilterButtonsKV->deleteThis();
m_pRecipeFilterButtonsKV = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
LoadControlSettings( GetResFile() );
BaseClass::ApplySchemeSettings( pScheme );
m_pRecipeListContainerScroller->GetScrollbar()->SetAutohideButtons( true );
m_pCraftButton = dynamic_cast<CExButton*>( m_pSelectedRecipeContainer->FindChildByName("CraftButton") );
if ( m_pCraftButton )
{
m_pCraftButton->AddActionSignalTarget( this );
}
m_pUpgradeButton = dynamic_cast<CExButton*>( m_pSelectedRecipeContainer->FindChildByName("UpgradeButton") );
if ( m_pUpgradeButton )
{
m_pUpgradeButton->AddActionSignalTarget( this );
}
m_pFreeAccountLabel = dynamic_cast<CExLabel*>( m_pSelectedRecipeContainer->FindChildByName("FreeAccountLabel") );
CreateRecipeFilterButtons();
UpdateRecipeFilter();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::ApplySettings( KeyValues *inResourceData )
{
BaseClass::ApplySettings( inResourceData );
KeyValues *pItemKV = inResourceData->FindKey( "recipebuttons_kv" );
if ( pItemKV )
{
if ( m_pRecipeButtonsKV )
{
m_pRecipeButtonsKV->deleteThis();
}
m_pRecipeButtonsKV = new KeyValues("recipebuttons_kv");
pItemKV->CopySubkeys( m_pRecipeButtonsKV );
}
KeyValues *pButtonKV = inResourceData->FindKey( "recipefilterbuttons_kv" );
if ( pButtonKV )
{
if ( m_pRecipeFilterButtonsKV )
{
m_pRecipeFilterButtonsKV->deleteThis();
}
m_pRecipeFilterButtonsKV = new KeyValues("recipefilterbuttons_kv");
pButtonKV->CopySubkeys( m_pRecipeFilterButtonsKV );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::PerformLayout( void )
{
BaseClass::PerformLayout();
// Need to lay these out before we start making item panels inside them
m_pRecipeListContainer->InvalidateLayout( true );
m_pRecipeListContainerScroller->InvalidateLayout( true );
// Position the recipe filters
FOR_EACH_VEC( m_pRecipeFilterButtons, i )
{
if ( m_pRecipeFilterButtonsKV )
{
m_pRecipeFilterButtons[i]->ApplySettings( m_pRecipeFilterButtonsKV );
m_pRecipeFilterButtons[i]->InvalidateLayout();
}
int iButtonW, iButtonH;
m_pRecipeFilterButtons[i]->GetSize( iButtonW, iButtonH );
int iXPos = (GetWide() * 0.5) + m_iFilterOffcenterX + ((iButtonW + m_iFilterDeltaX) * i);
int iYPos = m_iFilterYPos;// + ((iButtonH + m_iFilterDeltaY) * i);
m_pRecipeFilterButtons[i]->SetPos( iXPos, iYPos );
}
// Position the recipe buttons
for ( int i = 0; i < m_pRecipeButtons.Count(); i++ )
{
if ( m_pRecipeButtonsKV )
{
m_pRecipeButtons[i]->ApplySettings( m_pRecipeButtonsKV );
m_pRecipeButtons[i]->InvalidateLayout();
}
int iYDelta = m_pRecipeButtons[0]->GetTall() + YRES(2);
// Once we've setup our first item, we know how large to make the container
if ( i == 0 )
{
m_pRecipeListContainer->SetSize( m_pRecipeListContainer->GetWide(), iYDelta * m_pRecipeButtons.Count() );
}
int x,y;
m_pRecipeButtons[i]->GetPos( x,y );
m_pRecipeButtons[i]->SetPos( x, (iYDelta * i) );
}
// Now that the container has been sized, tell the scroller to re-evaluate
m_pRecipeListContainerScroller->InvalidateLayout();
m_pRecipeListContainerScroller->GetScrollbar()->InvalidateLayout();
// Then position all our item panels
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
PositionItemPanel( m_pItemModelPanels[i], i );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::CreateRecipeFilterButtons( void )
{
for ( int i = 0; i < NUM_RECIPE_CATEGORIES; i++ )
{
if ( m_pRecipeFilterButtons.Count() <= i )
{
CImageButton *pNewButton = new CImageButton( this, g_RecipeFilters[i].pszTooltipString );
m_pRecipeFilterButtons.AddToTail( pNewButton );
}
m_pRecipeFilterButtons[i]->SetInactiveImage( g_RecipeFilters[i].pszButtonImage );
m_pRecipeFilterButtons[i]->SetActiveImage( g_RecipeFilters[i].pszButtonImageMouseover );
m_pRecipeFilterButtons[i]->SetTooltip( m_pToolTip, g_RecipeFilters[i].pszTooltipString );
const char *pszCommand = VarArgs("selectfilter%d", i );
m_pRecipeFilterButtons[i]->SetCommand( pszCommand );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::UpdateRecipeFilter( void )
{
int iMatchingRecipes = 0;
m_iCurrentlySelectedRecipe = -1;
m_iCurrentRecipeTotalInputs = 0;
m_iCurrentRecipeTotalOutputs = 0;
FOR_EACH_VEC( m_pRecipeFilterButtons, i )
{
bool bForceDepressed = ( i == m_iRecipeCategoryFilter );
m_pRecipeFilterButtons[i]->ForceDepressed( bForceDepressed );
}
// Loop through the known recipes, and see which ones match our category filter
for ( int i = 0; i < TFInventoryManager()->GetLocalTFInventory()->GetRecipeCount(); i++ )
{
const CEconCraftingRecipeDefinition *pRecipeDef = TFInventoryManager()->GetLocalTFInventory()->GetRecipeDef(i);
if ( !pRecipeDef )
continue;
if ( pRecipeDef->IsDisabled() )
continue;
if ( pRecipeDef->GetCategory() != m_iRecipeCategoryFilter )
continue;
wchar_t wTemp[256];
wchar_t *pName_A = g_pVGuiLocalize->Find( pRecipeDef->GetName_A() );
g_pVGuiLocalize->ConstructString_safe( wTemp, g_pVGuiLocalize->Find( pRecipeDef->GetName() ), 1, pName_A );
SetButtonToRecipe( iMatchingRecipes, pRecipeDef->GetDefinitionIndex(), wTemp );
iMatchingRecipes++;
}
// Add a "Custom" option to the bottom of the Special recipe list
if ( m_iRecipeCategoryFilter == RECIPE_CATEGORY_SPECIAL )
{
SetButtonToRecipe( iMatchingRecipes, RECIPE_CUSTOM, g_pVGuiLocalize->Find("#Craft_Recipe_Custom") );
iMatchingRecipes++;
}
// Delete excess buttons
for ( int i = m_pRecipeButtons.Count() - 1; i >= iMatchingRecipes; i-- )
{
m_pRecipeButtons[i]->MarkForDeletion();
m_pRecipeButtons.Remove( i );
}
// Move the scrollbar to the top
m_pRecipeListContainerScroller->GetScrollbar()->SetValue( 0 );
UpdateSelectedRecipe( true );
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnCancelSelection( void )
{
if ( m_pSelectionPanel )
{
m_pSelectionPanel->SetVisible( false );
}
CloseCraftingStatusDialog();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnSelectionReturned( KeyValues *data )
{
if ( data )
{
uint64 ulIndex = data->GetUint64( "itemindex", INVALID_ITEM_ID );
if ( ulIndex == INVALID_ITEM_ID )
{
// should this be INVALID_ITEM_ID?
m_InputItems[m_iSelectingForSlot] = 0;
}
else
{
m_InputItems[m_iSelectingForSlot] = ulIndex;
}
UpdateModelPanels();
UpdateCraftButton();
}
// It'll have deleted itself, so we don't need to clean it up
OnCancelSelection();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnShowPanel( bool bVisible, bool bReturningFromArmory )
{
if ( bVisible )
{
if ( m_pSelectionPanel )
{
m_pSelectionPanel->SetVisible( false );
}
memset( m_InputItems, 0, sizeof(m_InputItems) );
memset( m_ItemPanelCriteria, 0, sizeof(m_ItemPanelCriteria) );
m_iCurrentlySelectedRecipe = -1;
m_iCurrentRecipeTotalInputs = 0;
m_iCurrentRecipeTotalOutputs = 0;
UpdateRecipeFilter();
if ( !m_bEventLogging )
{
m_bEventLogging = true;
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_ENTERED );
}
}
else
{
CloseCraftingStatusDialog();
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
}
BaseClass::OnShowPanel( bVisible, bReturningFromArmory );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnClosing()
{
if ( m_bEventLogging )
{
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_EXITED );
m_bEventLogging = false;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::PositionItemPanel( CItemModelPanel *pPanel, int iIndex )
{
int iCenter = 0;
int iButtonX, iButtonY, iXPos, iYPos;
if ( IsInputItemPanel(iIndex) )
{
iButtonX = (iIndex % CRAFTING_SLOTS_INPUT_COLUMNS);
iButtonY = (iIndex / CRAFTING_SLOTS_INPUT_COLUMNS);
iXPos = (iCenter + m_iItemCraftingOffcenterX) + (iButtonX * m_pItemModelPanels[iIndex]->GetWide()) + (m_iItemBackpackXDelta * iButtonX);
iYPos = m_iItemYPos + (iButtonY * m_pItemModelPanels[iIndex]->GetTall() ) + (m_iItemBackpackYDelta * iButtonY);
}
else
{
int iButtonIndex = iIndex - CRAFTING_SLOTS_INPUTPANELS;
iButtonX = (iButtonIndex % CRAFTING_SLOTS_OUTPUT_COLUMNS);
iButtonY = (iButtonIndex / CRAFTING_SLOTS_OUTPUT_COLUMNS);
iXPos = (iCenter + m_iItemCraftingOffcenterX) + (iButtonX * m_pItemModelPanels[iIndex]->GetWide()) + (m_iItemBackpackXDelta * iButtonX);
iYPos = m_iOutputItemYPos + (iButtonY * m_pItemModelPanels[iIndex]->GetTall() ) + (m_iItemBackpackYDelta * iButtonY);
}
m_pItemModelPanels[iIndex]->SetPos( iXPos, iYPos );
return;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::UpdateRecipeItems( bool bClearInputItems )
{
if ( bClearInputItems )
{
memset( m_InputItems, 0, sizeof(m_InputItems) );
}
memset( m_ItemPanelCriteria, 0, sizeof(m_ItemPanelCriteria) );
m_iCurrentRecipeTotalInputs = 0;
m_iCurrentRecipeTotalOutputs = 0;
if ( m_iCurrentlySelectedRecipe == -1 )
return;
/*
// Build lists of items divided by class & loadout slot, so recipes can quickly test themselves
CUtlVector<CEconItem*> vecAllItems;
CUtlVector<CEconItem*> vecItemsByClass[ LOADOUT_COUNT ];
CUtlVector<CEconItem*> vecItemsBySlot[ LOADOUT_POSITION_COUNT ];
for ( int i = 1; i <= TFInventoryManager()->GetLocalTFInventory()->GetMaxItemCount(); i++ )
{
CEconItemView *pItemData = TFInventoryManager()->GetItemByBackpackPosition(i);
if ( pItemData && pItemData->IsValid() )
{
CEconItem *pSOCData = pItemData->GetSOCData();
vecAllItems.AddToTail( pSOCData );
CTFItemDefinition *pItemDef = pItemData->GetStaticData();
// Put it in class lists for any class that can use it. Use the zeroth list as all-class items.
if ( pItemDef->CanBeUsedByAllClasses() )
{
vecItemsByClass[0].AddToTail( pSOCData );
}
for (int iClass = TF_FIRST_NORMAL_CLASS; iClass < TF_LAST_NORMAL_CLASS; iClass++ )
{
if ( pItemDef->CanBeUsedByClass(iClass) )
{
vecItemsByClass[iClass].AddToTail( pSOCData );
}
}
// Put it in the slot lists for any slot that it can be equipped in
for (int iSlot = 0; iSlot < LOADOUT_POSITION_COUNT; iSlot++ )
{
if ( pItemDef->CanBePlacedInSlot( iSlot ) )
{
vecItemsBySlot[iSlot].AddToTail( pSOCData );
}
}
}
}
*/
// Find the items needed for the specified recipe
if ( m_iCurrentlySelectedRecipe == RECIPE_CUSTOM )
{
// Custom recipe. Show all open buttons, and let them put anything in there.
m_iCurrentRecipeTotalInputs = CRAFTING_SLOTS_INPUTPANELS;
m_iCurrentRecipeTotalOutputs = 0;
FOR_EACH_VEC( m_pItemModelPanels, i )
{
m_pItemModelPanels[i]->SetNoItemText( "" );
}
}
else
{
const CTFCraftingRecipeDefinition *pRecipeDef = (CTFCraftingRecipeDefinition*)TFInventoryManager()->GetLocalTFInventory()->GetRecipeDefByDefIndex( m_iCurrentlySelectedRecipe );
if ( pRecipeDef )
{
m_iCurrentRecipeTotalInputs = pRecipeDef->GetTotalInputItemsRequired();
m_iCurrentRecipeTotalOutputs = pRecipeDef->GetTotalOutputItems();
CUtlVector<itemid_t> vecItemsUsed;
// Set the text in each of the item panels
const CUtlVector<CItemSelectionCriteria> *vecInputCriteria;
vecInputCriteria = pRecipeDef->GetInputItems();
CUtlVector<uint32> vecInputDupes;
vecInputDupes = pRecipeDef->GetInputItemDupeCounts();
int iModelPanel = 0;
FOR_EACH_VEC( *vecInputCriteria, i )
{
const char *pszNoItemText = GetItemTextForCriteria( &(*vecInputCriteria)[i] );
int iNumPanels = vecInputDupes[i] ? vecInputDupes[i] : 1;
for ( int iPanel = 0; iPanel < iNumPanels; iPanel++ )
{
m_ItemPanelCriteria[iModelPanel] = &(*vecInputCriteria)[i];
if ( m_pItemModelPanels[iModelPanel] )
{
m_pItemModelPanels[iModelPanel]->SetNoItemText( pszNoItemText );
}
iModelPanel++;
}
}
// Set the output items as well
CUtlVector<CItemSelectionCriteria> vecOutputCriteria;
vecOutputCriteria = pRecipeDef->GetOutputItems();
FOR_EACH_VEC( vecOutputCriteria, i )
{
int iOutputPanel = CRAFTING_SLOTS_INPUTPANELS + i;
CEconItemDefinition *pDef = GetItemDefFromCriteria( &vecOutputCriteria[i] );
if ( pDef )
{
//m_pItemModelPanels[iOutputPanel]->SetNoItemText( pszNoItemText );
CEconItemView *pItemData = new CEconItemView();
pItemData->Init( pDef->GetDefinitionIndex(), AE_UNIQUE, AE_USE_SCRIPT_VALUE, true );
if ( m_pItemModelPanels[iOutputPanel] )
{
m_pItemModelPanels[iOutputPanel]->SetItem( pItemData );
}
delete pItemData;
continue;
}
// If we didn't manage to extract an output, just use the recipe output string
wchar_t wcTmpA[32];
wchar_t wcTmpB[32];
wchar_t wcTmpC[32];
wchar_t wcTmp[512];
wchar_t *pOut_A = LocalizeRecipeStringPiece( pRecipeDef->GetDescO_A(), wcTmpA, sizeof( wcTmpA ) );
wchar_t *pOut_B = LocalizeRecipeStringPiece( pRecipeDef->GetDescO_B(), wcTmpB, sizeof( wcTmpB ) );
wcTmp[0] = '\0';
V_wcscat_safe( wcTmp, pOut_A );
V_wcscat_safe( wcTmp, L" " );
V_wcscat_safe( wcTmp, pOut_B );
if ( Q_strnicmp( pRecipeDef->GetDescOutputs(), "#RDO_ABC", 8 ) == 0 )
{
wchar_t *pOut_C = LocalizeRecipeStringPiece( pRecipeDef->GetDescO_C(), wcTmpC, sizeof( wcTmpC ) );
V_wcscat_safe( wcTmp, L" " );
V_wcscat_safe( wcTmp, pOut_C );
}
if ( m_pItemModelPanels[iOutputPanel] )
{
m_pItemModelPanels[iOutputPanel]->SetItem( NULL );
m_pItemModelPanels[iOutputPanel]->SetNoItemText( wcTmp );
}
}
}
}
// Now check to see if they've got the right items in there
UpdateCraftButton();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::UpdateCraftButton( void )
{
if ( m_iCurrentlySelectedRecipe == -1 )
return;
bool bAllowedToUse = true;
const CEconCraftingRecipeDefinition *pRecipeDef = NULL;
if ( m_iCurrentlySelectedRecipe != RECIPE_CUSTOM )
{
pRecipeDef = (CTFCraftingRecipeDefinition*)TFInventoryManager()->GetLocalTFInventory()->GetRecipeDefByDefIndex( m_iCurrentlySelectedRecipe );
if ( !pRecipeDef )
return;
bAllowedToUse = ( !IsFreeTrialAccount() || !pRecipeDef->IsPremiumAccountOnly() );
}
if ( m_pCraftButton )
{
m_pCraftButton->SetVisible( bAllowedToUse );
}
if ( m_pUpgradeButton )
{
m_pUpgradeButton->SetVisible( !bAllowedToUse );
}
if ( m_pFreeAccountLabel )
{
m_pFreeAccountLabel->SetVisible( !bAllowedToUse );
}
if ( !bAllowedToUse )
return;
bool bCraftButtonActive = false;
if ( m_iCurrentlySelectedRecipe == RECIPE_CUSTOM )
{
// Need at least one item in a slot
for ( int i = 0; i < CRAFTING_SLOTS_INPUTPANELS; i++ )
{
CEconItemView *pItemData = TFInventoryManager()->GetLocalTFInventory()->GetInventoryItemByItemID( m_InputItems[i] );
if ( pItemData )
{
bCraftButtonActive = true;
break;
}
}
}
else
{
CUtlVector<CEconItem*> vecAllItems;
for ( int i = 0; i < CRAFTING_SLOTS_INPUTPANELS; i++ )
{
CEconItemView *pItemData = TFInventoryManager()->GetLocalTFInventory()->GetInventoryItemByItemID( m_InputItems[i] );
if ( pItemData )
{
vecAllItems.AddToTail( pItemData->GetSOCData() );
}
}
bCraftButtonActive = pRecipeDef->ItemListMatchesInputs( &vecAllItems, NULL, false, NULL );
}
if ( m_pCraftButton )
{
m_pCraftButton->SetEnabled( bCraftButtonActive );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CCraftingPanel::GetItemTextForCriteria( const CItemSelectionCriteria *pCriteria )
{
// Otherwise, look at the first condition, and see if we can determine what the item is
const char *pszVal = pCriteria->GetValueForFirstConditionOfType( k_EOperator_String_EQ );
if ( pszVal && pszVal[0] )
{
// Is it a loadout slot?
int iSlot = StringFieldToInt( pszVal, ItemSystem()->GetItemSchema()->GetLoadoutStrings( EEquipType_t::EQUIP_TYPE_CLASS ), true );
if ( iSlot != -1 )
return ItemSystem()->GetItemSchema()->GetLoadoutStringsForDisplay( EEquipType_t::EQUIP_TYPE_CLASS )[iSlot];
// Is it a craft material type?
if ( V_stricmp( pszVal, "weapon" ) == 0 )
{
return "#RI_W";
}
else if ( V_stricmp( pszVal, "hat" ) == 0 )
{
return "#RI_Hg";
}
else if ( V_stricmp( pszVal, "craft_token" ) == 0 )
{
return "#RI_T";
}
else if ( V_stricmp( pszVal, "class_token" ) == 0 )
{
return "#CI_T_C";
}
else if ( V_stricmp( pszVal, "slot_token" ) == 0 )
{
return "#CI_T_S";
}
// Is it an item name?
CEconItemDefinition *pDef = ItemSystem()->GetItemSchema()->GetItemDefinitionByName(pszVal);
if ( pDef )
return pDef->GetItemBaseName();
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CEconItemDefinition *CCraftingPanel::GetItemDefFromCriteria( const CItemSelectionCriteria *pCriteria )
{
// Otherwise, look at the first condition, and see if we can determine what the item is
const char *pszVal = pCriteria->GetValueForFirstConditionOfType( k_EOperator_String_EQ );
if ( pszVal && pszVal[0] )
return ItemSystem()->GetItemSchema()->GetItemDefinitionByName(pszVal);
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::AddNewItemPanel( int iPanelIndex )
{
BaseClass::AddNewItemPanel( iPanelIndex );
// Move the model panels to our selected recipe container
m_pItemModelPanels[iPanelIndex]->SetParent( m_pSelectedRecipeContainer );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::UpdateModelPanels( void )
{
BaseClass::UpdateModelPanels();
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
if ( IsInputItemPanel(i) )
{
if ( m_InputItems[i] != 0 )
{
CEconItemView *pItemData = TFInventoryManager()->GetLocalTFInventory()->GetInventoryItemByItemID( m_InputItems[i] );
m_pItemModelPanels[i]->SetItem( pItemData );
m_pItemModelPanels[i]->SetVisible( true );
m_pItemModelPanels[i]->SetShowEquipped( true );
SetBorderForItem( m_pItemModelPanels[i], false );
}
else
{
m_pItemModelPanels[i]->SetItem( NULL );
// Always show the number of slots that the recipe uses
bool bVisible = (m_iCurrentRecipeTotalInputs > i);
m_pItemModelPanels[i]->SetVisible( bVisible );
}
}
else
{
bool bVisible = ((m_iCurrentRecipeTotalOutputs + CRAFTING_SLOTS_INPUTPANELS) > i);
m_pItemModelPanels[i]->SetVisible( bVisible );
}
}
vgui::Panel *pLabel = m_pSelectedRecipeContainer->FindChildByName("OutputLabel");
if ( pLabel )
{
pLabel->SetVisible( m_iCurrentRecipeTotalOutputs > 0 );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::SetButtonToRecipe( int iButton, int iDefIndex, wchar_t *pszText )
{
// Re-use existing buttons, or make new ones if we need more
CRecipeButton *pRecipeButton = NULL;
if ( iButton < m_pRecipeButtons.Count() )
{
pRecipeButton = m_pRecipeButtons[iButton];
}
else
{
pRecipeButton = new CRecipeButton( m_pRecipeListContainer, "selectrecipe", "", this, "selectrecipe" );
if ( m_pRecipeButtonsKV )
{
pRecipeButton->ApplySettings( m_pRecipeButtonsKV );
}
pRecipeButton->MakeReadyForUse();
m_pRecipeButtons.AddToTail( pRecipeButton );
}
const char *pszCommand = VarArgs("selectrecipe%d", iDefIndex );
pRecipeButton->SetCommand( pszCommand );
pRecipeButton->SetText( pszText );
pRecipeButton->SetDefIndex( iDefIndex );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::UpdateSelectedRecipe( bool bClearInputItems )
{
for ( int i = 0; i < m_pRecipeButtons.Count(); i++ )
{
bool bSelected = m_pRecipeButtons[i]->m_iRecipeDefIndex == m_iCurrentlySelectedRecipe;
m_pRecipeButtons[i]->ForceDepressed( bSelected );
m_pRecipeButtons[i]->RecalculateDepressedState();
if ( bSelected )
{
wchar_t wszText[1024];
m_pRecipeButtons[i]->GetText( wszText, ARRAYSIZE( wszText ) );
m_pSelectedRecipeContainer->SetDialogVariable( "recipetitle", wszText );
if ( m_iCurrentlySelectedRecipe == RECIPE_CUSTOM )
{
m_pSelectedRecipeContainer->SetDialogVariable( "recipeinputstring", g_pVGuiLocalize->Find("#Craft_Recipe_CustomDesc") );
}
else
{
const CTFCraftingRecipeDefinition *pRecipeDef = (CTFCraftingRecipeDefinition*)TFInventoryManager()->GetLocalTFInventory()->GetRecipeDefByDefIndex( m_iCurrentlySelectedRecipe );
if ( pRecipeDef )
{
// Build the input string
wchar_t wcTmpA[32];
wchar_t wcTmpB[32];
wchar_t wcTmpC[32];
wchar_t wcTmpDesc[512];
wchar_t *pInp_A = LocalizeRecipeStringPiece( pRecipeDef->GetDescI_A(), wcTmpA, sizeof( wcTmpA ) );
wchar_t *pInp_B = LocalizeRecipeStringPiece( pRecipeDef->GetDescI_B(), wcTmpB, sizeof( wcTmpB ) );
wchar_t *pInp_C = LocalizeRecipeStringPiece( pRecipeDef->GetDescI_C(), wcTmpC, sizeof( wcTmpC ) );
g_pVGuiLocalize->ConstructString_safe( wcTmpDesc, g_pVGuiLocalize->Find( pRecipeDef->GetDescInputs() ), 3, pInp_A, pInp_B, pInp_C );
m_pSelectedRecipeContainer->SetDialogVariable( "recipeinputstring", wcTmpDesc );
}
}
}
}
m_pSelectedRecipeContainer->SetVisible( m_iCurrentlySelectedRecipe != -1 );
UpdateRecipeItems( bClearInputItems );
UpdateModelPanels();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnCommand( const char *command )
{
if ( !Q_strnicmp( command, "selectrecipe", 12 ) )
{
const char *pszNum = command+12;
if ( pszNum && pszNum[0] )
{
m_iCurrentlySelectedRecipe = atoi(pszNum);
UpdateSelectedRecipe( true );
}
return;
}
if ( !Q_strnicmp( command, "selectfilter", 12 ) )
{
const char *pszNum = command+12;
if ( pszNum && pszNum[0] )
{
m_iRecipeCategoryFilter = (recipecategories_t)atoi(pszNum);
UpdateRecipeFilter();
}
return;
}
else if ( !Q_strnicmp( command, "back", 4 ) )
{
PostMessage( GetParent(), new KeyValues("CraftingClosed") );
return;
}
else if ( !Q_strnicmp( command, "craft", 5 ) )
{
if ( CheckForUntradableItems() )
{
Craft();
}
return;
}
else if ( !Q_stricmp( command, "upgrade" ) )
{
EconUI()->CloseEconUI();
EconUI()->OpenStorePanel( STOREPANEL_SHOW_UPGRADESTEPS, false );
return;
}
else if ( !Q_stricmp( command, "reloadscheme" ) )
{
InvalidateLayout( true, true );
}
BaseClass::OnCommand( command );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnRecipePanelEntered( vgui::Panel *panel )
{
CRecipeButton *pRecipePanel = dynamic_cast < CRecipeButton * > ( panel );
if ( pRecipePanel && IsVisible() && !IsIgnoringItemPanelEnters() )
{
const CEconCraftingRecipeDefinition *pRecipeDef = NULL;
if ( pRecipePanel->m_iRecipeDefIndex != RECIPE_CUSTOM )
{
pRecipeDef = TFInventoryManager()->GetLocalTFInventory()->GetRecipeDefByDefIndex( pRecipePanel->m_iRecipeDefIndex );
}
SetItemPanelToRecipe( GetMouseOverPanel(), pRecipeDef, false );
PositionMouseOverPanelForRecipe( this, pRecipePanel, m_pRecipeListContainerScroller, GetMouseOverPanel() );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnRecipePanelExited( vgui::Panel *panel )
{
GetMouseOverPanel()->SetAttribOnly( false );
GetMouseOverPanel()->SetTextYPos( YRES(20) );
GetMouseOverPanel()->SetVisible( false );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CCraftingPanel::GetItemPanelIndex( CItemModelPanel *pItemPanel )
{
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
if ( m_pItemModelPanels[i] == pItemPanel )
return i;
}
return -1;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnItemPanelMousePressed( vgui::Panel *panel )
{
CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
if ( pItemPanel && IsVisible() && !pItemPanel->IsGreyedOut() )
{
int iPos = GetItemPanelIndex(pItemPanel);
if ( IsInputItemPanel(iPos) )
{
m_iSelectingForSlot = iPos;
// Create it the first time around
if ( !m_pSelectionPanel )
{
m_pSelectionPanel = new CCraftingItemSelectionPanel( this );
}
if ( m_iCurrentlySelectedRecipe == RECIPE_CUSTOM )
{
m_pSelectionPanel->UpdateOnShow( NULL, true, m_InputItems, ARRAYSIZE(m_InputItems) );
}
else
{
// Clicked on an item in the crafting area. Open up the selection panel.
m_pSelectionPanel->UpdateOnShow( m_ItemPanelCriteria[iPos], false, m_InputItems, ARRAYSIZE(m_InputItems) );
}
m_pSelectionPanel->ShowDuplicateCounts( true );
m_pSelectionPanel->ShowPanel( 0, true );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
static void ConfirmCraft( bool bConfirmed, void* pContext )
{
CCraftingPanel *pCraftingPanel = ( CCraftingPanel* )pContext;
if ( bConfirmed )
{
pCraftingPanel->Craft();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CCraftingPanel::CheckForUntradableItems( void )
{
bool bHasUntradable = false;
for ( int i = 0; i < CRAFTING_SLOTS_INPUTPANELS; i++ )
{
if ( m_InputItems[i] != 0 )
{
CEconItemView *pItemData = TFInventoryManager()->GetLocalTFInventory()->GetInventoryItemByItemID( m_InputItems[i] );
if ( pItemData->IsTradable() == false )
{
bHasUntradable = true;
break;
}
}
}
if ( bHasUntradable )
{
CTFGenericConfirmDialog *pDialog = ShowConfirmDialog( "#Craft_Untradable_Title", "#Craft_Untradable_Text", "#GameUI_OK", "#Cancel", &ConfirmCraft );
pDialog->SetContext( this );
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::Craft( void )
{
// Build our list of items that we're trying to craft
++m_iCraftingAttempts;
CUtlVector<itemid_t> vecCraftingItems;
for ( int i = 0; i < CRAFTING_SLOTS_INPUTPANELS; i++ )
{
if ( m_InputItems[i] != 0 )
{
CEconItemView *pItemData = TFInventoryManager()->GetLocalTFInventory()->GetInventoryItemByItemID( m_InputItems[i] );
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_ATTEMPT, pItemData, m_iCraftingAttempts );
vecCraftingItems.AddToTail( m_InputItems[i] );
}
}
if ( !vecCraftingItems.Count() )
return;
GCSDK::CGCMsg<MsgGCCraft_t> msg( k_EMsgGCCraft );
msg.Body().m_nRecipeDefIndex = m_iCurrentlySelectedRecipe;
msg.Body().m_nItemCount = vecCraftingItems.Count();
for ( int i = 0; i < vecCraftingItems.Count(); i++ )
{
msg.AddUint64Data( vecCraftingItems[i] );
}
GCClientSystem()->BSendMessage( msg );
OpenCraftingStatusDialog( this, "#CraftUpdate_Start", true, false, false );
// Start ticking so we can give up waiting if we don't get a response from the GC
// We use the VGUI time, because we may not be in a game at all.
m_flAbortCraftingAt = vgui::system()->GetCurrentTime() + 10;
m_bWaitingForCraftItems = false;
m_iRecipeIndexTried = m_iCurrentlySelectedRecipe;
vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnCraftResponse( EGCMsgResponse eResponse, CUtlVector<uint64> *vecCraftedIndices, int iRecipeUsed )
{
switch ( eResponse )
{
case k_EGCMsgResponseNoMatch:
{
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_NO_RECIPE_MATCH, NULL, m_iCraftingAttempts );
CleanupPostCraft( m_iCurrentlySelectedRecipe != RECIPE_CUSTOM );
OpenCraftingStatusDialog( this, "#CraftUpdate_NoMatch", false, true, false );
}
break;
case k_EGCMsgResponseDenied:
{
// Craft denied.
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_FAILURE, NULL, m_iCraftingAttempts );
CleanupPostCraft( m_iCurrentlySelectedRecipe != RECIPE_CUSTOM );
OpenCraftingStatusDialog( this, "#CraftUpdate_Denied", false, true, false );
}
break;
// We've got the list of items crafted. We save off the item list until our item cache has all the items.
case k_EGCMsgResponseOK:
{
// Start ticking, and wait until the cache contains all the items in the list.
m_bWaitingForCraftItems = true;
m_vecNewlyCraftedItems = *vecCraftedIndices;
if ( iRecipeUsed != m_iRecipeIndexTried && iRecipeUsed != -1 )
{
m_iNewRecipeIndex = iRecipeUsed;
}
}
break;
default:
{
// Craft failed in some way.
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_FAILURE, NULL, m_iCraftingAttempts );
OpenCraftingStatusDialog( this, "#CraftUpdate_Failed", false, true, false );
CleanupPostCraft( m_iCurrentlySelectedRecipe != RECIPE_CUSTOM );
}
break;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::ShowCraftFinish( void )
{
TFInventoryManager()->ShowItemsCrafted( &m_vecNewlyCraftedItems );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::OnTick( void )
{
BaseClass::OnTick();
if ( IsVisible() )
{
if ( m_flAbortCraftingAt )
{
if ( m_flAbortCraftingAt < vgui::system()->GetCurrentTime() )
{
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_TIMEOUT, NULL, m_iCraftingAttempts );
CleanupPostCraft( m_iCurrentlySelectedRecipe != RECIPE_CUSTOM );
OpenCraftingStatusDialog( this, "#CraftUpdate_Failed", false, true, false );
return;
}
}
if ( m_bWaitingForCraftItems )
{
// If all the items in our newly crafted list are in the cache, we can show the pickup.
FOR_EACH_VEC_BACK( m_vecNewlyCraftedItems, i )
{
CEconItemView* pNewItem = InventoryManager()->GetLocalInventory()->GetInventoryItemByItemID( m_vecNewlyCraftedItems[i] );
if ( pNewItem == NULL )
return;
C_CTF_GameStats.Event_Crafting( IE_CRAFTING_SUCCESS, pNewItem, m_iCraftingAttempts );
}
m_bWaitingForCraftItems = false;
// We have all the new items, show the pickup
OpenCraftingStatusDialog( this, "#CraftUpdate_Success", false, true, true );
CleanupPostCraft( true );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingPanel::CleanupPostCraft( bool bClearInputItems )
{
m_flAbortCraftingAt = 0;
m_bWaitingForCraftItems = false;
UpdateSelectedRecipe( bClearInputItems );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
ConVar *CCraftingPanel::GetExplanationConVar( void )
{
return &tf_explanations_craftingpanel;
}
//================================================================================================================================
// NOT CONNECTED TO STEAM WARNING DIALOG
//================================================================================================================================
static vgui::DHANDLE<CCraftingStatusDialog> g_CraftingStatusPanel;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCraftingStatusDialog::CCraftingStatusDialog( vgui::Panel *pParent, const char *pElementName ) : BaseClass( pParent, "CraftingStatusDialog" )
{
m_pRecipePanel = vgui::SETUP_PANEL( new CItemModelPanel( this, "RecipeItemModelPanel" ) );
m_bShowNewRecipe = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingStatusDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
if ( m_bShowNewRecipe )
{
LoadControlSettings( "resource/UI/NewRecipeFoundDialog.res" );
}
else
{
LoadControlSettings( "resource/UI/CraftingStatusDialog.res" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingStatusDialog::OnCommand( const char *command )
{
bool bClose = false;
if ( !Q_stricmp( command, "close" ) )
{
// If we were a success, show the player their new crafted items
if ( m_bShowOnExit )
{
if ( EconUI()->GetCraftingPanel() )
{
EconUI()->GetCraftingPanel()->ShowCraftFinish();
}
m_bShowOnExit = false;
}
bClose = true;
}
else if ( !Q_stricmp( command, "forceclose" ) )
{
bClose = true;
}
if ( bClose )
{
m_bShowOnExit = false;
TFModalStack()->PopModal( this );
SetVisible( false );
MarkForDeletion();
EconUI()->SetPreventClosure( false );
return;
}
BaseClass::OnCommand( command );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingStatusDialog::OnTick( void )
{
if ( !m_bAnimateEllipses || !IsVisible() )
{
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
}
else
{
m_iNumEllipses = ((m_iNumEllipses+1) % 4);
}
switch ( m_iNumEllipses )
{
case 3: SetDialogVariable( "ellipses", L"..." ); break;
case 2: SetDialogVariable( "ellipses", L".." ); break;
case 1: SetDialogVariable( "ellipses", L"." ); break;
default: SetDialogVariable( "ellipses", L"" ); break;
}
BaseClass::OnTick();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingStatusDialog::UpdateSchemeForVersion( bool bRecipe )
{
m_bShowNewRecipe = bRecipe;
InvalidateLayout( false, true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCraftingStatusDialog::ShowStatusUpdate( bool bAnimateEllipses, bool bAllowClose, bool bShowOnExit )
{
m_bShowNewRecipe = false;
CExButton *pButton = dynamic_cast<CExButton*>( FindChildByName("CloseButton") );
if ( pButton )
{
pButton->SetVisible( bAllowClose );
pButton->SetEnabled( bAllowClose );
}
m_bAnimateEllipses = bAnimateEllipses;
if ( m_bAnimateEllipses )
{
vgui::ivgui()->AddTickSignal( GetVPanel(), 500 );
SetDialogVariable( "ellipses", L"" );
m_iNumEllipses = 0;
}
else
{
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
SetDialogVariable( "ellipses", L"" );
}
m_bShowOnExit = bShowOnExit;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void SetupCraftingStatusDialog( vgui::Panel *pParent )
{
if (!g_CraftingStatusPanel.Get())
{
g_CraftingStatusPanel = vgui::SETUP_PANEL( new CCraftingStatusDialog( pParent, NULL ) );
}
g_CraftingStatusPanel->SetVisible( true );
g_CraftingStatusPanel->MakePopup();
g_CraftingStatusPanel->MoveToFront();
g_CraftingStatusPanel->SetKeyBoardInputEnabled(true);
g_CraftingStatusPanel->SetMouseInputEnabled(true);
TFModalStack()->PushModal( g_CraftingStatusPanel );
EconUI()->SetPreventClosure( true );
}
CCraftingStatusDialog *OpenCraftingStatusDialog( vgui::Panel *pParent, const char *pszText, bool bAnimateEllipses, bool bAllowClose, bool bShowOnExit )
{
SetupCraftingStatusDialog( pParent );
g_CraftingStatusPanel->UpdateSchemeForVersion( false );
g_CraftingStatusPanel->SetDialogVariable( "updatetext", g_pVGuiLocalize->Find( pszText ) );
g_CraftingStatusPanel->ShowStatusUpdate( bAnimateEllipses, bAllowClose, bShowOnExit );
return g_CraftingStatusPanel;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CloseCraftingStatusDialog( void )
{
if ( g_CraftingStatusPanel )
{
g_CraftingStatusPanel->OnCommand( "forceclose" );
}
}
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the craft response
//-----------------------------------------------------------------------------
class CGCCraftResponse : public GCSDK::CGCClientJob
{
public:
CGCCraftResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CGCMsg<MsgGCStandardResponse_t> msg( pNetPacket );
CUtlVector<uint64> vecCraftedIndices;
uint16 iItems = 0;
if ( !msg.BReadUint16Data( &iItems ) )
return true;
vecCraftedIndices.SetSize( iItems );
for ( int i = 0; i < iItems; i++ )
{
if( !msg.BReadUint64Data( &vecCraftedIndices[i] ) )
return true;
}
if ( EconUI()->GetCraftingPanel() )
{
EconUI()->GetCraftingPanel()->OnCraftResponse( (EGCMsgResponse)msg.Body().m_eResponse, &vecCraftedIndices, msg.Body().m_nResponseIndex );
}
//Msg("RECEIVED CGCCraftResponse: %d\n", msg.Body().m_eResponse );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCCraftResponse, "CGCCraftResponse", k_EMsgGCCraftResponse, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the Golden Wrench broadcast message
//-----------------------------------------------------------------------------
class CGCGoldenWrenchBroadcast : public GCSDK::CGCClientJob
{
public:
CGCGoldenWrenchBroadcast( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg<CMsgTFGoldenWrenchBroadcast> msg( pNetPacket );
// @todo Tom Bui: should we display this in some other manner? This gets covered up by the crafting panel.
CHudNotificationPanel *pNotifyPanel = GET_HUDELEMENT( CHudNotificationPanel );
if ( pNotifyPanel )
{
bool bDeleted = msg.Body().deleted();
wchar_t szPlayerName[1024];
g_pVGuiLocalize->ConvertANSIToUnicode( msg.Body().user_name().c_str(), szPlayerName, sizeof(szPlayerName) );
wchar_t szWrenchNumber[16]=L"";
_snwprintf( szWrenchNumber, ARRAYSIZE( szWrenchNumber ), L"%i", msg.Body().wrench_number() );
wchar_t szNotification[1024]=L"";
g_pVGuiLocalize->ConstructString_safe( szNotification,
g_pVGuiLocalize->Find( bDeleted ? "#TF_HUD_Event_GoldenWrench_D": "#TF_HUD_Event_GoldenWrench_C" ),
2, szPlayerName, szWrenchNumber );
pNotifyPanel->SetupNotifyCustom( szNotification, HUD_NOTIFY_GOLDEN_WRENCH, 10.0f );
// echo to chat
CBaseHudChat *pHUDChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );
if ( pHUDChat )
{
char szAnsi[1024];
g_pVGuiLocalize->ConvertUnicodeToANSI( szNotification, szAnsi, sizeof(szAnsi) );
pHUDChat->Printf( CHAT_FILTER_NONE, "%s", szAnsi );
}
// play a sound
vgui::surface()->PlaySound( bDeleted ? "vo/announcer_failure.mp3" : "vo/announcer_success.mp3" );
}
//Msg("RECEIVED CGCCraftResponse: %d\n", msg.Body().m_eResponse );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCGoldenWrenchBroadcast, "CGCGoldenWrenchBroadcast", k_EMsgGCGoldenWrenchBroadcast, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the Saxxy broadcast message
//-----------------------------------------------------------------------------
class CGSaxxyBroadcast : public GCSDK::CGCClientJob
{
public:
CGSaxxyBroadcast( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg<CMsgTFSaxxyBroadcast> msg( pNetPacket );
CEconNotification *pNotification = new CEconNotification();
pNotification->SetText( "#TF_Event_Saxxy_Deleted" );
pNotification->SetLifetime( 30.0f );
{
// Who deleted this?
wchar_t wszPlayerName[ MAX_PLAYER_NAME_LENGTH ];
g_pVGuiLocalize->ConvertANSIToUnicode( msg.Body().has_user_name() ? msg.Body().user_name().c_str() : NULL, wszPlayerName, sizeof( wszPlayerName ) );
pNotification->AddStringToken( "owner", wszPlayerName );
// What category was the Saxxy for?
char szCategory[MAX_ATTRIBUTE_DESCRIPTION_LENGTH];
Q_snprintf( szCategory, sizeof( szCategory ), "Replay_Contest_Category%d", msg.Body().category_number() );
pNotification->AddStringToken( "category", g_pVGuiLocalize->Find( szCategory ) );
}
NotificationQueue_Add( pNotification );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGSaxxyBroadcast, "CGSaxxyBroadcast", k_EMsgGCSaxxyBroadcast, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive any generic item deletion notification
//-----------------------------------------------------------------------------
class CClientItemBroadcastNotificationJob : public GCSDK::CGCClientJob
{
public:
CClientItemBroadcastNotificationJob( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg<CMsgGCTFSpecificItemBroadcast> msg( pNetPacket );
CEconNotification *pNotification = new CEconNotification();
pNotification->SetText( msg.Body().was_destruction() ? "#TF_Event_Item_Deleted" : "#TF_Event_Item_Created" );
pNotification->SetLifetime( 30.0f );
// Who deleted this?
wchar_t wszPlayerName[ MAX_PLAYER_NAME_LENGTH ];
g_pVGuiLocalize->ConvertANSIToUnicode( msg.Body().has_user_name() ? msg.Body().user_name().c_str() : NULL, wszPlayerName, sizeof( wszPlayerName ) );
pNotification->AddStringToken( "owner", wszPlayerName );
// What type of item was this?
const CEconItemDefinition *pItemDef = GetItemSchema()->GetItemDefinition( msg.Body().item_def_index() );
if ( pItemDef )
{
pNotification->AddStringToken( "item_name", g_pVGuiLocalize->Find( pItemDef->GetItemBaseName() ) );
NotificationQueue_Add( pNotification );
}
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CClientItemBroadcastNotificationJob, "CClientItemBroadcastNotificationJob", k_EMsgGCTFSpecificItemBroadcast, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the Saxxy Awarded broadcast message
//-----------------------------------------------------------------------------
class CGSaxxyAwardedBroadcast : public GCSDK::CGCClientJob
{
private:
// embedded notification for custom trigger
class CSaxxyAwardedNotification : public CEconNotification
{
public:
CSaxxyAwardedNotification()
{
SetSoundFilename( "vo/announcer_success.mp3" );
}
virtual EType NotificationType() { return eType_Trigger; }
virtual void Trigger()
{
if ( steamapicontext && steamapicontext->SteamFriends() )
{
steamapicontext->SteamFriends()->ActivateGameOverlayToWebPage( "http://www.teamfortress.com/saxxyawards/winners.php" );
}
MarkForDeletion();
}
};
public:
CGSaxxyAwardedBroadcast( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg< CMsgSaxxyAwarded > msg( pNetPacket );
CEconNotification *pNotification = new CSaxxyAwardedNotification();
pNotification->SetText( "#TF_Event_Saxxy_Awarded" );
pNotification->SetLifetime( 30.0f );
{
// Winners
CFmtStr1024 strWinners;
for ( int i = 0; i < msg.Body().winner_names_size(); ++i )
{
strWinners.Append( msg.Body().winner_names( i ).c_str() );
if ( i + 1 < msg.Body().winner_names_size() )
{
strWinners.Append( "\n" );
}
}
wchar_t wszPlayerNames[ 1024 ];
g_pVGuiLocalize->ConvertANSIToUnicode( strWinners.Access(), wszPlayerNames, sizeof( wszPlayerNames ) );
pNotification->AddStringToken( "winners", wszPlayerNames );
// year
CRTime cTime;
cTime.SetToCurrentTime();
cTime.SetToGMT( false );
locchar_t wszYear[10];
loc_sprintf_safe( wszYear, LOCCHAR( "%04u" ), cTime.GetYear() );
pNotification->AddStringToken( "year", wszYear );
// What category was the Saxxy for?
char szCategory[MAX_ATTRIBUTE_DESCRIPTION_LENGTH];
Q_snprintf( szCategory, sizeof( szCategory ), "Replay_Contest_Category%d", msg.Body().category() );
pNotification->AddStringToken( "category", g_pVGuiLocalize->Find( szCategory ) );
}
NotificationQueue_Add( pNotification );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGSaxxyAwardedBroadcast, "CGSaxxyAwardedBroadcast", k_EMsgGCSaxxy_Awarded, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive a generic system broadcast message
//-----------------------------------------------------------------------------
class CGCSystemMessageBroadcast : public GCSDK::CGCClientJob
{
public:
CGCSystemMessageBroadcast( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CBaseHudChat *pHUDChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );
if ( !pHUDChat )
return false;
GCSDK::CProtoBufMsg<CMsgSystemBroadcast> msg( pNetPacket );
// retrieve the text
const char *pchMessage = msg.Body().message().c_str();
wchar_t *pwMessage = g_pVGuiLocalize->Find( pchMessage );
wchar_t wszConvertedText[2048] = L"";
if ( pwMessage == NULL )
{
g_pVGuiLocalize->ConvertANSIToUnicode( pchMessage, wszConvertedText, sizeof( wszConvertedText ) );
pwMessage = wszConvertedText;
}
Color color( 0xff, 0xcc, 0x33, 255 );
KeyValuesAD keyValues( "System Message" );
keyValues->SetWString( "message", pwMessage );
keyValues->SetColor( "custom_color", color );
// print to chat log
wchar_t wszLocalizedString[2048] = L"";
g_pVGuiLocalize->ConstructString_safe( wszLocalizedString, "#Notification_System_Message", keyValues );
pHUDChat->SetCustomColor( color );
pHUDChat->Printf( CHAT_FILTER_NONE, "%ls", wszLocalizedString );
// send to notification
CEconNotification* pNotification = new CEconNotification();
pNotification->SetText( "#Notification_System_Message" );
pNotification->SetKeyValues( keyValues );
pNotification->SetLifetime( 30.0f );
pNotification->SetSoundFilename( "ui/system_message_alert.wav" );
NotificationQueue_Add( pNotification );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCSystemMessageBroadcast, "CGCSystemMessageBroadcast", k_EMsgGCSystemMessage, GCSDK::k_EServerTypeGCClient );
|