mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-08-28 16:28:59 +00:00
Added shift to map editor
This commit is contained in:
parent
9692f89145
commit
0ddc073a3d
@ -125,6 +125,16 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public void moveMapByY(int amt) {
|
||||
getCurrentMap().shift(0, amt);
|
||||
redraw();
|
||||
}
|
||||
|
||||
public void moveMapByX(int amt) {
|
||||
getCurrentMap().shift(amt, 0);
|
||||
redraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildEditorUI(Pane tileEditorAnchorPane) {
|
||||
anchorPane = tileEditorAnchorPane;
|
||||
|
@ -72,6 +72,9 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
||||
}
|
||||
|
||||
public void putLocationScript(int x, int y, Script s) {
|
||||
if (x < 0 || y < 0) {
|
||||
return;
|
||||
}
|
||||
LocationTrigger trigger = new Script.LocationTrigger();
|
||||
trigger.setX(x);
|
||||
trigger.setY(y);
|
||||
@ -129,6 +132,9 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
||||
}
|
||||
|
||||
public void put(int x, int y, Tile t) {
|
||||
if (x < 0 || y < 0) {
|
||||
return;
|
||||
}
|
||||
width = Math.max(x + 1, width);
|
||||
height = Math.max(y + 1, height);
|
||||
for (int i = size(); i <= y; i++) {
|
||||
@ -173,6 +179,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
||||
|
||||
private void loadFromMap(Map m) {
|
||||
clear();
|
||||
locationScripts.clear();
|
||||
width = 0;
|
||||
height = 0;
|
||||
Set<Tile> unknownTiles = new HashSet<>();
|
||||
@ -236,4 +243,24 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
||||
clearScriptTriggersFromMap(script);
|
||||
backingMap.getScripts().getScript().remove(script);
|
||||
}
|
||||
|
||||
public void shift(int xAmt, int yAmt) {
|
||||
Scripts scripts = backingMap.getScripts();
|
||||
if (scripts != null) {
|
||||
List<Script> allScripts = new ArrayList<>(scripts.getScript());
|
||||
allScripts.forEach(
|
||||
s -> s.getLocationTrigger().forEach(
|
||||
l -> {
|
||||
l.setX(l.getX() + xAmt);
|
||||
l.setY(l.getY() + yAmt);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
backingMap.getChunk().forEach(c -> {
|
||||
c.setX(c.getX() + xAmt);
|
||||
c.setY(c.getY() + yAmt);
|
||||
});
|
||||
loadFromMap(backingMap);
|
||||
}
|
||||
}
|
||||
|
@ -150,6 +150,9 @@ public abstract class MapEditorTabController {
|
||||
@FXML
|
||||
abstract public void scrollMapUp(ActionEvent event);
|
||||
|
||||
@FXML
|
||||
abstract public void showShiftUI(ActionEvent event);
|
||||
|
||||
public void initalize() {
|
||||
assert mapEditorAnchorPane != null : "fx:id=\"mapEditorAnchorPane\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
|
||||
assert mapNameField != null : "fx:id=\"mapNameField\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
|
||||
|
@ -13,8 +13,6 @@ import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.ComboBoxListCell;
|
||||
@ -22,6 +20,7 @@ import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.image.WritableImage;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
import javax.xml.bind.JAXBException;
|
||||
@ -331,6 +330,29 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
|
||||
redrawMapScripts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showShiftUI(ActionEvent evt) {
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.setTitle("Shift map");
|
||||
dialog.setOnCloseRequest(v->dialog.close());
|
||||
dialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
|
||||
GridPane pane = new GridPane();
|
||||
Button moveUp = new Button("↑");
|
||||
moveUp.setOnMouseClicked(v->getCurrentEditor().moveMapByY(-1));
|
||||
pane.add(moveUp, 1, 0);
|
||||
Button moveDown = new Button("↓");
|
||||
moveDown.setOnMouseClicked(v->getCurrentEditor().moveMapByY(1));
|
||||
pane.add(moveDown, 1, 2);
|
||||
Button moveLeft = new Button("←");
|
||||
moveLeft.setOnMouseClicked(v->getCurrentEditor().moveMapByX(-1));
|
||||
pane.add(moveLeft, 0, 1);
|
||||
Button moveRight = new Button("→");
|
||||
moveRight.setOnMouseClicked(v->getCurrentEditor().moveMapByX(1));
|
||||
pane.add(moveRight, 2, 1);
|
||||
dialog.getDialogPane().setContent(pane);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuildMapSelectors() {
|
||||
Map m = mapSelect.getSelectionModel().getSelectedItem();
|
||||
|
@ -16,7 +16,7 @@
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<AnchorPane id="mapsTab" minHeight="0.0" minWidth="0.0" prefHeight="480.0" prefWidth="677.0" stylesheets="@styles/applicationui.css" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.MapEditorTabControllerImpl">
|
||||
<AnchorPane id="mapsTab" minHeight="0.0" minWidth="0.0" prefHeight="480.0" prefWidth="677.0" stylesheets="@styles/applicationui.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.MapEditorTabControllerImpl">
|
||||
<children>
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
@ -44,6 +44,7 @@
|
||||
</items>
|
||||
</Menu>
|
||||
<MenuItem mnemonicParsing="false" onAction="#mapTogglePanZoom" text="Toggle pan/zoom controls" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#showShiftUI" text="Shft Map" />
|
||||
</items>
|
||||
</MenuButton>
|
||||
<Label fx:id="cursorInfo" text="CursorInfo" />
|
||||
|
Loading…
Reference in New Issue
Block a user