#pragma region License /* License (OLC-3) ~~~~~~~~~~~~~~~ Copyright 2024 Joshua Sigona 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 #include #include #include "olcPixelGameEngine.h" #include "safemap.h" #include "olcPGEX_TransformedView.h" #include #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, TOGGLE_MAP, }; }; 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>,STEAM_INPUT_MAX_COUNT>enumToActionName; static std::unordered_mapsteamIconToGameIcon; static std::unordered_map>>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>>steamGameInputToAnalogOrigin; static void Initialize(); static void UpdateSteamInput(); static std::arraysteamControllers; static uint8_t activeSteamControllerIndex; static uint8_t controllerCount; static std::vectorleftStickActionSets; static std::vectorrightStickActionSets; 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 typekeys; std::vectorkeyOrder; //A list of keys inserted in order, for primary key mapping. static safemapmenuNamesToInputGroups; static std::vectormenuInputGroups; static std::vectorgameplayInputGroups; 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::variantrenderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const; void DrawPrimaryInput(const std::variantrenderer,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::variantrenderer,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::optionalGetPrimaryKey(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,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;