Added row item display button components.

pull/28/head
sigonasr2 12 months ago
parent ac0f5c42aa
commit 3251053364
  1. 58
      Crawler/CharacterMenuWindow.cpp
  2. 7
      Crawler/Menu.h
  3. 2
      Crawler/MenuComponent.cpp
  4. 7
      Crawler/MenuComponent.h
  5. 4
      Crawler/MenuItemItemButton.h
  6. 37
      Crawler/RowItemDisplay.h
  7. 2
      Crawler/Version.h

@ -46,6 +46,7 @@ All rights reserved.
#include "EquipSlotButton.h"
#include "Item.h"
#include "ScrollableWindowComponent.h"
#include "RowItemDisplay.h"
INCLUDE_game
INCLUDE_GFX
@ -133,26 +134,37 @@ void Menu::InitializeCharacterMenuWindow(){
ScrollableWindowComponent*equipList=Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List");
equipList->RemoveAllComponents();
for(int counter=0;Item&it:availableEquipment){
float xOffset=(counter%3)*26;
Item&itemInvRef=Inventory::GetItem(it.Name());
auto equip=equipList->ADD("Equip Item "+std::to_string(counter),MenuItemItemButton)({{2+xOffset,2},{24,24}},itemInvRef,MenuType::ENUM_END,
auto equip=equipList->ADD("Equip Item "+std::to_string(counter),RowItemDisplay)({{2,2+counter*28.f},{120-12,28}},itemInvRef,
[](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);
RowItemDisplay*comp=dynamic_cast<RowItemDisplay*>(data.component);
if(comp!=nullptr){
Inventory::EquipItem(comp->GetItem(),EquipSlot(comp->I(Attribute::EQUIP_TYPE)));
for(MenuComponent*button:((ScrollableWindowComponent*)data.parentComponent)->GetComponents()){
RowItemDisplay*comp=dynamic_cast<RowItemDisplay*>(button);
if(comp!=nullptr){
comp->SetSelected(false);
}else{
ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!");
}
}
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());
}else{
ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!");
}
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;
},"Item Name","Item Description")END;
equip->SetHoverFunc(
[&](MenuFuncData data){
RowItemDisplay*button=dynamic_cast<RowItemDisplay*>(data.component);
if(button!=nullptr){
Item&buttonItem=button->GetItem();
std::vector<int>statsBeforeEquip;
EquipSlot slot=EquipSlot(button->I(Attribute::EQUIP_TYPE));
@ -171,16 +183,24 @@ void Menu::InitializeCharacterMenuWindow(){
if(*equippedItem!=Item::BLANK){
Inventory::EquipItem(*equippedItem,slot);
}
}else{
ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!");
}
return true;
},[](MenuFuncData data){
});
equip->SetMouseOutFunc(
[](MenuFuncData data){
for(int counter=0;ItemAttribute attribute:displayAttrs){
StatLabel*statDisplayLabel=Component<StatLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->SetStatChangeAmt(0);
counter++;
}
return true;
},"Item Name","Item Description")END;
});
equip->SetShowQuantity(false);
equip->SetSelectionType(SelectionType::NONE);
equip->I(Attribute::EQUIP_TYPE)=int(slot);
if(Inventory::GetEquip(slot)==&itemInvRef){
equip->SetSelected(true);

@ -231,7 +231,12 @@ private:
template<typename T>
T*Component(MenuType menu,std::string componentName){
return (T*)Menu::menus[menu]->components[componentName];
T*tmp=dynamic_cast<T*>(Menu::menus[menu]->components[componentName]);
if(tmp!=nullptr){
return tmp;
}else{
ERR("WARNING! Attempting to cast a button that isn't a "<<typeid(T).name()<<"!");
}
}
struct MenuFuncData{

@ -121,6 +121,7 @@ void MenuComponent::DrawDecal(ViewPort&window,bool focused){
case CROSSHAIR:drawutil::DrawCrosshairDecalViewPort(window,{rect.pos+V(A::DRAW_OFFSET),rect.size},0);break;
case INNER_BOX:window.DrawRectDecal(rect.pos+V(A::DRAW_OFFSET)+vi2d{1,1},rect.size-vi2d{2,2});break;
case HIGHLIGHT:break;//Not used.
case SelectionType::NONE:break;//Displays nothing.
default:ERR("Undefined selection type selected: "<<int(selectionType));
}
}
@ -205,7 +206,6 @@ void MenuComponent::OnMouseOut(){};
void MenuComponent::OnHover(){};
void MenuComponent::_OnMouseOut(){
if(name=="Equip Item 2"){std::cout<<std::boolalpha<<hoverState<<","<<hovered<<","<<runHoverFunctions<<std::endl;}
if(!hovered){
if(runHoverFunctions){
if(hoverState){

@ -57,9 +57,12 @@ enum class SelectionType{
CROSSHAIR,
HIGHLIGHT,
INNER_BOX,
NONE,
};
using enum SelectionType;
using SelectionType::CROSSHAIR;
using SelectionType::HIGHLIGHT;
using SelectionType::INNER_BOX;
class MenuComponent:public IAttributable{
friend class Menu;
@ -82,7 +85,6 @@ private:
void _DrawDecal(ViewPort&window,bool focused);
void _OnMouseOut();
void _OnHover();
bool selected=false;
SelectionType selectionType=CROSSHAIR;
protected:
int depth=0;
@ -99,6 +101,7 @@ protected:
bool hovered=false;
bool selectable=true;
bool selectableViaKeyboard=true;
bool selected=false;
bool disabled=false; //If set to true, this component will not be rendered or updated.
bool renderInMain=true; //If set to false, this component is the responsibility of some other windowing system and won't be rendered or updated via the main window loop.
bool valid=true; //If set to false, this would cause the component to be removed.

@ -107,11 +107,11 @@ protected:
labelNameText="";
labelDescriptionText="";
}
if(itemNameLabelName!=""&&labelNameText.length()>0){
if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText;
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true);
}
if(itemDescriptionLabelName!=""&&labelDescriptionText.length()>0){
if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText;
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true);
}

@ -47,22 +47,31 @@ class RowItemDisplay:public MenuComponent{
std::string itemNameLabelName;
std::string itemDescriptionLabelName;
CompactText compact=NON_COMPACT;
bool showQuantity=true;
public:
inline RowItemDisplay(geom2d::rect<float>rect,Item&itemRef,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,ButtonAttr attributes=ButtonAttr::NONE)
:MenuComponent(rect,"",onClick,attributes),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),itemRef(itemRef){
}
:MenuComponent(rect,"",onClick,attributes),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),itemRef(itemRef){}
virtual inline void DrawDecal(ViewPort&window,bool focused)final{
float scaleFactor=rect.size.y/24;
MenuComponent::DrawDecal(window,focused);
float scaleFactor=(rect.size.y-4)/24;
vf2d iconSize=vf2d{scaleFactor,scaleFactor}*24.f;
window.DrawDecal(rect.pos+vf2d{2,2},itemRef.Decal(),{scaleFactor,scaleFactor});
window.DrawRectDecal(rect.pos+vf2d{2,2},iconSize);
window.DrawShadowStringPropDecal(rect.pos+vf2d{4,4}+iconSize,itemRef.Name());
std::string itemName=itemRef.Name();
vf2d scaledSize={std::min(1.f,(rect.size.x-6-iconSize.x)/game->GetTextSizeProp(itemName).x),1};
std::string quantityText=std::format("x{}",itemRef.Amt());
vf2d qtyTextSize=game->GetTextSizeProp(quantityText);
window.DrawShadowStringPropDecal(rect.pos+rect.size-vf2d{2,2}+vf2d{-qtyTextSize.x,qtyTextSize.y},quantityText);
window.DrawShadowStringPropDecal(rect.pos+vf2d{4,4}+vf2d{iconSize.x,iconSize.y/2-4},itemName,WHITE,BLACK,scaledSize);
if(showQuantity){
std::string quantityText=std::format("x{}",itemRef.Amt());
vf2d qtyTextSize=game->GetTextSizeProp(quantityText);
window.DrawShadowStringPropDecal(rect.pos+rect.size-vf2d{2,2}+vf2d{-qtyTextSize.x,0},quantityText);
}
if(selected){
window.DrawShadowStringDecal(rect.pos+vf2d{2,2}+iconSize-vf2d{8,8},"E",GREEN,VERY_DARK_GREEN);
}
}
inline void SetCompactDescriptions(bool compact){
if(compact)this->compact=COMPACT;
@ -76,7 +85,14 @@ public:
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false);
}
}
virtual inline void OnHover()override{
virtual inline void SetShowQuantity(bool showQuantity){
this->showQuantity=showQuantity;
}
virtual inline Item&GetItem(){
return itemRef;
}
void UpdateLabel(){
if(itemRef.IsBlank())return;
std::string labelNameText;
std::string labelDescriptionText;
if(valid){
@ -95,4 +111,7 @@ public:
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true);
}
}
virtual inline void OnHover()override{
UpdateLabel();
}
};

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3990
#define VERSION_BUILD 4009
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save