1 // Property of Alientrap/AK
2 // custom/player/avatar.qm
10 void() Item_Nex_Avatar_Info_Destroy =
12 String_EntityFree( self, target );
13 String_EntityFree( self, link );
14 String_EntityFree( self, picture );
15 String_EntityFree( self, text );
16 String_EntityFree( self, normal );
19 void() Item_Nex_Avatar_Info_Spawn =
21 String_EntityZone( self, target );
22 String_EntityZone( self, link );
23 String_EntityZone( self, picture );
24 String_EntityZone( self, text );
25 String_EntityZone( self, normal );
27 Gfx_Precache( self.picture );
29 self._destroy = Item_Nex_Avatar_Info_Destroy;
39 // Nex_Action_Player_BuildAvatarList
40 // model definition format
45 // rest: description text
46 void() _IDNA_BuildList =
48 local float lSearchHandle;
49 local float lSearchSize;
50 local float lSearchCounter;
53 Menu_EmptyWindow( self );
57 // FIXME: only accept *.mdef later
58 lSearchHandle = search_begin( "models/player/*.txt", true, true );
59 if( lSearchHandle < 0 )
61 for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
62 lSearchCounter < lSearchSize; ++lSearchCounter ) {
63 local string lFilename;
67 local string lPicture;
70 local string lDescription;
72 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
73 lHandle = fopen( lFilename, FILE_READ );
75 print( "Menu: Couldn't open model definition file '", lFilename, "'\n" );
79 lName = String_Zone( fgets( lHandle ) );
80 lPicture = String_Zone( fgets( lHandle ) );
81 lSkin = String_Zone( fgets( lHandle ) );
82 lModel = String_Zone( fgets( lHandle ) );
83 if( !lName || !lPicture || !lSkin || !lModel ) {
85 String_Free( lPicture );
87 String_Free( lModel );
88 print( "Menu: Couldn't parse model definition file '",
89 search_getfilename( lSearchHandle, lSearchCounter ), "'\n" );
93 lDescription = String_Create();
97 lLine = fgets( lHandle );
98 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
99 } while( validstring( lLine ) );
100 if( lDescription ) { // add this avatar_info
101 lAvatar = Menu_CreateItem( "Item_Nex_Avatar_Info", ftos( lSearchCounter ), self.name );
103 lAvatar.target = lModel;
104 lAvatar.link = lSkin;
105 lAvatar.picture = lPicture;
106 lAvatar.normal = lName;
107 lAvatar.text = lDescription;
109 Menu_LinkItem( lAvatar );
111 String_Free( lName );
112 String_Free( lPicture );
113 String_Free( lSkin );
114 String_Free( lModel );
115 String_Free( lDescription );
119 search_end( lSearchHandle );
121 Menu_LinkChildren( self );
125 self.maxValue = fabs( lAvatar.orderPos );
130 local string lModel, lSkin;
133 lModel = String_Zone( cvar_string( "_cl_playermodel" ) );
134 lSkin = String_Zone( cvar_string( "_cl_playerskin" ) );
136 for( lMatch = self._child ; lMatch._next ; lMatch = lMatch._next )
137 if( lMatch.target == lModel && lMatch.link == lSkin )
142 self._realValue = fabs( lMatch.orderPos );
143 String_EntitySet( self, value, ftos( self._realValue ) );
144 String_EntitySet( self, _syncValue, self.value );
147 String_Free( lModel );
148 String_Free( lSkin );
151 void() _IDNA_UpdateLink =
153 local float lCurrent;
157 lCurrent = fabs( self._link.orderPos );
158 lTarget = self._realValue;
159 if( lCurrent < lTarget )
160 for( lMatch = self._link; lMatch._next && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._next );
162 for( lMatch = self._link; lMatch._prev && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._prev );
163 // lMatch always is valid if there are any children
166 self._realValue = fabs( self._link.orderPos );
167 String_EntitySet( self, value, ftos( self._realValue ) );
170 void() _IDNA_RawSet =
174 cmd( strcat( "playermodel \"", self._link.target, "\";" ) );
175 cmd( strcat( "playerskin \"", self._link.link, "\"\n" ) );
182 String_EntitySet( self, _syncValue, self.value );
185 void() _IDNA_Test_Start =
190 void() _IDNA_Test_End =
192 String_EntitySet( self, value, self._syncValue );
198 String_EntitySet( self, value, self.defValue );
202 void( float pEvent ) Item_Data_Nex_Avatar_DataEvent =
211 case ITEM_DATA_RESET:
214 case ITEM_DATA_TEST_START:
217 case ITEM_DATA_TEST_END:
220 case ITEM_DATALINK_SET:
226 void() Item_Data_Nex_Avatar_Spawn =
230 self.flag = self.flag | FLAG_HIDDEN;
232 self._reinit = _IDNA_Sync;
233 self._dataEvent = Item_Data_Nex_Avatar_DataEvent;