Condensed DrawInput function to accept a variant instead of having double copies of the function.
This commit is contained in:
parent
6121c72152
commit
a6d2765585
@ -39,6 +39,8 @@ All rights reserved.
|
||||
#include "Key.h"
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
class InputGroup;
|
||||
|
||||
class Player;
|
||||
|
||||
struct PrecastData{
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
@ -53,7 +53,7 @@ void Menu::InitializeKeyboardInputWindow(){
|
||||
|
||||
inputKeyboardWindow->ADD("Keyboard Mapping Label",MenuLabel)(geom2d::rect<float>{{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<float>{{4,28},{menuSize.x-8,56.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END;
|
||||
inputKeyboardWindow->ADD("Menu Inputs Background",MenuLabel)(geom2d::rect<float>{{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++){
|
||||
|
@ -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::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,InputType type)const{
|
||||
std::optional<Input>primaryKey;
|
||||
switch(type){
|
||||
case CONTROLLER:primaryKey=GetPrimaryKey(CONTROLLER);break;
|
||||
@ -276,10 +276,21 @@ 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);
|
||||
|
||||
#pragma region Render Macro
|
||||
#define Render(rendererType) \
|
||||
std::get<rendererType*const>(renderer)->FillRectDecal(pos+offset+vf2d{-2.f,0.f},vf2d{textSize.x+4,textSize.y},buttonBackCol); \
|
||||
std::get<rendererType*const>(renderer)->FillRectDecal(pos+offset+vf2d{-1.f,-1.f},vf2d{textSize.x+2,textSize.y},buttonBackCol); \
|
||||
std::get<rendererType*const>(renderer)->FillRectDecal(pos+offset+vf2d{-1.f,0.f},vf2d{textSize.x+2,textSize.y+1.f},buttonBackCol); \
|
||||
std::get<rendererType*const>(renderer)->DrawStringPropDecal(pos+offset+vf2d{0.f,0.f},label,buttonTextCol);
|
||||
#pragma endregion
|
||||
|
||||
if(std::holds_alternative<AiL*const>(renderer)){
|
||||
Render(AiL);
|
||||
}else
|
||||
if(std::holds_alternative<TileTransformedView*const>(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!");
|
||||
|
||||
@ -287,65 +298,12 @@ void InputGroup::DrawInputView(const vf2d pos,const std::string_view displayText
|
||||
}
|
||||
}
|
||||
|
||||
void InputGroup::DrawInputView(const vf2d pos,const std::string_view displayText,const uint8_t alpha)const{
|
||||
void InputGroup::DrawInput(const std::variant<AiL*const,TileTransformedView*const>renderer,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);
|
||||
}
|
||||
|
||||
void InputGroup::DrawInput(const vf2d pos,const std::string_view displayText,const uint8_t alpha,InputType type)const{
|
||||
std::optional<Input>primaryKey;
|
||||
switch(type){
|
||||
case CONTROLLER:primaryKey=GetPrimaryKey(CONTROLLER);break;
|
||||
case MOUSE:primaryKey=GetPrimaryKey(MOUSE);break;
|
||||
default:primaryKey=GetPrimaryKey(KEY);break;
|
||||
}
|
||||
|
||||
vf2d buttonImgSize{};
|
||||
std::vector<std::variant<Decal*,std::string>>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<Decal*>(button)){
|
||||
Decal*img=std::get<Decal*>(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<std::string>(button)){
|
||||
std::string label=std::get<std::string>(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);
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
void InputGroup::DrawInput(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{
|
||||
|
@ -41,6 +41,10 @@ All rights reserved.
|
||||
#include <map>
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "safemap.h"
|
||||
#include "olcPGEX_TransformedView.h"
|
||||
#include <variant>
|
||||
|
||||
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::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const;
|
||||
void DrawInput(const std::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type)const;
|
||||
const std::optional<Input>GetPrimaryKey(InputType type)const;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -53,6 +53,7 @@ All rights reserved.
|
||||
#undef GetClassName
|
||||
struct DamageNumber;
|
||||
class MenuComponent;
|
||||
struct Ability;
|
||||
|
||||
struct CastInfo{
|
||||
std::string name="???";
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user