From a6d2765585807b65b6c2e5729cdfee4892c47d0b Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 3 Feb 2024 00:16:10 -0600 Subject: [PATCH] Condensed DrawInput function to accept a variant instead of having double copies of the function. --- Adventures in Lestoria/Ability.h | 2 + Adventures in Lestoria/AdventuresInLestoria.h | 1 - .../InputDisplayComponent.h | 2 +- .../InputKeyboardWindow.cpp | 2 +- Adventures in Lestoria/Key.cpp | 76 +++++-------------- Adventures in Lestoria/Key.h | 10 ++- Adventures in Lestoria/NPC.cpp | 2 +- Adventures in Lestoria/Player.h | 1 + Adventures in Lestoria/Version.h | 2 +- 9 files changed, 30 insertions(+), 68 deletions(-) diff --git a/Adventures in Lestoria/Ability.h b/Adventures in Lestoria/Ability.h index 4543d941..a999bf27 100644 --- a/Adventures in Lestoria/Ability.h +++ b/Adventures in Lestoria/Ability.h @@ -39,6 +39,8 @@ All rights reserved. #include "Key.h" #include "olcPixelGameEngine.h" +class InputGroup; + class Player; struct PrecastData{ diff --git a/Adventures in Lestoria/AdventuresInLestoria.h b/Adventures in Lestoria/AdventuresInLestoria.h index 7ad537ed..f2e0e96e 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.h +++ b/Adventures in Lestoria/AdventuresInLestoria.h @@ -47,7 +47,6 @@ All rights reserved. #include "Map.h" #include "TMXParser.h" #include "olcUTIL_DataFile.h" -#include "Key.h" #include "GameState.h" #ifndef __EMSCRIPTEN__ #include "discord.h" diff --git a/Adventures in Lestoria/InputDisplayComponent.h b/Adventures in Lestoria/InputDisplayComponent.h index 0e24ae04..681c937c 100644 --- a/Adventures in Lestoria/InputDisplayComponent.h +++ b/Adventures in Lestoria/InputDisplayComponent.h @@ -49,6 +49,6 @@ public: protected: inline void DrawDecal(ViewPort&window,bool focused)override{ MenuComponent::DrawDecal(window,focused); - input.DrawInput(Menu::menus[parentMenu]->pos+vf2d{rect.middle().x,rect.bottom().end.y+1},""sv,255,type); + input.DrawInput(game,Menu::menus[parentMenu]->pos+vf2d{rect.middle().x,rect.bottom().end.y+1},""sv,255,type); } }; \ No newline at end of file diff --git a/Adventures in Lestoria/InputKeyboardWindow.cpp b/Adventures in Lestoria/InputKeyboardWindow.cpp index d465834b..0d98a33c 100644 --- a/Adventures in Lestoria/InputKeyboardWindow.cpp +++ b/Adventures in Lestoria/InputKeyboardWindow.cpp @@ -53,7 +53,7 @@ void Menu::InitializeKeyboardInputWindow(){ inputKeyboardWindow->ADD("Keyboard Mapping Label",MenuLabel)(geom2d::rect{{4,0},{menuSize.x-8.f,24.f}},"Keyboard Mappings",2.f,ComponentAttr::SHADOW|ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; - inputKeyboardWindow->ADD("Menu Inputs Background",MenuLabel)(geom2d::rect{{4,28},{menuSize.x-8,56.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; + inputKeyboardWindow->ADD("Menu Inputs Background",MenuLabel)(geom2d::rect{{4,32},{menuSize.x-8,56.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; for(int row=0;row<4;row++){ for(int col=0;col<2;col++){ diff --git a/Adventures in Lestoria/Key.cpp b/Adventures in Lestoria/Key.cpp index f921531c..2b746ebc 100644 --- a/Adventures in Lestoria/Key.cpp +++ b/Adventures in Lestoria/Key.cpp @@ -242,7 +242,7 @@ std::string InputGroup::GetDisplayName(){ return combinationDisplay; } -void InputGroup::DrawInputView(const vf2d pos,const std::string_view displayText,const uint8_t alpha,InputType type)const{ +void InputGroup::DrawInput(const std::variantrenderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,InputType type)const{ std::optionalprimaryKey; switch(type){ case CONTROLLER:primaryKey=GetPrimaryKey(CONTROLLER);break; @@ -276,76 +276,34 @@ void InputGroup::DrawInputView(const vf2d pos,const std::string_view displayText Pixel buttonTextCol="Interface.InputButtonTextCol"_Pixel; buttonBackCol.a=alpha; buttonTextCol.a=alpha; - game->view.FillRectDecal(pos+offset+vf2d{-2.f,0.f},vf2d{textSize.x+4,textSize.y},buttonBackCol); - game->view.FillRectDecal(pos+offset+vf2d{-1.f,-1.f},vf2d{textSize.x+2,textSize.y},buttonBackCol); - game->view.FillRectDecal(pos+offset+vf2d{-1.f,0.f},vf2d{textSize.x+2,textSize.y+1.f},buttonBackCol); - game->view.DrawStringPropDecal(pos+offset+vf2d{0.f,0.f},label,buttonTextCol); - offset.x+=textSize.x+"Interface.InputHelperSpacing"_I; - }else [[unlikely]]ERR("WARNING! Hit a state where no data is inside of the button! THIS SHOULD NOT BE HAPPENING!"); - - game->view.DrawShadowStringPropDecal(pos+offset,displayText,{255,255,255,alpha},{0,0,0,alpha}); - } -} -void InputGroup::DrawInputView(const vf2d pos,const std::string_view displayText,const uint8_t alpha)const{ - InputType primaryType; - if(Input::UsingGamepad())primaryType=CONTROLLER; - else if(Menu::UsingMouseNavigation())primaryType=MOUSE; - else primaryType=KEY; - DrawInputView(pos,displayText,alpha,primaryType); -} + #pragma region Render Macro + #define Render(rendererType) \ + std::get(renderer)->FillRectDecal(pos+offset+vf2d{-2.f,0.f},vf2d{textSize.x+4,textSize.y},buttonBackCol); \ + std::get(renderer)->FillRectDecal(pos+offset+vf2d{-1.f,-1.f},vf2d{textSize.x+2,textSize.y},buttonBackCol); \ + std::get(renderer)->FillRectDecal(pos+offset+vf2d{-1.f,0.f},vf2d{textSize.x+2,textSize.y+1.f},buttonBackCol); \ + std::get(renderer)->DrawStringPropDecal(pos+offset+vf2d{0.f,0.f},label,buttonTextCol); + #pragma endregion -void InputGroup::DrawInput(const vf2d pos,const std::string_view displayText,const uint8_t alpha,InputType type)const{ - std::optionalprimaryKey; - switch(type){ - case CONTROLLER:primaryKey=GetPrimaryKey(CONTROLLER);break; - case MOUSE:primaryKey=GetPrimaryKey(MOUSE);break; - default:primaryKey=GetPrimaryKey(KEY);break; - } - - vf2d buttonImgSize{}; - std::vector>buttonImgs; - if(primaryKey.has_value()){ - if(primaryKey.value().HasIcon()){ - buttonImgSize+=primaryKey.value().GetIcon().Sprite()->Size()+vf2d{"Interface.InputHelperSpacing"_F,"Interface.InputHelperSpacing"_F}; - buttonImgs.push_back(primaryKey.value().GetIcon().Decal()); - }else{ - buttonImgSize+=game->GetTextSizeProp(primaryKey.value().GetDisplayName())+vf2d{"Interface.InputHelperSpacing"_F,"Interface.InputHelperSpacing"_F}; - buttonImgs.push_back(primaryKey.value().GetDisplayName()); - } - } - vf2d descriptionTextSize=game->GetTextSizeProp(displayText); - vf2d offset=-((buttonImgSize+descriptionTextSize)/2.f); - for(auto&button:buttonImgs){ - if(std::holds_alternative(button)){ - Decal*img=std::get(button); - game->view.DrawDecal(pos+offset,img,{1.f,1.f},{255,255,255,alpha}); - offset.x+=img->sprite->width+"Interface.InputHelperSpacing"_I; - }else - if(std::holds_alternative(button)){ - std::string label=std::get(button); - vf2d textSize=game->GetTextSizeProp(label); - Pixel buttonBackCol="Interface.InputButtonBackCol"_Pixel; - Pixel buttonTextCol="Interface.InputButtonTextCol"_Pixel; - buttonBackCol.a=alpha; - buttonTextCol.a=alpha; - game->FillRectDecal(pos+offset+vf2d{-2.f,0.f},vf2d{textSize.x+4,textSize.y},buttonBackCol); - game->FillRectDecal(pos+offset+vf2d{-1.f,-1.f},vf2d{textSize.x+2,textSize.y},buttonBackCol); - game->FillRectDecal(pos+offset+vf2d{-1.f,0.f},vf2d{textSize.x+2,textSize.y+1.f},buttonBackCol); - game->DrawStringPropDecal(pos+offset+vf2d{0.f,0.f},label,buttonTextCol); + if(std::holds_alternative(renderer)){ + Render(AiL); + }else + if(std::holds_alternative(renderer)){ + Render(TileTransformedView); + } offset.x+=textSize.x+"Interface.InputHelperSpacing"_I; }else [[unlikely]]ERR("WARNING! Hit a state where no data is inside of the button! THIS SHOULD NOT BE HAPPENING!"); - game->DrawShadowStringPropDecal(pos+offset,displayText,{255,255,255,alpha},{0,0,0,alpha}); + game->view.DrawShadowStringPropDecal(pos+offset,displayText,{255,255,255,alpha},{0,0,0,alpha}); } } -void InputGroup::DrawInput(const vf2d pos,const std::string_view displayText,const uint8_t alpha)const{ +void InputGroup::DrawInput(const std::variantrenderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const{ InputType primaryType; if(Input::UsingGamepad())primaryType=CONTROLLER; else if(Menu::UsingMouseNavigation())primaryType=MOUSE; else primaryType=KEY; - DrawInput(pos,displayText,alpha,primaryType); + DrawInput(renderer,pos,displayText,alpha,primaryType); } const bool Input::HasIcon()const{ diff --git a/Adventures in Lestoria/Key.h b/Adventures in Lestoria/Key.h index c9865a98..20a91714 100644 --- a/Adventures in Lestoria/Key.h +++ b/Adventures in Lestoria/Key.h @@ -41,6 +41,10 @@ All rights reserved. #include #include "olcPixelGameEngine.h" #include "safemap.h" +#include "olcPGEX_TransformedView.h" +#include + +class AiL; //Future-proof game controller support. enum InputType{ @@ -94,10 +98,8 @@ public: const float Analog()const; std::string GetDisplayName(); //Draws an input display with accompanying text centered at given position. - void DrawInputView(const vf2d pos,const std::string_view displayText,const uint8_t alpha)const; - void DrawInputView(const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type)const; - void DrawInput(const vf2d pos,const std::string_view displayText,const uint8_t alpha)const; - void DrawInput(const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type)const; + void DrawInput(const std::variantrenderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const; + void DrawInput(const std::variantrenderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type)const; const std::optionalGetPrimaryKey(InputType type)const; }; diff --git a/Adventures in Lestoria/NPC.cpp b/Adventures in Lestoria/NPC.cpp index 56568571..e921fdfa 100644 --- a/Adventures in Lestoria/NPC.cpp +++ b/Adventures in Lestoria/NPC.cpp @@ -57,7 +57,7 @@ void Monster::STRATEGY::NPC(Monster&m,float fElapsedTime,std::string strategy){ vf2d nameTextSize=game->GetTextSizeProp(m.GetName()); uint8_t alpha=uint8_t(util::lerp(0.f,255.f,m.F(A::TARGET_TIMER)/ConfigFloat("Interaction Display Ease in Timer"))); game->view.DrawShadowStringPropDecal(m.GetPos()-vf2d{0,12}-nameTextSize/2.f,m.GetName(),{255,255,0},{0,0,0}); - game->KEY_CONFIRM.DrawInputView(m.GetPos()+vf2d{ConfigFloatArr("Interaction Display Offset",0),ConfigFloatArr("Interaction Display Offset",1)},"Interact",alpha); + game->KEY_CONFIRM.DrawInput(&game->view,m.GetPos()+vf2d{ConfigFloatArr("Interaction Display Offset",0),ConfigFloatArr("Interaction Display Offset",1)},"Interact",alpha); }); } m.phase=1; diff --git a/Adventures in Lestoria/Player.h b/Adventures in Lestoria/Player.h index daa86038..ff6a9a82 100644 --- a/Adventures in Lestoria/Player.h +++ b/Adventures in Lestoria/Player.h @@ -53,6 +53,7 @@ All rights reserved. #undef GetClassName struct DamageNumber; class MenuComponent; +struct Ability; struct CastInfo{ std::string name="???"; diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 4ca26078..70d86a72 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 3 #define VERSION_PATCH 0 -#define VERSION_BUILD 6784 +#define VERSION_BUILD 6812 #define stringify(a) stringify_(a) #define stringify_(a) #a