Skip to content
Merged

Dev #44

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ author: '''
Port: 00SunRay00 & RE2b2m22
'''
minGameVersion: 157
version: 2.1.2
version: 2.1.3
hidden: true
main: scheme.Main
2 changes: 1 addition & 1 deletion src/java/scheme/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void init() {
MessageQueue.load();
RainbowTeam.load();
SBinding.load();
new com.xpdustry.claj.client.Main().init();
if(mods.getMod("claj") == null || !mods.getMod("claj").enabled())new com.xpdustry.claj.client.Main().init();

ui.schematics = schemas;
ui.listfrag = listfrag;
Expand Down
62 changes: 44 additions & 18 deletions src/java/scheme/ServerIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import arc.Core;
import arc.Events;
import arc.struct.IntMap;
import arc.util.Log;
import arc.util.Strings;
import arc.util.Time;
import mindustry.game.EventType.*;
Expand Down Expand Up @@ -47,18 +48,28 @@ public static void load() {
});

netServer.addPacketHandler("MySubtitle", (target, args) -> {
SSUsers.put(target.id, args);
IntMap<String> single = new IntMap<>(1);
single.put(target.id, args);
Call.clientPacketReliable("Subtitles", JsonIO.write(single));

if (SSUsers.size > 1) {
Call.clientPacketReliable(target.con, "Subtitles", JsonIO.write(SSUsers));
try {
if (args != null && args.length() > 256) return;
SSUsers.put(target.id, args);
IntMap<String> single = new IntMap<>(1);
single.put(target.id, args);
Call.clientPacketReliable("Subtitles", JsonIO.write(single));

if (SSUsers.size > 1) {
Call.clientPacketReliable(target.con, "Subtitles", JsonIO.write(SSUsers));
}
} catch (Exception e) {
Log.warn("Invalid MySubtitle packet from @", target.name, e);
}
});

netServer.addBinaryPacketHandler("schemesize.available", (player, data) -> {
Call.clientBinaryPacketReliable(player.con, "schemesize.available", data);
try {
if (data == null || data.length > 64) return;
Call.clientBinaryPacketReliable(player.con, "schemesize.available", data);
} catch (Exception e) {
Log.warn("Invalid schemesize.available packet from @", player.name, e);
}
});

// endregion
Expand All @@ -68,23 +79,38 @@ public static void load() {
Events.run(ClientPreConnectEvent.class, ServerIntegration::clear);

netClient.addPacketHandler("SendMeSubtitle", args -> {
Call.serverPacketReliable("MySubtitle", settings.getString("subtitle"));
if (args != null) hostID = Strings.parseInt(args, -1);
try {
Call.serverPacketReliable("MySubtitle", settings.getString("subtitle"));
if (args != null) hostID = Strings.parseInt(args, -1);
} catch (Exception e) {
Log.warn("Invalid SendMeSubtitle packet", e);
}
});

netClient.addPacketHandler("Subtitles", args -> {
IntMap<String> received = JsonIO.read(IntMap.class, args);
for (var entry : received) {
if (entry.value == null || entry.value.isEmpty()) SSUsers.remove(entry.key);
else SSUsers.put(entry.key, entry.value);
try {
if (args == null || args.isEmpty()) return;
IntMap<String> received = JsonIO.read(IntMap.class, args);
if (received == null) return;
for (var entry : received) {
if (entry.value == null || entry.value.isEmpty()) SSUsers.remove(entry.key);
else SSUsers.put(entry.key, entry.value);
}
hasData = true;
} catch (Exception e) {
Log.warn("Invalid Subtitles packet", e);
}
hasData = true;
});

netClient.addBinaryPacketHandler("schemesize.available", (data) -> {
schemeAvailable = true;
DisabledTools.clear();
DisabledTools.set(data);
try {
if (data == null || data.length == 0) return;
schemeAvailable = true;
DisabledTools.clear();
DisabledTools.set(data);
} catch (Exception e) {
Log.warn("Invalid schemesize.available packet", e);
}
});

Events.on(WorldLoadEndEvent.class, e -> {
Expand Down
57 changes: 57 additions & 0 deletions src/java/scheme/moded/ModedDesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import mindustry.input.*;
import mindustry.input.Placement.NormalizeDrawResult;
import mindustry.input.Placement.NormalizeResult;
import mindustry.gen.Building;
import mindustry.gen.Mechc;
import scheme.tools.DisabledTools;
import mindustry.world.Block;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class ModedDesktopInput extends DesktopInput implements ModedInputHandler
public Vec2 shootXY = new Vec2();
public boolean ctrlMove;
public Vec2 mi2uMove = new Vec2();
public Building forceTapped = null;

@Override
protected void removeSelection(int x1, int y1, int x2, int y2, int maxLength) {
Expand Down Expand Up @@ -98,6 +100,15 @@ public void drawTop() {

drawCommanded();

if (settings.getBool("forceTapTile") && block == null && !scene.hasMouse()) {
Vec2 vec = input.mouseWorld(getMouseX(), getMouseY());
Building build = world.buildWorld(vec.x, vec.y);
if (build != null && build.team != player.team()) {
build.drawSelect();
if (!build.enabled && build.block.drawDisabled) build.drawDisabled();
}
}

Draw.reset();
}

Expand Down Expand Up @@ -151,6 +162,17 @@ public void update() {

if (scene.hasKeyboard()) return;

if (input.keyTap(Binding.select) && !scene.hasMouse() && corefrag.choosesNode) corefrag.trySetNode(tileX(getMouseX()), tileY(getMouseY()));

if (settings.getBool("forceTapTile") && input.keyTap(Binding.select) && !scene.hasMouse()) {
if (player.dead()) {
var build = world.buildWorld(input.mouseWorldX(), input.mouseWorldY());
forceTap(build, true);
} else {
forceTap(prevSelected == null ? null : prevSelected.build, false);
}
}

modedInput();
buildInput();

Expand Down Expand Up @@ -334,6 +356,41 @@ public void move(Vec2 movement) {
mi2uMove.set(movement);
}

private void forceTap(Building build, boolean includeSelfTeam) {
if (build == null) return;
if (!includeSelfTeam && build.interactable(player.team())) return;

if (build == forceTapped) {
inv.hide();
config.hideConfig();
forceTapped = null;
return;
}

var ptm = state.playtestingMap;
state.playtestingMap = state.map;

if (build.block.configurable) {
if ((!config.isShown() && build.shouldShowConfigure(player))
|| (config.isShown() && config.getSelected().onConfigureBuildTapped(build))) {
config.showConfig(build);
}
} else if (!config.hasConfigMouse()) {
if (config.isShown() && config.getSelected().onConfigureBuildTapped(build)) {
config.hideConfig();
}
}

if (build.block.synthetic() && build.block.allowConfigInventory) {
if (build.block.hasItems && build.items.total() > 0) {
inv.showFor(build);
}
}

forceTapped = build;
state.playtestingMap = ptm;
}

@Override
public void clear() {
ctrlBoost = false;
Expand Down
52 changes: 52 additions & 0 deletions src/java/scheme/moded/ModedMobileInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import mindustry.gen.Mechc;
import mindustry.gen.Player;
import mindustry.gen.Unit;
import mindustry.gen.Building;
import mindustry.input.*;
import mindustry.input.Placement.NormalizeResult;
import mindustry.world.blocks.power.PowerNode;
Expand All @@ -39,6 +40,7 @@ public class ModedMobileInput extends MobileInput implements ModedInputHandler,
public Vec2 shootXY = new Vec2();
public boolean ctrlMove;
public Vec2 mi2uMove = new Vec2();
public Building forceTapped = null;

private boolean isRelease() {
return lastTouched && !input.isTouched(0);
Expand Down Expand Up @@ -89,6 +91,14 @@ else if (mode == rebuildSelect)
drawEditSelection(lastX, lastY, build.size);

drawCommanded();

if (settings.getBool("forceTapTile") && !scene.hasMouse()) {
var build = world.buildWorld(input.mouseWorldX(), input.mouseWorldY());
if (build != null && build.team != player.team()) {
build.drawSelect();
if (!build.enabled && build.block.drawDisabled) build.drawDisabled();
}
}
}

@Override
Expand All @@ -114,6 +124,13 @@ public void update() {
if (input.isTouched(0) && !scene.hasMouse()) observed = null;
}

if (isTap() && !scene.hasMouse() && corefrag.choosesNode) corefrag.trySetNode(tileX(), tileY());

if (settings.getBool("forceTapTile") && isTap() && !scene.hasMouse()) {
var build = world.buildWorld(input.mouseWorldX(), input.mouseWorldY());
forceTap(build, player.dead());
}

buildInput();
if (movementLocked) {
if (player.unit() == null) return;
Expand Down Expand Up @@ -265,6 +282,41 @@ public void move(Vec2 movement) {
mi2uMove.set(movement);
}

private void forceTap(Building build, boolean includeSelfTeam) {
if (build == null) return;
if (!includeSelfTeam && build.interactable(player.team())) return;

if (build == forceTapped) {
inv.hide();
config.hideConfig();
forceTapped = null;
return;
}

var ptm = state.playtestingMap;
state.playtestingMap = state.map;

if (build.block.configurable) {
if ((!config.isShown() && build.shouldShowConfigure(player))
|| (config.isShown() && config.getSelected().onConfigureBuildTapped(build))) {
config.showConfig(build);
}
} else if (!config.hasConfigMouse()) {
if (config.isShown() && config.getSelected().onConfigureBuildTapped(build)) {
config.hideConfig();
}
}

if (build.block.synthetic() && build.block.allowConfigInventory) {
if (build.block.hasItems && build.items.total() > 0) {
inv.showFor(build);
}
}

forceTapped = build;
state.playtestingMap = ptm;
}

@Override
public void clear() {
ctrlBoost = false;
Expand Down
Loading
Loading