The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
231 lines
8.1 KiB
231 lines
8.1 KiB
#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 <set>
|
|
#include <string>
|
|
#include <map>
|
|
#include "olcPixelGameEngine.h"
|
|
#include "safemap.h"
|
|
#include "olcPGEX_TransformedView.h"
|
|
#include <variant>
|
|
#include "IconType.h"
|
|
#include "olcPGEX_ViewPort.h"
|
|
#include "UndefKeys.h"
|
|
#ifndef __EMSCRIPTEN__
|
|
#include "steam/isteaminput.h"
|
|
#endif
|
|
#include "emscripten_compat.h"
|
|
|
|
class AiL;
|
|
|
|
//Future-proof game controller support.
|
|
enum InputType{
|
|
KEY,
|
|
MOUSE,
|
|
CONTROLLER,
|
|
STEAM,
|
|
ANALOG,
|
|
};
|
|
|
|
enum class Axis{
|
|
X,
|
|
Y,
|
|
};
|
|
|
|
namespace Steam{
|
|
enum SteamInput{
|
|
MOVE, //This is the left stick analog input. Whenever we use this, we assume left stick is being used.
|
|
SCROLL, //This is the right stick analog input. Whenever we use this, we assume right stick is being used.
|
|
BASIC_ATTACK,
|
|
DEFENSIVE,
|
|
MENU_PAUSE,
|
|
ABILITY_1,
|
|
ABILITY_2,
|
|
ABILITY_3,
|
|
ABILITY_4,
|
|
ITEM_1,
|
|
ITEM_2,
|
|
ITEM_3,
|
|
CONFIRM,
|
|
BACK,
|
|
FUNCTION_1,
|
|
FUNCTION_2,
|
|
UP,
|
|
DOWN,
|
|
LEFT,
|
|
RIGHT,
|
|
LOCK_UNLOCK_ACC,
|
|
FAST_SCROLL_UP,
|
|
FAST_SCROLL_DOWN,
|
|
};
|
|
};
|
|
|
|
using NumOfOrigins=uint8_t;
|
|
|
|
//A generic class that represents any type of input.
|
|
class Input{
|
|
friend class InputGroup;
|
|
friend class State_MainMenu;
|
|
friend class InputHelper;
|
|
friend class Menu;
|
|
friend class AiL;
|
|
InputType type;
|
|
int key; //This will be interpreted differently depending on input type.
|
|
static bool usingGamepad;
|
|
static void SetUsingGamepad(const bool usingGamepad);
|
|
static std::array<std::unordered_map<Steam::SteamInput,std::pair<std::string,HWButton>>,STEAM_INPUT_MAX_COUNT>enumToActionName;
|
|
static std::unordered_map<EInputActionOrigin,std::string>steamIconToGameIcon;
|
|
static std::unordered_map<Steam::SteamInput,std::pair<NumOfOrigins,std::array<EInputActionOrigin,STEAM_INPUT_MAX_ORIGINS>>>steamGameInputToOrigin; //Store the origins that steam knows about inside either the gameplay or menu input arrays provided. These are pairs where the first item is the number of origins for this input and the second item is the array itself.
|
|
static std::unordered_map<Steam::SteamInput,std::pair<NumOfOrigins,std::array<EInputActionOrigin,STEAM_INPUT_MAX_ORIGINS>>>steamGameInputToAnalogOrigin;
|
|
static void Initialize();
|
|
static void UpdateSteamInput();
|
|
static std::array<InputHandle_t,STEAM_INPUT_MAX_COUNT>steamControllers;
|
|
static uint8_t activeSteamControllerIndex;
|
|
static uint8_t controllerCount;
|
|
static std::vector<Steam::SteamInput>leftStickActionSets;
|
|
static std::vector<Steam::SteamInput>rightStickActionSets;
|
|
static void LoadSteamButtonIcons();
|
|
public:
|
|
Input(InputType type,int key);
|
|
bool Pressed();
|
|
//A version of Pressed() that will continuously return true after holding down for some time. Useful for scrolling through menus.
|
|
bool Held();
|
|
bool Released();
|
|
float Analog();
|
|
std::string GetDisplayName()const;
|
|
bool operator<(const Input&rhs)const{
|
|
return type<rhs.type||(type==rhs.type&&key<rhs.key);
|
|
}
|
|
static const bool UsingGamepad();
|
|
static const bool AxesActive();
|
|
static void StartVibration(const bool override=false);
|
|
static void StopVibration();
|
|
const InputType GetType()const;
|
|
const std::string str()const;
|
|
const bool HasIcon()const;
|
|
const bool HasExtendedIcons()const; //Whether or not this input has extended icons for all the button sets (See IconType.h)
|
|
const Renderable&GetIcon()const;
|
|
const Renderable&GetIcon(IconType type)const;
|
|
const int GetKeyCode()const;
|
|
friend const bool operator==(const Input&input1,const Input&input2);
|
|
std::string GetProperIconName(std::string currentIconName)const;
|
|
static void SetLightbar(const Pixel col);
|
|
static uint64_t ingameControlsHandle;
|
|
};
|
|
|
|
class InputGroup{
|
|
friend class AiL;
|
|
friend class Menu;
|
|
friend class State_OverworldMap;
|
|
friend class InputListener;
|
|
friend class SaveFile;
|
|
friend class State_MainMenu;
|
|
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;
|
|
static std::vector<std::string>menuInputGroups;
|
|
static std::vector<std::string>gameplayInputGroups;
|
|
void RemovePrimaryKeybind(InputType type);
|
|
void AddPrimaryKeybind(Input key);
|
|
|
|
float holdDownTime=0.f;
|
|
float initialHoldDownTime=0.f;
|
|
public:
|
|
InputGroup();
|
|
void AddKeybind(Input bind);
|
|
void RemoveKeybind(Input bind);
|
|
void SetNewPrimaryKeybind(Input key);
|
|
const bool Pressed()const;
|
|
//A version of Pressed() that will continuously return true after holding down for some time. Useful for scrolling through menus.
|
|
const bool PressedDAS();
|
|
const bool Held()const;
|
|
const bool Released();
|
|
const float Analog()const;
|
|
const float AnalogDAS(const float threshold=0.2f);
|
|
void ClearAllKeybinds();
|
|
std::string GetDisplayName();
|
|
//Draws an input display with accompanying text centered at given position.
|
|
void DrawPrimaryInput(const std::variant<AiL*const,TileTransformedView*const,ViewPort*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const;
|
|
void DrawPrimaryInput(const std::variant<AiL*const,TileTransformedView*const,ViewPort*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type,vf2d textScale={1.f,1.f})const;
|
|
void DrawInput(const std::variant<AiL*const,TileTransformedView*const,ViewPort*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type,vf2d textScale={1.f,1.f},const std::string_view preDisplayText="")const;
|
|
const std::optional<Input>GetPrimaryKey(InputType type)const;
|
|
};
|
|
|
|
class InputEngageGroup{
|
|
public:
|
|
static const bool VISIBLE=true;
|
|
static const bool NOT_VISIBLE=false;
|
|
enum EngageType{
|
|
Pressed,
|
|
PressedDAS,
|
|
Held,
|
|
Released,
|
|
Analog,
|
|
};
|
|
private:
|
|
InputGroup&group;
|
|
EngageType type;
|
|
bool labelVisible;
|
|
public:
|
|
InputEngageGroup(InputGroup&group,EngageType type=Released,const bool labelVisible=true);
|
|
const EngageType GetEngageType()const;
|
|
InputGroup&GetGroup()const;
|
|
const InputEngageGroup operator=(const InputEngageGroup&rhs);
|
|
const bool GetLabelVisible()const;
|
|
};
|
|
|
|
class GenericKey{
|
|
struct KeyInfo{
|
|
std::string displayName;
|
|
std::string iconName="";
|
|
std::string iconName2="";
|
|
std::string iconName3="";
|
|
};
|
|
public:
|
|
static std::map<std::pair<InputType,int>,KeyInfo>keyLiteral; //The displayed text for a given key for a given input type.
|
|
};
|
|
|
|
class InputListener{
|
|
public:
|
|
static void Update();
|
|
};
|
|
|
|
const bool operator<(const InputGroup&group1,const InputGroup&group2);
|
|
const bool operator<(const InputEngageGroup&group1,const InputEngageGroup&group2);
|
|
|
|
using enum InputEngageGroup::EngageType; |