Allowed the size of the levels to be changed and created the initial window that the world map will play in.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<?import javafx.scene.paint.Color?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.builder.MapBuilder">
|
||||
<VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.builder.MapBuilder">
|
||||
<children>
|
||||
<MenuBar VBox.vgrow="NEVER">
|
||||
<menus>
|
||||
@@ -50,6 +50,8 @@
|
||||
<SeparatorMenuItem mnemonicParsing="false" />
|
||||
<MenuItem mnemonicParsing="false" text="Select All" />
|
||||
<MenuItem mnemonicParsing="false" text="Unselect All" />
|
||||
<SeparatorMenuItem mnemonicParsing="false" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#onPropertiesDialog" text="Properties ..." />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Help">
|
||||
@@ -65,20 +67,28 @@
|
||||
<tabs>
|
||||
<Tab closable="false" text="A">
|
||||
<content>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<TilePane fx:id="tileSelector" hgap="2.0" prefColumns="8" vgap="2.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<ScrollPane>
|
||||
<content>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<TilePane fx:id="tileSelector" hgap="2.0" prefColumns="8" vgap="2.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
</content>
|
||||
</Tab>
|
||||
<Tab closable="false" text="B">
|
||||
<content>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<TilePane fx:id="doodadSelector" hgap="2.0" prefColumns="8" vgap="2.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<ScrollPane>
|
||||
<content>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<TilePane fx:id="doodadSelector" hgap="2.0" prefColumns="8" vgap="2.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
</content>
|
||||
</Tab>
|
||||
</tabs>
|
||||
@@ -88,6 +98,7 @@
|
||||
<AnchorPane id="Content" minHeight="-1.0" minWidth="-1.0" prefHeight="545.0" prefWidth="430.0">
|
||||
<children>
|
||||
<TilePane fx:id="gameMap" hgap="1.0" layoutX="14.0" layoutY="28.0" prefColumns="10" prefRows="10" vgap="1.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<TilePane fx:id="doodadMap" hgap="1.0" vgap="1.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
||||
@@ -21,24 +21,34 @@ import scalafx.scene.input.MouseEvent
|
||||
import scalafx.scene.paint.Color
|
||||
import scalafx.scene.layout._
|
||||
import scalafx.stage.FileChooser
|
||||
import scalafx.stage.Modality
|
||||
import FileChooser.ExtensionFilter
|
||||
|
||||
import fmon._
|
||||
import fmon.builder.dialog.MapProperties
|
||||
import fmon.draw.Palette
|
||||
import fmon.draw.tile._
|
||||
import fmon.util.{Direction, YamlHelper}
|
||||
import fmon.world._
|
||||
|
||||
import Direction._
|
||||
import Alert.AlertType
|
||||
|
||||
import scala.math.{min, max}
|
||||
|
||||
sealed trait MapBuilderState
|
||||
|
||||
case object GroundTile extends MapBuilderState
|
||||
case object DoodadTile extends MapBuilderState
|
||||
|
||||
class MapBuilder {
|
||||
@FXML var tileSelector: jfxsl.TilePane = _
|
||||
@FXML var doodadSelector: jfxsl.TilePane = _
|
||||
@FXML var gameMap: jfxsl.TilePane = _
|
||||
@FXML var doodadMap: jfxsl.TilePane = _
|
||||
|
||||
var imgSeq: IndexedSeq[ImageView] = _
|
||||
var doodadSeq: IndexedSeq[ImageView] = _
|
||||
|
||||
val tilesets = {
|
||||
val dir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Data")
|
||||
@@ -46,6 +56,7 @@ class MapBuilder {
|
||||
}
|
||||
var tileset: Tileset = _
|
||||
var currTile: AutoTile = _
|
||||
var currState: MapBuilderState = GroundTile
|
||||
|
||||
var level: GameMap = _
|
||||
|
||||
@@ -79,6 +90,7 @@ class MapBuilder {
|
||||
view.handleEvent(MouseEvent.Any) {
|
||||
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||
currTile = t
|
||||
currState = GroundTile
|
||||
}
|
||||
}
|
||||
view.delegate
|
||||
@@ -89,26 +101,50 @@ class MapBuilder {
|
||||
|
||||
val doodads = tileset.doodadTiles.map(d => {
|
||||
val view = new ImageView(d.icon.croppedImage())
|
||||
view.handleEvent(MouseEvent.Any) {
|
||||
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||
currTile = d
|
||||
currState = DoodadTile
|
||||
}
|
||||
}
|
||||
view.delegate
|
||||
})
|
||||
doodadSelector.children.clear()
|
||||
doodadSelector.children ++= doodads
|
||||
|
||||
imgSeq = for (y <- 0 until level.height; x <- 0 until level.width) yield {
|
||||
val view = new ImageView(currTile.icon.croppedImage()) // TODO Tile with adjacent
|
||||
val view = new ImageView(level(x, y).icon.croppedImage()) // TODO Tile with adjacent
|
||||
view.handleEvent(MouseEvent.Any) {
|
||||
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||
val index = point2index(x, y)
|
||||
level.tiles = level.tiles.updated(index, currTile)
|
||||
autotile(x, y)
|
||||
currState match {
|
||||
case GroundTile => {
|
||||
level.tiles = level.tiles.updated(index, currTile)
|
||||
autotile(x, y)
|
||||
}
|
||||
case DoodadTile => {
|
||||
level.doodads = level.doodads.updated(index, currTile)
|
||||
doodadSeq(index).image = level.doodads(index).icon.croppedImage()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
view
|
||||
}
|
||||
doodadSeq = for (y <- 0 until level.height; x <- 0 until level.width) yield {
|
||||
val view = new ImageView(level.doodad(x, y).icon.croppedImage())
|
||||
view
|
||||
}
|
||||
gameMap.children.clear()
|
||||
gameMap.prefColumns = level.width
|
||||
gameMap.prefRows = level.height
|
||||
gameMap.children ++= imgSeq.map(_.delegate)
|
||||
doodadMap.children.clear()
|
||||
doodadMap.prefColumns = level.width
|
||||
doodadMap.prefRows = level.height
|
||||
doodadMap.children ++= doodadSeq.map(_.delegate)
|
||||
doodadMap.mouseTransparent = true
|
||||
|
||||
for (y <- 0 until level.height; x <- 0 until level.width) {
|
||||
smoothTile(x, y)
|
||||
@@ -123,24 +159,39 @@ class MapBuilder {
|
||||
}
|
||||
|
||||
def smoothTile(x: Int, y: Int) = {
|
||||
val i = point2index(x, y)
|
||||
val dirs = scala.collection.mutable.Set[Direction.Value]()
|
||||
|
||||
val onLeft = x == 0
|
||||
val onRight = x + 1 == level.width
|
||||
val onTop = y == 0
|
||||
val onBottom = y + 1 == level.height
|
||||
|
||||
if (onLeft || level.tiles(left(i)) == level.tiles(i)) dirs += West
|
||||
if (onRight || level.tiles(right(i)) == level.tiles(i)) dirs += East
|
||||
if (onTop || level.tiles(up(i)) == level.tiles(i)) dirs += North
|
||||
if (onBottom || level.tiles(down(i)) == level.tiles(i)) dirs += South
|
||||
if (onLeft || onTop || level.tiles(left(up(i))) == level.tiles(i)) dirs += Northwest
|
||||
if (onLeft || onBottom || level.tiles(down(left(i))) == level.tiles(i)) dirs += Southwest
|
||||
if (onTop || onRight || level.tiles(right(up(i))) == level.tiles(i)) dirs += Northeast
|
||||
if (onBottom || onRight || level.tiles(right(down(i))) == level.tiles(i)) dirs += Southeast
|
||||
val index = point2index(x, y)
|
||||
imgSeq(index).image = level.tiles(index).build(dirs.toSet).croppedImage()
|
||||
imgSeq(level.pt2index(x, y)).image = level.smoothed(x, y)
|
||||
}
|
||||
|
||||
@FXML
|
||||
def onPropertiesDialog: Unit = {
|
||||
val fxmlLoader = new FXMLLoader(getClass().getResource("dialog/MapProperties.fxml"))
|
||||
val parent: Parent = fxmlLoader.load()
|
||||
val dialogController = fxmlLoader.getController[MapProperties]();
|
||||
//dialogController.setAppMainObservableList(tvObservableList);
|
||||
dialogController.init(level)
|
||||
|
||||
val dialog = new Alert(AlertType.Confirmation) {
|
||||
title = "Map Properties"
|
||||
dialogPane().content = parent
|
||||
headerText = ""
|
||||
graphic = null
|
||||
}
|
||||
val result = dialog.showAndWait()
|
||||
println(result)
|
||||
result match {
|
||||
case Some(ButtonType.OK) => {
|
||||
println(dialogController.width, dialogController.height)
|
||||
level = new GameMap(dialogController.width, dialogController.height, tileset)
|
||||
level.tiles = level.tiles.map(_ => currTile)
|
||||
setup()
|
||||
}
|
||||
case _ => ()
|
||||
}
|
||||
/*val scene = new Scene(parent, 300, 200);
|
||||
val stage = new Stage();
|
||||
stage.initModality(Modality.ApplicationModal);
|
||||
stage.setScene(scene);
|
||||
stage.showAndWait();*/
|
||||
}
|
||||
|
||||
def save() = {
|
||||
|
||||
28
Builder/src/fmon/builder/dialog/MapProperties.fxml
Normal file
28
Builder/src/fmon/builder/dialog/MapProperties.fxml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Spinner?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.builder.dialog.MapProperties">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="294.0" minWidth="10.0" prefWidth="74.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Width" />
|
||||
<Label text="Height" GridPane.rowIndex="1" />
|
||||
<Label text="Tileset" GridPane.rowIndex="2" />
|
||||
<Spinner fx:id="widthSpin" editable="true" initialValue="10" max="100" min="10" GridPane.columnIndex="1" />
|
||||
<Spinner fx:id="heightSpin" editable="true" initialValue="10" max="100" min="10" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<ComboBox fx:id="tilesetChooser" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
</children>
|
||||
</GridPane>
|
||||
26
Builder/src/fmon/builder/dialog/MapProperties.scala
Normal file
26
Builder/src/fmon/builder/dialog/MapProperties.scala
Normal file
@@ -0,0 +1,26 @@
|
||||
package fmon.builder.dialog
|
||||
|
||||
import javafx.fxml.FXML
|
||||
import javafx.scene.{control => jfxsc, layout => jfxsl, Parent, Scene}
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.scene.control.SpinnerValueFactory
|
||||
|
||||
import fmon.world.GameMap
|
||||
|
||||
class MapProperties {
|
||||
@FXML var widthSpin: jfxsc.Spinner[Int] = _
|
||||
@FXML var heightSpin: jfxsc.Spinner[Int] = _
|
||||
|
||||
@FXML def initialize(): Unit = {
|
||||
println(widthSpin)
|
||||
}
|
||||
|
||||
def init(level: GameMap): Unit = {
|
||||
widthSpin.valueFactory().value = level.width
|
||||
heightSpin.valueFactory().value = level.height
|
||||
}
|
||||
|
||||
def width = widthSpin.value()
|
||||
def height = heightSpin.value()
|
||||
}
|
||||
Reference in New Issue
Block a user