Browse Source

[QOL] Colored slot backs (#5266)

pull/5453/head
KPhoenix 3 years ago committed by GitHub
parent
commit
069ba7f1d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      Source/inv.cpp
  2. 2
      Source/inv.h
  3. 4
      Source/qol/stash.cpp

28
Source/inv.cpp

@ -1017,7 +1017,7 @@ int CreateGoldItemInInventorySlot(Player &player, int slotIndex, int value)
} // namespace
void InvDrawSlotBack(const Surface &out, Point targetPosition, Size size)
void InvDrawSlotBack(const Surface &out, Point targetPosition, Size size, item_quality itemQuality)
{
SDL_Rect srcRect = MakeSdlRect(0, 0, size.width, size.height);
out.Clip(&srcRect, &targetPosition);
@ -1030,11 +1030,18 @@ void InvDrawSlotBack(const Surface &out, Point targetPosition, Size size)
for (int hgt = size.height; hgt != 0; hgt--, dst -= dstPitch + size.width) {
for (int wdt = size.width; wdt != 0; wdt--) {
std::uint8_t pix = *dst;
if (pix >= PAL16_BLUE) {
if (pix <= PAL16_BLUE + 15)
pix -= PAL16_BLUE - PAL16_BEIGE;
else if (pix >= PAL16_GRAY)
pix -= PAL16_GRAY - PAL16_BEIGE;
if (pix >= PAL16_GRAY) {
switch (itemQuality) {
case ITEM_QUALITY_MAGIC:
pix -= PAL16_GRAY - PAL16_BLUE - 1;
break;
case ITEM_QUALITY_UNIQUE:
pix -= PAL16_GRAY - PAL16_YELLOW - 1;
break;
default:
pix -= PAL16_GRAY - PAL16_BEIGE - 1;
break;
}
}
*dst++ = pix;
}
@ -1104,7 +1111,7 @@ void DrawInv(const Surface &out)
if (!myPlayer.InvBody[slot].isEmpty()) {
int screenX = slotPos[slot].x;
int screenY = slotPos[slot].y;
InvDrawSlotBack(out, GetPanelPosition(UiPanels::Inventory, { screenX, screenY }), { slotSize[slot].width * InventorySlotSizeInPixels.width, slotSize[slot].height * InventorySlotSizeInPixels.height });
InvDrawSlotBack(out, GetPanelPosition(UiPanels::Inventory, { screenX, screenY }), { slotSize[slot].width * InventorySlotSizeInPixels.width, slotSize[slot].height * InventorySlotSizeInPixels.height }, myPlayer.InvBody[slot]._iMagical);
const int cursId = myPlayer.InvBody[slot]._iCurs + CURSOR_FIRSTITEM;
@ -1130,7 +1137,7 @@ void DrawInv(const Surface &out)
if (slot == INVLOC_HAND_LEFT) {
if (myPlayer.GetItemLocation(myPlayer.InvBody[slot]) == ILOC_TWOHAND) {
InvDrawSlotBack(out, GetPanelPosition(UiPanels::Inventory, slotPos[INVLOC_HAND_RIGHT]), { slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height });
InvDrawSlotBack(out, GetPanelPosition(UiPanels::Inventory, slotPos[INVLOC_HAND_RIGHT]), { slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height }, myPlayer.InvBody[slot]._iMagical);
LightTableIndex = 0;
cel_transparency_active = true;
@ -1149,7 +1156,8 @@ void DrawInv(const Surface &out)
InvDrawSlotBack(
out,
GetPanelPosition(UiPanels::Inventory, InvRect[i + SLOTXY_INV_FIRST]) + Displacement { 0, -1 },
InventorySlotSizeInPixels);
InventorySlotSizeInPixels,
myPlayer.InvList[abs(myPlayer.InvGrid[i]) - 1]._iMagical);
}
}
@ -1187,7 +1195,7 @@ void DrawInvBelt(const Surface &out)
}
const Point position { InvRect[i + SLOTXY_BELT_FIRST].x + mainPanelPosition.x, InvRect[i + SLOTXY_BELT_FIRST].y + mainPanelPosition.y - 1 };
InvDrawSlotBack(out, position, InventorySlotSizeInPixels);
InvDrawSlotBack(out, position, InventorySlotSizeInPixels, myPlayer.SpdList[i]._iMagical);
const int cursId = myPlayer.SpdList[i]._iCurs + CURSOR_FIRSTITEM;
const ClxSprite sprite = GetInvItemSprite(cursId);

2
Source/inv.h

@ -86,7 +86,7 @@ extern bool invflag;
extern bool drawsbarflag;
extern const Point InvRect[73];
void InvDrawSlotBack(const Surface &out, Point targetPosition, Size size);
void InvDrawSlotBack(const Surface &out, Point targetPosition, Size size, item_quality itemQuality);
/**
* @brief Checks whether the given item can be placed on the belt. Takes item size as well as characteristics into account. Items
* that cannot be placed on the belt have to be placed in the inventory instead.

4
Source/qol/stash.cpp

@ -353,8 +353,10 @@ void DrawStash(const Surface &out)
constexpr Displacement offset { 0, INV_SLOT_SIZE_PX - 1 };
for (auto slot : StashGridRange) {
StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slot);
Item &item = Stash.stashList[itemId];
if (Stash.IsItemAtPosition(slot)) {
InvDrawSlotBack(out, GetStashSlotCoord(slot) + offset, InventorySlotSizeInPixels);
InvDrawSlotBack(out, GetStashSlotCoord(slot) + offset, InventorySlotSizeInPixels, item._iMagical);
}
}

Loading…
Cancel
Save