Skip to content

Commit e8d4dbe

Browse files
committed
MAJOR CHANGES! Input is rewritten! Key method is removed, introduced two new mehtods: KeyUp and KeyDown. onActivate event renamed to onReleased. QMF_ACT_ONRELEASE is removed. Added more helper functions to UI::Key. KeyUp/KeyDown methods doesn't return sound name anymore, instead of this you should call CMenuBaseItem::PlayLocalSound, which will take care of QMF_SILENT flag automatically. These methods now return true if key was handled, that means, for example, item holder will not use navigation code. In context of windows this doesn't mean anything for now. Items now will never get released event, if were not pressed before.
1 parent 634a0b8 commit e8d4dbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+902
-786
lines changed

BaseMenu.cpp

+24-18
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,6 @@ void UI_UpdateMenu( float flTime )
756756
// we loading background so skip SCR_Update
757757
if( UI_StartBackGroundMap( )) return;
758758

759-
uiStatic.menu.menuActive->Activate();
760-
761759
uiStatic.firstDraw = false;
762760
static int first = TRUE;
763761

@@ -784,32 +782,40 @@ void UI_UpdateMenu( float flTime )
784782
uiStatic.menu.Update();
785783
}
786784

787-
void windowStack_t::KeyEvent( int key, int down )
785+
void windowStack_t::KeyUpEvent( int key )
788786
{
789787
const char *sound = NULL;
790788

791-
if( !IsActive() )
792-
return;
793-
794-
if( key == K_MOUSE1 )
789+
// go down on stack to nearest root or dialog
790+
int rootPos = rootPosition;
791+
for( int i = menuDepth-1; i >= rootPos; i-- )
795792
{
796-
g_bCursorDown = !!down;
793+
bool handled = menuStack[i]->KeyUp( key );
794+
795+
if( menuStack[i]->iFlags & QMF_DIALOG )
796+
break;
797797
}
798+
}
798799

800+
void windowStack_t::KeyDownEvent( int key )
801+
{
799802
// go down on stack to nearest root or dialog
800803
int rootPos = rootPosition;
801804
for( int i = menuDepth-1; i >= rootPos; i-- )
802805
{
803-
sound = menuStack[i]->Key( key, down );
804-
805-
if( !down && sound && sound != uiSoundNull )
806-
EngFuncs::PlayLocalSound( sound );
806+
bool handled = menuStack[i]->KeyDown( key );
807807

808808
if( menuStack[i]->iFlags & QMF_DIALOG )
809809
break;
810810
}
811811
}
812812

