Fix scrollbar boundary not updating upon switching to new menus. Fix bug with positions from keyboard/button maps not using original positions in scrollable components.

pull/28/head
sigonasr2 12 months ago
parent 3251053364
commit 46926be340
  1. 2
      Crawler/CharacterMenuWindow.cpp
  2. 1
      Crawler/Crawler.cpp
  3. 2
      Crawler/InventoryScrollableWindowComponent.h
  4. 42
      Crawler/ScrollableWindowComponent.h
  5. 2
      Crawler/Version.h
  6. 9
      Crawler/assets/config/items/ItemDatabase.txt

@ -135,7 +135,7 @@ void Menu::InitializeCharacterMenuWindow(){
equipList->RemoveAllComponents(); equipList->RemoveAllComponents();
for(int counter=0;Item&it:availableEquipment){ for(int counter=0;Item&it:availableEquipment){
Item&itemInvRef=Inventory::GetItem(it.Name()); Item&itemInvRef=Inventory::GetItem(it.Name());
auto equip=equipList->ADD("Equip Item "+std::to_string(counter),RowItemDisplay)({{2,2+counter*28.f},{120-12,28}},itemInvRef, auto equip=equipList->ADD("Equip Item "+std::to_string(counter),RowItemDisplay)({{2,2+counter*28.f},{120-15,28}},itemInvRef,
[](MenuFuncData data){ [](MenuFuncData data){
RowItemDisplay*comp=dynamic_cast<RowItemDisplay*>(data.component); RowItemDisplay*comp=dynamic_cast<RowItemDisplay*>(data.component);
if(comp!=nullptr){ if(comp!=nullptr){

@ -196,6 +196,7 @@ bool Crawler::OnUserCreate(){
Inventory::AddItem("Copper Pants"); Inventory::AddItem("Copper Pants");
Inventory::AddItem("Shell Helmet"); Inventory::AddItem("Shell Helmet");
Inventory::AddItem("Shell Armor"); Inventory::AddItem("Shell Armor");
Inventory::AddItem("Bone Armor");
Inventory::AddItem("Shell Gloves"); Inventory::AddItem("Shell Gloves");
Inventory::AddItem("Shell Shoes"); Inventory::AddItem("Shell Shoes");
Inventory::AddItem("Bone Pants"); Inventory::AddItem("Bone Pants");

@ -117,7 +117,7 @@ protected:
i--; //Subtract one from the index so we don't accidently skip slots. i--; //Subtract one from the index so we don't accidently skip slots.
} }
} }
bounds=CalculateBounds(); //Recalculate the bounds as it's possible the width/height of the component has changed. CalculateBounds(); //Recalculate the bounds as it's possible the width/height of the component has changed.
} }
virtual inline void OnInventorySlotsUpdate(ITCategory cat)override{ virtual inline void OnInventorySlotsUpdate(ITCategory cat)override{
size_t invSize=Inventory::get(cat).size(); size_t invSize=Inventory::get(cat).size();

@ -71,8 +71,8 @@ public:
} }
} }
virtual inline void RemoveButton(MenuComponent*button){ virtual inline void RemoveButton(MenuComponent*button){
std::vector<MenuComponent*>&buttonList=Menu::menus[button->parentMenu]->buttons.at(int(button->GetPos().y)); std::vector<MenuComponent*>&buttonList=Menu::menus[button->parentMenu]->buttons.at(int(button->originalPos.y));
std::vector<MenuComponent*>&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(int(button->GetPos().y)); std::vector<MenuComponent*>&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(int(button->originalPos.y));
size_t removedCount=0; size_t removedCount=0;
removedCount+=std::erase(buttonList,button); removedCount+=std::erase(buttonList,button);
removedCount+=std::erase(keyboardButtonList,button); removedCount+=std::erase(keyboardButtonList,button);
@ -80,19 +80,20 @@ public:
std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!"; std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!";
} }
if(buttonList.size()==0){ if(buttonList.size()==0){
if(!Menu::menus[button->parentMenu]->buttons.erase(int(button->GetPos().y))){ if(!Menu::menus[button->parentMenu]->buttons.erase(int(button->originalPos.y))){
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!") ERR("WARNING! Attempted to erase key "<<button->originalPos.y<<" from button map, but the list still exists!")
} }
} }
if(keyboardButtonList.size()==0){ if(keyboardButtonList.size()==0){
if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(int(button->GetPos().y))){ if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(int(button->originalPos.y))){
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!") ERR("WARNING! Attempted to erase key "<<button->originalPos.y<<" from button map, but the list still exists!")
} }
} }
Menu::menus[button->parentMenu]->components.erase(button->GetName()); Menu::menus[button->parentMenu]->components.erase(button->GetName());
components.erase(std::find(components.begin(),components.end(),button)); components.erase(std::find(components.begin(),components.end(),button));
Menu::menus[button->parentMenu]->RecalculateComponentCount(); Menu::menus[button->parentMenu]->RecalculateComponentCount();
delete button; delete button;
CalculateBounds();
} }
virtual inline void SetScrollAmount(vf2d scrollOffset){ virtual inline void SetScrollAmount(vf2d scrollOffset){
this->scrollOffset=scrollOffset; this->scrollOffset=scrollOffset;
@ -106,8 +107,8 @@ public:
protected: protected:
virtual inline void AfterCreate()override{ virtual inline void AfterCreate()override{
//Let's use the internal name of this component to add unique names for sub-components. //Let's use the internal name of this component to add unique names for sub-components.
upButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+vf2d{rect.size.x-12,0}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){SetScrollAmount(GetScrollAmount()+vf2d{0,"ThemeGlobal.MenuButtonScrollSpeed"_F});return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END; upButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+vf2d{rect.size.x-12,0}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){SetScrollAmount(GetScrollAmount()+vf2d{0,"ThemeGlobal.MenuButtonScrollSpeed"_F});return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH depth-1 END;
downButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+rect.size-vf2d{12,12}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){SetScrollAmount(GetScrollAmount()-vf2d{0,"ThemeGlobal.MenuButtonScrollSpeed"_F});return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END; downButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+rect.size-vf2d{12,12}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){SetScrollAmount(GetScrollAmount()-vf2d{0,"ThemeGlobal.MenuButtonScrollSpeed"_F});return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH depth-1 END;
subWindow=ViewPort::rectViewPort({},rect.size,Menu::menus[parentMenu]->pos+rect.pos); subWindow=ViewPort::rectViewPort({},rect.size,Menu::menus[parentMenu]->pos+rect.pos);
if(upButton){upButton->Enable(!disabled);} if(upButton){upButton->Enable(!disabled);}
if(downButton){downButton->Enable(!disabled);} if(downButton){downButton->Enable(!disabled);}
@ -137,7 +138,6 @@ protected:
float spaceBetweenTopAndBottomArrows=rect.size.y-24; float spaceBetweenTopAndBottomArrows=rect.size.y-24;
float viewHeight=rect.size.y; float viewHeight=rect.size.y;
float totalContentHeight=bounds.size.y; float totalContentHeight=bounds.size.y;
if(totalContentHeight==0)totalContentHeight=1; if(totalContentHeight==0)totalContentHeight=1;
float scrollBarScale=(spaceBetweenTopAndBottomArrows/totalContentHeight); float scrollBarScale=(spaceBetweenTopAndBottomArrows/totalContentHeight);
@ -205,8 +205,8 @@ protected:
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos,child->rect.size},game->GetMousePos()); return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos,child->rect.size},game->GetMousePos());
} }
//Calculates the bounds of all components. //Calculates the bounds of all components.
geom2d::rect<float> inline CalculateBounds(){ inline void CalculateBounds(){
geom2d::rect<float>bounds; bounds={};
for(MenuComponent*component:components){ for(MenuComponent*component:components){
if(component->rect.pos.x<bounds.pos.x){ if(component->rect.pos.x<bounds.pos.x){
float sizeIncrease=bounds.pos.x-component->rect.pos.x; float sizeIncrease=bounds.pos.x-component->rect.pos.x;
@ -227,7 +227,6 @@ protected:
bounds.size.y+=sizeIncrease; bounds.size.y+=sizeIncrease;
} }
} }
return bounds;
} }
public: public:
template<class T> template<class T>
@ -236,24 +235,7 @@ public:
button->renderInMain=false; //Now we are in control! button->renderInMain=false; //Now we are in control!
button->parentComponent=this; button->parentComponent=this;
if(button->rect.pos.x<bounds.pos.x){ CalculateBounds();
float sizeIncrease=bounds.pos.x-button->rect.pos.x;
bounds.size.x+=sizeIncrease;
bounds.pos.x=button->rect.pos.x;
}
if(button->rect.right().start.x>bounds.right().start.x){
float sizeIncrease=button->rect.right().start.x-bounds.right().start.x;
bounds.size.x+=sizeIncrease;
}
if(button->rect.pos.y<bounds.pos.y){
float sizeIncrease=bounds.pos.y-button->rect.pos.y;
bounds.size.y+=sizeIncrease;
bounds.pos.y=button->rect.pos.y;
}
if(button->rect.bottom().start.y>bounds.bottom().start.y){
float sizeIncrease=button->rect.bottom().start.y-bounds.bottom().start.y;
bounds.size.y+=sizeIncrease;
}
Menu::menus[parentMenu]->_AddComponent(key,button); Menu::menus[parentMenu]->_AddComponent(key,button);
return button; return button;

