]> icculus.org git repositories - divverent/nexuiz.git/blob - data/scmenu/source/control/data/textswitch.qc
restructure
[divverent/nexuiz.git] / data / 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                 if( lPos > lCount ) {
36                         // if there is no match test for a custom entry
37                         if( Util_GetAltStringCount( self.descList ) > lCount ) {
38                                 lPos++;
39                         } else {
40                                 lPos = 0;
41                         }
42                 }
43                 self._realValue = lPos;
44                 String_EntitySet( self, value, String_Normal( Util_GetAltStringItem( self.descList, lPos ) ) );
45         } else
46                 Raise_DataEvent( self._link, pEvent );
47 };
48
49 void() Item_DataLink_TextSwitch_Destroy =
50 {
51         String_EntityFree( self, valueList );
52         Item_DataLink_Switch_Destroy();
53 };
54
55 void() Item_DataLink_TextSwitch_Spawn =
56 {
57         Item_DataLink_Switch_Init();
58         String_EntityZone( self, valueList );
59
60         self.minValue = 0.0;
61         if( self.maxValue == 0.0 )
62                 self.maxValue = Util_GetAltStringCount( self.valueList ) - 1;
63         if( self.maxValue == 0.0 )
64                 self.stepValue = 0.0;
65         else
66                 self.stepValue = 1.0;
67
68         self._destroy = Item_DataLink_TextSwitch_Destroy;
69         self._dataEvent = Item_DataLink_TextSwitch_DataEvent;
70 };