Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.{Platform, Application}
- import javafx.event.{ActionEvent, EventHandler}
- import javafx.scene.Scene
- import javafx.scene.control.{Button, TextField, Label}
- import javafx.scene.layout.{HBox, TilePane, VBox, GridPane}
- import javafx.stage.Stage
- sealed trait Stat
- {
- val label: String
- val statWeight: Double
- def adjust(num: Int) = num * statWeight
- }
- //Marksman
- case object Agility extends Stat{val label = "Agility:";val statWeight = 4.83}
- case object Multistrike extends Stat{val label = "Multistrike:";val statWeight = 1.83}
- case object Crit extends Stat{val label = "Crit:";val statWeight = 1.61}
- case object Versatility extends Stat{val label = "Versatility:";val statWeight = 1.55}
- case object Haste extends Stat{val label = "Haste:";val statWeight = 1.26}
- case object Mastery extends Stat{val label = "Mastery:";val statWeight = 1.25}
- //Kitty
- //case object Agility extends Stat{val label = "Agility:";val statWeight = 4.79}
- //case object Multistrike extends Stat{val label = "Multistrike:";val statWeight = 1.64}
- //case object Crit extends Stat{val label = "Crit:";val statWeight = 1.74}
- //case object Versatility extends Stat{val label = "Versatility:";val statWeight = 1.42}
- //case object Haste extends Stat{val label = "Haste:";val statWeight = 1.49}
- //case object Mastery extends Stat{val label = "Mastery:";val statWeight = 1.33}
- case class Gear(stats: Array[(Stat, Int)])
- class GearPane(piece: Gear) extends GridPane
- {
- var i = 0
- var total = 0.0
- for (stat <- piece.stats)
- {
- val label = new Label(stat._1.label)
- val valueField = new TextField(stat._2.toString)
- valueField.setPrefColumnCount(4)
- val adjLabel = new Label("Adjusted Value:")
- val adjValue = stat._1.adjust(stat._2)
- total += adjValue
- val adjValueField = new TextField(adjValue.toString)
- adjValueField.setPrefColumnCount(4)
- add(label, 0, i)
- add(valueField, 1, i)
- add(adjLabel, 2, i)
- add(adjValueField, 3, i)
- i += 1
- }
- val totalLabel = new Label("Overall Item Value:")
- val totalValue = new TextField(total.toString)
- totalValue.setPrefColumnCount(4)
- add(totalLabel, 1, i)
- add(totalValue, 2, i)
- setStyle("-fx-font-size: 10pt; -fx-font-weight: bold; -fx-border-size: 1px; -fx-border-style: solid; -fx-border-color: black")
- }
- object Main extends App{new Main().launch}
- class Main extends Application
- {
- def launch = javafx.application.Application.launch()
- def start(stg: Stage) =
- {
- val stats = Array(Agility, Multistrike, Crit, Versatility, Haste, Mastery)
- val labels = Array[Label](
- new Label("Agility:"),
- new Label("Multistrike:"),
- new Label("Crit:"),
- new Label("Versatility:"),
- new Label("Haste:"),
- new Label("Mastery:")
- )
- val values = Array(
- new TextField("0"),
- new TextField("0"),
- new TextField("0"),
- new TextField("0"),
- new TextField("0"),
- new TextField("0")
- )
- values.foreach(tf => tf.setPrefColumnCount(4))
- val inputPane = new GridPane
- inputPane.setHgap(10)
- inputPane.setVgap(10)
- for (i <- 0 until values.length)
- {
- inputPane.add(labels(i), i, 0)
- inputPane.add(values(i), i, 1)
- }
- val gear = new TilePane
- gear.setHgap(10)
- gear.setVgap(10)
- val add = new Button("Add Calc")
- add.setOnAction(new EventHandler[ActionEvent]
- {
- def handle(evt: ActionEvent): Unit =
- {
- var statPairs = Array[(Stat, Int)]()
- for (i <- 0 until values.length)
- {
- if (values(i).getText.toInt != 0)
- statPairs = statPairs :+ (stats(i), values(i).getText.toInt)
- values(i).setText("0")
- }
- gear.getChildren.add(new GearPane(Gear(statPairs)))
- Platform.runLater(new Runnable{def run = values(0).requestFocus})
- }
- })
- val clear = new Button("Clear")
- clear.setOnAction(new EventHandler[ActionEvent]{def handle(evt: ActionEvent) = gear.getChildren.clear})
- val buttons = new HBox
- buttons.setSpacing(10)
- buttons.getChildren.addAll(add, clear)
- val vb = new VBox
- vb.setSpacing(10)
- vb.setStyle("-fx-font-size: 10pt; -fx-font-weight: bold")
- vb.getChildren.addAll(inputPane, buttons, gear)
- stg.setScene(new Scene(vb, 1024, 768))
- stg.setTitle("Gear Compare By Stat Weight")
- stg.show
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement