| 1 |
/* Copyright (C) 2025 Wildfire Games. |
| 2 |
* This file is part of 0 A.D. |
| 3 |
* |
| 4 |
* 0 A.D. is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* 0 A.D. is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "precompiled.h" |
| 19 |
|
| 20 |
#include "tools/atlas/AtlasUI/General/AtlasWindowCommandProc.h" |
| 21 |
#include "tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h" |
| 22 |
#include "tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.h" |
| 23 |
#include "tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h" |
| 24 |
#include "tools/atlas/GameInterface/MessagePasser.h" |
| 25 |
#include "tools/atlas/GameInterface/Messages.h" |
| 26 |
#include "tools/atlas/GameInterface/SharedTypes.h" |
| 27 |
|
| 28 |
#include <wx/defs.h> |
| 29 |
#include <wx/event.h> |
| 30 |
#include <wx/gdicmn.h> |
| 31 |
#include <wx/object.h> |
| 32 |
|
| 33 |
using AtlasMessage::Position; |
| 34 |
|
| 35 |
class FlattenElevation : public StateDrivenTool<FlattenElevation> |
| 36 |
{ |
| 37 |
DECLARE_DYNAMIC_CLASS(FlattenElevation); |
| 38 |
|
| 39 |
Position m_Pos; |
| 40 |
|
| 41 |
public: |
| 42 |
FlattenElevation() |
| 43 |
{ |
| 44 |
SetState(&Waiting); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
void OnEnable() |
| 49 |
{ |
| 50 |
g_Brush_Elevation.MakeActive(); |
| 51 |
} |
| 52 |
|
| 53 |
void OnDisable() |
| 54 |
{ |
| 55 |
POST_MESSAGE(BrushPreview, (false, Position())); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
struct sWaiting : public State |
| 60 |
{ |
| 61 |
bool OnMouse(FlattenElevation* obj, wxMouseEvent& evt) |
| 62 |
{ |
| 63 |
if (evt.LeftDown()) |
| 64 |
{ |
| 65 |
obj->m_Pos = Position(evt.GetPosition()); |
| 66 |
SET_STATE(Flattening); |
| 67 |
return true; |
| 68 |
} |
| 69 |
else if (evt.Moving()) |
| 70 |
{ |
| 71 |
POST_MESSAGE(BrushPreview, (true, Position(evt.GetPosition()))); |
| 72 |
return true; |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
return false; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
Waiting; |
| 81 |
|
| 82 |
|
| 83 |
struct sFlattening : public State |
| 84 |
{ |
| 85 |
void OnEnter(FlattenElevation* obj) |
| 86 |
{ |
| 87 |
POST_MESSAGE(BrushPreview, (true, obj->m_Pos)); |
| 88 |
} |
| 89 |
|
| 90 |
void OnLeave(FlattenElevation*) |
| 91 |
{ |
| 92 |
ScenarioEditor::GetCommandProc().FinaliseLastCommand(); |
| 93 |
} |
| 94 |
|
| 95 |
bool OnMouse(FlattenElevation* obj, wxMouseEvent& evt) |
| 96 |
{ |
| 97 |
if (evt.LeftUp()) |
| 98 |
{ |
| 99 |
SET_STATE(Waiting); |
| 100 |
return true; |
| 101 |
} |
| 102 |
else if (evt.Dragging()) |
| 103 |
{ |
| 104 |
wxPoint pos = evt.GetPosition(); |
| 105 |
obj->m_Pos = Position(pos); |
| 106 |
POST_MESSAGE(BrushPreview, (true, obj->m_Pos)); |
| 107 |
return true; |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
return false; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
void OnTick(FlattenElevation* obj, float dt) |
| 116 |
{ |
| 117 |
POST_COMMAND(FlattenElevation, (obj->m_Pos, dt*g_Brush_Elevation.STRENGTH_MULTIPLIER*g_Brush_Elevation.GetStrength())); |
| 118 |
obj->m_Pos = Position::Unchanged(); |
| 119 |
} |
| 120 |
} |
| 121 |
Flattening; |
| 122 |
}; |
| 123 |
|
| 124 |
IMPLEMENT_DYNAMIC_CLASS(FlattenElevation, StateDrivenTool<FlattenElevation>); |