|
|
@@ -1,12 +1,16 @@
|
|
|
package view.ui;
|
|
|
|
|
|
+import controller.factories.InteractiveTileFactory;
|
|
|
+import controller.tiles.interactive.InteractiveTileController;
|
|
|
import model.Inventory;
|
|
|
import model.items.ITEM_NAME;
|
|
|
+import model.tiles.InteractiveTileModel;
|
|
|
import model.tiles.InteractiveTileType;
|
|
|
import util.Translator;
|
|
|
import util.economy.EconomyData;
|
|
|
import util.economy.EconomyInfo;
|
|
|
import view.GamePanel;
|
|
|
+import view.tile.TileManager;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
|
@@ -15,7 +19,6 @@ import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
public class ShopView {
|
|
|
private GamePanel gamePanel;
|
|
|
@@ -60,7 +63,31 @@ public class ShopView {
|
|
|
for(InteractiveTileType type : offers){
|
|
|
drawOffer(g2, type);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ public InteractiveTileController getClickedOffer(int x, int y) {
|
|
|
+ int offerCount = offers.size();
|
|
|
+
|
|
|
+ int overlayWidth = (slotSize + spacing) * offerCount + spacing;
|
|
|
+
|
|
|
+ int baseOffsetX = gamePanel.getWidth() / 2 - overlayWidth / 2;
|
|
|
+ int baseOffsetY = overlayY + spacing;
|
|
|
+
|
|
|
+ int offerX = baseOffsetX + spacing;
|
|
|
+ int offerY = baseOffsetY + spacing;
|
|
|
|
|
|
+ for (int i = 0; i < offerCount; i++) {
|
|
|
+ int currentX = offerX + i * (slotSize + spacing);
|
|
|
+ int currentY = offerY;
|
|
|
+
|
|
|
+ if (x >= currentX && x <= currentX + slotSize &&
|
|
|
+ y >= currentY && y <= currentY + slotSize) {
|
|
|
+ TileManager tm = gamePanel.tileManager;
|
|
|
+
|
|
|
+ return InteractiveTileFactory.createTile(gamePanel.gameController, new InteractiveTileModel(tm.screenToWorldX(x), tm.screenToWorldY(y), offers.get(i)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null; // No offer clicked
|
|
|
}
|
|
|
|
|
|
private void drawOffer(Graphics2D g2, InteractiveTileType offer){
|
|
|
@@ -79,6 +106,7 @@ public class ShopView {
|
|
|
|
|
|
for(Map.Entry<ITEM_NAME, Integer> entry : entries){
|
|
|
String needed = Translator.translate("item."+entry.getKey()) + ": " + entry.getValue();
|
|
|
+
|
|
|
int strWidth = g2.getFontMetrics().stringWidth(needed);
|
|
|
Inventory inventory = gamePanel.gameController.getModel().getInventory();
|
|
|
|
|
|
@@ -114,7 +142,7 @@ public class ShopView {
|
|
|
g2.setFont(defaultF);
|
|
|
}
|
|
|
|
|
|
- public BufferedImage getImage(String imagePath){
|
|
|
+ private BufferedImage getImage(String imagePath){
|
|
|
try {
|
|
|
return ImageIO.read(getClass().getResourceAsStream(imagePath));
|
|
|
} catch (IOException e) {
|