Incorporated stat differences to equip menu display.

pull/28/head
sigonasr2 12 months ago
parent 5eec1a21c5
commit 54677e9263
  1. 52
      Crawler/AttributableStat.cpp
  2. 4
      Crawler/AttributableStat.h
  3. 33
      Crawler/CharacterMenuWindow.cpp
  4. 4
      Crawler/Crawler.cpp
  5. 4
      Crawler/Crawler.vcxproj
  6. 3
      Crawler/Crawler.vcxproj.filters
  7. 6
      Crawler/Item.cpp
  8. 6
      Crawler/Item.h
  9. 2
      Crawler/MonsterAttribute.h
  10. 7
      Crawler/Player.cpp
  11. 2
      Crawler/Version.h
  12. 1
      Crawler/olcPGEX_TTF.h
  13. 2
      Crawler/olcPixelGameEngine.h

@ -0,0 +1,52 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2018 - 2022 OneLoneCoder.com
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "Item.h"
ItemAttributable&ItemAttributable::operator+=(Stats&rhs){
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
A(a)+=rhs.get_readOnly(a);
}
return *this;
};
ItemAttributable&ItemAttributable::operator+=(ItemAttributable&rhs){
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
A(a)+=rhs.get_readOnly(a);
}
return *this;
};

@ -76,6 +76,8 @@ enum class ItemAttribute{
/*////////////////////////////////////////////*/
};
class Stats;
class ItemAttributable{
friend class ItemInfo;
std::map<ItemAttribute,int>attributes;
@ -96,6 +98,8 @@ private:
{ItemAttribute::attackPct,{"Attack %",DisplayType::DISPLAY_AS_PERCENT}}, //Percentage of damage increased by.
};
public:
ItemAttributable&operator+=(ItemAttributable&rhs);
ItemAttributable&operator+=(Stats&rhs);
//Returns a copy of all the attributes to be passed to a new instance easily / to sync values between both.
inline void copyTo(ItemAttributable&target){

@ -133,23 +133,37 @@ void Menu::InitializeCharacterMenuWindow(){
},[&](MenuFuncData data){
MenuItemItemButton*button=(MenuItemItemButton*)data.component;
Item&buttonItem=button->GetItem();
std::vector<int>statsBeforeEquip;
EquipSlot slot=EquipSlot(button->I(Attribute::EQUIP_TYPE));
for(ItemAttribute attribute:displayAttrs){
int stat=buttonItem.GetStats().get(attribute);
if(stat>0){
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->I(Attribute::STAT_CHANGE)=stat;
statsBeforeEquip.push_back(game->GetPlayer()->GetStat(attribute));
}
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");
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);
counter++;
}
Inventory::UnequipItem(slot);
if(*equippedItem!=Item::BLANK){
Inventory::EquipItem(*equippedItem,slot);
}
return true;
},[&](MenuFuncData data){
MenuItemItemButton*button=(MenuItemItemButton*)data.component;
Item&buttonItem=button->GetItem();
for(ItemAttribute attribute:displayAttrs){
int stat=buttonItem.GetStats().get(attribute);
if(stat>0){
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->I(Attribute::STAT_CHANGE)=stat;
}
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->SetLabel(statDisplayLabel->S(Attribute::BASE_TEXT));
}
return true;
});
@ -185,6 +199,7 @@ void Menu::InitializeCharacterMenuWindow(){
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;
yOffset+=20;
characterMenuWindow->AddComponent("Attribute "+data.name+" Label",attrLabel);
}

@ -150,8 +150,6 @@ bool Crawler::OnUserCreate(){
InitializeLevels();
player=std::make_unique<Warrior>();
//Initialize Camera.
camera=Camera2D{WINDOW_SIZE};
camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow);
@ -161,6 +159,8 @@ bool Crawler::OnUserCreate(){
ItemInfo::InitializeItems();
player=std::make_unique<Warrior>();
InitializeGraphics();
InitializeClasses();

@ -380,6 +380,10 @@
<ClCompile Include="Ability.cpp" />
<ClCompile Include="Animation.cpp" />
<ClCompile Include="Arrow.cpp" />
<ClCompile Include="AttributableStat.cpp">
<SubType>
</SubType>
</ClCompile>
<ClCompile Include="Bullet.cpp" />
<ClCompile Include="CharacterInfoWindow.cpp" />
<ClCompile Include="CharacterMenuWindow.cpp">

@ -482,6 +482,9 @@
<ClCompile Include="CharacterMenuWindow.cpp">
<Filter>Source Files\Interface</Filter>
</ClCompile>
<ClCompile Include="AttributableStat.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />

@ -61,7 +61,7 @@ ItemInfo::ItemInfo()
void ItemInfo::InitializeItems(){
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
Inventory::equipment[EquipSlot(i)]=nullptr;
Inventory::equipment[EquipSlot(i)]=&Item::BLANK;
}
nameToEquipSlot["Helmet"]=EquipSlot::HELMET;
@ -503,7 +503,8 @@ void Inventory::EquipItem(Item&it,EquipSlot slot){
PlayerStats::RecalculateEquipStats();
};
void Inventory::UnequipItem(EquipSlot slot){
Inventory::equipment[slot]=nullptr;
Inventory::equipment[slot]=&Item::BLANK;
PlayerStats::RecalculateEquipStats();
};
EquipSlot Inventory::GetSlotEquippedIn(Item&it){
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
@ -556,6 +557,7 @@ Stats ItemInfo::GetStats(int enhancementLevel){
}
Stats Item::GetStats()const{
if(it==nullptr)return{};
return it->GetStats(enhancementLevel);
};

@ -73,6 +73,12 @@ public:
}
return *this;
};
inline Stats&operator+=(ItemAttributable&rhs){
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
A(a)+=rhs.get_readOnly(a);
}
return *this;
};
};
struct EnhancementInfo{

@ -70,5 +70,5 @@ enum class Attribute{
LOADOUT_SLOT, //Which loadout slot we are selecting an item for.
ALLOW_DRAGGING, //Whether or not to allow inventory dragging.
EQUIP_TYPE,
STAT_CHANGE,
BASE_TEXT,
};

@ -866,6 +866,13 @@ const int Player::GetBaseStat(ItemAttribute a)const{
void PlayerStats::RecalculateEquipStats(){
baseStats.copyTo(equipStats);
for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){
EquipSlot slot=EquipSlot(i);
Item*equip=Inventory::GetEquip(slot);
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
equipStats.get(a)+=equip->GetStats().A(a);
}
}
}
const int PlayerStats::GetStat(ItemAttribute stat){
return equipStats.A(stat);

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

@ -194,6 +194,7 @@ namespace olc {
for (size_t i = 0; i < string.size(); i++) {
char32_t chr = string[i];
if(chr=='\r')continue;
else if(chr<0)continue;
int prevmaxX=maxX;

@ -3607,6 +3607,7 @@ namespace olc
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n') { pos.y++; pos.x = 0; }
else if (c == '\t') { pos.x += nTabSizeInSpaces; }
else if(c<0)continue;
else pos.x++;
size.x = std::max(size.x, pos.x);
size.y = std::max(size.y, pos.y);
@ -3684,6 +3685,7 @@ namespace olc
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n') { pos.y += 1; pos.x = 0; }
else if (c == '\t') { pos.x += nTabSizeInSpaces * 8; }
else if(c<0)continue;
else pos.x += vFontSpacing[c - 32].y;
size.x = std::max(size.x, pos.x);
size.y = std::max(size.y, pos.y);

Loading…
Cancel
Save