Removed property changes

This commit is contained in:
2026-05-14 16:42:19 +02:00
parent 9fa51e9fe7
commit 711d57e4cd
3 changed files with 8 additions and 54 deletions
@@ -6,15 +6,12 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.GamePackage.Board; import it.polimi.ingsw.gc14.Model.GamePackage.Board;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState; import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
public class MiniModel implements Serializable { public class MiniModel implements Serializable {
private final PropertyChangeSupport support = new PropertyChangeSupport(this);
public Board board; public Board board;
public Map<Slot, Player> slotPlayerMap; public Map<Slot, Player> slotPlayerMap;
public OrderLogicCard orderLogicCard; public OrderLogicCard orderLogicCard;
@@ -22,7 +19,7 @@ public class MiniModel implements Serializable {
public Map<String, Player> players; public Map<String, Player> players;
public List<Totems> availableTotems; public List<Totems> availableTotems;
// --- Costruttori invariati --- // --- Costruttori ---
public MiniModel() { public MiniModel() {
@@ -43,63 +40,39 @@ public class MiniModel implements Serializable {
setPlayers(players); setPlayers(players);
} }
// --- Gestione listener ---
public void addPropertyChangeListener(PropertyChangeListener listener) { // --- Setter ---
support.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
// --- Setter con notifica ---
public void setBoard(Board board) { public void setBoard(Board board) {
Board old = this.board;
this.board = board; this.board = board;
support.firePropertyChange("board", old, board);
} }
public void setAvailableTotems(List<Totems> availableTotems) { public void setAvailableTotems(List<Totems> availableTotems) {
List<Totems> old = this.availableTotems;
this.availableTotems = availableTotems; this.availableTotems = availableTotems;
support.firePropertyChange("availableTotems", old, availableTotems);
} }
public void setSlotPlayerMap(Map<Slot, Player> slotPlayerMap) { public void setSlotPlayerMap(Map<Slot, Player> slotPlayerMap) {
Map<Slot, Player> old = this.slotPlayerMap;
this.slotPlayerMap = slotPlayerMap; this.slotPlayerMap = slotPlayerMap;
support.firePropertyChange("slotPlayerMap", old, slotPlayerMap);
} }
public void setOrderLogicCard(OrderLogicCard orderLogicCard) { public void setOrderLogicCard(OrderLogicCard orderLogicCard) {
OrderLogicCard old = this.orderLogicCard;
this.orderLogicCard = orderLogicCard; this.orderLogicCard = orderLogicCard;
support.firePropertyChange("orderLogicCard", old, orderLogicCard);
} }
public void setCurrentState(CurrentState currentState) { public void setCurrentState(CurrentState currentState) {
CurrentState old = this.currentState;
this.currentState = currentState; this.currentState = currentState;
support.firePropertyChange("currentState", old, currentState);
} }
public void setPlayers(List<Player> players) { public void setPlayers(List<Player> players) {
Map<String, Player> old = new HashMap<>(this.players != null ? this.players : new HashMap<>());
for (Player player : players) { for (Player player : players) {
this.players.put(player.getUserName(), player); this.players.put(player.getUserName(), player);
} }
support.firePropertyChange("players", old, this.players);
} }
public void setPlayer(Player player) { public void setPlayer(Player player) {
Map<String, Player> old = new HashMap<>(this.players);
players.put(player.getUserName(), player); players.put(player.getUserName(), player);
support.firePropertyChange("players", old, this.players);
} }
// --- Metodi invariati ---
public int getPositionByUsername(String username) { public int getPositionByUsername(String username) {
int i = 0; int i = 0;
@@ -25,7 +25,7 @@ public abstract class OrderLogicCard implements Serializable {
/** /**
* The list of {@link Player Players} associated with this order logic card. * The list of {@link Player Players} associated with this order logic card.
*/ */
protected List<OrderPlayer> playerList; public List<OrderPlayer> playerList;
/** /**
@@ -6,6 +6,7 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard; import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.GamePackage.Board; import it.polimi.ingsw.gc14.Model.GamePackage.Board;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState; import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
import javafx.animation.ScaleTransition; import javafx.animation.ScaleTransition;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.Event; import javafx.event.Event;
@@ -70,25 +71,9 @@ public class MainFXMLController {
// Initialize popup // Initialize popup
initPopup(); initPopup();
controller.miniModel.addPropertyChangeListener(evt -> {
switch (evt.getPropertyName()) {
case "board" -> ciao("board");
case "currentState" -> ciao("currentState");
case "players" -> Platform.runLater(() -> renderSidePanel());
case "slotPlayerMap" -> Platform.runLater(() -> renderBoard());
case "orderLogicCard"-> Platform.runLater(() -> renderBoard());
case "availableTotems"-> ciao("availableTotems");
}
});
} }
public void ciao(String s) {
System.out.println(s);
}
public void render() { public void render() {
renderBackground(); renderBackground();
@@ -309,15 +294,11 @@ public class MainFXMLController {
StackPane.setAlignment(overlay, Pos.TOP_LEFT); StackPane.setAlignment(overlay, Pos.TOP_LEFT);
StackPane.setMargin(overlay, new Insets(9, 0, 0, 57)); StackPane.setMargin(overlay, new Insets(9, 0, 0, 57));
List<Player> ordered = controller.miniModel.players.values().stream() for (OrderPlayer player : controller.miniModel.orderLogicCard.playerList) {
.filter(p -> !controller.miniModel.orderLogicCard.players.contains(p)) ImageView totem = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Totems/totem_" + player.player.totem.toString().toLowerCase(Locale.ROOT) + ".png")));
.collect(Collectors.toList());
ordered.addAll(controller.miniModel.orderLogicCard.players);
for (Player player : ordered) {
ImageView totem = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Totems/totem_" + player.totem.toString().toLowerCase(Locale.ROOT) + ".png")));
totem.setFitHeight(70); totem.setFitHeight(70);
totem.setPreserveRatio(true); totem.setPreserveRatio(true);
if (!controller.miniModel.orderLogicCard.players.contains(player)) { if(controller.miniModel.slotPlayerMap.containsValue(player.player)) {
totem.setOpacity(0.5); totem.setOpacity(0.5);
} }
overlay.getChildren().add(totem); overlay.getChildren().add(totem);