Browse Source

♻️ Replace 'icursW28' and 'icursH28' globals with single 'icursSize28'

pull/2753/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
317ebcdd3e
  1. 14
      Source/controls/plrctrls.cpp
  2. 9
      Source/cursor.cpp
  3. 3
      Source/cursor.h
  4. 2
      Source/inv.cpp
  5. 4
      test/cursor_test.cpp

14
Source/controls/plrctrls.cpp

@ -494,7 +494,7 @@ void AttrIncBtnSnap(AxisDirection dir)
Point InvGetEquipSlotCoord(const inv_body_loc invSlot)
{
Point result = GetPanelPosition(UiPanels::Inventory);
result.x -= (icursW28 - 1) * (InventorySlotSizeInPixels.width / 2);
result.x -= (icursSize28.width - 1) * (InventorySlotSizeInPixels.width / 2);
switch (invSlot) {
case INVLOC_HEAD:
result.x += ((InvRect[SLOTXY_HEAD_FIRST].x + InvRect[SLOTXY_HEAD_LAST].x) / 2);
@ -683,7 +683,7 @@ void InvMove(AxisDirection dir)
if (isHoldingItem) {
if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
if (Slot == SLOTXY_INV_ROW1_FIRST || Slot == SLOTXY_INV_ROW2_FIRST || Slot == SLOTXY_INV_ROW3_FIRST || Slot == SLOTXY_INV_ROW4_FIRST) {
Slot += INV_ROW_SLOT_SIZE - icursW28;
Slot += INV_ROW_SLOT_SIZE - icursSize28.width;
} else {
Slot -= 1;
}
@ -732,8 +732,8 @@ void InvMove(AxisDirection dir)
if (isHoldingItem) {
if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
if (
Slot == SLOTXY_INV_ROW1_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW2_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW3_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW4_LAST + 1 - icursW28) {
Slot -= INV_ROW_SLOT_SIZE - icursW28;
Slot == SLOTXY_INV_ROW1_LAST + 1 - icursSize28.width || Slot == SLOTXY_INV_ROW2_LAST + 1 - icursSize28.width || Slot == SLOTXY_INV_ROW3_LAST + 1 - icursSize28.width || Slot == SLOTXY_INV_ROW4_LAST + 1 - icursSize28.width) {
Slot -= INV_ROW_SLOT_SIZE - icursSize28.width;
} else {
Slot += 1;
}
@ -849,10 +849,10 @@ void InvMove(AxisDirection dir)
} else if (Slot == SLOTXY_RING_RIGHT || Slot == SLOTXY_HAND_RIGHT_FIRST || Slot == SLOTXY_AMULET) {
Slot = SLOTXY_INV_ROW1_LAST - 1;
mousePos = InvGetSlotCoord(Slot);
} else if (Slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) {
} else if (Slot <= (SLOTXY_INV_ROW4_LAST - (icursSize28.height * INV_ROW_SLOT_SIZE))) {
Slot += INV_ROW_SLOT_SIZE;
mousePos = InvGetSlotCoord(Slot);
} else if (Slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items
} else if (Slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursSize28 == Size { 1, 1 }) { // forcing only 1x1 misc items
Slot += INV_ROW_SLOT_SIZE;
if (Slot > SLOTXY_BELT_LAST)
Slot = SLOTXY_BELT_LAST;
@ -922,7 +922,7 @@ void InvMove(AxisDirection dir)
if (Slot >= SLOTXY_INV_FIRST)
mousePos.y -= InventorySlotSizeInPixels.height;
else
mousePos.y -= (int)((icursH28 / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2);
mousePos.y -= (int)((icursSize28.height / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2);
} else {
mousePos.x += (InventorySlotSizeInPixels.width / 2);
mousePos.y -= (InventorySlotSizeInPixels.height / 2);

9
Source/cursor.cpp

@ -105,10 +105,8 @@ const int InvItemHeight2[] = {
Size cursSize;
/** Current highlighted monster */
int pcursmonst = -1;
/** Width of current cursor in inventory cells */
int icursW28;
/** Height of current cursor in inventory cells */
int icursH28;
/** Size of current cursor in inventory cells */
Size icursSize28;
/** inv_item value */
int8_t pcursinvitem;
@ -169,8 +167,7 @@ void SetICursor(int cursId)
auto size = GetInvItemSize(cursId);
icursW = size.width;
icursH = size.height;
icursW28 = icursW / 28;
icursH28 = icursH / 28;
icursSize28 = Size { icursW, icursH } / 28;
}
void NewCursor(int cursId)

3
Source/cursor.h

@ -33,8 +33,7 @@ enum cursor_id : uint8_t {
extern Size cursSize;
extern int pcursmonst;
extern int icursW28;
extern int icursH28;
extern Size icursSize28;
extern int icursH;
extern int8_t pcursinvitem;
extern int icursW;

2
Source/inv.cpp

@ -360,7 +360,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
int i = cursorPosition.x + (IsHardwareCursor() ? 0 : (icursW / 2));
int j = cursorPosition.y + (IsHardwareCursor() ? 0 : (icursH / 2));
Size itemSize { icursW28, icursH28 };
Size itemSize { icursSize28 };
bool done = false;
int r = 0;
for (; r < NUM_XY_SLOTS && !done; r++) {

4
test/cursor_test.cpp

@ -14,6 +14,6 @@ TEST(Cursor, SetCursor)
EXPECT_EQ(cursSize.height, 3 * 28);
EXPECT_EQ(icursW, 1 * 28);
EXPECT_EQ(icursH, 3 * 28);
EXPECT_EQ(icursW28, 1);
EXPECT_EQ(icursH28, 3);
EXPECT_EQ(icursSize28.width, 1);
EXPECT_EQ(icursSize28.height, 3);
}

Loading…
Cancel
Save