Skip to content

Commit d300d2d

Browse files
committed
Turret controller sprites
1 parent 2789c3c commit d300d2d

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed
Loading
Loading
Loading
Loading
634 Bytes
Loading

src/extrasandredux/world/blocks/logic/TurretController.java

+58-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package extrasandredux.world.blocks.logic;
22

3+
import arc.*;
4+
import arc.graphics.*;
35
import arc.graphics.g2d.*;
46
import arc.math.geom.*;
57
import arc.scene.ui.*;
@@ -8,6 +10,7 @@
810
import arc.util.*;
911
import arc.util.io.*;
1012
import extrasandredux.util.*;
13+
import mindustry.entities.units.*;
1114
import mindustry.game.*;
1215
import mindustry.gen.*;
1316
import mindustry.graphics.*;
@@ -20,13 +23,17 @@
2023
import static mindustry.Vars.*;
2124

2225
public class TurretController extends Block{
26+
protected TextureRegion modeRegion;
27+
protected TextureRegion plugRegion0, plugRegion1;
28+
2329
public TurretController(String name){
2430
super(name);
2531
ESRUtls.applySandboxDefaults(this, Category.logic);
2632

2733
update = true;
2834
solid = true;
2935
rotate = true;
36+
rotateDraw = false;
3037
configurable = true;
3138
saveConfig = false;
3239

@@ -38,13 +45,44 @@ public TurretController(String name){
3845
});
3946
}
4047

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+
4167
@Override
4268
public boolean canPlaceOn(Tile tile, Team team, int rotation){
4369
//Assumes this block is 1x1. Too lazy to bother with anything larger because I won't make something larger.
4470
Tile front = tile.nearby(rotation);
4571
return front != null && front.build instanceof TurretBuild;
4672
}
4773

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+
4886
public class TurretControllerBuild extends Building{
4987
public ControlState controlState = ControlState.off;
5088
/** x = angle, y = distance */
@@ -115,6 +153,17 @@ public void buildConfiguration(Table table){
115153
});
116154
}
117155

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+
118167
@Override
119168
public void drawSelect(){
120169
Building front = front();
@@ -143,12 +192,18 @@ public void read(Reads read, byte revision){
143192
}
144193

145194
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;
149200

150201
public static ControlState[] all = values();
151202

203+
ControlState(Color modeColor){
204+
this.modeColor = modeColor;
205+
}
206+
152207
public ControlState next(){
153208
int next = ordinal() + 1;
154209
if(next >= all.length) next = 0;

0 commit comments

Comments
 (0)