diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 353f9c77..7130058f 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -1066,6 +1066,8 @@ void Crawler::RenderHud(){ if("debug_player_info"_I){ DrawShadowStringDecal({0,128},player->GetPos().str()); DrawShadowStringDecal({0,136},"Spd: "+std::to_string(player->GetMoveSpdMult())); + DrawShadowStringDecal({0,4},"Selection: "+Menu::menus[INVENTORY]->selection.str()); + DrawShadowStringDecal({0,12},"Button Hold Time: "+std::to_string(Menu::menus[INVENTORY]->buttonHoldTime)); } } diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index dceb7613..0bdf3a41 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -13,6 +13,8 @@ const vf2d Menu::CENTERED = {-456,-456}; INCLUDE_GFX extern vi2d WINDOW_SIZE; +typedef Attribute A; + Menu::Menu(){} Menu::Menu(vf2d pos,vf2d size) @@ -80,7 +82,7 @@ void Menu::MenuSelect(Crawler*game){ } void Menu::Update(Crawler*game){ - if(draggingComponent==nullptr&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){ + if(draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){ buttonHoldTime+=game->GetElapsedTime(); } @@ -98,6 +100,7 @@ void Menu::Update(Crawler*game){ if(!MOUSE_NAVIGATION){ if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true; }else{ + selection={-1,-1}; for(auto&key:buttons){ int index=0; for(auto&button:key.second){ @@ -201,7 +204,11 @@ void Menu::Draw(Crawler*game){ vf2d offsetPos=draggingComponent->rect.pos; if(!MOUSE_NAVIGATION){ MenuComponent*selectedComponent=buttons[selection.y][selection.x]; - draggingComponent->Draw(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); + vf2d drawOffset{}; + if(selectedComponent->parentComponent!=nullptr){ + drawOffset+=selectedComponent->parentComponent->V(A::SCROLL_OFFSET); + } + draggingComponent->Draw(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); }else{ draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back()); } @@ -211,7 +218,11 @@ void Menu::Draw(Crawler*game){ game->DrawDecal({0,0},overlay.Decal()); if(!MOUSE_NAVIGATION){ MenuComponent*selectedComponent=buttons[selection.y][selection.x]; - draggingComponent->DrawDecal(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); + vf2d drawOffset{}; + if(selectedComponent->parentComponent!=nullptr){ + drawOffset+=selectedComponent->parentComponent->V(A::SCROLL_OFFSET); + } + draggingComponent->DrawDecal(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); }else{ draggingComponent->DrawDecal(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back()); } @@ -340,9 +351,11 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ for(auto&key:buttons){ int index=0; for(auto&button:key.second){ - if(geom2d::overlaps(geom2d::rect{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){ - selection={index,key.first}; - break; + if(!button->disabled){ + if(geom2d::overlaps(geom2d::rect{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){ + selection={index,key.first}; + break; + } } index++; } diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 84e8ce7d..b262fe0a 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -1,7 +1,7 @@ #pragma once #include "Menu.h" -class MenuComponent{ +class MenuComponent:IAttributable{ friend class Menu; friend class MenuItemButton; friend class ScrollableWindowComponent; diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index aadcf67d..ffb9ec02 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -28,4 +28,5 @@ enum class Attribute{ JUMP_TOWARDS_PLAYER, HITS_UNTIL_DEATH, //When this is set, it is reduced by 1 each time the monster is hit. INDEXED_THEME, + SCROLL_OFFSET, }; \ No newline at end of file diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index 5b08592a..aa788b23 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -3,15 +3,16 @@ #include "MenuComponent.h" #include "Crawler.h" +typedef Attribute A; + class ScrollableWindowComponent:public MenuComponent{ protected: Renderable r; std::vectorcomponents; - vf2d scrollOffset{}; geom2d::rectbounds; //It's for the scrollbar. private: inline bool OnScreen(MenuComponent*component){ - return geom2d::overlaps(rect,geom2d::rect{component->rect.pos+scrollOffset,component->rect.size}); + return geom2d::overlaps(rect,geom2d::rect{component->rect.pos+V(A::SCROLL_OFFSET),component->rect.size}); } public: inline ScrollableWindowComponent(MenuType parent,geom2d::rectrect,Decal*icon,MenuFunc onClick) @@ -24,9 +25,9 @@ protected: if(game->GetMouseWheel()!=0){ if(game->GetMouseWheel()>0){ - scrollOffset.y+="ThemeGlobal.MenuScrollWheelSpeed"_I; + V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuScrollWheelSpeed"_I; }else{ - scrollOffset.y-="ThemeGlobal.MenuScrollWheelSpeed"_I; + V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuScrollWheelSpeed"_I; } } @@ -41,7 +42,7 @@ protected: game->SetDrawTarget(r.Sprite()); game->Clear(BLANK); for(MenuComponent*component:components){ - component->_Draw(game,scrollOffset,focused); + component->_Draw(game,V(A::SCROLL_OFFSET),focused); } game->SetDrawTarget(prevDrawTarget); game->DrawSprite(parentPos,r.Sprite()); @@ -50,11 +51,11 @@ protected: MenuComponent::DrawDecal(game,parentPos,focused); game->DrawRectDecal(parentPos,rect.size); for(MenuComponent*component:components){ - component->_DrawDecal(game,parentPos+scrollOffset,focused); + component->_DrawDecal(game,parentPos+V(A::SCROLL_OFFSET),focused); } } virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{ - return geom2d::overlaps(geom2d::rect{Menu::menus[parentMenu]->pos+child->rect.pos+scrollOffset,child->rect.size},game->GetMousePos()); + return geom2d::overlaps(geom2d::rect{Menu::menus[parentMenu]->pos+child->rect.pos+V(A::SCROLL_OFFSET),child->rect.size},game->GetMousePos()); } public: void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){ diff --git a/Crawler/Version.h b/Crawler/Version.h index 9d541036..d4125829 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 2007 +#define VERSION_BUILD 2026 #define stringify(a) stringify_(a) #define stringify_(a) #a