diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index 5799a23423..266ef47beb 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -15,6 +15,7 @@ #include "cmdlib.h" #include "i_system.h" #include "v_text.h" +#include "sc_man.h" #include #include @@ -324,7 +325,7 @@ FString ExtractFileBase (const char *path, bool include_extension) // //========================================================================== -int ParseHex (const char *hex) +int ParseHex (const char *hex, FScriptPosition *sc) { const char *str; int num; @@ -342,7 +343,8 @@ int ParseHex (const char *hex) else if (*str >= 'A' && *str <= 'F') num += 10 + *str-'A'; else { - Printf ("Bad hex number: %s\n",hex); + if (!sc) Printf ("Bad hex number: %s\n",hex); + else sc->Message(MSG_WARNING, "Bad hex number: %s", hex); return 0; } str++; @@ -351,21 +353,6 @@ int ParseHex (const char *hex) return num; } -//========================================================================== -// -// ParseNum -// -//========================================================================== - -int ParseNum (const char *str) -{ - if (str[0] == '$') - return ParseHex (str+1); - if (str[0] == '0' && str[1] == 'x') - return ParseHex (str+2); - return atol (str); -} - //========================================================================== // // IsNum diff --git a/src/cmdlib.h b/src/cmdlib.h index b035842cdf..6e9fcd622f 100644 --- a/src/cmdlib.h +++ b/src/cmdlib.h @@ -33,8 +33,8 @@ void DefaultExtension (FString &path, const char *extension); FString ExtractFilePath (const char *path); FString ExtractFileBase (const char *path, bool keep_extension=false); -int ParseHex (const char *str); -int ParseNum (const char *str); +struct FScriptPosition; +int ParseHex(const char *str, FScriptPosition *sc = nullptr); bool IsNum (const char *str); // [RH] added char *copystring(const char *s); diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index 1fc63e03d3..b80cbaf988 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -193,10 +193,10 @@ void FIWadManager::ParseIWadInfo(const char *fn, const char *data, int datasize) { sc.MustGetStringName("="); sc.MustGetString(); - iwad->FgColor = V_GetColor(NULL, sc.String); + iwad->FgColor = V_GetColor(NULL, sc); sc.MustGetStringName(","); sc.MustGetString(); - iwad->BkColor = V_GetColor(NULL, sc.String); + iwad->BkColor = V_GetColor(NULL, sc); } else if (sc.Compare("Load")) { diff --git a/src/d_main.cpp b/src/d_main.cpp index 7cc40cc058..a2cb181f18 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1844,10 +1844,10 @@ static FString ParseGameInfo(TArray &pwads, const char *fn, const char else if (!nextKey.CompareNoCase("STARTUPCOLORS")) { sc.MustGetString(); - DoomStartupInfo.FgColor = V_GetColor(NULL, sc.String); + DoomStartupInfo.FgColor = V_GetColor(NULL, sc); sc.MustGetStringName(","); sc.MustGetString(); - DoomStartupInfo.BkColor = V_GetColor(NULL, sc.String); + DoomStartupInfo.BkColor = V_GetColor(NULL, sc); } else if (!nextKey.CompareNoCase("STARTUPTYPE")) { diff --git a/src/decallib.cpp b/src/decallib.cpp index 9fe2966eb4..5d24e44d51 100644 --- a/src/decallib.cpp +++ b/src/decallib.cpp @@ -532,7 +532,7 @@ void FDecalLib::ParseDecal (FScanner &sc) sc.MustGetString (); if (!sc.Compare("BloodDefault")) { - newdecal.ShadeColor = V_GetColor (NULL, sc.String); + newdecal.ShadeColor = V_GetColor (NULL, sc); } else { @@ -547,8 +547,8 @@ void FDecalLib::ParseDecal (FScanner &sc) case DECAL_COLORS: DWORD startcolor, endcolor; - sc.MustGetString (); startcolor = V_GetColor (NULL, sc.String); - sc.MustGetString (); endcolor = V_GetColor (NULL, sc.String); + sc.MustGetString (); startcolor = V_GetColor (NULL, sc); + sc.MustGetString (); endcolor = V_GetColor (NULL, sc); newdecal.Translation = GenerateTranslation (startcolor, endcolor)->Index; break; @@ -819,7 +819,7 @@ void FDecalLib::ParseColorchanger (FScanner &sc) else if (sc.Compare ("Color")) { sc.MustGetString (); - goal = V_GetColor (NULL, sc.String); + goal = V_GetColor (NULL, sc); } else { diff --git a/src/g_mapinfo.cpp b/src/g_mapinfo.cpp index b839059014..5ffb04732b 100644 --- a/src/g_mapinfo.cpp +++ b/src/g_mapinfo.cpp @@ -860,14 +860,14 @@ DEFINE_MAP_OPTION(fade, true) { parse.ParseAssign(); parse.sc.MustGetString(); - info->fadeto = V_GetColor(NULL, parse.sc.String); + info->fadeto = V_GetColor(NULL, parse.sc); } DEFINE_MAP_OPTION(outsidefog, true) { parse.ParseAssign(); parse.sc.MustGetString(); - info->outsidefog = V_GetColor(NULL, parse.sc.String); + info->outsidefog = V_GetColor(NULL, parse.sc); } DEFINE_MAP_OPTION(titlepatch, true) diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 0fcf4e4d5a..d09cb40b6e 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -400,10 +400,10 @@ static void ParseListMenuBody(FScanner &sc, FListMenuDescriptor *desc) int y = sc.Number; sc.MustGetStringName(","); sc.MustGetString(); - PalEntry c1 = V_GetColor(NULL, sc.String); + PalEntry c1 = V_GetColor(NULL, sc); sc.MustGetStringName(","); sc.MustGetString(); - PalEntry c2 = V_GetColor(NULL, sc.String); + PalEntry c2 = V_GetColor(NULL, sc); if (sc.CheckString(",")) { sc.MustGetNumber(); diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index c392d97d32..a0491f69d8 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -1256,7 +1256,7 @@ FxExpression *FxColorCast::Resolve(FCompileContext &ctx) } else { - FxExpression *x = new FxConstant(V_GetColor(nullptr, constval.GetString()), ScriptPosition); + FxExpression *x = new FxConstant(V_GetColor(nullptr, constval.GetString(), &ScriptPosition), ScriptPosition); delete this; return x; } diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index 442e52884f..f53b970067 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -165,7 +165,7 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c } else { - int c = V_GetColor (NULL, sc.String); + int c = V_GetColor (NULL, sc); // 0 needs to be the default so we have to mark the color. v = MAKEARGB(1, RPART(c), GPART(c), BPART(c)); } diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 2eb5f67812..ef6309d4bd 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -2305,8 +2305,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, color, C_f, Inventory) *pBlendColor = MakeSpecialColormap(65535); return; } - - color = V_GetColor(NULL, name); + color = V_GetColor(NULL, name, &bag.ScriptPosition); } if (PROP_PARM_COUNT > 2) { diff --git a/src/teaminfo.cpp b/src/teaminfo.cpp index bf0ef8a40b..38ba56f4cd 100644 --- a/src/teaminfo.cpp +++ b/src/teaminfo.cpp @@ -182,7 +182,7 @@ void FTeam::ParseTeamDefinition (FScanner &Scan) case TEAMINFO_PlayerColor: Scan.MustGetString (); - Team.m_iPlayerColor = V_GetColor (NULL, Scan.String); + Team.m_iPlayerColor = V_GetColor (NULL, Scan); break; case TEAMINFO_TextColor: diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index de3dd2f131..e68c4e20f2 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -1097,7 +1097,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part, TexInit &init) if (!sc.CheckNumber()) { sc.MustGetString(); - part.Blend = V_GetColor(NULL, sc.String); + part.Blend = V_GetColor(NULL, sc); } else { diff --git a/src/v_font.cpp b/src/v_font.cpp index 0eb28a67c3..f024e2d2ba 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -2300,19 +2300,19 @@ void V_InitFontColors () else if (sc.Compare ("Flat:")) { sc.MustGetString(); - logcolor = V_GetColor (NULL, sc.String); + logcolor = V_GetColor (NULL, sc); } else { // Get first color - c = V_GetColor (NULL, sc.String); + c = V_GetColor (NULL, sc); tparm.Start[0] = RPART(c); tparm.Start[1] = GPART(c); tparm.Start[2] = BPART(c); // Get second color sc.MustGetString(); - c = V_GetColor (NULL, sc.String); + c = V_GetColor (NULL, sc); tparm.End[0] = RPART(c); tparm.End[1] = GPART(c); tparm.End[2] = BPART(c); diff --git a/src/v_video.cpp b/src/v_video.cpp index 7192c5d033..efe93aa04a 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -44,6 +44,7 @@ #include "i_video.h" #include "v_video.h" #include "v_text.h" +#include "sc_man.h" #include "w_wad.h" @@ -437,7 +438,7 @@ void DCanvas::ReleaseScreenshotBuffer() // //========================================================================== -int V_GetColorFromString (const DWORD *palette, const char *cstr) +int V_GetColorFromString (const DWORD *palette, const char *cstr, FScriptPosition *sc) { int c[3], i, p; char val[3]; @@ -456,7 +457,7 @@ int V_GetColorFromString (const DWORD *palette, const char *cstr) { val[0] = cstr[1 + i*2]; val[1] = cstr[2 + i*2]; - c[i] = ParseHex (val); + c[i] = ParseHex (val, sc); } } else if (len == 4) @@ -465,7 +466,7 @@ int V_GetColorFromString (const DWORD *palette, const char *cstr) for (i = 0; i < 3; ++i) { val[1] = val[0] = cstr[1 + i]; - c[i] = ParseHex (val); + c[i] = ParseHex (val, sc); } } else @@ -518,7 +519,7 @@ normal: { val[1] = val[0]; } - c[i] = ParseHex (val); + c[i] = ParseHex (val, sc); } } } @@ -538,7 +539,7 @@ normal: // //========================================================================== -FString V_GetColorStringByName (const char *name) +FString V_GetColorStringByName (const char *name, FScriptPosition *sc) { FMemLump rgbNames; char *rgbEnd; @@ -552,7 +553,8 @@ FString V_GetColorStringByName (const char *name) rgblump = Wads.CheckNumForName ("X11R6RGB"); if (rgblump == -1) { - Printf ("X11R6RGB lump not found\n"); + if (!sc) Printf ("X11R6RGB lump not found\n"); + else sc->Message(MSG_WARNING, "X11R6RGB lump not found"); return FString(); } @@ -614,7 +616,8 @@ FString V_GetColorStringByName (const char *name) } if (rgb < rgbEnd) { - Printf ("X11R6RGB lump is corrupt\n"); + if (!sc) Printf ("X11R6RGB lump is corrupt\n"); + else sc->Message(MSG_WARNING, "X11R6RGB lump is corrupt"); } return FString(); } @@ -627,22 +630,28 @@ FString V_GetColorStringByName (const char *name) // //========================================================================== -int V_GetColor (const DWORD *palette, const char *str) +int V_GetColor (const DWORD *palette, const char *str, FScriptPosition *sc) { - FString string = V_GetColorStringByName (str); + FString string = V_GetColorStringByName (str, sc); int res; if (!string.IsEmpty()) { - res = V_GetColorFromString (palette, string); + res = V_GetColorFromString (palette, string, sc); } else { - res = V_GetColorFromString (palette, str); + res = V_GetColorFromString (palette, str, sc); } return res; } +int V_GetColor(const DWORD *palette, FScanner &sc) +{ + FScriptPosition scc = sc; + return V_GetColor(palette, sc.String, &scc); +} + //========================================================================== // // BuildTransTable diff --git a/src/v_video.h b/src/v_video.h index 890ab6d638..971aa6c13d 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -497,15 +497,17 @@ void V_Shutdown (); void V_MarkRect (int x, int y, int width, int height); +class FScanner; // Returns the closest color to the one desired. String // should be of the form "rr gg bb". -int V_GetColorFromString (const DWORD *palette, const char *colorstring); +int V_GetColorFromString (const DWORD *palette, const char *colorstring, FScriptPosition *sc = nullptr); // Scans through the X11R6RGB lump for a matching color // and returns a color string suitable for V_GetColorFromString. -FString V_GetColorStringByName (const char *name); +FString V_GetColorStringByName (const char *name, FScriptPosition *sc = nullptr); // Tries to get color by name, then by string -int V_GetColor (const DWORD *palette, const char *str); +int V_GetColor (const DWORD *palette, const char *str, FScriptPosition *sc = nullptr); +int V_GetColor(const DWORD *palette, FScanner &sc); void V_DrawFrame (int left, int top, int width, int height); // If the view size is not full screen, draws a border around it.