|
|
@@ -1,5 +1,6 @@
|
|
|
package view.popUpMenu;
|
|
|
|
|
|
+import util.TextUtil;
|
|
|
import view.components.Button;
|
|
|
|
|
|
import java.awt.*;
|
|
|
@@ -10,12 +11,22 @@ public abstract class PopupMenu implements Serializable {
|
|
|
|
|
|
public int overlayWidth;
|
|
|
public int overlayHeight;
|
|
|
+ public String title;
|
|
|
public ArrayList<Button> buttonArrayList = new ArrayList<>();
|
|
|
+ public PopupMenu(int width, int height, String title) {
|
|
|
+ overlayWidth = width;
|
|
|
+ overlayHeight = height;
|
|
|
+ this.title = title;
|
|
|
+ }
|
|
|
public PopupMenu(int width, int height) {
|
|
|
overlayWidth = width;
|
|
|
overlayHeight = height;
|
|
|
}
|
|
|
|
|
|
+ public void setTitle(String title){
|
|
|
+ this.title = title;
|
|
|
+ }
|
|
|
+
|
|
|
public void addButton(Button button, int offsetX, int offsetY){
|
|
|
button.setOffset(offsetX, offsetY);
|
|
|
buttonArrayList.add(button);
|
|
|
@@ -23,10 +34,20 @@ public abstract class PopupMenu implements Serializable {
|
|
|
|
|
|
|
|
|
public void draw(int x, int y, Graphics2D g2){
|
|
|
+ FontMetrics fm = g2.getFontMetrics();
|
|
|
+ int msgWidth = fm.stringWidth(title);
|
|
|
+ int msgHeight = fm.getAscent();
|
|
|
+ if(overlayWidth < msgWidth) overlayWidth = msgWidth + 20;
|
|
|
+
|
|
|
+ centerButtons();
|
|
|
+
|
|
|
g2.setColor(Color.GRAY);
|
|
|
g2.fillRoundRect(x,y, overlayWidth, overlayHeight, 15, 15);
|
|
|
g2.setColor(Color.WHITE);
|
|
|
g2.drawRoundRect(x,y,overlayWidth,overlayHeight, 15, 15);
|
|
|
+
|
|
|
+ g2.drawString(title, x + ((overlayWidth - msgWidth )/2), y+ 20);
|
|
|
+
|
|
|
for (Button button : buttonArrayList){
|
|
|
button.setRelativeScreenCoordinates(x,y);
|
|
|
button.draw(g2);
|
|
|
@@ -34,6 +55,12 @@ public abstract class PopupMenu implements Serializable {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void centerButtons() {
|
|
|
+ for (Button button : buttonArrayList){
|
|
|
+ button.centerToWidth(overlayWidth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public Button getClickedButton(int screenX, int screenY) {
|
|
|
for (Button button : buttonArrayList){
|
|
|
if(button.wasClicked(screenX, screenY)) return button;
|