Add button generator, add list of player colours
This commit is contained in:
parent
40d56974d2
commit
34647418af
21
JavaFX.iml
21
JavaFX.iml
|
@ -32,5 +32,26 @@
|
|||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:xmlgraphics-commons:2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: de.codecentric.centerdevice:javafxsvg:1.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-transcoder:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-anim:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-css:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-ext:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-parser:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-svg-dom:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-awt-util:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-bridge:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-script:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: xalan:xalan:2.7.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-dom:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-gvt:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-svggen:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-util:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-xml:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.04" level="project" />
|
||||
<orderEntry type="library" name="Maven: xml-apis:xml-apis-ext:1.3.04" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:xmlgraphics-commons:2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
|
||||
</component>
|
||||
</module>
|
1
pom.xml
1
pom.xml
|
@ -15,7 +15,6 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<configuration>
|
||||
<!-- or whatever version you use -->
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
|
|
11
src/main/java/nl/minkema/leendert/Game.java
Normal file
11
src/main/java/nl/minkema/leendert/Game.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package nl.minkema.leendert;
|
||||
|
||||
import javafx.scene.Group;
|
||||
|
||||
/**
|
||||
* @author J0QUE
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Game extends Group {
|
||||
|
||||
}
|
|
@ -8,6 +8,10 @@ import javafx.scene.media.Media;
|
|||
import javafx.scene.media.MediaPlayer;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* @author J0QUE
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Main extends Application {
|
||||
public static Scene scene;
|
||||
|
||||
|
|
|
@ -1,21 +1,41 @@
|
|||
package nl.minkema.leendert;
|
||||
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.media.Media;
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextBoundsType;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by jpdej on 23-2-2017.
|
||||
* @author J0QUE
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Menu extends Group {
|
||||
|
||||
public Menu() throws URISyntaxException {
|
||||
public static ArrayList<Paint> playerColors = new ArrayList<>();
|
||||
|
||||
public Menu() throws URISyntaxException, MalformedURLException {
|
||||
while(playerColors.size()<21) {
|
||||
Color c = getRandomColor();
|
||||
if (!playerColors.contains(c)) {
|
||||
playerColors.add(c);
|
||||
}
|
||||
}
|
||||
ArrayList<Node> nodes = new ArrayList<>();
|
||||
Image bg = new Image("https://s-media-cache-ak0.pinimg.com/originals/56/b2/3e/56b23e286dc03db415db7af75d15d58a.jpg");
|
||||
ImageView view = new ImageView(bg);
|
||||
|
@ -24,14 +44,76 @@ public class Menu extends Group {
|
|||
view.setY(0);
|
||||
view.setFitHeight(900);
|
||||
view.setPreserveRatio(true);
|
||||
String loc = this.getClass().getResource("/music/menu.wav").toString();
|
||||
String loc = this.getClass().getResource("/music/menu.mp4").toString();
|
||||
//loc = new File("menu.mp4").toURI().toURL().toString();
|
||||
System.out.println(loc);
|
||||
Media music = new Media(loc);
|
||||
|
||||
MediaPlayer menuplayer = new MediaPlayer(music);
|
||||
menuplayer.setCycleCount(Integer.MAX_VALUE);
|
||||
menuplayer.setVolume(0.6f);
|
||||
menuplayer.setAutoPlay(true);
|
||||
menuplayer.play();
|
||||
menuplayer.play();
|
||||
nodes.add(view);
|
||||
nodes.add(createButton("2 players", 100, 100, event -> {
|
||||
System.out.println("2 players");
|
||||
}));
|
||||
nodes.add(createButton("3 players", 100, 150, event -> System.out.println("3 players")));
|
||||
|
||||
getChildren().addAll(nodes);
|
||||
playerColors.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public static StackPane createButton(String string, double x, double y, EventHandler<MouseEvent> onClick) {
|
||||
Text text = createText(string);
|
||||
Rectangle rectangle = rectangulate(text);
|
||||
StackPane pane = new StackPane(rectangle, text);
|
||||
pane.setOnMouseClicked(onClick);
|
||||
pane.setLayoutX(x);
|
||||
pane.setLayoutY(y);
|
||||
return pane;
|
||||
}
|
||||
|
||||
private static Text createText(String string) {
|
||||
Text text = new Text(string);
|
||||
text.setBoundsType(TextBoundsType.VISUAL);
|
||||
text.setStyle(
|
||||
"-fx-font-family: \"Arial\";" +
|
||||
//"-fx-font-style: normal;" +
|
||||
"-fx-font-size: 24px;"
|
||||
);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private static Rectangle rectangulate(Text text) {
|
||||
Rectangle rectangle = new Rectangle();
|
||||
rectangle.setFill(getRandomColor());
|
||||
final double PADDING = 25;
|
||||
rectangle.setWidth(getWidth(text) + PADDING);
|
||||
rectangle.setHeight(getHeight(text) + PADDING);
|
||||
rectangle.setArcHeight(20);
|
||||
rectangle.setArcWidth(20);
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
private static double getWidth(Text text) {
|
||||
new Scene(new Group(text));
|
||||
text.applyCss();
|
||||
|
||||
return text.getLayoutBounds().getWidth();
|
||||
}
|
||||
|
||||
private static double getHeight(Text text) {
|
||||
new Scene(new Group(text));
|
||||
text.applyCss();
|
||||
|
||||
return text.getLayoutBounds().getHeight();
|
||||
}
|
||||
|
||||
public static Color getRandomColor() {
|
||||
Random random = new Random(System.currentTimeMillis());
|
||||
return Color.hsb(random.nextInt(360), 0.8, 0.8);
|
||||
}
|
||||
}
|
||||
|
|
BIN
src/main/resources/music/menu.mp4
Normal file
BIN
src/main/resources/music/menu.mp4
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue