1 /* Copyright (C) 2009 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 "ScenarioEditor/ScenarioEditor.h" 21 #include "Common/Tools.h" 22 #include "Common/Brushes.h" 23 #include "GameInterface/Messages.h" 24 25 using AtlasMessage::Position; 26 27 class AlterElevation : public StateDrivenTool<AlterElevation> 28 { 29 DECLARE_DYNAMIC_CLASS(AlterElevation); 30 31 int m_Direction; // +1 = raise, -1 = lower 32 Position m_Pos; 33 34 public: AlterElevation()35 AlterElevation() 36 { 37 SetState(&Waiting); 38 } 39 40 OnEnable()41 void OnEnable() 42 { 43 g_Brush_Elevation.MakeActive(); 44 } 45 OnDisable()46 void OnDisable() 47 { 48 POST_MESSAGE(BrushPreview, (false, Position())); 49 } 50 51 52 struct sWaiting : public State 53 { OnMouseAlterElevation::sWaiting54 bool OnMouse(AlterElevation* obj, wxMouseEvent& evt) 55 { 56 if (evt.LeftDown()) 57 { 58 obj->m_Pos = Position(evt.GetPosition()); 59 SET_STATE(Raising); 60 return true; 61 } 62 else if (evt.RightDown()) 63 { 64 obj->m_Pos = Position(evt.GetPosition()); 65 SET_STATE(Lowering); 66 return true; 67 } 68 else if (evt.Moving()) 69 { 70 POST_MESSAGE(BrushPreview, (true, Position(evt.GetPosition()))); 71 return true; 72 } 73 else 74 { 75 return false; 76 } 77 } 78 } 79 Waiting; 80 81 82 struct sAltering_common : public State 83 { OnEnterAlterElevation::sAltering_common84 void OnEnter(AlterElevation* obj) 85 { 86 POST_MESSAGE(BrushPreview, (true, obj->m_Pos)); 87 } 88 OnLeaveAlterElevation::sAltering_common89 void OnLeave(AlterElevation*) 90 { 91 ScenarioEditor::GetCommandProc().FinaliseLastCommand(); 92 } 93 OnMouseAlterElevation::sAltering_common94 bool OnMouse(AlterElevation* obj, wxMouseEvent& evt) 95 { 96 if (IsMouseUp(evt)) 97 { 98 SET_STATE(Waiting); 99 return true; 100 } 101 else if (evt.Dragging()) 102 { 103 wxPoint pos = evt.GetPosition(); 104 obj->m_Pos = Position(pos); 105 POST_MESSAGE(BrushPreview, (true, obj->m_Pos)); 106 return true; 107 } 108 else 109 { 110 return false; 111 } 112 } 113 OnTickAlterElevation::sAltering_common114 void OnTick(AlterElevation* obj, float dt) 115 { 116 POST_COMMAND(AlterElevation, (obj->m_Pos, dt*g_Brush_Elevation.STRENGTH_MULTIPLIER*GetDirection()*g_Brush_Elevation.GetStrength())); 117 obj->m_Pos = Position::Unchanged(); 118 } 119 120 virtual bool IsMouseUp(wxMouseEvent& evt) = 0; 121 virtual int GetDirection() = 0; 122 }; 123 124 struct sRaising : public sAltering_common 125 { IsMouseUpAlterElevation::sRaising126 bool IsMouseUp(wxMouseEvent& evt) { return evt.LeftUp(); } GetDirectionAlterElevation::sRaising127 int GetDirection() { return +1; } 128 } 129 Raising; 130 131 struct sLowering : public sAltering_common 132 { IsMouseUpAlterElevation::sLowering133 bool IsMouseUp(wxMouseEvent& evt) { return evt.RightUp(); } GetDirectionAlterElevation::sLowering134 int GetDirection() { return -1; } 135 } 136 Lowering; 137 }; 138 139 IMPLEMENT_DYNAMIC_CLASS(AlterElevation, StateDrivenTool<AlterElevation>); 140