Skip to content

Commit 923ab1a

Browse files
committed
Add 'src/' from commit 'c75f34a7d6cf0e6870968a0607bccae02b21afb1'
git-subtree-dir: src git-subtree-mainline: 81e3347 git-subtree-split: c75f34a
2 parents 81e3347 + c75f34a commit 923ab1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+9585
-0
lines changed

src/Hooks.java

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package mindustryX;
2+
3+
import arc.*;
4+
import arc.files.*;
5+
import arc.util.*;
6+
import mindustry.*;
7+
import mindustry.gen.*;
8+
import mindustry.input.*;
9+
import mindustryX.features.Settings;
10+
import mindustryX.features.*;
11+
import mindustryX.features.func.*;
12+
import mindustryX.features.ui.*;
13+
14+
import java.net.*;
15+
import java.util.*;
16+
17+
public class Hooks implements ApplicationListener{
18+
/** invoke before `Vars.init`. Note that may be executed from `Vars.loadAsync` */
19+
public static void beforeInit(){
20+
Log.infoTag("MindustryX", "Hooks.beforeInit");
21+
registerBundle();
22+
Settings.addSettings();
23+
DebugUtil.init();//this is safe, and better at beforeInit,
24+
}
25+
26+
/** invoke after loading, just before `Mod::init` */
27+
@Override
28+
public void init(){
29+
Log.infoTag("MindustryX", "Hooks.init");
30+
LogicExt.init();
31+
if(AutoUpdate.INSTANCE.getActive())
32+
AutoUpdate.INSTANCE.checkUpdate();
33+
if(!Vars.headless){
34+
RenderExt.init();
35+
TimeControl.init();
36+
UIExt.init();
37+
ReplayController.init();
38+
}
39+
}
40+
41+
@SuppressWarnings("unused")//call before arc.util.Http$HttpRequest.block
42+
public static void onHttp(Http.HttpRequest req){
43+
if(Core.settings.getBool("githubMirror")){
44+
try{
45+
String url = req.url;
46+
String host = new URL(url).getHost();
47+
if(host.contains("github.com") || host.contains("raw.githubusercontent.com")){
48+
url = "https://gh.tinylake.tech/" + url;
49+
req.url = url;
50+
}
51+
}catch(Exception e){
52+
//ignore
53+
}
54+
}
55+
}
56+
57+
public static @Nullable String onHandleSendMessage(String message, @Nullable Player sender){
58+
if(message == null) return null;
59+
if(Vars.ui != null){
60+
if(MarkerType.resolveMessage(message)) return message;
61+
try{
62+
ArcMessageDialog.resolveMsg(message, sender);
63+
if(sender != null){
64+
message = (sender.dead() ? Iconc.alphaaaa : sender.unit().type.emoji()) + " " + message;
65+
}
66+
}catch(Exception e){
67+
Log.err(e);
68+
}
69+
}
70+
return message;
71+
}
72+
73+
@Override
74+
public void update(){
75+
pollKeys();
76+
}
77+
78+
public static void pollKeys(){
79+
if(Vars.headless || Core.scene.hasField()) return;
80+
if(Core.input.keyTap(Binding.toggle_unit)){
81+
RenderExt.unitHide = !RenderExt.unitHide;
82+
}
83+
if(Core.input.keyTap(Binding.lockonLastMark)){
84+
MarkerType.lockOnLastMark();
85+
}
86+
if(Core.input.keyTap(Binding.point)){
87+
MarkerType.selected.markWithMessage(Core.input.mouseWorld());
88+
}
89+
if(Core.input.keyTap(Binding.toggle_block_render)){
90+
Core.settings.put("blockRenderLevel", (RenderExt.blockRenderLevel + 1) % 3);
91+
}
92+
if(Core.input.keyTap(Binding.focusLogicController)){
93+
FuncX.focusLogicController();
94+
}
95+
if(Core.input.keyTap(Binding.arcScanMode)){
96+
ArcScanMode.enabled = !ArcScanMode.enabled;
97+
}
98+
if(Core.input.keyTap(Binding.showRTSAi)){
99+
Settings.toggle("alwaysShowUnitRTSAi");
100+
}
101+
if(Core.input.keyTap(Binding.superUnitEffect)){
102+
Settings.cycle("superUnitEffect", 3);
103+
}
104+
}
105+
106+
private static void registerBundle(){
107+
//MDTX: bundle overwrite
108+
try{
109+
I18NBundle originBundle = Core.bundle;
110+
Fi handle = Core.files.internal("bundles/bundle-mdtx");
111+
Core.bundle = I18NBundle.createBundle(handle, Locale.getDefault());
112+
Reflect.set(Core.bundle, "locale", originBundle.getLocale());
113+
Log.info("MDTX: bundle has been loaded.");
114+
var rootBundle = Core.bundle;
115+
while(rootBundle.getParent() != null){
116+
rootBundle = rootBundle.getParent();
117+
}
118+
Reflect.set(rootBundle, "parent", originBundle);
119+
}catch(Throwable e){
120+
Log.err(e);
121+
}
122+
}
123+
}

