mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Client - Added number of active games to the header of the games column of the user list.
This commit is contained in:
parent
30ea2188bf
commit
aad1a2da89
11 changed files with 100 additions and 30 deletions
|
|
@ -51,6 +51,7 @@ import mage.remote.MageRemoteException;
|
|||
import mage.remote.Session;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.ChatMessage.MessageType;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.UsersView;
|
||||
|
||||
/**
|
||||
|
|
@ -303,12 +304,13 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
private final String[] columnNames = new String[]{"Players", "Info", "Games"};
|
||||
private UsersView[] players = new UsersView[0];
|
||||
|
||||
public void loadData(Collection<UsersView> players) throws MageRemoteException {
|
||||
this.players = players.toArray(new UsersView[0]);
|
||||
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
|
||||
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||
this.players = roomUserInfo.getUsersView().toArray(new UsersView[0]);
|
||||
JTableHeader th = jTablePlayers.getTableHeader();
|
||||
TableColumnModel tcm = th.getColumnModel();
|
||||
TableColumn tc = tcm.getColumn(0);
|
||||
tc.setHeaderValue(new StringBuilder("Players").append(" (").append(this.players.length).append(")").toString());
|
||||
tcm.getColumn(0).setHeaderValue(new StringBuilder("Players").append(" (").append(this.players.length).append(")").toString());
|
||||
tcm.getColumn(2).setHeaderValue(new StringBuilder("Games").append(" (").append(roomUserInfo.getNumberActiveGames()).append(")").toString());
|
||||
th.repaint();
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
|
@ -462,8 +464,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
}
|
||||
}//GEN-LAST:event_txtMessageKeyTyped
|
||||
|
||||
// public void setPlayers(Collection<String> players) {
|
||||
public void setPlayers(List<Collection<UsersView>> view) {
|
||||
public void setRoomUserInfo(List<Collection<RoomUsersView>> view) {
|
||||
try {
|
||||
tableModel.loadData(view.get(0));
|
||||
} catch (Exception ex) {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ import mage.game.match.MatchOptions;
|
|||
import mage.remote.MageRemoteException;
|
||||
import mage.remote.Session;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UsersView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -855,7 +856,7 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
|||
|
||||
}
|
||||
|
||||
class UpdatePlayersTask extends SwingWorker<Void, Collection<UsersView>> {
|
||||
class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
|
||||
|
||||
private final Session session;
|
||||
private final UUID roomId;
|
||||
|
|
@ -872,15 +873,15 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<UsersView>> {
|
|||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
this.publish(session.getConnectedPlayers(roomId));
|
||||
Thread.sleep(1000);
|
||||
this.publish(session.getRoomUsers(roomId));
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<UsersView>> players) {
|
||||
chat.setPlayers(players);
|
||||
protected void process(List<Collection<RoomUsersView>> roomUserInfo) {
|
||||
chat.setRoomUserInfo(roomUserInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1015,7 +1016,7 @@ class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
|||
if (matches != null) {
|
||||
this.publish(matches);
|
||||
}
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import mage.view.MatchView;
|
|||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserDataView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.UserView;
|
||||
import mage.view.UsersView;
|
||||
|
||||
|
|
@ -70,7 +71,7 @@ public interface MageServer {
|
|||
|
||||
// server state methods
|
||||
ServerState getServerState() throws MageException;
|
||||
List<UsersView> getConnectedPlayers(UUID roomId) throws MageException;
|
||||
List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException;
|
||||
List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
|
||||
Object getServerMessagesCompressed(String sessionId) throws MageException; // messages of the day
|
||||
|
||||
|
|
|
|||
|
|
@ -524,10 +524,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<UsersView> getConnectedPlayers(UUID roomId) throws MageRemoteException {
|
||||
public Collection<RoomUsersView> getRoomUsers(UUID roomId) throws MageRemoteException {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getConnectedPlayers(roomId);
|
||||
return server.getRoomUsers(roomId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import mage.view.UserView;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.UsersView;
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +47,7 @@ public interface ServerState {
|
|||
|
||||
List<UserView> getUsers();
|
||||
|
||||
Collection<UsersView> getConnectedPlayers(UUID roomId) throws MageRemoteException;
|
||||
Collection<RoomUsersView> getRoomUsers (UUID roomId) throws MageRemoteException;
|
||||
|
||||
List<String> getServerMessages();
|
||||
|
||||
|
|
|
|||
60
Mage.Common/src/mage/view/RoomUsersView.java
Normal file
60
Mage.Common/src/mage/view/RoomUsersView.java
Normal 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.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class RoomUsersView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int numberActiveGames;
|
||||
|
||||
private final List<UsersView> usersView;
|
||||
|
||||
public RoomUsersView(List<UsersView> usersView, int numberActiveGames) {
|
||||
|
||||
this.numberActiveGames = numberActiveGames;
|
||||
|
||||
this.usersView = usersView;
|
||||
}
|
||||
|
||||
public int getNumberActiveGames() {
|
||||
return numberActiveGames;
|
||||
}
|
||||
|
||||
public List<UsersView> getUsersView() {
|
||||
return usersView;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -37,9 +37,9 @@ public class UsersView implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String userName;
|
||||
private String infoState;
|
||||
private String infoGames;
|
||||
private final String userName;
|
||||
private final String infoState;
|
||||
private final String infoGames;
|
||||
|
||||
public UsersView(String userName, String infoState, String infoGames) {
|
||||
this.userName = userName;
|
||||
|
|
|
|||
|
|
@ -297,12 +297,11 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public List<UsersView> getConnectedPlayers(UUID roomId) throws MageException {
|
||||
public List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getPlayers();
|
||||
return room.getRoomUsersInfo();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,4 +210,7 @@ public class GameManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public int getNumberActiveGames() {
|
||||
return gameControllers.size();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import mage.game.match.MatchOptions;
|
|||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.server.Room;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UsersView;
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ public interface GamesRoom extends Room {
|
|||
|
||||
List<TableView> getTables();
|
||||
List<MatchView> getFinished();
|
||||
List<UsersView> getPlayers();
|
||||
List<RoomUsersView> getRoomUsersInfo();
|
||||
boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
||||
boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||
TableView createTable(UUID userId, MatchOptions options);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import mage.server.User;
|
|||
import mage.server.UserManager;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UsersView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -66,7 +67,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
private static final ScheduledExecutorService updateExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
private static List<TableView> tableView = new ArrayList<>();
|
||||
private static List<MatchView> matchView = new ArrayList<>();
|
||||
private static List<UsersView> usersView = new ArrayList<>();
|
||||
private static List<RoomUsersView> roomUsersView = new ArrayList<>();
|
||||
|
||||
private final ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
@ -125,7 +126,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
Collections.sort(users, new UserNameSorter());
|
||||
usersView = users;
|
||||
List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
||||
roomUserInfo.add(new RoomUsersView(users, GameManager.getInstance().getNumberActiveGames()));
|
||||
roomUsersView = roomUserInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -201,8 +204,8 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<UsersView> getPlayers() {
|
||||
return usersView;
|
||||
public List<RoomUsersView> getRoomUsersInfo() {
|
||||
return roomUsersView;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue