Browse Source

Item & Magic selection fix, compatible for DOS/WIN

louyihua 8 years ago
parent
commit
31774cf5d1
2 changed files with 34 additions and 30 deletions
  1. 17 15
      itemmenu.c
  2. 17 15
      magicmenu.c

+ 17 - 15
itemmenu.c

@@ -46,7 +46,7 @@ PAL_ItemSelectMenuUpdate(
 
 --*/
 {
-   int                i, j, k, line;
+   int                i, j, k, line, item_delta;
    WORD               wObject, wScript;
    BYTE               bColor;
    static BYTE        bufImage[2048];
@@ -65,27 +65,27 @@ PAL_ItemSelectMenuUpdate(
    //
    if (g_InputState.dwKeyPress & kKeyUp)
    {
-      gpGlobals->iCurInvMenuItem -= iItemsPerLine;
+      item_delta = -iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyDown)
    {
-      gpGlobals->iCurInvMenuItem += iItemsPerLine;
+      item_delta = iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyLeft)
    {
-      gpGlobals->iCurInvMenuItem--;
+      item_delta = -1;
    }
    else if (g_InputState.dwKeyPress & kKeyRight)
    {
-      gpGlobals->iCurInvMenuItem++;
+      item_delta = 1;
    }
    else if (g_InputState.dwKeyPress & kKeyPgUp)
    {
-      gpGlobals->iCurInvMenuItem -= iItemsPerLine * iLinesPerPage;
+      item_delta = -(iItemsPerLine * iLinesPerPage);
    }
    else if (g_InputState.dwKeyPress & kKeyPgDn)
    {
-      gpGlobals->iCurInvMenuItem += iItemsPerLine * iLinesPerPage;
+      item_delta = iItemsPerLine * iLinesPerPage;
    }
    else if (g_InputState.dwKeyPress & kKeyMenu)
    {
@@ -95,14 +95,16 @@ PAL_ItemSelectMenuUpdate(
    //
    // Make sure the current menu item index is in bound
    //
-   if (gpGlobals->iCurInvMenuItem < 0)
-   {
-      gpGlobals->iCurInvMenuItem = 0;
-   }
-   else if (gpGlobals->iCurInvMenuItem >= g_iNumInventory)
-   {
-      gpGlobals->iCurInvMenuItem = g_iNumInventory - 1;
-   }
+   //if (gpGlobals->iCurInvMenuItem < 0)
+   //{
+   //   gpGlobals->iCurInvMenuItem = 0;
+   //}
+   //else if (gpGlobals->iCurInvMenuItem >= g_iNumInventory)
+   //{
+   //   gpGlobals->iCurInvMenuItem = g_iNumInventory - 1;
+   //}
+   if (gpGlobals->iCurInvMenuItem + item_delta >= 0 && gpGlobals->iCurInvMenuItem + item_delta < g_iNumInventory)
+      gpGlobals->iCurInvMenuItem += item_delta;
 
    //
    // Redraw the box

+ 17 - 15
magicmenu.c

@@ -53,7 +53,7 @@ PAL_MagicSelectionMenuUpdate(
 
 --*/
 {
-   int         i, j, k, line;
+   int         i, j, k, line, item_delta;
    BYTE        bColor;
    WORD        wScript;
    const int   iItemsPerLine = 32 / gpGlobals->dwWordLength;
@@ -68,27 +68,27 @@ PAL_MagicSelectionMenuUpdate(
    //
    if (g_InputState.dwKeyPress & kKeyUp)
    {
-      g_iCurrentItem -= iItemsPerLine;
+      item_delta = -iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyDown)
    {
-      g_iCurrentItem += iItemsPerLine;
+      item_delta = iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyLeft)
    {
-      g_iCurrentItem--;
+      item_delta = -1;
    }
    else if (g_InputState.dwKeyPress & kKeyRight)
    {
-      g_iCurrentItem++;
+      item_delta = 1;
    }
    else if (g_InputState.dwKeyPress & kKeyPgUp)
    {
-      g_iCurrentItem -= iItemsPerLine * iLinesPerPage;
+      item_delta = -(iItemsPerLine * iLinesPerPage);
    }
    else if (g_InputState.dwKeyPress & kKeyPgDn)
    {
-      g_iCurrentItem += iItemsPerLine * iLinesPerPage;
+      item_delta = iItemsPerLine * iLinesPerPage;
    }
    else if (g_InputState.dwKeyPress & kKeyMenu)
    {
@@ -98,14 +98,16 @@ PAL_MagicSelectionMenuUpdate(
    //
    // Make sure the current menu item index is in bound
    //
-   if (g_iCurrentItem < 0)
-   {
-      g_iCurrentItem = 0;
-   }
-   else if (g_iCurrentItem >= g_iNumMagic)
-   {
-      g_iCurrentItem = g_iNumMagic - 1;
-   }
+   //if (g_iCurrentItem < 0)
+   //{
+   //   g_iCurrentItem = 0;
+   //}
+   //else if (g_iCurrentItem >= g_iNumMagic)
+   //{
+   //   g_iCurrentItem = g_iNumMagic - 1;
+   //}
+   if (g_iCurrentItem + item_delta >= 0 && g_iCurrentItem + item_delta < g_iNumMagic)
+      g_iCurrentItem += item_delta;
 
    //
    // Create the box.