Condensed DrawInput function to accept a variant instead of having double copies of the function.
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user