Revision: 26736
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 8, 2010 20:16 by spire8989
Initial Code
void InventoryGui::setGui() { if(inv) { // set item list { // here we have to hide the items which are assigned to slots // create a 'is' array which determines visibility of an element (1=visible, 0=hidden) Bool *is=Alloc<Bool>(inv->items.elms()); // allocate bytes for all items in container SetMem(is,1,inv->items.elms()); // set memory to '1' (make all items visible by default) REPA(inv->slot) // iterate through all slots { if(inv->slot[i].valid()) // if the slot is valid { Int index=inv->items.validIndex(&inv->slot[i]()); // get index of a slot item in items container if(InRange(index,inv->items)) // if its valid is[index]=0; // set visibility for item assigned to a slot to 0, to be hidden on the list } } list.setData(inv->items,is); // set list data from items container and visibility list Free(is); // free allocated memory } // set slot images REP(SLOT_NUM) // for all slots if(i!=SLOT_TEMP) // skip temporary slot because it's not drawn using 'Image' class { GuiImage &img_back= slot_img[i][0], // background image, we use it for accessing its rectangle &img_item= slot_img[i][1]; // item image Reference<Item> & item=inv->slot [i] ; // item at slot if(!item.valid())img_item.set(NULL);else // if there is no item then clear the item image slot { Image *icon=item().icon; // access item's icon img_item.set(icon); // set slot image as the item's icon if(icon) // set proper scaling { Vec2 size(icon->x(),icon->y()); size*=PIXEL_SIZE; // set default size if(size.x>img_back.rect.w())size*=img_back.rect.w()/size.x; // clamp item size to background slot width if(size.y>img_back.rect.h())size*=img_back.rect.h()/size.y; // clamp item size to background slot height Rect rect(img_back.rect.center()); rect.extend(size/2); img_item.setRect(rect); } } } }else { list.clear(); REP(SLOT_NUM)slot_img[i][1].set(NULL); } }
Initial URL
Initial Description
Initial Title
Stranded - Snippet 1
Initial Tags
Initial Language
C++