Make starting a match work

This commit is contained in:
drdev
2014-02-28 02:12:47 +00:00
parent 1ce397c463
commit bef8f2cc69
4 changed files with 139 additions and 4 deletions

1
.gitattributes vendored
View File

@@ -16013,6 +16013,7 @@ forge-m-base/src/forge/screens/constructed/ConstructedScreen.java -text
forge-m-base/src/forge/screens/draft/DraftScreen.java -text
forge-m-base/src/forge/screens/guantlet/GuantletScreen.java -text
forge-m-base/src/forge/screens/home/HomeScreen.java -text
forge-m-base/src/forge/screens/match/MatchController.java -text
forge-m-base/src/forge/screens/match/MatchScreen.java -text
forge-m-base/src/forge/screens/quest/QuestScreen.java -text
forge-m-base/src/forge/screens/sealed/SealedScreen.java -text

View File

@@ -1,5 +1,6 @@
package forge.player;
import forge.ai.PlayerControllerAi;
import forge.game.Game;
import forge.game.player.LobbyPlayer;
import forge.game.player.Player;
@@ -17,15 +18,15 @@ public class LobbyPlayerHuman extends LobbyPlayer {
@Override
public PlayerController createControllerFor(Player human) {
return null; //TODO new PlayerControllerHuman(human.getGame(), human, this);
return new PlayerControllerAi(human.getGame(), human, this); //TODO new PlayerControllerHuman(human.getGame(), human, this);
}
@Override
public Player createIngamePlayer(Game game) { //TODO
Player player = new Player(/*GuiDisplayUtil.personalizeHuman(*/getName()/*)*/, game);
/*player.setFirstController(new PlayerControllerHuman(game, player, this));
player.setFirstController(new PlayerControllerAi(game, player, this)/*new PlayerControllerHuman(game, player, this)*/);
if (ForgePreferences.DEV_MODE && Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) {
/*if (ForgePreferences.DEV_MODE && Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) {
player.canCheatPlayUnlimitedLands = true;
}*/

View File

@@ -0,0 +1,130 @@
package forge.screens.match;
import java.util.ArrayList;
import java.util.List;
import forge.Forge;
import forge.game.Game;
import forge.game.Match;
import forge.game.player.LobbyPlayer;
import forge.game.player.Player;
public class MatchController {
private final MatchScreen view;
private Game game;
private List<Player> sortedPlayers;
public MatchController(MatchScreen view0) {
view = view0;
}
public final void startGameWithUi(final Match match) {
game = match.createGame();
/*if (game.getRules().getGameType() == GameType.Quest) {
QuestController qc = Singletons.getModel().getQuest();
// Reset new list when the Match round starts, not when each game starts
if (game.getMatch().getPlayedGames().isEmpty()) {
qc.getCards().resetNewList();
}
game.subscribeToEvents(qc); // this one listens to player's mulligans ATM
}*/
//inputQueue = new InputQueue();
//game.subscribeToEvents(Singletons.getControl().getSoundSystem());
LobbyPlayer humanLobbyPlayer = game.getRegisteredPlayers().get(0).getLobbyPlayer(); //FServer.instance.getLobby().getGuiPlayer();
// The UI controls should use these game data as models
initMatch(game.getRegisteredPlayers(), humanLobbyPlayer);
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
// Game is set on pause while gui player takes decisions
game.getAction().invoke(new Runnable() {
@Override
public void run() {
match.startGame(game);
}
});
}
public final void endCurrentGame() {
if (this.game == null) { return; }
Forge.back();
this.game = null;
}
public void initMatch(final List<Player> players, LobbyPlayer localPlayer) {
// TODO fix for use with multiplayer
final String[] indices = new String[] { "1", "2" }; //Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
// Instantiate all required field slots (user at 0)
sortedPlayers = shiftPlayersPlaceLocalFirst(players, localPlayer);
/*final List<VField> fields = new ArrayList<VField>();
final List<VCommand> commands = new ArrayList<VCommand>();
int i = 0;
for (Player p : sortedPlayers) {
// A field must be initialized after it's instantiated, to update player info.
// No player, no init.
VField f = new VField(EDocID.Fields[i], p, localPlayer);
VCommand c = new VCommand(EDocID.Commands[i], p);
fields.add(f);
commands.add(c);
//setAvatar(f, new ImageIcon(FSkin.getAvatars().get()));
setAvatar(f, getPlayerAvatar(p, Integer.parseInt(indices[i > 2 ? 1 : 0])));
f.getLayoutControl().initialize();
c.getLayoutControl().initialize();
i++;
}
// Replace old instances
view.setCommandViews(commands);
view.setFieldViews(fields);
VPlayers.SINGLETON_INSTANCE.init(players);*/
initHandViews(localPlayer);
}
public void initHandViews(LobbyPlayer localPlayer) {
/*final List<VHand> hands = new ArrayList<VHand>();
int i = 0;
for (Player p : sortedPlayers) {
if (p.getLobbyPlayer() == localPlayer) {
VHand newHand = new VHand(EDocID.Hands[i], p);
newHand.getLayoutControl().initialize();
hands.add(newHand);
}
i++;
}
if (hands.isEmpty()) { // add empty hand for matches without human
VHand newHand = new VHand(EDocID.Hands[0], null);
newHand.getLayoutControl().initialize();
hands.add(newHand);
}
view.setHandViews(hands);*/
}
private List<Player> shiftPlayersPlaceLocalFirst(final List<Player> players, LobbyPlayer localPlayer) {
// get an arranged list so that the first local player is at index 0
List<Player> sortedPlayers = new ArrayList<Player>(players);
int ixFirstHuman = -1;
for (int i = 0; i < players.size(); i++) {
if (sortedPlayers.get(i).getLobbyPlayer() == localPlayer) {
ixFirstHuman = i;
break;
}
}
if (ixFirstHuman > 0) {
sortedPlayers.add(0, sortedPlayers.remove(ixFirstHuman));
}
return sortedPlayers;
}
}

View File

@@ -5,10 +5,13 @@ import forge.game.Match;
public class MatchScreen extends FScreen {
private final Match match;
private final MatchController controller;
public MatchScreen(Match match0) {
super(false, null, true);
this.match = match0;
match = match0;
controller = new MatchController(this);
controller.startGameWithUi(match0);
}
@Override