* Some changes to table and match view.

This commit is contained in:
LevelX2 2014-11-01 14:24:23 +01:00
parent 54de525401
commit 8426816b09
13 changed files with 205 additions and 95 deletions

View file

@ -43,8 +43,8 @@ import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableRowSorter;
import mage.client.MageFrame;
import mage.client.util.MageTableRowSorter;
import mage.remote.MageRemoteException;
import mage.remote.Session;
import mage.view.ChatMessage.MessageColor;
@ -143,7 +143,7 @@ public class ChatPanel extends javax.swing.JPanel {
setBackground(new Color(0, 0, 0, ALPHA));
jTablePlayers.setBackground(new Color(0, 0, 0, ALPHA));
jTablePlayers.setForeground(Color.white);
jTablePlayers.setRowSorter(new TableRowSorter(tableModel));
jTablePlayers.setRowSorter(new MageTableRowSorter(tableModel));
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setBackground(new Color(0, 0, 0, ALPHA));
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, ALPHA));

View file

@ -73,6 +73,7 @@ import mage.client.dialog.NewTournamentDialog;
import mage.client.dialog.PreferencesDialog;
import mage.client.dialog.TableWaitingDialog;
import mage.client.util.ButtonColumn;
import mage.client.util.MageTableRowSorter;
import mage.client.util.gui.GuiDisplayUtil;
import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption;
@ -120,6 +121,10 @@ public class TablesPanel extends javax.swing.JPanel {
chkShowCompleted.setVisible(true);
tableTables.createDefaultColumnsFromModel();
tableTables.setRowSorter(new MageTableRowSorter(tableModel));
tableCompleted.setRowSorter(new MageTableRowSorter(matchesModel));
chatPanel.useExtendedView(ChatPanel.VIEW_MODE.NONE);
chatPanel.setBorder(null);
chatPanel.setChatType(ChatPanel.ChatType.TABLES);
@ -705,13 +710,13 @@ private void chkShowCompletedActionPerformed(java.awt.event.ActionEvent evt) {//
class TableTableModel extends AbstractTableModel {
public static final int COLUMN_DECK_TYPE = 5; // column the deck type is located (starting with 0)
public static final int COLUMN_INFO = 6;
public static final int ACTION_COLUMN = 9; // column the action is located (starting with 0)
public static final int COLUMN_DECK_TYPE = 0; // column the deck type is located (starting with 0) Start string is used to check for Limited
public static final int COLUMN_INFO = 3;
public static final int ACTION_COLUMN = 6; // column the action is located (starting with 0)
private final String[] columnNames = new String[]{"Match Name", "Owner / Players", "Game Type", "Wins", "Free Mulligans", "Deck Type", "Info", "Status", "Created / Started", "Action"};
private final String[] columnNames = new String[]{"Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Created / Started", "Action"};
private TableView[] tables = new TableView[0];
private static final DateFormat timeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");;
private Session session;
@ -738,24 +743,18 @@ class TableTableModel extends AbstractTableModel {
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return tables[arg0].getTableName();
return tables[arg0].getDeckType();
case 1:
return tables[arg0].getControllerName();
case 2:
return tables[arg0].getGameType();
case 3:
return Integer.toString(tables[arg0].getWins());
case 4:
return Integer.toString(tables[arg0].getFreeMulligans());
case 5:
return tables[arg0].getDeckType();
case 6:
return tables[arg0].getAdditionalInfo();
case 7:
return tables[arg0].getTableState().toString();
case 8:
case 4:
return tables[arg0].getTableStateText();
case 5:
return timeFormatter.format(tables[arg0].getCreateTime());
case 9:
case 6:
switch (tables[arg0].getTableState()) {
case WAITING:
@ -782,14 +781,14 @@ class TableTableModel extends AbstractTableModel {
default:
return "";
}
case 10:
case 7:
return tables[arg0].isTournament();
case 11:
case 8:
if (!tables[arg0].getGames().isEmpty()) {
return tables[arg0].getGames().get(0);
}
return null;
case 12:
case 9:
return tables[arg0].getTableId();
}
return "";
@ -908,9 +907,9 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
class MatchesTableModel extends AbstractTableModel {
public static final int ACTION_COLUMN = 7; // column the action is located (starting with 0)
public static final int GAMES_LIST_COLUMN = 8;
private final String[] columnNames = new String[]{"Match Name", "Game Type", "Deck Type", "Players", "Result", "Start Time", "End Time","Action"};
public static final int ACTION_COLUMN = 6; // column the action is located (starting with 0)
public static final int GAMES_LIST_COLUMN = 7;
private final String[] columnNames = new String[]{"Deck Type", "Players", "Game Type", "Result", "Start Time", "End Time","Action"};
private MatchView[] matches = new MatchView[0];
private static final DateFormat timeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
@ -933,28 +932,26 @@ class MatchesTableModel extends AbstractTableModel {
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return matches[arg0].getName();
case 1:
return matches[arg0].getGameType();
case 2:
return matches[arg0].getDeckType();
case 3:
case 1:
return matches[arg0].getPlayers();
case 4:
case 2:
return matches[arg0].getGameType();
case 3:
return matches[arg0].getResult();
case 5:
case 4:
if (matches[arg0].getStartTime() != null) {
return timeFormatter.format(matches[arg0].getStartTime());
} else {
return "";
}
case 6:
case 5:
if (matches[arg0].getEndTime() != null) {
return timeFormatter.format(matches[arg0].getEndTime());
} else {
return "";
}
case 7:
case 6:
if (matches[arg0].isTournament()) {
return "Show";
} else {
@ -964,7 +961,7 @@ class MatchesTableModel extends AbstractTableModel {
return "None";
}
}
case 8:
case 7:
return matches[arg0].getGames();
}
return "";

View file

@ -0,0 +1,60 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.util;
import java.util.List;
import javax.swing.SortOrder;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
/**
*
* @author LevelX2
*/
public class MageTableRowSorter extends TableRowSorter {
public MageTableRowSorter(TableModel m) {
super(m);
}
/**
* @param column
* @inherited <p>
*/
@Override
public void toggleSortOrder(int column) {
List<? extends SortKey> sortKeys = getSortKeys();
if (sortKeys.size() > 0) {
if (sortKeys.get(0).getSortOrder() == SortOrder.DESCENDING) {
setSortKeys(null);
return;
}
}
super.toggleSortOrder(column);
}
}

View file

@ -75,7 +75,12 @@ public class MatchView implements Serializable {
this.matchId = match.getId();
this.matchName = match.getName();
this.gameType = match.getOptions().getGameType();
this.deckType = match.getOptions().getDeckType();
if (table.getName() != null && !table.getName().isEmpty()) {
this.deckType = match.getOptions().getDeckType() + " [" + table.getName() + "]";
} else {
this.deckType = match.getOptions().getDeckType();
}
for (Game game: match.getGames()) {
games.add(game.getId());
@ -123,8 +128,14 @@ public class MatchView implements Serializable {
if (table.getTournament().getOptions().getNumberRounds() > 0) {
this.gameType = new StringBuilder(this.gameType).append(" ").append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
}
this.deckType = new StringBuilder(table.getDeckType()).append(" ").append(table.getTournament().getBoosterInfo()).toString();
StringBuilder sbDeckType = new StringBuilder(table.getDeckType());
if (!table.getTournament().getBoosterInfo().isEmpty()) {
sbDeckType.append(" ").append(table.getTournament().getBoosterInfo());
}
if (table.getName() != null && !table.getName().isEmpty()) {
sbDeckType.append(table.getDeckType()).append(" [").append(table.getName()).append("]");
}
this.deckType = sbDeckType.toString();
StringBuilder sb1 = new StringBuilder();
for (TournamentPlayer tPlayer : table.getTournament().getPlayers()) {
sb1.append(tPlayer.getPlayer().getName()).append(" (").append(tPlayer.getPoints()).append(" P.) ");

View file

@ -37,6 +37,7 @@ import mage.constants.TableState;
import mage.game.Game;
import mage.game.Seat;
import mage.game.Table;
import mage.game.draft.Draft;
import mage.game.match.MatchPlayer;
import mage.game.tournament.TournamentPlayer;
@ -49,14 +50,13 @@ public class TableView implements Serializable {
private UUID tableId;
private String gameType;
private int wins;
private int freeMulligans;
private final String deckType;
private String tableName;
private String controllerName;
private final String additionalInfo;
private Date createTime;
private TableState tableState;
private final String tableStateText;
private boolean isTournament;
private List<SeatView> seats = new ArrayList<>();
private List<UUID> games = new ArrayList<>();
@ -65,6 +65,10 @@ public class TableView implements Serializable {
this.tableId = table.getId();
this.gameType = table.getGameType();
this.tableName = table.getName();
String tableNameInfo = null;
if (tableName != null && !tableName.isEmpty()) {
tableNameInfo = " [" + table.getName() + "]";
}
this.controllerName = table.getControllerName();
this.tableState = table.getState();
if (table.getState().equals(TableState.WAITING) ||
@ -83,8 +87,13 @@ public class TableView implements Serializable {
seats.add(new SeatView(seat));
}
if (!table.isTournament()) {
this.wins = table.getMatch().getWinsNeeded();
this.freeMulligans = table.getMatch().getFreeMulligans();
// MATCH
if (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.READY_TO_START)) {
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + "/"+ table.getSeats().length + ")" +
(table.getMatch().getOptions().getPassword().isEmpty() ? "":" PW");
} else {
tableStateText = table.getState().toString();
}
for (Game game: table.getMatch().getGames()) {
games.add(game.getId());
}
@ -98,30 +107,31 @@ public class TableView implements Serializable {
sb.append(", ").append(matchPlayer.getName());
sbScore.append("-").append(matchPlayer.getWins());
} else {
sbScore.insert(0,matchPlayer.getWins()).insert(0,"Score: ");
sbScore.insert(0,matchPlayer.getWins()).insert(0," Score: ");
}
}
if (table.getMatch().getDraws() > 0) {
sbScore.append(" Draws: ").append(table.getMatch().getDraws());
}
this.controllerName += sb.toString();
this.deckType = table.getDeckType();
this.deckType = table.getDeckType() + (tableNameInfo != null ? tableNameInfo : "");
StringBuilder addInfo = new StringBuilder();
if (table.getMatch().getGames().isEmpty()) {
if (!table.getMatch().getOptions().getPassword().isEmpty()) {
addInfo.append("PW-");
addInfo.append("Wins:").append(table.getMatch().getWinsNeeded());
addInfo.append(" Timer: ").append(table.getMatch().getOptions().getMatchTimeLimit().toString());
if (table.getMatch().getFreeMulligans() > 0) {
addInfo.append(" Free Mul.: ").append(table.getMatch().getFreeMulligans());
}
addInfo.append("Timer: ").append(table.getMatch().getOptions().getMatchTimeLimit().toString());
} else {
addInfo.append("Wins:").append(table.getMatch().getWinsNeeded());
addInfo.append(sbScore.toString());
}
this.additionalInfo = addInfo.toString();
} else {
this.wins = table.getTournament().getOptions().getMatchOptions().getWinsNeeded();
// TOURNAMENT
if (table.getTournament().getOptions().getNumberRounds() > 0) {
this.gameType = new StringBuilder(this.gameType).append(" ").append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
}
this.freeMulligans = table.getTournament().getOptions().getMatchOptions().getFreeMulligans();
StringBuilder sb1 = new StringBuilder();
for (TournamentPlayer tp: table.getTournament().getPlayers()) {
if (!tp.getPlayer().getName().equals(table.getControllerName())) {
@ -129,26 +139,41 @@ public class TableView implements Serializable {
}
}
this.controllerName += sb1.toString();
StringBuilder sb = new StringBuilder();
if (!table.getTournament().getOptions().getPassword().isEmpty()) {
sb.append("PW-");
StringBuilder infoText = new StringBuilder();
StringBuilder stateText = new StringBuilder(table.getState().toString());
infoText.append("Wins:").append(table.getTournament().getOptions().getMatchOptions().getWinsNeeded()).append(" ");
if (!table.getState().equals(TableState.WAITING)) {
infoText.append("Seats: ").append(table.getTournament().getPlayers().size()).append("/").append(table.getNumberOfSeats());
}
sb.append("Seats: ").append(table.getTournament().getPlayers().size()).append("/").append(table.getNumberOfSeats());
switch (table.getState()) {
case WAITING:
stateText.append(" (").append(table.getTournament().getPlayers().size()).append("/").append(table.getNumberOfSeats()).append(")");
if (!table.getTournament().getOptions().getPassword().isEmpty()) {
infoText.append(" PW");
}
case READY_TO_START:
case STARTING:
if (table.getTournament().getOptions().getMatchOptions().getFreeMulligans() > 0) {
infoText.append(" Free Mul.: ").append(table.getTournament().getOptions().getMatchOptions().getFreeMulligans());
}
if (table.getTournament().getTournamentType().isLimited()) {
sb.append(" Constr. Time: ").append(table.getTournament().getOptions().getLimitedOptions().getConstructionTime()/60).append(" Min.");
infoText.append(" Constr. Time: ").append(table.getTournament().getOptions().getLimitedOptions().getConstructionTime()/60).append(" Min.");
}
break;
case DUELING:
sb.append(" - Running round: ").append(table.getTournament().getRounds().size());
stateText.append(" Round: ").append(table.getTournament().getRounds().size());
break;
case DRAFTING:
Draft draft = table.getTournament().getDraft();
if (draft != null) {
stateText.append(" ").append(draft.getBoosterNum()).append("/").append(draft.getCardNum() -1);
}
default:
}
this.additionalInfo = sb.toString();
this.deckType = new StringBuilder(table.getDeckType()).append(" ").append(table.getTournament().getBoosterInfo()).toString();
this.additionalInfo = infoText.toString();
this.tableStateText = stateText.toString();
this.deckType = table.getDeckType() + " " + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : "");
}
}
@ -168,14 +193,6 @@ public class TableView implements Serializable {
return gameType;
}
public int getWins() {
return wins;
}
public int getFreeMulligans() {
return freeMulligans;
}
public String getDeckType() {
return deckType;
}
@ -203,4 +220,8 @@ public class TableView implements Serializable {
return this.additionalInfo;
}
public String getTableStateText() {
return tableStateText;
}
}

View file

@ -30,7 +30,6 @@ package mage.tournament;
import mage.constants.TournamentPlayerState;
import mage.game.draft.BoosterDraft;
import mage.game.draft.Draft;
import mage.game.draft.DraftOptions;
import mage.game.events.TableEvent.EventType;
import mage.game.tournament.TournamentOptions;

View file

@ -248,6 +248,10 @@ public class TableController {
if (user == null) {
return false;
}
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")){
user.showUserMessage("Join Table", new StringBuilder("You can join a table only one time.").toString());
return false;
}
if (table.getState() != TableState.WAITING) {
user.showUserMessage("Join Table", "No available seats.");
return false;
@ -644,6 +648,7 @@ public class TableController {
public synchronized void startTournament(UUID userId) {
try {
if (userId.equals(this.userId) && table.getState().equals(TableState.STARTING)) {
tournament.setStartTime();
TournamentManager.getInstance().createTournamentSession(tournament, userPlayerMap, table.getId());
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
User user = UserManager.getInstance().getUser(entry.getKey());

View file

@ -377,7 +377,7 @@ public class User {
public String getGameInfo() {
StringBuilder sb = new StringBuilder();
int draft = 0, match = 0, sideboard = 0, tournament = 0, construct = 0;
int draft = 0, match = 0, sideboard = 0, tournament = 0, construct = 0, waiting = 0;
for (Map.Entry<UUID, Table> tableEntry : tables.entrySet()) {
if (tableEntry != null) {
@ -389,6 +389,11 @@ public class User {
if (tournamentPlayer != null) {
if (!tournamentPlayer.isEliminated()) {
switch (table.getState()) {
case WAITING:
case STARTING:
case READY_TO_START:
waiting++;
break;
case CONSTRUCTING:
construct++;
break;
@ -415,6 +420,11 @@ public class User {
}
} else {
switch (table.getState()) {
case WAITING:
case STARTING:
case READY_TO_START:
waiting++;
break;
case SIDEBOARDING:
sideboard++;
break;
@ -426,6 +436,9 @@ public class User {
}
}
}
if (waiting > 0) {
sb.append("Wait: ").append(waiting).append(" ");
}
if (match > 0) {
sb.append("Match: ").append(match).append(" ");
}

View file

@ -224,36 +224,33 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
class TableListSorter implements Comparator<Table> {
@Override
public int compare(Table one, Table two) {
// priority 1 - Not started yet
if (one.getState().equals(TableState.READY_TO_START) || one.getState().equals(TableState.WAITING) || one.getState().equals(TableState.STARTING)) {
if (two.getState().equals(TableState.READY_TO_START) || two.getState().equals(TableState.WAITING) || two.getState().equals(TableState.STARTING)) {
return two.getCreateTime().compareTo(one.getCreateTime());
} else {
return -1; // one has higher priority
if (!one.getState().equals(TableState.SIDEBOARDING) && !one.getState().equals(TableState.DUELING)) {
if (one.getState().compareTo(two.getState()) != 0 ) {
return one.getState().compareTo(two.getState());
}
}
// priority 2 - Not finished yet -> Sorted by time started
if (two.getState().equals(TableState.READY_TO_START) || two.getState().equals(TableState.WAITING) || two.getState().equals(TableState.STARTING)) {
return 1; // two has higher priority
} else if (one.getEndTime() == null) {
if (two.getEndTime() == null) {
if (two.getStartTime() == null) {
return -1;
} else if (one.getStartTime() == null) {
return 1;
}
return two.getStartTime().compareTo(one.getStartTime());
if (two.getEndTime() != null) {
if (one.getEndTime() == null) {
return 1;
} else {
return -1;
}
return two.getEndTime().compareTo(one.getEndTime());
}
}
// priority 3 - Finished tables -> Sorted by time finished
if (two.getEndTime() == null) {
return 1;
} else {
return two.getEndTime().compareTo(one.getEndTime());
if (two.getStartTime() != null) {
if (one.getStartTime() == null) {
return 1;
} else {
return two.getStartTime().compareTo(one.getStartTime());
}
}
if (two.getCreateTime() != null) {
if (one.getCreateTime() == null) {
return 1;
} else {
return two.getCreateTime().compareTo(one.getCreateTime());
}
}
return 0;
}
}

View file

@ -80,7 +80,7 @@ class BonfireOfTheDamnedEffect extends OneShotEffect {
public BonfireOfTheDamnedEffect() {
super(Outcome.Damage);
staticText = "Bonfire of the Damned deals X damage to target player and each creature he or she controls";
staticText = "{this} deals X damage to target player and each creature he or she controls";
}
public BonfireOfTheDamnedEffect(final BonfireOfTheDamnedEffect effect) {
@ -97,8 +97,8 @@ class BonfireOfTheDamnedEffect extends OneShotEffect {
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
perm.damage(damage, source.getSourceId(), game, false, true);
}
return true;
}
return true;
}
return false;
}

View file

@ -9,9 +9,9 @@ public enum TableState {
READY_TO_START("Waiting to start"),
STARTING ("Starting"),
DRAFTING ("Drafting"),
DUELING ("Dueling"),
SIDEBOARDING ("Sideboarding"),
CONSTRUCTING ("Constructing"),
DUELING ("Dueling"),
SIDEBOARDING ("Sideboarding"),
FINISHED ("Finished");
private final String text;

View file

@ -77,6 +77,7 @@ public interface Tournament {
TournamentOptions getOptions();
// tournament times
void setStartTime();
Date getStartTime();
Date getEndTime();

View file

@ -492,6 +492,12 @@ public abstract class TournamentImpl implements Tournament {
return null;
}
@Override
public void setStartTime() {
this.stepStartTime = new Date();
}
@Override
public void setStepStartTime(Date stepStartTime) {
this.stepStartTime = stepStartTime;