spjspj - Add a View Limited Deck option to allow you to see your deck during matches.

This commit is contained in:
spjspj 2017-04-22 19:16:12 +10:00
parent 3f8b193da6
commit 0cd4e06e22
10 changed files with 74 additions and 4 deletions

View file

@ -1034,7 +1034,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
if (window instanceof DeckEditorPane) {
DeckEditorPane deckEditorPane = (DeckEditorPane) window;
if (deckEditorPane.getDeckEditorMode() == DeckEditorMode.LIMITED_BUILDING
|| deckEditorPane.getDeckEditorMode() == DeckEditorMode.SIDEBOARDING) {
|| deckEditorPane.getDeckEditorMode() == DeckEditorMode.SIDEBOARDING
|| deckEditorPane.getDeckEditorMode() == DeckEditorMode.VIEW_LIMITED_DECK) {
deckEditorPane.removeFrame();
}
}
@ -1044,7 +1045,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
public void showDeckEditor(DeckEditorMode mode, Deck deck, UUID tableId, int time) {
String name;
if (mode == DeckEditorMode.SIDEBOARDING || mode == DeckEditorMode.LIMITED_BUILDING) {
if (mode == DeckEditorMode.SIDEBOARDING || mode == DeckEditorMode.LIMITED_BUILDING || mode == DeckEditorMode.VIEW_LIMITED_DECK) {
name = "Deck Editor - " + tableId.toString();
} else {
if (deck != null) {

View file

@ -91,7 +91,8 @@ public final class Constants {
FREE_BUILDING,
LIMITED_BUILDING,
SIDEBOARDING
SIDEBOARDING,
VIEW_LIMITED_DECK
}
public enum SortBy {

View file

@ -80,6 +80,8 @@ public class DeckEditorPane extends MagePane {
public void show(DeckEditorMode mode, Deck deck, String name, UUID tableId, int time) {
if (mode == DeckEditorMode.SIDEBOARDING || mode == DeckEditorMode.LIMITED_BUILDING) {
this.setTitle("Deck Editor - " + tableId.toString());
} else if (mode == DeckEditorMode.VIEW_LIMITED_DECK) {
this.setTitle("Deck Editor - Current Deck");
} else if (deck != null) {
this.setTitle("Deck Editor - " + deck.getName());
} else {

View file

@ -233,6 +233,24 @@ public class DeckEditorPanel extends javax.swing.JPanel {
this.deckArea.showSideboard(true);
this.txtTimeRemaining.setVisible(false);
break;
case VIEW_LIMITED_DECK:
this.btnExit.setVisible(true);
this.btnAddLand.setVisible(false);
this.btnGenDeck.setVisible(false);
this.btnImport.setVisible(false);
this.btnLoad.setVisible(false);
this.btnNew.setVisible(false);
this.btnSave.setVisible(false);
this.btnSubmit.setVisible(false);
this.btnSubmitTimer.setVisible(false);
this.cardSelector.loadCards(this.bigCard);
this.cardSelector.setVisible(false);
this.deckArea.setOrientation(/*limitedBuildingOrientation = */true);
this.deckArea.showSideboard(true);
this.lblDeckName.setVisible(false);
this.txtDeckName.setVisible(false);
this.txtTimeRemaining.setVisible(false);
break;
}
init();
this.deckArea.setDeckEditorMode(mode);

View file

@ -472,6 +472,17 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
});
popupMenu.addSeparator();
menuItem = new JMenuItem("<html>View current deck");
menuItem.setMnemonic(KeyEvent.VK_V);
popupMenu.add(menuItem);
// View limited deck
menuItem.addActionListener(e -> {
SessionHandler.sendPlayerAction(PlayerAction.VIEW_LIMITED_DECK, gameId, null);
});
}
private void addPopupMenuWatcher() {

View file

@ -324,6 +324,13 @@ public class CallbackClientImpl implements CallbackClient {
}
break;
}
case VIEW_LIMITED_DECK: {
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
Deck deck = DeckUtil.construct(deckView);
viewLimitedDeck(deck, message.getTableId(), message.getTime());
break;
}
case CONSTRUCT: {
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
@ -512,6 +519,10 @@ public class CallbackClientImpl implements CallbackClient {
frame.showDeckEditor(DeckEditorMode.LIMITED_BUILDING, deck, tableId, time);
}
protected void viewLimitedDeck(Deck deck, UUID tableId, int time) {
frame.showDeckEditor(DeckEditorMode.VIEW_LIMITED_DECK, deck, tableId, time);
}
private void handleException(Exception ex) {
logger.fatal("Client error\n", ex);
frame.showError("Error: " + ex.getMessage());

View file

@ -13,6 +13,7 @@ public enum ClientCallbackMethod {
START_DRAFT("startDraft"),
START_TOURNAMENT("startTournament"),
SIDEBOARD("sideboard"),
VIEW_LIMITED_DECK("viewLimitedDeck"),
CONSTRUCT("construct"),
SHOW_USERMESSAGE("showUserMessage"),
WATCHGAME("watchGame"),

View file

@ -269,6 +269,10 @@ public class User {
sideboarding.put(tableId, deck);
}
public void ccViewLimitedDeck(final Deck deck, final UUID tableId, final int time, boolean limited) {
fireCallback(new ClientCallback(ClientCallbackMethod.VIEW_LIMITED_DECK, tableId, new TableClientMessage(deck, tableId, time, limited)));
}
public void ccConstruct(final Deck deck, final UUID tableId, final int time) {
fireCallback(new ClientCallback(ClientCallbackMethod.CONSTRUCT, tableId, new TableClientMessage(deck, tableId, time)));
}

View file

@ -545,6 +545,9 @@ public class GameController implements GameCallback {
requestPermissionToSeeHandCards(userId, (UUID) data);
}
break;
case VIEW_LIMITED_DECK:
viewLimitedDeck(getPlayerId(userId), userId);
break;
default:
game.sendPlayerAction(playerAction, getPlayerId(userId), data);
}
@ -601,6 +604,23 @@ public class GameController implements GameCallback {
}
}
private void viewLimitedDeck(UUID userIdRequester, UUID origId) {
Player viewLimitedDeckPlayer = game.getPlayer(userIdRequester);
if (viewLimitedDeckPlayer != null) {
if (viewLimitedDeckPlayer.isHuman()) {
System.out.println("Origid: " + origId + " req:" + userIdRequester);
for (MatchPlayer p : TableManager.instance.getTable(tableId).getMatch().getPlayers()) {
if (p.getPlayer().getId() == userIdRequester) {
Optional<User> u = UserManager.instance.getUser(origId);
if (u != null && u.isPresent() && p.getDeck() != null) {
u.get().ccViewLimitedDeck(p.getDeck(), tableId, requestsOpen, true);
}
}
}
}
}
}
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
try {
Deck deck = Deck.load(deckList, false, false);

View file

@ -83,5 +83,6 @@ public enum PlayerAction {
CLIENT_RECONNECT,
CLIENT_REPLAY_ACTION,
HOLD_PRIORITY,
UNHOLD_PRIORITY
UNHOLD_PRIORITY,
VIEW_LIMITED_DECK
}