813+
void windowStack_t::KeyEvent( int key, bool down )
814+
{
815+
down ? KeyDownEvent( key ) : KeyUpEvent( key );
816+
}
817+
818+
813819
/*
814820
=================
815821
UI_KeyEvent
@@ -822,6 +828,11 @@ void UI_KeyEvent( int key, int down )
822828
if( !uiStatic.initialized )
823829
return;
824830

831+
if( key == K_MOUSE1 )
832+
{
833+
g_bCursorDown = !!down;
834+
}
835+
825836
clientActive = uiStatic.client.IsActive();
826837
menuActive = uiStatic.menu.IsActive();
827838

@@ -834,9 +845,6 @@ void UI_KeyEvent( int key, int down )
834845

835846
void windowStack_t::CharEvent( int key )
836847
{
837-
if( !menuActive )
838-
return;
839-
840848
int rootPos = rootPosition;
841849
for( int i = menuDepth-1; i >= rootPos; i-- )
842850
{
@@ -869,11 +877,9 @@ void UI_CharEvent( int key )
869877

870878
void windowStack_t::MouseEvent( int x, int y )
871879
{
872-
int i;
873-
874880
// go down on stack to nearest root or dialog
875881
int rootPos = rootPosition;
876-
for( i = menuDepth-1; i >= rootPos; i-- )
882+
for( int i = menuDepth-1; i >= rootPos; i-- )
877883
{
878884
menuStack[i]->MouseMove( x, y );
879885

BaseMenu.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ class windowStack_t
8585
bool IsActive( void ) { return menuDepth > 0; }
8686
void VidInit( bool firstTime );
8787
void Update( void );
88-
void KeyEvent( int key, int down );
88+
void KeyEvent( int key, bool down );
89+
void KeyUpEvent( int key );
90+
void KeyDownEvent( int key );
8991
void CharEvent( int ch );
9092
void MouseEvent( int x, int y );
9193

EventSystem.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ enum menuEvent_e
6868
{
6969
QM_GOTFOCUS = 1,
7070
QM_LOSTFOCUS,
71-
QM_ACTIVATED,
71+
QM_RELEASED,
7272
QM_CHANGED,
7373
QM_PRESSED,
7474
QM_IMRESIZED

Primitive.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ enum
5454
QMF_HASMOUSEFOCUS = BIT( 6 ),
5555
QMF_MOUSEONLY = BIT( 7 ), // Only mouse input allowed
5656
QMF_NOTIFY = BIT( 9 ), // draw notify at right screen side
57-
QMF_ACT_ONRELEASE = BIT( 10 ), // call Key_Event when button is released
57+
// deprecated: QMF_ACT_ONRELEASE = BIT( 10 ), // call Key_Event when button is released
5858
QMF_HASKEYBOARDFOCUS = BIT( 11 ),
5959
QMF_DIALOG = BIT( 12 ), // modal windows. Will grab key, char and mousemove events
6060
QMF_DISABLESCAILING = BIT( 13 ), // disables CalcPosition and CalcSizes
61-
QMF_EVENTSIGNOREFOCUS = BIT( 14 ), // don't care if item have focus, it must get events anyway. NOTE: they cannot issue sounds
62-
61+
QMF_EVENTSIGNOREFOCUS = BIT( 14 ), // don't care if item have focus, it must get events anyway
6362
QMF_HIDDENBYPARENT = BIT( 30 ), // INTERNAL USE ONLY: parent set this flag and don't want to draw this control
6463
QMF_HIDDEN = BIT( 31 ), // INTERNAL USE ONLY: Use Show/Hide/SetVisibility/ToggleVisibility
6564
};

Utils.h

+41-8
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,53 @@ namespace Key
205205
{
206206
inline bool IsEscape( int key )
207207
{
208-
return ( key == K_ESCAPE
208+
switch( key )
209+
{
210+
case K_ESCAPE:
209211
#ifndef XASH_DISABLE_FWGS_EXTENSIONS
210-
|| key == K_B_BUTTON
211-
#endif // XASH_DISABLE_FWGS_EXTENSIONS
212-
);
212+
case K_B_BUTTON:
213+
#endif
214+
return true;
215+
}
216+
return false;
213217
}
214218

215219
inline bool IsEnter( int key )
216220
{
217-
return ( key == K_ENTER
221+
switch( key )
222+
{
223+
case K_ENTER:
224+
case K_KP_ENTER:
218225
#ifndef XASH_DISABLE_FWGS_EXTENSIONS
219-
|| key == K_A_BUTTON
220-
#endif // XASH_DISABLE_FWGS_EXTENSIONS
221-
);
226+
case K_A_BUTTON:
227+
#endif
228+
return true;
229+
}
230+
return false;
231+
}
232+
233+
inline bool IsLeftMouse( int key )
234+
{
235+
switch( key )
236+
{
237+
case K_MOUSE1:
238+
return true;
239+
}
240+
return false;
241+
}
242+
243+
inline bool IsMouse( int key )
244+
{
245+
switch( key )
246+
{
247+
case K_MOUSE1:
248+
case K_MOUSE2:
249+
case K_MOUSE3:
250+
case K_MOUSE4:
251+
case K_MOUSE5:
252+
return true;
253+
}
254+
return false;
222255
}
223256
}
224257

controls/Action.cpp

+23-38
Original file line numberDiff line numberDiff line change
@@ -74,52 +74,37 @@ void CMenuAction::VidInit( )
7474
CMenuAction::Key
7575
=================
7676
*/
77-
const char *CMenuAction::Key( int key, int down )
77+
bool CMenuAction::KeyUp( int key )
7878
{
79-
const char *sound = 0;
79+
const char *sound = 0;
8080

81-
switch( key )
82-
{
83-
case K_MOUSE1:
84-
if(!( iFlags & QMF_HASMOUSEFOCUS ))
85-
break;
81+
if( UI::Key::IsEnter( key ) && !(iFlags & QMF_MOUSEONLY) )
8682
sound = uiSoundLaunch;
87-
break;
88-
case K_ENTER:
89-
case K_KP_ENTER:
90-
case K_AUX1:
91-
//if( !down ) return sound;
92-
if( iFlags & QMF_MOUSEONLY )
93-
break;
83+
else if( UI::Key::IsLeftMouse( key ) && ( iFlags & QMF_HASMOUSEFOCUS ) )
9484
sound = uiSoundLaunch;
95-
break;
96-
}
9785

98-
if( sound && ( iFlags & QMF_SILENT ))
99-
sound = uiSoundNull;
100-
101-
if( iFlags & QMF_ACT_ONRELEASE )
102-
{
103-
if( sound )
104-
{
105-
int event;
106-
107-
if( down )
108-
{
109-
event = QM_PRESSED;
110-
m_bPressed = true;
111-
}
112-
else event = QM_ACTIVATED;
113-
_Event( event );
114-
}
115-
}
116-
else if( down )
86+
if( sound )
11787
{
118-
if( sound )
119-
_Event( QM_ACTIVATED );
88+
_Event( QM_PRESSED );
89+
PlayLocalSound( sound );
12090
}
12191

122-
return sound;
92+
return sound != NULL;
93+
}
94+
95+
bool CMenuAction::KeyDown( int key )
96+
{
97+
bool handled = false;
98+
99+
if( UI::Key::IsEnter( key ) && !(iFlags & QMF_MOUSEONLY) )
100+
handled = true;
101+
else if( UI::Key::IsLeftMouse( key ) && ( iFlags & QMF_HASMOUSEFOCUS ) )
102+
handled = true;
103+
104+
if( handled )
105+
_Event( QM_PRESSED );
106+
107+
return handled;
123108
}
124109

