Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static void openLayout() {

FThreads.invokeInEdtLater(() -> {
SLayoutIO.loadLayout(loadFile);
Singletons.getControl().getCurrentScreen().getView().populate();
SLayoutIO.saveLayout(null);
SOverlayUtils.hideOverlay();
});
Expand All @@ -89,6 +90,7 @@ public static void revertLayout() {

FThreads.invokeInEdtLater(() -> {
SLayoutIO.loadLayout(null);
Singletons.getControl().getCurrentScreen().getView().populate();
SOverlayUtils.hideOverlay();
});
}
Expand Down
37 changes: 27 additions & 10 deletions forge-gui-desktop/src/main/java/forge/screens/match/VMatchUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,38 @@ public void populate() {
getBtnCancel().requestFocusInWindow();
}

// Add extra players alternatively to existing user/AI field panels.
for (int i = 2; i < lstFields.size(); i++) {
// If already in layout, no need to add again.
// Ensure all field views are added to the layout
for (int i = 0; i < lstFields.size(); i++) {
VField vField = lstFields.get(i);
if (vField.getParentCell() == null) {
lstFields.get(i % 2).getParentCell().addDoc(vField);
// Check if field is in a visible cell (not a stale reference from old layout)
DragCell parentCell = vField.getParentCell();
if (parentCell != null && parentCell.isShowing()) {
continue;
}

if (i < 2) {
// Base fields: use REPORT_LOG's cell as fallback
DragCell fallbackCell = EDocID.REPORT_LOG.getDoc().getParentCell();
if (fallbackCell != null) {
fallbackCell.addDoc(vField);
}
} else {
// Extra players: add to corresponding base field's cell
DragCell baseFieldCell = lstFields.get(i % 2).getParentCell();
if (baseFieldCell != null) {
baseFieldCell.addDoc(vField);
}
}
}

// Determine (an) existing hand panel
DragCell cellWithHands = null;
for (final EDocID handId : EDocID.Hands) {
cellWithHands = handId.getDoc().getParentCell();
if (cellWithHands != null) {
if (cellWithHands != null && cellWithHands.isShowing()) {
break;
}
cellWithHands = null;
}
if (cellWithHands == null) {
// Default to a cell we know exists
Expand All @@ -109,11 +125,12 @@ public void populate() {
handId.setDoc(new VEmptyDoc(handId));
}
} else {
// Hand present, add it if necessary
if (parentCell == null) {
// Hand present, add it if necessary (check isShowing for stale references)
if (parentCell == null || !parentCell.isShowing()) {
final EDocID fieldDoc = EDocID.Fields[iHandId];
if (fieldDoc.getDoc().getParentCell() != null) {
fieldDoc.getDoc().getParentCell().addDoc(myVHand);
DragCell fieldCell = fieldDoc.getDoc().getParentCell();
if (fieldCell != null && fieldCell.isShowing()) {
fieldCell.addDoc(myVHand);
continue;
}
cellWithHands.addDoc(myVHand);
Expand Down