📄 m_menu.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: m_menu.c,v 1.34 2001/04/29 14:25:26 hurdler Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// 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.////// $Log: m_menu.c,v $// Revision 1.34 2001/04/29 14:25:26 hurdler// small fix//// Revision 1.33 2001/04/01 17:35:06 bpereira// no message//// Revision 1.32 2001/03/03 06:17:33 bpereira// no message//// Revision 1.31 2001/02/24 13:35:20 bpereira// no message//// Revision 1.30 2001/02/10 12:27:14 bpereira// no message//// Revision 1.29 2001/01/25 22:15:42 bpereira// added heretic support//// Revision 1.28 2000/11/26 20:36:14 hurdler// Adding autorun2//// Revision 1.27 2000/10/21 08:43:29 bpereira// no message//// Revision 1.26 2000/10/17 10:09:27 hurdler// Update master server code for easy connect from menu//// Revision 1.25 2000/10/16 20:02:29 bpereira// no message//// Revision 1.24 2000/10/08 13:30:01 bpereira// no message//// Revision 1.23 2000/10/02 18:25:45 bpereira// no message//// Revision 1.22 2000/10/01 15:20:23 hurdler// Add private server//// Revision 1.21 2000/10/01 10:18:17 bpereira// no message//// Revision 1.20 2000/10/01 09:09:36 hurdler// Put the md2 code in #ifdef TANDL//// Revision 1.19 2000/09/15 19:49:22 bpereira// no message//// Revision 1.18 2000/09/08 22:28:30 hurdler// merge masterserver_ip/port in one cvar, add -private//// Revision 1.17 2000/09/02 15:38:24 hurdler// Add master server to menus (temporaray)//// Revision 1.16 2000/08/31 14:30:55 bpereira// no message//// Revision 1.15 2000/04/24 15:10:56 hurdler// Support colormap for text//// Revision 1.14 2000/04/23 00:29:28 hurdler// fix a small bug in skin color//// Revision 1.13 2000/04/23 00:25:20 hurdler// fix a small bug in skin color//// Revision 1.12 2000/04/22 21:12:15 hurdler// I like it better like that//// Revision 1.11 2000/04/22 20:27:35 metzgermeister// support for immediate fullscreen switching//// Revision 1.10 2000/04/16 18:38:07 bpereira// no message//// Revision 1.9 2000/04/13 16:26:41 hurdler// looks better like that//// Revision 1.8 2000/04/12 19:31:37 metzgermeister// added use_mouse to menu//// Revision 1.7 2000/04/08 17:29:24 stroggonmeth// no message//// Revision 1.6 2000/04/07 23:11:17 metzgermeister// added mouse move//// Revision 1.5 2000/04/04 10:44:00 hurdler// Remove a warning message in Dos/Windows//// Revision 1.4 2000/04/04 00:32:46 stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.3 2000/03/23 22:54:00 metzgermeister// added support for HOME/.legacy under Linux//// Revision 1.2 2000/02/27 00:42:10 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:33 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// DOOM selection menu, options, episode etc.// Sliders and icons. Kinda widget stuff.//// NOTE:// All V_DrawPatchDirect () has been replaced by V_DrawScaledPatch ()// so that the menu is scaled to the screen size. The scaling is always// an integer multiple of the original size, so that the graphics look// good.////-----------------------------------------------------------------------------#ifndef __WIN32__#include <unistd.h>#endif#include <fcntl.h>#include "am_map.h"#include "doomdef.h"#include "dstrings.h"#include "d_main.h"#include "console.h"#include "r_local.h"#include "hu_stuff.h"#include "g_game.h"#include "g_input.h"#include "m_argv.h"// Data.#include "sounds.h"#include "s_sound.h"#include "i_system.h"#include "m_menu.h"#include "v_video.h"#include "i_video.h"#include "keys.h"#include "z_zone.h"#include "w_wad.h"#include "p_local.h"#include "p_fab.h"#ifdef HWRENDER#include "hardware/hw_main.h"#endif#include "d_net.h"#include "mserv.h"// -1 = no quicksave slot picked!int quickSaveSlot;boolean menuactive;#define SKULLXOFF -32#define LINEHEIGHT 16#define FONTBHEIGHT 20#define SMALLLINEHEIGHT 8#define SLIDER_RANGE 10#define SLIDER_WIDTH (8*SLIDER_RANGE+6)#define MAXSTRINGLENGTH 32// we are going to be entering a savegame stringint saveStringEnter;int saveSlot; // which slot to save inint saveCharIndex; // which char we're editing// old save description before editchar saveOldString[SAVESTRINGSIZE];char savegamestrings[10][SAVESTRINGSIZE];// flags for items in the menu// menu handle (what we do when key is pressed#define IT_TYPE 14 // (2+4+8)#define IT_CALL 0 // call the function#define IT_ARROWS 2 // call function with 0 for left arrow and 1 for right arrow in param#define IT_KEYHANDLER 4 // call with the key in param#define IT_SUBMENU 6 // go to sub menu#define IT_CVAR 8 // hangdle as a cvar#define IT_SPACE 10 // no handling#define IT_MSGHANDLER 12 // same as key but with event and sometime can handle y/n key (special for message#define IT_DISPLAY (48+64) // 16+32+64#define IT_NOTHING 0 // space#define IT_PATCH 16 // a patch or a string with big font#define IT_STRING 32 // little string (spaced with 10#define IT_WHITESTRING 48 // little string in white#define IT_DYBIGSPACE 64 // same as noting#define IT_DYLITLSPACE (16+64) // little space#define IT_STRING2 (32+64) // a simple string#define IT_GRAYPATCH (16+32+64) // grayed patch or big font string//consvar specific#define IT_CVARTYPE (128+256+512)#define IT_CV_NORMAL 0#define IT_CV_SLIDER 128#define IT_CV_STRING 256#define IT_CV_NOPRINT (128+256)#define IT_CV_NOMOD 512// in short for some common use#define IT_BIGSPACE (IT_SPACE +IT_DYBIGSPACE)#define IT_LITLSPACE (IT_SPACE +IT_DYLITLSPACE)#define IT_CONTROL (IT_STRING2+IT_CALL)#define IT_CVARMAX (IT_CVAR +IT_CV_NOMOD)#define IT_DISABLED (IT_SPACE +IT_GRAYPATCH)typedef union{ struct menu_s *submenu; // IT_SUBMENU consvar_t *cvar; // IT_CVAR void (*routine)(int choice); // IT_CALL, IT_KEYHANDLER, IT_ARROWS} itemaction_t;//// MENU TYPEDEFS//typedef struct menuitem_s{ // show IT_xxx short status; char *patch; char *text; // used when FONTBxx lump is found // FIXME: should be itemaction_t !!! void *itemaction; // hotkey in menu // or y of the item byte alphaKey;} menuitem_t;typedef struct menu_s{ char *menutitlepic; char *menutitle; // title as string for display with fontb if present short numitems; // # of menu items struct menu_s* prevMenu; // previous menu menuitem_t* menuitems; // menu items void (*drawroutine)(void); // draw routine short x; short y; // x,y of menu short lastOn; // last item user was on in menu boolean (*quitroutine)(void); // called before quit a menu return true if we can} menu_t;// current menudefmenu_t* currentMenu;short itemOn; // menu item skull is onshort skullAnimCounter; // skull animation countershort whichSkull; // which skull to drawint SkullBaseLump;// graphic name of skullschar skullName[2][9] = {"M_SKULL1","M_SKULL2"};//// PROTOTYPES//void M_DrawSaveLoadBorder(int x,int y);void M_SetupNextMenu(menu_t *menudef);void M_DrawTextBox (int x, int y, int width, int lines); //added:06-02-98:void M_DrawThermo(int x,int y,int thermWidth,int thermDot);void M_DrawEmptyCell(menu_t *menu,int item);void M_DrawSelCell(menu_t *menu,int item);void M_DrawSlider (int x, int y, int range);void M_CentreText(int y, char* string); //added:30-01-98:writetext centeredvoid M_StartControlPanel(void);void M_StopMessage(int choice);void M_ClearMenus (boolean callexitmenufunc);int M_StringHeight(char* string);void M_GameOption(int choice);void M_NetOption(int choice);//28/08/99: added by Hurdlervoid M_OpenGLOption(int choice);menu_t MainDef,SinglePlayerDef,MultiPlayerDef,SetupMultiPlayerDef, EpiDef,NewDef,OptionsDef,VidModeDef,ControlDef,SoundDef, ReadDef2,ReadDef1,SaveDef,LoadDef,ControlDef2,GameOptionDef, NetOptionDef,VideoOptionsDef,MouseOptionsDef,ServerOptionsDef;const char *ALLREADYPLAYING="You are already playing\n\nLeave this game first\n";//===========================================================================//Generic Stuffs (more easy to create menus :))//===========================================================================void M_DrawGenericMenu(void){ int x,y,i,cursory=0; // DRAW MENU x = currentMenu->x; y = currentMenu->y; // draw title (or big pic) if( FontBBaseLump && currentMenu->menutitle ) { int xtitle = (BASEVIDWIDTH-V_TextBWidth(currentMenu->menutitle))/2; int ytitle = (y-V_TextBHeight(currentMenu->menutitle))/2; if(xtitle<0) xtitle=0; if(ytitle<0) ytitle=0; V_DrawTextB(currentMenu->menutitle, xtitle, ytitle); } else if( currentMenu->menutitlepic ) { patch_t* p = W_CachePatchName(currentMenu->menutitlepic,PU_CACHE);#if 1 //SoM: 4/7/2000: Old code was causing problems with large graphics.// int xtitle = (vid.width / 2) - (p->width / 2);// int ytitle = (y-p->height)/2; int xtitle = 94; int ytitle = 2;#else int xtitle = (BASEVIDWIDTH-p->width)/2; int ytitle = (y-p->height)/2;#endif if(xtitle<0) xtitle=0; if(ytitle<0) ytitle=0; V_DrawScaledPatch (xtitle,ytitle,0,p); } for (i=0;i<currentMenu->numitems;i++) { if (i==itemOn) cursory=y; switch (currentMenu->menuitems[i].status & IT_DISPLAY) { case IT_PATCH : if( FontBBaseLump && currentMenu->menuitems[i].text ) { V_DrawTextB(currentMenu->menuitems[i].text, x, y); y += FONTBHEIGHT-LINEHEIGHT; } else if( currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0] ) V_DrawScaledPatch (x,y,0, W_CachePatchName(currentMenu->menuitems[i].patch ,PU_CACHE)); case IT_NOTHING: case IT_DYBIGSPACE: y += LINEHEIGHT; break; case IT_STRING : case IT_WHITESTRING : if( currentMenu->menuitems[i].alphaKey ) y = currentMenu->y+currentMenu->menuitems[i].alphaKey; if (i==itemOn) cursory=y; if( (currentMenu->menuitems[i].status & IT_DISPLAY)==IT_STRING ) V_DrawString (x,y,currentMenu->menuitems[i].text); else V_DrawStringWhite (x,y,currentMenu->menuitems[i].text); // Cvar specific handling switch (currentMenu->menuitems[i].status & IT_TYPE) case IT_CVAR: { consvar_t *cv=(consvar_t *)currentMenu->menuitems[i].itemaction; switch (currentMenu->menuitems[i].status & IT_CVARTYPE) { case IT_CV_SLIDER : M_DrawSlider (BASEVIDWIDTH-x-SLIDER_WIDTH, y, ( (cv->value - cv->PossibleValue[0].value) * 100 / (cv->PossibleValue[1].value - cv->PossibleValue[0].value))); case IT_CV_NOPRINT: // color use this break; case IT_CV_STRING: M_DrawTextBox(x,y+4,MAXSTRINGLENGTH,1); V_DrawString (x+8,y+12,cv->string); if( skullAnimCounter<4 && i==itemOn ) V_DrawCharacter( x+8+V_StringWidth(cv->string), y+12, '_' | 0x80); y+=16; break; default: V_DrawStringWhite(BASEVIDWIDTH-x-V_StringWidth (cv->string), y, cv->string); break; } break; } y+=10; break; case IT_STRING2: V_DrawString (x,y,currentMenu->menuitems[i].text); case IT_DYLITLSPACE: y+=SMALLLINEHEIGHT; break; case IT_GRAYPATCH: if( FontBBaseLump && currentMenu->menuitems[i].text ) { V_DrawTextBGray(currentMenu->menuitems[i].text, x, y); y += FONTBHEIGHT-LINEHEIGHT; } else if( currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0] ) V_DrawMappedPatch (x,y,0, W_CachePatchName(currentMenu->menuitems[i].patch ,PU_CACHE), graymap); y += LINEHEIGHT; break; } } // DRAW THE SKULL CURSOR if (((currentMenu->menuitems[itemOn].status & IT_DISPLAY)==IT_PATCH) ||((currentMenu->menuitems[itemOn].status & IT_DISPLAY)==IT_NOTHING) ) { V_DrawScaledPatch(currentMenu->x + SKULLXOFF, cursory-5, 0, W_CachePatchName(skullName[whichSkull],PU_CACHE) ); } else if (skullAnimCounter<4 * NEWTICRATERATIO) //blink cursor { V_DrawCharacter(currentMenu->x - 10, cursory, '*' | 0x80); }}//===========================================================================//MAIN MENU//===========================================================================void M_QuitDOOM(int choice);enum{ singleplr = 0, multiplr, options, readthis, quitdoom, main_end} main_e;menuitem_t MainMenu[]={ {IT_SUBMENU | IT_PATCH,"M_SINGLE","SINGLE PLAYER",&SinglePlayerDef ,'s'}, {IT_SUBMENU | IT_PATCH,"M_MULTI" ,"MULTIPLAYER",&MultiPlayerDef ,'m'}, {IT_SUBMENU | IT_PATCH,"M_OPTION","OPTIONS",&OptionsDef ,'o'}, {IT_SUBMENU | IT_PATCH,"M_RDTHIS","INFO",&ReadDef1 ,'r'}, // Another hickup with Special edition. {IT_CALL | IT_PATCH,"M_QUITG" ,"QUIT GAME",M_QuitDOOM ,'q'}};void HereticMainMenuDrawer(void){ int frame = (I_GetTime()/3)%18; V_DrawScaledPatch(40, 10, 0, W_CachePatchNum(SkullBaseLump+(17-frame), PU_CACHE)); V_DrawScaledPatch(232, 10, 0, W_CachePatchNum(SkullBaseLump+frame, PU_CACHE)); M_DrawGenericMenu();}menu_t MainDef ={ "M_DOOM", NULL, main_end, NULL,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -