Revision | f7473637d80ca78d38031f8420ff6f0a81aff8ae (tree) |
---|---|
Time | 2023-03-25 10:13:32 |
Author | Adam Kaminski <kaminskiadam9@gmai...> |
Commiter | Adam Kaminski |
- Separated the data that's used by custom columns, and in turn, removed the now superflous CustomScoreColumn class.
- Mods now allocate or deallocate data for custom columns using the "addcustomdata" and "removecustomdata" commands respectively in the GameInfo block of a MAPINFO lump.
- Removed the column flag DONTRESETONLEVELCHANGE.
@@ -598,7 +598,7 @@ | ||
598 | 598 | CHAT_ClearChatMessages( ulPlayerIdx ); |
599 | 599 | |
600 | 600 | // [AK] Reset this player's custom columns to their default values. |
601 | - SCOREBOARD_ResetCustomColumnsForPlayer( ulPlayerIdx, false ); | |
601 | + SCOREBOARD_ResetCustomColumnsForPlayer( ulPlayerIdx ); | |
602 | 602 | |
603 | 603 | // [BB] Morphed bots need to be unmorphed before disconnecting. |
604 | 604 | if (players[ulPlayerIdx].morphTics) |
@@ -4545,7 +4545,7 @@ | ||
4545 | 4545 | CHAT_ClearChatMessages( player - players ); |
4546 | 4546 | |
4547 | 4547 | // [AK] Reset this player's custom columns to their default values. |
4548 | - SCOREBOARD_ResetCustomColumnsForPlayer( player - players, false ); | |
4548 | + SCOREBOARD_ResetCustomColumnsForPlayer( player - players ); | |
4549 | 4549 | |
4550 | 4550 | // Zero out all the player information. |
4551 | 4551 | PLAYER_ResetPlayerData( player ); |
@@ -294,6 +294,35 @@ | ||
294 | 294 | } |
295 | 295 | else gameinfo.mCheatMapArrow = ""; |
296 | 296 | } |
297 | + // [AK] Adds or removes a set of custom data that will be used by a custom column. | |
298 | + else if (( nextKey.CompareNoCase( "addcustomdata" ) == 0 ) || ( nextKey.CompareNoCase( "removecustomdata" ) == 0 )) | |
299 | + { | |
300 | + const bool bAddingData = ( nextKey.CompareNoCase( "addcustomdata" ) == 0 ); | |
301 | + sc.MustGetToken( TK_StringConst ); | |
302 | + | |
303 | + if ( sc.StringLen == 0 ) | |
304 | + sc.ScriptError( "Got an empty string for a name." ); | |
305 | + | |
306 | + FName Name = sc.String; | |
307 | + | |
308 | + if ( bAddingData ) | |
309 | + { | |
310 | + // [AK] Don't allow the same data to be defined more than once. | |
311 | + if ( gameinfo.CustomPlayerData.CheckKey( Name ) != NULL ) | |
312 | + sc.ScriptError( "Custom data '%s' is already defined.", Name.GetChars( )); | |
313 | + | |
314 | + sc.MustGetToken( ',' ); | |
315 | + gameinfo.CustomPlayerData.Insert( Name, CustomPlayerData( sc, gameinfo.CustomPlayerData.CountUsed( ))); | |
316 | + } | |
317 | + else | |
318 | + { | |
319 | + // [AK] Make sure that the data is already defined. | |
320 | + if ( gameinfo.CustomPlayerData.CheckKey( Name ) == NULL ) | |
321 | + sc.ScriptError( "Custom data '%s' isn't defined.", Name.GetChars( )); | |
322 | + | |
323 | + gameinfo.CustomPlayerData.Remove( Name ); | |
324 | + } | |
325 | + } | |
297 | 326 | // Insert valid keys here. |
298 | 327 | GAMEINFOKEY_CSTRING(titlePage, "titlePage", 8) |
299 | 328 | GAMEINFOKEY_STRINGARRAY(creditPages, "addcreditPage", 8, false) |
@@ -36,6 +36,8 @@ | ||
36 | 36 | |
37 | 37 | #include "basictypes.h" |
38 | 38 | #include "zstring.h" |
39 | +// [AK] New #includes. | |
40 | +#include "scoreboard.h" | |
39 | 41 | |
40 | 42 | // Flags are not user configurable and only depend on the standard IWADs |
41 | 43 | #define GI_MAPxx 0x00000001 |
@@ -150,6 +152,9 @@ | ||
150 | 152 | bool bForceSpawnEventScripts; |
151 | 153 | bool bForceDamageEventScripts; |
152 | 154 | |
155 | + // [AK] A list of all custom data for players, particularly used by custom columns. | |
156 | + TMap<FName, CustomPlayerData> CustomPlayerData; | |
157 | + | |
153 | 158 | const char *GetFinalePage(unsigned int num) const; |
154 | 159 | }; |
155 | 160 |
@@ -1861,25 +1861,6 @@ | ||
1861 | 1861 | return 0; |
1862 | 1862 | } |
1863 | 1863 | |
1864 | -// ================================================================================================ | |
1865 | -// | |
1866 | -// [AK] GetCustomScoreColumn | |
1867 | -// | |
1868 | -// Returns a pointer to a usable CustomScoreColumn object, using its name as an argument. | |
1869 | -// | |
1870 | -// ================================================================================================ | |
1871 | - | |
1872 | -static CustomScoreColumn *GetCustomScoreColumn ( const char *pszColumnName ) | |
1873 | -{ | |
1874 | - ScoreColumn *pColumn = SCOREBOARD_GetColumn( pszColumnName, true ); | |
1875 | - | |
1876 | - // [AK] Return NULL if the column doesn't exist, isn't usable right now, or isn't a custom column. | |
1877 | - if (( pColumn == NULL ) || ( pColumn->IsCustomColumn( ) == false )) | |
1878 | - return NULL; | |
1879 | - | |
1880 | - return static_cast<CustomScoreColumn *>( pColumn ); | |
1881 | -} | |
1882 | - | |
1883 | 1864 | //---- Plane watchers ----// |
1884 | 1865 | |
1885 | 1866 | class DPlaneWatcher : public DThinker |
@@ -7897,14 +7878,14 @@ | ||
7897 | 7878 | |
7898 | 7879 | case ACSF_SetCustomColumnValue: |
7899 | 7880 | { |
7900 | - CustomScoreColumn *pCustomColumn = GetCustomScoreColumn( FBehavior::StaticLookupString( args[0] )); | |
7881 | + CustomPlayerData *pData = gameinfo.CustomPlayerData.CheckKey( FBehavior::StaticLookupString( args[0] )); | |
7901 | 7882 | |
7902 | 7883 | // [AK] Make sure that the column and player are both valid. |
7903 | - if (( pCustomColumn != NULL ) && ( PLAYER_IsValidPlayer( args[1] ))) | |
7884 | + if (( pData != NULL ) && ( PLAYER_IsValidPlayer( args[1] ))) | |
7904 | 7885 | { |
7905 | 7886 | ColumnValue Val; |
7906 | 7887 | |
7907 | - switch ( pCustomColumn->GetDataType( )) | |
7888 | + switch ( pData->GetDataType( )) | |
7908 | 7889 | { |
7909 | 7890 | case COLUMNDATA_INT: |
7910 | 7891 | case COLUMNDATA_COLOR: |
@@ -7924,14 +7905,14 @@ | ||
7924 | 7905 | { |
7925 | 7906 | const char *pszValue = FBehavior::StaticLookupString( args[2] ); |
7926 | 7907 | |
7927 | - if ( pCustomColumn->GetDataType( ) == COLUMNDATA_STRING ) | |
7908 | + if ( pData->GetDataType( ) == COLUMNDATA_STRING ) | |
7928 | 7909 | Val = pszValue; |
7929 | 7910 | else |
7930 | 7911 | Val = TexMan.FindTexture( pszValue ); |
7931 | 7912 | } |
7932 | 7913 | } |
7933 | 7914 | |
7934 | - pCustomColumn->SetValue( args[1], Val ); | |
7915 | + pData->SetValue( args[1], Val ); | |
7935 | 7916 | return 1; |
7936 | 7917 | } |
7937 | 7918 |
@@ -7940,12 +7921,12 @@ | ||
7940 | 7921 | |
7941 | 7922 | case ACSF_GetCustomColumnValue: |
7942 | 7923 | { |
7943 | - CustomScoreColumn *pCustomColumn = GetCustomScoreColumn( FBehavior::StaticLookupString( args[0] )); | |
7924 | + CustomPlayerData *pData = gameinfo.CustomPlayerData.CheckKey( FBehavior::StaticLookupString( args[0] )); | |
7944 | 7925 | |
7945 | 7926 | // [AK] Make sure that the column and player are both valid. |
7946 | - if (( pCustomColumn != NULL ) && ( PLAYER_IsValidPlayer( args[1] ))) | |
7947 | - { | |
7948 | - const ColumnValue Val = pCustomColumn->GetValue( args[1] ); | |
7927 | + if (( pData != NULL ) && ( PLAYER_IsValidPlayer( args[1] ))) | |
7928 | + { | |
7929 | + const ColumnValue Val = pData->GetValue( args[1] ); | |
7949 | 7930 | |
7950 | 7931 | switch ( Val.GetDataType( )) |
7951 | 7932 | { |
@@ -7977,13 +7958,13 @@ | ||
7977 | 7958 | |
7978 | 7959 | case ACSF_ResetCustomColumnToDefault: |
7979 | 7960 | { |
7980 | - CustomScoreColumn *pCustomColumn = GetCustomScoreColumn( FBehavior::StaticLookupString( args[0] )); | |
7961 | + CustomPlayerData *pData = gameinfo.CustomPlayerData.CheckKey( FBehavior::StaticLookupString( args[0] )); | |
7981 | 7962 | const ULONG ulPlayer = args[1] < 0 ? MAXPLAYERS : args[1]; |
7982 | 7963 | |
7983 | 7964 | // [AK] Make sure that the column and player are both valid (unless we're resetting for all players). |
7984 | - if (( pCustomColumn != NULL ) && (( ulPlayer == MAXPLAYERS ) || ( PLAYER_IsValidPlayer( ulPlayer )))) | |
7985 | - { | |
7986 | - pCustomColumn->ResetToDefault( ulPlayer, false ); | |
7965 | + if (( pData != NULL ) && (( ulPlayer == MAXPLAYERS ) || ( PLAYER_IsValidPlayer( ulPlayer )))) | |
7966 | + { | |
7967 | + pData->ResetToDefault( ulPlayer ); | |
7987 | 7968 | return 1; |
7988 | 7969 | } |
7989 | 7970 |
@@ -431,6 +431,150 @@ | ||
431 | 431 | |
432 | 432 | //***************************************************************************** |
433 | 433 | // |
434 | +// [AK] CustomPlayerData::CustomPlayerData | |
435 | +// | |
436 | +// Initializes the data type and default value that will be used. | |
437 | +// | |
438 | +//***************************************************************************** | |
439 | + | |
440 | +CustomPlayerData::CustomPlayerData( FScanner &sc, BYTE NewIndex ) : Index( NewIndex ) | |
441 | +{ | |
442 | + // [AK] Grab the data type first. | |
443 | + sc.MustGetToken( TK_StringConst ); | |
444 | + | |
445 | + if ( sc.StringLen == 0 ) | |
446 | + sc.ScriptError( "Got an empty string for a data type." ); | |
447 | + | |
448 | + DataType = static_cast<COLUMNDATA_e>( sc.MustGetEnumName( "data type", "COLUMNDATA_", GetValueCOLUMNDATA_e, true )); | |
449 | + | |
450 | + // [AK] Don't accept an "unknown" data type. | |
451 | + if ( DataType == COLUMNDATA_UNKNOWN ) | |
452 | + sc.ScriptError( "You can't specify an 'unknown' data type!" ); | |
453 | + | |
454 | + sc.MustGetToken( ',' ); | |
455 | + | |
456 | + // [AK] Next, grab the default value and store it into a string. | |
457 | + switch ( DataType ) | |
458 | + { | |
459 | + case COLUMNDATA_INT: | |
460 | + { | |
461 | + sc.MustGetNumber( ); | |
462 | + DefaultValString.Format( "%d", sc.Number ); | |
463 | + break; | |
464 | + } | |
465 | + | |
466 | + case COLUMNDATA_FLOAT: | |
467 | + { | |
468 | + sc.MustGetFloat( ); | |
469 | + DefaultValString.Format( "%f", static_cast<float>( sc.Float )); | |
470 | + break; | |
471 | + } | |
472 | + | |
473 | + case COLUMNDATA_BOOL: | |
474 | + case COLUMNDATA_STRING: | |
475 | + case COLUMNDATA_COLOR: | |
476 | + case COLUMNDATA_TEXTURE: | |
477 | + { | |
478 | + sc.MustGetString( ); | |
479 | + | |
480 | + // [AK] Color values must be saved differently. | |
481 | + if ( DataType == COLUMNDATA_COLOR ) | |
482 | + { | |
483 | + FString ColorString = V_GetColorStringByName( sc.String ); | |
484 | + DefaultValString.Format( "%d", V_GetColorFromString( NULL, ColorString.IsNotEmpty( ) ? ColorString.GetChars( ) : sc.String )); | |
485 | + } | |
486 | + else | |
487 | + { | |
488 | + DefaultValString = sc.String; | |
489 | + } | |
490 | + | |
491 | + break; | |
492 | + } | |
493 | + } | |
494 | +} | |
495 | + | |
496 | +//***************************************************************************** | |
497 | +// | |
498 | +// [AK] CustomPlayerData::GetValue | |
499 | +// | |
500 | +// Returns a ColumnValue object containing the value associated with a player, | |
501 | +// or the default value if the given player index is invalid. | |
502 | +// | |
503 | +//***************************************************************************** | |
504 | + | |
505 | +ColumnValue CustomPlayerData::GetValue( const ULONG ulPlayer ) const | |
506 | +{ | |
507 | + return PLAYER_IsValidPlayer( ulPlayer ) ? Val[ulPlayer] : GetDefaultValue( ); | |
508 | +} | |
509 | + | |
510 | +//***************************************************************************** | |
511 | +// | |
512 | +// [AK] CustomPlayerData::GetDefaultValue | |
513 | +// | |
514 | +// Returns a ColumnValue object containing the default value. | |
515 | +// | |
516 | +//***************************************************************************** | |
517 | + | |
518 | +ColumnValue CustomPlayerData::GetDefaultValue( void ) const | |
519 | +{ | |
520 | + ColumnValue DefaultVal; | |
521 | + DefaultVal.FromString( DefaultValString.GetChars( ), DataType ); | |
522 | + | |
523 | + return DefaultVal; | |
524 | +} | |
525 | + | |
526 | +//***************************************************************************** | |
527 | +// | |
528 | +// [AK] CustomPlayerData::SetValue | |
529 | +// | |
530 | +// Changes the value for a player in this column. | |
531 | +// | |
532 | +//***************************************************************************** | |
533 | + | |
534 | +void CustomPlayerData::SetValue( const ULONG ulPlayer, const ColumnValue &Value ) | |
535 | +{ | |
536 | + // [AK] Stop here if the player's invalid, or the new value is equal to the old one. | |
537 | + if (( PLAYER_IsValidPlayer( ulPlayer ) == false ) || ( GetValue( ulPlayer ) == Value )) | |
538 | + return; | |
539 | + | |
540 | + // [AK] Only set the value if the data types match. Otherwise, throw a fatal error. | |
541 | + if ( DataType != Value.GetDataType( )) | |
542 | + I_Error( "CustomPlayerData::SetValue: data type doesn't match." ); | |
543 | + | |
544 | + Val[ulPlayer] = Value; | |
545 | + SCOREBOARD_ShouldRefreshBeforeRendering( ); | |
546 | +} | |
547 | + | |
548 | +//***************************************************************************** | |
549 | +// | |
550 | +// [AK] CustomPlayerData::ResetToDefault | |
551 | +// | |
552 | +// Resets the value of a single player or all players in this column to their | |
553 | +// default values. | |
554 | +// | |
555 | +//***************************************************************************** | |
556 | + | |
557 | +void CustomPlayerData::ResetToDefault( const ULONG ulPlayer ) | |
558 | +{ | |
559 | + const ColumnValue DefaultVal = GetDefaultValue( ); | |
560 | + | |
561 | + // [AK] Check if we want to restore the default value for all players. | |
562 | + if ( ulPlayer == MAXPLAYERS ) | |
563 | + { | |
564 | + for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) | |
565 | + Val[ulIdx] = DefaultVal; | |
566 | + } | |
567 | + // [AK] Otherwise, restore it only for the one player. | |
568 | + else if ( ulPlayer < MAXPLAYERS ) | |
569 | + { | |
570 | + Val[ulPlayer] = DefaultVal; | |
571 | + } | |
572 | + | |
573 | + SCOREBOARD_ShouldRefreshBeforeRendering( ); | |
574 | +} | |
575 | + | |
576 | +//***************************************************************************** | |
577 | +// | |
434 | 578 | // [AK] ScoreColumn::ScoreColumn |
435 | 579 | // |
436 | 580 | // Initializes the members of a ScoreColumn object to their default values. |
@@ -1073,6 +1217,16 @@ | ||
1073 | 1217 | case COLUMNTYPE_COUNTRYFLAG: |
1074 | 1218 | return COLUMNDATA_TEXTURE; |
1075 | 1219 | |
1220 | + case COLUMNTYPE_CUSTOM: | |
1221 | + { | |
1222 | + CustomPlayerData *pData = gameinfo.CustomPlayerData.CheckKey( InternalName ); | |
1223 | + | |
1224 | + if ( pData == NULL ) | |
1225 | + I_Error( "DataScoreColumn::GetDataType: custom column '%s' has no data.", GetInternalName( )); | |
1226 | + | |
1227 | + return pData->GetDataType( ); | |
1228 | + } | |
1229 | + | |
1076 | 1230 | default: |
1077 | 1231 | return COLUMNDATA_UNKNOWN; |
1078 | 1232 | } |
@@ -1394,6 +1548,16 @@ | ||
1394 | 1548 | case COLUMNTYPE_COUNTRYCODE: |
1395 | 1549 | Result = NETWORK_GetCountryCodeFromIndex( players[ulPlayer].ulCountryIndex, cl_usealpha3countrycode ); |
1396 | 1550 | break; |
1551 | + | |
1552 | + case COLUMNTYPE_CUSTOM: | |
1553 | + { | |
1554 | + CustomPlayerData *pData = gameinfo.CustomPlayerData.CheckKey( InternalName ); | |
1555 | + | |
1556 | + if ( pData == NULL ) | |
1557 | + I_Error( "DataScoreColumn::GetValue: custom column '%s' has no data.", GetInternalName( )); | |
1558 | + | |
1559 | + Result = pData->GetValue( ulPlayer ); | |
1560 | + } | |
1397 | 1561 | } |
1398 | 1562 | } |
1399 | 1563 |
@@ -1719,253 +1883,6 @@ | ||
1719 | 1883 | |
1720 | 1884 | //***************************************************************************** |
1721 | 1885 | // |
1722 | -// [AK] CustomScoreColumn::CustomScoreColumn | |
1723 | -// | |
1724 | -// Initializes the custom column's data type and sets its default value to zero | |
1725 | -// (e.g. 0 for integers, booleans, floats, or colors, and NULL for strings | |
1726 | -// or textures). | |
1727 | -// | |
1728 | -//***************************************************************************** | |
1729 | - | |
1730 | -CustomScoreColumn::CustomScoreColumn( COLUMNDATA_e DataType, const char *pszName ) : DataScoreColumn( COLUMNTYPE_CUSTOM, pszName ), CurrentDataType( COLUMNDATA_UNKNOWN ) | |
1731 | -{ | |
1732 | - ValidateDataType( DataType, "CustomScoreColumn::CustomScoreColumn" ); | |
1733 | - SetDataType( DataType ); | |
1734 | -} | |
1735 | - | |
1736 | -//***************************************************************************** | |
1737 | -// | |
1738 | -// [AK] CustomScoreColumn::GetValue | |
1739 | -// | |
1740 | -// Returns a ColumnValue object containing the value associated with a player, | |
1741 | -// or the default value if the given player index is invalid. | |
1742 | -// | |
1743 | -//***************************************************************************** | |
1744 | - | |
1745 | -ColumnValue CustomScoreColumn::GetValue( ULONG ulPlayer ) const | |
1746 | -{ | |
1747 | - return PLAYER_IsValidPlayer( ulPlayer ) ? Val[ulPlayer] : DefaultVal; | |
1748 | -} | |
1749 | - | |
1750 | -//***************************************************************************** | |
1751 | -// | |
1752 | -// [AK] CustomScoreColumn::GetDefaultValue | |
1753 | -// | |
1754 | -// Returns a ColumnValue object containing the column's default value. | |
1755 | -// | |
1756 | -//***************************************************************************** | |
1757 | - | |
1758 | -ColumnValue CustomScoreColumn::GetDefaultValue( void ) const | |
1759 | -{ | |
1760 | - return DefaultVal; | |
1761 | -} | |
1762 | - | |
1763 | -//***************************************************************************** | |
1764 | -// | |
1765 | -// [AK] CustomScoreColumn::SetDataType | |
1766 | -// | |
1767 | -// Changes the columm's data type and zeroes every player's value. | |
1768 | -// | |
1769 | -//***************************************************************************** | |
1770 | - | |
1771 | -void CustomScoreColumn::SetDataType( COLUMNDATA_e NewDataType ) | |
1772 | -{ | |
1773 | - if ( CurrentDataType == NewDataType ) | |
1774 | - return; | |
1775 | - | |
1776 | - ValidateDataType( NewDataType, "CustomScoreColumn::SetDataType" ); | |
1777 | - CurrentDataType = NewDataType; | |
1778 | - | |
1779 | - // [AK] We changed the custom column's data type. Now we need to do the same with | |
1780 | - // the (default) values and zero everything. | |
1781 | - for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) | |
1782 | - Val[ulIdx].ChangeDataType( CurrentDataType ); | |
1783 | - | |
1784 | - DefaultVal.ChangeDataType( CurrentDataType ); | |
1785 | -} | |
1786 | - | |
1787 | -//***************************************************************************** | |
1788 | -// | |
1789 | -// [AK] CustomScoreColumn::SetValue | |
1790 | -// | |
1791 | -// Changes the value for a player in this column. | |
1792 | -// | |
1793 | -//***************************************************************************** | |
1794 | - | |
1795 | -void CustomScoreColumn::SetValue( const ULONG ulPlayer, const ColumnValue &Value ) | |
1796 | -{ | |
1797 | - if ( PLAYER_IsValidPlayer( ulPlayer )) | |
1798 | - { | |
1799 | - // [AK] Stop here if the new value is equal to the old one. | |
1800 | - if ( GetValue( ulPlayer ) == Value ) | |
1801 | - return; | |
1802 | - | |
1803 | - TryChangingValue( Val[ulPlayer], Value, "CustomScoreColumn::SetValue" ); | |
1804 | - SCOREBOARD_ShouldRefreshBeforeRendering( ); | |
1805 | - } | |
1806 | -} | |
1807 | - | |
1808 | -//***************************************************************************** | |
1809 | -// | |
1810 | -// [AK] CustomScoreColumn::SetDefaultValue | |
1811 | -// | |
1812 | -// Changes the column's default value. | |
1813 | -// | |
1814 | -//***************************************************************************** | |
1815 | - | |
1816 | -void CustomScoreColumn::SetDefaultValue( const ColumnValue &Value ) | |
1817 | -{ | |
1818 | - TryChangingValue( DefaultVal, Value, "CustomScoreColumn::SetDefaultValue" ); | |
1819 | -} | |
1820 | - | |
1821 | -//***************************************************************************** | |
1822 | -// | |
1823 | -// [AK] CustomScoreColumn::ParseCommand | |
1824 | -// | |
1825 | -// Parses commands that are only used for custom columns. | |
1826 | -// | |
1827 | -//***************************************************************************** | |
1828 | - | |
1829 | -void CustomScoreColumn::ParseCommand( FScanner &sc, const COLUMNCMD_e Command, const FString CommandName ) | |
1830 | -{ | |
1831 | - switch ( Command ) | |
1832 | - { | |
1833 | - case COLUMNCMD_DEFAULTVALUE: | |
1834 | - { | |
1835 | - const COLUMNDATA_e DataType = GetDataType( ); | |
1836 | - ColumnValue Value; | |
1837 | - | |
1838 | - switch ( DataType ) | |
1839 | - { | |
1840 | - case COLUMNDATA_INT: | |
1841 | - { | |
1842 | - sc.MustGetNumber( ); | |
1843 | - Value = sc.Number; | |
1844 | - break; | |
1845 | - } | |
1846 | - | |
1847 | - case COLUMNDATA_FLOAT: | |
1848 | - { | |
1849 | - sc.MustGetFloat( ); | |
1850 | - Value = static_cast<float>( sc.Float ); | |
1851 | - break; | |
1852 | - } | |
1853 | - | |
1854 | - case COLUMNDATA_BOOL: | |
1855 | - case COLUMNDATA_STRING: | |
1856 | - case COLUMNDATA_COLOR: | |
1857 | - case COLUMNDATA_TEXTURE: | |
1858 | - { | |
1859 | - sc.MustGetString( ); | |
1860 | - | |
1861 | - if ( DataType == COLUMNDATA_BOOL ) | |
1862 | - { | |
1863 | - if ( stricmp( sc.String, "true" ) == 0 ) | |
1864 | - Value = true; | |
1865 | - else if ( stricmp( sc.String, "false" ) == 0 ) | |
1866 | - Value = false; | |
1867 | - else | |
1868 | - Value = !!atoi( sc.String ); | |
1869 | - } | |
1870 | - else if ( DataType == COLUMNDATA_STRING ) | |
1871 | - { | |
1872 | - Value = sc.String; | |
1873 | - } | |
1874 | - else if ( DataType == COLUMNDATA_COLOR ) | |
1875 | - { | |
1876 | - FString ColorString = V_GetColorStringByName( sc.String ); | |
1877 | - Value = V_GetColorFromString( NULL, ColorString.IsNotEmpty( ) ? ColorString.GetChars( ) : sc.String ); | |
1878 | - } | |
1879 | - else | |
1880 | - { | |
1881 | - FTexture *pTexture = TexMan.FindTexture( sc.String ); | |
1882 | - | |
1883 | - if ( pTexture == NULL ) | |
1884 | - sc.ScriptError( "Couldn't find texture '%s'.", sc.String ); | |
1885 | - | |
1886 | - Value = pTexture; | |
1887 | - } | |
1888 | - | |
1889 | - break; | |
1890 | - } | |
1891 | - } | |
1892 | - | |
1893 | - SetDefaultValue( Value ); | |
1894 | - break; | |
1895 | - } | |
1896 | - | |
1897 | - // [AK] Parse any data column commands if we reach here. | |
1898 | - default: | |
1899 | - DataScoreColumn::ParseCommand( sc, Command, CommandName ); | |
1900 | - break; | |
1901 | - } | |
1902 | -} | |
1903 | - | |
1904 | -//***************************************************************************** | |
1905 | -// | |
1906 | -// [AK] CustomScoreColumn::ResetToDefault | |
1907 | -// | |
1908 | -// Resets the value of a single player or all players in this column to their | |
1909 | -// default values. | |
1910 | -// | |
1911 | -//***************************************************************************** | |
1912 | - | |
1913 | -void CustomScoreColumn::ResetToDefault( const ULONG ulPlayer, const bool bChangingLevel ) | |
1914 | -{ | |
1915 | - // [AK] Don't reset to default if this column forbids it during a level change. | |
1916 | - if (( bChangingLevel ) && ( ulFlags & COLUMNFLAG_DONTRESETONLEVELCHANGE )) | |
1917 | - return; | |
1918 | - | |
1919 | - // [AK] Check if we want to restore the default value for all players. | |
1920 | - if ( ulPlayer == MAXPLAYERS ) | |
1921 | - { | |
1922 | - for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) | |
1923 | - Val[ulIdx] = DefaultVal; | |
1924 | - } | |
1925 | - // [AK] Otherwise, restore it only for the one player. | |
1926 | - else if ( ulPlayer < MAXPLAYERS ) | |
1927 | - { | |
1928 | - Val[ulPlayer] = DefaultVal; | |
1929 | - } | |
1930 | - | |
1931 | - SCOREBOARD_ShouldRefreshBeforeRendering( ); | |
1932 | -} | |
1933 | - | |
1934 | -//***************************************************************************** | |
1935 | -// | |
1936 | -// [AK] CustomScoreColumn::ValidateDataType | |
1937 | -// | |
1938 | -// Checks if a data type is valid, and throws a fatal error if it isn't. | |
1939 | -// | |
1940 | -//***************************************************************************** | |
1941 | - | |
1942 | -void CustomScoreColumn::ValidateDataType( COLUMNDATA_e DataType, const char *pszFunctionName ) const | |
1943 | -{ | |
1944 | - // [AK] Throw a fatal error if an invalid data type was used. | |
1945 | - if (( DataType <= COLUMNDATA_UNKNOWN ) || ( DataType >= NUM_COLUMNDATA_TYPES )) | |
1946 | - I_Error( "%s: an invalid data type was used, %d.", pszFunctionName ? pszFunctionName : "CustomScoreColumn", static_cast<int>( DataType )); | |
1947 | -} | |
1948 | - | |
1949 | -//***************************************************************************** | |
1950 | -// | |
1951 | -// [AK] CustomScoreColumn::TryChangingValue | |
1952 | -// | |
1953 | -// Checks if it's safe to change a value to that of another ColumnValue object | |
1954 | -// (i.e. their data types match), and throws a fatal error if they aren't. | |
1955 | -// | |
1956 | -//***************************************************************************** | |
1957 | - | |
1958 | -void CustomScoreColumn::TryChangingValue( ColumnValue &To, const ColumnValue &From, const char *pszFunctionName ) | |
1959 | -{ | |
1960 | - // [AK] Only set the value if the data types match. Otherwise, throw a fatal error. | |
1961 | - if ( GetDataType( ) == From.GetDataType( )) | |
1962 | - To = From; | |
1963 | - else | |
1964 | - I_Error( "%s: the value's data type doesn't match the column's data type.", pszFunctionName ? pszFunctionName : "CustomScoreColumn" ); | |
1965 | -} | |
1966 | - | |
1967 | -//***************************************************************************** | |
1968 | -// | |
1969 | 1886 | // [AK] CompositeScoreColumn::ParseCommand |
1970 | 1887 | // |
1971 | 1888 | // Parses commands that are only used for composite columns. |
@@ -3332,7 +3249,7 @@ | ||
3332 | 3249 | } |
3333 | 3250 | |
3334 | 3251 | // [AK] Reset custom columns to their default values for all players. |
3335 | - SCOREBOARD_ResetCustomColumnsForPlayer( MAXPLAYERS, bChangingLevel ); | |
3252 | + SCOREBOARD_ResetCustomColumnsForPlayer( MAXPLAYERS ); | |
3336 | 3253 | |
3337 | 3254 | // [AK] It would be a good idea to refresh the scoreboard after resetting. |
3338 | 3255 | SCOREBOARD_ShouldRefreshBeforeRendering( ); |
@@ -3347,20 +3264,17 @@ | ||
3347 | 3264 | // |
3348 | 3265 | //***************************************************************************** |
3349 | 3266 | |
3350 | -void SCOREBOARD_ResetCustomColumnsForPlayer( const ULONG ulPlayer, const bool bChangingLevel ) | |
3267 | +void SCOREBOARD_ResetCustomColumnsForPlayer( const ULONG ulPlayer ) | |
3351 | 3268 | { |
3352 | - // [AK] Don't do anything if there are no defined columns. | |
3353 | - if ( g_Columns.CountUsed( ) == 0 ) | |
3269 | + // [AK] Don't do anything if there is no data. | |
3270 | + if ( gameinfo.CustomPlayerData.CountUsed( ) == 0 ) | |
3354 | 3271 | return; |
3355 | 3272 | |
3356 | - TMapIterator<FName, ScoreColumn *> it( g_Columns ); | |
3357 | - TMap<FName, ScoreColumn *>::Pair *pair; | |
3273 | + TMapIterator<FName, CustomPlayerData> it( gameinfo.CustomPlayerData ); | |
3274 | + TMap<FName, CustomPlayerData>::Pair *pair; | |
3358 | 3275 | |
3359 | 3276 | while ( it.NextPair( pair )) |
3360 | - { | |
3361 | - if (( pair->Value->IsUsableInCurrentGame( )) && ( pair->Value->IsCustomColumn( ))) | |
3362 | - static_cast<CustomScoreColumn *>( pair->Value )->ResetToDefault( ulPlayer, bChangingLevel ); | |
3363 | - } | |
3277 | + pair->Value.ResetToDefault( ulPlayer ); | |
3364 | 3278 | } |
3365 | 3279 | |
3366 | 3280 | //***************************************************************************** |
@@ -187,6 +187,37 @@ | ||
187 | 187 | |
188 | 188 | //***************************************************************************** |
189 | 189 | // |
190 | +// [AK] CustomPlayerData | |
191 | +// | |
192 | +// An array of ColumnValues for each player, used by custom columns to store data. | |
193 | +// | |
194 | +//***************************************************************************** | |
195 | + | |
196 | +class CustomPlayerData | |
197 | +{ | |
198 | +public: | |
199 | + CustomPlayerData( FScanner &sc, BYTE NewIndex ); | |
200 | + | |
201 | + COLUMNDATA_e GetDataType( void ) const { return DataType; } | |
202 | + ColumnValue GetValue( const ULONG ulPlayer ) const; | |
203 | + ColumnValue GetDefaultValue( void ) const; | |
204 | + BYTE GetIndex( void ) const { return Index; } | |
205 | + void SetValue( const ULONG ulPlayer, const ColumnValue &Value ); | |
206 | + void ResetToDefault( const ULONG ulPlayer ); | |
207 | + | |
208 | +private: | |
209 | + COLUMNDATA_e DataType; | |
210 | + ColumnValue Val[MAXPLAYERS]; | |
211 | + BYTE Index; | |
212 | + | |
213 | + // [AK] The default value as a string. MAPINFO lumps are parsed before any | |
214 | + // graphics are loaded, so if a custom column uses textures as data, then | |
215 | + // this is why the value must be stored as a string. | |
216 | + FString DefaultValString; | |
217 | +}; | |
218 | + | |
219 | +//***************************************************************************** | |
220 | +// | |
190 | 221 | // [AK] ScoreColumn |
191 | 222 | // |
192 | 223 | // A base class for all column types (e.g. data or composite) that will appear |
@@ -222,7 +253,6 @@ | ||
222 | 253 | void DrawTexture( FTexture *pTexture, const LONG lYPos, const ULONG ulHeight, const float fAlpha, const int clipWidth, const int clipHeight ) const; |
223 | 254 | |
224 | 255 | virtual COLUMNTEMPLATE_e GetTemplate( void ) const { return COLUMNTEMPLATE_UNKNOWN; } |
225 | - virtual bool IsCustomColumn( void ) const { return false; } | |
226 | 256 | virtual void Parse( FScanner &sc ); |
227 | 257 | virtual void ParseCommand( FScanner &sc, const COLUMNCMD_e Command, const FString CommandName ); |
228 | 258 | virtual void CheckIfUsable( void ); |
@@ -337,39 +367,6 @@ | ||
337 | 367 | |
338 | 368 | //***************************************************************************** |
339 | 369 | // |
340 | -// [AK] CustomScoreColumn | |
341 | -// | |
342 | -// A separate class for all custom columns and their respective data types. | |
343 | -// | |
344 | -//***************************************************************************** | |
345 | - | |
346 | -class CustomScoreColumn : public DataScoreColumn | |
347 | -{ | |
348 | -public: | |
349 | - CustomScoreColumn( COLUMNDATA_e DataType, const char *pszName ); | |
350 | - | |
351 | - virtual bool IsCustomColumn( void ) const { return true; } | |
352 | - virtual COLUMNDATA_e GetDataType( void ) const { return CurrentDataType; } | |
353 | - virtual ColumnValue GetValue( const ULONG ulPlayer ) const; | |
354 | - virtual ColumnValue GetDefaultValue( void ) const; | |
355 | - virtual void SetDataType( COLUMNDATA_e NewDataType ); | |
356 | - virtual void SetValue( const ULONG ulPlayer, const ColumnValue &Value ); | |
357 | - virtual void SetDefaultValue( const ColumnValue &Value ); | |
358 | - virtual void ParseCommand( FScanner &sc, const COLUMNCMD_e Command, const FString CommandName ); | |
359 | - virtual void ResetToDefault( const ULONG ulPlayer, const bool bChangingLevel ); | |
360 | - | |
361 | -protected: | |
362 | - COLUMNDATA_e CurrentDataType; | |
363 | - ColumnValue Val[MAXPLAYERS]; | |
364 | - ColumnValue DefaultVal; | |
365 | - | |
366 | -private: | |
367 | - void ValidateDataType( COLUMNDATA_e DataType, const char *pszFunctionName ) const; | |
368 | - void TryChangingValue( ColumnValue &To, const ColumnValue &From, const char *pszFunctionName ); | |
369 | -}; | |
370 | - | |
371 | -//***************************************************************************** | |
372 | -// | |
373 | 370 | // [AK] CompositeScoreColumn |
374 | 371 | // |
375 | 372 | // A column consisting of more than one data column that are tucked underneath |
@@ -501,7 +498,7 @@ | ||
501 | 498 | ScoreColumn *SCOREBOARD_GetColumn( FName Name, const bool bMustBeUsable ); |
502 | 499 | bool SCOREBOARD_ShouldDrawBoard( void ); |
503 | 500 | void SCOREBOARD_Reset( const bool bChangingLevel ); |
504 | -void SCOREBOARD_ResetCustomColumnsForPlayer( const ULONG ulPlayer, const bool bChangingLevel ); | |
501 | +void SCOREBOARD_ResetCustomColumnsForPlayer( const ULONG ulPlayer ); | |
505 | 502 | void SCOREBOARD_Render( ULONG ulDisplayPlayer ); |
506 | 503 | void SCOREBOARD_Refresh( void ); |
507 | 504 | void SCOREBOARD_ShouldRefreshBeforeRendering( void ); |
@@ -192,8 +192,6 @@ | ||
192 | 192 | ENUM_ELEMENT2( COLUMNFLAG_CVARMUSTBEZERO, 0x4000 ), |
193 | 193 | // If the column's empty (i.e. no contents inside it), then it's disabled. |
194 | 194 | ENUM_ELEMENT2( COLUMNFLAG_DISABLEIFEMPTY, 0x8000 ), |
195 | - // This column's values aren't reset to default when the level changes (custom columns only). | |
196 | - ENUM_ELEMENT2( COLUMNFLAG_DONTRESETONLEVELCHANGE, 0x10000 ), | |
197 | 195 | } |
198 | 196 | END_ENUM( COLUMNFLAG_e ) |
199 | 197 |
@@ -256,8 +254,6 @@ | ||
256 | 254 | ENUM_ELEMENT( COLUMNCMD_TRUETEXT ), |
257 | 255 | // What gets drawn when a row's value is 0 (boolean columns only). |
258 | 256 | ENUM_ELEMENT( COLUMNCMD_FALSETEXT ), |
259 | - // The default value of this column at the start of a new game (custom columns only). | |
260 | - ENUM_ELEMENT( COLUMNCMD_DEFAULTVALUE ), | |
261 | 257 | // What sub-columns are inside the composite column and their order (composite columns only). |
262 | 258 | ENUM_ELEMENT( COLUMNCMD_COLUMNS ), |
263 | 259 | // Adds column(s) to the end of the composite column's sub-column list (composite columns only). |
@@ -3011,7 +3011,7 @@ | ||
3011 | 3011 | CHAT_ClearChatMessages( ulClient ); |
3012 | 3012 | |
3013 | 3013 | // [AK] Reset this player's custom columns to their default values. |
3014 | - SCOREBOARD_ResetCustomColumnsForPlayer( ulClient, false ); | |
3014 | + SCOREBOARD_ResetCustomColumnsForPlayer( ulClient ); | |
3015 | 3015 | |
3016 | 3016 | // [BB] Morphed players need to be unmorphed before disconnecting. |
3017 | 3017 | if (players[ulClient].morphTics) |