From 51330dde5e6900a423f8e88ebc555375a5361aab Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 6 Sep 2015 19:12:00 +0200 Subject: [PATCH] Added code battle start button; fixed bug with starting code battle --- data | 2 +- src/common/event.h | 22 +++++++++--------- src/level/robotmain.cpp | 50 ++++++++++++++++++++++++++++++++++++++++- src/level/robotmain.h | 3 +++ src/ui/displayinfo.cpp | 6 +++++ src/ui/maindialog.cpp | 4 ++-- src/ui/studio.cpp | 4 ++-- 7 files changed, 75 insertions(+), 16 deletions(-) diff --git a/data b/data index 305cad6f..256cbfc7 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 305cad6f4361e612aed130ea59294240ddb9dcff +Subproject commit 256cbfc75da33250b331177b9d4e8d220e4fe17b diff --git a/src/common/event.h b/src/common/event.h index 68db83e3..9340e2dc 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -129,16 +129,16 @@ enum EventType EVENT_EDIT8 = 78, EVENT_EDIT9 = 79, - EVENT_WINDOW0 = 80, // the bottom panel - EVENT_WINDOW1 = 81, // map - EVENT_WINDOW2 = 82, // CDisplayText - EVENT_WINDOW3 = 83, // CStudio - EVENT_WINDOW4 = 84, // DisplayInfo - EVENT_WINDOW5 = 85, // setup - EVENT_WINDOW6 = 86, - EVENT_WINDOW7 = 87, - EVENT_WINDOW8 = 88, - EVENT_WINDOW9 = 89, // dialogue + EVENT_WINDOW0 = 80, //!< object interface (CObjectInterface + CAuto classes) + EVENT_WINDOW1 = 81, //!< CMainMap + EVENT_WINDOW2 = 82, //!< CDisplayText + EVENT_WINDOW3 = 83, //!< CStudio + EVENT_WINDOW4 = 84, //!< CDisplayInfo + EVENT_WINDOW5 = 85, //!< all menu windows + EVENT_WINDOW6 = 86, //!< code battle interface + EVENT_WINDOW7 = 87, //!< (unused) + EVENT_WINDOW8 = 88, //!< (unused) + EVENT_WINDOW9 = 89, //!< CMainDialog and CStudio file selector EVENT_LABEL0 = 90, EVENT_LABEL1 = 91, @@ -531,6 +531,8 @@ enum EventType EVENT_WRITE_SCENE_FINISHED = 2100, //!< indicates end of writing scene (writing screenshot image) + EVENT_CODE_BATTLE_START = 2200, //!< button that starts the code battle + //! Maximum value of standard events EVENT_STD_MAX, diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 367623de..dff1f0d8 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -678,6 +678,20 @@ bool CRobotMain::ProcessEvent(Event &event) return false; } + if (event.type == EVENT_UPDINTERFACE) + { + if (m_missionType == MISSION_CODE_BATTLE && !m_codeBattleStarted) + { + CreateCodeBattleInterface(); + } + } + + if (event.type == EVENT_CODE_BATTLE_START) + { + m_pause->DeactivatePause(m_userPause); + m_userPause = nullptr; + } + // Management of the console. if (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(BACKQUOTE)) // Pause ? @@ -2609,9 +2623,10 @@ bool CRobotMain::EventFrame(const Event &event) m_codeBattleInit = true; // Will start on resume } - if (!m_codeBattleStarted && m_userPause != nullptr) + if (!m_codeBattleStarted && m_userPause == nullptr) { m_codeBattleStarted = true; + DestroyCodeBattleInterface(); m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); } } @@ -3730,6 +3745,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_eventQueue->AddEvent(Event(EVENT_QUIT)); m_ui->ShowLoadingScreen(false); + if (m_missionType == MISSION_CODE_BATTLE) + { + CreateCodeBattleInterface(); + } CreateShortcuts(); } @@ -5932,3 +5951,32 @@ void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) m_sound->Play(target != nullptr ? SOUND_BUILD : SOUND_RECOVER); } + +void CRobotMain::CreateCodeBattleInterface() +{ + Math::Point pos, ddim; + + ddim.x = 100.0f/640.0f; + ddim.y = 100.0f/480.0f; + pos.x = 540.0f/640.0f; + pos.y = 100.0f/480.0f; + Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6); + + ddim.x = 100.0f/640.0f; + ddim.y = 16.0f/480.0f; + pos.x = 540.0f/640.0f; + pos.y = 178.0f/480.0f; + pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, "Code battle"); + + float titleBarSize = (11.0f/64.0f); // this is from the texture + ddim.x = 80.0f/640.0f; + ddim.y = ((1-titleBarSize)*100.0f-20.0f)/480.0f; + pos.x = 550.0f/640.0f; + pos.y = 110.0f/480.0f; + pw->CreateButton(pos, ddim, 21, EVENT_CODE_BATTLE_START); +} + +void CRobotMain::DestroyCodeBattleInterface() +{ + m_interface->DeleteControl(EVENT_WINDOW6); +} diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 14fa77d5..c4394c02 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -416,6 +416,9 @@ protected: void PushToSelectionHistory(CObject* obj); CObject* PopFromSelectionHistory(); + void CreateCodeBattleInterface(); + void DestroyCodeBattleInterface(); + protected: CController* m_ctrl = nullptr; diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index d1fdc845..5c394d80 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -367,6 +367,9 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_infoCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_INFO); + pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); + if (pw != nullptr) pw->ClearState(STATE_VISIBLE); + pos = m_infoActualPos = m_infoFinalPos; dim = m_infoActualDim = m_infoFinalDim; pw = m_interface->CreateWindows(pos, dim, 4, EVENT_WINDOW4); @@ -829,6 +832,9 @@ void CDisplayInfo::StopDisplayInfo() else { m_main->SetEditLock(false, false); + + pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); + if (pw != nullptr) pw->SetState(STATE_VISIBLE); } m_pause->DeactivatePause(m_satcomPause); m_satcomPause = nullptr; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 38d8e05e..e1e0aff4 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -369,7 +369,7 @@ void CMainDialog::StartDialog(Math::Point dim, bool fireParticles) if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); + if ( pw != nullptr ) pw->ClearState(STATE_VISIBLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW7)); if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); @@ -524,7 +524,7 @@ void CMainDialog::StopDialog() if ( pw != nullptr ) pw->SetState(STATE_ENABLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if ( pw != nullptr ) pw->SetState(STATE_ENABLE); + if ( pw != nullptr ) pw->SetState(STATE_VISIBLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW7)); if ( pw != nullptr ) pw->SetState(STATE_ENABLE); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 93a452d0..ad6b6a38 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1104,7 +1104,7 @@ void CStudio::StartDialog(StudioDialog type) if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW6)); - if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); + if ( pw != nullptr ) pw->ClearState(STATE_VISIBLE); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW7)); if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); @@ -1219,7 +1219,7 @@ void CStudio::StopDialog() if ( pw != nullptr ) pw->SetState(STATE_ENABLE); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW6)); - if ( pw != nullptr ) pw->SetState(STATE_ENABLE); + if ( pw != nullptr ) pw->SetState(STATE_VISIBLE); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW7)); if ( pw != nullptr ) pw->SetState(STATE_ENABLE);