src/MindustryXApi.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mindustryX;
2+
3+
import java.lang.annotation.*;
4+
5+
@Documented
6+
@Retention(RetentionPolicy.SOURCE)
7+
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD})
8+
public @interface MindustryXApi{
9+
/** Need Keep for compatibility with vanilla */
10+
@Documented
11+
@Retention(RetentionPolicy.SOURCE)
12+
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD})
13+
public @interface Keep{
14+
}
15+
}

src/VarsX.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package mindustryX;
2+
3+
public class VarsX{
4+
public static boolean isLoader = false;
5+
}

src/events/LogicAssembledEvent.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package mindustryX.events;
2+
3+
import mindustry.logic.*;
4+
import mindustry.world.blocks.logic.LogicBlock.*;
5+
import mindustryX.*;
6+
7+
/**
8+
* Fired after LAssembler finish assemble and about to load to LExecutor
9+
* Allow mods to modify LAssembler, try parse InvalidStatement again.
10+
* Not fired when LogicBlock load empty code.
11+
*/
12+
@MindustryXApi
13+
public class LogicAssembledEvent{
14+
public LogicBuild build;
15+
public LAssembler assembler;
16+
17+
public LogicAssembledEvent(LogicBuild build, LAssembler assembler){
18+
this.build = build;
19+
this.assembler = assembler;
20+
}
21+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package mindustryX.events;
2+
3+
import mindustry.game.*;
4+
import mindustry.gen.*;
5+
import mindustryX.*;
6+
7+
/** Called after the team of a player changed. */
8+
@MindustryXApi
9+
public class PlayerTeamChangedEvent{
10+
public final Team previous;
11+
public final Player player;
12+
public PlayerTeamChangedEvent(Team previous, Player player) {
13+
this.previous = previous;
14+
this.player = player;
15+
}
16+
}
17+

src/events/SendPacketEvent.java

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package mindustryX.events;
2+
3+
import arc.*;
4+
import arc.util.*;
5+
import mindustry.net.*;
6+
import mindustryX.*;
7+
8+
@MindustryXApi
9+
public class SendPacketEvent{
10+
/** null for all, may emit again */
11+
@Nullable
12+
public NetConnection con;
13+
/** only when call in sendExcept */
14+
@Nullable
15+
public NetConnection except;
16+
public Object packet;
17+
public boolean isCancelled;
18+
19+
private SendPacketEvent(){
20+
}
21+
22+
private static final SendPacketEvent inst = new SendPacketEvent();
23+
24+
/** @return isCancelled */
25+
public static boolean emit(@Nullable NetConnection con, @Nullable NetConnection except, Object packet){
26+
inst.isCancelled = false;
27+
inst.con = con;
28+
inst.except = except;
29+
inst.packet = packet;
30+
Events.fire(inst);
31+
return inst.isCancelled;
32+
}
33+
}

src/features/ArcBuilds.java

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package mindustryX.features;
2+
3+
import arc.*;
4+
import arc.graphics.g2d.*;
5+
import arc.math.*;
6+
import arc.math.geom.*;
7+
import arc.struct.*;
8+
import arc.util.*;
9+
import mindustry.ctype.*;
10+
import mindustry.entities.bullet.*;
11+
import mindustry.game.*;
12+
import mindustry.gen.*;
13+
import mindustry.graphics.*;
14+
import mindustry.type.*;
15+
import mindustry.world.blocks.defense.turrets.*;
16+
17+
import static mindustry.Vars.*;
18+
19+
//move from mindustry.arcModule.draw.ARCBuilds
20+
public class ArcBuilds{
21+
private static boolean targetAir = false, targetGround = false, canShoot = false;
22+
private static boolean turretForceShowRange = false;
23+
private static int turretShowRange = 0, turretAlertRange;
24+
private static boolean showTurretAmmo = false, showTurretAmmoAmount = false;
25+
private static boolean blockWeaponTargetLine = false, blockWeaponTargetLineWhenIdle = false;
26+
27+
static{
28+
// 减少性能开销
29+
Events.run(EventType.Trigger.update, () -> {
30+
turretForceShowRange = Core.settings.getBool("turretForceShowRange");
31+
turretShowRange = Core.settings.getInt("turretShowRange");
32+
33+
turretAlertRange = Core.settings.getInt("turretAlertRange") * tilesize;
34+
35+
showTurretAmmo = Core.settings.getBool("showTurretAmmo");
36+
showTurretAmmoAmount = Core.settings.getBool("showTurretAmmoAmount");
37+
38+
blockWeaponTargetLine = Core.settings.getBool("blockWeaponTargetLine");
39+
blockWeaponTargetLineWhenIdle = Core.settings.getBool("blockWeaponTargetLineWhenIdle");
40+
});
41+
}
42+
43+
private static void drawRange(BaseTurret.BaseTurretBuild build){
44+
Draw.z(Layer.turret - 0.8f);
45+
//Draw.color(build.team.color, 0.05f);
46+
//Fill.circle(build.x, build.y, build.range());
47+
Draw.color(build.team.color, 0.6f);
48+
Lines.circle(build.x, build.y, build.range());
49+
Draw.reset();
50+
}
51+
52+
public static void arcTurret(BaseTurret.BaseTurretBuild build){
53+
if(build == null || !(build.team == player.team() || RenderExt.showOtherInfo)) return;
54+
Draw.z(Layer.turret);
55+
56+
Vec2 targetPos = Vec2.ZERO;
57+
if(build.block instanceof Turret t){
58+
targetAir = t.targetAir;
59+
targetGround = t.targetGround;
60+
targetPos = ((Turret.TurretBuild)build).targetPos;
61+
canShoot = ((Turret.TurretBuild)build).hasAmmo();
62+
}else if(build.block instanceof TractorBeamTurret t){
63+
targetAir = t.targetAir;
64+
targetGround = t.targetGround;
65+
Unit target = ((TractorBeamTurret.TractorBeamBuild)build).target;
66+
if(target != null){
67+
targetPos = Tmp.v1.set(target.x, target.y);
68+
}
69+
canShoot = build.potentialEfficiency > 0;
70+
}
71+
if(build instanceof PowerTurret.PowerTurretBuild){
72+
canShoot = build.efficiency > 0;
73+
}
74+
75+
if(turretForceShowRange || canShoot){
76+
if((turretShowRange == 3 || (turretShowRange == 2 && targetAir) || (turretShowRange == 1 && targetGround)))
77+
drawRange(build);
78+
else if(turretAlertRange > 0 && build.team != player.team()){
79+
boolean canHitPlayer = !player.dead() && player.unit().hittable() && (player.unit().isFlying() ? targetAir : targetGround)
80+
&& build.within(player.unit().x, player.unit().y, build.range() + turretAlertRange);
81+
boolean canHitMouse = build.within(Core.input.mouseWorldX(), Core.input.mouseWorldY(), build.range() + turretAlertRange);
82+
boolean canHitCommand = control.input.commandMode && ((ArcUnits.selectedUnitsFlyer && targetAir) || (ArcUnits.selectedUnitsLand && targetGround));
83+
boolean canHitPlans = (control.input.block != null || control.input.selectPlans.size > 0) && targetGround;
84+
if(canHitPlayer || (canHitMouse && (canHitCommand || canHitPlans))) drawRange(build);
85+
}
86+
87+
if(showTurretAmmo && build instanceof ItemTurret.ItemTurretBuild it && it.ammo.any()){
88+
//lc参考miner代码
89+
ItemTurret.ItemEntry entry = (ItemTurret.ItemEntry)it.ammo.peek();
90+
Item lastAmmo = entry.item;
91+
92+
Draw.z(Layer.turret + 0.1f);
93+
94+
float size = Math.max(4f, build.block.size * tilesize / 2.5f);
95+
float ammoX = build.x - (build.block.size * tilesize / 2.0F) + (size / 2);
96+
float ammoY = build.y - (build.block.size * tilesize / 2.0F) + (size / 2);
97+
98+
Draw.rect(lastAmmo.fullIcon, ammoX, ammoY, size, size);
99+
100+
float leftAmmo = Mathf.lerp(0, 1, Math.min(1f, (float)entry.amount / ((ItemTurret)it.block).maxAmmo));
101+
if(leftAmmo < 0.75f && showTurretAmmoAmount){
102+
Draw.alpha(0.5f);
103+
Draw.color(lastAmmo.color);
104+
Lines.stroke(Lines.getStroke() * build.block.size * 0.5f);
105+
Lines.arc(ammoX, ammoY, size * 0.5f, leftAmmo);
106+
}
107+
108+
Draw.reset();
109+
}
110+
if(targetPos.x != 0 && targetPos.y != 0 && blockWeaponTargetLine && Mathf.len(targetPos.x - build.x, targetPos.y - build.y) <= 1500f){
111+
if(!(build instanceof Turret.TurretBuild) || ((Turret.TurretBuild)build).isShooting() || ((Turret.TurretBuild)build).isControlled()){
112+
Draw.color(1f, 0.2f, 0.2f, 0.8f);
113+
Lines.stroke(1.5f);
114+
Lines.line(build.x, build.y, targetPos.x, targetPos.y);
115+
Lines.dashCircle(targetPos.x, targetPos.y, 8);
116+
}else if(blockWeaponTargetLineWhenIdle){
117+
Draw.color(1f, 1f, 1f, 0.3f);
118+
Lines.stroke(1.5f);
119+
Lines.line(build.x, build.y, targetPos.x, targetPos.y);
120+
Lines.dashCircle(targetPos.x, targetPos.y, 8);
121+
}
122+
}
123+
}
124+
}
125+
126+
public static void turretPlaceDraw(float x, float y, BaseTurret block){
127+
float oldZ = Draw.z();
128+
Draw.z(oldZ+0.1f);//MDTX: There no replace for Icon.power, so we offset the layer.
129+
float iconSize = 6f + 2f * block.size, range = block.range;
130+
ObjectMap<? extends UnlockableContent, BulletType> ammoTypes;
131+
if(block instanceof ContinuousLiquidTurret t){
132+
ammoTypes = t.ammoTypes;
133+
}else if(block instanceof LiquidTurret t){
134+
ammoTypes = t.ammoTypes;
135+
}else if(block instanceof ItemTurret t){
136+
ammoTypes = t.ammoTypes;
137+
}else if(block instanceof PowerTurret){
138+
turretBulletDraw(x, y, Icon.power.getRegion(), iconSize, range, 0f);
139+
return;
140+
}else return;
141+
142+
int drawIndex = 0;
143+
for(var e : ammoTypes.entries()){
144+
var item = e.key;
145+
var bulletType = e.value;
146+
drawIndex += 1;
147+
if(!item.unlockedNow()) return;
148+
if(bulletType.rangeChange > 0) Drawf.dashCircle(x, y, range + bulletType.rangeChange, Pal.placing);
149+
turretBulletDraw(x, y, item.uiIcon, iconSize, range + bulletType.rangeChange, (float)drawIndex / ammoTypes.size);
150+
}
151+
Draw.z(oldZ);
152+
}
153+
154+
private static void turretBulletDraw(float x, float y, TextureRegion icon, float iconSize, float range, float rotOffset){
155+
for(int i = 0; i < 4; i++){
156+
float rot = (i + rotOffset) * 90f + Time.time * 0.5f;
157+
Draw.rect(icon,
158+
x + (Mathf.sin((float)Math.toRadians(rot)) * (range )),
159+
y + (Mathf.cos((float)Math.toRadians(rot)) * (range )),
160+
iconSize, iconSize, -rot);
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)