11using CentrED . Map ;
2+ using CentrED . Network ;
23using CentrED . UI ;
3- using CentrED . UI . Windows ;
44using Microsoft . Xna . Framework . Input ;
55using static CentrED . Application ;
66
@@ -10,31 +10,31 @@ namespace CentrED.Tools;
1010public abstract class BaseTool : Tool
1111{
1212 // Properties to track area operations
13- //TODO: Move these to DrawTool!
14- protected bool IsAreaOperation { get ; private set ; }
15- protected ushort AreaStartX { get ; private set ; }
16- protected ushort AreaStartY { get ; private set ; }
17- protected ushort AreaEndX { get ; private set ; }
18- protected ushort AreaEndY { get ; private set ; }
13+ protected bool AreaMode ;
14+ protected TileObject ? AreaStartTile ;
15+ protected RectU16 Area ;
1916
20- public void OnAreaOperationStart ( ushort x , ushort y )
17+ protected virtual void OnAreaOperationStart ( TileObject ? o )
2118 {
22- IsAreaOperation = true ;
23- AreaStartX = x ;
24- AreaStartY = y ;
25- AreaEndX = x ;
26- AreaEndY = y ;
19+ if ( o == null )
20+ return ;
21+
22+ AreaStartTile = o ;
23+ Area = new RectU16 ( o . Tile . X , o . Tile . Y , o . Tile . X , o . Tile . Y ) ;
2724 }
2825
29- public void OnAreaOperationUpdate ( ushort x , ushort y )
26+ protected virtual void OnAreaOperationUpdate ( TileObject ? to )
3027 {
31- AreaEndX = x ;
32- AreaEndY = y ;
28+ if ( to == null )
29+ return ;
30+
31+ Area . X2 = to . Tile . X ;
32+ Area . Y2 = to . Tile . Y ;
3333 }
34-
35- public void OnAreaOperationEnd ( )
34+
35+ protected virtual void OnAreaOperationEnd ( )
3636 {
37- IsAreaOperation = false ;
37+ AreaStartTile = null ;
3838 }
3939
4040 protected static readonly Random Random = Random . Shared ;
@@ -44,9 +44,7 @@ public void OnAreaOperationEnd()
4444
4545 protected static int _chance = 100 ;
4646 protected bool Pressed ;
47- protected bool AreaMode ;
4847 protected bool TopTilesOnly = true ;
49- private TileObject ? _areaStartTile ;
5048
5149 internal override void Draw ( )
5250 {
@@ -93,138 +91,77 @@ public sealed override void OnKeyReleased(Keys key)
9391 public sealed override void OnMousePressed ( TileObject ? o )
9492 {
9593 Pressed = true ;
96- if ( AreaMode && _areaStartTile == null && o != null )
94+ if ( AreaMode )
9795 {
98- TileObject to = o ;
99- var tilesWindow = UIManager . GetWindow < TilesWindow > ( ) ;
100- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && o is VirtualLayerTile )
101- {
102- to = CEDGame . MapManager . LandTiles [ to . Tile . X , to . Tile . Y ] ;
103- }
104- _areaStartTile = to ;
105-
106- OnAreaOperationStart ( to . Tile . X , to . Tile . Y ) ;
96+ OnAreaOperationStart ( o ) ;
10797 }
10898 CEDClient . BeginUndoGroup ( ) ;
10999 }
110100
111101 public sealed override void OnMouseReleased ( TileObject ? o )
112102 {
113- var tilesWindow = UIManager . GetWindow < TilesWindow > ( ) ;
114-
115103 if ( Pressed )
116104 {
117105 if ( AreaMode )
118106 {
119- foreach ( var to in MapManager . GetTiles ( _areaStartTile , o , TopTilesOnly ) )
107+ foreach ( var to in MapManager . GetTiles ( AreaStartTile , o , TopTilesOnly ) )
120108 {
121- TileObject to2 = to ;
122- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to2 is VirtualLayerTile )
123- {
124- to2 = CEDGame . MapManager . LandTiles [ to2 . Tile . X , to2 . Tile . Y ] ;
125- }
126- InternalApply ( to2 ) ;
127- GhostClear ( to2 ) ;
109+ InternalApply ( to ) ;
110+ GhostClear ( to ) ;
128111 }
112+ OnAreaOperationEnd ( ) ;
129113 }
130114 else
131115 {
132- TileObject to = o ;
133- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to is VirtualLayerTile )
134- {
135- to = CEDGame . MapManager . LandTiles [ to . Tile . X , to . Tile . Y ] ;
136- }
137- InternalApply ( to ) ;
138- GhostClear ( to ) ;
116+ InternalApply ( o ) ;
117+ GhostClear ( o ) ;
139118 }
140119 }
141120 Pressed = false ;
142- _areaStartTile = null ;
143-
144- if ( AreaMode )
145- {
146- OnAreaOperationEnd ( ) ;
147- }
148121
149122 CEDClient . EndUndoGroup ( ) ;
150123 }
151124
152125
153126 public sealed override void OnMouseEnter ( TileObject ? o )
154127 {
155- if ( o == null )
156- return ;
157-
158- if ( AreaMode && Pressed )
159- {
160- OnAreaOperationUpdate ( o . Tile . X , o . Tile . Y ) ;
161- }
162-
163- var tilesWindow = UIManager . GetWindow < TilesWindow > ( ) ;
164-
165128 if ( AreaMode && Pressed )
166129 {
167- foreach ( var to in MapManager . GetTiles ( _areaStartTile , o , TopTilesOnly ) )
130+ OnAreaOperationUpdate ( o ) ;
131+ foreach ( var to in MapManager . GetTiles ( AreaStartTile , o , TopTilesOnly ) )
168132 {
169133 if ( Random . Next ( 100 ) < _chance )
170134 {
171- TileObject to2 = to ;
172- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to2 is VirtualLayerTile )
173- {
174- to2 = CEDGame . MapManager . LandTiles [ to2 . Tile . X , to2 . Tile . Y ] ;
175- }
176- GhostApply ( to2 ) ;
135+ GhostApply ( to ) ;
177136 }
178137 }
179138 }
180139 else
181140 {
182141 if ( Random . Next ( 100 ) < _chance )
183142 {
184- TileObject to = o ;
185- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to is VirtualLayerTile )
186- {
187- to = CEDGame . MapManager . LandTiles [ to . Tile . X , to . Tile . Y ] ;
188- }
189- GhostApply ( to ) ;
143+ GhostApply ( o ) ;
190144 }
191145 }
192146 }
193147
194148 public sealed override void OnMouseLeave ( TileObject ? o )
195149 {
196- var tilesWindow = UIManager . GetWindow < TilesWindow > ( ) ;
197-
198- if ( Pressed && ! AreaMode )
199- {
200- TileObject to = o ;
201- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to is VirtualLayerTile )
202- {
203- to = CEDGame . MapManager . LandTiles [ to . Tile . X , to . Tile . Y ] ;
204- }
205- InternalApply ( to ) ;
206- }
207- if ( Pressed && AreaMode )
150+ if ( Pressed )
208151 {
209- foreach ( var to in MapManager . GetTiles ( _areaStartTile , o , TopTilesOnly ) )
152+ if ( AreaMode )
210153 {
211- TileObject to2 = to ;
212- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to2 is VirtualLayerTile )
154+ foreach ( var to in MapManager . GetTiles ( AreaStartTile , o , TopTilesOnly ) )
213155 {
214- to2 = CEDGame . MapManager . LandTiles [ to2 . Tile . X , to2 . Tile . Y ] ;
156+ GhostClear ( to ) ;
215157 }
216- GhostClear ( to2 ) ;
217158 }
218- }
219- else
220- {
221- TileObject to = o ;
222- if ( CEDGame . MapManager . UseVirtualLayer && tilesWindow . LandMode && to is VirtualLayerTile )
159+ else
223160 {
224- to = CEDGame . MapManager . LandTiles [ to . Tile . X , to . Tile . Y ] ;
161+ InternalApply ( o ) ;
225162 }
226- GhostClear ( to ) ;
227163 }
164+ GhostClear ( o ) ;
228165 }
229166
230167 public override void Apply ( TileObject ? o )
0 commit comments