Setup Sell Layout for merchant screen.

pull/28/head
sigonasr2 11 months ago
parent 4ac15dd1cc
commit 25dd39b60a
  1. 4
      Crawler/Crawler.cpp
  2. 2
      Crawler/Crawler.h
  3. 10
      Crawler/InventoryWindow.cpp
  4. 5
      Crawler/Menu.cpp
  5. 99
      Crawler/MerchantWindow.cpp
  6. 1
      Crawler/MonsterAttribute.h
  7. 1
      Crawler/TODO.txt
  8. 2
      Crawler/Version.h
  9. 10
      Crawler/olcPixelGameEngine.h
  10. 2
      Crawler/olcUTIL_Animate2D.h

@ -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&timestamps=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);});

@ -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::map<MapName,Map>MAP_DATA;
private:

@ -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<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+lastInventoryTypeOpened)->Enable(false);
Component<MenuComponent>(data.menu.GetType(),lastInventoryTypeOpened+" Inventory Tab")->SetSelected(false);
Component<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(false);
Component<MenuComponent>(data.menu.GetType(),data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)+" Inventory Tab")->SetSelected(false);
Component<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.component->S(A::CATEGORY_NAME))->Enable(true);
Component<MenuComponent>(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.
}

@ -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::vector<Menu*>Menu::stack;

@ -60,6 +60,36 @@ void Menu::InitializeMerchantWindow(){
}
std::sort(categories.begin(),categories.end(),[](std::pair<std::string,int>&cat1,std::pair<std::string,int>&cat2){return cat1.second<cat2.second;});
auto buyTab=merchantWindow->ADD("Buy Tab",MenuComponent)({{2,0},{merchantWindow->size.x/2-4,24}},"Buy",[](MenuFuncData data){
Component<RowMerchantInventoryScrollableWindowComponent>(MERCHANT,"Merchant Inventory Display")->Enable(true);
Component<MenuComponent>(MERCHANT,"Sell Tab")->selected=false;
Component<MenuComponent>(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<MenuComponent>(MERCHANT,category+" Inventory Tab")->Enable(false);
}
Component<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(false);
Component<MenuComponent>(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<RowMerchantInventoryScrollableWindowComponent>(MERCHANT,"Merchant Inventory Display")->Enable(false);
Component<MenuComponent>(MERCHANT,"Buy Tab")->selected=false;
Component<MenuComponent>(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<MenuComponent>(MERCHANT,category+" Inventory Tab")->Enable(true);
}
Component<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(true);
Component<MenuComponent>(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<std::string,int>&cat1,std::pair<std::string,int>&cat2){return cat1.second<cat2.second;});
#pragma region Inventory Tabs
bool first=true;
for(float yOffset=0;auto&[category,sortOrder]:categories){
float textWidth=game->GetTextSizeProp(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<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.menu.S(A::LAST_INVENTORY_TYPE_OPENED))->Enable(false);
Component<MenuComponent>(data.menu.GetType(),data.menu.S(A::LAST_INVENTORY_TYPE_OPENED)+" Inventory Tab")->SetSelected(false);
Component<RowInventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.component->S(A::CATEGORY_NAME))->Enable(true);
Component<MenuComponent>(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<RowItemDisplay*>(data.component);
Component<MenuLabel>(SELL_ITEM,"Item Sell Header")->S(A::ITEM_NAME)=item->GetItem().lock()->ActualName();
Component<MenuLabel>(SELL_ITEM,"Price per item Amount Label")->SetLabel(std::to_string(item->GetItem().lock()->BuyValue()));
Component<MenuLabel>(SELL_ITEM,"Amount to sell Amount Label")->SetLabel("1");
Component<MenuLabel>(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<MenuLabel>(SELL_ITEM,"Total Price Amount Label")->SetLabel(colorCode+std::to_string(item->GetItem().lock()->BuyValue()));
Component<MenuLabel>(SELL_ITEM,"Item Purchase Header")->SetLabel("Buying "+item->GetItem().lock()->DisplayName());
Component<MenuComponent>(SELL_ITEM,"Purchase Button")->SetGrayedOut(!merchant.CanPurchaseItem(item->GetItem().lock()->ActualName(),1));
Menu::OpenMenu(SELL_ITEM);
return true;
},
[](MenuFuncData data){
Component<MenuItemItemButton>(data.menu.GetType(),"Item Icon")->SetItem(dynamic_cast<RowItemDisplay*>(data.component)->GetItem());
Component<MenuItemItemButton>(data.menu.GetType(),"Item Icon")->UpdateIcon();
return true;
},
[](MenuFuncData data){
Component<MenuItemItemButton>(data.menu.GetType(),"Item Icon")->SetItem(Item::BLANK);
Component<MenuItemItemButton>(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});
}

@ -74,4 +74,5 @@ enum class Attribute{
DRAW_OFFSET,
ITEM_NAME,
ITEM_QUANTITY,
LAST_INVENTORY_TYPE_OPENED,
};

@ -1,6 +1,5 @@
January 1st
===========
Level Up Stats, Levels/EXP
Sell Item Merchant Screen
Blacksmith Item Crafting Screen
Randomized Item Stats

@ -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

@ -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<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode;
std::chrono::time_point<std::chrono::system_clock> 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;

@ -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:

Loading…
Cancel
Save