diff --git a/source/code/HelpGamepadState.cpp b/source/code/HelpGamepadState.cpp index e5ff542..8b6c819 100644 --- a/source/code/HelpGamepadState.cpp +++ b/source/code/HelpGamepadState.cpp @@ -25,6 +25,11 @@ https://blockattack.net #include "global.hpp" #include "common.h" #include "MenuSystem.h" +#include "gamecontroller.h" + +const int xsize = 1024; +const int ysize = 768; +const int buttonOffset = 160; static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text){ field.SetHolder(holder); @@ -35,12 +40,30 @@ static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTex field.SetText(text); } +static void setHelpGamepadFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text){ + field.SetHolder(holder); + field.SetFont("freeserif"); + field.SetColor({255,255,255,255}); + field.SetFontSize(30); + field.SetOutline(1, {128,128,128,255}); + field.SetText(text); +} + + HelpGamepadState::HelpGamepadState() { setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), moveLabel, _("Move cursor")); setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), pushLabel, _("Push line")); setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), backLabel, _("Back (Menu)")); setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), switchLabel, _("Switch")); setHelpGamepadFont(&globalData.spriteHolder->GetDataHolder(), confirmLabel, _("Confirm")); + std::string s = _("Only SDL2 compatible controllers are supported!\nSupported controllers: "); + for (size_t i = 0 ; iGetDataHolder(), supportedControllers, s.c_str()); } HelpGamepadState::~HelpGamepadState() { @@ -59,6 +82,8 @@ void HelpGamepadState::ProcessInput(const SDL_Event& event, bool& processed) { } } +extern sago::SagoSprite bExit; + void HelpGamepadState::Draw(SDL_Renderer* target) { DrawBackground(target); const sago::SagoSprite& gamepad = globalData.spriteHolder->GetSprite("help_controller"); @@ -80,6 +105,9 @@ void HelpGamepadState::Draw(SDL_Renderer* target) { SDL_RenderDrawLine(target, 900, 207, 900, 400); switchLabel.Draw(target, 900, 404, sago::SagoTextField::Alignment::center); confirmLabel.Draw(target, 900, 404+30, sago::SagoTextField::Alignment::center); + bExit.Draw(globalData.screen, SDL_GetTicks(), xsize-buttonOffset, ysize-buttonOffset); + supportedControllers.Draw(target, 10, 600); + #if DEBUG static sago::SagoTextField mousePos; mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder()); @@ -91,5 +119,19 @@ void HelpGamepadState::Draw(SDL_Renderer* target) { } void HelpGamepadState::Update() { - + // If the mouse button is released, make bMouseUp equal true + if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) { + bMouseUp=true; + } + + if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { + bMouseUp = false; + + //The Score button: + if ((globalData.mousex>xsize-buttonOffset) && (globalData.mousexysize-buttonOffset) && (globalData.mousey controllerStatusMap; +static std::map gamecontrollers_assigned; +static std::vector supportedControllers; void GameControllerSetVerbose(bool value) { @@ -61,7 +63,6 @@ static std::string GetGuidAsHex(const SDL_JoystickGUID& guid) { return ret; } -static std::map gamecontrollers_assigned; static int GetNextPlayerByGui(const SDL_JoystickGUID& guid) { Config::getInstance()->setDefault("gc_AllToOnePlayer", "0"); @@ -100,6 +101,7 @@ void InitGameControllers() { SDL_JoystickGUID guid = SDL_JoystickGetGUID(j); int assingToPlayer = GetNextPlayerByGui(guid); controllerStatusMap[instanceId].player = assingToPlayer; + supportedControllers.push_back(GameControllerGetName(controller)); if (verbose) { std::cout << "Supported game controller detected: " << GameControllerGetName(controller) << ", mapping: " << SDL_GameControllerMapping(controller) << "\n"; std::cout << "Assigned to player: " << controllerStatusMap[instanceId].player << "\n"; @@ -108,6 +110,10 @@ void InitGameControllers() { } } +const std::vector& GetSupportedControllerNames() { + return supportedControllers; +} + void checkDeadZone(const SDL_Event& event) { if (event.type != SDL_CONTROLLERAXISMOTION) { return; //assert? diff --git a/source/code/gamecontroller.h b/source/code/gamecontroller.h index 8c02c58..0cff6b6 100644 --- a/source/code/gamecontroller.h +++ b/source/code/gamecontroller.h @@ -22,7 +22,8 @@ http://www.blockattack.net */ #include "SDL.h" - +#include +#include const int deadZoneLimit = 20000; @@ -35,6 +36,7 @@ bool isPlayerRightEvent(int playerNumber, const SDL_Event& event); bool isPlayerSwitchEvent(int playerNumber, const SDL_Event& event); bool isPlayerPushEvent(int playerNumber, const SDL_Event& event); void GameControllerSetVerbose(bool value); +const std::vector& GetSupportedControllerNames(); /** * Checks that the given event is in the dead zone. diff --git a/source/code/mainVars.inc b/source/code/mainVars.inc index e59b831..758d75f 100644 --- a/source/code/mainVars.inc +++ b/source/code/mainVars.inc @@ -44,8 +44,9 @@ http://blockattack.net const char sharedir[] = SHAREDIR; -//All graphic in the game (as pointers): +//All graphic in the game: sago::SagoSprite backgroundImage; //Stores the background image +sago::SagoSprite bExit; static sago::SagoSprite backBoard; //Stores the background to the board static sago::SagoSprite bForward; //The "forward" button #if NETWORK @@ -92,7 +93,6 @@ static sago::SagoSprite garbageGMR; static sago::SagoSprite transCover; //The transperant block, covers the upcomming static sago::SagoSprite bSkip; static sago::SagoSprite bRetry; -static sago::SagoSprite bExit; const int bExitSize = 100; //height and width of the exit button const int bExitOffset = 140; //pixels from the buttom right corner to the top left of the exit button