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,

pull/28/head
sigonasr2 12 months ago
parent 737463c695
commit 469bea4c5e
  1. 7
      Crawler/InventoryScrollableWindowComponent.h
  2. 48
      Crawler/InventoryWindow.cpp
  3. 4
      Crawler/Menu.cpp
  4. 7
      Crawler/Menu.h
  5. 9
      Crawler/MenuComponent.cpp
  6. 2
      Crawler/MenuComponent.h
  7. 8
      Crawler/MenuItemButton.h
  8. 1
      Crawler/MonsterAttribute.h
  9. 2
      Crawler/Player.cpp
  10. 4
      Crawler/ScrollableWindowComponent.h
  11. 2
      Crawler/Version.h
  12. 2
      Crawler/assets/config/classes/Ranger.txt
  13. 15
      Crawler/assets/config/items/ItemCategory.txt

@ -68,10 +68,13 @@ public:
} }
} }
if(noneHovered){ if(noneHovered){
Component<MenuLabel>(parentMenu,itemNameLabelName)->SetLabel(""); if(itemNameLabelName.length()>0)Component<MenuLabel>(parentMenu,itemNameLabelName)->SetLabel("");
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->SetLabel(""); if(itemDescriptionLabelName.length()>0)Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->SetLabel("");
} }
} }
virtual inline void SetInventoryType(ITCategory inventoryType){
this->inventoryType=inventoryType;
}
protected: protected:
inline void RemoveEmptySlots(){ 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. //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.

@ -39,23 +39,55 @@ All rights reserved.
#include "DEFINES.h" #include "DEFINES.h"
#include "Menu.h" #include "Menu.h"
#include "MenuLabel.h" #include "MenuLabel.h"
#include "InventoryScrollableWindowComponent.h"
INCLUDE_game INCLUDE_game
INCLUDE_ITEM_CATEGORIES
INCLUDE_DATA
using A=Attribute; using A=Attribute;
using enum ComponentAttr; using enum ComponentAttr;
using ButtonAttr::UNSELECTABLE; using ButtonAttr::UNSELECTABLE;
using ButtonAttr::UNSELECTABLE_VIA_KEYBOARD; using ButtonAttr::UNSELECTABLE_VIA_KEYBOARD;
struct testStruct{
int val1;
int val2;
int val3;
testStruct(int val1,int val2,int val3){};
};
void Menu::InitializeInventoryWindow(){ void Menu::InitializeInventoryWindow(){
Menu*inventoryWindow=CreateMenu(INVENTORY,CENTERED,game->GetScreenSize()-vi2d{52,52}); 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 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<std::pair<std::string,int>>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<std::string,int>&cat1,std::pair<std::string,int>&cat2){return cat1.second<cat2.second;});
#pragma region Inventory Item Display
auto itemList=inventoryWindow->ADD("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<InventoryScrollableWindowComponent>(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
} }

@ -692,3 +692,7 @@ void Menu::DrawThemedWindow(vf2d menuPos,vf2d size,Pixel renderColor){
void Menu::RecalculateComponentCount(){ void Menu::RecalculateComponentCount(){
componentCount=displayComponents.size()+buttons.size(); componentCount=displayComponents.size()+buttons.size();
} }
MenuType Menu::GetType(){
return type;
}

@ -48,7 +48,7 @@ class MenuComponent;
class ScrollableWindowComponent; class ScrollableWindowComponent;
//Add a component to a menu using this macro. Follow-up with END at the end of it. //Add a component to a menu using this macro. Follow-up with END at the end of it.
#define ADD(key,componentType) AddComponent<componentType>(key,NEW componentType #define ADD(key,componentType) _AddComponent<componentType>(key,NEW componentType
#define END ) #define END )
#define DEPTH , #define DEPTH ,
@ -110,7 +110,7 @@ public:
~Menu(); ~Menu();
//DO NOT USE DIRECTLY! You should be utilizing the ADD macro for adding components. //DO NOT USE DIRECTLY! You should be utilizing the ADD macro for adding components.
template<class T> template<class T>
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; component->parentMenu=type;
if(depth==DEFAULT_DEPTH){ if(depth==DEFAULT_DEPTH){
component->depth=STARTING_DEPTH-componentCount; component->depth=STARTING_DEPTH-componentCount;
@ -174,9 +174,10 @@ public:
static std::vector<Menu*>stack; static std::vector<Menu*>stack;
static std::string themeSelection; static std::string themeSelection;
static safeunorderedmap<std::string,Theme>themes; static safeunorderedmap<std::string,Theme>themes;
static std::vector<MenuComponent*>unhandledComponents; //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::vector<MenuComponent*>unhandledComponents; //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 const vf2d CENTERED;
static bool IsMenuOpen(); static bool IsMenuOpen();
MenuType GetType();
safemap<std::string,MenuComponent*>components; //A friendly way to interrogate any component we are interested in. safemap<std::string,MenuComponent*>components; //A friendly way to interrogate any component we are interested in.
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes. std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
static std::map<MenuType,Menu*>menus; static std::map<MenuType,Menu*>menus;

@ -51,6 +51,13 @@ MenuComponent::MenuComponent(geom2d::rect<float>rect,std::string label,MenuType
this->menuDest=menuDest; this->menuDest=menuDest;
} }
MenuComponent::MenuComponent(geom2d::rect<float>rect,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(){ MenuComponent::~MenuComponent(){
Menu*pMenu=Menu::menus[parentMenu]; Menu*pMenu=Menu::menus[parentMenu];
for(auto key:pMenu->buttons){ 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}); game->FillRectDecal(rect.pos+parentPos+vf2d{0,rect.size.y-1},{rect.size.x,1});
} }
if(showDefaultLabel){ 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);
} }
} }
} }