@ -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 4009 #define VERSION_BUILD 4019
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -113,7 +113,8 @@ ItemDatabase
ItemScript = Restore ItemScript = Restore
HP Restore = 1 HP Restore = 1
Description = Does nothing apparently. Description = Does nothing apparently.
ItemCategory = Consumables ItemCategory = Equipment
Slot = Armor
Cooldown Time = 5.0 Cooldown Time = 5.0
Cast Time = 0.0 Cast Time = 0.0
} }
@ -122,7 +123,8 @@ ItemDatabase
ItemScript = Restore ItemScript = Restore
HP Restore = 1 HP Restore = 1
Description = Does nothing apparently. Description = Does nothing apparently.
ItemCategory = Consumables ItemCategory = Equipment
Slot = Armor
Cooldown Time = 5.0 Cooldown Time = 5.0
Cast Time = 0.0 Cast Time = 0.0
} }
@ -131,7 +133,8 @@ ItemDatabase
ItemScript = Restore ItemScript = Restore
HP Restore = 1 HP Restore = 1
Description = Does nothing apparently. Description = Does nothing apparently.
ItemCategory = Consumables ItemCategory = Equipment
Slot = Armor
Cooldown Time = 5.0 Cooldown Time = 5.0
Cast Time = 0.0 Cast Time = 0.0
} }

Loading…
Cancel
Save