📄 menu.java
字号:
/* * Menu.java * Copyright (C) 2004 * * $Id: Menu.java,v 1.20.2.1 2006/04/06 13:14:59 cawe Exp $ *//* Copyright (C) 1997-2001 Id Software, Inc. 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. */package jake2.client;import jake2.Globals;import jake2.game.Cmd;import jake2.game.cvar_t;import jake2.qcommon.*;import jake2.sound.S;import jake2.sys.*;import jake2.sys.NET;import jake2.sys.Sys;import jake2.util.*;import java.awt.Dimension;import java.io.RandomAccessFile;import java.util.Arrays;import java.util.Comparator;/** * Menu * * */abstract class keyfunc_t { abstract String execute(int key);}public final class Menu extends Key { static int m_main_cursor; static final int NUM_CURSOR_FRAMES = 15; static final String menu_in_sound = "misc/menu1.wav"; static final String menu_move_sound = "misc/menu2.wav"; static final String menu_out_sound = "misc/menu3.wav"; static boolean m_entersound; // play after drawing a frame, so caching // won't disrupt the sound static xcommand_t m_drawfunc; static keyfunc_t m_keyfunc; // ============================================================================= /* Support Routines */ public final static int MAX_MENU_DEPTH = 8; public static class menulayer_t { xcommand_t draw; keyfunc_t key; } static class menuframework_s { int x, y; int cursor; int nitems; int nslots; menucommon_s items[] = new menucommon_s[64]; String statusbar; //void (*cursordraw)( struct _tag_menuframework *m ); mcallback cursordraw; } abstract static class mcallback { abstract public void execute(Object self); } static class menucommon_s { int type; String name = ""; int x, y; menuframework_s parent; int cursor_offset; int localdata[] = { 0, 0, 0, 0 }; int flags; int n = -1; //position in an array. String statusbar; mcallback callback; mcallback statusbarfunc; mcallback ownerdraw; mcallback cursordraw; } static class menufield_s extends menucommon_s { //char buffer[80]; StringBuffer buffer; //allow deletion. int cursor; int length; int visible_length; int visible_offset; } static class menuslider_s extends menucommon_s { float minvalue; float maxvalue; float curvalue; float range; } static class menulist_s extends menucommon_s { int curvalue; String itemnames[]; } static class menuaction_s extends menucommon_s { } static class menuseparator_s extends menucommon_s { } public static menulayer_t m_layers[] = new menulayer_t[MAX_MENU_DEPTH]; public static int m_menudepth; static void Banner(String name) { Dimension dim = new Dimension(); Globals.re.DrawGetPicSize(dim, name); Globals.re.DrawPic(viddef.width / 2 - dim.width / 2, viddef.height / 2 - 110, name); } static void PushMenu(xcommand_t draw, keyfunc_t key) { //, String(*key) // (int k) ) { int i; if (Cvar.VariableValue("maxclients") == 1 && Globals.server_state != 0) Cvar.Set("paused", "1"); // if this menu is already present, drop back to that level // to avoid stacking menus by hotkeys for (i = 0; i < m_menudepth; i++) if (m_layers[i].draw == draw && m_layers[i].key == key) { m_menudepth = i; } if (i == m_menudepth) { if (m_menudepth >= MAX_MENU_DEPTH) Com.Error(ERR_FATAL, "PushMenu: MAX_MENU_DEPTH"); m_layers[m_menudepth].draw = draw;//m_drawfunc; m_layers[m_menudepth].key = key;//m_keyfunc; } m_menudepth++; m_drawfunc = draw; m_keyfunc = key; m_entersound = true; cls.key_dest = key_menu; } static void ForceMenuOff() { m_drawfunc = null; m_keyfunc = null; cls.key_dest = key_game; m_menudepth = 0; Key.ClearStates(); Cvar.Set("paused", "0"); } static void PopMenu() { S.StartLocalSound(menu_out_sound); m_menudepth--; if (m_menudepth < 0) Com.Error(ERR_FATAL, "PopMenu: depth < 1"); if (0 < m_menudepth){ m_drawfunc = m_layers[m_menudepth-1].draw; m_keyfunc = m_layers[m_menudepth-1].key; } if (0 == m_menudepth) ForceMenuOff(); } static String Default_MenuKey(menuframework_s m, int key) { String sound = null; menucommon_s item; if (m != null) { if ((item = ((menucommon_s) Menu_ItemAtCursor(m))) != null) { if (item.type == MTYPE_FIELD) { if (Field_Key((menufield_s) item, key)) return null; } } } switch (key) { case K_ESCAPE: PopMenu(); return menu_out_sound; case K_KP_UPARROW: case K_UPARROW: if (m != null) { m.cursor--; Menu_AdjustCursor(m, -1); sound = menu_move_sound; } break; case K_TAB: if (m != null) { m.cursor++; Menu_AdjustCursor(m, 1); sound = menu_move_sound; } break; case K_KP_DOWNARROW: case K_DOWNARROW: if (m != null) { m.cursor++; Menu_AdjustCursor(m, 1); sound = menu_move_sound; } break; case K_KP_LEFTARROW: case K_LEFTARROW: if (m != null) { Menu_SlideItem(m, -1); sound = menu_move_sound; } break; case K_KP_RIGHTARROW: case K_RIGHTARROW: if (m != null) { Menu_SlideItem(m, 1); sound = menu_move_sound; } break; case K_MOUSE1: case K_MOUSE2: case K_MOUSE3: case K_JOY1: case K_JOY2: case K_JOY3: case K_JOY4: /* * case K_AUX1 : case K_AUX2 : case K_AUX3 : case K_AUX4 : case K_AUX5 : * case K_AUX6 : case K_AUX7 : case K_AUX8 : case K_AUX9 : case K_AUX10 : * case K_AUX11 : case K_AUX12 : case K_AUX13 : case K_AUX14 : case * K_AUX15 : case K_AUX16 : case K_AUX17 : case K_AUX18 : case K_AUX19 : * case K_AUX20 : case K_AUX21 : case K_AUX22 : case K_AUX23 : case * K_AUX24 : case K_AUX25 : case K_AUX26 : case K_AUX27 : case K_AUX28 : * case K_AUX29 : case K_AUX30 : case K_AUX31 : case K_AUX32 : */ case K_KP_ENTER: case K_ENTER: if (m != null) Menu_SelectItem(m); sound = menu_move_sound; break; } return sound; } /* * ================ DrawCharacter * * Draws one solid graphics character cx and cy are in 320*240 coordinates, * and will be centered on higher res screens. ================ */ public static void DrawCharacter(int cx, int cy, int num) { re.DrawChar(cx + ((viddef.width - 320) >> 1), cy + ((viddef.height - 240) >> 1), num); } public static void Print(int cx, int cy, String str) { //while (*str) for (int n = 0; n < str.length(); n++) { DrawCharacter(cx, cy, str.charAt(n) + 128); //str++; cx += 8; } } public static void PrintWhite(int cx, int cy, String str) { for (int n = 0; n < str.length(); n++) { DrawCharacter(cx, cy, str.charAt(n)); //str++; cx += 8; } } public static void DrawPic(int x, int y, String pic) { re.DrawPic(x + ((viddef.width - 320) >> 1), y + ((viddef.height - 240) >> 1), pic); } /* * ============= DrawCursor * * Draws an animating cursor with the point at x,y. The pic will extend to * the left of x, and both above and below y. ============= */ static boolean cached; static void DrawCursor(int x, int y, int f) { //char cursorname[80]; String cursorname; assert (f >= 0) : "negative time and cursor bug"; f = Math.abs(f); if (!cached) { int i; for (i = 0; i < NUM_CURSOR_FRAMES; i++) { cursorname = "m_cursor" + i; re.RegisterPic(cursorname); } cached = true; } cursorname = "m_cursor" + f; re.DrawPic(x, y, cursorname); } public static void DrawTextBox(int x, int y, int width, int lines) { int cx, cy; int n; // draw left side cx = x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -