1
1
package extrasandredux .world .blocks .logic ;
2
2
3
+ import arc .*;
4
+ import arc .graphics .*;
3
5
import arc .graphics .g2d .*;
4
6
import arc .math .geom .*;
5
7
import arc .scene .ui .*;
8
10
import arc .util .*;
9
11
import arc .util .io .*;
10
12
import extrasandredux .util .*;
13
+ import mindustry .entities .units .*;
11
14
import mindustry .game .*;
12
15
import mindustry .gen .*;
13
16
import mindustry .graphics .*;
20
23
import static mindustry .Vars .*;
21
24
22
25
public class TurretController extends Block {
26
+ protected TextureRegion modeRegion ;
27
+ protected TextureRegion plugRegion0 , plugRegion1 ;
28
+
23
29
public TurretController (String name ){
24
30
super (name );
25
31
ESRUtls .applySandboxDefaults (this , Category .logic );
26
32
27
33
update = true ;
28
34
solid = true ;
29
35
rotate = true ;
36
+ rotateDraw = false ;
30
37
configurable = true ;
31
38
saveConfig = false ;
32
39
@@ -38,13 +45,44 @@ public TurretController(String name){
38
45
});
39
46
}
40
47
48
+ @ Override
49
+ public void load (){
50
+ super .load ();
51
+
52
+ modeRegion = Core .atlas .find (name + "-mode" );
53
+ plugRegion0 = Core .atlas .find (name + "-plug0" );
54
+ plugRegion1 = Core .atlas .find (name + "-plug1" );
55
+ }
56
+
57
+ @ Override
58
+ protected TextureRegion [] icons (){
59
+ return new TextureRegion []{Core .atlas .find (name + "-preview" )};
60
+ }
61
+
62
+ @ Override
63
+ public TextureRegion getPlanRegion (BuildPlan plan , Eachable <BuildPlan > list ){
64
+ return region ;
65
+ }
66
+
41
67
@ Override
42
68
public boolean canPlaceOn (Tile tile , Team team , int rotation ){
43
69
//Assumes this block is 1x1. Too lazy to bother with anything larger because I won't make something larger.
44
70
Tile front = tile .nearby (rotation );
45
71
return front != null && front .build instanceof TurretBuild ;
46
72
}
47
73
74
+ @ Override
75
+ public void drawPlanRegion (BuildPlan plan , Eachable <BuildPlan > list ){
76
+ super .drawPlanRegion (plan , list );
77
+ drawPlug (plan .x * 8f , plan .y * 8f , plan .rotation );
78
+ }
79
+
80
+ public void drawPlug (float x , float y , int rotation ){
81
+ TextureRegion region = rotation > 1 ? plugRegion1 : plugRegion0 ;
82
+ float flip = rotation % 2 == 0 ? 1 : -1 ;
83
+ Draw .rect (region , x , y , region .width / 4f , flip * region .height / 4f , rotation * 90f );
84
+ }
85
+
48
86
public class TurretControllerBuild extends Building {
49
87
public ControlState controlState = ControlState .off ;
50
88
/** x = angle, y = distance */
@@ -115,6 +153,17 @@ public void buildConfiguration(Table table){
115
153
});
116
154
}
117
155
156
+ @ Override
157
+ public void draw (){
158
+ super .draw ();
159
+
160
+ Draw .color (controlState .modeColor );
161
+ Draw .rect (modeRegion , x , y );
162
+ Draw .color ();
163
+ Draw .z (Layer .block + 0.01f );
164
+ drawPlug (x , y , rotation );
165
+ }
166
+
118
167
@ Override
119
168
public void drawSelect (){
120
169
Building front = front ();
@@ -143,12 +192,18 @@ public void read(Reads read, byte revision){
143
192
}
144
193
145
194
public enum ControlState {
146
- off ,
147
- on ,
148
- disable ;
195
+ off (Pal .darkerGray ),
196
+ on (Pal .heal ),
197
+ disable (Color .red );
198
+
199
+ public Color modeColor ;
149
200
150
201
public static ControlState [] all = values ();
151
202
203
+ ControlState (Color modeColor ){
204
+ this .modeColor = modeColor ;
205
+ }
206
+
152
207
public ControlState next (){
153
208
int next = ordinal () + 1 ;
154
209
if (next >= all .length ) next = 0 ;
0 commit comments