Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ba40a5

Browse files
committed
Move window stack to seperate class, so we can have more than one stacks active, i.e. one for main menu, second for client menus. Add little class for client windows.
1 parent abba872 commit 0ba40a5

10 files changed

Lines changed: 442 additions & 265 deletions

BaseMenu.cpp

Lines changed: 222 additions & 196 deletions
Large diffs are not rendered by default.

BaseMenu.h

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ GNU General Public License for more details.
1515

1616
#ifndef BASEMENU_H
1717
#define BASEMENU_H
18+
#ifdef CS16CLIENT
19+
#include "../public/cl_dll/IGameClientExports.h"
20+
#endif
1821
#include "enginecallback_menu.h"
1922
#include "keydefs.h"
2023
#include "Primitive.h"
@@ -58,22 +61,47 @@ GNU General Public License for more details.
5861
// =====================================================================
5962
// Main menu interface
6063

64+
#ifdef CS16CLIENT
65+
extern IGameClientExports *g_pClient;
66+
#endif
6167
extern cvar_t *ui_precache;
6268
extern cvar_t *ui_showmodels;
6369
extern cvar_t *ui_show_window_stack;
6470
extern cvar_t *ui_borderclip;
6571

6672
class CMenuBaseWindow;
6773

68-
typedef struct
74+
class windowStack_t
6975
{
76+
public:
7077
CMenuBaseWindow *rootActive; // current active fullscreen holder(menu framework)
7178
CMenuBaseWindow *menuActive; // current active window
7279
CMenuBaseWindow *prevMenu; // previous active window
7380
CMenuBaseWindow *menuStack[UI_MAX_MENUDEPTH];
74-
int menuDepth;
75-
int rootPosition;
81+
int menuDepth;
82+
int rootPosition;
83+
84+
bool IsActive( void ) { return menuDepth > 0; }
85+
void VidInit( bool firstTime );
86+
void Update( void );
87+
void KeyEvent( int key, int down );
88+
void CharEvent( int ch );
89+
void MouseEvent( int x, int y );
90+
91+
void InputMethodResized( void );
92+
93+
void Close( void )
94+
{
95+
menuActive = NULL;
96+
menuDepth = 0;
97+
rootPosition = 0;
98+
}
99+
};
76100

101+
typedef struct
102+
{
103+
windowStack_t menu;
104+
windowStack_t client; // separate window stack for client windows
77105
char bgmaps[UI_MAX_BGMAPS][80];
78106
int bgmapcount;
79107

@@ -89,8 +117,8 @@ typedef struct
89117
HFont hHeavyBlur;
90118
#endif
91119
bool m_fDemosPlayed;
92-
int m_iOldMenuDepth;
93120
bool m_fNoOldBackground;
121+
int m_iOldMenuDepth;
94122

95123
float scaleX;
96124
float scaleY;
@@ -103,7 +131,6 @@ typedef struct
103131
float enterSound;
104132
int mouseInRect;
105133
int hideCursor;
106-
int visible;
107134
int framecount; // how many frames menu visible
108135
int initialized;
109136

@@ -116,8 +143,7 @@ typedef struct
116143
int buttons_draw_width; // scaled image what we drawing
117144
int buttons_draw_height;
118145
int width;
119-
bool textInput;
120-
146+
bool textInput;
121147
bool enableAlphaFactor;
122148
float alphaFactor;
123149
int xOffset, yOffset;
@@ -133,6 +159,7 @@ extern uiStatic_t uiStatic;
133159
#define DLG_X ((uiStatic.width - 640) / 2 - 192) // Dialogs are 640px in width
134160

135161
extern const char *uiSoundIn;
162+
extern const char *uiSoundRollOver;
136163
extern const char *uiSoundOut;
137164
extern const char *uiSoundKey;
138165
extern const char *uiSoundRemoveKey;
@@ -175,8 +202,8 @@ enum ETextFlags
175202
ETF_ADDITIVE = BIT( 3 )
176203
};
177204

178-
int UI_DrawString( HFont font, int x, int y, int w, int h, const char *str, const unsigned int col, int charH, ETextAlignment justify, uint flags = 0 );
179-
inline int UI_DrawString( HFont font, Point pos, Size size, const char *str, const unsigned int col, int charH, ETextAlignment justify, uint flags = 0 )
205+
int UI_DrawString( HFont font, int x, int y, int w, int h, const char *str, const unsigned int col, int charH, uint justify, uint flags = 0 );
206+
inline int UI_DrawString( HFont font, Point pos, Size size, const char *str, const unsigned int col, int charH, uint justify, uint flags = 0 )
180207
{
181208
return UI_DrawString( font, pos.x, pos.y, size.w, size.h, str, col, charH, justify, flags );
182209
}

