1 /* 2 =========================================================================== 3 4 Return to Castle Wolfenstein multiplayer GPL Source Code 5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (RTCW MP Source Code). 8 9 RTCW MP Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 RTCW MP Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #ifndef __UI_SHARED_H 30 #define __UI_SHARED_H 31 32 33 #include "../qcommon/q_shared.h" 34 #include "../renderer/tr_types.h" 35 #include "../client/keycodes.h" 36 37 // TTimo case sensitivity 38 #include "../../MAIN/ui_mp/menudef.h" 39 40 #define MAX_MENUNAME 32 41 #define MAX_ITEMTEXT 64 42 #define MAX_ITEMACTION 64 43 #define MAX_MENUDEFFILE 4096 44 #define MAX_MENUFILE 32768 45 #define MAX_MENUS 64 46 //#define MAX_MENUITEMS 256 47 #define MAX_MENUITEMS 128 // JPW NERVE q3ta was 96 48 #define MAX_COLOR_RANGES 10 49 #define MAX_MODAL_MENUS 16 50 51 #define WINDOW_MOUSEOVER 0x00000001 // mouse is over it, non exclusive 52 #define WINDOW_HASFOCUS 0x00000002 // has cursor focus, exclusive 53 #define WINDOW_VISIBLE 0x00000004 // is visible 54 #define WINDOW_GREY 0x00000008 // is visible but grey ( non-active ) 55 #define WINDOW_DECORATION 0x00000010 // for decoration only, no mouse, keyboard, etc.. 56 #define WINDOW_FADINGOUT 0x00000020 // fading out, non-active 57 #define WINDOW_FADINGIN 0x00000040 // fading in 58 #define WINDOW_MOUSEOVERTEXT 0x00000080 // mouse is over it, non exclusive 59 #define WINDOW_INTRANSITION 0x00000100 // window is in transition 60 #define WINDOW_FORECOLORSET 0x00000200 // forecolor was explicitly set ( used to color alpha images or not ) 61 #define WINDOW_HORIZONTAL 0x00000400 // for list boxes and sliders, vertical is default this is set of horizontal 62 #define WINDOW_LB_LEFTARROW 0x00000800 // mouse is over left/up arrow 63 #define WINDOW_LB_RIGHTARROW 0x00001000 // mouse is over right/down arrow 64 #define WINDOW_LB_THUMB 0x00002000 // mouse is over thumb 65 #define WINDOW_LB_PGUP 0x00004000 // mouse is over page up 66 #define WINDOW_LB_PGDN 0x00008000 // mouse is over page down 67 #define WINDOW_ORBITING 0x00010000 // item is in orbit 68 #define WINDOW_OOB_CLICK 0x00020000 // close on out of bounds click 69 #define WINDOW_WRAPPED 0x00040000 // manually wrap text 70 #define WINDOW_AUTOWRAPPED 0x00080000 // auto wrap text 71 #define WINDOW_FORCED 0x00100000 // forced open 72 #define WINDOW_POPUP 0x00200000 // popup 73 #define WINDOW_BACKCOLORSET 0x00400000 // backcolor was explicitly set 74 #define WINDOW_TIMEDVISIBLE 0x00800000 // visibility timing ( NOT implemented ) 75 #define WINDOW_IGNORE_HUDALPHA 0x01000000 // window will apply cg_hudAlpha value to colors unless this flag is set 76 #define WINDOW_MODAL 0x02000000 // window is modal, the window to go back to is stored in a stack 77 78 // CGAME cursor type bits 79 #define CURSOR_NONE 0x00000001 80 #define CURSOR_ARROW 0x00000002 81 #define CURSOR_SIZER 0x00000004 82 83 #ifdef CGAME 84 #define STRING_POOL_SIZE 128 * 1024 85 #else 86 #define STRING_POOL_SIZE 384 * 1024 87 #endif 88 89 #define MAX_STRING_HANDLES 4096 90 #define MAX_SCRIPT_ARGS 12 91 #define MAX_EDITFIELD 256 92 93 #define ART_FX_BASE "menu/art/fx_base" 94 #define ART_FX_BLUE "menu/art/fx_blue" 95 #define ART_FX_CYAN "menu/art/fx_cyan" 96 #define ART_FX_GREEN "menu/art/fx_grn" 97 #define ART_FX_RED "menu/art/fx_red" 98 #define ART_FX_TEAL "menu/art/fx_teal" 99 #define ART_FX_WHITE "menu/art/fx_white" 100 #define ART_FX_YELLOW "menu/art/fx_yel" 101 102 #define ASSET_GRADIENTBAR "ui_mp/assets/gradientbar2.tga" 103 #define ASSET_SCROLLBAR "ui_mp/assets/scrollbar.tga" 104 #define ASSET_SCROLLBAR_ARROWDOWN "ui_mp/assets/scrollbar_arrow_dwn_a.tga" 105 #define ASSET_SCROLLBAR_ARROWUP "ui_mp/assets/scrollbar_arrow_up_a.tga" 106 #define ASSET_SCROLLBAR_ARROWLEFT "ui_mp/assets/scrollbar_arrow_left.tga" 107 #define ASSET_SCROLLBAR_ARROWRIGHT "ui_mp/assets/scrollbar_arrow_right.tga" 108 #define ASSET_SCROLL_THUMB "ui_mp/assets/scrollbar_thumb.tga" 109 #define ASSET_SLIDER_BAR "ui_mp/assets/slider2.tga" 110 #define ASSET_SLIDER_THUMB "ui_mp/assets/sliderbutt_1.tga" 111 112 #define SCROLLBAR_SIZE 16.0 113 #define SLIDER_WIDTH 96.0 114 #define SLIDER_HEIGHT 16.0 115 #define SLIDER_THUMB_WIDTH 12.0 116 #define SLIDER_THUMB_HEIGHT 20.0 117 #define NUM_CROSSHAIRS 10 118 119 typedef struct { 120 const char *command; 121 const char *args[MAX_SCRIPT_ARGS]; 122 } scriptDef_t; 123 124 125 typedef struct { 126 float x; // horiz position 127 float y; // vert position 128 float w; // width 129 float h; // height; 130 } rectDef_t; 131 132 typedef rectDef_t Rectangle; 133 134 // FIXME: do something to separate text vs window stuff 135 typedef struct { 136 Rectangle rect; // client coord rectangle 137 Rectangle rectClient; // screen coord rectangle 138 const char *name; // 139 const char *model; // 140 const char *group; // if it belongs to a group 141 const char *cinematicName; // cinematic name 142 int cinematic; // cinematic handle 143 int style; // 144 int border; // 145 int ownerDraw; // ownerDraw style 146 int ownerDrawFlags; // show flags for ownerdraw items 147 float borderSize; // 148 int flags; // visible, focus, mouseover, cursor 149 Rectangle rectEffects; // for various effects 150 Rectangle rectEffects2; // for various effects 151 int offsetTime; // time based value for various effects 152 int nextTime; // time next effect should cycle 153 vec4_t foreColor; // text color 154 vec4_t backColor; // border color 155 vec4_t borderColor; // border color 156 vec4_t outlineColor; // border color 157 qhandle_t background; // background asset 158 } windowDef_t; 159 160 typedef windowDef_t Window; 161 162 163 typedef struct { 164 vec4_t color; 165 int type; 166 float low; 167 float high; 168 } colorRangeDef_t; 169 170 // FIXME: combine flags into bitfields to save space 171 // FIXME: consolidate all of the common stuff in one structure for menus and items 172 // THINKABOUTME: is there any compelling reason not to have items contain items 173 // and do away with a menu per say.. major issue is not being able to dynamically allocate 174 // and destroy stuff.. Another point to consider is adding an alloc free call for vm's and have 175 // the engine just allocate the pool for it based on a cvar 176 // many of the vars are re-used for different item types, as such they are not always named appropriately 177 // the benefits of c++ in DOOM will greatly help crap like this 178 // FIXME: need to put a type ptr that points to specific type info per type 179 // 180 #define MAX_LB_COLUMNS 16 181 182 typedef struct columnInfo_s { 183 int pos; 184 int width; 185 int maxChars; 186 } columnInfo_t; 187 188 typedef struct listBoxDef_s { 189 int startPos; 190 int endPos; 191 int drawPadding; 192 int cursorPos; 193 float elementWidth; 194 float elementHeight; 195 int elementStyle; 196 int numColumns; 197 columnInfo_t columnInfo[MAX_LB_COLUMNS]; 198 const char *doubleClick; 199 qboolean notselectable; 200 } listBoxDef_t; 201 202 typedef struct editFieldDef_s { 203 float minVal; // edit field limits 204 float maxVal; // 205 float defVal; // 206 float range; // 207 int maxChars; // for edit fields 208 int maxPaintChars; // for edit fields 209 int paintOffset; // 210 } editFieldDef_t; 211 212 #define MAX_MULTI_CVARS 32 213 214 typedef struct multiDef_s { 215 const char *cvarList[MAX_MULTI_CVARS]; 216 const char *cvarStr[MAX_MULTI_CVARS]; 217 float cvarValue[MAX_MULTI_CVARS]; 218 int count; 219 qboolean strDef; 220 } multiDef_t; 221 222 typedef struct modelDef_s { 223 int angle; 224 vec3_t origin; 225 float fov_x; 226 float fov_y; 227 int rotationSpeed; 228 229 int animated; 230 int startframe; 231 int numframes; 232 int loopframes; 233 int fps; 234 235 int frame; 236 int oldframe; 237 float backlerp; 238 int frameTime; 239 } modelDef_t; 240 241 #define CVAR_ENABLE 0x00000001 242 #define CVAR_DISABLE 0x00000002 243 #define CVAR_SHOW 0x00000004 244 #define CVAR_HIDE 0x00000008 245 #define CVAR_NOTOGGLE 0x00000010 246 247 #define UI_MAX_TEXT_LINES 64 248 249 typedef struct itemDef_s { 250 Window window; // common positional, border, style, layout info 251 Rectangle textRect; // rectangle the text ( if any ) consumes 252 int type; // text, button, radiobutton, checkbox, textfield, listbox, combo 253 int alignment; // left center right 254 int textalignment; // ( optional ) alignment for text within rect based on text width 255 float textalignx; // ( optional ) text alignment x coord 256 float textaligny; // ( optional ) text alignment x coord 257 float textscale; // scale percentage from 72pts 258 int font; // (SA) 259 int textStyle; // ( optional ) style, normal and shadowed are it for now 260 const char *text; // display text 261 void *parent; // menu owner 262 qhandle_t asset; // handle to asset 263 const char *mouseEnterText; // mouse enter script 264 const char *mouseExitText; // mouse exit script 265 const char *mouseEnter; // mouse enter script 266 const char *mouseExit; // mouse exit script 267 const char *action; // select script 268 const char *onAccept; // NERVE - SMF - run when the users presses the enter key 269 const char *onFocus; // select script 270 const char *leaveFocus; // select script 271 const char *cvar; // associated cvar 272 const char *cvarTest; // associated cvar for enable actions 273 const char *enableCvar; // enable, disable, show, or hide based on value, this can contain a list 274 int cvarFlags; // what type of action to take on cvarenables 275 sfxHandle_t focusSound; 276 int numColors; // number of color ranges 277 colorRangeDef_t colorRanges[MAX_COLOR_RANGES]; 278 int colorRangeType; // either 279 float special; // used for feeder id's etc.. diff per type 280 int cursorPos; // cursor position in characters 281 void *typeData; // type specific data ptr's 282 } itemDef_t; 283 284 typedef struct { 285 Window window; 286 const char *font; // font 287 qboolean fullScreen; // covers entire screen 288 int itemCount; // number of items; 289 int fontIndex; // 290 int cursorItem; // which item as the cursor 291 int fadeCycle; // 292 float fadeClamp; // 293 float fadeAmount; // 294 const char *onOpen; // run when the menu is first opened 295 const char *onClose; // run when the menu is closed 296 const char *onESC; // run when the menu is closed 297 const char *onKey[255]; // NERVE - SMF - execs commands when a key is pressed 298 const char *soundName; // background loop sound for menu 299 300 vec4_t focusColor; // focus color for items 301 vec4_t disableColor; // focus color for items 302 itemDef_t *items[MAX_MENUITEMS]; // items this menu contains 303 } menuDef_t; 304 305 typedef struct { 306 const char *fontStr; 307 const char *cursorStr; 308 const char *gradientStr; 309 fontInfo_t textFont; 310 fontInfo_t smallFont; 311 fontInfo_t bigFont; 312 qhandle_t cursor; 313 qhandle_t gradientBar; 314 qhandle_t scrollBarArrowUp; 315 qhandle_t scrollBarArrowDown; 316 qhandle_t scrollBarArrowLeft; 317 qhandle_t scrollBarArrowRight; 318 qhandle_t scrollBar; 319 qhandle_t scrollBarThumb; 320 qhandle_t buttonMiddle; 321 qhandle_t buttonInside; 322 qhandle_t solidBox; 323 qhandle_t sliderBar; 324 qhandle_t sliderThumb; 325 sfxHandle_t menuEnterSound; 326 sfxHandle_t menuExitSound; 327 sfxHandle_t menuBuzzSound; 328 sfxHandle_t itemFocusSound; 329 float fadeClamp; 330 int fadeCycle; 331 float fadeAmount; 332 float shadowX; 333 float shadowY; 334 vec4_t shadowColor; 335 float shadowFadeClamp; 336 qboolean fontRegistered; 337 338 // player settings 339 qhandle_t fxBasePic; 340 qhandle_t fxPic[7]; 341 qhandle_t crosshairShader[NUM_CROSSHAIRS]; 342 343 } cachedAssets_t; 344 345 typedef struct { 346 const char *name; 347 void ( *handler )( itemDef_t *item, char** args ); 348 } commandDef_t; 349 350 typedef struct { 351 qhandle_t ( *registerShaderNoMip )( const char *p ); 352 void ( *setColor )( const vec4_t v ); 353 void ( *drawHandlePic )( float x, float y, float w, float h, qhandle_t asset ); 354 void ( *drawStretchPic )( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); 355 void ( *drawText )( float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style ); 356 int ( *textWidth )( const char *text, float scale, int limit ); 357 int ( *textHeight )( const char *text, float scale, int limit ); 358 void ( *textFont )( int font ); // NERVE - SMF 359 qhandle_t ( *registerModel )( const char *p ); 360 void ( *modelBounds )( qhandle_t model, vec3_t min, vec3_t max ); 361 void ( *fillRect )( float x, float y, float w, float h, const vec4_t color ); 362 void ( *drawRect )( float x, float y, float w, float h, float size, const vec4_t color ); 363 void ( *drawSides )( float x, float y, float w, float h, float size ); 364 void ( *drawTopBottom )( float x, float y, float w, float h, float size ); 365 void ( *clearScene )( void ); 366 void ( *addRefEntityToScene )( const refEntity_t *re ); 367 void ( *renderScene )( const refdef_t *fd ); 368 void ( *registerFont )( const char *pFontname, int pointSize, fontInfo_t *font ); 369 void ( *ownerDrawItem )( float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, float special, float scale, vec4_t color, qhandle_t shader, int textStyle ); 370 float ( *getValue )( int ownerDraw, int type ); 371 qboolean ( *ownerDrawVisible )( int flags ); 372 void ( *runScript )( char **p ); 373 void ( *getTeamColor )( vec4_t *color ); 374 void ( *getCVarString )( const char *cvar, char *buffer, int bufsize ); 375 float ( *getCVarValue )( const char *cvar ); 376 void ( *setCVar )( const char *cvar, const char *value ); 377 void ( *drawTextWithCursor )( float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style ); 378 void ( *setOverstrikeMode )( qboolean b ); 379 qboolean ( *getOverstrikeMode )( void ); 380 void ( *startLocalSound )( sfxHandle_t sfx, int channelNum ); 381 qboolean ( *ownerDrawHandleKey )( int ownerDraw, int flags, float *special, int key ); 382 int ( *feederCount )( float feederID ); 383 const char *( *feederItemText )( float feederID, int index, int column, qhandle_t * handle ); 384 const char *( *fileText )( char *flieName ); 385 qhandle_t ( *feederItemImage )( float feederID, int index ); 386 void ( *feederSelection )( float feederID, int index ); 387 void ( *feederAddItem )( float feederID, const char *name, int index ); // NERVE - SMF 388 char* ( *translateString )( const char *string ); // NERVE - SMF 389 void ( *checkAutoUpdate )( void ); // DHM - Nerve 390 void ( *getAutoUpdate )( void ); // DHM - Nerve 391 392 void ( *keynumToStringBuf )( int keynum, char *buf, int buflen ); 393 void ( *getBindingBuf )( int keynum, char *buf, int buflen ); 394 void ( *setBinding )( int keynum, const char *binding ); 395 void ( *executeText )( int exec_when, const char *text ); 396 void (*Error)(int level, const char *error, ...) __attribute__ ((noreturn, format (printf, 2, 3))); 397 void (*Print)(const char *msg, ...) __attribute__ ((format (printf, 1, 2))); 398 void (*DPrint)(const char *msg, ...) __attribute__ ((format (printf, 1, 2))); 399 void ( *Pause )( qboolean b ); 400 int ( *ownerDrawWidth )( int ownerDraw, float scale ); 401 // sfxHandle_t (*registerSound)(const char *name, qboolean compressed); 402 sfxHandle_t ( *registerSound )( const char *name ); 403 void ( *startBackgroundTrack )( const char *intro, const char *loop ); 404 void ( *stopBackgroundTrack )( void ); 405 int ( *playCinematic )( const char *name, float x, float y, float w, float h ); 406 void ( *stopCinematic )( int handle ); 407 void ( *drawCinematic )( int handle, float x, float y, float w, float h ); 408 void ( *runCinematicFrame )( int handle ); 409 410 float yscale; 411 float xscale; 412 float yscaleStretch; 413 float xscaleStretch; 414 float yBias; 415 float xBias; 416 float bias; 417 int realTime; 418 int frameTime; 419 int cursorx; 420 int cursory; 421 qboolean debug; 422 423 cachedAssets_t Assets; 424 425 glconfig_t glconfig; 426 qhandle_t whiteShader; 427 qhandle_t gradientImage; 428 qhandle_t cursor; 429 float FPS; 430 431 } displayContextDef_t; 432 433 const char *String_Alloc( const char *p ); 434 void String_Init( void ); 435 void String_Report( void ); 436 void Init_Display( displayContextDef_t *dc ); 437 void Display_ExpandMacros( char * buff ); 438 void Menu_Init( menuDef_t *menu ); 439 void Item_Init( itemDef_t *item ); 440 void Menu_PostParse( menuDef_t *menu ); 441 menuDef_t *Menu_GetFocused( void ); 442 void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ); 443 void Menu_HandleMouseMove( menuDef_t *menu, float x, float y ); 444 void Menu_ScrollFeeder( menuDef_t *menu, int feeder, qboolean down ); 445 qboolean Float_Parse( char **p, float *f ); 446 qboolean Color_Parse( char **p, vec4_t *c ); 447 qboolean Int_Parse( char **p, int *i ); 448 qboolean Rect_Parse( char **p, rectDef_t *r ); 449 qboolean String_Parse( char **p, const char **out ); 450 qboolean Script_Parse( char **p, const char **out ); 451 qboolean PC_Float_Parse( int handle, float *f ); 452 qboolean PC_Color_Parse( int handle, vec4_t *c ); 453 qboolean PC_Int_Parse( int handle, int *i ); 454 qboolean PC_Rect_Parse( int handle, rectDef_t *r ); 455 qboolean PC_String_Parse( int handle, const char **out ); 456 qboolean PC_Script_Parse( int handle, const char **out ); 457 qboolean PC_Char_Parse( int handle, char *out ); // NERVE - SMF 458 int Menu_Count( void ); 459 void Menu_New( int handle ); 460 void Menu_PaintAll( void ); 461 menuDef_t *Menus_ActivateByName( const char *p, qboolean modalStack ); 462 void Menu_Reset( void ); 463 qboolean Menus_AnyFullScreenVisible( void ); 464 void Menus_Activate( menuDef_t *menu ); 465 466 int UI_SelectForKey(int key); 467 displayContextDef_t *Display_GetContext( void ); 468 void *Display_CaptureItem( int x, int y ); 469 qboolean Display_MouseMove( void *p, int x, int y ); 470 int Display_CursorType( int x, int y ); 471 qboolean Display_KeyBindPending( void ); 472 void Menus_OpenByName( const char *p ); 473 menuDef_t *Menus_FindByName( const char *p ); 474 void Menus_ShowByName( const char *p ); 475 void Menus_CloseByName( const char *p ); 476 void Display_HandleKey( int key, qboolean down, int x, int y ); 477 void LerpColor( vec4_t a, vec4_t b, vec4_t c, float t ); 478 void Menus_CloseAll( void ); 479 void Menu_Paint( menuDef_t *menu, qboolean forcePaint ); 480 void Menu_SetFeederSelection( menuDef_t *menu, int feeder, int index, const char *name ); 481 void Display_CacheAll( void ); 482 483 // TTimo 484 void Menu_ShowItemByName( menuDef_t *menu, const char *p, qboolean bShow ); 485 486 void *UI_Alloc( int size ); 487 void UI_InitMemory( void ); 488 qboolean UI_OutOfMemory( void ); 489 490 void Controls_GetConfig( void ); 491 void Controls_SetConfig( qboolean restart ); 492 void Controls_SetDefaults( void ); 493 494 int trap_PC_AddGlobalDefine( char *define ); 495 int trap_PC_LoadSource( const char *filename ); 496 int trap_PC_FreeSource( int handle ); 497 int trap_PC_ReadToken( int handle, pc_token_t *pc_token ); 498 int trap_PC_SourceFileAndLine( int handle, char *filename, int *line ); 499 500 void UI_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos); 501 502 #endif 503