]> icculus.org git repositories - divverent/nexuiz.git/blob - scmenu/source/custom/creategame/maps.qc
Adding my current version of the scmenu to the nexuiz cvs.
[divverent/nexuiz.git] / scmenu / source / custom / creategame / maps.qc
1 // Property of Alientrap/AK
2 // custom/player/avatar.qm
3
4 /*
5 ===================
6 Item_Nex_Map_Info
7 ===================
8 */
9
10 void() Item_Nex_Map_Info_Destroy =
11 {
12         String_EntityFree( self, link );
13         String_EntityFree( self, picture );
14         String_EntityFree( self, text );
15         String_EntityFree( self, normal );
16 };
17
18 void() Item_Nex_Map_Info_Spawn =
19 {
20         String_EntityZone( self, link );
21         String_EntityZone( self, picture );
22         String_EntityZone( self, text );
23         String_EntityZone( self, normal );
24
25         Gfx_Precache( self.picture );
26
27         self._destroy = Item_Nex_Map_Info_Destroy;
28 };
29
30 /*
31 ===================
32 Item_Data_Nex_Avatar
33 ===================
34 */
35
36
37 // Nex_Action_Map_BuildAvatarList
38 // model definition format
39 // name
40 // picture\n
41 // skin filename\n
42 // model filename\n
43 // rest: description text
44 void() _IDNM_BuildList =
45 {
46         local float     lSearchHandle;
47         local float     lSearchSize;
48         local float     lSearchCounter;
49         local entity    lMap;
50
51         Menu_EmptyWindow( self );
52
53         lSearchHandle = search_begin( "maps/*.bsp", true, true );
54         if( lSearchHandle < 0 )
55                 return;
56         for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
57         lSearchCounter < lSearchSize; ++lSearchCounter ) {
58                 local float     lHandle;
59
60                 local string    lFilename;
61                 local string    lStripped;
62                 local string    lName;
63                 local string    lDescription;
64
65                 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
66                 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 4 ) );
67                 lName = String_Zone( substring( lStripped, 5, 100000 ) );
68
69                 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
70                 if( lHandle < 0 )
71                         lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
72                 else {
73                         lDescription = String_Create();
74                         do {
75                                 local string lLine;
76
77                                 lLine = fgets( lHandle );
78                                 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
79                         } while( validstring( lLine ) );
80
81                         fclose( lHandle );
82                 }
83
84                 // add this avatar_info
85                 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
86
87                 lMap.link = lName;
88                 lMap.picture = lStripped;
89                 lMap.normal = lName;
90                 lMap.text = lDescription;
91
92                 Menu_LinkItem( lMap );
93
94                 String_Free( lName );
95                 String_Free( lStripped );
96                 String_Free( lDescription );
97         }
98
99         search_end( lSearchHandle );
100
101         Menu_LinkChildren( self );
102
103         self.minValue = 1;
104         self.stepValue = 1;
105         self.maxValue = fabs( lMap.orderPos );
106 };
107
108 void() _IDNM_UpdateLink =
109 {
110         local float lCurrent;
111         local float lTarget;
112         local entity lMatch;
113
114         lCurrent = fabs( self._link.orderPos );
115         lTarget = self._realValue;
116         if( lCurrent < lTarget )
117                 for( lMatch = self._link; lMatch._next && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._next );
118         else
119                 for( lMatch = self._link; lMatch._prev && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._prev );
120         // lMatch always is valid if there are any children
121         self._link = lMatch;
122
123         self._realValue = fabs( self._link.orderPos );
124         String_EntitySet( self, value, ftos( self._realValue ) );
125 };
126
127 void() _IDNM_Sync =
128 {
129         String_EntitySet( self, value, ftos( self._realValue ) );
130         String_EntitySet( self, _syncValue, ftos( self._realValue ) );
131 };
132
133 void() _IDNM_Send =
134 {
135         _IDNM_UpdateLink();
136         String_EntitySet( self, _syncValue, self.value );
137 };
138
139 void() _IDNM_Test_Start =
140 {
141         _IDNM_UpdateLink();
142 };
143
144 void() _IDNM_Test_End =
145 {
146         String_EntitySet( self, value, self._syncValue );
147         _IDNM_UpdateLink();
148 };
149
150 void() _IDNM_Reset =
151 {
152         String_EntitySet( self, value, self.defValue );
153         _IDNM_Send();
154 };
155
156 void( float pEvent ) Item_Data_Nex_Map_DataEvent =
157 {
158         switch( pEvent ) {
159         case ITEM_DATA_SYNC:
160                 _IDNM_Sync();
161                 break;
162         case ITEM_DATA_SEND:
163                 _IDNM_Send();
164                 break;
165         case ITEM_DATA_RESET:
166                 _IDNM_Reset();
167                 break;
168         case ITEM_DATA_TEST_START:
169                 _IDNM_Test_Start();
170                 break;
171         case ITEM_DATA_TEST_END:
172                 _IDNM_Test_End();
173                 break;
174         case ITEM_DATALINK_SET:
175                 _IDNM_UpdateLink();
176                 break;
177         }
178 };
179
180 void() Item_Data_Nex_Map_Spawn =
181 {
182         Item_Data_Init();
183
184         self.flag = self.flag | FLAG_HIDDEN;
185
186         self._dataEvent = Item_Data_Nex_Map_DataEvent;
187
188         _IDNM_BuildList();
189
190         self._link = self._child;
191         self._realValue = stof( self.defValue );
192         _IDNM_UpdateLink();
193 };