controls/BaseClientWindow.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
BaseWindow.h -- base client menu window
3+
Copyright (C) 2018 a1batross
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
*/
15+
#include "BaseMenu.h"
16+
#include "BaseClientWindow.h"
17+
18+
CMenuBaseClientWindow::CMenuBaseClientWindow( const char *name ) :
19+
BaseClass( name )
20+
{
21+
m_pStack = &uiStatic.client;
22+
}
23+
24+
const char *CMenuBaseClientWindow::Key(int key, int down)
25+
{
26+
if( down )
27+
{
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+
}
38+
}
39+
40+
return BaseClass::Key( key, down );
41+
42+
}
43+
44+

controls/BaseClientWindow.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
BaseWindow.h -- base client menu window
3+
Copyright (C) 2018 a1batross
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
*/
15+
#pragma once
16+
#ifndef BASECLIENTWINDOW_H
17+
#define BASECLIENTWINDOW_H
18+
19+
#include "BaseWindow.h"
20+
21+
class CMenuBaseClientWindow : public CMenuBaseWindow
22+
{
23+
public:
24+
typedef CMenuBaseWindow BaseClass;
25+
CMenuBaseClientWindow( const char *name = "BaseClientWindow" );
26+
27+
const char *Key( int key, int down ) override;
28+
};
29+
30+
#endif // BASECLIENTWINDOW_H

controls/BaseWindow.cpp

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,77 +25,79 @@ CMenuBaseWindow::CMenuBaseWindow(const char *name) : BaseClass()
2525
m_bHolding = false;
2626
bInTransition = false;
2727
szName = name;
28+
m_pStack = &uiStatic.menu;
2829
}
2930

3031
void CMenuBaseWindow::Show()
3132
{
3233
Init();
3334
VidInit();
3435
Reload(); // take a chance to reload info for items
35-
PushMenu();
36+
PushMenu( *m_pStack );
3637
EnableTransition();
3738
}
3839

3940
void CMenuBaseWindow::Hide()
4041
{
41-
PopMenu();
42+
PopMenu( *m_pStack );
4243
EnableTransition();
4344
}
4445

4546
bool CMenuBaseWindow::IsVisible() const
4647
{
4748
// slow!
48-
for( int i = uiStatic.rootPosition; i < uiStatic.menuDepth; i++ )
49+
for( int i = m_pStack->rootPosition; i < m_pStack->menuDepth; i++ )
4950
{
50-
if( uiStatic.menuStack[i] == this )
51+
if( m_pStack->menuStack[i] == this )
5152
return true;
5253
}
5354
return false;
5455
}
5556

56-
void CMenuBaseWindow::PushMenu()
57+
void CMenuBaseWindow::PushMenu( windowStack_t &stack )
5758
{
5859
int i;
5960
CMenuBaseItem *item;
6061

6162
// if this menu is already present, drop back to that level to avoid stacking menus by hotkeys
62-
for( i = 0; i < uiStatic.menuDepth; i++ )
63+
for( i = 0; i < stack.menuDepth; i++ )
6364
{
64-
if( uiStatic.menuStack[i] == this )
65+
if( stack.menuStack[i] == this )
6566
{
6667
if( IsRoot() )
67-
uiStatic.menuDepth = i;
68+
stack.menuDepth = i;
6869
else
6970
{
70-
if( i != uiStatic.menuDepth - 1 )
71+
if( i != stack.menuDepth - 1 )
7172
{
7273
// swap windows
73-
uiStatic.menuStack[i] = uiStatic.menuActive;
74-
uiStatic.menuStack[uiStatic.menuDepth] = this;
74+
stack.menuStack[i] = stack.menuActive;
75+
stack.menuStack[stack.menuDepth] = this;
7576
}
7677
}
7778
break;
7879
}
7980
}
8081

81-
if( i == uiStatic.menuDepth )
82+
if( i == stack.menuDepth )
8283
{
83-
if( uiStatic.menuDepth >= UI_MAX_MENUDEPTH )
84+
if( stack.menuDepth >= UI_MAX_MENUDEPTH )
8485
Host_Error( "UI_PushMenu: menu stack overflow\n" );
85-
uiStatic.menuStack[uiStatic.menuDepth++] = this;
86+
stack.menuStack[stack.menuDepth++] = this;
8687
}
8788

88-
uiStatic.prevMenu = uiStatic.menuActive;
89-
if( this->IsRoot() && uiStatic.prevMenu && uiStatic.prevMenu->IsRoot() )
90-
uiStatic.prevMenu->EnableTransition();
91-
uiStatic.menuActive = this;
89+
stack.prevMenu = stack.menuActive;
90+
if( this->IsRoot() && stack.prevMenu && stack.prevMenu->IsRoot() )
91+
stack.prevMenu->EnableTransition();
92+
stack.menuActive = this;
9293

93-
uiStatic.firstDraw = true;
94-
uiStatic.enterSound = gpGlobals->time + 0.15f; // make some delay
95-
uiStatic.visible = true;
96-
97-
EngFuncs::KEY_SetDest ( KEY_MENU );
94+
if( &stack == &uiStatic.menu ) // hack!
95+
{
96+
uiStatic.firstDraw = true;
97+
uiStatic.enterSound = gpGlobals->time + 0.15f; // make some delay
9898

99+
EngFuncs::KEY_SetDest ( KEY_MENU );
100+
}
99101

100102
m_iCursor = 0;
101103

@@ -123,38 +125,44 @@ void CMenuBaseWindow::PushMenu()
123125
#endif
124126
}
125127

