diff --git a/src/common/event.cpp b/src/common/event.cpp index 10d1ae9f..4e7af795 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -522,6 +522,17 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_START] = "EVENT_CODE_BATTLE_START"; EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_SPECTATOR] = "EVENT_CODE_BATTLE_SPECTATOR"; + + EVENT_TYPE_TEXT[EVENT_VIEWPOINT0] = "EVENT_VIEWPOINT0"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT1] = "EVENT_VIEWPOINT1"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT2] = "EVENT_VIEWPOINT2"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT3] = "EVENT_VIEWPOINT3"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT4] = "EVENT_VIEWPOINT4"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT5] = "EVENT_VIEWPOINT5"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT6] = "EVENT_VIEWPOINT6"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT7] = "EVENT_VIEWPOINT7"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT8] = "EVENT_VIEWPOINT8"; + EVENT_TYPE_TEXT[EVENT_VIEWPOINT9] = "EVENT_VIEWPOINT9"; } std::string ParseEventType(EventType eventType) diff --git a/src/common/event.h b/src/common/event.h index 27ab1141..4b92727e 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -594,6 +594,17 @@ enum EventType EVENT_CODE_BATTLE_START = 2200, //!< button that starts the code battle EVENT_CODE_BATTLE_SPECTATOR = 2201, //!< button that controls the code battle spectator camera + //! Buttons that switch viewpoints + EVENT_VIEWPOINT0 = 3000, + EVENT_VIEWPOINT1 = 3001, + EVENT_VIEWPOINT2 = 3002, + EVENT_VIEWPOINT3 = 3003, + EVENT_VIEWPOINT4 = 3004, + EVENT_VIEWPOINT5 = 3005, + EVENT_VIEWPOINT6 = 3006, + EVENT_VIEWPOINT7 = 3007, + EVENT_VIEWPOINT8 = 3008, + EVENT_VIEWPOINT9 = 3009, //! Maximum value of standard events EVENT_STD_MAX, diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 3df62fe5..31aee5af 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -456,6 +456,8 @@ void CRobotMain::ChangePhase(Phase phase) m_movie->Flush(); m_movieInfoIndex = -1; m_shortCut = true; + + m_viewpoints.clear(); } ClearInterface(); @@ -744,6 +746,11 @@ bool CRobotMain::ProcessEvent(Event &event) SetCodeBattleSpectatorMode(!m_codeBattleSpectator); } + if (event.type >= EVENT_VIEWPOINT0 && event.type <= EVENT_VIEWPOINT9) + { + m_camera->SetScriptCamera(m_viewpoints[event.type - EVENT_VIEWPOINT0].eye, m_viewpoints[event.type - EVENT_VIEWPOINT0].look); + } + // Management of the console. if (event.type == EVENT_KEY_DOWN) { @@ -3528,6 +3535,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } + //! Note: This feature may be changed in next releases, + //! Places new viewpoint, which can be selected later in (currently only in Code Battle) UI. + //! Usage: View eye=x; y; z lookat=x; y; z + + if (line->GetCommand() == "View") + { + if(m_viewpoints.size() == 10) + { + GetLogger()->Warn("Reached limit of 10 viewpoints, next ones will be ommited.\n"); + continue; + } + Viewpoint tmp; + tmp.eye = line->GetParam("eye")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit; + tmp.look = line->GetParam("lookat")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit; + m_viewpoints.push_back(tmp); + continue; + } + if (line->GetCommand() == "EndMissionTake" && !resetObject) { auto endTake = MakeUnique(); @@ -5814,25 +5839,40 @@ void CRobotMain::CreateCodeBattleInterface() if (m_phase == PHASE_SIMUL) { Math::Point pos, ddim; + float offset = (ceil(m_viewpoints.size() / 2.0f) * 50); int numTeams = m_scoreboard ? GetAllTeams().size() : 0; assert(numTeams < EVENT_SCOREBOARD_MAX-EVENT_SCOREBOARD+1); float textHeight = m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); + //window ddim.x = 100.0f/640.0f; - ddim.y = 100.0f/480.0f + numTeams * textHeight; + ddim.y = (100.0f+offset)/480.0f + numTeams * textHeight; pos.x = 540.0f/640.0f; pos.y = 100.0f/480.0f; Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6); + //label text ddim.x = 100.0f/640.0f; ddim.y = 16.0f/480.0f; pos.x = 540.0f/640.0f; - pos.y = 178.0f/480.0f + numTeams * textHeight; + pos.y = (178.0f+offset)/480.0f + numTeams * textHeight; std::string text; GetResource(RES_EVENT, EVENT_LABEL_CODE_BATTLE, text); pw->CreateLabel(pos, ddim, 0, EVENT_LABEL_CODE_BATTLE, text); + //viewpoint selection section + ddim.x = 40.0f/640.0f; + ddim.y = 50.0f/640.0f; + for(unsigned int i = 0; iCreateButton(pos,ddim, 13, EventType(EVENT_VIEWPOINT0 + i)); + } + + //start/camera button 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; @@ -5930,6 +5970,7 @@ void CRobotMain::UpdateCodeBattleInterface() void CRobotMain::DestroyCodeBattleInterface() { + m_viewpoints.clear(); m_interface->DeleteControl(EVENT_WINDOW6); } diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 9b1511c0..8409ffed 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -150,6 +150,11 @@ struct MinMax int max = -1; }; +struct Viewpoint +{ + Math::Vector eye; + Math::Vector look; +}; const int SATCOM_HUSTON = 0; const int SATCOM_SAT = 1; @@ -717,4 +722,7 @@ protected: std::deque m_commandHistory; //! Index of currently selected element in command history int m_commandHistoryIndex; + + //! Vector of available viewpoints + std::vector m_viewpoints; };