From cc26a0eeb30af7ff3295eb5d9f88c34030f31cc7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 24 Jun 2022 21:18:04 -0400 Subject: [PATCH] WIP objective editor progress --- .../sprites/effects/point-laser-center.png | Bin 0 -> 496 bytes .../sprites/effects/point-laser-end.png | Bin 0 -> 539 bytes .../sprites/effects/point-laser.png | Bin 0 -> 131 bytes core/src/mindustry/content/Blocks.java | 4 +- .../mindustry/editor/MapObjectivesDialog.java | 250 +++++++++++++++++- .../entities/bullet/PointLaserBulletType.java | 2 +- core/src/mindustry/game/MapObjectives.java | 7 +- 7 files changed, 256 insertions(+), 7 deletions(-) create mode 100644 core/assets-raw/sprites/effects/point-laser-center.png create mode 100644 core/assets-raw/sprites/effects/point-laser-end.png create mode 100644 core/assets-raw/sprites/effects/point-laser.png diff --git a/core/assets-raw/sprites/effects/point-laser-center.png b/core/assets-raw/sprites/effects/point-laser-center.png new file mode 100644 index 0000000000000000000000000000000000000000..31aa55c04063bab3a4203105f0dc5d1cf4136454 GIT binary patch literal 496 zcmeAS@N?(olHy`uVBq!ia0y~yVDJE84mJh`hS0a0-5D4d7>k44ofy`glX=O&z_`lO z#WAE}&fD3Jeuo`+Tz!u+?qC+W(@}k3l2@$A!D-b6i<_$2=QV7a<$L9bpUwTii`A#I zj4toFvG_>g83qV=uxm$T@yGXnKWC@hIsERk^WXSm8sZ{Tjoh}bF>;JFbYA6hlJ%>Y zv5T&kmWS^0g;P|7LsXY9oOC7j!q1v*^S4i*Fz5I2-QQ2_c>HinZ%?qtD?JS%%RobC zrA1ZVue44~-W+m9z(2&_^Day1$;=SXS4u0Q{1!W1QnPMs_v)*9=VsNkY|-*ZEN7M} zYf8IrpV_>8hI0DnExUjGet+F=PuQ2R1ih6Ur`*oZn4u^bxJqNv8%NuxF2`40irnWJ zA5+pc=Zv9k#GIt$mrr9)zUi!bX*Mm(`*O}yj$LYAtY1AQzY0-qk`Z{)puo;zsc>Rp zNWhnyUbe?&IuzJX9$xh-Z`UuqTRBTPq9&~u1 zr+p#9C=3jDv*$;tDnm{r-UW|y0_oh literal 0 HcmV?d00001 diff --git a/core/assets-raw/sprites/effects/point-laser-end.png b/core/assets-raw/sprites/effects/point-laser-end.png new file mode 100644 index 0000000000000000000000000000000000000000..23690954175b86148d352998b9c998b4d28a1c63 GIT binary patch literal 539 zcmeAS@N?(olHy`uVBq!ia0y~yVDJE84mJh`hS0a0-5D4d7>k44ofy`glX=O&zF= zho`ohPxQ3pTsz{P^9CtU-! z%yDT^`4P;c%6_+ekyX>OMe0cmN|z^wNV~rC-*`mEa&`OL7tf!spZhcFT6p8m5Z8d* zFHer}Z0vAy6-?p#G$lE=+v~aOG^yezS89$oKN2~;^!kmtUu5P?%i9^E?Yp@+;;5P_G&hQ~L*ewj zGjkZP=apY!xEP2nlle#S)2UL3Z>^`wi z*v2B{!NtvolvqQSUQF@SeBY!sZNG*|eA9G?sgGihB#A~Yzp+Q5L{R;7gXpZ;&3fA= q)bxn`>v8}^gA<2h%Y objectives = new Seq<>(); + private @Nullable MapObjective selectedObjective; + private Table list = new Table(); public MapObjectivesDialog(){ super("@editor.objectives"); - buttons.defaults().size(180f, 64f).pad(2f); + buttons.defaults().size(170f, 64f).pad(2f); buttons.button("@back", Icon.left, this::hide); buttons.button("@edit", Icon.edit, () -> { @@ -54,17 +68,247 @@ public class MapObjectivesDialog extends BaseDialog{ dialog.addCloseButton(); dialog.show(); }); + + buttons.button("@add", Icon.add, () -> { + var selection = new BaseDialog("@add"); + selection.cont.pane(p -> { + p.background(Tex.button); + p.marginRight(14); + p.defaults().size(195f, 56f); + int i = 0; + for(var gen : MapObjectives.allObjectiveTypes){ + var objective = gen.get(); + + p.button(objective.typeName(), Styles.flatt, () -> { + objectives.add(objective); + setup(); + selection.hide(); + }).with(Table::left).get().getLabelCell().growX().left().padLeft(5).labelAlign(Align.left); + + if(++i % 3 == 0) p.row(); + } + }).scrollX(false); + + selection.addCloseButton(); + selection.show(); + }); + + cont.clear(); + cont.pane(t -> { + list = t; + list.top(); + }).grow(); } public void show(Seq objectives){ super.show(); + selectedObjective = null; this.objectives = objectives; setup(); } void setup(){ - cont.clear(); - cont.add("This editor doesn't work yet. Come back later."); + list.clear(); + + for(var objective : objectives){ + list.table(Tex.button, t -> { + t.margin(0); + + t.button(b -> { + b.left(); + b.add(objective.typeName()).color(Pal.accent); + + b.add().growX(); + + b.button(Icon.upOpen, Styles.emptyi, () -> { + int index = objectives.indexOf(objective); + if(index > 0){ + objectives.swap(index, index - 1); + setup(); + } + }).pad(-6).size(46f); + + b.button(Icon.downOpen, Styles.emptyi, () -> { + int index = objectives.indexOf(objective); + if(index < objectives.size - 1){ + objectives.swap(index, index + 1); + setup(); + } + }).pad(-6).size(46f); + + b.button(Icon.cancel, Styles.emptyi, () -> { + objectives.remove(objective); + list.getCell(t).pad(0f); + + t.remove(); + setup(); + }).pad(-6).size(46f).padRight(-12f); + }, () -> { + if(selectedObjective != objective){ + selectedObjective = objective; + setup(); + } + }).growX().height(46f).pad(-6f).padBottom(0f).row(); + + if(selectedObjective == objective){ + t.table(f -> { + f.left(); + f.margin(10f); + + f.defaults().minHeight(40f).left(); + + var fields = objective.getClass().getFields(); + + 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(); + } + + }).grow(); + } + + }).width(340f).pad(8f).row(); + } + } + + void showContentSelect(@Nullable ContentType type, Cons cons, Boolf check){ + BaseDialog dialog = new BaseDialog(""); + dialog.cont.pane(p -> { + int i = 0; + for(var block : (type == null ? Vars.content.blocks().copy().as() + .add(Vars.content.items()) + .add(Vars.content.liquids()) + .add(Vars.content.units()) : + Vars.content.getBy(type).as())){ + + if(!check.get(block)) continue; + + p.image(block == Blocks.air ? Icon.none.getRegion() : block.uiIcon).size(iconMed).pad(3).with(b -> b.addListener(new HandCursorListener())) + .tooltip(block.localizedName).get().clicked(() -> { + cons.get(block); + dialog.hide(); + }); + if(++i % 10 == 0) p.row(); + } + }); + + dialog.closeOnBack(); + dialog.show(); + } + + void showTeamSelect(Cons cons){ + BaseDialog dialog = new BaseDialog(""); + for(var team : Team.baseTeams){ + + dialog.cont.image(Tex.whiteui).size(iconMed).color(team.color).pad(4).with(i -> i.addListener(new HandCursorListener())) + .tooltip(team.localized()).get().clicked(() -> { + cons.get(team); + dialog.hide(); + }); + } + + dialog.closeOnBack(); + dialog.show(); } } diff --git a/core/src/mindustry/entities/bullet/PointLaserBulletType.java b/core/src/mindustry/entities/bullet/PointLaserBulletType.java index a007f113df..c794f97f14 100644 --- a/core/src/mindustry/entities/bullet/PointLaserBulletType.java +++ b/core/src/mindustry/entities/bullet/PointLaserBulletType.java @@ -12,7 +12,7 @@ import mindustry.graphics.*; /** A continuous bullet type that only damages in a point. */ public class PointLaserBulletType extends BulletType{ - public String sprite = "drill-laser"; + public String sprite = "point-laser"; public TextureRegion laser, laserEnd; public Color color = Color.white; diff --git a/core/src/mindustry/game/MapObjectives.java b/core/src/mindustry/game/MapObjectives.java index b1f3c926b3..07ed022020 100644 --- a/core/src/mindustry/game/MapObjectives.java +++ b/core/src/mindustry/game/MapObjectives.java @@ -365,10 +365,15 @@ public class MapObjectives{ /** Base abstract class for any in-map objective. */ public static abstract class MapObjective{ + public @Nullable String details; public String[] flagsAdded = {}; public String[] flagsRemoved = {}; public ObjectiveMarker[] markers = {}; - public @Nullable String details; + + //TODO localize + public String typeName(){ + return getClass().getSimpleName().replace("Objective", ""); + } public MapObjective withFlags(String... flags){ this.flagsAdded = flags;