126-
void CMenuBaseWindow::PopMenu()
128+
void CMenuBaseWindow::PopMenu( windowStack_t &stack )
127129
{
128-
EngFuncs::PlayLocalSound( uiSoundOut );
130+
if( &stack == &uiStatic.menu ) // hack!
131+
{
132+
EngFuncs::PlayLocalSound( uiSoundOut );
133+
}
129134

130-
uiStatic.menuDepth--;
135+
stack.menuDepth--;
131136

132-
if( uiStatic.menuDepth < 0 )
137+
if( stack.menuDepth < 0 )
133138
Host_Error( "UI_PopMenu: menu stack underflow\n" );
134139

135-
if( uiStatic.menuDepth )
140+
if( stack.menuDepth )
136141
{
137-
uiStatic.prevMenu = this;
138-
uiStatic.menuActive = uiStatic.menuStack[uiStatic.menuDepth-1];
139-
if( this->IsRoot() && uiStatic.menuActive->IsRoot() )
140-
uiStatic.menuActive->EnableTransition();
142+
stack.prevMenu = this;
143+
stack.menuActive = stack.menuStack[stack.menuDepth-1];
144+
if( this->IsRoot() && stack.menuActive->IsRoot() )
145+
stack.menuActive->EnableTransition();
141146

142147
uiStatic.firstDraw = true;
143148
}
144-
else if ( CL_IsActive( ))
149+
else if( &stack == &uiStatic.menu ) // hack!
145150
{
146-
UI_CloseMenu();
147-
}
148-
else
149-
{
150-
// a1ba: not needed anymore?
151+
if ( CL_IsActive( ))
152+
{
153+
UI_CloseMenu();
154+
}
155+
else
156+
{
157+
// a1ba: not needed anymore?
151158

152-
// never trying the close menu when client isn't connected
153-
EngFuncs::KEY_SetDest( KEY_MENU );
154-
UI_Main_Menu();
159+
// never trying the close menu when client isn't connected
160+
EngFuncs::KEY_SetDest( KEY_MENU );
161+
UI_Main_Menu();
162+
}
155163
}
156164

157-
if( uiStatic.m_fDemosPlayed && uiStatic.m_iOldMenuDepth == uiStatic.menuDepth )
165+
if( &stack == &uiStatic.menu && uiStatic.m_fDemosPlayed && uiStatic.m_iOldMenuDepth == stack.menuDepth )
158166
{
159167
EngFuncs::ClientCmd( FALSE, "demos\n" );
160168
uiStatic.m_fDemosPlayed = false;
@@ -224,8 +232,6 @@ bool CMenuBaseWindow::DrawAnimation(EAnimation anim)
224232

225233
UI_DisableAlphaFactor();
226234

227-
if( IsRoot() )
228-
CMenuPicButton::DrawTitleAnim( anim );
229235
return false;
230236
}
231237

@@ -256,7 +262,7 @@ bool CMenuBaseWindow::KeyValueData(const char *key, const char *data)
256262

257263
void CMenuBaseWindow::EnableTransition()
258264
{
259-
if( uiStatic.prevMenu )
265+
if( m_pStack->prevMenu )
260266
{
261267
bInTransition = true;
262268
m_iTransitionStartTime = uiStatic.realTime;

controls/BaseWindow.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,19 @@ class CMenuBaseWindow : public CMenuItemsHolder
7575
bool bInTransition;
7676
EAnimation eTransitionType; // valid only when in transition
7777
CMenuBackgroundBitmap background;
78+
79+
const windowStack_t *WindowStack() const
80+
{
81+
return m_pStack;
82+
}
83+
7884
protected:
7985
int m_iTransitionStartTime;
8086

87+
void PushMenu( windowStack_t &stack );
88+
void PopMenu( windowStack_t &stack );
89+
windowStack_t *m_pStack;
90+
8191
private:
8292
CMenuBaseWindow(); // remove
8393

@@ -88,9 +98,6 @@ class CMenuBaseWindow : public CMenuItemsHolder
8898

8999
bool m_bHolding;
90100
Point m_bHoldOffset;
91-
92-
void PushMenu();
93-
void PopMenu();
94101
};
95102

96103
#endif // BASEWINDOW_H

0 commit comments

Comments
 (0)