diff --git a/resources/po/planetblupi.pot b/resources/po/planetblupi.pot index 36bc15f3..11753a47 100644 --- a/resources/po/planetblupi.pot +++ b/resources/po/planetblupi.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-17 14:11+0100\n" +"POT-Creation-Date: 2021-02-09 02:45-0600\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/event.cxx b/src/event.cxx index a05b353c..d4bdc88c 100644 --- a/src/event.cxx +++ b/src/event.cxx @@ -81,10 +81,7 @@ typedef struct { Sint16 reserve2[88]; } DescInfo; -// Toutes les premières lettres doivent -// être différentes ! - -static char cheat_code[9][20] = { +static char cheat_code[MAXCHEAT][CHEATLENGTH] = { "vision", // 0 "power", // 1 "lonesome", // 2 @@ -1669,6 +1666,9 @@ CEvent::CEvent () memset (m_textToolTips, 0, sizeof (m_textToolTips)); memset (m_libelle, 0, sizeof (m_libelle)); + for (i = 0; i < MAXCHEAT; i++) + m_bCheatCandidates[i] = true; + for (i = 0; i < MAXBUTTON; i++) m_lastFloor[i] = 0; @@ -5690,7 +5690,7 @@ CEvent::TreatEventBase (const SDL_Event & event) Sint32 i; Sounds sound; char c; - bool bEnable; + bool bIncrement = false; DemoRecEvent (event); @@ -5701,96 +5701,61 @@ CEvent::TreatEventBase (const SDL_Event & event) { if (m_posCheat == 0) // première lettre ? { - m_rankCheat = -1; - for (i = 0; i < 9; i++) + for (i = 0; i < MAXCHEAT; i++) { if ((char) event.key.keysym.sym == cheat_code[i][0]) { - m_rankCheat = i; - break; + m_bCheatCandidates[i] = true; + m_posCheat = 1; + } + else + { + m_bCheatCandidates[i] = false; } } } - if (m_rankCheat != -1) + else if (m_posCheat > 0) { - c = cheat_code[m_rankCheat][m_posCheat]; - if (m_posCheat != 0 && m_rankCheat == 8) - c++; // CONSTRUIRE ? - if ((char) event.key.keysym.sym == c) + bIncrement = false; + for (i = 0; i < MAXCHEAT; i++) { - m_posCheat++; - if (cheat_code[m_rankCheat][m_posCheat] == 0) + if (m_posCheat >= CHEATLENGTH) { - bEnable = true; - if (m_phase == EV_PHASE_PLAY) - { - if (m_rankCheat == 0) // vision ? - m_pDecor->EnableFog (false); - else if ( - m_rankCheat == 1 || // power ? - m_rankCheat == 2) // lonesome ? - m_pDecor->BlupiCheat (m_rankCheat); - } - - switch (m_rankCheat) - { - case 3: // allmissions ? - { - m_bAllMissions = !m_bAllMissions; - bEnable = m_bAllMissions; - break; - } - case 4: // quick ? - { - m_bSpeed = !m_bSpeed; - bEnable = m_bSpeed; - break; - } - case 5: // helpme ? - { - m_bHelp = !m_bHelp; - bEnable = m_bHelp; - break; - } - case 6: // invincible ? - { - m_pDecor->SetInvincible (!m_pDecor->GetInvincible ()); - bEnable = m_pDecor->GetInvincible (); - break; - } - case 7: // superblupi ? - { - m_pDecor->SetSuper (!m_pDecor->GetSuper ()); - bEnable = m_pDecor->GetSuper (); - break; - } - case 8: // construire ? - { - m_bAccessBuild = !m_bAccessBuild; - bEnable = m_bAccessBuild; - break; - } - } - - if (m_phase != EV_PHASE_PLAY) - ChangePhase (m_phase); - - pos.x = LXIMAGE () / 2; - pos.y = LYIMAGE () / 2; - if (bEnable) - m_pSound->PlayImage (SOUND_GOAL, pos); - else - m_pSound->PlayImage (SOUND_BOING, pos); - - m_rankCheat = -1; - m_posCheat = 0; + m_posCheat = 0; + break; + } + + if (!m_bCheatCandidates[i]) + continue; + + c = cheat_code[i][m_posCheat]; + + if (i == 8) // CONSTRUIRE ? + c++; + + if ((char) event.key.keysym.sym == c) + { + if (!bIncrement) + m_posCheat++; + bIncrement = true; + } + else + { + m_bCheatCandidates[i] = false; + } + + if (cheat_code[i][m_posCheat] == 0) + { + HandleCheat (i); + m_posCheat = 0; } - return true; } + if (bIncrement) + return true; + else + m_posCheat = 0; } } - m_rankCheat = -1; - m_posCheat = 0; if (m_phase == EV_PHASE_INTRO1) { @@ -6426,3 +6391,56 @@ CEvent::PushUserEvent (Sint32 code, void * data) SDL_PushEvent (&event); } + +void +CEvent::HandleCheat (Sint32 index) +{ + bool bEnable = true; + if (m_phase == EV_PHASE_PLAY) + { + if (index == 0) // vision ? + m_pDecor->EnableFog (false); + else if ( + index == 1 || // power ? + index == 2) // lonesome ? + m_pDecor->BlupiCheat (index); + } + + switch (index) + { + case 3: // allmissions ? + m_bAllMissions = !m_bAllMissions; + bEnable = m_bAllMissions; + break; + case 4: // quick ? + m_bSpeed = !m_bSpeed; + bEnable = m_bSpeed; + break; + case 5: // helpme ? + m_bHelp = !m_bHelp; + bEnable = m_bHelp; + break; + case 6: // invincible ? + m_pDecor->SetInvincible (!m_pDecor->GetInvincible ()); + bEnable = m_pDecor->GetInvincible (); + break; + case 7: // superblupi ? + m_pDecor->SetSuper (!m_pDecor->GetSuper ()); + bEnable = m_pDecor->GetSuper (); + break; + case 8: // construire ? + m_bAccessBuild = !m_bAccessBuild; + bEnable = m_bAccessBuild; + break; + } + + if (m_phase != EV_PHASE_PLAY) + ChangePhase (m_phase); + + if (bEnable) + m_pSound->PlayImage (SOUND_GOAL, {LXIMAGE () / 2, 0}); + else + m_pSound->PlayImage (SOUND_BOING, {LXIMAGE () / 2, 0}); + + return; +} diff --git a/src/event.h b/src/event.h index 0dfd9b07..082a198c 100644 --- a/src/event.h +++ b/src/event.h @@ -31,6 +31,9 @@ class CMovie; +#define MAXCHEAT 9 +#define CHEATLENGTH 20 + ///////////////////////////////////////////////////////////////////////////// typedef struct { @@ -159,6 +162,8 @@ class CEvent static void PushUserEvent (Sint32 code, void * data = nullptr); + void HandleCheat (Sint32 index); + protected: void DrawTextCenter (const char * text, Sint32 x, Sint32 y, Sint32 font = 0); bool CreateButtons (Sint32 phase); @@ -279,6 +284,7 @@ class CEvent std::string m_updateVersion; Uint32 shiftDirection; bool statDisabled; + bool m_bCheatCandidates[MAXCHEAT]; }; /////////////////////////////////////////////////////////////////////////////