Equip Window is now functional.

This commit is contained in:
2023-12-06 22:47:09 -06:00
parent 54677e9263
commit 88a239cd91
16 changed files with 272 additions and 53 deletions
+53 -40
View File
@@ -37,13 +37,14 @@ All rights reserved.
#pragma endregion
#include "Menu.h"
#include "MenuComponent.h"
#include "MenuLabel.h"
#include "PopupMenuLabel.h"
#include "StatLabel.h"
#include "CharacterRotatingDisplay.h"
#include "Crawler.h"
#include "ClassInfo.h"
#include "MenuItemItemButton.h"
#include "EquipSlotButton.h"
#include "Item.h"
#include "PopupMenuLabel.h"
#include "ScrollableWindowComponent.h"
INCLUDE_game
@@ -62,6 +63,16 @@ void Menu::InitializeCharacterMenuWindow(){
characterMenuWindow->AddComponent("Equip Slot Outline",equipSlotOutline);
characterMenuWindow->AddComponent("Character Rotating Display",charDisplay);
const static std::array<ItemAttribute,7>displayAttrs{
ItemAttribute::health,
ItemAttribute::attack,
ItemAttribute::defense,
ItemAttribute::moveSpdPct,
ItemAttribute::cdrPct,
ItemAttribute::critPct,
ItemAttribute::critDmgPct,
};
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}});
MenuComponent*equipSelectionBottomOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36+(windowSize.y-37-24)},{120,24}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE);
@@ -71,6 +82,10 @@ void Menu::InitializeCharacterMenuWindow(){
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);
for(int counter=0;ItemAttribute attribute:displayAttrs){
StatLabel*statDisplayLabel=Component<StatLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->SetStatChangeAmt(0);
}
return true;
});
@@ -84,14 +99,14 @@ void Menu::InitializeCharacterMenuWindow(){
characterMenuWindow->AddComponent("Equip Selection Bottom Outline",equipSelectionBottomOutline);
characterMenuWindow->AddComponent("Equip Selection Select Button",equipSelectionSelectButton);
const static std::array<ItemAttribute,7>displayAttrs{
ItemAttribute::health,
ItemAttribute::attack,
ItemAttribute::defense,
ItemAttribute::moveSpdPct,
ItemAttribute::cdrPct,
ItemAttribute::critPct,
ItemAttribute::critDmgPct,
const static auto GetLabelText=[](ItemAttribute attribute){
AttributeData data=ItemAttributable::GetDisplayInfo(attribute);
std::string attrStr=data.name+":\n ";
attrStr+=std::to_string(game->GetPlayer()->GetStat(attribute));
if(data.displayAsPercent){
attrStr+="%";
}
return attrStr;
};
int equipSlot=1;
@@ -104,10 +119,10 @@ void Menu::InitializeCharacterMenuWindow(){
y-=8;
labelY-=8;
}
const std::array<std::string,8>slotNames{"Helmet","Weapon","Armor","Gloves","Pants","Shoes","Ring 1","Ring 2"};
const static std::array<std::string,8>slotNames{"Helmet","Weapon","Armor","Gloves","Pants","Shoes","Ring 1","Ring 2"};
EquipSlot slot=EquipSlot(equipSlot);
MenuItemItemButton*equipmentSlot=NEW MenuItemItemButton(CHARACTER_MENU,{{x,y+36},{24,24}},Item::BLANK,MenuType::ENUM_END,
EquipSlotButton*equipmentSlot=NEW EquipSlotButton(CHARACTER_MENU,{{x,y+36},{24,24}},slot,MenuType::ENUM_END,
[&](MenuFuncData data){
EquipSlot slot=EquipSlot(data.component->I(Attribute::EQUIP_TYPE));
@@ -129,6 +144,17 @@ void Menu::InitializeCharacterMenuWindow(){
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)));
for(MenuComponent*button:((ScrollableWindowComponent*)data.parentComponent)->GetComponents()){
MenuItemItemButton*comp=(MenuItemItemButton*)button;
comp->SetSelected(false);
}
comp->SetSelected(true);
for(int counter=0;ItemAttribute attribute:displayAttrs){
StatLabel*statDisplayLabel=Component<StatLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->SetStatChangeAmt(0);
}
MenuItemItemButton*equipButton=Component<MenuItemItemButton>(CHARACTER_MENU,"Equip Slot "+slotNames[data.parentComponent->I(A::INDEXED_THEME)]);
equipButton->SetItem(comp->GetItem());
return true;
},[&](MenuFuncData data){
MenuItemItemButton*button=(MenuItemItemButton*)data.component;
@@ -141,16 +167,9 @@ void Menu::InitializeCharacterMenuWindow(){
Item*equippedItem=Inventory::GetEquip(slot);
Inventory::EquipItem(buttonItem,slot);
for(int counter=0;ItemAttribute attribute:displayAttrs){
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
StatLabel*statDisplayLabel=Component<StatLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
int statChangeAmt=game->GetPlayer()->GetStat(attribute)-statsBeforeEquip[counter];
std::string baseLabel=statDisplayLabel->S(Attribute::BASE_TEXT);
if(statChangeAmt>0){
baseLabel+=Color::Green+"(+"+std::to_string(statChangeAmt)+")";
}else
if(statChangeAmt<0){
baseLabel+=Color::Red+"("+std::to_string(statChangeAmt)+")";
}
statDisplayLabel->SetLabel(baseLabel);
statDisplayLabel->SetStatChangeAmt(statChangeAmt);
counter++;
}
Inventory::UnequipItem(slot);
@@ -158,32 +177,30 @@ void Menu::InitializeCharacterMenuWindow(){
Inventory::EquipItem(*equippedItem,slot);
}
return true;
},[&](MenuFuncData data){
MenuItemItemButton*button=(MenuItemItemButton*)data.component;
Item&buttonItem=button->GetItem();
for(ItemAttribute attribute:displayAttrs){
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->SetLabel(statDisplayLabel->S(Attribute::BASE_TEXT));
}
return true;
});
},DO_NOTHING);
equip->I(Attribute::EQUIP_TYPE)=int(slot);
if(Inventory::GetEquip(slot)==&itemInvRef){
equip->SetSelected(true);
}
equipList->AddComponent(Menu::menus[CHARACTER_MENU],"Equip Item "+std::to_string(counter),equip);
counter++;
}
equipList->I(Attribute::INDEXED_THEME)=data.component->I(Attribute::INDEXED_THEME);
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Outline")->Enable(true);
equipList->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<CharacterRotatingDisplay>(data.component->parentMenu,"Character Rotating Display")->Enable(false);
return true;
},MenuType::ENUM_END,"","");
},DO_NOTHING,DO_NOTHING);
PopupMenuLabel*equipmentLabel=NEW PopupMenuLabel(CHARACTER_MENU,{{labelX,labelY},{29,24}},slotNames[i],{0.5,1},ComponentAttr::SHADOW);
equipmentSlot->I(Attribute::EQUIP_TYPE)=int(slot);
equipmentSlot->I(Attribute::INDEXED_THEME)=i;
equipmentSlot->SetShowQuantity(false);
equipSlot<<=1;
characterMenuWindow->AddComponent("Equip Slot "+slotNames[i],equipmentSlot);
characterMenuWindow->AddComponent("Equip Label "+slotNames[i],equipmentLabel);
Menu::AddEquipStatListener(equipmentSlot);
}
MenuComponent*statDisplayOutline=NEW MenuComponent(CHARACTER_MENU,{{245,36},{62,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE);
@@ -192,15 +209,11 @@ void Menu::InitializeCharacterMenuWindow(){
int yOffset=0;
for(ItemAttribute attribute:displayAttrs){
AttributeData data=ItemAttributable::GetDisplayInfo(attribute);
std::string attrStr=data.name+":\n ";
attrStr+=std::to_string(game->GetPlayer()->GetStat(attribute));
if(data.displayAsPercent){
attrStr+="%";
}
MenuLabel*attrLabel=NEW MenuLabel(CHARACTER_MENU,{{245,36+2+float(yOffset)},{62,18}},attrStr,1,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN);
attrLabel->S(Attribute::BASE_TEXT)=attrStr;
std::string attrStr=GetLabelText(attribute);
StatLabel*attrLabel=NEW StatLabel(CHARACTER_MENU,{{245,36+2+float(yOffset)},{62,18}},attribute,1,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN);
yOffset+=20;
AttributeData data=ItemAttributable::GetDisplayInfo(attribute);
characterMenuWindow->AddComponent("Attribute "+data.name+" Label",attrLabel);
Menu::AddEquipStatListener(attrLabel);
}
}