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:
parent
0ff64797d9
commit
32542df86c
@ -18,7 +18,7 @@
|
|||||||
<?import javafx.scene.paint.Color?>
|
<?import javafx.scene.paint.Color?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?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>
|
<children>
|
||||||
<MenuBar VBox.vgrow="NEVER">
|
<MenuBar VBox.vgrow="NEVER">
|
||||||
<menus>
|
<menus>
|
||||||
@ -50,6 +50,8 @@
|
|||||||
<SeparatorMenuItem mnemonicParsing="false" />
|
<SeparatorMenuItem mnemonicParsing="false" />
|
||||||
<MenuItem mnemonicParsing="false" text="Select All" />
|
<MenuItem mnemonicParsing="false" text="Select All" />
|
||||||
<MenuItem mnemonicParsing="false" text="Unselect All" />
|
<MenuItem mnemonicParsing="false" text="Unselect All" />
|
||||||
|
<SeparatorMenuItem mnemonicParsing="false" />
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onPropertiesDialog" text="Properties ..." />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu mnemonicParsing="false" text="Help">
|
<Menu mnemonicParsing="false" text="Help">
|
||||||
@ -64,6 +66,8 @@
|
|||||||
<TabPane>
|
<TabPane>
|
||||||
<tabs>
|
<tabs>
|
||||||
<Tab closable="false" text="A">
|
<Tab closable="false" text="A">
|
||||||
|
<content>
|
||||||
|
<ScrollPane>
|
||||||
<content>
|
<content>
|
||||||
<AnchorPane>
|
<AnchorPane>
|
||||||
<children>
|
<children>
|
||||||
@ -71,8 +75,12 @@
|
|||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
</ScrollPane>
|
||||||
|
</content>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab closable="false" text="B">
|
<Tab closable="false" text="B">
|
||||||
|
<content>
|
||||||
|
<ScrollPane>
|
||||||
<content>
|
<content>
|
||||||
<AnchorPane>
|
<AnchorPane>
|
||||||
<children>
|
<children>
|
||||||
@ -80,6 +88,8 @@
|
|||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
</ScrollPane>
|
||||||
|
</content>
|
||||||
</Tab>
|
</Tab>
|
||||||
</tabs>
|
</tabs>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
@ -88,6 +98,7 @@
|
|||||||
<AnchorPane id="Content" minHeight="-1.0" minWidth="-1.0" prefHeight="545.0" prefWidth="430.0">
|
<AnchorPane id="Content" minHeight="-1.0" minWidth="-1.0" prefHeight="545.0" prefWidth="430.0">
|
||||||
<children>
|
<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="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>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
@ -21,24 +21,34 @@ import scalafx.scene.input.MouseEvent
|
|||||||
import scalafx.scene.paint.Color
|
import scalafx.scene.paint.Color
|
||||||
import scalafx.scene.layout._
|
import scalafx.scene.layout._
|
||||||
import scalafx.stage.FileChooser
|
import scalafx.stage.FileChooser
|
||||||
|
import scalafx.stage.Modality
|
||||||
import FileChooser.ExtensionFilter
|
import FileChooser.ExtensionFilter
|
||||||
|
|
||||||
import fmon._
|
import fmon._
|
||||||
|
import fmon.builder.dialog.MapProperties
|
||||||
import fmon.draw.Palette
|
import fmon.draw.Palette
|
||||||
import fmon.draw.tile._
|
import fmon.draw.tile._
|
||||||
import fmon.util.{Direction, YamlHelper}
|
import fmon.util.{Direction, YamlHelper}
|
||||||
import fmon.world._
|
import fmon.world._
|
||||||
|
|
||||||
import Direction._
|
import Direction._
|
||||||
|
import Alert.AlertType
|
||||||
|
|
||||||
import scala.math.{min, max}
|
import scala.math.{min, max}
|
||||||
|
|
||||||
|
sealed trait MapBuilderState
|
||||||
|
|
||||||
|
case object GroundTile extends MapBuilderState
|
||||||
|
case object DoodadTile extends MapBuilderState
|
||||||
|
|
||||||
class MapBuilder {
|
class MapBuilder {
|
||||||
@FXML var tileSelector: jfxsl.TilePane = _
|
@FXML var tileSelector: jfxsl.TilePane = _
|
||||||
@FXML var doodadSelector: jfxsl.TilePane = _
|
@FXML var doodadSelector: jfxsl.TilePane = _
|
||||||
@FXML var gameMap: jfxsl.TilePane = _
|
@FXML var gameMap: jfxsl.TilePane = _
|
||||||
|
@FXML var doodadMap: jfxsl.TilePane = _
|
||||||
|
|
||||||
var imgSeq: IndexedSeq[ImageView] = _
|
var imgSeq: IndexedSeq[ImageView] = _
|
||||||
|
var doodadSeq: IndexedSeq[ImageView] = _
|
||||||
|
|
||||||
val tilesets = {
|
val tilesets = {
|
||||||
val dir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Data")
|
val dir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Data")
|
||||||
@ -46,6 +56,7 @@ class MapBuilder {
|
|||||||
}
|
}
|
||||||
var tileset: Tileset = _
|
var tileset: Tileset = _
|
||||||
var currTile: AutoTile = _
|
var currTile: AutoTile = _
|
||||||
|
var currState: MapBuilderState = GroundTile
|
||||||
|
|
||||||
var level: GameMap = _
|
var level: GameMap = _
|
||||||
|
|
||||||
@ -79,6 +90,7 @@ class MapBuilder {
|
|||||||
view.handleEvent(MouseEvent.Any) {
|
view.handleEvent(MouseEvent.Any) {
|
||||||
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||||
currTile = t
|
currTile = t
|
||||||
|
currState = GroundTile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view.delegate
|
view.delegate
|
||||||
@ -89,26 +101,50 @@ class MapBuilder {
|
|||||||
|
|
||||||
val doodads = tileset.doodadTiles.map(d => {
|
val doodads = tileset.doodadTiles.map(d => {
|
||||||
val view = new ImageView(d.icon.croppedImage())
|
val view = new ImageView(d.icon.croppedImage())
|
||||||
|
view.handleEvent(MouseEvent.Any) {
|
||||||
|
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||||
|
currTile = d
|
||||||
|
currState = DoodadTile
|
||||||
|
}
|
||||||
|
}
|
||||||
view.delegate
|
view.delegate
|
||||||
})
|
})
|
||||||
doodadSelector.children.clear()
|
doodadSelector.children.clear()
|
||||||
doodadSelector.children ++= doodads
|
doodadSelector.children ++= doodads
|
||||||
|
|
||||||
imgSeq = for (y <- 0 until level.height; x <- 0 until level.width) yield {
|
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) {
|
view.handleEvent(MouseEvent.Any) {
|
||||||
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||||
val index = point2index(x, y)
|
val index = point2index(x, y)
|
||||||
|
currState match {
|
||||||
|
case GroundTile => {
|
||||||
level.tiles = level.tiles.updated(index, currTile)
|
level.tiles = level.tiles.updated(index, currTile)
|
||||||
autotile(x, y)
|
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
|
view
|
||||||
}
|
}
|
||||||
gameMap.children.clear()
|
gameMap.children.clear()
|
||||||
gameMap.prefColumns = level.width
|
gameMap.prefColumns = level.width
|
||||||
gameMap.prefRows = level.height
|
gameMap.prefRows = level.height
|
||||||
gameMap.children ++= imgSeq.map(_.delegate)
|
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) {
|
for (y <- 0 until level.height; x <- 0 until level.width) {
|
||||||
smoothTile(x, y)
|
smoothTile(x, y)
|
||||||
@ -123,24 +159,39 @@ class MapBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def smoothTile(x: Int, y: Int) = {
|
def smoothTile(x: Int, y: Int) = {
|
||||||
val i = point2index(x, y)
|
imgSeq(level.pt2index(x, y)).image = level.smoothed(x, y)
|
||||||
val dirs = scala.collection.mutable.Set[Direction.Value]()
|
}
|
||||||
|
|
||||||
val onLeft = x == 0
|
@FXML
|
||||||
val onRight = x + 1 == level.width
|
def onPropertiesDialog: Unit = {
|
||||||
val onTop = y == 0
|
val fxmlLoader = new FXMLLoader(getClass().getResource("dialog/MapProperties.fxml"))
|
||||||
val onBottom = y + 1 == level.height
|
val parent: Parent = fxmlLoader.load()
|
||||||
|
val dialogController = fxmlLoader.getController[MapProperties]();
|
||||||
|
//dialogController.setAppMainObservableList(tvObservableList);
|
||||||
|
dialogController.init(level)
|
||||||
|
|
||||||
if (onLeft || level.tiles(left(i)) == level.tiles(i)) dirs += West
|
val dialog = new Alert(AlertType.Confirmation) {
|
||||||
if (onRight || level.tiles(right(i)) == level.tiles(i)) dirs += East
|
title = "Map Properties"
|
||||||
if (onTop || level.tiles(up(i)) == level.tiles(i)) dirs += North
|
dialogPane().content = parent
|
||||||
if (onBottom || level.tiles(down(i)) == level.tiles(i)) dirs += South
|
headerText = ""
|
||||||
if (onLeft || onTop || level.tiles(left(up(i))) == level.tiles(i)) dirs += Northwest
|
graphic = null
|
||||||
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
|
val result = dialog.showAndWait()
|
||||||
if (onBottom || onRight || level.tiles(right(down(i))) == level.tiles(i)) dirs += Southeast
|
println(result)
|
||||||
val index = point2index(x, y)
|
result match {
|
||||||
imgSeq(index).image = level.tiles(index).build(dirs.toSet).croppedImage()
|
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() = {
|
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()
|
||||||
|
}
|
@ -1,13 +1,19 @@
|
|||||||
package fmon.world
|
package fmon.world
|
||||||
|
|
||||||
|
import scalafx.scene.image.Image
|
||||||
|
|
||||||
import java.io._
|
import java.io._
|
||||||
|
|
||||||
|
import fmon.draw._
|
||||||
import fmon.draw.tile._
|
import fmon.draw.tile._
|
||||||
import fmon.util._
|
import fmon.util._
|
||||||
|
|
||||||
|
import Direction._
|
||||||
|
|
||||||
class GameMap(val width: Int, val height: Int, val tileset: Tileset) {
|
class GameMap(val width: Int, val height: Int, val tileset: Tileset) {
|
||||||
|
|
||||||
var tiles: IndexedSeq[AutoTile] = for (y <- 0 until height; x <- 0 until width) yield tileset.groundTiles.head
|
var tiles: IndexedSeq[AutoTile] = for (y <- 0 until height; x <- 0 until width) yield tileset.groundTiles.head
|
||||||
|
var doodads: IndexedSeq[AutoTile] = for (y <- 0 until height; x <- 0 until width) yield tileset.doodadTiles.head
|
||||||
|
|
||||||
def saveTo(file: File): Unit = {
|
def saveTo(file: File): Unit = {
|
||||||
val ostream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))
|
val ostream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))
|
||||||
@ -17,12 +23,43 @@ class GameMap(val width: Int, val height: Int, val tileset: Tileset) {
|
|||||||
val tileIndices = tileset.groundTiles.zipWithIndex.toMap
|
val tileIndices = tileset.groundTiles.zipWithIndex.toMap
|
||||||
tiles.foreach(t => ostream.writeInt(tileIndices(t)))
|
tiles.foreach(t => ostream.writeInt(tileIndices(t)))
|
||||||
//ostream.writeObject(tiles.map(tileIndices(_)).mkString(" "))
|
//ostream.writeObject(tiles.map(tileIndices(_)).mkString(" "))
|
||||||
|
val doodadIndices = tileset.doodadTiles.zipWithIndex.toMap
|
||||||
|
doodads.foreach(t => ostream.writeInt(doodadIndices(t)))
|
||||||
ostream.close()
|
ostream.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def apply(x: Int, y: Int): AutoTile = tiles(pt2index(x, y))
|
||||||
|
def doodad(x: Int, y: Int): AutoTile = doodads(pt2index(x, y))
|
||||||
|
|
||||||
|
def smoothed(x: Int, y: Int): Image = {
|
||||||
|
val i = pt2index(x, y)
|
||||||
|
val dirs = scala.collection.mutable.Set[Direction.Value]()
|
||||||
|
|
||||||
|
val onLeft = x == 0
|
||||||
|
val onRight = x + 1 == width
|
||||||
|
val onTop = y == 0
|
||||||
|
val onBottom = y + 1 == height
|
||||||
|
|
||||||
|
if (onLeft || tiles(left(i)) == tiles(i)) dirs += West
|
||||||
|
if (onRight || tiles(right(i)) == tiles(i)) dirs += East
|
||||||
|
if (onTop || tiles(up(i)) == tiles(i)) dirs += North
|
||||||
|
if (onBottom || tiles(down(i)) == tiles(i)) dirs += South
|
||||||
|
if (onLeft || onTop || tiles(left(up(i))) == tiles(i)) dirs += Northwest
|
||||||
|
if (onLeft || onBottom || tiles(down(left(i))) == tiles(i)) dirs += Southwest
|
||||||
|
if (onTop || onRight || tiles(right(up(i))) == tiles(i)) dirs += Northeast
|
||||||
|
if (onBottom || onRight || tiles(right(down(i))) == tiles(i)) dirs += Southeast
|
||||||
|
val index = pt2index(x, y)
|
||||||
|
tiles(index).build(dirs.toSet).croppedImage()
|
||||||
|
}
|
||||||
|
|
||||||
def pt2index(x: Int, y: Int) = y * width + x
|
def pt2index(x: Int, y: Int) = y * width + x
|
||||||
def index2x(i: Int) = i % width
|
def index2x(i: Int) = i % width
|
||||||
def index2y(i: Int) = i / width
|
def index2y(i: Int) = i / width
|
||||||
|
|
||||||
|
def left(i: Int) = i - 1
|
||||||
|
def right(i: Int) = i + 1
|
||||||
|
def up(i: Int) = i - width
|
||||||
|
def down(i: Int) = i + width
|
||||||
}
|
}
|
||||||
|
|
||||||
object GameMap {
|
object GameMap {
|
||||||
@ -36,9 +73,12 @@ object GameMap {
|
|||||||
val tokens = YamlHelper.extractSeq[TilesetToken](new FileInputStream(new File(dir, "Tilesets.yaml"))).map(t => (t.name, t)).toMap
|
val tokens = YamlHelper.extractSeq[TilesetToken](new FileInputStream(new File(dir, "Tilesets.yaml"))).map(t => (t.name, t)).toMap
|
||||||
val tileset = tokens("Outside").load(resourceDir)
|
val tileset = tokens("Outside").load(resourceDir)
|
||||||
val indices = for (y <- 0 until height; x <- 0 until width) yield istream.readInt()
|
val indices = for (y <- 0 until height; x <- 0 until width) yield istream.readInt()
|
||||||
|
val dindices = for (y <- 0 until height; x <- 0 until width) yield istream.readInt()
|
||||||
val map = new GameMap(width, height, tileset)
|
val map = new GameMap(width, height, tileset)
|
||||||
val tiles = indices.map(i => tileset.groundTiles(i))
|
val tiles = indices.map(i => tileset.groundTiles(i))
|
||||||
|
val doodads = dindices.map(i => tileset.doodadTiles(i))
|
||||||
map.tiles = tiles
|
map.tiles = tiles
|
||||||
|
map.doodads = doodads
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ import fmon.draw.tile._
|
|||||||
|
|
||||||
class Tileset(val groundTiles: IndexedSeq[AutoTile], val doodadTiles: IndexedSeq[AutoTile], val info: IndexedSeq[TileInfo]) {
|
class Tileset(val groundTiles: IndexedSeq[AutoTile], val doodadTiles: IndexedSeq[AutoTile], val info: IndexedSeq[TileInfo]) {
|
||||||
def groundInfo(index: Int) = info(index)
|
def groundInfo(index: Int) = info(index)
|
||||||
def doodadTiles(index: Int) = info(index - groundTiles.size)
|
def doodadInfo(index: Int) = info(index - groundTiles.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class TileInfo(
|
case class TileInfo(
|
||||||
|
17
FakeMon/src/fmon/world/ui/GameView.fxml
Normal file
17
FakeMon/src/fmon/world/ui/GameView.fxml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.ScrollPane?>
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
|
<?import javafx.scene.layout.TilePane?>
|
||||||
|
|
||||||
|
|
||||||
|
<ScrollPane fx:id="scroller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.world.ui.GameView">
|
||||||
|
<content>
|
||||||
|
<StackPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
|
||||||
|
<children>
|
||||||
|
<TilePane fx:id="background" />
|
||||||
|
<TilePane fx:id="doodads" />
|
||||||
|
</children>
|
||||||
|
</StackPane>
|
||||||
|
</content>
|
||||||
|
</ScrollPane>
|
75
FakeMon/src/fmon/world/ui/GameView.scala
Normal file
75
FakeMon/src/fmon/world/ui/GameView.scala
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package fmon.world.ui
|
||||||
|
|
||||||
|
import java.io._
|
||||||
|
|
||||||
|
import javafx.application.Application
|
||||||
|
import javafx.fxml.FXML
|
||||||
|
import javafx.fxml.FXMLLoader
|
||||||
|
import javafx.fxml.JavaFXBuilderFactory
|
||||||
|
import javafx.scene.{control => jfxsc, layout => jfxsl, Parent, Scene}
|
||||||
|
import javafx.stage.Stage
|
||||||
|
|
||||||
|
import scalafx.Includes._
|
||||||
|
import scalafx.beans.property._
|
||||||
|
import scalafx.collections.ObservableBuffer
|
||||||
|
import scalafx.scene.control._
|
||||||
|
import scalafx.scene.image.ImageView
|
||||||
|
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.world._
|
||||||
|
import fmon.util.YamlHelper
|
||||||
|
|
||||||
|
class GameView {
|
||||||
|
@FXML var scroller: jfxsc.ScrollPane = _
|
||||||
|
@FXML var background: jfxsl.TilePane = _
|
||||||
|
@FXML var doodads: jfxsl.TilePane = _
|
||||||
|
|
||||||
|
def loadLevel(level: GameMap): Unit = {
|
||||||
|
background.prefColumns = level.width
|
||||||
|
val tiles = for (y <- 0 until level.height; x <- 0 until level.width) yield {
|
||||||
|
new ImageView(level.smoothed(x, y)).delegate
|
||||||
|
}
|
||||||
|
|
||||||
|
background.children ++= tiles
|
||||||
|
|
||||||
|
doodads.prefColumns = level.width
|
||||||
|
val dtiles = for (y <- 0 until level.height; x <- 0 until level.width) yield {
|
||||||
|
new ImageView(level.doodad(x, y).icon.croppedImage()).delegate
|
||||||
|
}
|
||||||
|
doodads.children ++= dtiles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object GameView {
|
||||||
|
class GameApp extends Application {
|
||||||
|
override def start(primaryStage: Stage): Unit = {
|
||||||
|
val frameLoader = new FXMLLoader(getClass.getResource("GameView.fxml"))
|
||||||
|
val root: Parent = frameLoader.load()
|
||||||
|
val controller = frameLoader.getController[GameView]()
|
||||||
|
|
||||||
|
val stageFile = raw"C:\Users\James\Documents\Design\Project\Progena\Data\outside.map"
|
||||||
|
val level = GameMap.loadFrom(new File(stageFile))
|
||||||
|
controller.loadLevel(level)
|
||||||
|
//val builderLoader = new FXMLLoader(getClass.getResource("ElementBuilder.fxml"))
|
||||||
|
//val builder: Parent = builderLoader.load()
|
||||||
|
//val builderController = builderLoader.getController[ElementBuilder]()
|
||||||
|
|
||||||
|
//controller.pane.children = builder
|
||||||
|
//controller.builder = builderController
|
||||||
|
|
||||||
|
val scene: Scene = new Scene(root)
|
||||||
|
primaryStage.setScene(scene)
|
||||||
|
primaryStage.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def main(args: Array[String]): Unit = {
|
||||||
|
Application.launch(classOf[GameApp], args: _*)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user