diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp
index 7c92c08d45..2d9b659eef 100644
--- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp
+++ b/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 @@ END_EVENT_TABLE()
//////////////////////////////////////////////////////////////////////////
enum {
- ID_RecomputeWaterData
+ ID_RecomputeWaterData,
+ ID_PickWaterHeight
};
static void SendToGame(const AtlasMessage::sEnvironmentSettings& settings)
{
@@ -219,6 +220,7 @@ EnvironmentSidebar::EnvironmentSidebar(ScenarioEditor& scenarioEditor, wxWindow*
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,20 +271,12 @@ void EnvironmentSidebar::OnFirstDisplay()
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()
{
- AtlasMessage::qGetEnvironmentSettings qry_env;
- qry_env.Post();
- g_EnvironmentSettings = qry_env.settings;
-
- g_EnvironmentSettings.NotifyObservers();
+ UpdateEnvironmentSettings();
}
void EnvironmentSidebar::RecomputeWaterData(wxCommandEvent& WXUNUSED(evt))
@@ -290,7 +284,22 @@ 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;
+
+ g_EnvironmentSettings.NotifyObservers();
+}
+
+void EnvironmentSidebar::OnPickWaterHeight(wxCommandEvent& evt)
+{
+ 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();
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h
index 013acf103d..d2a2afe80c 100644
--- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h
+++ b/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 @@ class EnvironmentSidebar : public Sidebar
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();
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PickWaterHeight.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PickWaterHeight.cpp
new file mode 100644
index 0000000000..fddf852fa2
--- /dev/null
+++ b/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);
diff --git a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp
index 902c5a1389..252c70515b 100644
--- a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp
+++ b/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 @@ BEGIN_COMMAND(RecalculateWaterData)
};
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)
{
diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h
index 358690f6a6..46b5ef5f9f 100644
--- a/source/tools/atlas/GameInterface/Messages.h
+++ b/source/tools/atlas/GameInterface/Messages.h
@@ -503,7 +503,9 @@ COMMAND(SetEnvironmentSettings, MERGE, // merge lots of small changes into one u
((sEnvironmentSettings, settings))
);
-COMMAND(RecalculateWaterData, NOMERGE, ((float,unused)));
+COMMAND(RecalculateWaterData, NOMERGE, ((float, unused)));
+
+COMMAND(PickWaterHeight, NOMERGE, ((Position, screenPos)));
QUERY(GetSkySets,
// no inputs