diff --git a/Source/engine/render/cel_render.cpp b/Source/engine/render/cel_render.cpp index 533d6a1c0..e7b89fd8c 100644 --- a/Source/engine/render/cel_render.cpp +++ b/Source/engine/render/cel_render.cpp @@ -647,12 +647,20 @@ void CelClippedDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const Cel CelBlitSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } -void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, char light) +void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; const auto *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); - const std::uint8_t *tbl = GetLightTable(light); - RenderCelWithLightTable(out, { sx, sy }, pRLEBytes, nDataSize, cel.Width(frame), tbl); + RenderCelWithLightTable(out, { sx, sy }, pRLEBytes, nDataSize, cel.Width(frame), GetLightTable(1)); +} + +void CelDrawItem(bool usable, const CelOutputBuffer &out, int x, int y, const CelSprite &cel, int frame) +{ + if (usable) { + CelDrawLightRedTo(out, x, y, cel, frame); + } else { + CelClippedDrawTo(out, x, y, cel, frame); + } } void CelClippedDrawSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) @@ -678,11 +686,11 @@ void CelClippedBlitLightTransTo(const CelOutputBuffer &out, int sx, int sy, cons CelBlitSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } -void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, char light) +void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; const auto *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); - RenderCelWithLightTable(out, { sx, sy }, pRLEBytes, nDataSize, cel.Width(frame), GetLightTable(light)); + RenderCelWithLightTable(out, { sx, sy }, pRLEBytes, nDataSize, cel.Width(frame), GetLightTable(1)); } void CelDrawUnsafeTo(const CelOutputBuffer &out, int x, int y, const CelSprite &cel, int frame) diff --git a/Source/engine/render/cel_render.hpp b/Source/engine/render/cel_render.hpp index 4794a527b..c6346a318 100644 --- a/Source/engine/render/cel_render.hpp +++ b/Source/engine/render/cel_render.hpp @@ -84,9 +84,19 @@ void CelClippedBlitLightTransTo(const CelOutputBuffer &out, int sx, int sy, cons * @param sy Target buffer coordinate * @param cel CEL sprite * @param frame CEL frame number - * @param light Light shade to use */ -void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, char light); +void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame); + +/** + * @brief Blit item's CEL sprite recolored red if not usable, normal if usable + * @param usable indicates if the item should be recolored red or not + * @param out Target buffer + * @param x Target buffer coordinate + * @param y Target buffer coordinate + * @param cel CEL sprite + * @param frame CEL frame number + */ +void CelDrawItem(bool usable, const CelOutputBuffer &out, int x, int y, const CelSprite &cel, int frame); /** * @brief Same as CelClippedDrawTo but checks for drawing outside the buffer @@ -105,9 +115,8 @@ void CelClippedDrawSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelS * @param sy Target buffer coordinate * @param cel CEL sprite * @param frame CEL frame number - * @param light Light shade to use */ -void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, char light); +void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame); /** * @brief Blit a solid colder shape one pixel larger then the given sprite shape, to the target buffer at the given coordianates diff --git a/Source/inv.cpp b/Source/inv.cpp index 137aa1146..73f3d8da6 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -230,11 +230,7 @@ void DrawInv(const CelOutputBuffer &out) CelBlitOutlineTo(out, GetOutlineColor(plr[myplr].InvBody[slot], true), RIGHT_PANEL_X + screen_x, screen_y, cel, celFrame, false); } - if (plr[myplr].InvBody[slot]._iStatFlag) { - CelClippedDrawTo(out, RIGHT_PANEL_X + screen_x, screen_y, cel, celFrame); - } else { - CelDrawLightRedTo(out, RIGHT_PANEL_X + screen_x, screen_y, cel, celFrame, 1); - } + CelDrawItem(plr[myplr].InvBody[slot]._iStatFlag, out, RIGHT_PANEL_X + screen_x, screen_y, cel, celFrame); if (slot == INVLOC_HAND_LEFT) { if (plr[myplr].InvBody[slot]._iLoc == ILOC_TWOHAND) { @@ -284,19 +280,12 @@ void DrawInv(const CelOutputBuffer &out) cel, celFrame, false); } - if (plr[myplr].InvList[ii]._iStatFlag) { - CelClippedDrawTo( - out, - InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, - InvRect[j + SLOTXY_INV_FIRST].Y - 1, - cel, celFrame); - } else { - CelDrawLightRedTo( - out, - InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, - InvRect[j + SLOTXY_INV_FIRST].Y - 1, - cel, celFrame, 1); - } + CelDrawItem( + plr[myplr].InvList[ii]._iStatFlag, + out, + InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, + InvRect[j + SLOTXY_INV_FIRST].Y - 1, + cel, celFrame); } } } @@ -326,11 +315,7 @@ void DrawInvBelt(const CelOutputBuffer &out) } } - if (plr[myplr].SpdList[i]._iStatFlag) { - CelClippedDrawTo(out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame); - } else { - CelDrawLightRedTo(out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame, 1); - } + CelDrawItem(plr[myplr].SpdList[i]._iStatFlag, out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame); if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable && plr[myplr].SpdList[i]._iStatFlag diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index a9dea66fe..0ec81f90a 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -186,17 +186,13 @@ static void DrawCursor(const CelOutputBuffer &out) const auto &sprite = GetInvItemSprite(pcurs); const int frame = GetInvItemFrame(pcurs); + bool usable = true; if (pcurs >= CURSOR_FIRSTITEM) { const auto &heldItem = plr[myplr].HoldItem; CelBlitOutlineTo(out, GetOutlineColor(heldItem, true), MouseX, MouseY + cursH - 1, sprite, frame, false); - if (heldItem._iStatFlag) { - CelClippedDrawSafeTo(out, MouseX, MouseY + cursH - 1, sprite, frame); - } else { - CelDrawLightRedSafeTo(out, MouseX, MouseY + cursH - 1, sprite, frame, 1); - } - } else { - CelClippedDrawSafeTo(out, MouseX, MouseY + cursH - 1, sprite, frame); + usable = heldItem._iStatFlag; } + CelDrawItem(usable, out, MouseX, MouseY + cursH - 1, sprite, frame); } /**