コード例 #1
0
ファイル: inventry.c プロジェクト: Tigerwhit4/Meridian59
/*
 * InventoryClick:  User clicked on inventory box.
 *   Return True iff processing of click should continue.
 */
Bool InventoryClick(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
    int row, col, old_row, old_col, index;
    InvItem *item;

    // Find row and col in absolute coordinates
    col = x / INVENTORY_BOX_WIDTH;
    row = top_row + y / INVENTORY_BOX_HEIGHT;

    switch (GameGetState())
    {
    case GAME_PLAY:
        SetFocus(hwnd);
        if (!InventoryItemVisible(row, col))
            return False;

        old_row = cursor_row;
        old_col = cursor_col;

        cursor_row = row;
        cursor_col = col;

        // Redraw cursor
        if (InventoryItemVisible(old_row, old_col))
        {
            item = (InvItem *) list_nth_item(items, old_row * cols + old_col);
            if (item != NULL)
                InventoryDrawSingleItem(item, old_row - top_row, old_col);
        }

        item = (InvItem *) list_nth_item(items, cursor_row * cols + cursor_col);
        if (item != NULL)
            InventoryDrawSingleItem(item, cursor_row - top_row, cursor_col);
        break;

    case GAME_SELECT:
        if (InventoryItemVisible(row, col))
        {
            /* User clicked on an object--get its id */
            index = row * cols + col;
            item = (InvItem *) list_nth_item(items, index);
            if (item != NULL)
                SelectedObject(item->obj->id);
        }
        return False;
    }
    return True;
}
コード例 #2
0
ファイル: inventry.c プロジェクト: Tigerwhit4/Meridian59
/*
 * InventoryMoveCurrentItem:  Move the item with the inventory cursor, if any.
 *   Return True iff item moved.
 */
Bool InventoryMoveCurrentItem(int x, int y)
{
    int row, col;
    InvItem *item, *drop_position;

    item = InventoryGetCurrentItem();
    if (item == NULL)
        return False;

    // Find row and col in absolute coordinates
    col = x / INVENTORY_BOX_WIDTH;
    row = top_row + y / INVENTORY_BOX_HEIGHT;

    drop_position = (InvItem *) list_nth_item(items, row * cols + col);
    if (drop_position == NULL)
        return False;

    if (item->obj->id == drop_position->obj->id)
        return False;

    items = list_move_to_nth(items,(void *)item->obj->id,(void *)drop_position->obj->id,InventoryCompareIdItem);
    InventoryRedraw();

    RequestInventoryMove(item->obj->id, drop_position->obj->id);

    return True;
}
コード例 #3
0
/*
 * GuildShieldDraw:
 */
void GuildShieldDraw(void)
{
   HDC hDC;
   AREA areaWndShield;
   RECT rcWndShield;
   object_node obj;
   list_type listBlank = NULL;
   void* pIcon = NULL;

   if (!hwndShield)
      return;

   GetClientRect(hwndShield, &rcWndShield);
   RectToArea(&rcWndShield, &areaWndShield);
   memset(&obj, 0, sizeof(object_node));

   pIcon = list_nth_item(listShieldIDs, iChosenPattern-1);
   if (pIcon)
   {
      obj.icon_res = (pIcon? (*(ID*)pIcon) : 0);
      obj.translation = XLAT_GUILDCOLOR_BASE + iNumColors*iChosenColor1 + iChosenColor2;
      obj.overlays = &listBlank;
      hDC = GetDC(hwndShield);
      DrawStretchedObjectDefault(hDC, &obj, &areaWndShield, GetSysColorBrush(COLOR_3DFACE));
      ReleaseDC(hwndShield, hDC);
   }
}
コード例 #4
0
ファイル: inventry.c プロジェクト: Tigerwhit4/Meridian59
/*
 * InventoryCursorMove:  User requests the given cursor movement action.
 *   Move cursor.
 */
void InventoryCursorMove(int action)
{
    int dx = 0, dy = 0;
    int old_row, old_col, new_row, new_col;
    InvItem *item;

    switch (action)
    {
    case A_CURSORUP:
        dy = -1;
        break;
    case A_CURSORDOWN:
        dy = +1;
        break;
    case A_CURSORLEFT:
        dx = -1;
        break;
    case A_CURSORRIGHT:
        dx = +1;
        break;
    case A_CURSORUPLEFT:
        dx = -1;
        dy = -1;
        break;
    case A_CURSORUPRIGHT:
        dx = +1;
        dy = -1;
        break;
    case A_CURSORDOWNLEFT:
        dx = -1;
        dy = +1;
        break;
    case A_CURSORDOWNRIGHT:
        dx = +1;
        dy = +1;
        break;
    default:
        return;
    }

    new_col = (cursor_col + dx) % cols;
    if (new_col < 0)
        new_col += cols;

    new_row = max(0, cursor_row + dy);

    // See if we're going off end of inventory
    if (new_row * cols + new_col >= num_items)
        return;

    old_row = cursor_row;
    old_col = cursor_col;

    cursor_col = new_col;
    cursor_row = new_row;

    // Scroll inventory if necessary
    if (!InventoryItemVisible(cursor_row, cursor_col))
    {
        top_row += dy;
        InventoryRedraw();
        SetScrollPos(hwndInvScroll, SB_CTL, top_row, TRUE);
    }
    else // Otherwise, redraw cursor to show movement
    {
        item = (InvItem *) list_nth_item(items, old_row * cols + old_col);
        if (item != NULL)
            InventoryDrawSingleItem(item, old_row - top_row, old_col);
        item = (InvItem *) list_nth_item(items, cursor_row * cols + cursor_col);
        if (item != NULL)
            InventoryDrawSingleItem(item, cursor_row - top_row, cursor_col);
    }
}
コード例 #5
0
ファイル: inventry.c プロジェクト: Tigerwhit4/Meridian59
/*
 * InventoryGetCurrentItem:  Return item with cursor in inventory, or NULL if none.
 */
InvItem *InventoryGetCurrentItem(void)
{
    int index = cursor_row * cols + cursor_col;
    return (InvItem *) list_nth_item(items, index);
}