Advertisement
Stormtalons

Untitled

Dec 9th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 4.17 KB | None | 0 0
  1. import javafx.application.{Platform, Application}
  2. import javafx.event.{ActionEvent, EventHandler}
  3. import javafx.scene.Scene
  4. import javafx.scene.control.{Button, TextField, Label}
  5. import javafx.scene.layout.{HBox, TilePane, VBox, GridPane}
  6. import javafx.stage.Stage
  7.  
  8. sealed trait Stat
  9. {
  10.     val label: String
  11.     val statWeight: Double
  12.     def adjust(num: Int) = num * statWeight
  13. }
  14.  
  15. //Marksman
  16. case object Agility extends Stat{val label = "Agility:";val statWeight = 4.83}
  17. case object Multistrike extends Stat{val label = "Multistrike:";val statWeight = 1.83}
  18. case object Crit extends Stat{val label = "Crit:";val statWeight = 1.61}
  19. case object Versatility extends Stat{val label = "Versatility:";val statWeight = 1.55}
  20. case object Haste extends Stat{val label = "Haste:";val statWeight = 1.26}
  21. case object Mastery extends Stat{val label = "Mastery:";val statWeight = 1.25}
  22.  
  23. //Kitty
  24. //case object Agility extends Stat{val label = "Agility:";val statWeight = 4.79}
  25. //case object Multistrike extends Stat{val label = "Multistrike:";val statWeight = 1.64}
  26. //case object Crit extends Stat{val label = "Crit:";val statWeight = 1.74}
  27. //case object Versatility extends Stat{val label = "Versatility:";val statWeight = 1.42}
  28. //case object Haste extends Stat{val label = "Haste:";val statWeight = 1.49}
  29. //case object Mastery extends Stat{val label = "Mastery:";val statWeight = 1.33}
  30.  
  31. case class Gear(stats: Array[(Stat, Int)])
  32.  
  33. class GearPane(piece: Gear) extends GridPane
  34. {
  35.     var i = 0
  36.     var total = 0.0
  37.     for (stat <- piece.stats)
  38.     {
  39.         val label = new Label(stat._1.label)
  40.         val valueField = new TextField(stat._2.toString)
  41.         valueField.setPrefColumnCount(4)
  42.         val adjLabel = new Label("Adjusted Value:")
  43.         val adjValue = stat._1.adjust(stat._2)
  44.         total += adjValue
  45.         val adjValueField = new TextField(adjValue.toString)
  46.         adjValueField.setPrefColumnCount(4)
  47.  
  48.         add(label, 0, i)
  49.         add(valueField, 1, i)
  50.         add(adjLabel, 2, i)
  51.         add(adjValueField, 3, i)
  52.  
  53.         i += 1
  54.     }
  55.  
  56.     val totalLabel = new Label("Overall Item Value:")
  57.     val totalValue = new TextField(total.toString)
  58.     totalValue.setPrefColumnCount(4)
  59.  
  60.     add(totalLabel, 1, i)
  61.     add(totalValue, 2, i)
  62.  
  63.     setStyle("-fx-font-size: 10pt; -fx-font-weight: bold; -fx-border-size: 1px; -fx-border-style: solid; -fx-border-color: black")
  64. }
  65.  
  66. object Main extends App{new Main().launch}
  67. class Main extends Application
  68. {
  69.     def launch = javafx.application.Application.launch()
  70.  
  71.     def start(stg: Stage) =
  72.     {
  73.         val stats = Array(Agility, Multistrike, Crit, Versatility, Haste, Mastery)
  74.         val labels = Array[Label](
  75.             new Label("Agility:"),
  76.             new Label("Multistrike:"),
  77.             new Label("Crit:"),
  78.             new Label("Versatility:"),
  79.             new Label("Haste:"),
  80.             new Label("Mastery:")
  81.         )
  82.         val values = Array(
  83.             new TextField("0"),
  84.             new TextField("0"),
  85.             new TextField("0"),
  86.             new TextField("0"),
  87.             new TextField("0"),
  88.             new TextField("0")
  89.         )
  90.         values.foreach(tf => tf.setPrefColumnCount(4))
  91.         val inputPane = new GridPane
  92.         inputPane.setHgap(10)
  93.         inputPane.setVgap(10)
  94.         for (i <- 0 until values.length)
  95.         {
  96.             inputPane.add(labels(i), i, 0)
  97.             inputPane.add(values(i), i, 1)
  98.         }
  99.  
  100.         val gear = new TilePane
  101.         gear.setHgap(10)
  102.         gear.setVgap(10)
  103.  
  104.         val add = new Button("Add Calc")
  105.         add.setOnAction(new EventHandler[ActionEvent]
  106.         {
  107.             def handle(evt: ActionEvent): Unit =
  108.             {
  109.                 var statPairs = Array[(Stat, Int)]()
  110.                 for (i <- 0 until values.length)
  111.                 {
  112.                     if (values(i).getText.toInt != 0)
  113.                         statPairs = statPairs :+ (stats(i), values(i).getText.toInt)
  114.                     values(i).setText("0")
  115.                 }
  116.                 gear.getChildren.add(new GearPane(Gear(statPairs)))
  117.                 Platform.runLater(new Runnable{def run = values(0).requestFocus})
  118.             }
  119.         })
  120.         val clear = new Button("Clear")
  121.         clear.setOnAction(new EventHandler[ActionEvent]{def handle(evt: ActionEvent) = gear.getChildren.clear})
  122.  
  123.         val buttons = new HBox
  124.         buttons.setSpacing(10)
  125.         buttons.getChildren.addAll(add, clear)
  126.  
  127.         val vb = new VBox
  128.         vb.setSpacing(10)
  129.         vb.setStyle("-fx-font-size: 10pt; -fx-font-weight: bold")
  130.         vb.getChildren.addAll(inputPane, buttons, gear)
  131.  
  132.         stg.setScene(new Scene(vb, 1024, 768))
  133.         stg.setTitle("Gear Compare By Stat Weight")
  134.         stg.show
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement