Refactored analog control system to use digital DAS input system with directional input support.
This commit is contained in:
parent
b0e9799624
commit
ce46a1d3d7
@ -108,13 +108,17 @@ InputGroup AiL::KEY_DOWN;
|
||||
InputGroup AiL::KEY_ATTACK;
|
||||
InputGroup AiL::KEY_CONFIRM;
|
||||
InputGroup AiL::KEY_MENU;
|
||||
InputGroup AiL::KEY_SCROLLUP;
|
||||
InputGroup AiL::KEY_SCROLLDOWN;
|
||||
InputGroup AiL::KEY_BACK;
|
||||
InputGroup AiL::KEY_START;
|
||||
InputGroup AiL::KEY_SELECT;
|
||||
InputGroup AiL::KEY_UNEQUIP;
|
||||
|
||||
InputGroup AiL::KEY_SCROLLDOWN;
|
||||
InputGroup AiL::KEY_SCROLLUP;
|
||||
InputGroup AiL::KEY_SCROLLLEFT;
|
||||
InputGroup AiL::KEY_SCROLLRIGHT;
|
||||
InputGroup AiL::KEY_SCROLLHORZ;
|
||||
InputGroup AiL::KEY_SCROLLVERT;
|
||||
InputGroup AiL::KEY_SCROLL;
|
||||
InputGroup AiL::KEY_CHANGE_LOADOUT;
|
||||
|
||||
@ -2505,8 +2509,19 @@ void AiL::InitializeDefaultKeybinds(){
|
||||
KEY_SELECT.AddKeybind({KEY,ESCAPE});
|
||||
KEY_SELECT.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::SELECT)});
|
||||
|
||||
KEY_SCROLL.AddKeybind({ANALOG,static_cast<int>(GPAxes::LY)});
|
||||
KEY_SCROLL.AddKeybind({ANALOG,static_cast<int>(GPAxes::RY)});
|
||||
KEY_SCROLLLEFT.AddKeybind({ANALOG,static_cast<int>(GPAxes::LX)});
|
||||
KEY_SCROLLLEFT.AddKeybind({ANALOG,static_cast<int>(GPAxes::RX)});
|
||||
KEY_SCROLLRIGHT.AddKeybind({ANALOG,static_cast<int>(GPAxes::LX)});
|
||||
KEY_SCROLLRIGHT.AddKeybind({ANALOG,static_cast<int>(GPAxes::RX)});
|
||||
KEY_SCROLLUP.AddKeybind({ANALOG,static_cast<int>(GPAxes::LY)});
|
||||
KEY_SCROLLUP.AddKeybind({ANALOG,static_cast<int>(GPAxes::RY)});
|
||||
KEY_SCROLLDOWN.AddKeybind({ANALOG,static_cast<int>(GPAxes::LY)});
|
||||
KEY_SCROLLDOWN.AddKeybind({ANALOG,static_cast<int>(GPAxes::RY)});
|
||||
KEY_SCROLLVERT.AddKeybind({ANALOG,static_cast<int>(GPAxes::LY)});
|
||||
KEY_SCROLLVERT.AddKeybind({ANALOG,static_cast<int>(GPAxes::RY)});
|
||||
KEY_SCROLLHORZ.AddKeybind({ANALOG,static_cast<int>(GPAxes::LX)});
|
||||
KEY_SCROLLHORZ.AddKeybind({ANALOG,static_cast<int>(GPAxes::RX)});
|
||||
KEY_SCROLL.AddKeybind({ANALOG,static_cast<int>(GPAxes::ALL)});
|
||||
|
||||
KEY_UNEQUIP.AddKeybind({KEY,R});
|
||||
KEY_UNEQUIP.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_U)});
|
||||
|
||||
@ -73,8 +73,6 @@ class AiL : public olc::PixelGameEngine
|
||||
SplashScreen splash;
|
||||
public:
|
||||
Pathfinding pathfinder;
|
||||
static InputGroup KEY_SCROLLUP;
|
||||
static InputGroup KEY_SCROLLDOWN;
|
||||
static InputGroup KEY_BACK;
|
||||
static InputGroup KEY_CONFIRM;
|
||||
static InputGroup KEY_ATTACK;
|
||||
@ -88,6 +86,12 @@ public:
|
||||
static InputGroup KEY_START;
|
||||
static InputGroup KEY_SELECT;
|
||||
|
||||
static InputGroup KEY_SCROLLDOWN;
|
||||
static InputGroup KEY_SCROLLUP;
|
||||
static InputGroup KEY_SCROLLLEFT;
|
||||
static InputGroup KEY_SCROLLRIGHT;
|
||||
static InputGroup KEY_SCROLLHORZ;
|
||||
static InputGroup KEY_SCROLLVERT;
|
||||
static InputGroup KEY_SCROLL;
|
||||
static InputGroup KEY_CHANGE_LOADOUT;
|
||||
|
||||
|
||||
@ -86,18 +86,6 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
|
||||
auto okButton=inventoryWindow->ADD("OK Button",MenuComponent)(geom2d::rect<float>{{windowSize.x/2-24,173.f},{48,12}},"Ok",[](MenuFuncData data){Menu::CloseMenu();return true;})END;
|
||||
|
||||
#pragma region ScrollWindow macro lambda
|
||||
#define ScrollWindow(amount) \
|
||||
[](MenuType type){ \
|
||||
auto scrollWindow=Component<InventoryScrollableWindowComponent>(type,"inventory"); \
|
||||
scrollWindow->Scroll(amount); \
|
||||
int invWidth=int((scrollWindow->rect.size.x-12)/(float(scrollWindow->options.size.x)+scrollWindow->options.padding)); /*The inventory width determines how many items to skip at a time.*/ \
|
||||
scrollWindow->SetSelectionSkipIncrement(invWidth); \
|
||||
float scrollAmt=amount*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F; \
|
||||
scrollWindow->IncreaseSelectionIndex(scrollAmt/24.f); \
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
inventoryWindow->SetupKeyboardNavigation(
|
||||
[](MenuType type,Data&returnData){ //On Open
|
||||
//Try to find the component that matches the loadout item we have on us.
|
||||
@ -123,9 +111,7 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
{game->KEY_BACK,{"Back",[](MenuType type){
|
||||
Menu::CloseMenu();
|
||||
}}},
|
||||
{{game->KEY_SCROLL,Analog},{"Scroll",ScrollWindow(game->KEY_SCROLL.Analog())}},
|
||||
{{game->KEY_SCROLLUP,Held},{"Scroll Up",ScrollWindow(-1.0f)}},
|
||||
{{game->KEY_SCROLLDOWN,Held},{"Scroll Down",ScrollWindow(1.0f)}},
|
||||
{{game->KEY_SCROLLVERT,Analog},{"Scroll",[](MenuType type){}}},
|
||||
}
|
||||
,{ //Button Navigation Rules
|
||||
{"OK Button",{
|
||||
|
||||
@ -260,6 +260,34 @@ const float InputGroup::Analog()const{
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
const float InputGroup::AnalogDAS(){
|
||||
for(Input input:keys){
|
||||
float analogVal=input.Analog();
|
||||
if(analogVal!=0.f&&initialHoldDownTime==0.f){
|
||||
initialHoldDownTime="Interface.InitialScrollDelay"_F;
|
||||
return analogVal;
|
||||
}else
|
||||
if(analogVal!=0.f&&initialHoldDownTime>0.f){
|
||||
initialHoldDownTime-=game->GetElapsedTime();
|
||||
if(initialHoldDownTime<=0.f){
|
||||
holdDownTime="Interface.ScrollDelay"_F;
|
||||
return analogVal;
|
||||
}
|
||||
return 0.f;
|
||||
}else
|
||||
if(analogVal!=0.f&&holdDownTime>0.f){
|
||||
holdDownTime-=game->GetElapsedTime();
|
||||
if(holdDownTime<=0.f){
|
||||
holdDownTime="Interface.ScrollDelay"_F;
|
||||
return analogVal;
|
||||
}
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
initialHoldDownTime=holdDownTime=0.f;
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
std::string InputGroup::GetDisplayName(){
|
||||
std::string combinationDisplay="";
|
||||
for(Input input:keys){
|
||||
@ -480,6 +508,7 @@ std::map<std::pair<InputType,int>,GenericKey::KeyInfo> GenericKey::keyLiteral={
|
||||
{{ANALOG, static_cast<int>(GPAxes::TR)},{"Right Trigger","themes/button_r2.png"}},
|
||||
{{ANALOG, static_cast<int>(GPAxes::DX)},{"Right/Left","themes/button_analogstick_horz.png"}},
|
||||
{{ANALOG, static_cast<int>(GPAxes::DY)},{"Up/Down","themes/button_analogstick_vert.png"}},
|
||||
{{ANALOG, static_cast<int>(GPAxes::ALL)},{"Analog Stick","themes/button_analogstick.png"}},
|
||||
};
|
||||
|
||||
void Input::SetUsingGamepad(const bool usingGamepad){
|
||||
|
||||
@ -111,6 +111,7 @@ public:
|
||||
const bool Held()const;
|
||||
const bool Released();
|
||||
const float Analog()const;
|
||||
const float AnalogDAS();
|
||||
std::string GetDisplayName();
|
||||
//Draws an input display with accompanying text centered at given position.
|
||||
void DrawInput(const std::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const;
|
||||
|
||||
@ -81,17 +81,6 @@ void Menu::InitializeLoadGameWindow(){
|
||||
onlineCharacterTab->SetSelectionType(HIGHLIGHT);
|
||||
#endif
|
||||
|
||||
#pragma region ScrollWindow macro lambda
|
||||
#define ScrollWindow(amount) \
|
||||
[](MenuType type){ \
|
||||
auto scrollWindow=Component<ScrollableWindowComponent>(type,"Game Files List"); \
|
||||
scrollWindow->Scroll(amount); \
|
||||
float scrollAmt=amount*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F;\
|
||||
/*Height of these buttons is 48.*/ \
|
||||
scrollWindow->IncreaseSelectionIndex(scrollAmt/48.f); \
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Keyboard Navigation Rules
|
||||
loadGameWindow->SetupKeyboardNavigation(
|
||||
[](MenuType type,Data&returnData){ //On Open
|
||||
@ -109,9 +98,7 @@ void Menu::InitializeLoadGameWindow(){
|
||||
{{game->KEY_BACK},{"Back to Title Screen",[](MenuType type){
|
||||
Component<MenuComponent>(type,"Go Back Button")->Click();
|
||||
}}},
|
||||
{{game->KEY_SCROLL,Analog},{"Scroll",ScrollWindow(game->KEY_SCROLL.Analog())}},
|
||||
{{game->KEY_SCROLLUP,Held},{"Scroll Up",ScrollWindow(-1.0f)}},
|
||||
{{game->KEY_SCROLLDOWN,Held},{"Scroll Down",ScrollWindow(1.0f)}},
|
||||
{{game->KEY_SCROLLVERT,Analog},{"Scroll",[](MenuType type){}}},
|
||||
}
|
||||
,{ //Button Navigation Rules
|
||||
{"Game Files List",{
|
||||
|
||||
@ -342,7 +342,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
if(navigationGroups.count(selectionButtonName)){
|
||||
Navigation nav=navigationGroups[selectionButtonName];
|
||||
|
||||
if(game->KEY_UP.PressedDAS()){
|
||||
if(game->KEY_UP.PressedDAS()||game->KEY_SCROLLUP.AnalogDAS()<-0.2f){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.up)));
|
||||
else
|
||||
@ -352,7 +352,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
SetSelection(returnData);
|
||||
}
|
||||
}
|
||||
if(game->KEY_DOWN.PressedDAS()){
|
||||
if(game->KEY_DOWN.PressedDAS()||game->KEY_SCROLLDOWN.AnalogDAS()>0.2f){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.down)));
|
||||
else
|
||||
@ -362,7 +362,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
SetSelection(returnData);
|
||||
}
|
||||
}
|
||||
if(game->KEY_LEFT.PressedDAS()){
|
||||
if(game->KEY_LEFT.PressedDAS()||game->KEY_SCROLLLEFT.AnalogDAS()<-0.2f){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.left)));
|
||||
else
|
||||
@ -372,7 +372,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
SetSelection(returnData);
|
||||
}
|
||||
}
|
||||
if(game->KEY_RIGHT.PressedDAS()){
|
||||
if(game->KEY_RIGHT.PressedDAS()||game->KEY_SCROLLRIGHT.AnalogDAS()>0.2f){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.right)));
|
||||
else
|
||||
@ -387,7 +387,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
|
||||
if(game->KEY_UP.Released()||game->KEY_RIGHT.Released()||game->KEY_LEFT.Released()||game->KEY_DOWN.Released()||
|
||||
game->KEY_BACK.Released()||game->KEY_CONFIRM.Released()||game->KEY_START.Released()||game->KEY_SELECT.Released()||
|
||||
game->KEY_SCROLLDOWN.Released()||game->KEY_SCROLLUP.Released()||game->KEY_SCROLL.Analog()!=0.f){
|
||||
game->KEY_SCROLLDOWN.Released()||game->KEY_SCROLLUP.Released()||game->KEY_SCROLLVERT.Analog()!=0.f){
|
||||
SetMouseNavigation(game->GetMouse(Mouse::LEFT).bReleased||game->GetMouse(Mouse::RIGHT).bReleased||game->GetMouse(Mouse::MIDDLE).bReleased); //If a click occurs we use mouse controls.
|
||||
buttonHoldTime=0;
|
||||
}
|
||||
|
||||
@ -74,8 +74,8 @@ void Menu::InitializeOverworldMapLevelWindow(){
|
||||
{{game->KEY_CHANGE_LOADOUT},{"Change Loadout",[](MenuType type){
|
||||
Component<MenuComponent>(type,"Change Loadout Button")->Click();
|
||||
}}},
|
||||
{{game->KEY_SCROLL,Analog},{"Scroll Encounters",[](MenuType type){
|
||||
Component<EncountersSpawnListScrollableWindowComponent>(type,"Spawns List")->Scroll(game->KEY_SCROLL.Analog());
|
||||
{{game->KEY_SCROLLVERT,Analog},{"Scroll Encounters",[](MenuType type){
|
||||
Component<EncountersSpawnListScrollableWindowComponent>(type,"Spawns List")->Scroll(game->KEY_SCROLLVERT.Analog());
|
||||
}}},
|
||||
{{game->KEY_SCROLLUP,Held},{"",[](MenuType type){
|
||||
Component<EncountersSpawnListScrollableWindowComponent>(type,"Spawns List")->Scroll(1.f);
|
||||
|
||||
@ -105,16 +105,6 @@ public:
|
||||
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos,rect.size},game->GetMousePos())&& //Make sure the mouse is inside the parent window component first....
|
||||
geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos,child->rect.size},game->GetMousePos());
|
||||
}
|
||||
|
||||
inline void SetSelectionSkipIncrement(const int selectionSkipIncrement){
|
||||
this->selectionSkipIncrement=selectionSkipIncrement;
|
||||
}
|
||||
|
||||
inline void IncreaseSelectionIndex(const float val){
|
||||
float prevIndex=selectionIndex/selectionSkipIncrement;
|
||||
selectionIndex=std::clamp(selectionIndex+val,0.f,float(components.size()-1));
|
||||
if(size_t(prevIndex)!=size_t(selectionIndex/selectionSkipIncrement)){Menu::menus[parentMenu]->SetSelection(components[size_t(selectionIndex)],false);}
|
||||
}
|
||||
protected:
|
||||
virtual inline vf2d GetScrollAmount()const{
|
||||
return scrollOffset;
|
||||
|
||||
@ -56,4 +56,5 @@ void State_MainMenu::OnUserUpdate(AiL*game){
|
||||
};
|
||||
void State_MainMenu::Draw(AiL*game){
|
||||
TitleScreen::Draw();
|
||||
game->DrawOGStringDecal({0,0},"DOWN: "+std::to_string(game->KEY_SCROLLVERT.Analog()));
|
||||
};
|
||||
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 6923
|
||||
#define VERSION_BUILD 6933
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
||||
BIN
Adventures in Lestoria/assets/themes/button_analogstick.png
Normal file
BIN
Adventures in Lestoria/assets/themes/button_analogstick.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
@ -151,6 +151,7 @@ namespace olc {
|
||||
TR = 3,
|
||||
DX = 6,
|
||||
DY = 7,
|
||||
ALL = 8, //This does not actually do anything, but is useful for detecting an icon for any analog stick control!
|
||||
};
|
||||
#pragma endregion
|
||||
|
||||
|
||||
@ -1162,6 +1162,7 @@ namespace olc
|
||||
void DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f, 1.0f }, const olc::Pixel& tint = olc::WHITE);
|
||||
// Draws a multiline string as a decal, with tiniting and scaling
|
||||
void DrawStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false);
|
||||
void DrawOGStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
|
||||
void DrawStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }, const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false);
|
||||
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false);
|
||||
@ -3375,6 +3376,29 @@ namespace olc
|
||||
void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint)
|
||||
{ DrawPartialWarpedDecal(decal, &pos[0], source_pos, source_size, tint); }
|
||||
|
||||
void PixelGameEngine::DrawOGStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale)
|
||||
{
|
||||
olc::vf2d spos = { 0.0f, 0.0f };
|
||||
for (auto c : sText)
|
||||
{
|
||||
if (c == '\n')
|
||||
{
|
||||
spos.x = 0; spos.y += 8.0f * scale.y;
|
||||
}
|
||||
else if (c == '\t')
|
||||
{
|
||||
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t ox = (c - 32) % 16;
|
||||
int32_t oy = (c - 32) / 16;
|
||||
DrawPartialDecal(pos + spos, fontRenderable.Decal(), {float(ox) * 8.0f, float(oy) * 8.0f}, {8.0f, 8.0f}, scale, col);
|
||||
spos.x += 8.0f * scale.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PixelGameEngine::DrawStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const olc::vf2d& scale,const float width,const bool disableDynamicScaling)
|
||||
{
|
||||
struct DecalData{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user