Skip to content

Commit

Permalink
Heretic & Hexen: Display selected item in the middle of inventory bar…
Browse files Browse the repository at this point in the history
… (if possible) when it is opening

If there are not enough items on one of the sides to fill the inventory bar, they will be shifted to that side or left if there are less than 7 items in the inventory.
  • Loading branch information
Dasperal committed Jan 16, 2024
1 parent 930e386 commit 573f48a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
37 changes: 28 additions & 9 deletions src/heretic/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,23 @@ static void G_DoLoadLevel (void)
}
}

// TODO:common Heretic Hexen Strife?
static const int init_inventory_cursor(const int num_of_items, const int selected_item)
{
if(num_of_items < 7 || selected_item < 3)
{
return selected_item; // cursor on the left side
}
else if(num_of_items - selected_item <= 3)
{
return 7 - (num_of_items - selected_item); // cursor on the right side
}
else
{
return 3; // cursor in the middle
}
}

/*
===============================================================================
=
Expand Down Expand Up @@ -879,48 +896,50 @@ boolean G_Responder(event_t * ev)
next_weapon = 1;
}

if (BK_isKeyDown(ev, bk_inv_left))
if(BK_isKeyDown(ev, bk_inv_left))
{
inventoryTics = 5 * 35;
if (!inventory)
if(!inventory)
{
inventory = true;
curpos = init_inventory_cursor(plr->inventorySlotNum, inv_ptr);
return false;
}
inv_ptr--;
if (inv_ptr < 0)
if(inv_ptr < 0)
{
inv_ptr = 0;
}
else
{
curpos--;
if (curpos < 0)
if(curpos < 0)
{
curpos = 0;
}
}
return true;
}
if (BK_isKeyDown(ev, bk_inv_right))
if(BK_isKeyDown(ev, bk_inv_right))
{
inventoryTics = 5 * 35;
if (!inventory)
if(!inventory)
{
inventory = true;
curpos = init_inventory_cursor(plr->inventorySlotNum, inv_ptr);
return false;
}
inv_ptr++;
if (inv_ptr >= plr->inventorySlotNum)
if(inv_ptr >= plr->inventorySlotNum)
{
inv_ptr--;
if (inv_ptr < 0)
if(inv_ptr < 0)
inv_ptr = 0;
}
else
{
curpos++;
if (curpos > 6)
if(curpos > 6)
{
curpos = 6;
}
Expand Down
37 changes: 28 additions & 9 deletions src/hexen/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,23 @@ void G_DoLoadLevel(void)
}
}

// TODO:common Heretic Hexen Strife?
static const int init_inventory_cursor(const int num_of_items, const int selected_item)
{
if(num_of_items < 7 || selected_item < 3)
{
return selected_item; // cursor on the left side
}
else if(num_of_items - selected_item <= 3)
{
return 7 - (num_of_items - selected_item); // cursor on the right side
}
else
{
return 3; // cursor in the middle
}
}

/*
===============================================================================
=
Expand Down Expand Up @@ -853,48 +870,50 @@ boolean G_Responder(event_t * ev)
next_weapon = 1;
}

if (BK_isKeyDown(ev, bk_inv_left))
if(BK_isKeyDown(ev, bk_inv_left))
{
inventoryTics = 5 * 35;
if (!inventory)
if(!inventory)
{
inventory = true;
curpos = init_inventory_cursor(plr->inventorySlotNum, inv_ptr);
return false;
}
inv_ptr--;
if (inv_ptr < 0)
if(inv_ptr < 0)
{
inv_ptr = 0;
}
else
{
curpos--;
if (curpos < 0)
if(curpos < 0)
{
curpos = 0;
}
}
return true;
}
if (BK_isKeyDown(ev, bk_inv_right))
if(BK_isKeyDown(ev, bk_inv_right))
{
inventoryTics = 5 * 35;
if (!inventory)
if(!inventory)
{
inventory = true;
curpos = init_inventory_cursor(plr->inventorySlotNum, inv_ptr);
return false;
}
inv_ptr++;
if (inv_ptr >= plr->inventorySlotNum)
if(inv_ptr >= plr->inventorySlotNum)
{
inv_ptr--;
if (inv_ptr < 0)
if(inv_ptr < 0)
inv_ptr = 0;
}
else
{
curpos++;
if (curpos > 6)
if(curpos > 6)
{
curpos = 6;
}
Expand Down

0 comments on commit 573f48a

Please sign in to comment.