Add in keyboard mapping display settings window. Add in keybind display buttons.
This commit is contained in:
@@ -45,6 +45,7 @@ INCLUDE_game
|
||||
INCLUDE_GFX
|
||||
|
||||
bool Input::usingGamepad;
|
||||
safemap<std::string,InputGroup*>InputGroup::menuNamesToInputGroups;
|
||||
|
||||
Input::Input(InputType type,int key)
|
||||
:type(type),key(key){}
|
||||
@@ -241,15 +242,17 @@ std::string InputGroup::GetDisplayName(){
|
||||
return combinationDisplay;
|
||||
}
|
||||
|
||||
void InputGroup::DrawInput(const vf2d pos,const std::string_view displayText,const uint8_t alpha)const{
|
||||
void InputGroup::DrawInputView(const vf2d pos,const std::string_view displayText,const uint8_t alpha,InputType type)const{
|
||||
std::optional<Input>primaryKey;
|
||||
if(Input::UsingGamepad())primaryKey=GetPrimaryKey(CONTROLLER);
|
||||
else if(Menu::UsingMouseNavigation())primaryKey=GetPrimaryKey(MOUSE);
|
||||
else primaryKey=GetPrimaryKey(KEY);
|
||||
|
||||
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(displayText.length()>0&&primaryKey.has_value()){
|
||||
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());
|
||||
@@ -260,7 +263,6 @@ void InputGroup::DrawInput(const vf2d pos,const std::string_view displayText,con
|
||||
}
|
||||
vf2d descriptionTextSize=game->GetTextSizeProp(displayText);
|
||||
vf2d offset=-((buttonImgSize+descriptionTextSize)/2.f);
|
||||
if(buttonImgs.size()!=1)ERR("WARNING! Did not have two elements when rendering input button group display! THIS SHOULD NOT BE HAPPENING!")
|
||||
for(auto&button:buttonImgs){
|
||||
if(std::holds_alternative<Decal*>(button)){
|
||||
Decal*img=std::get<Decal*>(button);
|
||||
@@ -285,6 +287,67 @@ void InputGroup::DrawInput(const vf2d pos,const std::string_view displayText,con
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
const bool Input::HasIcon()const{
|
||||
return GenericKey::keyLiteral.at({type,key}).iconName.length()>0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user