| 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/Observable.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/MiscState.h" |
| 24 |
#include "tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h" |
| 25 |
#include "tools/atlas/GameInterface/MessagePasser.h" |
| 26 |
#include "tools/atlas/GameInterface/Messages.h" |
| 27 |
#include "tools/atlas/GameInterface/SharedTypes.h" |
| 28 |
|
| 29 |
#include <string> |
| 30 |
#include <wx/defs.h> |
| 31 |
#include <wx/event.h> |
| 32 |
#include <wx/object.h> |
| 33 |
#include <wx/string.h> |
| 34 |
|
| 35 |
using AtlasMessage::Position; |
| 36 |
|
| 37 |
class FillTerrain : public StateDrivenTool<FillTerrain> |
| 38 |
{ |
| 39 |
DECLARE_DYNAMIC_CLASS(FillTerrain); |
| 40 |
|
| 41 |
Position m_Pos; |
| 42 |
Brush m_Brush; |
| 43 |
|
| 44 |
public: |
| 45 |
FillTerrain() |
| 46 |
{ |
| 47 |
m_Brush.SetSquare(2); |
| 48 |
SetState(&Waiting); |
| 49 |
} |
| 50 |
|
| 51 |
void OnEnable() |
| 52 |
{ |
| 53 |
m_Brush.MakeActive(); |
| 54 |
} |
| 55 |
|
| 56 |
void OnDisable() |
| 57 |
{ |
| 58 |
POST_MESSAGE(BrushPreview, (false, Position())); |
| 59 |
} |
| 60 |
|
| 61 |
struct sWaiting : public State |
| 62 |
{ |
| 63 |
bool OnMouse(FillTerrain* WXUNUSED(obj), wxMouseEvent& evt) |
| 64 |
{ |
| 65 |
if (evt.LeftDown()) |
| 66 |
{ |
| 67 |
Position pos(evt.GetPosition()); |
| 68 |
POST_MESSAGE(BrushPreview, (true, pos)); |
| 69 |
POST_COMMAND(FillTerrain, (pos, (std::wstring)g_SelectedTexture.wc_str())); |
| 70 |
return true; |
| 71 |
} |
| 72 |
else if (evt.Moving()) |
| 73 |
{ |
| 74 |
POST_MESSAGE(BrushPreview, (true, Position(evt.GetPosition()))); |
| 75 |
return true; |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
return false; |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
Waiting; |
| 84 |
}; |
| 85 |
|
| 86 |
IMPLEMENT_DYNAMIC_CLASS(FillTerrain, StateDrivenTool<FillTerrain>); |