Started work on an animation builder

This commit is contained in:
James Daly 2019-06-29 23:24:53 -04:00
parent 2b001a9ab0
commit a9fc91ddde
3 changed files with 170 additions and 2 deletions

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.TilePane?>
<GridPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.builder.AnimationBuilder">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="234.0" minWidth="10.0" prefWidth="127.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="308.0" minWidth="10.0" prefWidth="308.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="267.0" minHeight="10.0" prefHeight="267.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="125.0" minHeight="0.0" prefHeight="34.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="124.0" minHeight="10.0" prefHeight="99.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ListView fx:id="animationList" prefWidth="150.0" />
<Button mnemonicParsing="false" onAction="#addAnimation" text="+" GridPane.rowIndex="1" />
<ImageView fx:id="viewpane" fitHeight="269.0" fitWidth="308.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" />
<ListView fx:id="frameList" prefWidth="150.0" GridPane.columnIndex="2" />
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
<children>
<Button mnemonicParsing="false" onAction="#playAnimation" text="Play" />
<Button mnemonicParsing="false" onAction="#addFrame" text="+" />
<Button mnemonicParsing="false" onAction="#removeFrame" text="-" />
</children>
</HBox>
<ScrollPane GridPane.columnSpan="3" GridPane.rowIndex="2">
<content>
<TilePane fx:id="tiles" hgap="5.0" prefHeight="121.0" prefWidth="600.0" vgap="5.0" />
</content>
</ScrollPane>
</children>
</GridPane>

View File

@ -0,0 +1,122 @@
package fmon.builder
import java.io._
import javafx.application.Application
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.fxml.JavaFXBuilderFactory
import javafx.scene.{control => jfxsc, 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.paint.Color
import scalafx.scene.layout._
import fmon.draw.Palette
class ObsAnimation(name_ : String) {
val name = new StringProperty(this, "name", name_)
val frames = new ObservableBuffer[FrameToken]()
override def toString = name()
}
case class FrameToken() {
}
class AnimationBuilder extends Savable {
@FXML var animationList: jfxsc.ListView[ObsAnimation] = _
@FXML var frameList: jfxsc.ListView[FrameToken] = _
@FXML var viewpane: javafx.scene.image.ImageView = _
@FXML var tiles: javafx.scene.layout.TilePane = _
val animations = ObservableBuffer[ObsAnimation]()
@FXML
def initialize(): Unit = {
animationList.items = animations
animationList.selectionModel().selectedIndex.onChange(selectionChange)
val palette = new Palette(new FileInputStream(raw"C:\Users\James\Documents\Design\Images\TimmahLexusX\Standalone Animations\Fireball.png"), 5, 3)
//for (x <- 0 until palette.numAcross; y <- 0 until palette.numDown) {
val children = for (y <- 0 until palette.numDown; x <- 0 until palette.numAcross) yield {
val img = palette(x, y)
val imgView = new ImageView() {
scaleX = 0.5
scaleY = 0.5
image = img.croppedImage()
}
imgView.delegate
//imgView.autosize()
//println(imgView.getBoundsInParent)
//img.draw(imgView)
//imgView.resize(100, 100)
}
tiles.children ++= children
tiles.prefTileWidth = 96 // TODO : I think this has to do with how the image is scaled
tiles.prefTileHeight = 96
}
def addAnimation(): Unit = {
animations += new ObsAnimation("Animation")
}
def selectionChange(): Unit = {
frameList.items = selected.frames
}
def playAnimation(): Unit = {
}
def addFrame(): Unit = {
println("New frame")
selected.frames += new FrameToken
}
def removeFrame(): Unit = {
frameList.items() --= frameList.selectionModel().getSelectedItems
}
override def saveTo(file: File): Unit = {
}
override def openFrom(file: File): Unit = {
}
private def selected: ObsAnimation = {
animationList.selectionModel().getSelectedItem
}
}
object AnimationBuilder {
class ABA extends Application {
override def start(primaryStage: Stage): Unit = {
val frameLoader = new FXMLLoader(getClass.getResource("App.fxml"))
val root: Parent = frameLoader.load()
val controller = frameLoader.getController[App]()
val builderLoader = new FXMLLoader(getClass.getResource("AnimationBuilder.fxml"))
val builder: Parent = builderLoader.load()
val builderController = builderLoader.getController[AnimationBuilder]()
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[ABA], args: _*)
}
}

View File

@ -3,17 +3,21 @@ package fmon.draw
import java.io.InputStream
import scalafx.geometry.Rectangle2D
import scalafx.scene.image.{Image, ImageView}
import scalafx.scene.image._
case class Box(val x: Int, val y: Int, val width: Int, val height: Int)
case class StillImg(val image: Image, val x: Double, val y: Double, val width: Double, val height: Double) extends Drawable {
def draw(view: ImageView, t: Double): Unit = {
def draw(view: ImageView, t: Double = 0): Unit = {
if (view.image() != image.delegate) {
view.image = image
}
view.viewport = new Rectangle2D(x, y, width, height)
}
def croppedImage(): Image = {
new WritableImage(image.pixelReader.get, x.toInt, y.toInt, width.toInt, height.toInt)
}
}
class Palette(val image: Image, val numAcross: Int, val numDown: Int) {