Added money display to inventory GUI. Corrected inventory amounts displaying incorrectly in inventory menus (references to other items fixed). Added MenuIconButton appearance flags to disable outlines/backgrounds

pull/28/head
sigonasr2 11 months ago
parent f1aa872717
commit cb09825455
  1. 2
      Crawler/CharacterMenuWindow.cpp
  2. 7
      Crawler/InventoryWindow.cpp
  3. 10
      Crawler/Item.cpp
  4. 5
      Crawler/Item.h
  5. 10
      Crawler/MenuIconButton.h
  6. 12
      Crawler/MenuItemItemButton.h
  7. 2
      Crawler/Player.h
  8. 4
      Crawler/RowInventoryScrollableWindowComponent.h
  9. 10
      Crawler/RowItemDisplay.h
  10. 2
      Crawler/Version.h
  11. 2
      Crawler/assets/config/Player.txt
  12. 1
      Crawler/assets/config/gfx/gfx.txt
  13. BIN
      Crawler/assets/currency_coin.png
  14. BIN
      Crawler/assets/items/Pile of Coins.png
  15. BIN
      Crawler/assets/money.png

@ -165,7 +165,7 @@ void Menu::InitializeCharacterMenuWindow(){
[&](MenuFuncData data){
RowItemDisplay*button=dynamic_cast<RowItemDisplay*>(data.component);
if(button!=nullptr){
Item&buttonItem=button->GetItem();
const Item&buttonItem=button->GetItem();
std::vector<int>statsBeforeEquip;
EquipSlot slot=EquipSlot(button->I(Attribute::EQUIP_TYPE));
for(ItemAttribute attribute:displayAttrs){

@ -48,6 +48,7 @@ All rights reserved.
INCLUDE_game
INCLUDE_ITEM_CATEGORIES
INCLUDE_DATA
INCLUDE_GFX
using A=Attribute;
using enum ComponentAttr;
using ButtonAttr::UNSELECTABLE;
@ -120,4 +121,10 @@ void Menu::InitializeInventoryWindow(){
inventoryWindow->ADD("Item Name Label",MenuLabel)({{226,84},{inventoryDescriptionWidth-6,12}},"",0.75f,LEFT_ALIGN|SHADOW)END;
inventoryWindow->ADD("Item Description Label",MenuLabel)({{226,94},{inventoryDescriptionWidth-6,inventoryWindow->size.y-44-66}},"",0.5f,LEFT_ALIGN|SHADOW)END;
#pragma endregion
vf2d moneyIconPos={224+inventoryDescriptionWidth-24,28+inventoryWindow->size.y-44+8};
auto moneyIcon=inventoryWindow->ADD("Money Icon",MenuIconButton)({moneyIconPos,{24,24}},GFX["money.png"].Decal(),DO_NOTHING,IconButtonAttr::NOT_SELECTABLE|IconButtonAttr::NO_OUTLINE|IconButtonAttr::NO_BACKGROUND)END;
std::string moneyText=std::to_string(game->GetPlayer()->GetMoney());
vf2d moneyTextSize=game->GetTextSizeProp(moneyText)*2;
inventoryWindow->ADD("Money Label",MenuLabel)({moneyIconPos-vf2d{2+moneyTextSize.x,0},moneyTextSize},moneyText,2,SHADOW|LEFT_ALIGN)END;
}

@ -561,19 +561,19 @@ void ItemSet::AddSetBonus(std::string setName,int pieceCount,Stats&bonuses){
sets[setName].setBonusBreakpoints.push_back({pieceCount,bonuses});
}
void Inventory::EquipItem(Item&it,EquipSlot slot){
void Inventory::EquipItem(const Item&it,EquipSlot slot){
if(!(it.it->slot&slot))return;
EquipSlot equippedSlot=GetSlotEquippedIn(it);
if(equippedSlot!=EquipSlot::NONE)UnequipItem(equippedSlot);
if(GetEquip(slot)!=nullptr)UnequipItem(slot);
Inventory::equipment[slot]=&it;
Inventory::equipment[slot]=const_cast<Item*>(&it);
PlayerStats::RecalculateEquipStats();
};
void Inventory::UnequipItem(EquipSlot slot){
Inventory::equipment[slot]=&Item::BLANK;
PlayerStats::RecalculateEquipStats();
};
EquipSlot Inventory::GetSlotEquippedIn(Item&it){
EquipSlot Inventory::GetSlotEquippedIn(const Item&it){
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
EquipSlot slot=EquipSlot(i);
Item*equip=GetEquip(slot);
@ -713,4 +713,8 @@ const bool Item::CanBePurchased()const{
void Item::SetAmt(uint32_t newAmt){
amt=newAmt;
}
const Item&Inventory::GetInventorySlot(ITCategory itemCategory,size_t slot){
return GetItem(get(itemCategory)[slot].ActualName());
}

@ -182,10 +182,11 @@ public:
static bool RemoveItem(IT it,ITCategory inventory,uint32_t amt = 1);
static bool RemoveItem(IT it,uint32_t amt=1);
static std::vector<Item>&get(ITCategory itemCategory);
static const Item&GetInventorySlot(ITCategory itemCategory,size_t slot);
static void Clear(ITCategory itemCategory);
static void EquipItem(Item&it,EquipSlot slot);
static void EquipItem(const Item&it,EquipSlot slot);
static void UnequipItem(EquipSlot slot);
static EquipSlot GetSlotEquippedIn(Item&it);
static EquipSlot GetSlotEquippedIn(const Item&it);
static Item*GetEquip(EquipSlot slot);
static const std::map<ItemSet,int>GetEquippedItemSets();

@ -45,6 +45,9 @@ INCLUDE_game
enum class IconButtonAttr{
SELECTABLE=0b0,
NOT_SELECTABLE=int(ButtonAttr::UNSELECTABLE),
//Skipping 0b0010
NO_OUTLINE=0b0100, //Adds an outline around the component.
NO_BACKGROUND=0b1000, //Renders the background of the menu theme for this component.
};
class MenuIconButton:public MenuComponent{
@ -52,9 +55,12 @@ protected:
Decal*icon;
public:
inline MenuIconButton(geom2d::rect<float>rect,Decal*icon,MenuFunc onClick,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuComponent(rect,"",onClick,ButtonAttr(attributes)),icon(icon){}
:MenuIconButton(rect,icon,MenuType::ENUM_END,onClick,attributes){}
inline MenuIconButton(geom2d::rect<float>rect,Decal*icon,MenuType menuDest,MenuFunc onClick,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuComponent(rect,"",menuDest,onClick,ButtonAttr(attributes)),icon(icon){}
:MenuComponent(rect,"",menuDest,onClick,ButtonAttr(attributes)),icon(icon){
border=!(attributes&IconButtonAttr::NO_OUTLINE);
background=!(attributes&IconButtonAttr::NO_BACKGROUND);
}
protected:
virtual inline void Update(Crawler*game)override{
MenuComponent::Update(game);

@ -50,18 +50,18 @@ INCLUDE_ITEM_DATA
class MenuItemItemButton:public MenuIconButton{
private:
std::reference_wrapper<Item>itemRef;
std::reference_wrapper<const Item>itemRef;
std::string itemNameLabelName;
std::string itemDescriptionLabelName;
bool hideQty=false;
CompactText compact=COMPACT;
public:
inline MenuItemItemButton(geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
inline MenuItemItemButton(geom2d::rect<float>rect,const Item&itemRef,MenuType menuDest,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuIconButton(rect,(!itemRef.IsBlank())?const_cast<Decal*>(itemRef.Decal()):nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
draggable=false;
valid=!itemRef.IsBlank();
}
inline MenuItemItemButton(geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="",IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
inline MenuItemItemButton(geom2d::rect<float>rect,const Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="",IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuIconButton(rect,(!itemRef.IsBlank())?const_cast<Decal*>(itemRef.Decal()):nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
runHoverFunctions=true;
draggable=false;
@ -69,11 +69,11 @@ public:
SetHoverFunc(onHover);
SetMouseOutFunc(onMouseOut);
}
inline Item&GetItem(){
inline const Item&GetItem(){
return itemRef.get();
}
inline Item&SetItem(Item&newItem){
return itemRef=std::reference_wrapper<Item>(newItem);
inline const Item&SetItem(const Item&newItem){
return itemRef=std::reference_wrapper<const Item>(newItem);
}
inline void SetShowQuantity(bool show){
this->hideQty=!show;

@ -115,7 +115,7 @@ private:
Ability useItem1;
Ability useItem2;
Ability useItem3;
uint32_t money=9999;
uint32_t money="Player.Starting Money"_I;
protected:
const float ATTACK_COOLDOWN="Warrior.Auto Attack.Cooldown"_F;
const float MAGIC_ATTACK_COOLDOWN="Wizard.Auto Attack.Cooldown"_F;

@ -67,7 +67,7 @@ public:
vf2d buttonSize=options.size;
vf2d totalSpacing={options.padding+buttonSize.x,options.padding+buttonSize.y};
auto newItem=ADD("item_"+cat+"_"+std::to_string(itemIndex),RowItemDisplay)({totalSpacing*vf2d{float(x),float(y)},buttonSize},Inventory::get(cat)[itemIndex],inventoryButtonClickAction,itemNameLabelName,itemDescriptionLabelName,inventoryButtonsActive?ButtonAttr::NONE:ButtonAttr::UNSELECTABLE)END;
auto newItem=ADD("item_"+cat+"_"+std::to_string(itemIndex),RowItemDisplay)({totalSpacing*vf2d{float(x),float(y)},buttonSize},Inventory::GetInventorySlot(cat,itemIndex),inventoryButtonClickAction,itemNameLabelName,itemDescriptionLabelName,inventoryButtonsActive?ButtonAttr::NONE:ButtonAttr::UNSELECTABLE)END;
newItem->SetCompactDescriptions(compact==COMPACT);
newItem->SetHoverFunc(inventoryButtonHoverAction);
newItem->SetMouseOutFunc(inventoryButtonMouseOutAction);
@ -77,7 +77,7 @@ public:
for(int counter=0;MenuComponent*component:components){
RowItemDisplay*item=dynamic_cast<RowItemDisplay*>(component);
if(item!=nullptr){
item->SetItem(Inventory::get(cat)[counter]);
item->SetItem(Inventory::GetInventorySlot(cat,counter));
}else{
ERR("WARNING! Could not properly cast item to RowItemDisplay* type!");
}

@ -43,13 +43,13 @@ All rights reserved.
INCLUDE_game
class RowItemDisplay:public MenuComponent{
std::reference_wrapper<Item>itemRef;
std::reference_wrapper<const Item>itemRef;
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)
inline RowItemDisplay(geom2d::rect<float>rect,const Item&itemRef,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,ButtonAttr attributes=ButtonAttr::NONE)
:MenuComponent(rect,"",onClick,attributes),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),itemRef(itemRef){
if(itemRef.IsEquippable())SetShowQuantity(false);
}
@ -98,11 +98,11 @@ public:
virtual inline void SetShowQuantity(bool showQuantity){
this->showQuantity=showQuantity;
}
virtual inline Item&GetItem(){
virtual inline const Item&GetItem(){
return itemRef;
}
virtual inline void SetItem(Item&itemRef){
this->itemRef=std::reference_wrapper<Item>(itemRef);
virtual inline void SetItem(const Item&itemRef){
this->itemRef=std::reference_wrapper<const Item>(itemRef);
}
void UpdateLabel(){
if(itemRef.get().IsBlank())return;

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

@ -3,6 +3,8 @@ Player
BaseMana = 100
MoveSpd = 100
Starting Money = 100
# Amount of spd to increase/decrease vertically as you climb staircases
StaircaseClimbSpd = 45

@ -42,6 +42,7 @@ Images
GFX_FinishRingGreen = finishring_green.png
GFX_SqareSkillIcon = square_skill_overlay_icon.png
GFX_SqareSkillIconEmpty = square_skill_overlay_icon_empty.png
GFX_Money = money.png
# Ability Icons
GFX_Warrior_BattleCry_Icon = Ability Icons/battlecry.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 810 B

Loading…
Cancel
Save