]> icculus.org git repositories - divverent/nexuiz.git/blob - data/source/custom/key.qc
give menu source its own directory
[divverent/nexuiz.git] / data / source / custom / key.qc
1 // Property of Alientrap/AK
2 // custom/key.qc
3
4 void( float pEvent ) Item_Data_Nex_Key_DataEvent;
5
6 void() _IDNK_Sync =
7 {
8         String_EntitySet( self, value, String_Normal( Key_GetBindList( self.target ) ) );
9         String_EntitySet( self, _syncValue, self.value );
10 };
11
12 void() _IDNK_Set =
13 {
14         local float lCount, lCounter;
15
16         lCount = Util_GetAltStringCount( self.value );
17         Key_LimitBinds( 0, self.target );
18
19         for( lCounter = 0 ; lCounter < lCount ; ++lCounter )
20                 Key_Bind( Key_GetName( stof( String_Normal( Util_GetAltStringItem( self.value, lCounter ) ) ) ), self.target );
21 };
22
23 void() _IDNK_Send =
24 {
25         _IDNK_Set();
26         String_EntitySet( self, _syncValue, self.value );
27 };
28
29 void() _IDNK_Reset =
30 {
31         local float lCount, lCounter;
32         local string lKey;
33         // TODO: remove this - but we need this for testing purposes atm
34         // INFO: defValue should contain the key names used by DP not the key numbers!
35         if( !self.defValue )
36                 return;
37
38         String_EntitySet( self, value, "" );
39
40         lCount = Util_GetAltStringCount( self.defValue );
41         Key_LimitBinds( 0, self.target );
42
43         for( lCounter = 0 ; lCounter < lCount ; lCounter++ ) {
44                 lKey = Util_GetAltStringItem( self.defValue, lCounter );
45                 Key_Bind( lKey, self.target );
46                 String_EntitySet( self, value, strcat( self.value, " '", Key_GetNum( lKey ), "'" ) );
47                 String_Free( lKey );
48         }
49
50         String_EntitySet( self, _syncValue, self.value );
51 };
52
53 void() _IDNK_Test_Start =
54 {
55         _IDNK_Set();
56 };
57
58 void() _IDNK_Test_End =
59 {
60         String_EntitySet( self, value, self._syncValue );
61         _IDNK_Set();
62 };
63
64 void( float pEvent ) Item_Data_Nex_Key_DataEvent =
65 {
66         switch( pEvent ) {
67         case ITEM_DATA_SYNC:
68                 _IDNK_Sync();
69                 break;
70         case ITEM_DATA_SEND:
71                 _IDNK_Send();
72                 break;
73         case ITEM_DATA_RESET:
74                 _IDNK_Reset();
75                 break;
76         case ITEM_DATA_TEST_START:
77                 _IDNK_Test_Start();
78                 break;
79         case ITEM_DATA_TEST_END:
80                 _IDNK_Test_End();
81                 break;
82         }
83 };
84
85 void() Item_Data_Nex_Key_Destroy =
86 {
87         String_EntityFree( self, target );
88         Item_Data_Destroy();
89 };
90
91 void() Item_Data_Nex_Key_Spawn =
92 {
93         Item_Data_Init();
94
95         String_EntityZone( self, target );
96
97         self._destroy = Item_Data_Nex_Key_Destroy;
98         self._reinit = _IDNK_Sync;
99         self._dataEvent = Item_Data_Nex_Key_DataEvent;
100 };
101
102
103 /*
104 ===================
105 Item_Nex_KeyButton Item_Button
106 ===================
107 */
108
109 bool( float pKey, float pAscii ) Item_Nex_KeyButton_Key =
110 {
111         if( pKey == K_BACKSPACE ) {
112                 local float lNum;
113                 // unbind the key
114                 Raise_DataEvent( self._target, ITEM_DATALINK_GET );
115                 lNum = stof( self._target.value );
116                 if( lNum >= 0 ) {
117                         Key_Unbind( Key_GetName( lNum ) );
118                         Raise_DataEvent( self._target, ITEM_DATALINK_SET );
119                 }
120                 return true;
121         } else if( pKey == K_UPARROW ) {
122                 Menu_SelectPrev( false );
123                 Menu_SelectPrev( true );
124                 return true;
125         } else if( pKey == K_DOWNARROW ) {
126                 Menu_SelectNext( false );
127                 Menu_SelectNext( true );
128                 return true;
129         } else
130                 return Item_Button_Key( pKey, pAscii );
131 };
132
133 void() Item_Nex_KeyButton_Update =
134 {
135         local float lNum;
136         Item_DataUser_Update();
137
138         Raise_DataEvent( self._target, ITEM_DATALINK_GET );
139         lNum = stof( self._target.value );
140         if( lNum < 0 )
141                 String_EntitySet( self, normal, "-" );
142         else
143                 String_EntitySet( self, normal, Key_GetName( lNum ) );
144         Item_Button_Update();
145 };
146
147 void() Item_Nex_KeyButton_Destroy =
148 {
149         Item_DataUser_Destroy();
150         Item_Button_Destroy();
151 };
152
153 void() Item_Nex_KeyButton_Spawn =
154 {
155         Item_DataUser_Init();
156         Item_Button_Spawn();
157
158         self._destroy = Item_Nex_KeyButton_Destroy;
159         self._update = Item_Nex_KeyButton_Update;
160         self._key = Item_Nex_KeyButton_Key;
161 };
162