⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Con.java * Copyright (C) 2003 *  * $Id: Console.java,v 1.7 2005/06/30 08:36:22 hzi 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 java.io.IOException;import java.io.RandomAccessFile;import java.util.Arrays;import jake2.Defines;import jake2.Globals;import jake2.game.Cmd;import jake2.qcommon.*;import jake2.util.Lib;import jake2.util.Vargs;/** * Console */public final class Console extends Globals {    public static xcommand_t ToggleConsole_f = new xcommand_t() {        public void execute() {            SCR.EndLoadingPlaque(); // get rid of loading plaque            if (Globals.cl.attractloop) {                Cbuf.AddText("killserver\n");                return;            }            if (Globals.cls.state == Defines.ca_disconnected) {                // start the demo loop again                Cbuf.AddText("d1\n");                return;            }            Key.ClearTyping();            Console.ClearNotify();            if (Globals.cls.key_dest == Defines.key_console) {                Menu.ForceMenuOff();                Cvar.Set("paused", "0");            } else {                Menu.ForceMenuOff();                Globals.cls.key_dest = Defines.key_console;                if (Cvar.VariableValue("maxclients") == 1                        && Globals.server_state != 0)                    Cvar.Set("paused", "1");            }        }    };    public static xcommand_t Clear_f = new xcommand_t() {        public void execute() {            Arrays.fill(Globals.con.text, (byte) ' ');        }    };    public static xcommand_t Dump_f = new xcommand_t() {        public void execute() {            int l, x;            int line;            RandomAccessFile f;            byte[] buffer = new byte[1024];            String name;            if (Cmd.Argc() != 2) {                Com.Printf("usage: condump <filename>\n");                return;            }            //Com_sprintf (name, sizeof(name), "%s/%s.txt", FS_Gamedir(),            // Cmd_Argv(1));            name = FS.Gamedir() + "/" + Cmd.Argv(1) + ".txt";            Com.Printf("Dumped console text to " + name + ".\n");            FS.CreatePath(name);            f = Lib.fopen(name, "rw");            if (f == null) {                Com.Printf("ERROR: couldn't open.\n");                return;            }            // skip empty lines            for (l = con.current - con.totallines + 1; l <= con.current; l++) {                line = (l % con.totallines) * con.linewidth;                for (x = 0; x < con.linewidth; x++)                    if (con.text[line + x] != ' ')                        break;                if (x != con.linewidth)                    break;            }            // write the remaining lines            buffer[con.linewidth] = 0;            for (; l <= con.current; l++) {                line = (l % con.totallines) * con.linewidth;                //strncpy (buffer, line, con.linewidth);                System.arraycopy(con.text, line, buffer, 0, con.linewidth);                for (x = con.linewidth - 1; x >= 0; x--) {                    if (buffer[x] == ' ')                        buffer[x] = 0;                    else                        break;                }                for (x = 0; buffer[x] != 0; x++)                    buffer[x] &= 0x7f;                buffer[x] = '\n';                // fprintf (f, "%s\n", buffer);                try {                    f.write(buffer, 0, x + 1);                } catch (IOException e) {                }            }            Lib.fclose(f);        }    };    /**     *       */    public static void Init() {        Globals.con.linewidth = -1;        CheckResize();        Com.Printf("Console initialized.\n");        //        // register our commands        //        Globals.con_notifytime = Cvar.Get("con_notifytime", "3", 0);        Cmd.AddCommand("toggleconsole", ToggleConsole_f);        Cmd.AddCommand("togglechat", ToggleChat_f);        Cmd.AddCommand("messagemode", MessageMode_f);        Cmd.AddCommand("messagemode2", MessageMode2_f);        Cmd.AddCommand("clear", Clear_f);        Cmd.AddCommand("condump", Dump_f);        Globals.con.initialized = true;    }    /**     * If the line width has changed, reformat the buffer.     */    public static void CheckResize() {        int width = (Globals.viddef.width >> 3) - 2;        if (width > Defines.MAXCMDLINE) width = Defines.MAXCMDLINE;        if (width == Globals.con.linewidth)            return;        if (width < 1) { // video hasn't been initialized yet            width = 38;            Globals.con.linewidth = width;            Globals.con.totallines = Defines.CON_TEXTSIZE                    / Globals.con.linewidth;            Arrays.fill(Globals.con.text, (byte) ' ');        } else {            int oldwidth = Globals.con.linewidth;            Globals.con.linewidth = width;            int oldtotallines = Globals.con.totallines;            Globals.con.totallines = Defines.CON_TEXTSIZE                    / Globals.con.linewidth;            int numlines = oldtotallines;            if (Globals.con.totallines < numlines)                numlines = Globals.con.totallines;            int numchars = oldwidth;            if (Globals.con.linewidth < numchars)                numchars = Globals.con.linewidth;            byte[] tbuf = new byte[Defines.CON_TEXTSIZE];            System                    .arraycopy(Globals.con.text, 0, tbuf, 0,                            Defines.CON_TEXTSIZE);            Arrays.fill(Globals.con.text, (byte) ' ');            for (int i = 0; i < numlines; i++) {                for (int j = 0; j < numchars; j++) {                    Globals.con.text[(Globals.con.totallines - 1 - i)                            * Globals.con.linewidth + j] = tbuf[((Globals.con.current                            - i + oldtotallines) % oldtotallines)                            * oldwidth + j];                }            }            Console.ClearNotify();        }        Globals.con.current = Globals.con.totallines - 1;        Globals.con.display = Globals.con.current;    }    public static void ClearNotify() {        int i;        for (i = 0; i < Defines.NUM_CON_TIMES; i++)            Globals.con.times[i] = 0;    }    static void DrawString(int x, int y, String s) {        for (int i = 0; i < s.length(); i++) {            Globals.re.DrawChar(x, y, s.charAt(i));            x += 8;        }    }    static void DrawAltString(int x, int y, String s) {        for (int i = 0; i < s.length(); i++) {            Globals.re.DrawChar(x, y, s.charAt(i) ^ 0x80);            x += 8;        }    }    /*     * ================ Con_ToggleChat_f ================     */    static xcommand_t ToggleChat_f = new xcommand_t() {        public void execute() {            Key.ClearTyping();            if (cls.key_dest == key_console) {                if (cls.state == ca_active) {                    Menu.ForceMenuOff();                    cls.key_dest = key_game;                }            } else                cls.key_dest = key_console;            ClearNotify();        }    };    /*     * ================ Con_MessageMode_f ================     */    static xcommand_t MessageMode_f = new xcommand_t() {        public void execute() {            chat_team = false;            cls.key_dest = key_message;        }    };    /*     * ================ Con_MessageMode2_f ================     */    static xcommand_t MessageMode2_f = new xcommand_t() {        public void execute() {            chat_team = true;            cls.key_dest = key_message;        }    };    /*     * =============== Con_Linefeed ===============     */    static void Linefeed() {        Globals.con.x = 0;        if (Globals.con.display == Globals.con.current)            Globals.con.display++;        Globals.con.current++;        int i = (Globals.con.current % Globals.con.totallines)                * Globals.con.linewidth;        int e = i + Globals.con.linewidth;        while (i++ < e)            Globals.con.text[i] = ' ';    }    /*     * ================ Con_Print     *      * Handles cursor positioning, line wrapping, etc All console printing must     * go through this in order to be logged to disk If no console is visible,     * the text will appear at the top of the game window ================     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -