diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index fd33c472..3d284d2f 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -2489,14 +2489,14 @@ void Crawler::UpdateDiscordStatus(std::string levelName,std::string className){ if(Discord){ ::discord::Activity newActivity{}; newActivity.SetDetails(levelName.c_str()); - newActivity.SetState(("Class: "+className).c_str()); + newActivity.SetState(std::format("Level {} {}",player->Level(),className).c_str()); discord::ActivityTimestamps×tamps=newActivity.GetTimestamps(); timestamps.SetStart(gameStarted); newActivity.SetType(discord::ActivityType::Playing); discord::ActivityAssets&assets=newActivity.GetAssets(); assets.SetLargeImage("heart_512"); assets.SetLargeText(game->sAppName.c_str()); - assets.SetSmallText(className.c_str()); + assets.SetSmallText(std::format("Level {} {}",player->Level(),className).c_str()); if(levelName!="Main Menu"){ std::for_each(className.begin(),className.end(),[](char&c){c=std::tolower(c);}); diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index 8e8caf01..1d31dfaf 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -70,7 +70,7 @@ public: static InputGroup KEY_DOWN; static InputGroup KEY_MENU; static float SIZE_CHANGE_SPEED; - float levelTime; + double levelTime; Camera2D camera; std::mapMAP_DATA; private: diff --git a/Crawler/InventoryWindow.cpp b/Crawler/InventoryWindow.cpp index 48031b2b..2fac300c 100644 --- a/Crawler/InventoryWindow.cpp +++ b/Crawler/InventoryWindow.cpp @@ -56,8 +56,6 @@ using ButtonAttr::UNSELECTABLE; using ButtonAttr::UNSELECTABLE_VIA_KEYBOARD; void Menu::InitializeInventoryWindow(){ - static std::string lastInventoryTypeOpened=""; - Menu*inventoryWindow=CreateMenu(INVENTORY,CENTERED,game->GetScreenSize()-vi2d{52,52}); inventoryWindow->ADD("Inventory Label",MenuLabel)({{0,0},{inventoryWindow->size.x-1,24}},"Inventory",2,SHADOW|OUTLINE|BACKGROUND)END; @@ -80,11 +78,11 @@ void Menu::InitializeInventoryWindow(){ auto button=inventoryWindow->ADD(category+" Inventory Tab",MenuComponent)({{2,30+yOffset},{68,16}},category,MenuType::ENUM_END, [&](MenuFuncData data){ //Close the old inventory window and show the proper one. - Component(data.menu.GetType(),"Inventory Display - "+lastInventoryTypeOpened)->Enable(false); - Component(data.menu.GetType(),lastInventoryTypeOpened+" Inventory Tab")->SetSelected(false); + Component(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(false); + Component(data.menu.GetType(),data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)+" Inventory Tab")->SetSelected(false); Component(data.menu.GetType(),"Inventory Display - "+data.component->S(A::CATEGORY_NAME))->Enable(true); Component(data.menu.GetType(),data.component->S(A::CATEGORY_NAME)+" Inventory Tab")->SetSelected(true); - lastInventoryTypeOpened=data.component->S(A::CATEGORY_NAME); + data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)=data.component->S(A::CATEGORY_NAME); return true; },{textScaling,1.f})END; button->SetSelectionType(HIGHLIGHT); @@ -103,7 +101,7 @@ void Menu::InitializeInventoryWindow(){ },{.padding=1,.size={137,28}})END; if(first){ - lastInventoryTypeOpened=category; + inventoryWindow->S(A::LAST_INVENTORY_TYPE_OPENED)=category; button->onClick(MenuFuncData{*inventoryWindow,game,button}); //Simulate a click of this button if it's the top one for an initial inventory display. } diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index db2a417c..b8c31eb6 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -42,6 +42,11 @@ All rights reserved. #include "Item.h" #include "MenuItemButton.h" #include "ScrollableWindowComponent.h" +#include "RowInventoryScrollableWindowComponent.h" +#include "MenuItemItemButton.h" + +INCLUDE_ITEM_CATEGORIES +INCLUDE_DATA bool Menu::MOUSE_NAVIGATION=true; std::vectorMenu::stack; diff --git a/Crawler/MerchantWindow.cpp b/Crawler/MerchantWindow.cpp index 749d0bf5..d57c6588 100644 --- a/Crawler/MerchantWindow.cpp +++ b/Crawler/MerchantWindow.cpp @@ -60,6 +60,36 @@ void Menu::InitializeMerchantWindow(){ } std::sort(categories.begin(),categories.end(),[](std::pair&cat1,std::pair&cat2){return cat1.secondADD("Buy Tab",MenuComponent)({{2,0},{merchantWindow->size.x/2-4,24}},"Buy",[](MenuFuncData data){ + Component(MERCHANT,"Merchant Inventory Display")->Enable(true); + Component(MERCHANT,"Sell Tab")->selected=false; + Component(MERCHANT,"Inventory Tabs Outline")->Enable(false); + for(auto&[category,items]:ITEM_CATEGORIES){ + if(DATA["ItemCategory"][category].GetString(0)=="!HIDE")continue; //This category is meant to be hidden! + Component(MERCHANT,category+" Inventory Tab")->Enable(false); + } + Component(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(false); + Component(data.menu.GetType(),data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)+" Inventory Tab")->Enable(false); + data.component->selected=true; + return true; + })END; + buyTab->selected=true; + buyTab->selectionType=SelectionType::HIGHLIGHT; + + auto sellTab=merchantWindow->ADD("Sell Tab",MenuComponent)({{merchantWindow->size.x/2+2,0},{merchantWindow->size.x/2-4,24}},"Sell",[](MenuFuncData data){ + Component(MERCHANT,"Merchant Inventory Display")->Enable(false); + Component(MERCHANT,"Buy Tab")->selected=false; + Component(MERCHANT,"Inventory Tabs Outline")->Enable(true); + for(auto&[category,items]:ITEM_CATEGORIES){ + if(DATA["ItemCategory"][category].GetString(0)=="!HIDE")continue; //This category is meant to be hidden! + Component(MERCHANT,category+" Inventory Tab")->Enable(true); + } + Component(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(true); + Component(data.menu.GetType(),data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)+" Inventory Tab")->Enable(true); + data.component->selected=true; + return true; + })END; + sellTab->selectionType=SelectionType::HIGHLIGHT; auto inventoryDisplay=merchantWindow->ADD("Merchant Inventory Display",RowMerchantInventoryScrollableWindowComponent)({{2,28},{220,merchantWindow->size.y-44}},"Item Name Label","Item Description Label", [](MenuFuncData data){ @@ -94,6 +124,73 @@ void Menu::InitializeMerchantWindow(){ Menu::AddMerchantInventoryListener(inventoryDisplay,category); } + merchantWindow->ADD("Inventory Tabs Outline",MenuComponent)({{0,28},{72,merchantWindow->size.y-44}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END; + + std::sort(categories.begin(),categories.end(),[](std::pair&cat1,std::pair&cat2){return cat1.secondGetTextSizeProp(category).x; + float buttonWidth=64; + float textScaling=std::min(1.f,buttonWidth/textWidth); + + auto button=merchantWindow->ADD(category+" Inventory Tab",MenuComponent)({{2,30+yOffset},{68,16}},category,MenuType::ENUM_END, + [&](MenuFuncData data){ + //Close the old inventory window and show the proper one. + Component(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(false); + Component(data.menu.GetType(),data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)+" Inventory Tab")->SetSelected(false); + Component(data.menu.GetType(),"Inventory Display - "+data.component->S(A::CATEGORY_NAME))->Enable(true); + Component(data.menu.GetType(),data.component->S(A::CATEGORY_NAME)+" Inventory Tab")->SetSelected(true); + data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)=data.component->S(A::CATEGORY_NAME); + return true; + },{textScaling,1.f})END; + button->SetSelectionType(HIGHLIGHT); + button->S(A::CATEGORY_NAME)=category; + + auto inventoryDisplay=merchantWindow->ADD("Inventory Display - "+category,RowInventoryScrollableWindowComponent)({{72,28},{150,merchantWindow->size.y-44}},category,"Item Name Label","Item Description Label", + [](MenuFuncData data){ + RowItemDisplay*item=dynamic_cast(data.component); + Component(SELL_ITEM,"Item Sell Header")->S(A::ITEM_NAME)=item->GetItem().lock()->ActualName(); + Component(SELL_ITEM,"Price per item Amount Label")->SetLabel(std::to_string(item->GetItem().lock()->BuyValue())); + Component(SELL_ITEM,"Amount to sell Amount Label")->SetLabel("1"); + Component(SELL_ITEM,"Total Price Amount Label")->SetLabel(std::to_string(item->GetItem().lock()->BuyValue())); + Merchant&merchant=Merchant::GetCurrentTravelingMerchant(); + bool canPurchase=merchant.CanPurchaseItem(item->GetItem().lock()->ActualName(),1); + + std::string colorCode=""; + if(!canPurchase)colorCode="#FF0000"; + Component(SELL_ITEM,"Total Price Amount Label")->SetLabel(colorCode+std::to_string(item->GetItem().lock()->BuyValue())); + Component(SELL_ITEM,"Item Purchase Header")->SetLabel("Buying "+item->GetItem().lock()->DisplayName()); + Component(SELL_ITEM,"Purchase Button")->SetGrayedOut(!merchant.CanPurchaseItem(item->GetItem().lock()->ActualName(),1)); + Menu::OpenMenu(SELL_ITEM); + return true; + }, + [](MenuFuncData data){ + Component(data.menu.GetType(),"Item Icon")->SetItem(dynamic_cast(data.component)->GetItem()); + Component(data.menu.GetType(),"Item Icon")->UpdateIcon(); + return true; + }, + [](MenuFuncData data){ + Component(data.menu.GetType(),"Item Icon")->SetItem(Item::BLANK); + Component(data.menu.GetType(),"Item Icon")->UpdateIcon(); + return true; + },{.padding=1,.size={137,28}})END; + + if(first){ + merchantWindow->S(A::LAST_INVENTORY_TYPE_OPENED)=category; + button->onClick(MenuFuncData{*merchantWindow,game,button}); //Simulate a click of this button if it's the top one for an initial inventory display. + } + + Menu::AddInventoryListener(inventoryDisplay,category); + inventoryDisplay->Enable(first); + inventoryDisplay->SetCompactDescriptions(false); + + yOffset+=20; + first=false; + } + #pragma endregion + #pragma region Inventory Description float inventoryDescriptionWidth=merchantWindow->pos.x+merchantWindow->size.x-26-224; merchantWindow->ADD("Item Description Outline",MenuLabel)({{224,28},{inventoryDescriptionWidth,merchantWindow->size.y-44}},"",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END; @@ -117,4 +214,6 @@ void Menu::InitializeMerchantWindow(){ Menu::CloseMenu(); return true; },{2,2})END; + + buyTab->onClick(MenuFuncData{*merchantWindow,game,buyTab}); } \ No newline at end of file diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index 0adaabd7..f3bb0d69 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -74,4 +74,5 @@ enum class Attribute{ DRAW_OFFSET, ITEM_NAME, ITEM_QUANTITY, + LAST_INVENTORY_TYPE_OPENED, }; \ No newline at end of file diff --git a/Crawler/TODO.txt b/Crawler/TODO.txt index 2afd0bfc..494decfa 100644 --- a/Crawler/TODO.txt +++ b/Crawler/TODO.txt @@ -1,6 +1,5 @@ January 1st =========== -Level Up Stats, Levels/EXP Sell Item Merchant Screen Blacksmith Item Crafting Screen Randomized Item Stats diff --git a/Crawler/Version.h b/Crawler/Version.h index 872fda03..7d9a5a02 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 4787 +#define VERSION_BUILD 4798 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/olcPixelGameEngine.h b/Crawler/olcPixelGameEngine.h index 3022b71d..29f780e7 100644 --- a/Crawler/olcPixelGameEngine.h +++ b/Crawler/olcPixelGameEngine.h @@ -1032,7 +1032,7 @@ namespace olc // Specify which Sprite should be the target of drawing functions, use nullptr // to specify the primary screen void SetDrawTarget(Sprite* target); - float GetRuntime() const; + double GetRuntime() const; // Gets the current Frames Per Second uint32_t GetFPS() const; // Gets last update of elapsed time @@ -1298,7 +1298,7 @@ namespace olc uint32_t nLastFPS = 0; bool bPixelCohesion = false; DecalMode nDecalMode = DecalMode::NORMAL; - float fRunTime = 0.0f; + double dRunTime = 0.0; DecalStructure nDecalStructure = DecalStructure::FAN; std::function funcPixelMode; std::chrono::time_point m_tp1, m_tp2; @@ -2185,8 +2185,8 @@ namespace olc return 0; } - float PixelGameEngine::GetRuntime() const - { return fRunTime; } + double PixelGameEngine::GetRuntime() const + { return dRunTime; } uint32_t PixelGameEngine::GetFPS() const { return nLastFPS; } @@ -4576,7 +4576,7 @@ namespace olc float actualElapsedTime = elapsedTime.count(); float fElapsedTime = std::clamp(elapsedTime.count(),0.f,1/30.f); //HACK fix. We can't have a negative time. Although using a more precise system clock should make this never occur. Also make sure if the game is too slow we advance by only 1/30th of a second. fLastElapsed = fElapsedTime; - fRunTime += fElapsedTime; + dRunTime += fElapsedTime; if (bConsoleSuspendTime) fElapsedTime = 0.0f; diff --git a/Crawler/olcUTIL_Animate2D.h b/Crawler/olcUTIL_Animate2D.h index 6571ad8c..e676c09f 100644 --- a/Crawler/olcUTIL_Animate2D.h +++ b/Crawler/olcUTIL_Animate2D.h @@ -159,7 +159,7 @@ namespace olc::utils::Animate2D { private: size_t nIndex = 0; - float fTime = 0.0f; + float fTime = 0.0f; template friend class Animation; }; @@ -188,7 +188,7 @@ namespace olc::utils::Animate2D // Update an animation state token inline void UpdateState(AnimationState& state, const float fElapsedTime) const { - state.fTime += fElapsedTime; + state.fTime += std::fmod(fElapsedTime,1000); } public: