Refactored window removing components for scrollable components.
This commit is contained in:
parent
a659bf7924
commit
b51d6f571a
@ -65,7 +65,14 @@ void Menu::InitializeCharacterMenuWindow(){
|
|||||||
MenuComponent*equipSelectionOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE);
|
MenuComponent*equipSelectionOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE);
|
||||||
ScrollableWindowComponent*equipmentList=NEW ScrollableWindowComponent(CHARACTER_MENU,{{123,36},{120,windowSize.y-37-24}});
|
ScrollableWindowComponent*equipmentList=NEW ScrollableWindowComponent(CHARACTER_MENU,{{123,36},{120,windowSize.y-37-24}});
|
||||||
MenuComponent*equipSelectionBottomOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36+(windowSize.y-37-24)},{120,24}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE);
|
MenuComponent*equipSelectionBottomOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36+(windowSize.y-37-24)},{120,24}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE);
|
||||||
MenuComponent*equipSelectionSelectButton=NEW MenuComponent(CHARACTER_MENU,{{123+12,36+(windowSize.y-37-24)+6},{96,12}},"Select",DO_NOTHING);
|
MenuComponent*equipSelectionSelectButton=NEW MenuComponent(CHARACTER_MENU,{{123+12,36+(windowSize.y-37-24)+6},{96,12}},"Select",[](MenuFuncData data){
|
||||||
|
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Outline")->Enable(false);
|
||||||
|
Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List")->Enable(false);
|
||||||
|
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Bottom Outline")->Enable(false);
|
||||||
|
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Select Button")->Enable(false);
|
||||||
|
Component<CharacterRotatingDisplay>(data.component->parentMenu,"Character Rotating Display")->Enable(true);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
equipSelectionOutline->Enable(false);
|
equipSelectionOutline->Enable(false);
|
||||||
equipmentList->Enable(false);
|
equipmentList->Enable(false);
|
||||||
@ -89,16 +96,43 @@ void Menu::InitializeCharacterMenuWindow(){
|
|||||||
}
|
}
|
||||||
const std::array<std::string,8>slotNames{"Helmet","Weapon","Armor","Gloves","Pants","Shoes","Ring 1","Ring 2"};
|
const std::array<std::string,8>slotNames{"Helmet","Weapon","Armor","Gloves","Pants","Shoes","Ring 1","Ring 2"};
|
||||||
EquipSlot slot=EquipSlot(equipSlot);
|
EquipSlot slot=EquipSlot(equipSlot);
|
||||||
|
|
||||||
MenuItemItemButton*equipmentSlot=NEW MenuItemItemButton(CHARACTER_MENU,{{x,y+36},{24,24}},Item::BLANK,MenuType::ENUM_END,
|
MenuItemItemButton*equipmentSlot=NEW MenuItemItemButton(CHARACTER_MENU,{{x,y+36},{24,24}},Item::BLANK,MenuType::ENUM_END,
|
||||||
[](MenuFuncData data){
|
[](MenuFuncData data){
|
||||||
|
EquipSlot slot=EquipSlot(data.component->I(Attribute::EQUIP_TYPE));
|
||||||
|
|
||||||
|
std::vector<Item>&equips=Inventory::get("Equipment");
|
||||||
|
std::vector<Item>&accessories=Inventory::get("Accessories");
|
||||||
|
std::vector<Item>availableEquipment;
|
||||||
|
std::copy_if(equips.begin(),equips.end(),std::back_inserter(availableEquipment),[&](Item&it){
|
||||||
|
return it.GetEquipSlot()&slot;
|
||||||
|
});
|
||||||
|
|
||||||
|
ScrollableWindowComponent*equipList=Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List");
|
||||||
|
equipList->RemoveAllComponents();
|
||||||
|
int counter=0;
|
||||||
|
for(Item&it:availableEquipment){
|
||||||
|
float xOffset=(counter%3)*26;
|
||||||
|
Item&itemInvRef=Inventory::GetItem(it.Name());
|
||||||
|
MenuItemItemButton*equip=NEW MenuItemItemButton(CHARACTER_MENU,{{2+xOffset,2},{24,24}},itemInvRef,MenuType::ENUM_END,[](MenuFuncData data){
|
||||||
|
MenuItemItemButton*comp=(MenuItemItemButton*)data.component;
|
||||||
|
Inventory::EquipItem(comp->GetItem(),EquipSlot(comp->I(Attribute::EQUIP_TYPE)));
|
||||||
|
return true;
|
||||||
|
},MenuType::ENUM_END,"","");
|
||||||
|
equip->I(Attribute::EQUIP_TYPE)=int(slot);
|
||||||
|
equipList->AddComponent(Menu::menus[CHARACTER_MENU],"Equip Item "+std::to_string(counter),equip);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Outline")->Enable(true);
|
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Outline")->Enable(true);
|
||||||
Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List")->Enable(true);
|
equipList->Enable(true);
|
||||||
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Bottom Outline")->Enable(true);
|
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Bottom Outline")->Enable(true);
|
||||||
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Select Button")->Enable(true);
|
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Select Button")->Enable(true);
|
||||||
Component<CharacterRotatingDisplay>(data.component->parentMenu,"Character Rotating Display")->Enable(false);
|
Component<CharacterRotatingDisplay>(data.component->parentMenu,"Character Rotating Display")->Enable(false);
|
||||||
return true;
|
return true;
|
||||||
},MenuType::ENUM_END,"","");
|
},MenuType::ENUM_END,"","");
|
||||||
PopupMenuLabel*equipmentLabel=NEW PopupMenuLabel(CHARACTER_MENU,{{labelX,labelY},{29,24}},slotNames[i],{0.5,1},ComponentAttr::SHADOW);
|
PopupMenuLabel*equipmentLabel=NEW PopupMenuLabel(CHARACTER_MENU,{{labelX,labelY},{29,24}},slotNames[i],{0.5,1},ComponentAttr::SHADOW);
|
||||||
|
equipmentSlot->I(Attribute::EQUIP_TYPE)=int(slot);
|
||||||
equipSlot<<=1;
|
equipSlot<<=1;
|
||||||
characterMenuWindow->AddComponent("Equip Slot "+slotNames[i],equipmentSlot);
|
characterMenuWindow->AddComponent("Equip Slot "+slotNames[i],equipmentSlot);
|
||||||
characterMenuWindow->AddComponent("Equip Label "+slotNames[i],equipmentLabel);
|
characterMenuWindow->AddComponent("Equip Label "+slotNames[i],equipmentLabel);
|
||||||
|
|||||||
@ -200,11 +200,6 @@ bool Crawler::OnUserCreate(){
|
|||||||
|
|
||||||
ValidateGameStatus(); //Checks to make sure everything has been initialized properly.
|
ValidateGameStatus(); //Checks to make sure everything has been initialized properly.
|
||||||
|
|
||||||
Item&it=Inventory::GetItem("Dummy Item 10");
|
|
||||||
|
|
||||||
Inventory::EquipItem(it,EquipSlot::RING1);
|
|
||||||
Inventory::EquipItem(it,EquipSlot::RING2);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -73,28 +73,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual inline void RemoveButton(MenuComponent*button){
|
|
||||||
if(button->selectable){
|
|
||||||
std::vector<MenuComponent*>&buttonList=Menu::menus[button->parentMenu]->buttons.at(int(button->GetPos().y));
|
|
||||||
std::vector<MenuComponent*>&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(int(button->GetPos().y));
|
|
||||||
size_t removedCount=0;
|
|
||||||
removedCount+=std::erase(buttonList,button);
|
|
||||||
removedCount+=std::erase(keyboardButtonList,button);
|
|
||||||
if(removedCount!=2){
|
|
||||||
std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!";
|
|
||||||
}
|
|
||||||
if(buttonList.size()==0){
|
|
||||||
if(!Menu::menus[button->parentMenu]->buttons.erase(int(button->GetPos().y))){
|
|
||||||
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(keyboardButtonList.size()==0){
|
|
||||||
if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(int(button->GetPos().y))){
|
|
||||||
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inline void RemoveEmptySlots(){
|
inline void RemoveEmptySlots(){
|
||||||
//Algorithm will iterate through all slots, finding blank slots. Each time a blank slot is found, all items will shift over by one, and then the last item will be removed. Repeat until all slots iterated through.
|
//Algorithm will iterate through all slots, finding blank slots. Each time a blank slot is found, all items will shift over by one, and then the last item will be removed. Repeat until all slots iterated through.
|
||||||
for(int i=0;i<components.size();i++){
|
for(int i=0;i<components.size();i++){
|
||||||
@ -110,11 +88,7 @@ protected:
|
|||||||
MenuComponent*lastButton=Menu::menus[components[components.size()-1]->parentMenu]->components.at(components[components.size()-1]->name);
|
MenuComponent*lastButton=Menu::menus[components[components.size()-1]->parentMenu]->components.at(components[components.size()-1]->name);
|
||||||
//Now we have to fix up the keyboard button list.
|
//Now we have to fix up the keyboard button list.
|
||||||
RemoveButton(lastButton);
|
RemoveButton(lastButton);
|
||||||
Menu::menus[components[components.size()-1]->parentMenu]->components.erase(components[components.size()-1]->name);
|
|
||||||
//Now delete the last slot.
|
|
||||||
components.erase(components.end()-1);
|
|
||||||
i--; //Subtract one from the index so we don't accidently skip slots.
|
i--; //Subtract one from the index so we don't accidently skip slots.
|
||||||
delete lastButton;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bounds=CalculateBounds(); //Recalculate the bounds as it's possible the width/height of the component has changed.
|
bounds=CalculateBounds(); //Recalculate the bounds as it's possible the width/height of the component has changed.
|
||||||
|
|||||||
@ -474,4 +474,10 @@ EquipSlot Inventory::GetSlotEquippedIn(Item&it){
|
|||||||
};
|
};
|
||||||
Item*Inventory::GetEquip(EquipSlot slot){
|
Item*Inventory::GetEquip(EquipSlot slot){
|
||||||
return Inventory::equipment[slot];
|
return Inventory::equipment[slot];
|
||||||
|
}
|
||||||
|
EquipSlot Item::GetEquipSlot(){
|
||||||
|
return it->Slot();
|
||||||
|
}
|
||||||
|
EquipSlot ItemInfo::Slot(){
|
||||||
|
return slot;
|
||||||
}
|
}
|
||||||
@ -109,6 +109,7 @@ public:
|
|||||||
std::string Name();
|
std::string Name();
|
||||||
std::string Description();
|
std::string Description();
|
||||||
ITCategory Category();
|
ITCategory Category();
|
||||||
|
EquipSlot GetEquipSlot();
|
||||||
Decal*Decal();
|
Decal*Decal();
|
||||||
ItemScript&OnUseAction();
|
ItemScript&OnUseAction();
|
||||||
const ItemSet&GetItemSet()const;
|
const ItemSet&GetItemSet()const;
|
||||||
@ -198,6 +199,7 @@ public:
|
|||||||
ItemScript&OnUseAction();
|
ItemScript&OnUseAction();
|
||||||
float CastTime();
|
float CastTime();
|
||||||
float CooldownTime();
|
float CooldownTime();
|
||||||
|
EquipSlot Slot();
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemOverlay{
|
class ItemOverlay{
|
||||||
|
|||||||
@ -61,6 +61,9 @@ public:
|
|||||||
draggable=false;
|
draggable=false;
|
||||||
valid=!itemRef.IsBlank();
|
valid=!itemRef.IsBlank();
|
||||||
}
|
}
|
||||||
|
inline Item&GetItem(){
|
||||||
|
return itemRef;
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual inline void Update(Crawler*game)override{
|
virtual inline void Update(Crawler*game)override{
|
||||||
MenuIconButton::Update(game);
|
MenuIconButton::Update(game);
|
||||||
|
|||||||
@ -69,4 +69,5 @@ enum class Attribute{
|
|||||||
CLASS_SELECTION, //A class name that represents what the menu's class is.
|
CLASS_SELECTION, //A class name that represents what the menu's class is.
|
||||||
LOADOUT_SLOT, //Which loadout slot we are selecting an item for.
|
LOADOUT_SLOT, //Which loadout slot we are selecting an item for.
|
||||||
ALLOW_DRAGGING, //Whether or not to allow inventory dragging.
|
ALLOW_DRAGGING, //Whether or not to allow inventory dragging.
|
||||||
|
EQUIP_TYPE,
|
||||||
};
|
};
|
||||||
@ -70,6 +70,34 @@ public:
|
|||||||
Menu::menus[parentMenu]->AddComponent(name+upButton->rect.pos.str()+"_"+upButton->rect.size.str(),upButton);
|
Menu::menus[parentMenu]->AddComponent(name+upButton->rect.pos.str()+"_"+upButton->rect.size.str(),upButton);
|
||||||
Menu::menus[parentMenu]->AddComponent(name+downButton->rect.pos.str()+"_"+downButton->rect.size.str(),downButton);
|
Menu::menus[parentMenu]->AddComponent(name+downButton->rect.pos.str()+"_"+downButton->rect.size.str(),downButton);
|
||||||
}
|
}
|
||||||
|
virtual inline void RemoveAllComponents(){
|
||||||
|
for(MenuComponent*item:components){
|
||||||
|
RemoveButton(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual inline void RemoveButton(MenuComponent*button){
|
||||||
|
std::vector<MenuComponent*>&buttonList=Menu::menus[button->parentMenu]->buttons.at(int(button->GetPos().y));
|
||||||
|
std::vector<MenuComponent*>&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(int(button->GetPos().y));
|
||||||
|
size_t removedCount=0;
|
||||||
|
removedCount+=std::erase(buttonList,button);
|
||||||
|
removedCount+=std::erase(keyboardButtonList,button);
|
||||||
|
if(removedCount!=2){
|
||||||
|
std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!";
|
||||||
|
}
|
||||||
|
if(buttonList.size()==0){
|
||||||
|
if(!Menu::menus[button->parentMenu]->buttons.erase(int(button->GetPos().y))){
|
||||||
|
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(keyboardButtonList.size()==0){
|
||||||
|
if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(int(button->GetPos().y))){
|
||||||
|
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Menu::menus[button->parentMenu]->components.erase(button->GetName());
|
||||||
|
components.erase(std::find(components.begin(),components.end(),button));
|
||||||
|
delete button;
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual inline void Update(Crawler*game)override{
|
virtual inline void Update(Crawler*game)override{
|
||||||
MenuComponent::Update(game);
|
MenuComponent::Update(game);
|
||||||
|
|||||||
@ -39,7 +39,7 @@ All rights reserved.
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 1
|
#define VERSION_PATCH 1
|
||||||
#define VERSION_BUILD 3441
|
#define VERSION_BUILD 3455
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user