-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuiwsw_Export.cpp
298 lines (243 loc) · 10.9 KB
/
uiwsw_Export.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
Copyright (C) 2002-2008 The Warsow devteam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "uiwsw_Utils.h"
#include "uimenu_Global.h"
#include "uiwsw_Export.h"
#include "uiwsw_MapList.h"
#include "uiwsw_PlayerModels.h"
#include "../gameshared/gs_qrespath.h"
#include "../client/keys.h"
using namespace UIWsw;
int UIWsw::UI_API (void)
{
return UI_API_VERSION;
}
void UIWsw::UI_Init( int vidWidth, int vidHeight, float pixelRatio,
int protocol, const char *demoExtension, const char *basePath )
{
Local::vidWidth = vidWidth;
Local::vidHeight = vidHeight;
Local::gameProtocol = protocol;
#if 0
Local::scaleX = float(vidWidth) / REL_WIDTH;
Local::scaleY = float(vidHeight) / REL_HEIGHT;
#else
Local::scaleX = 1;
Local::scaleY = 1;
#endif
Local::cursorX = Local::vidWidth / 2;
Local::cursorY = Local::vidHeight / 2;
// wsw/Mokshu : test svn addin for VS 2005 and what about a "help/news" menu (latest news from website for example)
Trap::Cmd_AddCommand( "menu_main", UIMenu::M_Menu_Main_f );
Trap::Cmd_AddCommand( "menu_force", UIMenu::M_Menu_Force_f );
Trap::Cmd_AddCommand( "menu_joinserver", UIMenu::M_Menu_JoinServer_f );
Trap::Cmd_AddCommand( "menu_startserver", UIMenu::M_Menu_StartServer_f );
Trap::Cmd_AddCommand( "menu_setup", UIMenu::M_Menu_Setup_f );
Trap::Cmd_AddCommand( "menu_playersetup", UIMenu::M_Menu_SetupPlayer_f );
Trap::Cmd_AddCommand( "menu_sound", UIMenu::M_Menu_SetupSound_f );
Trap::Cmd_AddCommand( "menu_graphics", UIMenu::M_Menu_SetupGraphics_f );
Trap::Cmd_AddCommand( "menu_quit", UIMenu::M_Menu_Quit_f );
Trap::Cmd_AddCommand( "menu_login", UIMenu::M_Menu_Login_f );
Trap::Cmd_AddCommand( "menu_custom", UIMenu::M_Menu_Custom_f );
// precache sounds
Trap::S_RegisterSound( S_UI_MENU_IN_SOUND );
Trap::S_RegisterSound( S_UI_MENU_MOVE_SOUND );
Trap::S_RegisterSound( S_UI_MENU_OUT_SOUND );
// precache shaders
Local::whiteShader = Trap::R_RegisterPic( "gfx/ui/white" );
Trap::R_RegisterPic( UI_SHADER_FXBACK );
Trap::R_RegisterPic( UI_SHADER_BIGLOGO );
Trap::R_RegisterPic( UI_SHADER_CURSOR );
// precache fonts
cvar_t *con_fontSystemFamily = Trap::Cvar_Get( "con_fontSystemFamily", DEFAULT_SYSTEM_FONT_FAMILY, CVAR_ARCHIVE );
cvar_t *con_fontSystemSmallSize = Trap::Cvar_Get( "con_fontSystemSmallSize", va( "%i", DEFAULT_SYSTEM_FONT_SMALL_SIZE ), CVAR_ARCHIVE );
cvar_t *con_fontSystemMediumSize = Trap::Cvar_Get( "con_fontSystemMediumSize", va( "%i", DEFAULT_SYSTEM_FONT_MEDIUM_SIZE ), CVAR_ARCHIVE );
cvar_t *con_fontSystemBigSize = Trap::Cvar_Get( "con_fontSystemBigSize", va( "%i", DEFAULT_SYSTEM_FONT_BIG_SIZE ), CVAR_ARCHIVE );
Local::fontSystemSmall = Trap::SCR_RegisterFont( con_fontSystemFamily->string, 0, con_fontSystemSmallSize->integer );
Local::fontSystemMedium = Trap::SCR_RegisterFont( con_fontSystemFamily->string, 0, con_fontSystemMediumSize->integer );
Local::fontSystemBig = Trap::SCR_RegisterFont( con_fontSystemFamily->string, 0, con_fontSystemBigSize->integer );
UICore::setScale( Local::scaleX, Local::scaleY );
UIMenu::BuildTemplates();
#if 0
UICore::rootPanel = new UICore::Panel( NULL, 0, 0, REL_WIDTH, REL_HEIGHT );
#else
UICore::rootPanel = new UICore::Panel( NULL, 0, 0, Local::vidWidth, Local::vidHeight );
#endif
UICore::rootPanel->setClickable( true );
PlayerModels::Init(); // create a list with the available player models
MapList::Precache();
Local::backgroundTrackStarted = false;
}
void UIWsw::UI_Shutdown( void )
{
Trap::S_StopBackgroundTrack();
Trap::Cmd_RemoveCommand( "menu_main" );
Trap::Cmd_RemoveCommand( "menu_setup" );
Trap::Cmd_RemoveCommand( "menu_joinserver" );
Trap::Cmd_RemoveCommand( "menu_login" );
Trap::Cmd_RemoveCommand( "menu_register" );
Trap::Cmd_RemoveCommand( "menu_playersetup" );
Trap::Cmd_RemoveCommand( "menu_startserver" );
Trap::Cmd_RemoveCommand( "menu_graphics" );
Trap::Cmd_RemoveCommand( "menu_sound" );
Trap::Cmd_RemoveCommand( "menu_video" );
Trap::Cmd_RemoveCommand( "menu_options" );
Trap::Cmd_RemoveCommand( "menu_keys" );
Trap::Cmd_RemoveCommand( "menu_vsays" );
Trap::Cmd_RemoveCommand( "menu_quit" );
Trap::Cmd_RemoveCommand( "menu_demos" );
Trap::Cmd_RemoveCommand( "menu_mods" );
Trap::Cmd_RemoveCommand( "menu_game" );
Trap::Cmd_RemoveCommand( "menu_tv" );
Trap::Cmd_RemoveCommand( "menu_tv_channel_add" );
Trap::Cmd_RemoveCommand( "menu_tv_channel_remove" );
Trap::Cmd_RemoveCommand( "menu_failed" );
Trap::Cmd_RemoveCommand( "menu_teamconfig" );
Trap::Cmd_RemoveCommand( "menu_force" );
Trap::Cmd_RemoveCommand( "menu_custom" );
}
void UIWsw::UI_Refresh( unsigned int time, int clientState, int serverState,
bool demoPlaying, const char *demoName, bool demoPaused, unsigned int demoTime,
bool backGround, bool showCursor )
{
Local::frameTime = (time - Local::time) * 0.001f;
Local::time = time;
Local::clientState = clientState;
Local::serverState = serverState;
Local::background = (backGround == true);
if ( !UIMenu::activeMenu ) // ui is inactive
return;
// draw background
if( Local::background ) {
#if 0
Trap::R_DrawStretchPic( 0, 0, Local::vidWidth, Local::vidHeight,
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic( UI_SHADER_VIDEOBACK ) );
Trap::R_DrawStretchPic ( 0, 0, Local::vidWidth, Local::vidHeight,
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic( UI_SHADER_FXBACK ) );
/*
Trap::R_DrawStretchPic ( 0, 0, Local::vidWidth, Local::vidHeight,
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic( UI_SHADER_BIGLOGO ) );
*/
#else
Trap::R_DrawStretchPic ( 0, 0, Local::vidWidth, Local::vidHeight,
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic( "gfx/newui/ui_background" ) );
#endif
if( !Local::backgroundTrackStarted ) {
Trap::S_StartBackgroundTrack( S_PLAYLIST_MENU, "3" ); // shuffle and loop
Local::backgroundTrackStarted = true;
}
} else {
Local::backgroundTrackStarted = false;
}
UICore::rootPanel->Draw( time );
// draw cursor
if ( !Local::bind_grab )
Trap::R_DrawStretchPic( Local::cursorX, Local::cursorY, 32, 32,
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic( UI_SHADER_CURSOR ) );
// TODO : fix enter sound
// delay playing the enter sound until after the
// menu has been drawn, to avoid delay while
// caching images
//if ( m_entersound )
//{
// Trap::S_StartLocalSound( menu_in_sound );
// m_entersound = false;
//}
}
void UIWsw::UI_DrawConnectScreen( const char *serverName, const char *rejectmessage, int downloadType, const char *downloadFilename,
float downloadPercent, int downloadSpeed, int connectCount, bool backGround )
{
// TODO : replace current connect screen by an interactive one with cancel button, etc...
bool localhost;
char str[MAX_QPATH];
//char levelshot[MAX_QPATH];
char mapname[MAX_QPATH], message[MAX_QPATH];
Trap::S_StopBackgroundTrack();
localhost = (bool)(!serverName || !serverName[0] || !Q_stricmp ( serverName, "localhost" ));
Trap::GetConfigString ( CS_MAPNAME, mapname, sizeof(mapname) );
if ( backGround ) {
/* if ( mapname[0] ) {
Q_snprintfz ( levelshot, sizeof(levelshot), "levelshots/%s.jpg", mapname );
if ( Trap::FS_FOpenFile( levelshot, NULL, FS_READ ) == -1 )
Q_snprintfz ( levelshot, sizeof(levelshot), "levelshots/%s.tga", mapname );
if ( Trap::FS_FOpenFile( levelshot, NULL, FS_READ ) == -1 )
Q_snprintfz ( levelshot, sizeof(levelshot), "gfx/ui/unknownmap" );
Trap::R_DrawStretchPic ( 0, 0, Local::vidWidth, Local::vidHeight,
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic ( levelshot ) );
} else*/ {
Trap::R_DrawStretchPic( 0, 0, Local::vidWidth, Local::vidHeight,
0, 0, 1, 1, colorBlack, Local::getWhiteShader() );
}
}
// draw server name if not local host
if ( !localhost ) {
Q_snprintfz ( str, sizeof(str), "Connecting to %s", serverName );
Trap::SCR_DrawString( Local::vidWidth/2, 64, ALIGN_CENTER_TOP, str, Local::fontSystemBig, colorWhite );
}
if( rejectmessage ) {
Q_snprintfz ( str, sizeof(str), "Refused: %s", rejectmessage );
Trap::SCR_DrawString( Local::vidWidth/2, 86, ALIGN_CENTER_TOP, str, Local::fontSystemMedium, colorWhite );
}
if( downloadFilename ) {
Q_snprintfz ( str, sizeof(str), "Downloading %s", downloadFilename );
Trap::SCR_DrawString( Local::vidWidth/2, 86, ALIGN_CENTER_TOP, str, Local::fontSystemMedium, colorWhite );
}
if( mapname[0] ) {
// draw Warsow logo at bottom
Trap::R_DrawStretchPic( 0, (int)(Local::vidHeight - 90*Local::scaleY), Local::vidWidth, (int)(80*Local::scaleY),
0, 0, 1, 1, colorWhite, Trap::R_RegisterPic( "gfx/ui/loadscreen_logo" ) );
Trap::GetConfigString( CS_MESSAGE, message, sizeof(message) );
if( message[0] ) // level name ("message")
Trap::SCR_DrawString( Local::vidWidth/2, 180, ALIGN_CENTER_TOP, message, Local::fontSystemBig, colorWhite );
} else {
if( !localhost ) {
Q_snprintfz ( message, sizeof(message), "Awaiting connection ... %i", connectCount );
Trap::SCR_DrawString( Local::vidWidth/2, 180, ALIGN_CENTER_TOP, message, Local::fontSystemBig, colorWhite );
} else {
Q_strncpyz ( message, "Loading ...", sizeof(message) );
Trap::SCR_DrawString( Local::vidWidth/2, 180, ALIGN_CENTER_TOP, message, Local::fontSystemBig, colorWhite );
}
}
}
void UIWsw::UI_Keydown( int key )
{
if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MWHEELUP || key == K_MWHEELDOWN )
UICore::EventMouseDown( float(Local::cursorX)/Local::scaleX, float(Local::cursorY)/Local::scaleY, key );
else
UICore::EventKeyDown( key, 0 );
}
void UIWsw::UI_Keyup( int key )
{
if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MWHEELUP || key == K_MWHEELDOWN )
UICore::EventMouseUp( float(Local::cursorX)/Local::scaleX, float(Local::cursorY)/Local::scaleY, key );
else
UICore::EventKeyUp( key, 0 );
}
void UIWsw::UI_CharEvent( wchar_t key )
{
UICore::EventKeyDown( 0, key );
}
void UIWsw::UI_MouseMove( int dx, int dy )
{
if( Local::bind_grab )
return; //don't move the mouse if we're grabbing binds
Local::cursorX += dx;
Local::cursorY += dy;
clamp( Local::cursorX, 0, Local::vidWidth );
clamp( Local::cursorY, 0, Local::vidHeight );
if( dx || dy )
UICore::EventMouseMove( float(Local::cursorX) / Local::scaleX, float(Local::cursorY) / Local::scaleY,
float(dx) / Local::scaleX, float(dy) / Local::scaleY );
}