Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kiosk has now a repository selector #128

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/.gradle/
/build/
/out/
/.metadata/
/.settings/
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ task tiltyardRequestFarm(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
}

task batchValidator(type: JavaExec) {
main = 'org.ggp.base.apps.validator.BatchValidator'
classpath = sourceSets.main.runtimeClasspath
}

task validator(type: JavaExec) {
main = 'org.ggp.base.apps.validator.Validator'
classpath = sourceSets.main.runtimeClasspath
}

task player(type: JavaExec) {
main = 'org.ggp.base.apps.player.Player'
classpath = sourceSets.main.runtimeClasspath
Expand Down
64 changes: 37 additions & 27 deletions src/main/java/org/ggp/base/apps/kiosk/Kiosk.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;

import org.ggp.base.player.GamePlayer;
Expand All @@ -34,16 +30,16 @@
import org.ggp.base.server.event.ServerConnectionErrorEvent;
import org.ggp.base.server.event.ServerIllegalMoveEvent;
import org.ggp.base.server.event.ServerTimeoutEvent;
import org.ggp.base.util.game.CloudGameRepository;
import org.ggp.base.util.game.Game;
import org.ggp.base.util.game.GameRepository;
import org.ggp.base.util.gdl.grammar.GdlPool;
import org.ggp.base.util.logging.GamerLogger;
import org.ggp.base.util.match.Match;
import org.ggp.base.util.observer.Event;
import org.ggp.base.util.observer.Observer;
import org.ggp.base.util.reflection.ProjectSearcher;
import org.ggp.base.util.symbol.grammar.SymbolPool;
import org.ggp.base.util.ui.GameSelector;
import org.ggp.base.util.ui.GameSelector.NamedItem;
import org.ggp.base.util.ui.NativeUI;
import org.ggp.base.util.ui.PublishButton;

Expand Down Expand Up @@ -87,9 +83,13 @@ public void run() {

private final JTextField playClockTextField;
private final JTextField startClockTextField;
private final JTextPane gameDescription;

private final JButton runButton;
private final JList<AvailableGame> selectedGame;
private final java.util.Map<String,AvailableGame> name2availableGame;
private final java.util.Map<String,String> canvasNameToGameKey;
private final GameSelector gameSelector;

private final JCheckBox flipRoles;

private final PublishButton publishButton;
Expand All @@ -100,8 +100,6 @@ public void run() {
private List<Class<? extends Gamer>> gamers = null;
private final JTextField computerAddress;

private final GameRepository theRepository;

public Kiosk()
{
super(new GridBagLayout());
Expand All @@ -110,23 +108,25 @@ public Kiosk()
NativeUI.setNativeUI();
GamerLogger.setFileToDisplay("GamePlayer");

SortedSet<AvailableGame> theAvailableGames = new TreeSet<AvailableGame>();
name2availableGame = new java.util.HashMap<String,AvailableGame>();
canvasNameToGameKey = new java.util.HashMap<String,String>();

flipRoles = new JCheckBox("Flip roles?");
Set<Class<? extends GameCanvas>> theAvailableCanvasList = ProjectSearcher.GAME_CANVASES.getConcreteClasses();
for(Class<? extends GameCanvas> availableCanvas : theAvailableCanvasList) {
try {
GameCanvas theCanvas = availableCanvas.newInstance();
theAvailableGames.add(new AvailableGame(theCanvas.getGameName(), theCanvas.getGameKey(), availableCanvas));
String gameKey = theCanvas.getGameKey();
String canvasName = theCanvas.getGameName();
AvailableGame availableGame = new AvailableGame(canvasName, gameKey, availableCanvas);
name2availableGame.put(canvasName, availableGame);
canvasNameToGameKey.put(canvasName, gameKey);
} catch(Exception e) {
;
}
}

flipRoles = new JCheckBox("Flip roles?");

selectedGame = new JList<AvailableGame>(theAvailableGames.toArray(new AvailableGame[0]));
selectedGame.setSelectedIndex(0);
selectedGame.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane selectedGamePane = new JScrollPane(selectedGame);
gameSelector = new GameSelector(canvasNameToGameKey);

computerAddress = new JTextField("player.ggp.org:80");
playerComboBox = new JComboBox<String>();
Expand Down Expand Up @@ -156,6 +156,11 @@ public Kiosk()

startClockTextField = new JTextField("30");
playClockTextField = new JTextField("10");

gameDescription = new JTextPane();
gameDescription.setPreferredSize(new Dimension(0, 0));
gameSelector.getGameList().addItemListener(this);

managerPanel = new JPanel(new GridBagLayout());

startClockTextField.setColumns(15);
Expand All @@ -171,8 +176,12 @@ public Kiosk()
managerPanel.add(new JLabel("Play Clock:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(playClockTextField, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(flipRoles, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(new JLabel("Repository:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(gameSelector.getRepositoryList(), new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(new JLabel("Game:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(selectedGamePane, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 5.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(gameSelector.getGameList(), new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(new JLabel("Description:"), new GridBagConstraints(0, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(gameDescription, new GridBagConstraints(0, nRowCount++, 2, 1, 1.0, 5.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(new JLabel("Publishing:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
managerPanel.add(publishButton, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
//managerPanel.add(new ConsolePanel(), new GridBagConstraints(0, nRowCount++, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 5, 5));
Expand All @@ -195,11 +204,6 @@ public Kiosk()
} catch(Exception e) {
e.printStackTrace();
}

// This is where we get the rulesheets from. Each game has a corresponding
// game (with rulesheet) stored on this repository server. Changing this is
// likely to break things unless you know what you're doing.
theRepository = new CloudGameRepository("http://games.ggp.org/base/");
}

class AvailableGame implements Comparable<AvailableGame> {
Expand Down Expand Up @@ -301,8 +305,8 @@ public void actionPerformed(ActionEvent e) {
GdlPool.drainPool();
SymbolPool.drainPool();

AvailableGame theGame = selectedGame.getSelectedValue();
Game game = theRepository.getGame(theGame.kifFile);
AvailableGame theGame = name2availableGame.get(((NamedItem)gameSelector.getGameList().getSelectedItem()).theName);
Game game = gameSelector.getSelectedGameRepository().getGame(theGame.kifFile);

if (game == null) {
JOptionPane.showMessageDialog(this, "Cannot load game data for " + theGame.kifFile, "Error", JOptionPane.ERROR_MESSAGE);
Expand Down Expand Up @@ -398,6 +402,12 @@ public void itemStateChanged(ItemEvent e) {
}
validate();
}
if(e.getSource() == gameSelector.getGameList()) {
Game selectedGame = gameSelector.getSelectedGame();
if ( selectedGame != null) {
gameDescription.setText(selectedGame.getDescription());
}
}
}

@Override
Expand All @@ -413,4 +423,4 @@ public void observe(Event event) {
System.err.println("Connection error when communicating with role [" + x.getRole() + "].");
}
}
}
}
35 changes: 31 additions & 4 deletions src/main/java/org/ggp/base/util/ui/GameSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class GameSelector implements ActionListener {
GameRepository theSelectedRepository;
Map<String, GameRepository> theCachedRepositories;

class NamedItem {
java.util.Map<String,String> restrictionNameToKey = null;

public static class NamedItem {
public final String theKey;
public final String theName;

Expand All @@ -47,7 +49,7 @@ public String toString() {
}
}

public GameSelector() {
void init() {
theGameList = new JComboBox<NamedItem>();
theGameList.addActionListener(this);

Expand All @@ -60,6 +62,14 @@ public GameSelector() {
theRepositoryList.addItem("games.ggp.org/stanford");
theRepositoryList.addItem("Local Game Repository");
}
public GameSelector() {
init();
}

public GameSelector(java.util.Map<String,String> restrictionNameToKey) {
this.restrictionNameToKey = restrictionNameToKey;
init();
}

@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -85,10 +95,14 @@ public GameRepository getSelectedGameRepository() {

public void repopulateGameList() {
GameRepository theRepository = getSelectedGameRepository();
List<String> theKeyList = new ArrayList<String>(theRepository.getGameKeys());
List<String> theKeyList;
theKeyList = new ArrayList<String>(theRepository.getGameKeys());
Collections.sort(theKeyList);
theGameList.removeAllItems();
for (String theKey : theKeyList) {
if ( restrictionNameToKey != null && ! restrictionNameToKey.containsValue(theKey)) {
continue;
}
Game theGame = theRepository.getGame(theKey);
if (theGame == null) {
continue;
Expand All @@ -99,7 +113,20 @@ public void repopulateGameList() {
}
if (theName.length() > 24)
theName = theName.substring(0, 24) + "...";
theGameList.addItem(new NamedItem(theKey, theName));

if ( restrictionNameToKey == null) {
theGameList.addItem(new NamedItem(theKey, theName));
}
else {
for (String name: restrictionNameToKey.keySet()) {
String key = restrictionNameToKey.get(name);
//System.out.println("theKey: "+theKey+", theName: "+theName+", name:"+name + ", key: " + key);
if ( theKey.equals(key)) {
//System.out.println("key: " + key + ", name" + name);
theGameList.addItem(new NamedItem(theKey, name));
}
}
}
}
}

Expand Down