|
|
|
#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"
|
|
|
|
|
|
|
|
class AiL;
|
|
|
|
|
|
|
|
//Future-proof game controller support.
|
|
|
|
enum InputType{
|
|
|
|
KEY,
|
|
|
|
MOUSE,
|
|
|
|
CONTROLLER,
|
|
|
|
ANALOG,
|
|
|
|
};
|
|
|
|
|
|
|
|
//A generic class that represents any type of input.
|
|
|
|
class Input{
|
|
|
|
friend class InputGroup;
|
|
|
|
friend class State_MainMenu;
|
|
|
|
InputType type;
|
|
|
|
int key; //This will be interpreted differently depending on input type.
|
|
|
|
static bool usingGamepad;
|
|
|
|
static void SetUsingGamepad(const bool usingGamepad);
|
|
|
|
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();
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
void DrawInput(const std::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha,const InputType type)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;
|