From 469bea4c5ee240973ddc80f8876844a6b3334c55 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 10 Dec 2023 20:14:32 -0600 Subject: [PATCH] Inventory display window tabs are implemented, inventory component is displayed. Ranger Backstep cancels casts. Casts are forced to be channeled for 0.2 seconds before walking can cancel them, --- Crawler/InventoryScrollableWindowComponent.h | 7 ++- Crawler/InventoryWindow.cpp | 48 ++++++++++++++++---- Crawler/Menu.cpp | 4 ++ Crawler/Menu.h | 7 +-- Crawler/MenuComponent.cpp | 9 +++- Crawler/MenuComponent.h | 2 + Crawler/MenuItemButton.h | 8 ++-- Crawler/MonsterAttribute.h | 1 + Crawler/Player.cpp | 2 +- Crawler/ScrollableWindowComponent.h | 4 +- Crawler/Version.h | 2 +- Crawler/assets/config/classes/Ranger.txt | 2 +- Crawler/assets/config/items/ItemCategory.txt | 15 +++--- 13 files changed, 82 insertions(+), 29 deletions(-) diff --git a/Crawler/InventoryScrollableWindowComponent.h b/Crawler/InventoryScrollableWindowComponent.h index f2d872c9..446838d7 100644 --- a/Crawler/InventoryScrollableWindowComponent.h +++ b/Crawler/InventoryScrollableWindowComponent.h @@ -68,10 +68,13 @@ public: } } if(noneHovered){ - Component(parentMenu,itemNameLabelName)->SetLabel(""); - Component(parentMenu,itemDescriptionLabelName)->SetLabel(""); + if(itemNameLabelName.length()>0)Component(parentMenu,itemNameLabelName)->SetLabel(""); + if(itemDescriptionLabelName.length()>0)Component(parentMenu,itemDescriptionLabelName)->SetLabel(""); } } + virtual inline void SetInventoryType(ITCategory inventoryType){ + this->inventoryType=inventoryType; + } protected: inline void RemoveEmptySlots(){ //Algorithm will iterate through all slots, finding blank slots. Each time a blank slot is found, all items will shift over by one, and then the last item will be removed. Repeat until all slots iterated through. diff --git a/Crawler/InventoryWindow.cpp b/Crawler/InventoryWindow.cpp index 38eba332..dd4c99fd 100644 --- a/Crawler/InventoryWindow.cpp +++ b/Crawler/InventoryWindow.cpp @@ -39,23 +39,55 @@ All rights reserved. #include "DEFINES.h" #include "Menu.h" #include "MenuLabel.h" +#include "InventoryScrollableWindowComponent.h" INCLUDE_game +INCLUDE_ITEM_CATEGORIES +INCLUDE_DATA using A=Attribute; using enum ComponentAttr; using ButtonAttr::UNSELECTABLE; using ButtonAttr::UNSELECTABLE_VIA_KEYBOARD; -struct testStruct{ - int val1; - int val2; - int val3; - testStruct(int val1,int val2,int val3){}; -}; - void Menu::InitializeInventoryWindow(){ 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; - inventoryWindow->ADD("Inventory Tabs",MenuComponent)({{0,28},{72,inventoryWindow->size.x-44}},"",DO_NOTHING,UNSELECTABLE)END; + inventoryWindow->ADD("Inventory Tabs Outline",MenuComponent)({{0,28},{72,inventoryWindow->size.y-44}},"",DO_NOTHING,UNSELECTABLE)END; + + std::vector>categories; + for(auto&[category,items]:ITEM_CATEGORIES){ + if(DATA["ItemCategory"][category].GetString(0)=="!HIDE")continue; //This category is meant to be hidden! + categories.push_back({category,DATA["ItemCategory"][category].GetInt(0)}); //We assume the first value becomes the sort order we wish to use. + } + std::sort(categories.begin(),categories.end(),[](std::pair&cat1,std::pair&cat2){return cat1.secondADD("Inventory Display",InventoryScrollableWindowComponent)({{72,28},{150,inventoryWindow->size.y-44}},categories[0].first,"","",DO_NOTHING)END; + #pragma endregion + + #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=inventoryWindow->ADD(category+" Inventory Tab",MenuComponent)({{2,30+yOffset},{68,16}},category,MenuType::ENUM_END, + [&](MenuFuncData data){ + Component(data.menu.GetType(),"Inventory Display")->SetInventoryType(data.component->S(A::CATEGORY_NAME)); + return true; + },{textScaling,1.f})END; + + button->S(A::CATEGORY_NAME)=category; + + if(first){ + button->onClick(MenuFuncData{*inventoryWindow,game,button}); //Simulate a click of this button if it's the top one for an initial inventory display. + } + + yOffset+=20; + first=false; + } + #pragma endregion } \ No newline at end of file diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index 17cabb7c..ff5d12ef 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -691,4 +691,8 @@ void Menu::DrawThemedWindow(vf2d menuPos,vf2d size,Pixel renderColor){ void Menu::RecalculateComponentCount(){ componentCount=displayComponents.size()+buttons.size(); +} + +MenuType Menu::GetType(){ + return type; } \ No newline at end of file diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 567b394c..a8ec2ad4 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -48,7 +48,7 @@ class MenuComponent; class ScrollableWindowComponent; //Add a component to a menu using this macro. Follow-up with END at the end of it. -#define ADD(key,componentType) AddComponent(key,NEW componentType +#define ADD(key,componentType) _AddComponent(key,NEW componentType #define END ) #define DEPTH , @@ -110,7 +110,7 @@ public: ~Menu(); //DO NOT USE DIRECTLY! You should be utilizing the ADD macro for adding components. template - T*AddComponent(std::string componentKey,T*component,int depth=DEFAULT_DEPTH){ + T*_AddComponent(std::string componentKey,T*component,int depth=DEFAULT_DEPTH){ component->parentMenu=type; if(depth==DEFAULT_DEPTH){ component->depth=STARTING_DEPTH-componentCount; @@ -174,9 +174,10 @@ public: static std::vectorstack; static std::string themeSelection; static safeunorderedmapthemes; - static std::vectorunhandledComponents; //This list contains MenuComponents that are created and haven't been assigned via AddComponent. If we get to the end of menu initialization and there are any components in this vector, we have leaked memory and will report this. + static std::vectorunhandledComponents; //This list contains MenuComponents that are created and haven't been assigned via _AddComponent. If we get to the end of menu initialization and there are any components in this vector, we have leaked memory and will report this. static const vf2d CENTERED; static bool IsMenuOpen(); + MenuType GetType(); safemapcomponents; //A friendly way to interrogate any component we are interested in. std::vectordisplayComponents; //Components that are only for displaying purposes. static std::mapmenus; diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 8158a9f1..eb0de926 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -51,6 +51,13 @@ MenuComponent::MenuComponent(geom2d::rectrect,std::string label,MenuType this->menuDest=menuDest; } +MenuComponent::MenuComponent(geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,vf2d labelScaling,ButtonAttr attributes) + :MenuComponent(rect,label,menuDest,onClick,attributes){ + //NOTE: This constructor also calls the other constructor above! + this->labelScaling=labelScaling; + if (labelScaling!=vf2d{1,1})this->decal=true; //Since we would have to draw text smaller than an integer scale, we are forced to use a decal here. +} + MenuComponent::~MenuComponent(){ Menu*pMenu=Menu::menus[parentMenu]; for(auto key:pMenu->buttons){ @@ -122,7 +129,7 @@ void MenuComponent::DrawDecal(Crawler*game,vf2d parentPos,bool focused){ game->FillRectDecal(rect.pos+parentPos+vf2d{0,rect.size.y-1},{rect.size.x,1}); } if(showDefaultLabel){ - game->DrawStringPropDecal(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); + game->DrawStringPropDecal(rect.pos+parentPos+rect.size/2-vf2d(game->GetTextSizeProp(label))/2.f*labelScaling,label,WHITE,labelScaling); } } } diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 144ddae7..499e124f 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -87,6 +87,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 decal=false; //If set to true, will use decal rendering (For foreground shenanigans) + vf2d labelScaling={1,1}; virtual void Update(Crawler*game); virtual void Draw(Crawler*game,vf2d parentPos); virtual void DrawDecal(Crawler*game,vf2d parentPos,bool focused); @@ -99,6 +100,7 @@ public: MenuComponent*parentComponent=nullptr; MenuComponent(geom2d::rectrect,std::string label,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE); MenuComponent(geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE); + MenuComponent(geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,vf2d labelScaling,ButtonAttr attributes=ButtonAttr::NONE); virtual ~MenuComponent(); vf2d GetPos(); //We picked up a draggable component, we should make a copy and return it here. If a nullptr is returned here, the pickup is not allowed. diff --git a/Crawler/MenuItemButton.h b/Crawler/MenuItemButton.h index 0fee06d3..dbc631df 100644 --- a/Crawler/MenuItemButton.h +++ b/Crawler/MenuItemButton.h @@ -78,14 +78,14 @@ protected: if(valid){ icon=invRef[inventoryIndex].Decal(); if(hovered){ - Component(itemDescriptionMenu,itemNameLabelName)->label=invRef[inventoryIndex].Name(); - Component(itemDescriptionMenu,itemDescriptionLabelName)->label=invRef[inventoryIndex].Description(); + if(itemNameLabelName.length()>0)Component(itemDescriptionMenu,itemNameLabelName)->label=invRef[inventoryIndex].Name(); + if(itemDescriptionLabelName.length()>0)Component(itemDescriptionMenu,itemDescriptionLabelName)->label=invRef[inventoryIndex].Description(); } }else{ icon=nullptr; if(hovered){ - Component(itemDescriptionMenu,itemNameLabelName)->label=""; - Component(itemDescriptionMenu,itemDescriptionLabelName)->label=""; + if(itemNameLabelName.length()>0)Component(itemDescriptionMenu,itemNameLabelName)->label=""; + if(itemDescriptionLabelName.length()>0)Component(itemDescriptionMenu,itemDescriptionLabelName)->label=""; } } } diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index 3317e70c..cedc151b 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -71,4 +71,5 @@ enum class Attribute{ ALLOW_DRAGGING, //Whether or not to allow inventory dragging. EQUIP_TYPE, BASE_TEXT, + CATEGORY_NAME, }; \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index d04886e1..bc7bb30c 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -583,7 +583,7 @@ vf2d Player::GetVelocity(){ } bool Player::CanMove(){ - return state!=State::ANIMATION_LOCK; + return state!=State::ANIMATION_LOCK&&(state!=State::CASTING||(castInfo.castTotalTime-castInfo.castTimer>0.2f)); } bool Player::CanAct(){ diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index 43451f75..231c9e53 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -230,7 +230,7 @@ protected: } public: template - T* AddComponent(std::string key,T*button){ + T* _AddComponent(std::string key,T*button){ components.push_back(button); button->renderInMain=false; //Now we are in control! button->parentComponent=this; @@ -254,7 +254,7 @@ public: bounds.size.y+=sizeIncrease; } - Menu::menus[parentMenu]->AddComponent(key,button); + Menu::menus[parentMenu]->_AddComponent(key,button); return button; } virtual inline bool PointWithinParent(MenuComponent*child,vi2d drawPos)override{ diff --git a/Crawler/Version.h b/Crawler/Version.h index 81315c72..06e386e9 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 3722 +#define VERSION_BUILD 3744 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/classes/Ranger.txt b/Crawler/assets/config/classes/Ranger.txt index fc07baca..f9a3291e 100644 --- a/Crawler/assets/config/classes/Ranger.txt +++ b/Crawler/assets/config/classes/Ranger.txt @@ -31,7 +31,7 @@ Ranger Cooldown = 7 Mana Cost = 0 # Whether or not this ability cancels casts. - CancelCast = 0 + CancelCast = 1 Description = Quickly steps backwards to avoid incoming attacks. diff --git a/Crawler/assets/config/items/ItemCategory.txt b/Crawler/assets/config/items/ItemCategory.txt index dfc605d0..c6ee876a 100644 --- a/Crawler/assets/config/items/ItemCategory.txt +++ b/Crawler/assets/config/items/ItemCategory.txt @@ -1,10 +1,13 @@ ItemCategory { # Random side note, these descriptions aren't used anywhere in-game atm. - Consumables = Items that will be consumed after a single use. - Equipment = Gear that can be placed onto a player. - Accessories = Items worn as extra items on the player. - Materials = Items used as crafting materials for the forge. - Monster Loot = Monster drops obtained while navigating a level. - Stage Loot = Stage drops obtained while navigating a level. + # The numbers in front represent the order these buttons are to be displayed + # in the game inventory. + # !HIDE means do not show this tab in inventory menus. + Consumables = 0,Items that will be consumed after a single use. + Equipment = 1,Gear that can be placed onto a player. + Accessories = 2,Items worn as extra items on the player. + Materials = 3,Items used as crafting materials for the forge. + Monster Loot = !HIDE,Monster drops obtained while navigating a level. + Stage Loot = !HIDE,Stage drops obtained while navigating a level. } \ No newline at end of file