Implement dummy items and scrollablewindowcomponent setup
This commit is contained in:
+14
-11
@@ -6,39 +6,42 @@
|
||||
#include "Item.h"
|
||||
#include "MenuItemButton.h"
|
||||
#include "MenuLabel.h"
|
||||
#include "ScrollableWindowComponent.h"
|
||||
|
||||
INCLUDE_GFX
|
||||
typedef Attribute A;
|
||||
|
||||
Menu*Menu::InitializeInventoryWindow(){
|
||||
constexpr int invWidth=5;
|
||||
constexpr int invHeight=3;
|
||||
constexpr int totalItemSlots=invWidth*invHeight;
|
||||
constexpr int initialInvHeight=3;
|
||||
|
||||
constexpr int itemSpacing=8;
|
||||
constexpr int buttonSize=24;
|
||||
constexpr int totalSpacing=buttonSize+itemSpacing;
|
||||
|
||||
vf2d windowSize={totalSpacing*invWidth-itemSpacing+1,totalSpacing*(invHeight+1)-itemSpacing+24};
|
||||
vf2d windowSize={totalSpacing*invWidth-itemSpacing+1,totalSpacing*(3+1)-itemSpacing+24};
|
||||
|
||||
Menu*inventoryWindow=new Menu(CENTERED,windowSize);
|
||||
|
||||
ScrollableWindowComponent*inventory=new ScrollableWindowComponent(INVENTORY,{{0,0},{windowSize.x,totalSpacing*3-itemSpacing}},nullptr,[](MenuFuncData data){});
|
||||
inventoryWindow->AddComponent("inventory",inventory);
|
||||
|
||||
MenuFunc useItemFunc=[](MenuFuncData data){
|
||||
MenuItemButton*button=(MenuItemButton*)data.component;
|
||||
button->UseItem();
|
||||
};
|
||||
|
||||
for(int y=0;y<invHeight;y++){
|
||||
for(int x=0;x<invWidth;x++){
|
||||
int itemIndex=y*invWidth+x;
|
||||
MenuItemButton*button=new MenuItemButton{INVENTORY,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc};
|
||||
inventoryWindow->AddComponent("item"+std::to_string(itemIndex),button);
|
||||
}
|
||||
for(int i=0;i<Inventory::get("Consumables").size();i++){
|
||||
int x=i%invWidth;
|
||||
int y=i/invWidth;
|
||||
int itemIndex=y*invWidth+x;
|
||||
MenuItemButton*button=new MenuItemButton{INVENTORY,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc};
|
||||
inventory->AddComponent(inventoryWindow,"item"+std::to_string(itemIndex),button);
|
||||
}
|
||||
|
||||
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,invHeight*totalSpacing-4},windowSize),"",false,true};
|
||||
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,initialInvHeight*totalSpacing-4},windowSize),"",false,true};
|
||||
inventoryWindow->AddComponent("itemName",itemNameLabel);
|
||||
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,invHeight*totalSpacing+itemSpacing},{windowSize.x-4,windowSize.y-108}),"",true,true};
|
||||
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,initialInvHeight*totalSpacing+itemSpacing},{windowSize.x-4,windowSize.y-108}),"",true,true};
|
||||
inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel);
|
||||
|
||||
return inventoryWindow;
|
||||
|
||||
Reference in New Issue
Block a user