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 )
62 for( lSearchSize = search_getsize( lSearchHandle );
63 lSearchCounter < lSearchSize; ++lSearchCounter ) {
64 local string lFilename;
68 local string lPicture;
71 local string lDescription;
73 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
74 lHandle = fopen( lFilename, FILE_READ );
76 print( "Menu: Couldn't open model definition file '", lFilename, "'\n" );
80 lName = String_Zone( fgets( lHandle ) );
81 lPicture = String_Zone( fgets( lHandle ) );
82 lSkin = String_Zone( fgets( lHandle ) );
83 lModel = String_Zone( fgets( lHandle ) );
84 if( !lName || !lPicture || !lSkin || !lModel ) {
86 String_Free( lPicture );
88 String_Free( lModel );
89 print( "Menu: Couldn't parse model definition file '",
90 search_getfilename( lSearchHandle, lSearchCounter ), "'\n" );
94 lDescription = String_Create();
98 lLine = fgets( lHandle );
99 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
100 } while( validstring( lLine ) );
101 if( lDescription ) { // add this avatar_info
102 lAvatar = Menu_CreateItem( "Item_Nex_Avatar_Info", ftos( lSearchCounter ), self.name );
104 lAvatar.target = lModel;
105 lAvatar.link = lSkin;
106 lAvatar.picture = lPicture;
107 lAvatar.normal = lName;
108 lAvatar.text = lDescription;
110 Menu_LinkItem( lAvatar );
112 String_Free( lName );
113 String_Free( lPicture );
114 String_Free( lSkin );
115 String_Free( lModel );
116 String_Free( lDescription );
120 search_end( lSearchHandle );
122 Menu_LinkChildren( self );
126 self.maxValue = fabs( lAvatar.orderPos );
131 local string lModel, lSkin;
134 lModel = String_Zone( cvar_string( "_cl_playermodel" ) );
135 lSkin = String_Zone( cvar_string( "_cl_playerskin" ) );
137 for( lMatch = self._child ; lMatch._next ; lMatch = lMatch._next )
138 if( lMatch.target == lModel && lMatch.link == lSkin )
143 self._realValue = fabs( lMatch.orderPos );
144 String_EntitySet( self, value, ftos( self._realValue ) );
145 String_EntitySet( self, _syncValue, self.value );
148 String_Free( lModel );
149 String_Free( lSkin );
152 void() _IDNA_UpdateLink =
154 local float lCurrent;
158 lCurrent = fabs( self._link.orderPos );
159 lTarget = self._realValue;
160 if( lCurrent < lTarget )
161 for( lMatch = self._link; lMatch._next && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._next );
163 for( lMatch = self._link; lMatch._prev && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._prev );
164 // lMatch always is valid if there are any children
167 self._realValue = fabs( self._link.orderPos );
168 String_EntitySet( self, value, ftos( self._realValue ) );
171 void() _IDNA_RawSet =
175 cmd( "playermodel \"", self._link.target, "\";" );
176 cmd( "playerskin \"", self._link.link, "\"\n" );
183 String_EntitySet( self, _syncValue, self.value );
186 void() _IDNA_Test_Start =
191 void() _IDNA_Test_End =
193 String_EntitySet( self, value, self._syncValue );
199 String_EntitySet( self, value, self.defValue );
203 void( float pEvent ) Item_Data_Nex_Avatar_DataEvent =
212 case ITEM_DATA_RESET:
215 case ITEM_DATA_TEST_START:
218 case ITEM_DATA_TEST_END:
221 case ITEM_DATALINK_SET:
227 void() Item_Data_Nex_Avatar_Spawn =
231 self.flag = self.flag | FLAG_HIDDEN;
233 self._reinit = _IDNA_Sync;
234 self._dataEvent = Item_Data_Nex_Avatar_DataEvent;