]> icculus.org git repositories - divverent/nexuiz.git/blob - data/source/control/data/valueswitch.qc
give menu source its own directory
[divverent/nexuiz.git] / data / source / control / data / valueswitch.qc
1 // DP/Nex Menu
2 // control/data/valueswitch.qc
3
4 /*
5 ===================
6 Item_DataLink_ValueSwitch_DataEvent
7 ===================
8 */
9 void( float pEvent ) Item_DataLink_ValueSwitch_DataEvent =
10 {
11         Item_DataLink_Update();
12
13         if( pEvent == ITEM_DATALINK_SET ) {
14                 Item_DataLink_Value_Clamp();
15                 if( self._link ) {
16                         self._link._realValue = self._realValue;
17                         String_EntitySet( self._link, value, ftos( self._realValue ) );
18                         Raise_DataEvent( self._link, ITEM_DATALINK_SET );
19                 }
20         } else if( !self._link )
21                 return;
22         else if( pEvent == ITEM_DATALINK_GET ) {
23                 local float lPos;
24
25                 Raise_DataEvent( self._link, ITEM_DATALINK_GET );
26
27                 self._realValue = stof( self._link.value );
28                 Item_DataLink_Value_Clamp();
29
30                 lPos = rint( (self._realValue - self.minValue) / self.stepValue  );
31                 String_EntitySet( self, value, String_Normal( Util_GetAltStringItem( self.descList, lPos ) ) );
32         } else
33                 Raise_DataEvent( self._link, pEvent );
34 };
35
36 /*
37 ===================
38 Item_DataLink_ValueSwitch_Spawn
39 ===================
40 */
41 void() Item_DataLink_ValueSwitch_Spawn =
42 {
43         Item_DataLink_Switch_Init();
44
45         if( self.maxValue == 0.0 )
46                 self.maxValue = self.minValue + (Util_GetAltStringCount( self.descList ) - 1) * self.stepValue;
47         else {
48                 local float lCount;
49
50                 lCount = Util_GetAltStringCount( self.descList );
51                 if( lCount )
52                         self.stepValue = (self.maxValue - self.minValue ) / (lCount - 1);
53                 else
54                         self.stepValue = 0;
55         }
56
57         self._dataEvent = Item_DataLink_ValueSwitch_DataEvent;
58         self._destroy = Item_DataLink_Switch_Destroy;
59 };