diff --git a/core/src/mindustry/ClientLauncher.java b/core/src/mindustry/ClientLauncher.java index 732ff9f624..7694508f5d 100644 --- a/core/src/mindustry/ClientLauncher.java +++ b/core/src/mindustry/ClientLauncher.java @@ -4,6 +4,7 @@ import arc.*; import arc.assets.*; import arc.assets.loaders.*; import arc.audio.*; +import arc.files.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; @@ -69,7 +70,34 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform assets.setLoader(Texture.class, "." + mapExtension, new MapPreviewLoader()); tree = new FileTree(); - assets.setLoader(Sound.class, new SoundLoader(tree)); + assets.setLoader(Sound.class, new SoundLoader(tree){ + + @Override + public void loadAsync(AssetManager manager, String fileName, Fi file, SoundParameter parameter){ + + } + + @Override + public Sound loadSync(AssetManager manager, String fileName, Fi file, SoundParameter parameter){ + if(parameter != null && parameter.sound != null){ + mainExecutor.submit(() -> parameter.sound.load(file)); + + return parameter.sound; + }else{ + Sound sound = new Sound(); + + mainExecutor.submit(() -> { + try{ + sound.load(file); + }catch(Throwable t){ + Log.err("Error loading sound: " + file, t); + } + }); + + return sound; + } + } + }); assets.setLoader(Music.class, new MusicLoader(tree)); assets.load("sprites/error.png", Texture.class); diff --git a/core/src/mindustry/editor/MapGenerateDialog.java b/core/src/mindustry/editor/MapGenerateDialog.java index cc9f751d5e..64e3669a4a 100644 --- a/core/src/mindustry/editor/MapGenerateDialog.java +++ b/core/src/mindustry/editor/MapGenerateDialog.java @@ -310,7 +310,6 @@ public class MapGenerateDialog extends BaseDialog{ }).grow().left().pad(6).top(); }).width(280f).pad(3).top().left().fillY(); - if(++i % cols == 0){ filterTable.row(); } diff --git a/core/src/mindustry/editor/MapObjectivesDialog.java b/core/src/mindustry/editor/MapObjectivesDialog.java index 6d27ed5a3d..eff884b1a4 100644 --- a/core/src/mindustry/editor/MapObjectivesDialog.java +++ b/core/src/mindustry/editor/MapObjectivesDialog.java @@ -24,9 +24,11 @@ import static mindustry.Vars.*; public class MapObjectivesDialog extends BaseDialog{ private Seq objectives = new Seq<>(); - private @Nullable MapObjective selectedObjective; private Table list = new Table(); + private @Nullable MapObjective selectedObjective; + private @Nullable ObjectiveMarker selectedMarker; + public MapObjectivesDialog(){ super("@editor.objectives"); @@ -163,106 +165,7 @@ public class MapObjectivesDialog extends BaseDialog{ for(var field : fields){ if((field.getModifiers() & Modifier.PUBLIC) == 0) continue; - f.add(field.getName() + ": "); - - var type = field.getType(); - - if(type == String.class){ - f.field(Reflect.get(objective, field), text -> { - Reflect.set(objective, field, text); - }); - }else if(type == int.class){ - f.field(Reflect.get(objective, field) + "", text -> { - if(Strings.canParseInt(text)){ - Reflect.set(objective, field, Strings.parseInt(text)); - } - }).valid(Strings::canParseInt); - }else if(type == float.class){ - f.field(Reflect.get(objective, field) + "", text -> { - if(Strings.canParsePositiveFloat(text)){ - Reflect.set(objective, field, Strings.parseFloat(text)); - } - }).valid(Strings::canParseFloat); - }else if(type == UnlockableContent.class){ - - f.button(b -> b.image(Reflect.get(objective, field).uiIcon).size(iconSmall), () -> { - showContentSelect(null, result -> { - Reflect.set(objective, field, result); - setup(); - }, b -> b.techNode != null); - }).pad(4); - - }else if(type == Block.class){ - f.button(b -> b.image(Reflect.get(objective, field).uiIcon).size(iconSmall), () -> { - showContentSelect(ContentType.block, result -> { - Reflect.set(objective, field, result); - setup(); - }, b -> ((Block)b).synthetic()); - }).pad(4); - }else if(type == Team.class){ //TODO list of flags - f.button(b -> b.image(Tex.whiteui).color(Reflect.get(objective, field).color).size(iconSmall), () -> { - showTeamSelect(result -> { - Reflect.set(objective, field, result); - setup(); - }); - }).pad(4); - }else if(type == String[].class){ //TODO list of flags - - Table strings = new Table(); - strings.marginLeft(20f); - Runnable[] rebuild = {null}; - - strings.left(); - - float h = 40f; - - rebuild[0] = () -> { - strings.clear(); - strings.left().defaults().padBottom(3f).padTop(3f); - String[] array = Reflect.get(objective, field); - - for(int i = 0; i < array.length; i ++){ - int fi = i; - var str = array[i]; - strings.field(str, result -> { - array[fi] = result; - }).maxTextLength(20).height(h); - - strings.button(Icon.cancel, Styles.squarei, () -> { - - String[] next = new String[array.length - 1]; - System.arraycopy(array, 0, next, 0, fi); - if(fi < array.length - 1){ - System.arraycopy(array, fi + 1, next, fi, array.length - 1 - fi); - } - Reflect.set(objective, field, next); - - rebuild[0].run(); - }).padLeft(4).size(h); - - strings.row(); - } - - strings.button("+ Add", () -> { - String[] next = new String[array.length + 1]; - next[array.length] = ""; - System.arraycopy(array, 0, next, 0, array.length); - Reflect.set(objective, field, next); - - rebuild[0].run(); - }).height(h).width(140f).padLeft(-20f).left().row(); - }; - - rebuild[0].run(); - - f.row(); - f.add(strings).colspan(2).fill(); - - }else{ - f.add("[red]UNFINISHED"); - } - - f.row(); + displayField(f, field, objective); } }).grow(); @@ -272,6 +175,111 @@ public class MapObjectivesDialog extends BaseDialog{ } } + void displayField(Table f, Field field, Object objective){ + f.add(field.getName() + ": "); + + var type = field.getType(); + + if(type == String.class){ + f.field(Reflect.get(objective, field), text -> { + Reflect.set(objective, field, text); + }); + }else if(type == int.class){ + f.field(Reflect.get(objective, field) + "", text -> { + if(Strings.canParseInt(text)){ + Reflect.set(objective, field, Strings.parseInt(text)); + } + }).valid(Strings::canParseInt); + }else if(type == float.class){ + f.field(Reflect.get(objective, field) + "", text -> { + if(Strings.canParsePositiveFloat(text)){ + Reflect.set(objective, field, Strings.parseFloat(text)); + } + }).valid(Strings::canParseFloat); + }else if(type == UnlockableContent.class){ + + f.button(b -> b.image(Reflect.get(objective, field).uiIcon).size(iconSmall), () -> { + showContentSelect(null, result -> { + Reflect.set(objective, field, result); + setup(); + }, b -> b.techNode != null); + }).pad(4); + + }else if(type == Block.class){ + f.button(b -> b.image(Reflect.get(objective, field).uiIcon).size(iconSmall), () -> { + showContentSelect(ContentType.block, result -> { + Reflect.set(objective, field, result); + setup(); + }, b -> ((Block)b).synthetic()); + }).pad(4); + }else if(type == Team.class){ //TODO list of flags + f.button(b -> b.image(Tex.whiteui).color(Reflect.get(objective, field).color).size(iconSmall), () -> { + showTeamSelect(result -> { + Reflect.set(objective, field, result); + setup(); + }); + }).pad(4); + }else if(type == String[].class){ //TODO list of flags + + Table strings = new Table(); + strings.marginLeft(20f); + Runnable[] rebuild = {null}; + + strings.left(); + + float h = 40f; + + rebuild[0] = () -> { + strings.clear(); + strings.left().defaults().padBottom(3f).padTop(3f); + String[] array = Reflect.get(objective, field); + + for(int i = 0; i < array.length; i++){ + int fi = i; + var str = array[i]; + strings.field(str, result -> { + array[fi] = result; + }).maxTextLength(20).height(h); + + strings.button(Icon.cancel, Styles.squarei, () -> { + + String[] next = new String[array.length - 1]; + System.arraycopy(array, 0, next, 0, fi); + if(fi < array.length - 1){ + System.arraycopy(array, fi + 1, next, fi, array.length - 1 - fi); + } + Reflect.set(objective, field, next); + + rebuild[0].run(); + }).padLeft(4).size(h); + + strings.row(); + } + + strings.button("+ Add", () -> { + String[] next = new String[array.length + 1]; + next[array.length] = ""; + System.arraycopy(array, 0, next, 0, array.length); + Reflect.set(objective, field, next); + + rebuild[0].run(); + }).height(h).width(140f).padLeft(-20f).left().row(); + }; + + rebuild[0].run(); + + f.row(); + f.add(strings).colspan(2).fill(); + + //}else if(type == ObjectiveMarker[].class){ + + }else{ + f.add("[red]UNFINISHED"); + } + + f.row(); + } + void showContentSelect(@Nullable ContentType type, Cons cons, Boolf check){ BaseDialog dialog = new BaseDialog(""); dialog.cont.pane(p -> { diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index e347be85b7..0a39f15c9c 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1546,6 +1546,8 @@ public class LExecutor{ @Remote(called = Loc.server, unreliable = true) public static void logicExplosion(Team team, float x, float y, float radius, float damage, boolean air, boolean ground, boolean pierce){ + if(damage < 0f) return; + Damage.damage(team, x, y, radius, damage, pierce, air, ground); if(pierce){ Fx.spawnShockwave.at(x, y, World.conv(radius));