Переглянути джерело

Kleuren scrollen mee met het liedje

Dofensmirtsz 10 роки тому
батько
коміт
5d153d3a2c
2 змінених файлів з 102 додано та 101 видалено
  1. 77 12
      model/gameState/MenuState.java
  2. 25 89
      model/objects/MenuButton.java

+ 77 - 12
model/gameState/MenuState.java

@@ -39,6 +39,16 @@ public class MenuState extends GameState {
 	BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
 	int index = 0;
 	
+	
+	
+	int kleurButton1 = 0;
+	int kleurButton2 = 1;
+	int kleurButton3 = 2;
+	int kleurButton4 = 3;
+	int kleurButton5 = 4;
+	
+	
+	
 	public MenuState(GameStateManager gsm, SongHandler sh) {	
 		super(gsm, sh);
 		buttons = new ArrayList<MenuButton>();
@@ -47,12 +57,12 @@ public class MenuState extends GameState {
 		startanimation = true;
 		subscreen = false;
 		
-		buttons.add(new MenuButton(-600, 50,1.7, 0, Color.green, selectedToSong(selected-2) ));
-		buttons.add(new MenuButton(-600, 150, 1.7, 10, Color.BLUE, selectedToSong(selected-1)));
-		buttons.add(new MenuButton(-600, 250, 1.7, 20, Color.red, selectedToSong(selected)));
-		buttons.add(new MenuButton(-600, 350, 1.7, 30, Color.yellow,selectedToSong(selected+1)));
-		buttons.add(new MenuButton(-600, 450, 1.7, 30, Color.WHITE,selectedToSong(selected+2)));
-		buttons.get(2).setSelected(true);
+//		buttons.add(new MenuButton(400,150,GameModel.colors[kleurInt-2],selectedToSong(selected-2)));
+//		buttons.add(new MenuButton(400,250,GameModel.colors[kleurInt-1],selectedToSong(selected-1)));
+//		buttons.add(new MenuButton(400,350,GameModel.colors[kleurInt],selectedToSong(selected)));
+//		buttons.add(new MenuButton(400,450,GameModel.colors[kleurInt+1],selectedToSong(selected+1)));
+//		buttons.add(new MenuButton(400,550,GameModel.colors[kleurInt+2],selectedToSong(selected+2)));
+//		buttons.get(2).setSelected(true);
 		
 	}
 	@Override
@@ -72,15 +82,14 @@ public class MenuState extends GameState {
 		}else{
 			previousScreen();
 		}
-	     for(MenuButton b:buttons){
-	    	 b.update();
-	     }
 	     if(selected != oldselected){
 	    	 for(int i = 0; i < buttons.size(); i++){
 		    	 buttons.get(i).setSong(selectedToSong(selected+(i-2)));
+		    	 
 	    	 }
 	    	 oldselected = selected;
 	    	 
+	    	 
 	    	buttons2.clear();
 	 		int instanceNr = 0;
 	 		for(int i = sh.getCurrentSong().getSongs().size(); i>0; i--){
@@ -90,15 +99,22 @@ public class MenuState extends GameState {
 	 			buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
 	 			instanceNr += 100;
 	 		}
-	 		
 	     }
 	     index++;
+	     
 	}
 
 	@Override
 	public void draw(Graphics2D g2) {
-
-	    
+		buttons.clear();		
+		buttons.add(new MenuButton(400,150,GameModel.colors[kleurButton1],selectedToSong(selected-2)));
+		buttons.add(new MenuButton(400,250,GameModel.colors[kleurButton2],selectedToSong(selected-1)));
+		buttons.add(new MenuButton(400,350,GameModel.colors[kleurButton3],selectedToSong(selected)));
+		buttons.add(new MenuButton(400,450,GameModel.colors[kleurButton4],selectedToSong(selected+1)));
+		buttons.add(new MenuButton(400,550,GameModel.colors[kleurButton5],selectedToSong(selected+2)));
+		buttons.get(2).setSelected(true);
+		
+		
 		g2.setColor(Color.BLACK);
 		Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
 		g2.setFont(textFont2);
@@ -211,6 +227,7 @@ public class MenuState extends GameState {
 				if(difSelect > buttons2.size()-1){
 					difSelect = 0;
 				}
+
 				
 //				System.out.println(difSelect);
 			}
@@ -222,8 +239,56 @@ public class MenuState extends GameState {
 		}else{										//Screen for selecting song
 			if(e.getJoystick().getPos() == Joystick.Position.DOWN){
 				selected++;
+//				if(kleurInt > GameModel.colors.length-1){
+//					kleurInt = 0;
+//				} else
+//					kleurInt++;
+				kleurButton1++;
+				kleurButton1 %= 6;
+				
+				kleurButton2++;
+				kleurButton2 %= 6;
+				
+				kleurButton3++;
+				kleurButton3 %= 6;
+				
+				kleurButton4++;
+				kleurButton4 %= 6;
+				
+				kleurButton5++;
+				kleurButton5 %= 6;
+				
+				
+
 			}else if(e.getJoystick().getPos() == Joystick.Position.UP){
 				selected--;
+				kleurButton1--;
+				if(kleurButton1 < 0){
+					kleurButton1 = 1;
+				}
+				
+				kleurButton2--;
+				if(kleurButton2 < 0){
+					kleurButton2 = 1;
+				}
+				
+				kleurButton3--;
+				if(kleurButton3 < 0){
+					kleurButton3 = 1;
+				}
+					
+				kleurButton4--;
+				if(kleurButton4 < 0){
+					kleurButton4 = 1;
+				}
+				
+				kleurButton5--;
+				if(kleurButton5 < 0){
+					kleurButton5 = 1;
+				}
+				
+
+				
 			}
 			sh.set(songs.indexOf(selectedToSong(selected)));
 			sh.play(true);	

+ 25 - 89
model/objects/MenuButton.java

@@ -4,123 +4,60 @@ import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.Graphics2D;
-import java.awt.LinearGradientPaint;
-import java.awt.Paint;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Point2D;
 import java.util.ArrayList;
 
+import model.GameModel;
 import audio.Song;
 
 public class MenuButton {
 
-	private ArrayList<GeneralPath> buttonparts;
-	private GeneralPath border, line;
 	private ArrayList<Color> colors;
-	private Paint gradient;
-	private int x, y, rounding;
-	private double scalefactor;
-	
+	private int x, y;
 	private boolean selected; 
-	private int fadecounter;
-	
 	private Song song;
+	Color color;
 	
-	public MenuButton(int x, int y, double scale, int rounding, Color c0, Song song){
+	public MenuButton(int x, int y, Color color, Song song){
 		this.x = x;
 		this.y = y;
-		this.scalefactor = scale;
-		this.rounding = rounding;
-		calculateButton();
+		this.color = color;
 		setSong(song);
 		
-		colors = new ArrayList<Color>();
-		
-		Color c1 = c0.darker();
-		Color c2 = c0.darker().darker();
-		Color c3 = c0.darker().darker().darker();
-		
-		c1 = new Color((int)(c1.getRed()*0.8), (int)(c1.getGreen()*0.8),(int)(c1.getBlue()*0.8));
-		c2 = new Color((int)(c2.getRed()*0.8), (int)(c2.getGreen()*0.8),(int)(c2.getBlue()*0.8));
-		c3 = new Color((int)(c3.getRed()*0.8), (int)(c3.getGreen()*0.8),(int)(c3.getBlue()*0.8));
-		
-		colors.add(c2);
-		colors.add(c3);
-		colors.add(c2);
-		colors.add(c0);
-		colors.add(c1);
-		colors.add(c0);
-		
-		gradient = new LinearGradientPaint(
-							new Point2D.Double((-100)*scalefactor,(512)*scalefactor), 
-							new Point2D.Double((600)*scalefactor,(512)*scalefactor), 
-							new float[]{0.0f, 1.0f}, 
-							new Color[]{new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), 10), c0});
 	}
 	
-	public void calculateButton(){
-		buttonparts = new ArrayList<GeneralPath>();
-		buttonparts.add(arrayToGeneralpath(new int[][]{{449, 1}, {449, 68},{113, 103}, {106, 35}}));															//background right
-		buttonparts.add(arrayToGeneralpath(new int[][]{{113, 103}, {106, 35},{70, 12+rounding}, {77, 88+rounding}}));										//background middle
-		buttonparts.add(arrayToGeneralpath(new int[][]{{70, 12+rounding}, {77, 88+rounding},{4, 104+(int)(rounding*0.5)}, {-4, 32+(int)(rounding*0.5)}}));	//background left
-		buttonparts.add(arrayToGeneralpath(new int[][]{{449, 15}, {449, 54},{118, 88}, {114, 48}}));															//foreground right
-		buttonparts.add(arrayToGeneralpath(new int[][]{{118, 88}, {114, 48},{78, 25+rounding}, {82, 73+rounding}}));											//foreground middle
-		buttonparts.add(arrayToGeneralpath(new int[][]{{78, 25+rounding}, {82, 73+rounding},{15, 88+(int)(rounding*0.5)}, {10, 43+(int)(rounding*0.5)}}));	//foreground left
 	
-		border = arrayToGeneralpath(new int[][]{{449,15}, {114,48},{78,25+rounding},{10,43+(int)(rounding*0.5)},{15,88+(int)(rounding*0.5)},{82,73+rounding},{118,88},{449,54}});
-		line = arrayToGeneralpath(new int[][]{{-11,55},{-40,60},{-38,78},{-358,170-rounding*3},{-358,174-rounding*3},{-37,87},{-35,102},{-5,95}});
-	}
-	
-	public GeneralPath arrayToGeneralpath(int block[][]){
-		GeneralPath polyline =  new GeneralPath(GeneralPath.WIND_EVEN_ODD, block.length);
-		polyline.moveTo ((block[0][0]+x)*scalefactor, (block[0][1]+y)*scalefactor);
-		for (int index = 1; index < block.length; index++) {
-		         polyline.lineTo((block[index][0]+x)*scalefactor, (block[index][1]+y)*scalefactor);
-		};
-		polyline.closePath();
-		return polyline;
-	}
 
 	public void draw(Graphics2D g2d){
-		for(int i = 0; i < buttonparts.size(); i++){ //fill every part of the button with a specific color
-			g2d.setColor(colors.get(i));
-			g2d.fill((buttonparts.get(i)));
-		}
+			g2d.setColor(color);
+			g2d.fillRect(x,y,880,50);
 		
 		if(selected){
-			g2d.setStroke(new BasicStroke(4));
 			g2d.setColor(Color.BLACK);
-			g2d.draw(border);
+			g2d.drawRect(x, y, 880, 50);
 		}
-		g2d.setPaint(gradient);
-		g2d.fill(line);
 
 		//draw text
 		g2d.setColor(Color.BLACK);
-		Font textFont = new Font("OCR A Extended", Font.BOLD, (int)(30*scalefactor));
+		Font textFont = new Font("OCR A Extended", Font.BOLD,60);
 		g2d.setFont(textFont);
-		g2d.translate((x+160)*scalefactor, (y+74)*scalefactor);
-		g2d.rotate(-0.1);
-		g2d.drawString(song.getTitle(),  0, 0);
-		g2d.rotate(0.1);
-		g2d.translate(-(x+160)*scalefactor, -(y+74)*scalefactor);
+		g2d.drawString(song.getTitle(),  x+50, y+50);
 	}
 	
-	public void update(){
-		if(selected && fadecounter < 5){
-			x += 8;
-			y -= 8;
-			scalefactor += 0.04;
-			fadecounter++;
-			calculateButton();
-		}else if(!selected && fadecounter >0){
-			x += 8;
-			y += 8;
-			fadecounter--;
-			scalefactor -= 0.04;
-			calculateButton();
-		}
-	}
+//	public void update(){
+//		if(selected && fadecounter < 5){
+//			x += 8;
+//			y -= 8;
+//			scalefactor += 0.04;
+//			fadecounter++;
+//			calculateButton();
+//		}else if(!selected && fadecounter >0){
+//			x += 8;
+//			y += 8;
+//			fadecounter--;
+//			scalefactor -= 0.04;
+//			calculateButton();
+//		}
+//	}
 	
 	public void setSelected(boolean selected) {
 		this.selected = selected;
@@ -131,7 +68,6 @@ public class MenuButton {
 	}
 	public void setX(int x){
 		this.x = x;
-		calculateButton();
 	}
 
 	public int getX() {