]> icculus.org git repositories - divverent/nexuiz.git/blob - scmenu/source/control/data/textswitch.qc
Adding my current version of the scmenu to the nexuiz cvs.
[divverent/nexuiz.git] / scmenu / source / control / data / textswitch.qc
1 // DP/Nex Menu
2 // control/data/textswitch.qc
3
4
5 void( float pEvent ) Item_DataLink_TextSwitch_DataEvent =
6 {
7         Item_DataLink_Update();
8
9         if( pEvent == ITEM_DATALINK_SET ) {
10                 Item_DataLink_Value_Clamp();
11                 if( self._link ) {
12                         String_EntitySet( self._link, value, String_Normal( Util_GetAltStringItem( self.valueList, self._realValue ) ) );
13                         Raise_DataEvent( self._link, ITEM_DATALINK_SET );
14                 }
15         } else if( !self._link )
16                 return;
17         else if( pEvent == ITEM_DATALINK_GET ) {
18                 local float lPos, lCount;
19                 // sync _link.value
20                 Raise_DataEvent( self._link, ITEM_DATALINK_GET );
21
22                 // check if we need a full resync
23                 // TODO: Remove this check since we actually dont want to support twice-defined entries
24                 if( String_Normal( Util_GetAltStringItem( self.valueList, self._realValue ) ) == self._link.value ) {
25                         String_EntitySet( self, value, String_Normal( Util_GetAltStringItem( self.descList, self._realValue ) ) );
26                         return;
27                 }
28
29                 // resync _link.value
30                 lCount = Util_GetAltStringCount( self.valueList );
31                 for( lPos = 0 ; lPos < lCount ; ++lPos )
32                         if( String_Normal( Util_GetAltStringItem( self.valueList, lPos ) ) == self._link.value )
33                                 break;
34
35                 self._realValue = lPos;
36                 String_EntitySet( self, value, String_Normal( Util_GetAltStringItem( self.descList, lPos ) ) );
37         } else
38                 Raise_DataEvent( self._link, pEvent );
39 };
40
41 void() Item_DataLink_TextSwitch_Destroy =
42 {
43         String_EntityFree( self, valueList );
44         Item_DataLink_Switch_Destroy();
45 };
46
47 void() Item_DataLink_TextSwitch_Spawn =
48 {
49         Item_DataLink_Switch_Init();
50         String_EntityZone( self, valueList );
51
52         self.minValue = 0;
53         if( self.maxValue == 0.0 )
54                 self.maxValue = Util_GetAltStringCount( self.descList ) - 1;
55         if( self.maxValue == 0.0 )
56                 self.stepValue = 0.0;
57         else
58                 self.stepValue = 1;
59
60         self._destroy = Item_DataLink_TextSwitch_Destroy;
61         self._dataEvent = Item_DataLink_TextSwitch_DataEvent;
62 };