diff --git a/Crawler/CharacterAbilityPreviewComponent.h b/Crawler/CharacterAbilityPreviewComponent.h index 1256c58a..5e93662c 100644 --- a/Crawler/CharacterAbilityPreviewComponent.h +++ b/Crawler/CharacterAbilityPreviewComponent.h @@ -19,8 +19,8 @@ protected: virtual void inline Update(Crawler*game)override{ MenuLabel::Update(game); } - virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ - MenuLabel::Draw(game,parentPos,focused); + virtual void inline Draw(Crawler*game,vf2d parentPos)override{ + MenuLabel::Draw(game,parentPos); game->DrawRect(parentPos+rect.pos+vi2d{2,2},vi2d{int(rect.size.y)-4,int(rect.size.y)-4}); ICONPOS game->DrawSprite(iconPos,GFX[ability->icon].Sprite()); diff --git a/Crawler/CharacterRotatingDisplay.h b/Crawler/CharacterRotatingDisplay.h index 1bb699c4..66a28a36 100644 --- a/Crawler/CharacterRotatingDisplay.h +++ b/Crawler/CharacterRotatingDisplay.h @@ -22,9 +22,7 @@ protected: timer-=2*PI; } } - virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ - //MenuComponent::Draw(game,parentPos,focused); - } + virtual inline void Draw(Crawler*game,vf2d parentPos)override{} virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ //MenuComponent::DrawDecal(game,parentPos,focused); game->DrawWarpedDecal(icon,std::array{ diff --git a/Crawler/ClassSelectionWindow.cpp b/Crawler/ClassSelectionWindow.cpp index dbf65b53..d4bfa6c2 100644 --- a/Crawler/ClassSelectionWindow.cpp +++ b/Crawler/ClassSelectionWindow.cpp @@ -3,7 +3,7 @@ #include "DEFINES.h" #include "Menu.h" #include "MenuLabel.h" -#include "MenuAnimatedIconButton.h" +#include "MenuAnimatedIconToggleButton.h" #include "GameState.h" INCLUDE_game @@ -27,7 +27,17 @@ void Menu::InitializeClassSelectionWindow(){ MenuComponent*backButton=new MenuComponent(CLASS_SELECTION,{{4+2,outlineSize.y+4-navigationButtonSize.y-2},navigationButtonSize},"Back",[](MenuFuncData data){Menu::CloseMenu();}); classSelectionWindow->AddComponent("Back Button",backButton); - MenuComponent*confirmButton=new MenuComponent(CLASS_SELECTION,{{outlineSize.x+4-navigationButtonSize.x-2,outlineSize.y+4-navigationButtonSize.y-2},navigationButtonSize},"Confirm",[](MenuFuncData data){GameState::ChangeState(States::GAME_RUN);}); + MenuComponent*confirmButton=new MenuComponent(CLASS_SELECTION,{{outlineSize.x+4-navigationButtonSize.x-2,outlineSize.y+4-navigationButtonSize.y-2},navigationButtonSize},"Confirm",[](MenuFuncData data){ + std::string selectedClass=data.component->S(A::CLASS_SELECTION); + INCLUDE_DATA + std::vectorclassList=DATA["class_list"].GetValues(); + auto it=std::find(classList.begin(),classList.end(),selectedClass); + int element=std::distance(classList.begin(),it); + Class cl=Class(1<ChangePlayerClass(cl); + GameState::ChangeState(States::GAME_RUN); + }); + confirmButton->disabled=true; classSelectionWindow->AddComponent("Confirm",confirmButton); vf2d buttonPadding={2,2}; @@ -53,6 +63,8 @@ void Menu::InitializeClassSelectionWindow(){ Trapper::walk_s, Witch::walk_s, }; + + std::vectortoggleGroup; for(int i=0;i<6;i++){ std::string className=classNames[i]; @@ -68,17 +80,25 @@ void Menu::InitializeClassSelectionWindow(){ vf2d backgroundSize={floor(outlineSize.y/3-buttonPadding.y*3),outlineSize.y/3-buttonPadding.y*3}; //The floor is for fixing a small pixel rounding bug. MenuLabel*backgroundOutline=new MenuLabel(CLASS_SELECTION,{backgroundOffsetPos,backgroundSize},"",1,true,false,true,true); MenuLabel*classLabel=new MenuLabel(CLASS_SELECTION,{backgroundOffsetPos,buttonSize},className,1,true,true); - MenuAnimatedIconButton*classSprite=new MenuAnimatedIconButton(CLASS_SELECTION,{backgroundOffsetPos+vf2d{0,12},backgroundSize+vf2d{0,-buttonSize.y-12}},classAnimationName,[](MenuFuncData data){},false); + MenuAnimatedIconToggleButton*classSprite=new MenuAnimatedIconToggleButton(CLASS_SELECTION,{backgroundOffsetPos+vf2d{0,12},backgroundSize+vf2d{0,-buttonSize.y-12}},classAnimationName,[](MenuFuncData data){ + data.menu.components["Confirm"]->Enable(true); + data.menu.components["Confirm"]->S(A::CLASS_SELECTION)=data.component->S(A::CLASS_SELECTION); + }); + toggleGroup.push_back(classSprite); MenuComponent*classButton=new MenuComponent(CLASS_SELECTION,{offsetPos,buttonSize},"Info",CLASS_INFO, [](MenuFuncData data){ data.menu.S(A::CLASS_SELECTION)=data.component->S(A::CLASS_SELECTION); delete Menu::menus[CLASS_INFO]; Menu::InitializeClassInfoWindow(); }); - classButton->S(A::CLASS_SELECTION)=className; + classSprite->S(A::CLASS_SELECTION)=classButton->S(A::CLASS_SELECTION)=className; classSelectionWindow->AddComponent(className+" Button",classButton); classSelectionWindow->AddComponent(className+" Background",backgroundOutline); classSelectionWindow->AddComponent(className+" Label",classLabel); classSelectionWindow->AddComponent(className+" Icon",classSprite); } + + for(IToggleable*item:toggleGroup){ + item->SetToggleGroup(toggleGroup); + } } \ No newline at end of file diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 826693b0..6b364b0b 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -20,6 +20,7 @@ #include "Menu.h" #include "GameState.h" #include "Item.h" +#include "Toggleable.h" INCLUDE_EMITTER_LIST @@ -143,6 +144,8 @@ bool Crawler::OnUserCreate(){ GameState::Initialize(); + ValidateGameStatus(); //Checks to make sure everything has been initialized properly. + return true; } @@ -1818,4 +1821,14 @@ void Crawler::InitializeGraphics(){ MapTag Crawler::GetCurrentMap(){ return MAP_DATA[GetCurrentLevel()].MapData; +} + +void Crawler::ValidateGameStatus(){ + if(IToggleable::uninitializedToggleGroupItems.size()>0){ + for(IToggleable*item:IToggleable::uninitializedToggleGroupItems){ + std::cout<<"\tUninitialized Toggle Item Ptr: 0x"<monstersToBeSpawned; + + void ValidateGameStatus(); public: Crawler(); bool OnUserCreate() override; diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index cff5ede7..a55ba0ad 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -276,6 +276,7 @@ + @@ -303,6 +304,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index e58383cf..cc9c6f75 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -204,6 +204,12 @@ Header Files\Interface + + Header Files\Interface + + + Source Files + diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index 1ebcf0e7..04ba103d 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -276,13 +276,13 @@ void Menu::Draw(Crawler*game){ game->Clear(BLANK); for(auto&component:displayComponents){ if(component->renderInMain){ - component->_Draw(game,{0,0},this==Menu::stack.back()); + component->_Draw(game,{0,0}); } } for(auto&key:buttons){ for(auto&button:key.second){ if(button->renderInMain){ - button->_Draw(game,{0,0},this==Menu::stack.back()); + button->_Draw(game,{0,0}); } } } @@ -321,14 +321,14 @@ void Menu::Draw(Crawler*game){ 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()); + draggingComponent->Draw(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4}); }else{ - draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back()); + draggingComponent->Draw(game,-offsetPos+game->GetMousePos()); } game->SetPixelMode(prevMode); game->SetDrawTarget(nullptr); overlay.Decal()->Update(); - game->DrawDecal({0,0},overlay.Decal()); + game->DrawDecal({0,0},overlay.Decal(),{1,1},this==Menu::stack.back()?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); if(!UsingMouseNavigation()){ MenuComponent*selectedComponent=buttons[selection.y][selection.x]; vf2d drawOffset{}; diff --git a/Crawler/MenuAnimatedIconButton.h b/Crawler/MenuAnimatedIconButton.h index d8e90f42..05097047 100644 --- a/Crawler/MenuAnimatedIconButton.h +++ b/Crawler/MenuAnimatedIconButton.h @@ -19,8 +19,8 @@ protected: MenuIconButton::Update(game); animationTime+=game->GetElapsedTime(); } - virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ - MenuComponent::Draw(game,parentPos,focused); //INTENTIONAL! The way we draw animations is different from static images, we skip over MenuIconButton's draw! + virtual inline void Draw(Crawler*game,vf2d parentPos)override{ + MenuComponent::Draw(game,parentPos); //INTENTIONAL! The way we draw animations is different from static images, we skip over MenuIconButton's draw! Sprite*spr=ANIMATION_DATA[animation].GetFrame(animationTime).GetSourceImage()->Sprite(); geom2d::rectsprRect=ANIMATION_DATA[animation].GetFrame(animationTime).GetSourceRect(); game->DrawPartialSprite(parentPos+rect.middle()-sprRect.size/2,spr,sprRect.pos,sprRect.size,1,Sprite::Flip::NONE); diff --git a/Crawler/MenuAnimatedIconToggleButton.h b/Crawler/MenuAnimatedIconToggleButton.h new file mode 100644 index 00000000..f58997f3 --- /dev/null +++ b/Crawler/MenuAnimatedIconToggleButton.h @@ -0,0 +1,34 @@ +#pragma once +#include "MenuAnimatedIconButton.h" +#include "DEFINES.h" +#include "Crawler.h" +#include "Toggleable.h" + +INCLUDE_game + +class MenuAnimatedIconToggleButton:public MenuAnimatedIconButton,public IToggleable{ +protected: + MenuFunc _onClick; //What the user-defined behavior is. This toggle has its own custom-built onClick stuff to do. +private: + float animationTime=0; +public: + inline MenuAnimatedIconToggleButton(MenuType parent,geom2d::rectrect,std::string animation,MenuFunc onClick) + :MenuAnimatedIconButton(parent,rect,animation,[](MenuFuncData data){ + MenuAnimatedIconToggleButton*button=(MenuAnimatedIconToggleButton*)data.component; + button->Select(); + button->_onClick(data); + }),_onClick(onClick){} +protected: + virtual inline void Update(Crawler*game)override{ + MenuAnimatedIconButton::Update(game); + if(IsSelected()){ + hoverEffect="ThemeGlobal.HighlightTime"_F; //A hack that allows us to make it look like we have this selected. + } + } + virtual inline void Draw(Crawler*game,vf2d parentPos)override{ + MenuAnimatedIconButton::Draw(game,parentPos); + if(IsSelected()){ + game->DrawRect(rect.pos+vi2d{2,2},rect.size-vi2d{4,4},YELLOW); + } + } +}; \ No newline at end of file diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 4f4e3368..2d97762f 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -43,21 +43,21 @@ void MenuComponent::_Update(Crawler*game){ } } -void MenuComponent::Draw(Crawler*game,vf2d parentPos,bool focused){ +void MenuComponent::Draw(Crawler*game,vf2d parentPos){ if(background){ - game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)*(focused?1:"ThemeGlobal.MenuUnfocusedColorMult"_F)); + game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); } if(border){ - game->DrawRect(rect.pos+parentPos,rect.size,focused?GREY:GREY*"ThemeGlobal.MenuUnfocusedColorMult"_F); + game->DrawRect(rect.pos+parentPos,rect.size); } if(showDefaultLabel){ - game->DrawStringProp(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); + game->DrawStringProp(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); } } -void MenuComponent::_Draw(Crawler*game,vf2d parentPos,bool focused){ +void MenuComponent::_Draw(Crawler*game,vf2d parentPos){ if(!disabled){ - Draw(game,parentPos,focused); + Draw(game,parentPos); } } @@ -110,4 +110,8 @@ void MenuComponent::OnInventorySlotsUpdate(ITCategory cat){} std::string MenuComponent::GetLabel(){ return label; -} \ No newline at end of file +} + +void MenuComponent::Enable(bool enabled){ + disabled=!enabled; +}; \ No newline at end of file diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index d71efda3..e778ff63 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -8,12 +8,12 @@ class MenuComponent:IAttributable{ friend class InventoryScrollableWindowComponent; MenuType menuDest; private: - float hoverEffect=0; virtual bool GetHoverState(Crawler*game); //CALL THIS FOR A PARENT to check a child's DrawDecal validity! virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos); std::pairmemoryLeakInfo; //Used to identify memory leak hints for this component. protected: + float hoverEffect=0; std::string name=""; geom2d::rectrect; std::string label; @@ -31,7 +31,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. virtual void Update(Crawler*game); - virtual void Draw(Crawler*game,vf2d parentPos,bool focused); + virtual void Draw(Crawler*game,vf2d parentPos); virtual void DrawDecal(Crawler*game,vf2d parentPos,bool focused); virtual bool GetHoverState(Crawler*game,MenuComponent*child); virtual void AfterCreate(); //Called after the creation of all menus finish. @@ -40,7 +40,7 @@ public: MenuComponent(MenuType parent,geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true); virtual ~MenuComponent(); void _Update(Crawler*game); - void _Draw(Crawler*game,vf2d parentPos,bool focused); + void _Draw(Crawler*game,vf2d parentPos); void _DrawDecal(Crawler*game,vf2d parentPos,bool focused); 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. @@ -53,4 +53,5 @@ public: //Called whenever an inventory slot gets updated, whether it's adding or removing an item. virtual void OnInventorySlotsUpdate(ITCategory cat); std::string GetLabel(); + void Enable(bool enabled); }; \ No newline at end of file diff --git a/Crawler/MenuIconButton.h b/Crawler/MenuIconButton.h index 294f56bb..b5a4493f 100644 --- a/Crawler/MenuIconButton.h +++ b/Crawler/MenuIconButton.h @@ -15,10 +15,10 @@ protected: virtual inline void Update(Crawler*game)override{ MenuComponent::Update(game); } - virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ - MenuComponent::Draw(game,parentPos,focused); + virtual inline void Draw(Crawler*game,vf2d parentPos)override{ + MenuComponent::Draw(game,parentPos); if(icon!=nullptr){ - game->DrawSprite(parentPos+rect.middle()-icon->sprite->Size()/2,icon->sprite,1,Sprite::Flip::NONE,[&](Pixel&in){return focused?in:in*"ThemeGlobal.MenuUnfocusedColorMult"_F;}); + game->DrawSprite(parentPos+rect.middle()-icon->sprite->Size()/2,icon->sprite,1,Sprite::Flip::NONE); } } }; \ No newline at end of file diff --git a/Crawler/MenuLabel.h b/Crawler/MenuLabel.h index 61f09b0e..cbdcf334 100644 --- a/Crawler/MenuLabel.h +++ b/Crawler/MenuLabel.h @@ -24,17 +24,17 @@ protected: virtual void inline Update(Crawler*game)override{ MenuComponent::Update(game); } - virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ - MenuComponent::Draw(game,parentPos,focused); + virtual void inline Draw(Crawler*game,vf2d parentPos)override{ + MenuComponent::Draw(game,parentPos); std::string wrappedText=util::WrapText(game,label,rect.size.x,true,{float(scale),float(scale)}); vf2d drawPos=parentPos+rect.middle()-vf2d{game->GetTextSizeProp(wrappedText)}*float(scale)/2; //Assume centered. if(!centered){ drawPos=vf2d{rect.pos.x+2,rect.middle().y-game->GetTextSizeProp(wrappedText).y/2}+parentPos; //We should at least vertically align here. } if(shadow){ - game->DrawShadowStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F,BLACK,{float(scale),float(scale)}); + game->DrawShadowStringProp(drawPos,wrappedText,WHITE,BLACK,{float(scale),float(scale)}); }else{ - game->DrawStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F,scale); + game->DrawStringProp(drawPos,wrappedText,WHITE,scale); } } }; \ No newline at end of file diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index e8fae819..2061b5a9 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -94,13 +94,13 @@ protected: downButton->disabled=true; } } - virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ - MenuComponent::Draw(game,parentPos,focused); + virtual inline void Draw(Crawler*game,vf2d parentPos)override{ + MenuComponent::Draw(game,parentPos); Sprite*prevDrawTarget=game->GetDrawTarget(); game->SetDrawTarget(r.Sprite()); game->Clear(BLANK); for(MenuComponent*component:components){ - component->_Draw(game,rect.pos+V(A::SCROLL_OFFSET),focused); + component->_Draw(game,rect.pos+V(A::SCROLL_OFFSET)); } game->SetDrawTarget(prevDrawTarget); game->DrawSprite(parentPos,r.Sprite()); diff --git a/Crawler/Toggleable.h b/Crawler/Toggleable.h new file mode 100644 index 00000000..f450ea62 --- /dev/null +++ b/Crawler/Toggleable.h @@ -0,0 +1,42 @@ +#pragma once + +class IToggleable{ + friend class Crawler; +public: + inline std::vectorGetToggleGroup(){ + return toggleGroup; + } + inline void Select(){ + for(IToggleable*item:toggleGroup){ + item->selected=false; + } + selected=true; + } + inline bool IsSelected(){ + return selected; + } + inline void SetToggleGroup(){ + if(toggleGroupInitialized){ + std::cout<<"WARNING! Toggle group for this component was set twice for some reason! THIS SHOULD NOT BE HAPPENING!"<toggleGroup){ + this->toggleGroup=toggleGroup; + SetToggleGroup(); + } + inline IToggleable(){ + uninitializedToggleGroupItems.push_back(this); + if("debug_toggleable_items"_I){ + std::cout<<"\tInitialized Toggle Item Ptr: 0x"<toggleGroup; +private: + bool selected=false; + bool toggleGroupInitialized=false; + inline static std::vectoruninitializedToggleGroupItems; +}; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index 894c36a3..ee65efff 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 2393 +#define VERSION_BUILD 2404 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/configuration.txt b/Crawler/assets/config/configuration.txt index ed49527d..ab3df3e0 100644 --- a/Crawler/assets/config/configuration.txt +++ b/Crawler/assets/config/configuration.txt @@ -63,6 +63,9 @@ debug_collision_boxes = 0 # Shows pathfinding debugging debug_pathfinding = 0 +# Turn on to show when toggleable items are created and what their pointers are. This can help debug which toggleable item was not properly added to a tile group if you are getting Error TOGGLE. +debug_toggleable_items = 0 + # ms precision of animation tile caching. animation_tile_precision = 50