Schematic rotation

This commit is contained in:
Anuken
2019-10-18 11:38:00 -04:00
parent 30bcfb6d5e
commit f7d98591c9
7 changed files with 73 additions and 6 deletions

View File

@@ -24,7 +24,10 @@ load.content = Content
load.system = System load.system = System
load.mod = Mods load.mod = Mods
schematic.add = Save Schematic...
schematics = Schematics schematics = Schematics
schematic.flip = [accent][[{0}][]/[accent][[{1}][]: Flip Schematic
schematic.saved = Schematic saved.
stat.wave = Waves Defeated:[accent] {0} stat.wave = Waves Defeated:[accent] {0}
stat.enemiesDestroyed = Enemies Destroyed:[accent] {0} stat.enemiesDestroyed = Enemies Destroyed:[accent] {0}
@@ -629,6 +632,8 @@ keybind.press.axis = Press an axis or key...
keybind.screenshot.name = Map Screenshot keybind.screenshot.name = Map Screenshot
keybind.move_x.name = Move x keybind.move_x.name = Move x
keybind.move_y.name = Move y keybind.move_y.name = Move y
keybind.schematic_flip_x.name = Flip Schematic X
keybind.schematic_flip_y.name = Flip Schematic Y
keybind.fullscreen.name = Toggle Fullscreen keybind.fullscreen.name = Toggle Fullscreen
keybind.select.name = Select/Shoot keybind.select.name = Select/Shoot
keybind.diagonal_placement.name = Diagonal Placement keybind.diagonal_placement.name = Diagonal Placement

View File

@@ -186,6 +186,13 @@ public class UI implements ApplicationListener, Loadable{
Core.scene.act(); Core.scene.act();
Core.scene.draw(); Core.scene.draw();
if(Core.input.keyTap(KeyCode.MOUSE_LEFT) && Core.scene.getKeyboardFocus() instanceof TextField){
Element e = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
if(!(e instanceof TextField)){
Core.scene.setKeyboardFocus(null);
}
}
//draw overlay for buttons //draw overlay for buttons
if(state.rules.tutorial){ if(state.rules.tutorial){
control.tutorial.draw(); control.tutorial.draw();
@@ -309,7 +316,7 @@ public class UI implements ApplicationListener, Loadable{
Table table = new Table(); Table table = new Table();
table.setFillParent(true); table.setFillParent(true);
table.actions(Actions.fadeOut(7f, Interpolation.fade), Actions.remove()); table.actions(Actions.fadeOut(7f, Interpolation.fade), Actions.remove());
table.top().add(info).padTop(10); table.top().add(info).style(Styles.outlineLabel).padTop(10);
Core.scene.add(table); Core.scene.add(table);
} }

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.game; package io.anuke.mindustry.game;
import io.anuke.arc.collection.*; import io.anuke.arc.collection.*;
import io.anuke.arc.files.*;
import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
@@ -9,6 +10,7 @@ public class Schematic{
public StringMap tags; public StringMap tags;
public int width, height; public int width, height;
public boolean workshop; public boolean workshop;
public @Nullable FileHandle file;
public Schematic(Array<Stile> tiles, StringMap tags, int width, int height){ public Schematic(Array<Stile> tiles, StringMap tags, int width, int height){
this.tiles = tiles; this.tiles = tiles;

View File

@@ -244,6 +244,7 @@ public class Schematics implements Loadable{
if(!s.tags.containsKey("name")){ if(!s.tags.containsKey("name")){
s.tags.put("name", file.nameWithoutExtension()); s.tags.put("name", file.nameWithoutExtension());
} }
s.file = file;
return s; return s;
} }

View File

@@ -19,6 +19,8 @@ public enum Binding implements KeyBind{
diagonal_placement(KeyCode.CONTROL_LEFT), diagonal_placement(KeyCode.CONTROL_LEFT),
pick(KeyCode.MOUSE_MIDDLE), pick(KeyCode.MOUSE_MIDDLE),
schematic(KeyCode.F), schematic(KeyCode.F),
schematic_flip_x(KeyCode.Z),
schematic_flip_y(KeyCode.X),
dash(KeyCode.SHIFT_LEFT), dash(KeyCode.SHIFT_LEFT),
gridMode(KeyCode.BACKTICK), gridMode(KeyCode.BACKTICK),
gridModeShift(KeyCode.ALT_LEFT), gridModeShift(KeyCode.ALT_LEFT),

View File

@@ -7,6 +7,7 @@ import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.input.*; import io.anuke.arc.input.*;
import io.anuke.arc.math.*; import io.anuke.arc.math.*;
import io.anuke.arc.scene.*; import io.anuke.arc.scene.*;
import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.ui.*; import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.core.GameState.*; import io.anuke.mindustry.core.GameState.*;
@@ -42,7 +43,7 @@ public class DesktopInput extends InputHandler{
public void buildUI(Group group){ public void buildUI(Group group){
group.fill(t -> { group.fill(t -> {
t.bottom().update(() -> t.getColor().a = Mathf.lerpDelta(t.getColor().a, player.isBuilding() ? 1f : 0f, 0.15f)); t.bottom().update(() -> t.getColor().a = Mathf.lerpDelta(t.getColor().a, player.isBuilding() ? 1f : 0f, 0.15f));
t.visible(() -> Core.settings.getBool("hints")); t.visible(() -> Core.settings.getBool("hints") && selectRequests.isEmpty());
t.table(Styles.black6, b -> { t.table(Styles.black6, b -> {
b.defaults().left(); b.defaults().left();
b.label(() -> Core.bundle.format(!player.isBuilding ? "resumebuilding" : "pausebuilding", Core.keybinds.get(Binding.pause_building).key.name())).style(Styles.outlineLabel); b.label(() -> Core.bundle.format(!player.isBuilding ? "resumebuilding" : "pausebuilding", Core.keybinds.get(Binding.pause_building).key.name())).style(Styles.outlineLabel);
@@ -50,6 +51,28 @@ public class DesktopInput extends InputHandler{
b.add(Core.bundle.format("cancelbuilding", Core.keybinds.get(Binding.clear_building).key.name())).style(Styles.outlineLabel); b.add(Core.bundle.format("cancelbuilding", Core.keybinds.get(Binding.clear_building).key.name())).style(Styles.outlineLabel);
}).margin(10f); }).margin(10f);
}); });
group.fill(t -> {
t.visible(() -> lastSchematic != null && !selectRequests.isEmpty());
t.bottom();
t.table(Styles.black6, b -> {
b.touchable(Touchable.enabled);
b.defaults().left();
b.add(Core.bundle.format("schematic.flip",
Core.keybinds.get(Binding.schematic_flip_x).key.name(),
Core.keybinds.get(Binding.schematic_flip_y).key.name())).style(Styles.outlineLabel);
b.row();
b.table(a -> {
a.addImageTextButton("$schematic.add", Icon.saveSmall, () -> {
ui.showTextInput("$schematic.add", "$name", "", text -> {
lastSchematic.tags.put("name", text);
schematics.add(lastSchematic);
ui.showInfoFade("$schematic.saved");
});
}).colspan(2).size(250f, 50f);
});
}).margin(6f);
});
} }
@Override @Override
@@ -172,6 +195,8 @@ public class DesktopInput extends InputHandler{
if(Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0 && isPlacing() && mode == placing){ if(Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0 && isPlacing() && mode == placing){
updateLine(selectX, selectY); updateLine(selectX, selectY);
}else if(Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0 && !selectRequests.isEmpty()){
rotateRequests(selectRequests, (int)Core.input.axisTap(Binding.rotate));
} }
Tile cursor = tileAt(Core.input.mouseX(), Core.input.mouseY()); Tile cursor = tileAt(Core.input.mouseX(), Core.input.mouseY());
@@ -256,9 +281,11 @@ public class DesktopInput extends InputHandler{
} }
if(Core.input.keyRelease(Binding.schematic)){ if(Core.input.keyRelease(Binding.schematic)){
Schematic schem = schematics.create(schemX, schemY, rawCursorX, rawCursorY); lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
schematics.add(schem); useSchematic(lastSchematic);
useSchematic(schem); if(selectRequests.isEmpty()){
lastSchematic = null;
}
} }
//TODO remove //TODO remove

View File

@@ -14,13 +14,14 @@ import io.anuke.arc.scene.*;
import io.anuke.arc.scene.event.*; import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.content.*; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.effect.*; import io.anuke.mindustry.entities.effect.*;
import io.anuke.mindustry.entities.traits.BuilderTrait.*; import io.anuke.mindustry.entities.traits.BuilderTrait.*;
import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.Teams.*; import io.anuke.mindustry.game.Teams.*;
import io.anuke.mindustry.gen.*; import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.graphics.*;
@@ -52,6 +53,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public boolean droppingItem; public boolean droppingItem;
public Group uiGroup; public Group uiGroup;
protected @Nullable Schematic lastSchematic;
protected GestureDetector detector; protected GestureDetector detector;
protected PlaceLine line = new PlaceLine(); protected PlaceLine line = new PlaceLine();
protected BuildRequest resultreq; protected BuildRequest resultreq;
@@ -224,6 +226,27 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
selectRequests.addAll(schematics.toRequests(schem, world.toTile(player.x), world.toTile(player.y))); selectRequests.addAll(schematics.toRequests(schem, world.toTile(player.x), world.toTile(player.y)));
} }
public void rotateRequests(Array<BuildRequest> requests, int direction){
int ox = tileX(getMouseX()), oy = tileY(getMouseY());
requests.each(req -> {
//req.x -= ox;
//req.y -= oy;
float wx = (req.x - ox) * tilesize + req.block.offset(), wy = (req.y - oy) * tilesize + req.block.offset();
float x = wx;
if(direction >= 0){
wx = -wy;
wy = x;
}else{
wx = wy;
wy = -x;
}
req.x = world.toTile(wx - req.block.offset()) + ox;
req.y = world.toTile(wy - req.block.offset()) + oy;
req.rotation += direction;
});
}
/** Returns the selection request that overlaps this position, or null. */ /** Returns the selection request that overlaps this position, or null. */
protected BuildRequest getRequest(int x, int y){ protected BuildRequest getRequest(int x, int y){
return getRequest(x, y, 1, null); return getRequest(x, y, 1, null);