From bf1b4f9af524b82e901eea761ea5e95400f98253 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 17:23:46 -0400 Subject: [PATCH 01/17] Native file chooser, untested --- build.gradle | 2 + .../mindustry/desktop/DesktopLauncher.java | 51 +++++++++++++++++++ gradle.properties | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d051101a24..d68db91465 100644 --- a/build.gradle +++ b/build.gradle @@ -234,6 +234,8 @@ project(":desktop"){ dependencies{ implementation project(":core") implementation arcModule("extensions:discord") + implementation arcModule("extensions:filedialogs") + implementation arcModule("natives:natives-filedialogs") implementation arcModule("natives:natives-desktop") implementation arcModule("natives:natives-freetype-desktop") diff --git a/desktop/src/mindustry/desktop/DesktopLauncher.java b/desktop/src/mindustry/desktop/DesktopLauncher.java index 44f3b5b03f..21ba0f4e5d 100644 --- a/desktop/src/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/mindustry/desktop/DesktopLauncher.java @@ -6,6 +6,7 @@ import arc.backend.sdl.*; import arc.backend.sdl.jni.*; import arc.discord.*; import arc.discord.DiscordRPC.*; +import arc.filedialogs.*; import arc.files.*; import arc.func.*; import arc.math.*; @@ -23,6 +24,7 @@ import mindustry.net.*; import mindustry.net.Net.*; import mindustry.service.*; import mindustry.type.*; +import mindustry.ui.dialogs.*; import java.io.*; @@ -36,6 +38,55 @@ public class DesktopLauncher extends ClientLauncher{ public static void main(String[] arg){ try{ Vars.loadLogger(); + Vars.platform = new Platform(){ + @Override + public void showFileChooser(boolean open, String title, String extension, Cons cons){ + if(OS.isWindows || OS.isMac){ + Threads.daemon(() -> { + try{ + FileDialogs.loadNatives(); + + String result; + + if(open){ + result = FileDialogs.openFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); + }else{ + result = FileDialogs.saveFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); + } + + if(result == null) return; + + if(result.length() > 1 && result.contains("\n")){ + result = result.split("\n")[0]; + } + + //cancelled selection, ignore result + if(result.isEmpty() || result.equals("\n")) return; + if(result.endsWith("\n")) result = result.substring(0, result.length() - 1); + if(result.contains("\n")) throw new IOException("invalid input: \"" + result + "\""); + + Fi file = Core.files.absolute(result); + Core.app.post(() -> { + FileChooser.setLastDirectory(file.isDirectory() ? file : file.parent()); + + if(!open){ + cons.get(file.parent().child(file.nameWithoutExtension() + "." + extension)); + }else{ + cons.get(file); + } + }); + }catch(Throwable error){ + Log.err("Failure to execute native file chooser", error); + Core.app.post(() -> { + Platform.super.showFileChooser(open, title, extension, cons); + }); + } + }); + }else{ + Platform.super.showFileChooser(open, title, extension, cons); + } + } + }; new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{ title = "Mindustry"; maximized = true; diff --git a/gradle.properties b/gradle.properties index dd42df65ea..1196682aac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,4 +25,4 @@ org.gradle.caching=true #used for slow jitpack builds; TODO see if this actually works org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 -archash=eac3d7211c +archash=30a01a48a1 From e7d7890891af0c6eede925e82014e3e5e5211675 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 17:27:26 -0400 Subject: [PATCH 02/17] Fixes --- build.gradle | 2 +- core/src/mindustry/core/Platform.java | 43 +++++++++++++++- .../mindustry/desktop/DesktopLauncher.java | 51 ------------------- 3 files changed, 43 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index d68db91465..9bca8edb25 100644 --- a/build.gradle +++ b/build.gradle @@ -234,7 +234,6 @@ project(":desktop"){ dependencies{ implementation project(":core") implementation arcModule("extensions:discord") - implementation arcModule("extensions:filedialogs") implementation arcModule("natives:natives-filedialogs") implementation arcModule("natives:natives-desktop") implementation arcModule("natives:natives-freetype-desktop") @@ -322,6 +321,7 @@ project(":core"){ api arcModule("extensions:g3d") api arcModule("extensions:fx") api arcModule("extensions:arcnet") + implementation arcModule("extensions:filedialogs") api "com.github.Anuken:rhino:$rhinoVersion" if(localArc && debugged()) api arcModule("extensions:recorder") if(localArc) api arcModule(":extensions:packer") diff --git a/core/src/mindustry/core/Platform.java b/core/src/mindustry/core/Platform.java index 73e65615be..0cbc9869eb 100644 --- a/core/src/mindustry/core/Platform.java +++ b/core/src/mindustry/core/Platform.java @@ -1,6 +1,7 @@ package mindustry.core; import arc.*; +import arc.filedialogs.*; import arc.files.*; import arc.func.*; import arc.math.*; @@ -141,7 +142,47 @@ public interface Platform{ * @param title The title of the native dialog */ default void showFileChooser(boolean open, String title, String extension, Cons cons){ - if(OS.isLinux && !OS.isAndroid){ + if(OS.isWindows || OS.isMac){ + //native file dialog + Threads.daemon(() -> { + try{ + FileDialogs.loadNatives(); + + String result; + + if(open){ + result = FileDialogs.openFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); + }else{ + result = FileDialogs.saveFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); + } + + if(result == null) return; + + if(result.length() > 1 && result.contains("\n")){ + result = result.split("\n")[0]; + } + + //cancelled selection, ignore result + if(result.isEmpty() || result.equals("\n")) return; + if(result.endsWith("\n")) result = result.substring(0, result.length() - 1); + if(result.contains("\n")) throw new IOException("invalid input: \"" + result + "\""); + + Fi file = Core.files.absolute(result); + Core.app.post(() -> { + FileChooser.setLastDirectory(file.isDirectory() ? file : file.parent()); + + if(!open){ + cons.get(file.parent().child(file.nameWithoutExtension() + "." + extension)); + }else{ + cons.get(file); + } + }); + }catch(Throwable error){ + Log.err("Failure to execute native file chooser", error); + Core.app.post(() -> defaultFileDialog(open, title, extension, cons)); + } + }); + }else if(OS.isLinux && !OS.isAndroid){ showZenity(open, title, new String[]{extension}, cons, () -> defaultFileDialog(open, title, extension, cons)); }else{ defaultFileDialog(open, title, extension, cons); diff --git a/desktop/src/mindustry/desktop/DesktopLauncher.java b/desktop/src/mindustry/desktop/DesktopLauncher.java index 21ba0f4e5d..44f3b5b03f 100644 --- a/desktop/src/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/mindustry/desktop/DesktopLauncher.java @@ -6,7 +6,6 @@ import arc.backend.sdl.*; import arc.backend.sdl.jni.*; import arc.discord.*; import arc.discord.DiscordRPC.*; -import arc.filedialogs.*; import arc.files.*; import arc.func.*; import arc.math.*; @@ -24,7 +23,6 @@ import mindustry.net.*; import mindustry.net.Net.*; import mindustry.service.*; import mindustry.type.*; -import mindustry.ui.dialogs.*; import java.io.*; @@ -38,55 +36,6 @@ public class DesktopLauncher extends ClientLauncher{ public static void main(String[] arg){ try{ Vars.loadLogger(); - Vars.platform = new Platform(){ - @Override - public void showFileChooser(boolean open, String title, String extension, Cons cons){ - if(OS.isWindows || OS.isMac){ - Threads.daemon(() -> { - try{ - FileDialogs.loadNatives(); - - String result; - - if(open){ - result = FileDialogs.openFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); - }else{ - result = FileDialogs.saveFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); - } - - if(result == null) return; - - if(result.length() > 1 && result.contains("\n")){ - result = result.split("\n")[0]; - } - - //cancelled selection, ignore result - if(result.isEmpty() || result.equals("\n")) return; - if(result.endsWith("\n")) result = result.substring(0, result.length() - 1); - if(result.contains("\n")) throw new IOException("invalid input: \"" + result + "\""); - - Fi file = Core.files.absolute(result); - Core.app.post(() -> { - FileChooser.setLastDirectory(file.isDirectory() ? file : file.parent()); - - if(!open){ - cons.get(file.parent().child(file.nameWithoutExtension() + "." + extension)); - }else{ - cons.get(file); - } - }); - }catch(Throwable error){ - Log.err("Failure to execute native file chooser", error); - Core.app.post(() -> { - Platform.super.showFileChooser(open, title, extension, cons); - }); - } - }); - }else{ - Platform.super.showFileChooser(open, title, extension, cons); - } - } - }; new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{ title = "Mindustry"; maximized = true; From 9ac8d9a821618b3521909550a2692dc4089b6a62 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 17:29:04 -0400 Subject: [PATCH 03/17] Fixes --- core/src/mindustry/core/Platform.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/core/Platform.java b/core/src/mindustry/core/Platform.java index 0cbc9869eb..7c2860ea84 100644 --- a/core/src/mindustry/core/Platform.java +++ b/core/src/mindustry/core/Platform.java @@ -143,6 +143,8 @@ public interface Platform{ */ default void showFileChooser(boolean open, String title, String extension, Cons cons){ if(OS.isWindows || OS.isMac){ + String formatted = (title.startsWith("@") ? Core.bundle.get(title.substring(1)) : title).replaceAll("\"", "'"); + //native file dialog Threads.daemon(() -> { try{ @@ -151,9 +153,9 @@ public interface Platform{ String result; if(open){ - result = FileDialogs.openFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); + result = FileDialogs.openFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); }else{ - result = FileDialogs.saveFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); + result = FileDialogs.saveFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); } if(result == null) return; From 6e7613dee31776d0990fb2fa6c1e22a7b4cf5597 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 17:34:34 -0400 Subject: [PATCH 04/17] Fixes --- core/src/mindustry/core/Platform.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/mindustry/core/Platform.java b/core/src/mindustry/core/Platform.java index 7c2860ea84..09b89f79a8 100644 --- a/core/src/mindustry/core/Platform.java +++ b/core/src/mindustry/core/Platform.java @@ -155,7 +155,7 @@ public interface Platform{ if(open){ result = FileDialogs.openFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); }else{ - result = FileDialogs.saveFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); + result = FileDialogs.saveFileDialog(formatted, FileChooser.getLastDirectory().child("file." + extension).absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); } if(result == null) return; From a260710ee6e4153663e93cfeea05f3bc2b89d37c Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 17:57:34 -0400 Subject: [PATCH 05/17] MacOS file chooser fix --- core/src/mindustry/core/Platform.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/core/Platform.java b/core/src/mindustry/core/Platform.java index 09b89f79a8..77d62c6bf0 100644 --- a/core/src/mindustry/core/Platform.java +++ b/core/src/mindustry/core/Platform.java @@ -151,11 +151,13 @@ public interface Platform{ FileDialogs.loadNatives(); String result; + //on MacOS, .msav is not properly recognized until I put garbage into the array? + String[] extensions = OS.isMac && open ? new String[]{"", "*." + extension} : new String[]{"*." + extension}; if(open){ - result = FileDialogs.openFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false); + result = FileDialogs.openFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), extensions, "." + extension + " files", false); }else{ - result = FileDialogs.saveFileDialog(formatted, FileChooser.getLastDirectory().child("file." + extension).absolutePath(), new String[]{"*." + extension}, "." + extension + " files"); + result = FileDialogs.saveFileDialog(formatted, FileChooser.getLastDirectory().child("file." + extension).absolutePath(), extensions, "." + extension + " files"); } if(result == null) return; From c0c68ddad1cb82a03f820d4518b051900e5bc67b Mon Sep 17 00:00:00 2001 From: Tatarinyon Date: Tue, 28 May 2024 01:01:16 +0300 Subject: [PATCH 06/17] Update servers_v7.json (#9889) * Update servers_v7.json Yes, eventually I want to add my server and I think it will be the first server added from Turkey. Currently there are only classic maps on the server. I will make maps for the server in my spare time * Update servers_v7.json --- servers_v7.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/servers_v7.json b/servers_v7.json index 4b2fd7a56c..9a29440b8a 100644 --- a/servers_v7.json +++ b/servers_v7.json @@ -304,6 +304,10 @@ "name": "2D2R", "address": ["45.137.205.185:1045", "51.89.173.50:1432", "45.137.205.185:1052", "45.137.205.185:1040"] }, + { + "name": "TRFACT", + "address": ["213.142.156.83:25565"] + }, { "name": "ArmyOFUkraine", "address": ["194.247.42.131:27715"] From 4d2163d2486ccec6610d5374dab0f21fe1d4d197 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 18:12:21 -0400 Subject: [PATCH 07/17] Less frequent Erekir turret retargeting when valid target is present --- core/src/mindustry/content/Blocks.java | 7 +++++++ .../src/mindustry/world/blocks/defense/turrets/Turret.java | 7 ++++++- gradle.properties | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index d0f1cabe59..969090e462 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -4152,6 +4152,7 @@ public class Blocks{ liquidConsumed = 10f / 60f; targetInterval = 5f; + newTargetInterval = 30f; targetUnderBlocks = false; float r = range = 130f; @@ -4242,6 +4243,8 @@ public class Blocks{ shootY = 7f; rotateSpeed = 1.4f; minWarmup = 0.85f; + + newTargetInterval = 40f; shootWarmupSpeed = 0.07f; coolant = consume(new ConsumeLiquid(Liquids.water, 30f / 60f)); @@ -4462,6 +4465,8 @@ public class Blocks{ heatRequirement = 10f; maxHeatEfficiency = 2f; + newTargetInterval = 40f; + inaccuracy = 1f; shake = 2f; shootY = 4; @@ -4684,6 +4689,8 @@ public class Blocks{ shootSound = Sounds.missileLaunch; minWarmup = 0.94f; + newTargetInterval = 40f; + unitSort = UnitSorts.strongest; shootWarmupSpeed = 0.03f; targetAir = false; targetUnderBlocks = false; diff --git a/core/src/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/mindustry/world/blocks/defense/turrets/Turret.java index 3245ecc6e1..7659d6102c 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/Turret.java @@ -36,6 +36,8 @@ public class Turret extends ReloadTurret{ public final int timerTarget = timers++; /** Ticks between attempt at finding a target. */ public float targetInterval = 20; + /** Target interval for when this turret already has a valid target. -1 = targetInterval */ + public float newTargetInterval = -1f; /** Maximum ammo units stored. */ public int maxAmmo = 30; @@ -176,6 +178,7 @@ public class Turret extends ReloadTurret{ if(elevation < 0) elevation = size / 2f; if(recoilTime < 0f) recoilTime = reload; if(cooldownTime < 0f) cooldownTime = reload; + if(newTargetInterval <= 0f) newTargetInterval = targetInterval; super.init(); } @@ -405,7 +408,7 @@ public class Turret extends ReloadTurret{ if(hasAmmo()){ if(Float.isNaN(reloadCounter)) reloadCounter = 0; - if(timer(timerTarget, targetInterval)){ + if(timer(timerTarget, target == null ? newTargetInterval : targetInterval)){ findTarget(); } @@ -438,6 +441,8 @@ public class Turret extends ReloadTurret{ wasShooting = true; updateShooting(); } + }else{ + target = null; } if(alwaysShooting){ diff --git a/gradle.properties b/gradle.properties index 1196682aac..5736b39a3e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,4 +25,4 @@ org.gradle.caching=true #used for slow jitpack builds; TODO see if this actually works org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 -archash=30a01a48a1 +archash=2126b31154 From 05c2d47d51de24fedfa43accc7f928eed62216dd Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 18:25:39 -0400 Subject: [PATCH 08/17] Invert --- core/src/mindustry/world/blocks/defense/turrets/Turret.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/mindustry/world/blocks/defense/turrets/Turret.java index 7659d6102c..0baea25f93 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/Turret.java @@ -408,7 +408,7 @@ public class Turret extends ReloadTurret{ if(hasAmmo()){ if(Float.isNaN(reloadCounter)) reloadCounter = 0; - if(timer(timerTarget, target == null ? newTargetInterval : targetInterval)){ + if(timer(timerTarget, target != null ? newTargetInterval : targetInterval)){ findTarget(); } From 8944b08fbf67b3e6213cf4b21055ad0a198ebef0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 27 May 2024 21:45:23 -0400 Subject: [PATCH 09/17] Fixed map load dialog --- core/src/mindustry/editor/MapLoadDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/editor/MapLoadDialog.java b/core/src/mindustry/editor/MapLoadDialog.java index 46b98e037d..69acd8ed00 100644 --- a/core/src/mindustry/editor/MapLoadDialog.java +++ b/core/src/mindustry/editor/MapLoadDialog.java @@ -39,7 +39,7 @@ public class MapLoadDialog extends BaseDialog{ ButtonGroup