/src/MenuItemStorage.cpp
C++ | 82 lines | 52 code | 11 blank | 19 comment | 9 complexity | 2badbeb7d423d222ed614de166a1d8ef MD5 | raw file
Possible License(s): GPL-3.0
1/* 2Copyright 2011 Clint Bellanger 3 4This file is part of FLARE. 5 6FLARE is free software: you can redistribute it and/or modify it under the terms 7of the GNU General Public License as published by the Free Software Foundation, 8either version 3 of the License, or (at your option) any later version. 9 10FLARE is distributed in the hope that it will be useful, but WITHOUT ANY 11WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 12PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14You should have received a copy of the GNU General Public License along with 15FLARE. If not, see http://www.gnu.org/licenses/ 16*/ 17 18/** 19 * class MenuItemStorage 20 */ 21 22#include "MenuItemStorage.h" 23 24using namespace std; 25 26void MenuItemStorage::init(int _slot_number, ItemManager *_items, SDL_Rect _area, int _icon_size, int _nb_cols) { 27 ItemStorage::init( _slot_number, _items); 28 area = _area; 29 icon_size = _icon_size; 30 nb_cols = _nb_cols; 31} 32 33void MenuItemStorage::render() { 34 for (int i=0; i<slot_number; i++) { 35 if (storage[i].item > 0) { 36 items->renderIcon(storage[i], area.x + (i % nb_cols * icon_size), area.y + (i / nb_cols * icon_size), icon_size); 37 } 38 } 39} 40 41int MenuItemStorage::slotOver(Point mouse) { 42 if( isWithin( area, mouse)) { 43 return (mouse.x - area.x) / icon_size + (mouse.y - area.y) / icon_size * nb_cols; 44 } 45 else { 46 return -1; 47 } 48} 49 50TooltipData MenuItemStorage::checkTooltip(Point mouse, StatBlock *stats, bool vendor_view) { 51 TooltipData tip; 52 int slot = slotOver( mouse); 53 54 if (slot > -1 && storage[slot].item > 0) { 55 return items->getTooltip( storage[slot].item, stats, vendor_view); 56 } 57 return tip; 58} 59 60ItemStack MenuItemStorage::click(InputState * input) { 61 ItemStack item; 62 drag_prev_slot = slotOver(input->mouse); 63 if( drag_prev_slot > -1) { 64 item = storage[drag_prev_slot]; 65 if( input->pressing[SHIFT]) { 66 item.quantity = 1; 67 } 68 substract( drag_prev_slot, item.quantity); 69 return item; 70 } 71 else { 72 item.item = 0; 73 item.quantity = 0; 74 return item; 75 } 76} 77 78void MenuItemStorage::itemReturn(ItemStack stack) { 79 add( stack, drag_prev_slot); 80 drag_prev_slot = -1; 81} 82