package game;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.text.StyledEditorKit.AlignmentAction;
import data.OptionGuiBuildableVar;
import data.EngineVar;
public class OptionGuiBuildable extends JWindow {
private EngineVar engineVar;
private int hoehe;
private int breite;
private JTextField anzahl;
private JPanelOp content;
private JPanel bottomPanel;
private JPanel buyPanel;
private JPanel head;
private JPanel details;
private Border contentBorder;
private Button closeButton;
private JLabel nameLabel;
private JLabel imgLabel;
private JPanel menu;
private JTextArea detailsText;
private JLabelGebaeude gebaeude;
private int img = 1;
// Um die Benutzerinteraktion zu blockieren falls ein Menu offen ist!
private GlassPane glassPane;
OptionGuiBuildableVar buildOptionGuiVars;
public OptionGuiBuildable(EngineVar engineVar, PlanetSets planetSet,
JLabelGebaeude gebaeude, GlassPane glassPane, int img) {
this.buildOptionGuiVars = new OptionGuiBuildableVar(planetSet, gebaeude);
this.img = img;
this.engineVar = engineVar;
this.gebaeude = gebaeude;
this.glassPane = glassPane;
this.setContentPane(getContent());
this.breite = 450;
this.hoehe = 200;
// Posiotion mitteScreen
int postion[] = this.buildOptionGuiVars.getResulotion()
.getScreenCenter(this.breite, this.hoehe);
this.setBounds(postion[0], postion[1], this.breite, this.hoehe);
OpaqueImage o = new OpaqueImage(this.getBounds().x, this.getBounds().y,
this.breite, this.hoehe, this.img);
o.getBgImage();
this.setVisible(true);
this.requestFocus();
}
public JPanelOp getContent() {
content = new JPanelOp(this.img);
content.setLayout(new BorderLayout());
// Komponenten hinzufügen
content.add(getHead(), BorderLayout.NORTH);
content.add(getDetails(), BorderLayout.CENTER);
content.add(getBottomPanel(), BorderLayout.SOUTH);
// Ende Komponenten hinzufügen
content.repaint();
return content;
}
public void setContent(JPanelOp content) {
this.content = content;
}
public JPanel getDetails() {
details = new JPanel();
details.setOpaque(false);
details.setLayout(new BorderLayout());
details.setOpaque(false);
// Komponenten hinzufügen
// details.add(getImgLabel(), BorderLayout.WEST);
details.add(getDetailsText(), BorderLayout.CENTER);
Border b = BorderFactory.createLineBorder(buildOptionGuiVars
.getHeadColor(), 2);
details.setBorder(b);
// ende Komponenten hinzufügen
return details;
}
public void setDetails(JPanel details) {
this.details = details;
}
public JPanel getHead() {
head = new JPanel();
head.setBackground(buildOptionGuiVars.getHeadColor());
head.setLayout(new BorderLayout());
head.setBorder(BorderFactory.createLineBorder(this.buildOptionGuiVars
.getBorderColor(), 1));
head.add(getNameLabel("Bauoptionen", Color.WHITE), BorderLayout.WEST);
head.add(getCloseButton(),BorderLayout.EAST);
return head;
}
public void setHead(JPanel head) {
this.head = head;
}
public Border getContentBorder() {
contentBorder = BorderFactory.createLineBorder(this.buildOptionGuiVars
.getBorderColor(), 1);
return contentBorder;
}
public void setContentBorder(Border contentBorder) {
this.contentBorder = contentBorder;
}
public Button getCloseButton() {
closeButton = new Button();
closeButton.setOpaque(false);
closeButton.setIcon(new ImageIcon("images/button/buyMenu/schliessen.png"));
closeButton.setBorderPainted(false);
closeButton.setContentAreaFilled(false);
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
engineVar.setControll("gui");
setVisible(false);
File file = new File("game/screenshot.jpg");
if (file.exists()) {
file.delete();
}
}
});
return closeButton;
}
public void setCloseButton(Button closeButton) {
this.closeButton = closeButton;
}
public JWindow getWindow() {
return this;
}
public JLabel getNameLabel(String text, Color textColor) {
nameLabel = new JLabel(text + " - " + this.gebaeude.bez);
nameLabel.setOpaque(false);
nameLabel.setForeground(textColor);
return nameLabel;
}
public void setNameLabel(JLabel nameLabel) {
this.nameLabel = nameLabel;
}
public JTextArea getDetailsText() {
detailsText = new JTextArea();
detailsText.setOpaque(false);
detailsText.setForeground(Color.WHITE);
detailsText.setBorder(getContentBorder());
detailsText.setLineWrap(true);
detailsText.setWrapStyleWord(true);
// Informationen setzen
detailsText.append(this.gebaeude.geb.infoText+"\nBonis:");
if(this.gebaeude.geb.addC!=0)
detailsText.append("\nCredits +"+this.gebaeude.geb.addC);
if(this.gebaeude.geb.addC!=0)
detailsText.append("\nMetall +"+this.gebaeude.geb.addM);
if(this.gebaeude.geb.addC!=0)
detailsText.append("\nWasser +"+this.gebaeude.geb.addW);
if(this.gebaeude.geb.addC!=0)
detailsText.append("\nKristall +"+this.gebaeude.geb.addK);
//detailsText.append("\nNahrung +"+this.gebaeude.geb.addN);
//detailsText.append("\nPopulation"+this.gebaeude.geb.addP);
return detailsText;
}
public void setDetailsText(JTextArea detailsText) {
this.detailsText = detailsText;
}
public JLabel getImgLabel() {
imgLabel = new JLabel();
imgLabel.setOpaque(false);
imgLabel.setIcon(new ImageIcon(this.buildOptionGuiVars.getGebaeude()
.getGeb().bildPath));
imgLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
return imgLabel;
}
public void setImgLabel(JLabel imgLabel) {
this.imgLabel = imgLabel;
}
public JPanel getMenu() {
menu = new JPanel();
menu.setBackground(buildOptionGuiVars.getHeadColor());
menu.setLayout(new GridLayout(1, 6));
menu.setBorder(BorderFactory.createLineBorder(this.buildOptionGuiVars
.getBorderColor(), 1));
// Resourcen
String creditsS = "" + this.buildOptionGuiVars.getGebaeude().kostenC;
String metallS = "" + this.buildOptionGuiVars.getGebaeude().kostenM;
String wasserS = "" + this.buildOptionGuiVars.getGebaeude().kostenW;
String kristallS = "" + this.buildOptionGuiVars.getGebaeude().kostenK;
String nahrungS = "" + this.buildOptionGuiVars.getGebaeude().kostenN;
JLabel credits = new JLabel(creditsS);
credits.setForeground(Color.WHITE);
credits.setIcon(new ImageIcon("images/rohstoffe/credits.png"));
menu.add(credits);
JLabel metall = new JLabel(metallS);
metall.setForeground(Color.WHITE);
metall.setIcon(new ImageIcon("images/rohstoffe/metall.png"));
menu.add(metall);
JLabel wasser = new JLabel(wasserS);
wasser.setForeground(Color.WHITE);
wasser.setIcon(new ImageIcon("images/rohstoffe/wasser.png"));
menu.add(wasser);
JLabel kristall = new JLabel(kristallS);
kristall.setForeground(Color.WHITE);
kristall.setIcon(new ImageIcon("images/rohstoffe/kristall.png"));
menu.add(kristall);
JLabel nahrung = new JLabel(nahrungS);
nahrung.setForeground(Color.WHITE);
nahrung.setIcon(new ImageIcon("images/rohstoffe/nahrung.png"));
menu.add(nahrung);
JLabel population = new JLabel("0");
population.setForeground(Color.WHITE);
population.setIcon(new ImageIcon("images/rohstoffe/population.png"));
menu.add(population);
return menu;
}
public JPanel getBottomPanel() {
bottomPanel = new JPanel();
bottomPanel.setBackground(buildOptionGuiVars.getHeadColor());
bottomPanel.setLayout(new GridLayout(2, 1));
bottomPanel.add(getMenu());
bottomPanel.add(getBuyPanel());
return bottomPanel;
}
public JPanel getBuyPanel() {
buyPanel = new JPanel();
buyPanel.setBackground(buildOptionGuiVars.getHeadColor());
buyPanel.setLayout(new GridLayout(1,6));
// Button
Button kaufen = new Button();
kaufen.setOpaque(false);
kaufen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
buildOptionGuiVars.getPlanetSets().addGebaeude(
buildOptionGuiVars.getGebaeude());
}
});
kaufen.setBorderPainted(false);
kaufen.setContentAreaFilled(false);
kaufen.setIcon(new ImageIcon("images/button/buyMenu/kaufen.png"));
JLabel anzahlString = new JLabel("Anzahl");
anzahlString.setBackground(buildOptionGuiVars.getHeadColor());
anzahlString.setForeground(Color.WHITE);
JLabel fill1 = new JLabel("");
JLabel fill2 = new JLabel("");
JLabel fill3 = new JLabel("");
JLabel fill4 = new JLabel("");
JLabel fill5 = new JLabel("");
buyPanel.add(fill1);
buyPanel.add(fill2);
buyPanel.add(kaufen);
buyPanel.add(fill3);
buyPanel.add(fill4);
buyPanel.requestFocus();
return buyPanel;
}
public void setMenu(JPanel menu) {
this.menu = menu;
}
}