Added any keybind detection to PGE and began implementing menu helper innterfaces

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/35/head
Nic0Nic0Nii 1 year ago
parent d576e6143e
commit ef63a07f5c
  1. 5
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 1
      Adventures in Lestoria/AdventuresInLestoria.h
  3. 4
      Adventures in Lestoria/GameState.cpp
  4. 2
      Adventures in Lestoria/GameState.h
  5. 8
      Adventures in Lestoria/InputNewKeybindWindow.cpp
  6. 8
      Adventures in Lestoria/Key.cpp
  7. 3
      Adventures in Lestoria/Key.h
  8. 2
      Adventures in Lestoria/MonsterAttribute.h
  9. 59
      Adventures in Lestoria/State_Keybind.cpp
  10. 46
      Adventures in Lestoria/State_Keybind.h
  11. 33
      Adventures in Lestoria/State_OverworldMap.cpp
  12. 2
      Adventures in Lestoria/State_OverworldMap.h
  13. 5
      Adventures in Lestoria/olcPixelGameEngine.h

@ -3075,4 +3075,9 @@ const std::string_view AiL::GetCurrentMapDisplayName()const{
const uint8_t AiL::BossEncounterMobCount()const{
return totalBossEncounterMobs;
}
void AiL::GetAnyKeyPress(Key key){
GameState::STATE->GetAnyKeyPress(key);
}

@ -154,6 +154,7 @@ public:
bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override;
bool OnUserDestroy() override;
void GetAnyKeyPress(Key key)override;
public:
geom2d::rect<float>NO_COLLISION={{0.f,0.f,},{0.f,0.f}};
TileTransformedView view;

@ -77,4 +77,6 @@ void GameState::ChangeState(States::State newState,float fadeOutDuration){
}
}
GameState::~GameState(){}
GameState::~GameState(){}
void GameState::GetAnyKeyPress(Key k){}

@ -50,6 +50,7 @@ namespace States{
MAIN_MENU,
LEVEL_COMPLETE,
STORY,
KEYBIND,
};
};
@ -65,5 +66,6 @@ public:
virtual void OnStateChange(GameState*prevState)=0;
virtual void OnUserUpdate(AiL*game)=0;
virtual void Draw(AiL*game)=0;
virtual void GetAnyKeyPress(Key k);
static void ChangeState(States::State newState,float fadeOutDuration=0);
};

