Index: ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h =================================================================== --- ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h +++ ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -26,9 +26,12 @@ public: EnvironmentSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer); + void OnPickWaterHeight(wxCommandEvent& evt); virtual void OnMapReload(); virtual void RecomputeWaterData(wxCommandEvent& evt); + void UpdateEnvironmentSettings(); + protected: virtual void OnFirstDisplay(); Index: ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp =================================================================== --- ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp +++ ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -198,7 +198,8 @@ ////////////////////////////////////////////////////////////////////////// enum { - ID_RecomputeWaterData + ID_RecomputeWaterData, + ID_PickWaterHeight }; static void SendToGame(const AtlasMessage::sEnvironmentSettings& settings) { @@ -219,6 +220,7 @@ waterSizer->Add(new wxButton(scrolledWindow, ID_RecomputeWaterData, _("Reset Water Data")), wxSizerFlags().Expand()); waterSizer->Add(m_WaterTypeList = new VariableListBox(scrolledWindow, _("Water Type"), g_EnvironmentSettings.watertype), wxSizerFlags().Expand()); waterSizer->Add(new VariableSliderBox(scrolledWindow, _("Water height"), g_EnvironmentSettings.waterheight, 0.f, 1.2f), wxSizerFlags().Expand()); + waterSizer->Add(new wxButton(scrolledWindow, ID_PickWaterHeight, _("Pick Water Height")), wxSizerFlags().Expand()); waterSizer->Add(new VariableSliderBox(scrolledWindow, _("Water waviness"), g_EnvironmentSettings.waterwaviness, 0.f, 10.f), wxSizerFlags().Expand()); waterSizer->Add(new VariableSliderBox(scrolledWindow, _("Water murkiness"), g_EnvironmentSettings.watermurkiness, 0.f, 1.f), wxSizerFlags().Expand()); waterSizer->Add(new VariableSliderBox(scrolledWindow, _("Wind angle"), g_EnvironmentSettings.windangle, -M_PIf, M_PIf), wxSizerFlags().Expand()); @@ -269,15 +271,21 @@ qry_effects.Post(); m_PostEffectList->SetChoices(*qry_effects.posteffects); - AtlasMessage::qGetEnvironmentSettings qry_env; - qry_env.Post(); - g_EnvironmentSettings = qry_env.settings; - - g_EnvironmentSettings.NotifyObservers(); + UpdateEnvironmentSettings(); } void EnvironmentSidebar::OnMapReload() { + UpdateEnvironmentSettings(); +} + +void EnvironmentSidebar::RecomputeWaterData(wxCommandEvent& WXUNUSED(evt)) +{ + POST_COMMAND(RecalculateWaterData, (0.0f)); +} + +void EnvironmentSidebar::UpdateEnvironmentSettings() +{ AtlasMessage::qGetEnvironmentSettings qry_env; qry_env.Post(); g_EnvironmentSettings = qry_env.settings; @@ -285,12 +293,13 @@ g_EnvironmentSettings.NotifyObservers(); } -void EnvironmentSidebar::RecomputeWaterData(wxCommandEvent& WXUNUSED(evt)) +void EnvironmentSidebar::OnPickWaterHeight(wxCommandEvent& evt) { - POST_COMMAND(RecalculateWaterData, (0.0f)); + m_ScenarioEditor.GetToolManager().SetCurrentTool(_T("PickWaterHeight"), this); } BEGIN_EVENT_TABLE(EnvironmentSidebar, Sidebar) EVT_BUTTON(ID_RecomputeWaterData, EnvironmentSidebar::RecomputeWaterData) + EVT_BUTTON(ID_PickWaterHeight, EnvironmentSidebar::OnPickWaterHeight) END_EVENT_TABLE(); Index: ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PickWaterHeight.cpp =================================================================== --- ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PickWaterHeight.cpp +++ ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PickWaterHeight.cpp @@ -0,0 +1,72 @@ +/* Copyright (C) 2019 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "Common/Tools.h" +#include "Common/MiscState.h" +#include "GameInterface/Messages.h" +#include "ScenarioEditor/Sections/Environment/Environment.h" +#include "ScenarioEditor/ScenarioEditor.h" + +using AtlasMessage::Position; + +class PickWaterHeight : public StateDrivenTool +{ + DECLARE_DYNAMIC_CLASS(PickWaterHeight); + + // Uses a workaround to notify the environment settings directly, because + // we don't have any way to update them on the engine state change. + EnvironmentSidebar* m_Sidebar; + +public: + PickWaterHeight() + : m_Sidebar(nullptr) + { + SetState(&Waiting); + } + + virtual void Init(void* initData, ScenarioEditor* scenarioEditor) + { + StateDrivenTool::Init(initData, scenarioEditor); + + wxASSERT(initData); + m_Sidebar = static_cast(initData); + } + + void OnDisable() + { + if (m_Sidebar) + m_Sidebar->UpdateEnvironmentSettings(); + } + + struct sWaiting : public State + { + bool OnMouse(PickWaterHeight* WXUNUSED(obj), wxMouseEvent& evt) + { + if (evt.LeftDown()) + { + POST_COMMAND(PickWaterHeight, (evt.GetPosition())); + return true; + } + return false; + } + } + Waiting; +}; + +IMPLEMENT_DYNAMIC_CLASS(PickWaterHeight, StateDrivenTool); Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -198,6 +198,43 @@ }; END_COMMAND(RecalculateWaterData) +BEGIN_COMMAND(PickWaterHeight) +{ + entity_pos_t m_OldWaterHeight, m_NewWaterHeight; + + void Do() + { + CmpPtr cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + ENSURE(cmpWaterManager); + + CVector3D worldPos = msg->screenPos->GetWorldSpace(); + m_OldWaterHeight = cmpWaterManager->GetWaterLevel( + entity_pos_t::FromFloat(worldPos.X), entity_pos_t::FromFloat(worldPos.Z)); + m_NewWaterHeight = entity_pos_t::FromFloat(worldPos.Y); + SetWaterHeight(m_NewWaterHeight); + } + + void Redo() + { + SetWaterHeight(m_NewWaterHeight); + } + + void Undo() + { + SetWaterHeight(m_OldWaterHeight); + } + + void SetWaterHeight(entity_pos_t height) + { + CmpPtr cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + ENSURE(cmpWaterManager); + + cmpWaterManager->SetWaterLevel(height); + cmpWaterManager->RecomputeWaterData(); + } +}; +END_COMMAND(PickWaterHeight) + QUERYHANDLER(GetEnvironmentSettings) { Index: ps/trunk/source/tools/atlas/GameInterface/Messages.h =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Messages.h +++ ps/trunk/source/tools/atlas/GameInterface/Messages.h @@ -503,7 +503,9 @@ ((sEnvironmentSettings, settings)) ); -COMMAND(RecalculateWaterData, NOMERGE, ((float,unused))); +COMMAND(RecalculateWaterData, NOMERGE, ((float, unused))); + +COMMAND(PickWaterHeight, NOMERGE, ((Position, screenPos))); QUERY(GetSkySets, // no inputs