]> icculus.org git repositories - divverent/nexuiz.git/blob - scmenu/source/control/visual/list.qc
-Added the control item Item_List (to be used later in conjunction with the
[divverent/nexuiz.git] / scmenu / source / control / visual / list.qc
1 // DP/Nex Menu
2 // control/visual/list.qc
3
4 void() Item_List_Draw =
5 {
6         local float lStart;
7         local float lLines;
8         local float lLine;
9         local float lEnd;
10         local vector lPos;
11
12
13         if( !self._target )
14                 return;
15
16         lLines = floor( self.size_y / ( self.fontSize_y + 2 ) );
17         lStart = max( 0, floor( Item_DataLink_Switch_GetOrdinal( self._target, self._target._realValue ) - lLines / 2 ) );
18         lEnd = min( lStart + lLines, Item_DataLink_Switch_GetOrdinal( self._target, self._target.maxValue ) );
19
20         lPos = '0 1 0' + self.pos;
21         for( lLine = lStart ; lLine <= lEnd ; lLine++ ) {
22                 local string lText;
23                 lText = Util_GetAltStringItem( self._target.descList, lLine );
24                 if( lLine == Item_DataLink_Switch_GetOrdinal( self._target, self._target._realValue ) ) {
25                         if( self._state == ITEM_STATE_SELECTED )
26                                 Menu_DrawString( lPos, lText, self.fontSize, self.colorSelected, self.alphas_y, self.drawFlags_y );
27                         else if( self._state == ITEM_STATE_PRESSED )
28                                 Menu_DrawString( lPos, lText, self.fontSize, self.colorPressed, self.alphas_z, self.drawFlags_z );
29                         else
30                                 Menu_DrawString( lPos, lText, self.fontSize, self.colorInactive, self.alphaInactive, self.drawFlagInactive );
31                 } else {
32                         Menu_DrawString( lPos, lText, self.fontSize, self.color, self.alphas_x, self.drawFlags_x );
33                 }
34
35                 lPos_y = lPos_y + self.fontSize_y + 1;
36
37                 String_Free( lText );
38         }
39 };
40
41 void() Item_List_Update =
42 {
43         Item_DataUser_Update();
44
45         if( self._presstime + ITEM_BUTTON_ACTIONTIME > Timer_Time )
46                 self._state = ITEM_STATE_PRESSED;
47         else if( Menu_ActiveItem == self )
48                 self._state = ITEM_STATE_SELECTED;
49         else
50                 self._state = ITEM_STATE_NORMAL;
51
52         /*if( Menu_HasRunFlag( self, RUNFLAG_MOUSEINAREA ) ) {
53                 local float lItem;
54                 local float lStart;
55                 local float lLines;
56
57                 lLines = floor( self.size_y / ( self.fontSize_y + 2 ) );
58                 lStart = max( 0, floor( Item_DataLink_Switch_GetOrdinal( self._target, self._target._realValue ) - lLines / 2 ) );
59                 lItem = floor( ( Menu_Cursor_Position_y - self.pos_y ) / ( self.fontSize_y + 2 ) );
60                 lItem = min( lStart + lItem, Item_DataLink_Switch_GetOrdinal( self._target, self._target.maxValue ) );
61
62                 print( ftos( lItem ), "\n" );
63
64                 self._target._realValue = lItem * self._target.stepValue + self._target.minValue;
65                 Raise_DataEvent( self._target, ITEM_DATALINK_SET );
66
67                 CtCall_Action();
68         }*/
69 };
70
71 void( bool pSelect, bool pUser ) Item_List_Select =
72 {
73         if( pSelect && pUser )
74                 Sound_Play( self.soundSelected );
75 };
76
77 bool( float pKey, float pAscii ) Item_List_Key =
78 {
79         if( pKey == K_DOWNARROW ) {
80                 Sound_Play( self.soundPressed );
81                 self._presstime = Timer_Time;
82
83                 self._target._realValue = self._target._realValue + 1;
84                 if( self._target._realValue > self._target.maxValue )
85                         self._target._realValue = self._target.minValue;
86                 Raise_DataEvent( self._target, ITEM_DATALINK_SET );
87
88                 CtCall_Action();
89                 return true;
90         } else if( pKey == K_UPARROW ) {
91                 Sound_Play( self.soundPressed );
92                 self._presstime = Timer_Time;
93
94                 self._target._realValue = self._target._realValue - 1;
95                 if( self._target._realValue < self._target.minValue )
96                         self._target._realValue = self._target.maxValue;
97
98                 Raise_DataEvent( self._target, ITEM_DATALINK_SET );
99
100                 CtCall_Action();
101                 return true;
102         }
103         return false;
104 };
105
106 void() Item_List_Destroy =
107 {
108         CtCall_Destroy();
109
110         String_EntityFree( self, soundSelected );
111         String_EntityFree( self, soundPressed );
112
113         Item_DataUser_Destroy();
114 };
115
116 void() Item_List_Spawn =
117 {
118         Item_DataUser_Init();
119
120         String_EntityZone( self, soundSelected );
121         String_EntityZone( self, soundPressed );
122
123         Sound_Precache( self.soundSelected );
124         Sound_Precache( self.soundPressed );
125
126         self._draw = Item_List_Draw;
127         self._update = Item_List_Update;
128         self._select = Item_List_Select;
129         self._key = Item_List_Key;
130         self._reinit = CtCall_Reinit;
131
132         CtCall_Init();
133 };