From 7500ab4988e1bf55154c2e0f48269f766e4c0121 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 13 Sep 2015 15:59:42 +0200 Subject: [PATCH] Added code battle spectator mode switch --- data | 2 +- src/common/event.cpp | 3 +++ src/common/event.h | 1 + src/level/robotmain.cpp | 38 +++++++++++++++++++++++++++++++------- src/level/robotmain.h | 3 +++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/data b/data index 9a3bba50..d6a5cd49 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 9a3bba50a6e2a556e21728da15a3055c65910615 +Subproject commit d6a5cd49165903fdadbe63cd87d0982e8118b8af diff --git a/src/common/event.cpp b/src/common/event.cpp index b41d6b5e..9bd0cff9 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -501,6 +501,9 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_STUDIO_STEP] = "EVENT_STUDIO_STEP"; EVENT_TYPE_TEXT[EVENT_WRITE_SCENE_FINISHED] = "EVENT_WRITE_SCENE_FINISHED"; + + EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_START] = "EVENT_CODE_BATTLE_START"; + EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_SPECTATOR] = "EVENT_CODE_BATTLE_SPECTATOR"; } std::string ParseEventType(EventType eventType) diff --git a/src/common/event.h b/src/common/event.h index f8cedf8a..a905833e 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -533,6 +533,7 @@ 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 + EVENT_CODE_BATTLE_SPECTATOR = 2201, //!< button that controls the code battle spectator camera //! Maximum value of standard events EVENT_STD_MAX, diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index b9cf2fb2..8d7cd0a0 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -692,6 +692,11 @@ bool CRobotMain::ProcessEvent(Event &event) m_userPause = nullptr; } + if (event.type == EVENT_CODE_BATTLE_SPECTATOR) + { + SetCodeBattleSpectatorMode(!m_codeBattleSpectator); + } + // Management of the console. if (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(BACKQUOTE)) // Pause ? @@ -1820,7 +1825,7 @@ bool CRobotMain::SelectObject(CObject* obj, bool displayError) if (m_movie->IsExist()) return false; if (obj != nullptr && !IsSelectable(obj)) return false; - if (m_missionType == MISSION_CODE_BATTLE && m_codeBattleStarted) + if (m_missionType == MISSION_CODE_BATTLE && m_codeBattleStarted && m_codeBattleSpectator) { DeselectAll(); @@ -2644,12 +2649,9 @@ bool CRobotMain::EventFrame(const Event &event) if (!m_codeBattleStarted && m_userPause == nullptr) { m_codeBattleStarted = true; - DestroyCodeBattleInterface(); + CreateCodeBattleInterface(); - // Deselect object, but keep camera attached to it - CObject* obj = DeselectAll(); - SelectObject(obj, false); // this uses code battle selection mode already - m_camera->SetFixDirectionV(-0.25f*Math::PI); + SetCodeBattleSpectatorMode(true); m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); } @@ -5997,10 +5999,32 @@ void CRobotMain::CreateCodeBattleInterface() 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); + if (!m_codeBattleStarted) + { + pw->CreateButton(pos, ddim, 21, EVENT_CODE_BATTLE_START); + } + else + { + pw->CreateButton(pos, ddim, 13, EVENT_CODE_BATTLE_SPECTATOR); + } } void CRobotMain::DestroyCodeBattleInterface() { m_interface->DeleteControl(EVENT_WINDOW6); } + +void CRobotMain::SetCodeBattleSpectatorMode(bool mode) +{ + + // Deselect object, but keep camera attached to it + CObject* obj = DeselectAll(); + if (m_codeBattleSpectator) + obj = m_camera->GetControllingObject(); + + m_codeBattleSpectator = mode; + SelectObject(obj, false); // this uses code battle selection mode already + + if (mode) + m_camera->SetFixDirectionV(-0.25f*Math::PI); +} diff --git a/src/level/robotmain.h b/src/level/robotmain.h index c4394c02..604e5e59 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -418,6 +418,7 @@ protected: void CreateCodeBattleInterface(); void DestroyCodeBattleInterface(); + void SetCodeBattleSpectatorMode(bool mode); protected: @@ -537,6 +538,8 @@ protected: bool m_codeBattleInit = false; bool m_codeBattleStarted = false; + //! Code battle spectator mode, hides object UI, changes camera to CAM_TYPE_PLANE and allows for switching to free camera by clicking outside of any object + bool m_codeBattleSpectator = true; std::map m_teamNames;