From eae8239501768b33e27cbc5a0f89e020f48e7c3a Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 19 Dec 2023 18:46:59 -0600 Subject: [PATCH] Traveling Merchant Purchase Window and systems implemented. --- Crawler/BuyItemWindow.cpp | 42 +++++++++++++ Crawler/Crawler.cpp | 2 + Crawler/Crawler.vcxproj | 10 +++ Crawler/Crawler.vcxproj.filters | 24 +++++++ Crawler/InventoryWindow.cpp | 15 +++-- Crawler/Menu.cpp | 6 +- Crawler/MenuComponent.cpp | 14 ++++- Crawler/MenuComponent.h | 3 + Crawler/MenuItemButton.h | 5 +- Crawler/MenuItemItemButton.h | 5 +- Crawler/MenuLabel.h | 7 +-- Crawler/MerchantWindow.cpp | 25 +++++++- Crawler/MonsterAttribute.h | 1 + Crawler/Player.cpp | 11 +++- Crawler/Player.h | 5 +- Crawler/PlayerMoneyLabel.h | 62 +++++++++++++++++++ Crawler/RowItemDisplay.h | 2 +- Crawler/Version.h | 2 +- .../config/shops/Chapter 1 Merchants.txt | 14 ++--- 19 files changed, 225 insertions(+), 30 deletions(-) create mode 100644 Crawler/PlayerMoneyLabel.h diff --git a/Crawler/BuyItemWindow.cpp b/Crawler/BuyItemWindow.cpp index b109c315..46617dd7 100644 --- a/Crawler/BuyItemWindow.cpp +++ b/Crawler/BuyItemWindow.cpp @@ -39,10 +39,52 @@ All rights reserved. #include "Menu.h" #include "MenuLabel.h" +using A=Attribute; + void Menu::InitializeBuyItemWindow(){ Menu*buyItemWindow=CreateMenu(BUY_ITEM,CENTERED,{192,72}); + static auto GetQuantity = [&](){ + return std::stoi(Component(BUY_ITEM,"Amount to buy Amount Label")->GetLabel()); + }; + static auto UpdateMenu = [&](int32_t qty){ + qty=std::clamp(qty,1,99); + int pricePerItem=std::stoi(Component(BUY_ITEM,"Price per item Amount Label")->GetLabel()); + Component(BUY_ITEM,"Amount to buy Amount Label")->SetLabel(std::to_string(qty)); + Component(BUY_ITEM,"Total Price Amount Label")->SetLabel(std::to_string(qty*pricePerItem)); + Merchant&merchant=Merchant::GetCurrentTravelingMerchant(); + const std::string&item=Component(BUY_ITEM,"Item Purchase Header")->GetString(A::ITEM_NAME); + Component(BUY_ITEM,"Purchase Button")->SetGrayedOut(!merchant.CanPurchaseItem(item,GetQuantity())); + }; buyItemWindow->ADD("Item Purchase Header",MenuLabel)({{2,2},{188,12}},"Buying ",1,ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND|ComponentAttr::SHADOW|ComponentAttr::FIT_TO_LABEL)END; + buyItemWindow->ADD("Price Per Item Label",MenuLabel)({{4,18},{188,12}},"Price Per Item",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW)END; + buyItemWindow->ADD("Amount to Buy Label",MenuLabel)({{4,34},{188,12}},"Amount to Buy",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW)END; + buyItemWindow->ADD("Price Label",MenuLabel)({{4,50},{188,12}},"Total Cost",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW)END; + + buyItemWindow->ADD("Price per item Amount Label",MenuLabel)({{buyItemWindow->size.x/2+28,18},{72,12}},"0",1.0f,ComponentAttr::SHADOW|ComponentAttr::FIT_TO_LABEL)END; + buyItemWindow->ADD("Amount to buy Amount Label",MenuLabel)({{buyItemWindow->size.x/2+48,34},{32,12}},"0",1.0f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::FIT_TO_LABEL)END; + + buyItemWindow->ADD("Increase buy amount Button",MenuComponent)({{buyItemWindow->size.x/2+80+2,34},{12,12}},"+",[&](MenuFuncData data){ + UpdateMenu(GetQuantity()+1); + return true; + })END; + buyItemWindow->ADD("Decrease buy amount Button",MenuComponent)({{buyItemWindow->size.x/2+48-14,34},{12,12}},"-",[](MenuFuncData data){ + UpdateMenu(GetQuantity()-1); + return true; + })END; + + buyItemWindow->ADD("Total Price Amount Label",MenuLabel)({{buyItemWindow->size.x/2+28,50},{72,12}},"0",1.0f,ComponentAttr::SHADOW|ComponentAttr::FIT_TO_LABEL)END; + buyItemWindow->ADD("Purchase Button",MenuComponent)({{buyItemWindow->size.x/2+18,70},{64,12}},"Purchase",[&](MenuFuncData data){ + Merchant&merchant=Merchant::GetCurrentTravelingMerchant(); + const std::string&item=Component(BUY_ITEM,"Item Purchase Header")->GetString(A::ITEM_NAME); + merchant.PurchaseItem(item,GetQuantity()); + Menu::CloseMenu(); + return true; + })END; + buyItemWindow->ADD("Cancel Button",MenuComponent)({{buyItemWindow->size.x/2-82,70},{64,12}},"Cancel",[](MenuFuncData data){ + Menu::CloseMenu(); + return true; + })END; } \ No newline at end of file diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 6f69c247..46b291ca 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -1739,6 +1739,7 @@ void Crawler::ChangePlayerClass(Class cl){ Ability itemAbility2=player->useItem2; Ability itemAbility3=player->useItem3; uint32_t oldMoney=player->money; + std::setmoneyListeners=Player::moneyListeners; switch(cl){ case WARRIOR:{ player.reset(NEW Warrior(player.get())); @@ -1771,6 +1772,7 @@ void Crawler::ChangePlayerClass(Class cl){ GetPlayer()->SetItem2UseFunc(itemAbility2); GetPlayer()->SetItem3UseFunc(itemAbility3); camera.SetTarget(player->GetPos()); + Player::moneyListeners=moneyListeners; } void Crawler::InitializeClasses(){ diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 53a2ce67..89a0d560 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -342,6 +342,10 @@ + + + + @@ -568,6 +572,12 @@ + + + + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 3161ce03..1e5a7534 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -79,6 +79,9 @@ {8911e0bb-703c-4a2b-b3dd-259192956733} + + {8423ea80-23c9-48cb-a506-6b3bdfa8000e} + @@ -372,6 +375,9 @@ Header Files\Interface + + Header Files\Interface + @@ -698,6 +704,24 @@ Configurations\Items + + Configurations\Item Merchants + + + Configurations\Item Merchants + + + Configurations\Item Merchants + + + Configurations\Item Merchants + + + Configurations\Item Merchants + + + Configurations\Item Merchants + diff --git a/Crawler/InventoryWindow.cpp b/Crawler/InventoryWindow.cpp index 2896021d..c9dd404e 100644 --- a/Crawler/InventoryWindow.cpp +++ b/Crawler/InventoryWindow.cpp @@ -44,6 +44,7 @@ All rights reserved. #include "MenuItemButton.h" #include "MenuItemItemButton.h" #include "RowItemDisplay.h" +#include "PlayerMoneyLabel.h" INCLUDE_game INCLUDE_ITEM_CATEGORIES @@ -123,9 +124,13 @@ void Menu::InitializeInventoryWindow(){ 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; + #pragma region Money Display + 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; + auto moneyDisplay=inventoryWindow->ADD("Money Label",PlayerMoneyLabel)({moneyIconPos-vf2d{2+moneyTextSize.x,0},moneyTextSize},2,SHADOW|LEFT_ALIGN)END; + moneyDisplay->SetRightAlignment(true); + Player::AddMoneyListener(moneyDisplay); + #pragma endregion } \ No newline at end of file diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index e8c92638..381f0a7e 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -158,7 +158,7 @@ void Menu::HoverMenuSelect(Crawler*game){ } void Menu::MenuSelect(Crawler*game){ - if(selection==vi2d{-1,-1}||buttons[selection.y][selection.x]->disabled)return; + if(selection==vi2d{-1,-1}||(buttons[selection.y][selection.x]->disabled||buttons[selection.y][selection.x]->grayedOut))return; bool buttonStillValid=buttons[selection.y][selection.x]->onClick(MenuFuncData{*this,game,buttons[selection.y][selection.x],(ScrollableWindowComponent*)buttons[selection.y][selection.x]->parentComponent}); if(buttonStillValid){ if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){ @@ -200,7 +200,7 @@ void Menu::Update(Crawler*game){ for(auto&[key,value]:buttons){ int index=0; for(auto&button:value){ - if(!button->disabled){ + if(!button->disabled&&!button->grayedOut){ if(button->GetHoverState(game)){ button->hovered=true; itemHovered=true; @@ -449,7 +449,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ } } if(prevSelection!=selection){ - if(selection!=vi2d{-1,-1}&&buttons[selection.y][selection.x]->disabled){ + if(selection!=vi2d{-1,-1}&&(buttons[selection.y][selection.x]->disabled||buttons[selection.y][selection.x]->grayedOut)){ bool handled=false; if(!UsingMouseNavigation()){ //Let's transfer some information about our selection being off the screen. Our intention with keyboard controls is that the screen will scroll to the correct location instead. diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 5e24ff1f..1d7a9ded 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -102,7 +102,11 @@ void MenuComponent::OnEquipStatsUpdate(){} void MenuComponent::DrawDecal(ViewPort&window,bool focused){ if(background){ - window.FillRectDecal(rect.pos+V(A::DRAW_OFFSET),rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); + Pixel backCol=PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F); + if(grayedOut){ + backCol=DARK_GREY; + } + window.FillRectDecal(rect.pos+V(A::DRAW_OFFSET),rect.size,backCol); } if(selected&&selectionType==HIGHLIGHT){ window.FillRectDecal(rect.pos+V(A::DRAW_OFFSET),rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),util::lerp(0.75f,1.0f,hoverEffect/"ThemeGlobal.HighlightTime"_F))); @@ -240,4 +244,10 @@ void MenuComponent::SetHoverFunc(std::functionfunc){ void MenuComponent::SetMouseOutFunc(std::functionfunc){ runHoverFunctions=true; onMouseOut=func; -}; \ No newline at end of file +}; + +void MenuComponent::SetGrayedOut(bool grayedOut){ + this->grayedOut=grayedOut; +} + +void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){} \ No newline at end of file diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 61d6168e..6139c848 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -108,6 +108,7 @@ protected: 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. bool fitToLabel=false; //Will shrink text horizontally to fit the size of the label if the display text is too large. + bool grayedOut=false; //If turned on, a button will appear grayed out and unresponsive. vf2d labelScaling={1,1}; virtual void Update(Crawler*game); virtual void DrawDecal(ViewPort&window,bool focused); @@ -146,4 +147,6 @@ public: virtual void Cleanup(); virtual void SetHoverFunc(std::functionfunc); virtual void SetMouseOutFunc(std::functionfunc); + void SetGrayedOut(bool grayedOut); + virtual void OnPlayerMoneyUpdate(uint32_t newMoney); }; \ No newline at end of file diff --git a/Crawler/MenuItemButton.h b/Crawler/MenuItemButton.h index c9f8c468..cdea42b4 100644 --- a/Crawler/MenuItemButton.h +++ b/Crawler/MenuItemButton.h @@ -140,8 +140,9 @@ protected: vf2d quantityTextScale=rect.size/48.f; vf2d textSize=vf2d(game->GetTextSizeProp(quantityText))*quantityTextScale; vf2d drawPos=rect.pos+rect.size-textSize; - geom2d::rectboundingBox={drawPos,textSize}; - window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale,quantityTextScale.x); + if(itemQuantity!=INFINITE){ + window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale,quantityTextScale.x); + } } } inline MenuComponent*PickUpDraggableItem()override final{ diff --git a/Crawler/MenuItemItemButton.h b/Crawler/MenuItemItemButton.h index 08369959..3d882266 100644 --- a/Crawler/MenuItemItemButton.h +++ b/Crawler/MenuItemItemButton.h @@ -139,8 +139,9 @@ protected: vf2d quantityTextScale=rect.size/48.f; vf2d textSize=vf2d(game->GetTextSizeProp(quantityText))*quantityTextScale; vf2d drawPos=rect.pos+rect.size-textSize; - geom2d::rectboundingBox={drawPos,textSize}; - window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale,quantityTextScale.x); + if(itemRef.get().Amt()!=INFINITE){ + window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale,quantityTextScale.x); + } } } }; \ No newline at end of file diff --git a/Crawler/MenuLabel.h b/Crawler/MenuLabel.h index 49b53c2b..fe5c8714 100644 --- a/Crawler/MenuLabel.h +++ b/Crawler/MenuLabel.h @@ -45,9 +45,8 @@ All rights reserved. INCLUDE_game class MenuLabel:public MenuComponent{ -private: - float scale=1; protected: + float scale=1; bool shadow=false; bool centered=true; public: @@ -62,10 +61,10 @@ public: label=text; } protected: - virtual void inline Update(Crawler*game)override{ + inline virtual void Update(Crawler*game)override{ MenuComponent::Update(game); } - virtual void inline DrawDecal(ViewPort&window,bool focused)override{ + inline virtual void DrawDecal(ViewPort&window,bool focused)override{ MenuComponent::DrawDecal(window,focused); std::string adjustedText=label; if(!fitToLabel){ diff --git a/Crawler/MerchantWindow.cpp b/Crawler/MerchantWindow.cpp index 77ba137a..163ea31c 100644 --- a/Crawler/MerchantWindow.cpp +++ b/Crawler/MerchantWindow.cpp @@ -41,13 +41,15 @@ All rights reserved. #include "RowMerchantInventoryScrollableWindowComponent.h" #include "MenuItemItemButton.h" #include "MenuComponent.h" +#include "PlayerMoneyLabel.h" INCLUDE_game INCLUDE_ITEM_CATEGORIES INCLUDE_DATA +INCLUDE_GFX void Menu::InitializeMerchantWindow(){ - Menu*merchantWindow=CreateMenu(MERCHANT,CENTERED,game->GetScreenSize()-vi2d{24,24}); + Menu*merchantWindow=CreateMenu(MERCHANT,CENTERED,game->GetScreenSize()-vi2d{52,52}); static std::string lastInventoryTypeOpened=""; @@ -63,7 +65,12 @@ void Menu::InitializeMerchantWindow(){ [](MenuFuncData data){ RowItemDisplay*item=dynamic_cast(data.component); Component(BUY_ITEM,"Item Purchase Header")->S(A::ITEM_NAME)=item->GetItem().ActualName(); + Component(BUY_ITEM,"Price per item Amount Label")->SetLabel(std::to_string(item->GetItem().BuyValue())); + Component(BUY_ITEM,"Amount to buy Amount Label")->SetLabel("1"); + Component(BUY_ITEM,"Total Price Amount Label")->SetLabel(std::to_string(item->GetItem().BuyValue())); + Merchant&merchant=Merchant::GetCurrentTravelingMerchant(); Component(BUY_ITEM,"Item Purchase Header")->SetLabel("Buying "+item->GetItem().DisplayName()); + Component(BUY_ITEM,"Purchase Button")->SetGrayedOut(!merchant.CanPurchaseItem(item->GetItem().DisplayName(),1)); Menu::OpenMenu(BUY_ITEM); return true; }, @@ -89,4 +96,20 @@ void Menu::InitializeMerchantWindow(){ merchantWindow->ADD("Item Name Label",MenuLabel)({{226,84},{inventoryDescriptionWidth-6,12}},"",0.75f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW)END; merchantWindow->ADD("Item Description Label",MenuLabel)({{226,94},{inventoryDescriptionWidth-6,merchantWindow->size.y-44-66}},"",0.5f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW)END; #pragma endregion + + #pragma region Money Display + vf2d moneyIconPos={224+inventoryDescriptionWidth-24,28+merchantWindow->size.y-44+8}; + auto moneyIcon=merchantWindow->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; + auto moneyDisplay=merchantWindow->ADD("Money Label",PlayerMoneyLabel)({moneyIconPos-vf2d{2+moneyTextSize.x,0},moneyTextSize},2,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END; + moneyDisplay->SetRightAlignment(true); + Player::AddMoneyListener(moneyDisplay); + #pragma endregion + + merchantWindow->ADD("Leave Button",MenuComponent)({{merchantWindow->size.x/2-48,28+merchantWindow->size.y-44+6},{96,24}},"Leave",MenuType::ENUM_END, + [](MenuFuncData data){ + Menu::CloseMenu(); + return true; + },{2,2})END; } \ No newline at end of file diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index dd481b6b..0adaabd7 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -73,4 +73,5 @@ enum class Attribute{ CATEGORY_NAME, DRAW_OFFSET, ITEM_NAME, + ITEM_QUANTITY, }; \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 4a3b937a..4b6e6b14 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -72,6 +72,8 @@ InputGroup Player::KEY_ITEM3; ItemAttributable PlayerStats::equipStats; ItemAttributable PlayerStats::baseStats; +std::setPlayer::moneyListeners; + Player::Player() :lastReleasedMovementKey(DOWN),facingDirection(DOWN),state(State::NORMAL){ Initialize(); @@ -915,4 +917,11 @@ uint32_t Player::GetMoney()const{ }; void Player::SetMoney(uint32_t newMoney){ money=newMoney; -}; \ No newline at end of file + for(auto&component:moneyListeners){ + component->OnPlayerMoneyUpdate(newMoney); + } +}; +void Player::AddMoneyListener(MenuComponent*component){ + if(moneyListeners.count(component))ERR("WARNING! Trying to add a second copy of component "<GetName())); + moneyListeners.insert(component); +} \ No newline at end of file diff --git a/Crawler/Player.h b/Crawler/Player.h index 8f30d833..02f3c608 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -52,6 +52,7 @@ All rights reserved. #undef GetClassName struct DamageNumber; +class MenuComponent; struct CastInfo{ std::string name; @@ -252,7 +253,9 @@ public: void SetItem3UseFunc(Ability a); static InputGroup KEY_ABILITY1, KEY_ABILITY2, KEY_ABILITY3, KEY_ABILITY4, KEY_DEFENSIVE, KEY_ITEM1, KEY_ITEM2, KEY_ITEM3; - + static std::setmoneyListeners; + + static void AddMoneyListener(MenuComponent*component); uint32_t GetMoney()const; void SetMoney(uint32_t newMoney); }; diff --git a/Crawler/PlayerMoneyLabel.h b/Crawler/PlayerMoneyLabel.h new file mode 100644 index 00000000..f9ea3c32 --- /dev/null +++ b/Crawler/PlayerMoneyLabel.h @@ -0,0 +1,62 @@ +#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 "MenuLabel.h" +#include "Crawler.h" + +INCLUDE_game + +class PlayerMoneyLabel:public MenuLabel{ + bool rightAligned=false; + float anchorPointX=0; +public: + inline PlayerMoneyLabel(geom2d::rectrect,float scale=1,ComponentAttr attributes=ComponentAttr::NONE) + :MenuLabel(rect,std::to_string(game->GetPlayer()->GetMoney()),scale,attributes){} + + inline virtual void OnPlayerMoneyUpdate(uint32_t newMoney)final{ + SetLabel(std::to_string(newMoney)); + std::string moneyText=std::to_string(newMoney); + vf2d moneyTextSize=game->GetTextSizeProp(moneyText)*scale; + rect.pos.x=anchorPointX-moneyTextSize.x; + } + + inline void SetRightAlignment(bool rightAligned){ + this->rightAligned=rightAligned; + anchorPointX=rect.pos.x+rect.size.x; + } +}; \ No newline at end of file diff --git a/Crawler/RowItemDisplay.h b/Crawler/RowItemDisplay.h index 3396668d..b2273763 100644 --- a/Crawler/RowItemDisplay.h +++ b/Crawler/RowItemDisplay.h @@ -65,7 +65,7 @@ public: window.DrawShadowStringPropDecal(rect.pos+vf2d{4,4}+vf2d{iconSize.x,iconSize.y/2-4},itemName,WHITE,BLACK,scaledSize); - if(showQuantity){ + if(showQuantity&&itemRef.get().Amt()!=INFINITE){ std::string quantityText=std::format("x{}",itemRef.get().Amt()); float qtyTextScale=0.75f; vf2d qtyTextSize=vf2d(game->GetTextSizeProp(quantityText))*qtyTextScale; diff --git a/Crawler/Version.h b/Crawler/Version.h index 3d33888d..b9a24053 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 4220 +#define VERSION_BUILD 4251 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/shops/Chapter 1 Merchants.txt b/Crawler/assets/config/shops/Chapter 1 Merchants.txt index 0ff12f6c..1dcdcf43 100644 --- a/Crawler/assets/config/shops/Chapter 1 Merchants.txt +++ b/Crawler/assets/config/shops/Chapter 1 Merchants.txt @@ -6,28 +6,28 @@ Merchant { DisplayName = Merchant # Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply. - Item[1] = Minor Health Potion,5 - Item[2] = Minor Mana Potion,5 + Item[1] = Minor Health Potion + Item[2] = Minor Mana Potion } Chapter1_B { DisplayName = Merchant # Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply. - Item[1] = Minor Health Potion,5 + Item[1] = Minor Health Potion } Chapter1_C { DisplayName = Merchant # Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply. - Item[1] = Minor Mana Potion,5 + Item[1] = Minor Mana Potion } Chapter1_D { DisplayName = Merchant # Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply. - Item[1] = Minor Health Potion,5 - Item[2] = Minor Mana Potion,5 - Item[3] = Bandages,5 + Item[1] = Minor Health Potion + Item[2] = Minor Mana Potion + Item[3] = Bandages } } } \ No newline at end of file