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

📄 console.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:

Procedure Con_Init;
begin
  con.linewidth := -1;
  Con_CheckResize;
  Com_Printf ('Console initialized.'#10,[]);
  //
  // register our commands
  //
  con_notifytime := Cvar_Get ('con_notifytime', '3', 0);

  Cmd_AddCommand ('toggleconsole', Con_ToggleConsole_f);
  Cmd_AddCommand ('togglechat', Con_ToggleChat_f);
  Cmd_AddCommand ('messagemode', Con_MessageMode_f);
  Cmd_AddCommand ('messagemode2', Con_MessageMode2_f);
  Cmd_AddCommand ('clear', Con_Clear_f);
  Cmd_AddCommand ('condump', Con_Dump_f);
  con.initialized := true;
end; {Con_Init}

{
===============
Con_Linefeed
===============
}
Procedure Con_Linefeed;
begin
  con.x := 0;
  if (con.display = con.current) then
    Inc(con.display);
  Inc(con.current);
  Fillchar (con.text[(con.current mod con.totallines)*con.linewidth], con.linewidth, ' ');
end;  {Con_Linefeed}

{
================
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
================
}
var
   cr : boolean = false;

Procedure Con_Print (txt : Pchar);
var
  y,l,mask : integer;
  ch : char;
begin
  if not con.initialized then
    exit;

  if (txt[0] = #1 ) or ( txt[0] = #2) then
  begin
    mask := 128; // go to colored text
    inc(txt);
  end
  else
    mask := 0;

  ch := txt[0];
  while ch <> #0 do
  begin
  // count word length
  for l := 0 to con.linewidth -1 do
    if Ord(txt[l]) <= Ord(' ') then
      break;
  // word wrap
  if (l <> con.linewidth) and (con.x + l > con.linewidth) then
    con.x := 0;

  inc(txt);

  if cr then
    begin
      dec(con.current);
      cr := false;
    end;

  if con.x = 0 then
    begin
    Con_Linefeed;
    // mark time for transparent overlay
    if con.current >= 0 then
      con.times[con.current mod NUM_CON_TIMES] := cls.realtime;
    end;

  case ch of
    #10 : con.x := 0;
    #13 :
    begin
      con.x := 0;
      cr := true;
    end;
    else  // display character and advance
    begin
      y := con.current mod con.totallines;
      con.text[y * con.linewidth + con.x] := Char(Ord(ch) or mask or con.ormask);
      Inc(con.x);
      if con.x >= con.linewidth then
        con.x := 0;
    end;
  end;
  ch := txt[0];
  end;
end; {Con_Print}

{
==============
Con_CenteredPrint
==============
}
Procedure Con_CenteredPrint (text : Pchar);
var
  Len : integer;
  buffer : array [0..1024-1] of char;
begin
  Len := strlen(text);
  Len := (con.linewidth - Len ) div 2;
  if Len < 0 then
    Len := 0;
  Fillchar(buffer,Len,Ord(' '));
  strcpy (buffer+Len, text);
  strcat (buffer, #10);
  Con_Print (buffer);
end; {Con_CenteredPrint}

{
==============================================================================

DRAWING

==============================================================================
}


{
================
Con_DrawInput

The input line scrolls horizontally if typing goes beyond the right edge
================
}
Procedure Con_DrawInput;
var
  Index,y : integer;
  text : pchar;
begin
  if cls.key_dest = Client.key_menu then
    exit;
  if (cls.key_dest <> Client.key_console) and (cls.state = ca_active) then
    exit;   // don't draw anything (always draw if not active)

  text := key_lines[edit_line];

  // add the cursor frame
  text[key_linepos] := Char(10+(cls.realtime shr 8) and 1);

  // fill out remainder with spaces
  for Index := key_linepos+1 to con.linewidth-1 do
    text[Index] := ' ';

  //  prestep if horizontally scrolling
  if key_linepos >= con.linewidth then
    text := text + 1 + key_linepos - con.linewidth;

  // draw it
  y := con.vislines - 16;
  for Index := 0 to con.linewidth -1 do
    re.DrawChar ( (Index+1) Shl 3, con.vislines - 22, byte(text[Index]));

  // remove cursor
  key_lines[edit_line][key_linepos] := #0;
end; {Con_DrawInput}

{
================
Con_DrawNotify

Draws the last few lines of output transparently over the game top
================
}
Procedure Con_DrawNotify;
var
  x,v,index,skip : integer;
  time : integer;
  Text,s : pchar;
begin
  v := 0;
  for index := con.current - NUM_CON_TIMES+1 to con.current  do
  begin
    if index < 0 then
      continue;
    time := Round(con.times[index mod NUM_CON_TIMES]);
    if time = 0 then
      continue;
    time := cls.realtime - time;
    if time > con_notifytime^.value * 1000 then
      continue;
    text := con.text + (index mod con.totallines) * con.linewidth;

    for x := 0 to con.linewidth -1 do
      re.DrawChar ( (x+1) shl 3, v, byte(text[x]));

    inc(v,8);
  end;


  if cls.key_dest = Client.key_message then
  begin
    if chat_team then
    begin
      DrawString (8, v, 'say_team:');
      skip := 11;
    end
    else
    begin
      DrawString (8, v, 'say:');
      skip := 5;
    end;

    s := chat_buffer;
    if chat_bufferlen > (viddef.width shr 3)-(skip+1) then
      s := s + chat_bufferlen - ((viddef.width shr 3)-(skip+1));
    x := 0;
    while s[x] <> #0 do
    begin
      re.DrawChar ( (x+skip) shl 3, v, byte(s[x]));
      Inc(x);
    end;
    re.DrawChar ( (x+skip) shl 3, v, Byte(10+((cls.realtime  shr 8) and 1)));
    inc(v,8);
  end;

  if v <> 0 then
  begin
    SCR_AddDirtyPoint (0,0);
    SCR_AddDirtyPoint (viddef.width-1, v);
  end;
end; {Con_DrawNotify}

{
================
Con_DrawConsole

Draws the console with the solid background
================
}

Procedure Con_DrawConsole(frac : Single);
var
  index , j, x, y, n : integer;
  rows,row,lines : integer;
  text : Pchar;
  VersionStr : array [0..63] of char;
  dlbar : array [0..1023] of char;
begin
  lines := Round(viddef.height * frac);
  if lines <= 0 then
    exit;

  if lines > viddef.height then
    lines := viddef.height;

  // draw the background
  re.DrawStretchPic (0, -viddef.height+lines, viddef.width, viddef.height, 'conback');
  SCR_AddDirtyPoint (0,0);
  SCR_AddDirtyPoint (viddef.width-1,lines-1);

  Com_sprintf (VersionStr, sizeof(VersionStr), 'v%4.2f', [VERSION]);
  For x := 0 to 4 do
    re.DrawChar (viddef.width - 44 + x * 8, lines-12, Byte(128 + Ord(VersionStr[x])) );

  // draw the text
  con.vislines := lines;

  {
  rows := (lines-8) Shr 3;		// rows of text to draw
  y := lines - 24;
  }
  rows := (lines-22) Shr 3;		// rows of text to draw
  y := lines - 30;

  // draw from the bottom up
  if (con.display <> con.current) then
  begin
    // draw arrows to show the buffer is backscrolled
    x := 0;
    While x < con.linewidth  do
    begin
      re.DrawChar ( (x+1)shl 3, y, Byte('^'));
      inc(x,4)
    end;
    dec(y,8);
    dec(rows);
  end;

  row := con.display;
  for index := 0  to rows -1 do
  begin
    if row < 0 then
      break;
    if con.current - row >= con.totallines then
      break;  // past scrollback wrap point
    text := con.text + (row mod con.totallines) * con.linewidth;

    for x := 0 to con.linewidth -1 do
      re.DrawChar ( (x+1) shl 3, y, Byte(text[x]));
    dec(y,8);
    dec(row);
  end;

//ZOID

// draw the download bar
// figure out width
if cls.download > 0 then
  begin
  text := strrchr(cls.downloadname, Byte('/'));
  if (text <> nil) then
    Inc(text)
  else
    text := cls.downloadname;

  x := con.linewidth - ((con.linewidth * 7) div 40);
  y := x - Integer(strlen(text)) - 8;
  index := con.linewidth div 3;
  if Integer(strlen(text)) > index then
    begin
    y := x - index - 11;
    strncpy(dlbar, text, index);
    dlbar[index] := #0;
    strcat(dlbar, '...');
    end
  else
    strcopy(dlbar, text);
  strcat(dlbar, ': ');
  index := strlen(dlbar);
  dlbar[index] := #$80;  // dlbar[i++] = '\x80';
  Inc(Index);
  // where's the dot go?
  if cls.downloadpercent = 0 then
    n := 0
  else
    n := y * cls.downloadpercent div 100;
			
  for j := 0 to y -1 do
    begin
    if j = n then
      dlbar[index] := #$83
    else
      dlbar[index] := #$81;
     inc(index);
    end;
  dlbar[index] := #$82;
  inc(index);
  dlbar[index] := #0;

  StrFmt(dlbar + strlen(dlbar), ' %02d%%', [cls.downloadpercent]);

  // draw it
  y := con.vislines-12;
  for index := 0 to strlen(dlbar) -1 do
    re.DrawChar ( (index +1) shl 3, y, Byte(dlbar[index]));
  end;
  //ZOID

  // draw the input prompt, user text, and cursor if desired
  Con_DrawInput;
end; {Con_DrawConsole}


initialization
finalization
// make sure the memory allocated for the key bindings is freed

end.

⌨️ 快捷键说明

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