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.remote.Session;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import mage.view.ChatMessage.MessageType;
|
import mage.view.ChatMessage.MessageType;
|
||||||
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.UsersView;
|
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 final String[] columnNames = new String[]{"Players", "Info", "Games"};
|
||||||
private UsersView[] players = new UsersView[0];
|
private UsersView[] players = new UsersView[0];
|
||||||
|
|
||||||
public void loadData(Collection<UsersView> players) throws MageRemoteException {
|
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
|
||||||
this.players = players.toArray(new UsersView[0]);
|
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||||
|
this.players = roomUserInfo.getUsersView().toArray(new UsersView[0]);
|
||||||
JTableHeader th = jTablePlayers.getTableHeader();
|
JTableHeader th = jTablePlayers.getTableHeader();
|
||||||
TableColumnModel tcm = th.getColumnModel();
|
TableColumnModel tcm = th.getColumnModel();
|
||||||
TableColumn tc = tcm.getColumn(0);
|
tcm.getColumn(0).setHeaderValue(new StringBuilder("Players").append(" (").append(this.players.length).append(")").toString());
|
||||||
tc.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();
|
th.repaint();
|
||||||
this.fireTableDataChanged();
|
this.fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
@ -462,8 +464,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_txtMessageKeyTyped
|
}//GEN-LAST:event_txtMessageKeyTyped
|
||||||
|
|
||||||
// public void setPlayers(Collection<String> players) {
|
public void setRoomUserInfo(List<Collection<RoomUsersView>> view) {
|
||||||
public void setPlayers(List<Collection<UsersView>> view) {
|
|
||||||
try {
|
try {
|
||||||
tableModel.loadData(view.get(0));
|
tableModel.loadData(view.get(0));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ import mage.game.match.MatchOptions;
|
||||||
import mage.remote.MageRemoteException;
|
import mage.remote.MageRemoteException;
|
||||||
import mage.remote.Session;
|
import mage.remote.Session;
|
||||||
import mage.view.MatchView;
|
import mage.view.MatchView;
|
||||||
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.UsersView;
|
import mage.view.UsersView;
|
||||||
import org.apache.log4j.Logger;
|
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 Session session;
|
||||||
private final UUID roomId;
|
private final UUID roomId;
|
||||||
|
|
@ -872,15 +873,15 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<UsersView>> {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Exception {
|
protected Void doInBackground() throws Exception {
|
||||||
while (!isCancelled()) {
|
while (!isCancelled()) {
|
||||||
this.publish(session.getConnectedPlayers(roomId));
|
this.publish(session.getRoomUsers(roomId));
|
||||||
Thread.sleep(1000);
|
Thread.sleep(3000);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void process(List<Collection<UsersView>> players) {
|
protected void process(List<Collection<RoomUsersView>> roomUserInfo) {
|
||||||
chat.setPlayers(players);
|
chat.setRoomUserInfo(roomUserInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1015,7 +1016,7 @@ class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||||
if (matches != null) {
|
if (matches != null) {
|
||||||
this.publish(matches);
|
this.publish(matches);
|
||||||
}
|
}
|
||||||
Thread.sleep(5000);
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ import mage.view.MatchView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.TournamentView;
|
import mage.view.TournamentView;
|
||||||
import mage.view.UserDataView;
|
import mage.view.UserDataView;
|
||||||
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.UserView;
|
import mage.view.UserView;
|
||||||
import mage.view.UsersView;
|
import mage.view.UsersView;
|
||||||
|
|
||||||
|
|
@ -70,7 +71,7 @@ public interface MageServer {
|
||||||
|
|
||||||
// server state methods
|
// server state methods
|
||||||
ServerState getServerState() throws MageException;
|
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;
|
List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
|
||||||
Object getServerMessagesCompressed(String sessionId) throws MageException; // messages of the day
|
Object getServerMessagesCompressed(String sessionId) throws MageException; // messages of the day
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -524,16 +524,16 @@ public class SessionImpl implements Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<UsersView> getConnectedPlayers(UUID roomId) throws MageRemoteException {
|
public Collection<RoomUsersView> getRoomUsers(UUID roomId) throws MageRemoteException {
|
||||||
try {
|
try {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
return server.getConnectedPlayers(roomId);
|
return server.getRoomUsers(roomId);
|
||||||
}
|
}
|
||||||
} catch (MageException ex) {
|
} catch (MageException ex) {
|
||||||
handleMageException(ex);
|
handleMageException(ex);
|
||||||
throw new MageRemoteException();
|
throw new MageRemoteException();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
handleThrowable(t);
|
handleThrowable(t);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import mage.view.UserView;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.UsersView;
|
import mage.view.UsersView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,8 +47,8 @@ public interface ServerState {
|
||||||
|
|
||||||
List<UserView> getUsers();
|
List<UserView> getUsers();
|
||||||
|
|
||||||
Collection<UsersView> getConnectedPlayers(UUID roomId) throws MageRemoteException;
|
Collection<RoomUsersView> getRoomUsers (UUID roomId) throws MageRemoteException;
|
||||||
|
|
||||||
List<String> getServerMessages();
|
List<String> getServerMessages();
|
||||||
|
|
||||||
Collection<TableView> getTables(UUID roomId) throws MageRemoteException;
|
Collection<TableView> getTables(UUID roomId) throws MageRemoteException;
|
||||||
|
|
|
||||||
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 static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String userName;
|
private final String userName;
|
||||||
private String infoState;
|
private final String infoState;
|
||||||
private String infoGames;
|
private final String infoGames;
|
||||||
|
|
||||||
public UsersView(String userName, String infoState, String infoGames) {
|
public UsersView(String userName, String infoState, String infoGames) {
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
|
|
|
||||||
|
|
@ -297,12 +297,11 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//FIXME: why no sessionId here???
|
public List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException {
|
||||||
public List<UsersView> getConnectedPlayers(UUID roomId) throws MageException {
|
|
||||||
try {
|
try {
|
||||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||||
if (room != null) {
|
if (room != null) {
|
||||||
return room.getPlayers();
|
return room.getRoomUsersInfo();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -210,4 +210,7 @@ public class GameManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberActiveGames() {
|
||||||
|
return gameControllers.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import mage.game.match.MatchOptions;
|
||||||
import mage.game.tournament.TournamentOptions;
|
import mage.game.tournament.TournamentOptions;
|
||||||
import mage.server.Room;
|
import mage.server.Room;
|
||||||
import mage.view.MatchView;
|
import mage.view.MatchView;
|
||||||
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.UsersView;
|
import mage.view.UsersView;
|
||||||
|
|
||||||
|
|
@ -48,7 +49,7 @@ public interface GamesRoom extends Room {
|
||||||
|
|
||||||
List<TableView> getTables();
|
List<TableView> getTables();
|
||||||
List<MatchView> getFinished();
|
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 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;
|
boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||||
TableView createTable(UUID userId, MatchOptions options);
|
TableView createTable(UUID userId, MatchOptions options);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ import mage.server.User;
|
||||||
import mage.server.UserManager;
|
import mage.server.UserManager;
|
||||||
import mage.server.tournament.TournamentManager;
|
import mage.server.tournament.TournamentManager;
|
||||||
import mage.view.MatchView;
|
import mage.view.MatchView;
|
||||||
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.UsersView;
|
import mage.view.UsersView;
|
||||||
import org.apache.log4j.Logger;
|
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 final ScheduledExecutorService updateExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static List<TableView> tableView = new ArrayList<>();
|
private static List<TableView> tableView = new ArrayList<>();
|
||||||
private static List<MatchView> matchView = 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<>();
|
private final ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
@ -124,8 +125,10 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(users, new UserNameSorter());
|
Collections.sort(users, new UserNameSorter());
|
||||||
usersView = users;
|
List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
||||||
|
roomUserInfo.add(new RoomUsersView(users, GameManager.getInstance().getNumberActiveGames()));
|
||||||
|
roomUsersView = roomUserInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -201,8 +204,8 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UsersView> getPlayers() {
|
public List<RoomUsersView> getRoomUsersInfo() {
|
||||||
return usersView;
|
return roomUsersView;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue