|
|
|
#pragma region License
|
|
|
|
/*
|
|
|
|
License (OLC-3)
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Copyright 2018 - 2023 OneLoneCoder.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 © 2023 The FreeType
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
All rights reserved.
|
|
|
|
*/
|
|
|
|
#pragma endregion
|
|
|
|
#include "Key.h"
|
|
|
|
#include "DEFINES.h"
|
|
|
|
#include "Crawler.h"
|
|
|
|
|
|
|
|
INCLUDE_game
|
|
|
|
|
|
|
|
Input::Input(InputType type,int key)
|
|
|
|
:type(type),key(key){}
|
|
|
|
|
|
|
|
bool Input::Pressed(){
|
|
|
|
if(!game->IsFocused())return false;
|
|
|
|
switch(type){
|
|
|
|
case KEY:{
|
|
|
|
return game->GetKey(Key(key)).bPressed;
|
|
|
|
}break;
|
|
|
|
case MOUSE:{
|
|
|
|
return game->GetMouse(key).bPressed;
|
|
|
|
}break;
|
|
|
|
case CONTROLLER:{
|
|
|
|
throw; //TODO: Throw for now, this control scheme is unsupported!
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::Held(){
|
|
|
|
if(!game->IsFocused())return false;
|
|
|
|
switch(type){
|
|
|
|
case KEY:{
|
|
|
|
return game->GetKey(Key(key)).bHeld;
|
|
|
|
}break;
|
|
|
|
case MOUSE:{
|
|
|
|
return game->GetMouse(key).bHeld;
|
|
|
|
}break;
|
|
|
|
case CONTROLLER:{
|
|
|
|
throw; //TODO: Throw for now, this control scheme is unsupported!
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::Released(){
|
|
|
|
if(!game->IsFocused())return false;
|
|
|
|
switch(type){
|
|
|
|
case KEY:{
|
|
|
|
return game->GetKey(Key(key)).bReleased;
|
|
|
|
}break;
|
|
|
|
case MOUSE:{
|
|
|
|
return game->GetMouse(key).bReleased;
|
|
|
|
}break;
|
|
|
|
case CONTROLLER:{
|
|
|
|
throw; //TODO: Throw for now, this control scheme is unsupported!
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Input::GetDisplayName(){
|
|
|
|
return GenericKey::keyLiteral.at({type,key});
|
|
|
|
}
|
|
|
|
|
|
|
|
InputGroup::InputGroup(){}
|
|
|
|
|
|
|
|
void InputGroup::AddKeybind(Input bind){
|
|
|
|
keys.insert(bind);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputGroup::RemoveKeybind(Input bind){
|
|
|
|
keys.erase(bind);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputGroup::Pressed(){
|
|
|
|
for(Input input:keys){
|
|
|
|
if(input.Pressed())return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputGroup::Held(){
|
|
|
|
for(Input input:keys){
|
|
|
|
if(input.Held())return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputGroup::Released(){
|
|
|
|
for(Input input:keys){
|
|
|
|
if(input.Released())return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InputGroup::GetDisplayName(){
|
|
|
|
std::string combinationDisplay="";
|
|
|
|
for(Input input:keys){
|
|
|
|
if(combinationDisplay.length()>0){
|
|
|
|
combinationDisplay+=",";
|
|
|
|
}
|
|
|
|
combinationDisplay+=input.GetDisplayName();
|
|
|
|
}
|
|
|
|
return combinationDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::pair<InputType,int>,std::string> GenericKey::keyLiteral={
|
|
|
|
{{KEY, NONE},""},
|
|
|
|
{{KEY, A},"A"},
|
|
|
|
{{KEY, B},"B"},
|
|
|
|
{{KEY, C},"C"},
|
|
|
|
{{KEY, D},"D"},
|
|
|
|
{{KEY, E},"E"},
|
|
|
|
{{KEY, F},"F"},
|
|
|
|
{{KEY, G},"G"},
|
|
|
|
{{KEY, H},"H"},
|
|
|
|
{{KEY, I},"I"},
|
|
|
|
{{KEY, J},"J"},
|
|
|
|
{{KEY, K},"L"},
|
|
|
|
{{KEY, L},"L"},
|
|
|
|
{{KEY, M},"M"},
|
|
|
|
{{KEY, N},"N"},
|
|
|
|
{{KEY, O},"O"},
|
|
|
|
{{KEY, P},"P"},
|
|
|
|
{{KEY, Q},"Q"},
|
|
|
|
{{KEY, R},"R"},
|
|
|
|
{{KEY, S},"S"},
|
|
|
|
{{KEY, T},"T"},
|
|
|
|
{{KEY, U},"U"},
|
|
|
|
{{KEY, V},"V"},
|
|
|
|
{{KEY, W},"W"},
|
|
|
|
{{KEY, X},"X"},
|
|
|
|
{{KEY, Y},"Y"},
|
|
|
|
{{KEY, Z},"Z"},
|
|
|
|
{{KEY, K0},"0"},
|
|
|
|
{{KEY, K1},"1"},
|
|
|
|
{{KEY, K2},"2"},
|
|
|
|
{{KEY, K3},"3"},
|
|
|
|
{{KEY, K4},"4"},
|
|
|
|
{{KEY, K5},"5"},
|
|
|
|
{{KEY, K6},"6"},
|
|
|
|
{{KEY, K7},"7"},
|
|
|
|
{{KEY, K8},"8"},
|
|
|
|
{{KEY, K9},"9"},
|
|
|
|
{{KEY, F1},"F1"},
|
|
|
|
{{KEY, F2},"F2"},
|
|
|
|
{{KEY, F3},"F3"},
|
|
|
|
{{KEY, F4},"F4"},
|
|
|
|
{{KEY, F5},"F5"},
|
|
|
|
{{KEY, F6},"F6"},
|
|
|
|
{{KEY, F7},"F7"},
|
|
|
|
{{KEY, F8},"F8"},
|
|
|
|
{{KEY, F9},"F9"},
|
|
|
|
{{KEY, F10},"F10"},
|
|
|
|
{{KEY, F11},"F11"},
|
|
|
|
{{KEY, F12},"F12"},
|
|
|
|
{{KEY, UP},"UP"},
|
|
|
|
{{KEY, DOWN},"DOWN"},
|
|
|
|
{{KEY, LEFT},"LEFT"},
|
|
|
|
{{KEY, RIGHT},"RIGHT"},
|
|
|
|
{{KEY, SPACE},"SPACE"},
|
|
|
|
{{KEY, TAB},"TAB"},
|
|
|
|
{{KEY, SHIFT},"SHIFT"},
|
|
|
|
{{KEY, CTRL},"CTRL"},
|
|
|
|
{{KEY, INS},"INS"},
|
|
|
|
{{KEY, DEL},"DEL"},
|
|
|
|
{{KEY, HOME},"HOME"},
|
|
|
|
{{KEY, END},"END"},
|
|
|
|
{{KEY, PGUP},"PGUP"},
|
|
|
|
{{KEY, PGDN},"PGDN"},
|
|
|
|
{{KEY, BACK},"BACK"},
|
|
|
|
{{KEY, ESCAPE},"ESC"},
|
|
|
|
{{KEY, RETURN},"ENTER"},
|
|
|
|
{{KEY, ENTER},"ENTER"},
|
|
|
|
{{KEY, PAUSE},"PAUSE"},
|
|
|
|
{{KEY, SCROLL},"SCR LK"},
|
|
|
|
{{KEY, NP0},"NP0"},
|
|
|
|
{{KEY, NP1},"NP1"},
|
|
|
|
{{KEY, NP2},"NP2"},
|
|
|
|
{{KEY, NP3},"NP3"},
|
|
|
|
{{KEY, NP4},"NP4"},
|
|
|
|
{{KEY, NP5},"NP5"},
|
|
|
|
{{KEY, NP6},"NP6"},
|
|
|
|
{{KEY, NP7},"NP7"},
|
|
|
|
{{KEY, NP8},"NP8"},
|
|
|
|
{{KEY, NP9},"NP9"},
|
|
|
|
{{KEY, NP_MUL},"NP*"},
|
|
|
|
{{KEY, NP_DIV},"NP/"},
|
|
|
|
{{KEY, NP_ADD},"NP+"},
|
|
|
|
{{KEY, NP_SUB},"NP-"},
|
|
|
|
{{KEY, NP_DECIMAL},"NP."},
|
|
|
|
{{KEY, PERIOD},"."},
|
|
|
|
{{KEY, EQUALS},"="},
|
|
|
|
{{KEY, COMMA},","},
|
|
|
|
{{KEY, MINUS},"-"},
|
|
|
|
{{KEY, OEM_1},";"},
|
|
|
|
{{KEY, OEM_2},"/"},
|
|
|
|
{{KEY, OEM_3},"~"},
|
|
|
|
{{KEY, OEM_4},"["},
|
|
|
|
{{KEY, OEM_5},"\\"},
|
|
|
|
{{KEY, OEM_6},"]"},
|
|
|
|
{{KEY, OEM_7},"\""},
|
|
|
|
{{KEY, OEM_8},"\\"},
|
|
|
|
{{KEY, CAPS_LOCK},"CAP LK"},
|
|
|
|
{{KEY, olc::ENUM_END},""},
|
|
|
|
{{MOUSE, Mouse::LEFT},"L.MOUSE"},
|
|
|
|
{{MOUSE, Mouse::RIGHT},"R.MOUSE"},
|
|
|
|
{{MOUSE, Mouse::MIDDLE},"M.MOUSE"},
|
|
|
|
};
|