@ -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 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 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) 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 Update(Crawler*game);
virtual void Draw(Crawler*game,vf2d parentPos); virtual void Draw(Crawler*game,vf2d parentPos);
virtual void DrawDecal(Crawler*game,vf2d parentPos,bool focused); virtual void DrawDecal(Crawler*game,vf2d parentPos,bool focused);
@ -99,6 +100,7 @@ public:
MenuComponent*parentComponent=nullptr; MenuComponent*parentComponent=nullptr;
MenuComponent(geom2d::rect<float>rect,std::string label,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE); MenuComponent(geom2d::rect<float>rect,std::string label,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE); MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,vf2d labelScaling,ButtonAttr attributes=ButtonAttr::NONE);
virtual ~MenuComponent(); virtual ~MenuComponent();
vf2d GetPos(); 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. //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.

@ -78,14 +78,14 @@ protected:
if(valid){ if(valid){
icon=invRef[inventoryIndex].Decal(); icon=invRef[inventoryIndex].Decal();
if(hovered){ if(hovered){
Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label=invRef[inventoryIndex].Name(); if(itemNameLabelName.length()>0)Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label=invRef[inventoryIndex].Name();
Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label=invRef[inventoryIndex].Description(); if(itemDescriptionLabelName.length()>0)Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label=invRef[inventoryIndex].Description();
} }
}else{ }else{
icon=nullptr; icon=nullptr;
if(hovered){ if(hovered){
Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label=""; if(itemNameLabelName.length()>0)Component<MenuLabel>(itemDescriptionMenu,itemNameLabelName)->label="";
Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label=""; if(itemDescriptionLabelName.length()>0)Component<MenuLabel>(itemDescriptionMenu,itemDescriptionLabelName)->label="";
} }
} }
} }

@ -71,4 +71,5 @@ enum class Attribute{
ALLOW_DRAGGING, //Whether or not to allow inventory dragging. ALLOW_DRAGGING, //Whether or not to allow inventory dragging.
EQUIP_TYPE, EQUIP_TYPE,
BASE_TEXT, BASE_TEXT,
CATEGORY_NAME,
}; };

@ -583,7 +583,7 @@ vf2d Player::GetVelocity(){
} }
bool Player::CanMove(){ 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(){ bool Player::CanAct(){

@ -230,7 +230,7 @@ protected:
} }
public: public:
template<class T> template<class T>
T* AddComponent(std::string key,T*button){ T* _AddComponent(std::string key,T*button){
components.push_back(button); components.push_back(button);
button->renderInMain=false; //Now we are in control! button->renderInMain=false; //Now we are in control!
button->parentComponent=this; button->parentComponent=this;
@ -254,7 +254,7 @@ public:
bounds.size.y+=sizeIncrease; bounds.size.y+=sizeIncrease;
} }
Menu::menus[parentMenu]->AddComponent(key,button); Menu::menus[parentMenu]->_AddComponent(key,button);
return button; return button;
} }
virtual inline bool PointWithinParent(MenuComponent*child,vi2d drawPos)override{ virtual inline bool PointWithinParent(MenuComponent*child,vi2d drawPos)override{

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 3722 #define VERSION_BUILD 3744
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -31,7 +31,7 @@ Ranger
Cooldown = 7 Cooldown = 7
Mana Cost = 0 Mana Cost = 0
# Whether or not this ability cancels casts. # Whether or not this ability cancels casts.
CancelCast = 0 CancelCast = 1
Description = Quickly steps backwards to avoid incoming attacks. Description = Quickly steps backwards to avoid incoming attacks.

@ -1,10 +1,13 @@
ItemCategory ItemCategory
{ {
# Random side note, these descriptions aren't used anywhere in-game atm. # Random side note, these descriptions aren't used anywhere in-game atm.
Consumables = Items that will be consumed after a single use. # The numbers in front represent the order these buttons are to be displayed
Equipment = Gear that can be placed onto a player. # in the game inventory.
Accessories = Items worn as extra items on the player. # !HIDE means do not show this tab in inventory menus.
Materials = Items used as crafting materials for the forge. Consumables = 0,Items that will be consumed after a single use.
Monster Loot = Monster drops obtained while navigating a level. Equipment = 1,Gear that can be placed onto a player.
Stage Loot = Stage drops obtained while navigating a level. 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.
} }
Loading…
Cancel
Save