// // GamepadService.h // App // // Created by Ben Tkacheff on 1/21/15. // // #pragma once #include "V8Tree/Instance.h" #include "V8Tree/Service.h" #define RBX_MAX_GAMEPADS 8 namespace RBX { class BasePlayerGui; extern const char* const sGamepadService; typedef boost::unordered_map > Gamepad; typedef boost::unordered_map Gamepads; class GamepadService : public DescribedNonCreatable , public Service { private: typedef DescribedNonCreatable Super; Gamepads gamepads; boost::unordered_map gamepadNavigationEnabledMap; RBX::Timer repeatGuiSelectionTimer; RBX::Timer fastRepeatGuiSelectionTimer; bool autoGuiSelectionAllowed; // whether this game allows for automatic gui selection with gamepad keys Vector2 lastGuiSelectionDirection; // helper for determining how to use thumbstick for gui selection rbx::signals::scoped_connection updateInputConnection; rbx::signals::scoped_connection inputEndedConnection; rbx::signals::scoped_connection inputChangedConnection; rbx::signals::scoped_connection cameraCframeUpdateConnection; shared_ptr createInputObjectForGamepadKeyCode(RBX::KeyCode keyCode, RBX::InputObject::UserInputType gamepadType); void createControllerKeyMapForController(int controllerIndex); Vector2 getGuiSelectionDirection(const shared_ptr& event); bool isVectorInDeadzone(const Vector2& correctGuiDirection) const; GuiResponse autoSelectGui(); GuiObject* getRandomShownGuiObject(Instance* object); void currentCameraChanged(shared_ptr newCurrentCamera); void cameraCframeChanged(CoordinateFrame cframe); void updateOnInputStep(); void onInputChanged(const shared_ptr& event); void onInputEnded(const shared_ptr& event); GuiResponse process(const shared_ptr& event, BasePlayerGui* guiToProcess); // Instance /*override*/ void onServiceProvider(ServiceProvider* oldProvider, ServiceProvider* newProvider); public: GamepadService(); static InputObject::UserInputType getGamepadEnumForInt(int controllerIndex); static int getGamepadIntForEnum(InputObject::UserInputType gamepadEnum); Gamepad getGamepadState(int controllerIndex); bool setAutoGuiSelectionAllowed(bool value); bool getAutoGuiSelectionAllowed() const { return autoGuiSelectionAllowed; } bool isNavigationGamepad(InputObject::UserInputType gamepadType); void setNavigationGamepad(InputObject::UserInputType gamepadType, bool enabled); boost::unordered_map getNavigationGamepadMap() { return gamepadNavigationEnabledMap; } GuiResponse processDev(const shared_ptr& event); GuiResponse processCore(const shared_ptr& event); GuiResponse trySelectGuiObject(const Vector2& inputVector, const shared_ptr& event, BasePlayerGui* guiToProcess); GuiResponse trySelectGuiObject(const Vector2& inputVector); }; }