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){
Component<MenuLabel>(parentMenu,itemNameLabelName)->SetLabel("");
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->SetLabel("");
if(itemNameLabelName.length()>0)Component<MenuLabel>(parentMenu,itemNameLabelName)->SetLabel("");
if(itemDescriptionLabelName.length()>0)Component<MenuLabel>(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.

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

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

@ -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<componentType>(key,NEW componentType
#define ADD(key,componentType) _AddComponent<componentType>(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<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;
if(depth==DEFAULT_DEPTH){
component->depth=STARTING_DEPTH-componentCount;
@ -174,9 +174,10 @@ public:
static std::vector<Menu*>stack;
static std::string themeSelection;
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 bool IsMenuOpen();
MenuType GetType();
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.
static std::map<MenuType,Menu*>menus;

@ -51,6 +51,13 @@ MenuComponent::MenuComponent(geom2d::rect<float>rect,std::string label,MenuType
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(){
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);
}
}
}

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

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

@ -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(){

@ -230,7 +230,7 @@ protected:
}
public:
template<class T>
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{

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

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

@ -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.
}
Loading…
Cancel
Save