From 54677e9263fc0a4002cf044d1c440bf3a276cb60 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 6 Dec 2023 20:52:48 -0600 Subject: [PATCH] Incorporated stat differences to equip menu display. --- Crawler/AttributableStat.cpp | 52 +++++++++++++++++++++++++++++++++ Crawler/AttributableStat.h | 4 +++ Crawler/CharacterMenuWindow.cpp | 33 +++++++++++++++------ Crawler/Crawler.cpp | 4 +-- Crawler/Crawler.vcxproj | 4 +++ Crawler/Crawler.vcxproj.filters | 3 ++ Crawler/Item.cpp | 6 ++-- Crawler/Item.h | 6 ++++ Crawler/MonsterAttribute.h | 2 +- Crawler/Player.cpp | 7 +++++ Crawler/Version.h | 2 +- Crawler/olcPGEX_TTF.h | 1 + Crawler/olcPixelGameEngine.h | 2 ++ 13 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 Crawler/AttributableStat.cpp diff --git a/Crawler/AttributableStat.cpp b/Crawler/AttributableStat.cpp new file mode 100644 index 00000000..fbbf8b2f --- /dev/null +++ b/Crawler/AttributableStat.cpp @@ -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);aattributes; @@ -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){ diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index 6b6ef8f7..2be0436b 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -133,23 +133,37 @@ void Menu::InitializeCharacterMenuWindow(){ },[&](MenuFuncData data){ MenuItemItemButton*button=(MenuItemItemButton*)data.component; Item&buttonItem=button->GetItem(); + std::vectorstatsBeforeEquip; + EquipSlot slot=EquipSlot(button->I(Attribute::EQUIP_TYPE)); for(ItemAttribute attribute:displayAttrs){ - int stat=buttonItem.GetStats().get(attribute); - if(stat>0){ - MenuLabel*statDisplayLabel=Component(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(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(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label"); - statDisplayLabel->I(Attribute::STAT_CHANGE)=stat; - } + MenuLabel*statDisplayLabel=Component(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); } diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index ebc0f906..b7421cb0 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -150,8 +150,6 @@ bool Crawler::OnUserCreate(){ InitializeLevels(); - player=std::make_unique(); - //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(); + InitializeGraphics(); InitializeClasses(); diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index eb36f1ca..6452f093 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -380,6 +380,10 @@ + + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 8e3edf6d..19c558de 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -482,6 +482,9 @@ Source Files\Interface + + Source Files + diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 84261c97..240bde0c 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -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); }; diff --git a/Crawler/Item.h b/Crawler/Item.h index cc4e567d..604a1b1c 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -73,6 +73,12 @@ public: } return *this; }; + inline Stats&operator+=(ItemAttributable&rhs){ + for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);aGetStats().A(a); + } + } } const int PlayerStats::GetStat(ItemAttribute stat){ return equipStats.A(stat); diff --git a/Crawler/Version.h b/Crawler/Version.h index 9a2edfbc..28b337e7 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -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 diff --git a/Crawler/olcPGEX_TTF.h b/Crawler/olcPGEX_TTF.h index 4e28ce75..b92deebb 100644 --- a/Crawler/olcPGEX_TTF.h +++ b/Crawler/olcPGEX_TTF.h @@ -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; diff --git a/Crawler/olcPixelGameEngine.h b/Crawler/olcPixelGameEngine.h index fdb164ed..5355a4fd 100644 --- a/Crawler/olcPixelGameEngine.h +++ b/Crawler/olcPixelGameEngine.h @@ -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);