@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Portions of this software are copyright <EFBFBD> 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
@ -39,8 +39,12 @@ All rights reserved.
#include "Menu.h"
#include "MenuLabel.h"
using A=Attribute;
void Menu::InitializeNewKeybindInputWindow(){
Menu*newKeybindWindow=CreateMenu(NEW_INPUT,CENTERED,vf2d{192,96});
newKeybindWindow->ADD("New Keybind Label",MenuLabel)(geom2d::rect<float>{{0.f,24.f},{192.f,24.f}},"Press a new key for {}",2.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
newKeybindWindow->B(A::IS_KEYBOARD)=true;
newKeybindWindow->S(A::KEYBIND)="";
newKeybindWindow->ADD("New Keybind Label",MenuLabel)(geom2d::rect<float>{{0.f,24.f},{192.f,96.f}},"Press a new key for '{}'\n\nPress Esc to cancel.",1.5f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
}

@ -535,4 +535,12 @@ InputGroup&InputEngageGroup::GetGroup()const{
const InputEngageGroup InputEngageGroup::operator=(const InputEngageGroup&rhs){
return InputEngageGroup{rhs.group,rhs.type};
}
void InputGroup::RemovePrimaryKeybind(InputType type){
std::erase(keyOrder.front());
}
void InputGroup::AddPrimaryKeybind(InputType type){
}

@ -85,6 +85,7 @@ public:
class InputGroup{
friend class AiL;
friend class Menu;
friend class State_Keybind;
std::set<Input>keys;
std::vector<Input>keyOrder; //A list of keys inserted in order, for primary key mapping.
static safemap<std::string,InputGroup*>menuNamesToInputGroups;
@ -92,6 +93,8 @@ public:
InputGroup();
void AddKeybind(Input bind);
void RemoveKeybind(Input bind);
void RemovePrimaryKeybind(InputType type);
void AddPrimaryKeybind(InputType type);
const bool Pressed()const;
const bool Held()const;
const bool Released()const;

@ -95,4 +95,6 @@ enum class Attribute{
COLLIDED_WITH_PLAYER, //A boolean flag that is set to true when an enemy makes contact with the player.
LAST_BGM_VOLUME,
LAST_SFX_VOLUME,
IS_KEYBOARD,
KEYBIND,
};

@ -0,0 +1,59 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "State_Keybind.h"
#include "VisualNovel.h"
#include "Menu.h"
#include "Key.h"
using A=Attribute;
void State_Keybind::OnStateChange(GameState*prevState){
Menu::CloseAllMenus();
};
void State_Keybind::OnUserUpdate(AiL*game){
};
void State_Keybind::Draw(AiL*game){
};
void State_Keybind::GetAnyKeyPress(Key key){
Input previousPrimaryKey=InputGroup::menuNamesToInputGroups[Menu::menus[NEW_INPUT].S(A::KEYBIND)]->keyOrder[0];
InputGroup::menuNamesToInputGroups[Menu::menus[NEW_INPUT].S(A::KEYBIND)]->RemoveKeybind({KEY,previousPrimaryKey});
}

@ -0,0 +1,46 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "GameState.h"
class State_Keybind:public GameState{
virtual void OnStateChange(GameState*prevState)override final;
virtual void OnUserUpdate(AiL*game)override final;
virtual void Draw(AiL*game)override final;
virtual void GetAnyKeyPress(Key key)override final;
};

@ -97,39 +97,6 @@ void State_OverworldMap::OnUserUpdate(AiL*game){
Menu::OpenMenu(OVERWORLD_MENU);
}
#pragma region Audio Test
if(game->GetKey(K1).bPressed){
Audio::Play("sfx100v2_loop_water_01.mp3"_SFX);
}
if(game->GetKey(F1).bPressed){
Audio::PlayBGM("foresty1_1");
lastAudioTime=0.f;
}else
if(game->GetKey(F2).bPressed){
Audio::PlayBGM("foresty0");
lastAudioTime=0.f;
}
if(game->GetKey(K2).bPressed){
Audio::SetAudioEvent("Default Volume");
lastEventTime=0.f;
}
if(game->GetKey(K3).bPressed){
Audio::SetAudioEvent("LowHealth");
lastEventTime=0.f;
}
if(game->GetKey(K4).bPressed){
Audio::SetAudioEvent("InCombat");
lastEventTime=0.f;
}
if(game->GetKey(K5).bPressed){
Audio::SetAudioEvent("Underwater");
lastEventTime=0.f;
}
lastEventTime=std::clamp(lastEventTime+game->GetElapsedTime(),0.f,5.0f);
lastAudioTime=std::clamp(lastAudioTime+game->GetElapsedTime(),0.f,5.0f);
#pragma endregion
#pragma region Handle Connection Point Clicking and Movement
for(ConnectionPoint&cp:connections){
if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)

@ -46,8 +46,6 @@ class State_OverworldMap:public GameState{
float currentTime=0;
vf2d playerTargetPos;
const float playerMoveSpd=48.0;
float lastEventTime=0.f;
float lastAudioTime=0.f;
public:
State_OverworldMap();
static std::vector<ConnectionPoint>connections;

@ -994,6 +994,7 @@ namespace olc
virtual bool OnUserUpdate(float fElapsedTime);
// Called once on application termination, so you can be one clean coder
virtual bool OnUserDestroy();
virtual void GetAnyKeyPress(Key key);
// Called when a text entry is confirmed with "enter" key
virtual void OnTextEntryComplete(const std::string& sText);
@ -4413,6 +4414,9 @@ namespace olc
bool PixelGameEngine::OnUserDestroy()
{ return true; }
void PixelGameEngine::GetAnyKeyPress(Key key)
{ }
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); }
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; }
@ -4639,6 +4643,7 @@ namespace olc
{
pKeys[i].bPressed = !pKeys[i].bHeld;
pKeys[i].bHeld = true;
GetAnyKeyPress(i);
}
else
{

Loading…
Cancel
Save