125110
/*

controls/Action.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class CMenuAction : public CMenuBaseItem
2727
CMenuAction();
2828

2929
void VidInit( void ) override;
30-
const char * Key( int key, int down ) override;
30+
bool KeyUp( int key ) override;
31+
bool KeyDown( int key ) override;
3132
void Draw( void ) override;
3233

3334
void SetBackground( const char *path, unsigned int color = uiColorWhite );

controls/BaseClientWindow.cpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,21 @@ CMenuBaseClientWindow::CMenuBaseClientWindow( const char *name ) :
2121
m_pStack = &uiStatic.client;
2222
}
2323

24-
const char *CMenuBaseClientWindow::Key(int key, int down)
24+
bool CMenuBaseClientWindow::KeyDown( int key )
2525
{
26-
if( down )
26+
// copy engine behaviour
27+
if( UI::Key::IsEscape( key ))
2728
{
28-
if( UI::Key::IsEscape( key ))
29-
{
30-
EngFuncs::KEY_SetDest( KEY_GAME ); // set engine states before "escape"
31-
EngFuncs::ClientCmd( FALSE, "escape\n" );
32-
return uiSoundNull;
33-
}
34-
else if( key == '`' )
35-
{
36-
EngFuncs::KEY_SetDest( KEY_CONSOLE );
37-
}
29+
EngFuncs::KEY_SetDest( KEY_GAME ); // set engine states before "escape"
30+
EngFuncs::ClientCmd( FALSE, "escape\n" );
31+
return true;
32+
}
33+
else if( key == '`' )
34+
{
35+
EngFuncs::KEY_SetDest( KEY_CONSOLE );
3836
}
3937

40-
return BaseClass::Key( key, down );
41-
38+
return BaseClass::KeyDown( key );
4239
}
4340

4441

controls/BaseClientWindow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CMenuBaseClientWindow : public CMenuBaseWindow
2424
typedef CMenuBaseWindow BaseClass;
2525
CMenuBaseClientWindow( const char *name = "BaseClientWindow" );
2626

27-
const char *Key( int key, int down ) override;
27+
bool KeyDown( int key ) override;
2828
};
2929

3030
#endif // BASECLIENTWINDOW_H

0 commit comments

Comments
 (0)