- cleaned up c_console.cpp to be moved into 'common'.
This commit is contained in:
parent
59701ddd81
commit
f912712f9d
11 changed files with 409 additions and 294 deletions
|
|
@ -35,44 +35,36 @@
|
|||
#include <string>
|
||||
|
||||
#include "templates.h"
|
||||
#include "p_setup.h"
|
||||
#include "i_system.h"
|
||||
#include "version.h"
|
||||
#include "g_game.h"
|
||||
#include "c_bind.h"
|
||||
#include "c_console.h"
|
||||
#include "c_cvars.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "hu_stuff.h"
|
||||
#include "i_system.h"
|
||||
#include "i_video.h"
|
||||
#include "g_input.h"
|
||||
#include "v_palette.h"
|
||||
#include "v_video.h"
|
||||
#include "gamestate.h"
|
||||
#include "v_text.h"
|
||||
#include "filesystem.h"
|
||||
#include "sbar.h"
|
||||
#include "s_sound.h"
|
||||
#include "doomstat.h"
|
||||
#include "d_gui.h"
|
||||
#include "cmdlib.h"
|
||||
#include "d_net.h"
|
||||
#include "d_event.h"
|
||||
#include "d_player.h"
|
||||
#include "gstrings.h"
|
||||
#include "c_consolebuffer.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "vm.h"
|
||||
#include "utf8.h"
|
||||
#include "s_music.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "v_draw.h"
|
||||
#include "v_font.h"
|
||||
#include "printf.h"
|
||||
#include "i_time.h"
|
||||
#include "texturemanager.h"
|
||||
#include "v_draw.h"
|
||||
#include "i_interface.h"
|
||||
|
||||
|
||||
#include "gi.h"
|
||||
#include "v_video.h"
|
||||
#include "i_system.h"
|
||||
#include "menu.h"
|
||||
#include "menustate.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "c_notifybufferbase.h"
|
||||
#include "g_input.h"
|
||||
#include "c_commandbuffer.h"
|
||||
#include "vm.h"
|
||||
|
||||
#define LEFTMARGIN 8
|
||||
#define RIGHTMARGIN 8
|
||||
|
|
@ -84,13 +76,23 @@ CUSTOM_CVAR(Int, con_buffersize, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|||
if (self >= 0 && self < 128) self = 128;
|
||||
}
|
||||
|
||||
double NotifyFontScale = 1;
|
||||
|
||||
DEFINE_GLOBAL(NotifyFontScale)
|
||||
|
||||
void C_SetNotifyFontScale(double scale)
|
||||
{
|
||||
NotifyFontScale = scale;
|
||||
}
|
||||
|
||||
|
||||
FConsoleBuffer *conbuffer;
|
||||
|
||||
static FTextureID conback;
|
||||
static uint32_t conshade;
|
||||
static bool conline;
|
||||
|
||||
|
||||
extern int chatmodeon;
|
||||
extern FBaseCVar *CVars;
|
||||
extern FConsoleCommand *Commands[FConsoleCommand::HASH_SIZE];
|
||||
|
||||
|
|
@ -101,15 +103,6 @@ int ConBottom, ConScroll, RowAdjust;
|
|||
uint64_t CursorTicker;
|
||||
constate_e ConsoleState = c_up;
|
||||
|
||||
double NotifyFontScale = 1;
|
||||
|
||||
DEFINE_GLOBAL(NotifyFontScale)
|
||||
|
||||
void C_SetNotifyFontScale(double scale)
|
||||
{
|
||||
NotifyFontScale = scale;
|
||||
}
|
||||
|
||||
static int TopLine, InsertLine;
|
||||
|
||||
static void ClearConsole ();
|
||||
|
|
@ -128,20 +121,10 @@ static GameAtExit *ExitCmdList;
|
|||
#define SCROLLDN 2
|
||||
#define SCROLLNO 0
|
||||
|
||||
EXTERN_CVAR (Bool, show_messages)
|
||||
|
||||
// Buffer for AddToConsole()
|
||||
static char *work = NULL;
|
||||
static int worklen = 0;
|
||||
|
||||
CVAR(Float, con_notifytime, 3.f, CVAR_ARCHIVE)
|
||||
CVAR(Bool, con_centernotify, false, CVAR_ARCHIVE)
|
||||
CUSTOM_CVAR(Int, con_scaletext, 0, CVAR_ARCHIVE) // Scale notify text at high resolutions?
|
||||
{
|
||||
if (self < 0) self = 0;
|
||||
}
|
||||
CVAR(Bool, con_pulsetext, false, CVAR_ARCHIVE)
|
||||
|
||||
CUSTOM_CVAR(Int, con_scale, 0, CVAR_ARCHIVE)
|
||||
{
|
||||
if (self < 0) self = 0;
|
||||
|
|
@ -153,6 +136,13 @@ CUSTOM_CVAR(Float, con_alpha, 0.75f, CVAR_ARCHIVE)
|
|||
if (self > 1.f) self = 1.f;
|
||||
}
|
||||
|
||||
// Show developer messages if true.
|
||||
CUSTOM_CVAR(Int, developer, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
FScriptPosition::Developer = self;
|
||||
}
|
||||
|
||||
|
||||
// Command to run when Ctrl-D is pressed at start of line
|
||||
CVAR(String, con_ctrl_d, "", CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
|
||||
|
|
@ -168,51 +158,15 @@ struct History
|
|||
static struct History *HistHead = NULL, *HistTail = NULL, *HistPos = NULL;
|
||||
static int HistSize;
|
||||
|
||||
#define NUMNOTIFIES 4
|
||||
#define NOTIFYFADETIME 6
|
||||
static FNotifyBufferBase *NotifyStrings;
|
||||
|
||||
struct FNotifyText
|
||||
void C_SetNotifyBuffer(FNotifyBufferBase* nbb)
|
||||
{
|
||||
int TimeOut;
|
||||
int Ticker;
|
||||
int PrintLevel;
|
||||
FString Text;
|
||||
};
|
||||
|
||||
struct FNotifyBuffer
|
||||
{
|
||||
public:
|
||||
FNotifyBuffer();
|
||||
void AddString(int printlevel, FString source);
|
||||
void Shift(int maxlines);
|
||||
void Clear()
|
||||
{
|
||||
Text.Clear();
|
||||
if (StatusBar == nullptr) return;
|
||||
IFVIRTUALPTR(StatusBar, DBaseStatusBar, FlushNotify)
|
||||
{
|
||||
VMValue params[] = { (DObject*)StatusBar };
|
||||
VMCall(func, params, countof(params), nullptr, 1);
|
||||
}
|
||||
|
||||
}
|
||||
void Tick();
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
TArray<FNotifyText> Text;
|
||||
int Top;
|
||||
int TopGoal;
|
||||
enum { NEWLINE, APPENDLINE, REPLACELINE } AddType;
|
||||
};
|
||||
static FNotifyBuffer NotifyStrings;
|
||||
|
||||
CUSTOM_CVAR(Int, con_notifylines, NUMNOTIFIES, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
|
||||
{
|
||||
NotifyStrings.Shift(self);
|
||||
NotifyStrings = nbb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int PrintColors[PRINTLEVELS+2] = { CR_UNTRANSLATED, CR_GOLD, CR_GRAY, CR_GREEN, CR_GREEN, CR_UNTRANSLATED };
|
||||
|
||||
static void setmsgcolor (int index, int color);
|
||||
|
|
@ -263,7 +217,7 @@ void C_InitConback()
|
|||
|
||||
if (!conback.isValid())
|
||||
{
|
||||
conback = TexMan.GetTextureID (gameinfo.TitlePage, ETextureType::MiscPatch);
|
||||
conback.SetInvalid();
|
||||
conshade = MAKEARGB(175,0,0,0);
|
||||
conline = true;
|
||||
}
|
||||
|
|
@ -422,101 +376,6 @@ static void setmsgcolor (int index, int color)
|
|||
PrintColors[index] = color;
|
||||
}
|
||||
|
||||
extern int DisplayWidth;
|
||||
|
||||
FNotifyBuffer::FNotifyBuffer()
|
||||
{
|
||||
Top = TopGoal = 0;
|
||||
AddType = NEWLINE;
|
||||
}
|
||||
|
||||
void FNotifyBuffer::Shift(int maxlines)
|
||||
{
|
||||
if (maxlines >= 0 && Text.Size() > (unsigned)maxlines)
|
||||
{
|
||||
Text.Delete(0, Text.Size() - maxlines);
|
||||
}
|
||||
}
|
||||
|
||||
void FNotifyBuffer::AddString(int printlevel, FString source)
|
||||
{
|
||||
TArray<FBrokenLines> lines;
|
||||
int width;
|
||||
|
||||
if (!show_messages ||
|
||||
source.IsEmpty() ||
|
||||
gamestate == GS_FULLCONSOLE ||
|
||||
gamestate == GS_DEMOSCREEN ||
|
||||
con_notifylines == 0)
|
||||
return;
|
||||
|
||||
// [MK] allow the status bar to take over notify printing
|
||||
if (StatusBar != nullptr)
|
||||
{
|
||||
IFVIRTUALPTR(StatusBar, DBaseStatusBar, ProcessNotify)
|
||||
{
|
||||
VMValue params[] = { (DObject*)StatusBar, printlevel, &source };
|
||||
int rv;
|
||||
VMReturn ret(&rv);
|
||||
VMCall(func, params, countof(params), &ret, 1);
|
||||
if (!!rv) return;
|
||||
}
|
||||
}
|
||||
|
||||
width = DisplayWidth / active_con_scaletext(twod, generic_ui);
|
||||
|
||||
FFont *font = generic_ui ? NewSmallFont : AlternativeSmallFont;
|
||||
if (font == nullptr) return; // Without an initialized font we cannot handle the message (this is for those which come here before the font system is ready.)
|
||||
|
||||
if (AddType == APPENDLINE && Text.Size() > 0 && Text[Text.Size() - 1].PrintLevel == printlevel)
|
||||
{
|
||||
FString str = Text[Text.Size() - 1].Text + source;
|
||||
lines = V_BreakLines (font, width, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
lines = V_BreakLines (font, width, source);
|
||||
if (AddType == APPENDLINE)
|
||||
{
|
||||
AddType = NEWLINE;
|
||||
}
|
||||
}
|
||||
|
||||
if (lines.Size() == 0)
|
||||
return;
|
||||
|
||||
for (auto &line : lines)
|
||||
{
|
||||
FNotifyText newline;
|
||||
|
||||
newline.Text = line.Text;
|
||||
newline.TimeOut = int(con_notifytime * GameTicRate);
|
||||
newline.Ticker = 0;
|
||||
newline.PrintLevel = printlevel;
|
||||
if (AddType == NEWLINE || Text.Size() == 0)
|
||||
{
|
||||
if (con_notifylines > 0)
|
||||
{
|
||||
Shift(con_notifylines - 1);
|
||||
}
|
||||
Text.Push(newline);
|
||||
}
|
||||
else
|
||||
{
|
||||
Text[Text.Size() - 1] = newline;
|
||||
}
|
||||
AddType = NEWLINE;
|
||||
}
|
||||
|
||||
switch (source[source.Len()-1])
|
||||
{
|
||||
case '\r': AddType = REPLACELINE; break;
|
||||
case '\n': AddType = NEWLINE; break;
|
||||
default: AddType = APPENDLINE; break;
|
||||
}
|
||||
|
||||
TopGoal = 0;
|
||||
}
|
||||
|
||||
void AddToConsole (int printlevel, const char *text)
|
||||
{
|
||||
|
|
@ -585,9 +444,9 @@ int PrintString (int iprintlevel, const char *outline)
|
|||
I_PrintStr(outline);
|
||||
|
||||
conbuffer->AddText(printlevel, outline);
|
||||
if (vidactive && screen && !(iprintlevel & PRINT_NONOTIFY))
|
||||
if (vidactive && screen && !(iprintlevel & PRINT_NONOTIFY) && NotifyStrings)
|
||||
{
|
||||
NotifyStrings.AddString(printlevel, outline);
|
||||
NotifyStrings->AddString(iprintlevel, outline);
|
||||
}
|
||||
}
|
||||
if (Logfile != nullptr && !(iprintlevel & PRINT_NOLOG))
|
||||
|
|
@ -599,11 +458,6 @@ int PrintString (int iprintlevel, const char *outline)
|
|||
return 0; // Don't waste time on calculating this if nothing at all was printed...
|
||||
}
|
||||
|
||||
void C_ClearMessages()
|
||||
{
|
||||
NotifyStrings.Clear();
|
||||
}
|
||||
|
||||
int VPrintf (int printlevel, const char *format, va_list parms)
|
||||
{
|
||||
FString outline;
|
||||
|
|
@ -655,7 +509,7 @@ int DPrintf (int level, const char *format, ...)
|
|||
|
||||
void C_FlushDisplay ()
|
||||
{
|
||||
NotifyStrings.Clear();
|
||||
if (NotifyStrings) NotifyStrings->Clear();
|
||||
}
|
||||
|
||||
void C_AdjustBottom ()
|
||||
|
|
@ -710,101 +564,7 @@ void C_Ticker()
|
|||
}
|
||||
|
||||
lasttic = consoletic;
|
||||
NotifyStrings.Tick();
|
||||
}
|
||||
|
||||
void FNotifyBuffer::Tick()
|
||||
{
|
||||
if (TopGoal > Top)
|
||||
{
|
||||
Top++;
|
||||
}
|
||||
else if (TopGoal < Top)
|
||||
{
|
||||
Top--;
|
||||
}
|
||||
|
||||
// Remove lines from the beginning that have expired.
|
||||
unsigned i;
|
||||
for (i = 0; i < Text.Size(); ++i)
|
||||
{
|
||||
Text[i].Ticker++;
|
||||
}
|
||||
|
||||
for (i = 0; i < Text.Size(); ++i)
|
||||
{
|
||||
if (Text[i].TimeOut != 0 && Text[i].TimeOut > Text[i].Ticker)
|
||||
break;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
Text.Delete(0, i);
|
||||
FFont* font = generic_ui ? NewSmallFont : AlternativeSmallFont;
|
||||
Top += font->GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
void FNotifyBuffer::Draw()
|
||||
{
|
||||
bool center = (con_centernotify != 0.f);
|
||||
int line, lineadv, color, j;
|
||||
bool canskip;
|
||||
|
||||
FFont* font = generic_ui ? NewSmallFont : AlternativeSmallFont;
|
||||
|
||||
line = Top + font->GetDisplacement();
|
||||
canskip = true;
|
||||
|
||||
lineadv = font->GetHeight ();
|
||||
|
||||
for (unsigned i = 0; i < Text.Size(); ++ i)
|
||||
{
|
||||
FNotifyText ¬ify = Text[i];
|
||||
|
||||
if (notify.TimeOut == 0)
|
||||
continue;
|
||||
|
||||
j = notify.TimeOut - notify.Ticker;
|
||||
if (j > 0)
|
||||
{
|
||||
double alpha = (j < NOTIFYFADETIME) ? 1. * j / NOTIFYFADETIME : 1;
|
||||
if (con_pulsetext)
|
||||
{
|
||||
alpha *= 0.7 + 0.3 * sin(I_msTime() / 100.);
|
||||
}
|
||||
|
||||
if (notify.PrintLevel >= PRINTLEVELS)
|
||||
color = CR_UNTRANSLATED;
|
||||
else
|
||||
color = PrintColors[notify.PrintLevel];
|
||||
|
||||
int scale = active_con_scaletext(twod, generic_ui);
|
||||
if (!center)
|
||||
DrawText(twod, font, color, 0, line, notify.Text,
|
||||
DTA_VirtualWidth, twod->GetWidth() / scale,
|
||||
DTA_VirtualHeight, twod->GetHeight() / scale,
|
||||
DTA_KeepRatio, true,
|
||||
DTA_Alpha, alpha, TAG_DONE);
|
||||
else
|
||||
DrawText(twod, font, color, (twod->GetWidth() -
|
||||
font->StringWidth (notify.Text) * scale) / 2 / scale,
|
||||
line, notify.Text,
|
||||
DTA_VirtualWidth, twod->GetWidth() / scale,
|
||||
DTA_VirtualHeight, twod->GetHeight() / scale,
|
||||
DTA_KeepRatio, true,
|
||||
DTA_Alpha, alpha, TAG_DONE);
|
||||
line += lineadv;
|
||||
canskip = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
notify.TimeOut = 0;
|
||||
}
|
||||
}
|
||||
if (canskip)
|
||||
{
|
||||
Top = TopGoal;
|
||||
}
|
||||
if (NotifyStrings) NotifyStrings->Tick();
|
||||
}
|
||||
|
||||
void C_DrawConsole ()
|
||||
|
|
@ -829,9 +589,9 @@ void C_DrawConsole ()
|
|||
oldbottom = ConBottom;
|
||||
|
||||
if (ConsoleState == c_up && gamestate != GS_INTRO && gamestate != GS_INTERMISSION &&
|
||||
gamestate != GS_FULLCONSOLE && gamestate == GS_MENUSCREEN)
|
||||
gamestate != GS_FULLCONSOLE && gamestate != GS_MENUSCREEN)
|
||||
{
|
||||
NotifyStrings.Draw();
|
||||
if (NotifyStrings) NotifyStrings->Draw();
|
||||
return;
|
||||
}
|
||||
else if (ConBottom)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue