]> icculus.org git repositories - divverent/nexuiz.git/blob - data/source/control/data/texttime.qc
restructure
[divverent/nexuiz.git] / data / source / control / data / texttime.qc
1 // DP/Nex Menu
2 // control/data/texttime.qc
3
4 float() _IDLTT_ConvertTime =
5 {
6         local float  lTotal;
7         local float  lCurrent;
8         local float  lCount, lCounter;
9
10         lTotal = 0;
11
12         lCount = tokenize( self.value );
13         for( lCounter = 0; lCounter < lCount; ++lCounter ) {
14                 lCurrent = stof( argv( lCounter ) );
15                 lTotal = lTotal * 60 + lCurrent;
16
17                 if( argv( ++lCounter ) != ":" )
18                         break;
19         }
20         return rint( lTotal );
21 };
22
23 string() _IDLTT_MakeString =
24 {
25         local string lString;
26         local float  lTotal;
27         local float  lCurrent;
28
29         lTotal = rint( self._realValue );
30         lString = "";
31         do {
32                 lCurrent = mod( lTotal, 60 );
33
34                 if( lString == "" )
35                         lString = String_Zone( ftos( lCurrent ) );
36                 else
37                         lString = String_Set( lString, strcat( ftos( lCurrent ), ":", lString ) );
38
39                 lTotal = floor( lTotal / 60 );
40         } while( lTotal );
41
42         return lString;
43 };
44
45 void( float pEvent ) Item_DataLink_TextTime_DataEvent =
46 {
47         Item_DataLink_Update();
48
49         if( pEvent == ITEM_DATALINK_SET ) {
50                 self._link._realValue = _IDLTT_ConvertTime();
51                 Raise_DataEvent( self._link, ITEM_DATALINK_SET );
52                 self._realValue = self._link._realValue;
53         } else if( !self._link )
54                 return;
55         else if( pEvent == ITEM_DATALINK_GET ) {
56                 Raise_DataEvent( self._link, ITEM_DATALINK_GET );
57                 if( self._link._realValue != self._realValue ) {
58                         self._realValue = self._link._realValue;
59                         String_EntitySet( self, value, String_Normal( _IDLTT_MakeString() ) );
60                 }
61         } else {
62                 Raise_DataEvent( self._link, pEvent );
63                 self._realValue = self._link._realValue;
64                 String_EntitySet( self, value, String_Normal( _IDLTT_MakeString() ) );
65         }
66 };
67
68 void() Item_DataLink_TextTime_Spawn =
69 {
70         Item_DataLink_Init();
71
72         self._dataEvent = Item_DataLink_TextTime_DataEvent;
73         self._realValue = self._link.minValue - 1;
74 };