Remove manually maintained switch statement in favor of defining what labels get modified on mouse-over for item buttons

pull/28/head
sigonasr2 1 year ago
parent 68c02adde6
commit bf84196cb0
  1. 2
      Crawler/InventoryScrollableWindowComponent.h
  2. 10
      Crawler/ItemLoadoutWindow.cpp
  3. 29
      Crawler/MenuItemButton.h
  4. 27
      Crawler/MenuItemItemButton.h
  5. 2
      Crawler/Version.h

@ -125,7 +125,7 @@ protected:
return true;
};
MenuItemButton*button=NEW MenuItemButton{parentMenu,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc};
MenuItemButton*button=NEW MenuItemButton{parentMenu,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc,parentMenu,"itemName","itemDescription"};
AddComponent(Menu::menus[parentMenu],"item"+std::to_string(itemIndex),button);
}else
if(components.size()>inv.size()){ //There are empty spots, so let's clean up.

@ -52,13 +52,13 @@ void Menu::InitializeItemLoadoutWindow(){
float buttonBorderPadding=64;
MenuItemItemButton*loadoutItem1=NEW MenuItemItemButton(ITEM_LOADOUT,{{64,120},{48,48}},game->GetLoadoutItem(0),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=0; return true;});
MenuItemItemButton*loadoutItem2=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth/2-24,120},{48,48}},game->GetLoadoutItem(1),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=1;return true;});
MenuItemItemButton*loadoutItem3=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth-48-64,120},{48,48}},game->GetLoadoutItem(2),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=2;return true;});
MenuItemItemButton*loadoutItem1=NEW MenuItemItemButton(ITEM_LOADOUT,{{64,96},{48,48}},game->GetLoadoutItem(0),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=0; return true;},ITEM_LOADOUT,"Item Name Label","Item Description");
MenuItemItemButton*loadoutItem2=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth/2-24,96},{48,48}},game->GetLoadoutItem(1),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=1;return true;},ITEM_LOADOUT,"Item Name Label","Item Description");
MenuItemItemButton*loadoutItem3=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth-48-64,96},{48,48}},game->GetLoadoutItem(2),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=2;return true;},ITEM_LOADOUT,"Item Name Label","Item Description");
//TODO: Make these two do something.
MenuLabel*itemNameLabel=NEW MenuLabel(ITEM_LOADOUT,{{0,182},{itemLoadoutWindowWidth,12}},"",1,ComponentAttr::SHADOW);
MenuLabel*itemDescription=NEW MenuLabel(ITEM_LOADOUT,{{0,194},{itemLoadoutWindowWidth,24}},"",1,ComponentAttr::SHADOW);
MenuLabel*itemNameLabel=NEW MenuLabel(ITEM_LOADOUT,{{0,158},{itemLoadoutWindowWidth,12}},"",1,ComponentAttr::SHADOW);
MenuLabel*itemDescription=NEW MenuLabel(ITEM_LOADOUT,{{0,170},{itemLoadoutWindowWidth,24}},"",1,ComponentAttr::SHADOW);
itemLoadoutWindow->AddComponent("Loadout Item 1",loadoutItem1);
itemLoadoutWindow->AddComponent("Loadout Item 2",loadoutItem2);

@ -47,10 +47,13 @@ class MenuItemButton:public MenuIconButton{
private:
std::vector<IT>&invRef;
int inventoryIndex=0;
MenuType itemDescriptionMenu;
std::string itemNameLabelName;
std::string itemDescriptionLabelName;
public:
int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected.
inline MenuItemButton(MenuType parent,geom2d::rect<float>rect,std::vector<IT>&invRef,int invIndex,MenuFunc onClick)
:MenuIconButton(parent,rect,invRef.size()>invIndex?ITEM_DATA.at(invRef[invIndex]).Decal():nullptr,onClick),invRef(invRef),inventoryIndex(invIndex){
inline MenuItemButton(MenuType parent,geom2d::rect<float>rect,std::vector<IT>&invRef,int invIndex,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName)
:MenuIconButton(parent,rect,invRef.size()>invIndex?ITEM_DATA.at(invRef[invIndex]).Decal():nullptr,onClick),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
draggable=false;
valid=invRef.size()>invIndex;
}
@ -69,26 +72,14 @@ protected:
if(valid){
icon=ITEM_DATA.at(invRef[inventoryIndex]).Decal();
if(hovered){
switch(parentMenu){
case INVENTORY:{
//There should be an itemName label to modify.
Component<MenuLabel>(INVENTORY,"itemName")->label=ITEM_DATA.at(invRef[inventoryIndex]).Name();
//There should be an itemDescription label to modify.
Component<MenuLabel>(INVENTORY,"itemDescription")->label=ITEM_DATA.at(invRef[inventoryIndex]).Description();
}break;
}
Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label=ITEM_DATA.at(invRef[inventoryIndex]).Name();
Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label=ITEM_DATA.at(invRef[inventoryIndex]).Description();
}
}else{
icon=nullptr;
if(hovered){
switch(parentMenu){
case INVENTORY:{
//There should be an itemName label to modify.
Component<MenuLabel>(INVENTORY,"itemName")->label="";
//There should be an itemDescription label to modify.
Component<MenuLabel>(INVENTORY,"itemDescription")->label="";
}break;
}
Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label="";
Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label="";
}
}
}
@ -111,7 +102,7 @@ protected:
}
inline MenuComponent*PickUpDraggableItem()override final{
if(valid){
MenuItemButton*pickUp=NEW MenuItemButton(parentMenu,rect,invRef,inventoryIndex,onClick);
MenuItemButton*pickUp=NEW MenuItemButton(parentMenu,rect,invRef,inventoryIndex,onClick,itemDescriptionMenu,itemNameLabelName,itemDescriptionLabelName);
valid=false;
return pickUp;
}else{

@ -46,9 +46,12 @@ INCLUDE_ITEM_DATA
class MenuItemItemButton:public MenuIconButton{
private:
Item&itemRef;
MenuType itemDescriptionMenu;
std::string itemNameLabelName;
std::string itemDescriptionLabelName;
public:
inline MenuItemItemButton(MenuType parent,geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick)
:MenuIconButton(parent,rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick),itemRef(itemRef){
inline MenuItemItemButton(MenuType parent,geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName)
:MenuIconButton(parent,rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick),itemRef(itemRef),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
draggable=false;
valid=!itemRef.IsBlank();
}
@ -59,26 +62,14 @@ protected:
if(valid){
icon=itemRef.Decal();
if(hovered){
switch(parentMenu){
case INVENTORY:{
//There should be an itemName label to modify.
Component<MenuLabel>(ITEM_LOADOUT,"Item Name Label")->label=itemRef.Name();
//There should be an itemDescription label to modify.
Component<MenuLabel>(ITEM_LOADOUT,"Item Description")->label=itemRef.Description();
}break;
}
Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label=itemRef.Name();
Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label=itemRef.Description();
}
}else{
icon=nullptr;
if(hovered){
switch(parentMenu){
case INVENTORY:{
//There should be an itemName label to modify.
Component<MenuLabel>(ITEM_LOADOUT,"Item Name Label")->label="";
//There should be an itemDescription label to modify.
Component<MenuLabel>(ITEM_LOADOUT,"Item Description")->label="";
}break;
}
Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label="";
Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label="";
}
}
}

@ -33,7 +33,7 @@ SUCH DAMAGE.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 2856
#define VERSION_BUILD 2860
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save