use of soc.game.SOCInventoryItem in project JSettlers2 by jdmonin.
the class SOCHandPanel method clickPlayCardButton.
/**
* Handle a click on the "play card" button, or double-click
* on an item in the inventory/list of cards held.
*<P>
* Inventory items are almost always {@link SOCDevCard}s.
* Some scenarios may place other items in the player's inventory,
* such as a "gift" port being moved in {@link SOCGameOption#K_SC_FTRI _SC_FTRI}.
* If one of these is chosen, this method calls {@link #clickPlayInventorySpecialItem(SOCInventoryItem)}.
*<P>
* Called from actionPerformed()
*/
public void clickPlayCardButton() {
// Check first for "Cancel"
if (game.getGameState() == SOCGame.PLACING_INV_ITEM) {
client.getGameManager().cancelBuildRequest(game, SOCCancelBuildRequest.INV_ITEM_PLACE_CANCEL);
return;
}
String itemText;
// Which one to play from list?
int itemNum;
// SOCDevCard or special item
SOCInventoryItem itemObj = null;
// Clear prompt if Play Card clicked (instead of Roll clicked)
setRollPrompt(null, false);
itemText = inventory.getSelectedItem();
itemNum = inventory.getSelectedIndex();
if ((itemText == null) || (itemText.length() == 0)) {
if (inventory.getItemCount() == 1) {
// No card selected, but only one to choose from
itemText = inventory.getItem(0);
itemNum = 0;
if (itemText.length() == 0)
return;
itemObj = inventoryItems.get(0);
} else {
/**
* No card selected, multiple are in the list.
* See if only one card isn't a "(VP)" card, isn't new.
* If more than one, but they're all same type (ex.
* unplayed Robbers), pretend there's only one.
*/
// Nothing yet
itemNum = -1;
String itemNumText = null;
for (int i = inventory.getItemCount() - 1; i >= 0; --i) {
itemText = inventory.getItem(i);
if ((itemText != null) && (itemText.length() > 0)) {
SOCInventoryItem item = inventoryItems.get(i);
if (item.isPlayable()) {
// Playable (not VP card, not new) item found
if (itemObj == null) {
itemNum = i;
itemNumText = itemText;
itemObj = item;
} else if (itemObj.itype != item.itype) {
// More than one found, and they aren't the same type;
itemNum = -1;
// we can't auto-pick among them, so stop looking through the list.
break;
}
}
}
}
if ((itemNum == -1) || (itemObj == null)) {
// * "Please click a card first to select it."
playerInterface.printKeyed("hpan.devcards.clickfirst");
return;
}
itemText = itemNumText;
}
} else {
// get selected item's Card object
if (itemNum < inventoryItems.size())
itemObj = inventoryItems.get(itemNum);
}
if ((!playerIsCurrent) || (itemObj == null)) {
// <--- Early Return: Not current player ---
return;
}
if (itemObj.isVPItem()) {
playerInterface.print("*** " + strings.get("hpan.devcards.vp.secretlyplayed"));
// "You secretly played this VP card when you bought it."
itemNum = inventory.getSelectedIndex();
if (itemNum >= 0)
inventory.deselect(itemNum);
// <--- Early Return: Can't play a VP card ---
return;
}
if (itemObj.isNew()) {
// "Wait a turn before playing new cards."
playerInterface.print("*** " + strings.get("hpan.devcards.wait"));
// <--- Early Return: Card is new ---
return;
}
if (!(itemObj instanceof SOCDevCard)) {
clickPlayInventorySpecialItem(itemObj);
// <--- Early Return: Special item, not a dev card ---
return;
}
if (player.hasPlayedDevCard()) {
// "You may play only one card per turn."
playerInterface.print("*** " + strings.get("hpan.devcards.oneperturn"));
playCardBut.setEnabled(false);
return;
}
int cardTypeToPlay = -1;
switch(itemObj.itype) {
case SOCDevCardConstants.KNIGHT:
if (game.canPlayKnight(playerNumber)) {
cardTypeToPlay = SOCDevCardConstants.KNIGHT;
} else if (game.isGameOptionSet(SOCGameOption.K_SC_PIRI)) {
playerInterface.printKeyed("hpan.devcards.warship.cannotnow");
// "You cannot convert a ship to a warship right now."
}
break;
case SOCDevCardConstants.ROADS:
if (game.canPlayRoadBuilding(playerNumber)) {
cardTypeToPlay = SOCDevCardConstants.ROADS;
} else if (player.getNumPieces(SOCPlayingPiece.ROAD) == 0) {
if (game.hasSeaBoard && (player.getNumPieces(SOCPlayingPiece.SHIP) == 0))
playerInterface.printKeyed("hpan.devcards.roads_ships.none");
else
// "You have no roads or ships left to place."
playerInterface.printKeyed("hpan.devcards.roads.none");
// "You have no roads left to place."
}
break;
case SOCDevCardConstants.DISC:
if (game.canPlayDiscovery(playerNumber)) {
cardTypeToPlay = SOCDevCardConstants.DISC;
}
break;
case SOCDevCardConstants.MONO:
if (game.canPlayMonopoly(playerNumber)) {
cardTypeToPlay = SOCDevCardConstants.MONO;
}
break;
default:
playerInterface.printKeyed("hpan.devcards.interror.ctype", itemObj.itype, itemText);
}
if (cardTypeToPlay != -1) {
client.getGameManager().playDevCard(game, cardTypeToPlay);
disableBankUndoButton();
}
}
use of soc.game.SOCInventoryItem in project JSettlers2 by jdmonin.
the class SOCHandPanel method updateRollDoneBankButtons.
/**
* Client is current player; enable or disable buttons according to game state:
* {@link #rollBut}, {@link #doneBut}, {@link #bankBut}.
* Call only if {@link #playerIsCurrent} and {@link #playerIsClient}.
*<P>
* v2.0.00+: In game state {@link SOCGame#PLACING_INV_ITEM}, the Play Card button's label
* becomes {@link #CANCEL}, and {@link #inventory} is disabled, while the player places
* an item on the board. They can hit Cancel to return the item to their inventory instead.
* (Checks the flag set in {@link #setCanCancelInvItemPlay(boolean)}.)
* Once that state is over, button and inventory return to normal.
*
* @since 1.1.00
*/
private void updateRollDoneBankButtons() {
final int gs = game.getGameState();
rollBut.setEnabled(gs == SOCGame.ROLL_OR_CARD);
doneBut.setEnabled((gs == SOCGame.PLAY1) || (gs == SOCGame.SPECIAL_BUILDING) || (gs <= SOCGame.START3B) || doneButIsRestart);
bankBut.setEnabled(gs == SOCGame.PLAY1);
if (game.hasSeaBoard) {
if (gs == SOCGame.PLACING_INV_ITEM) {
// in this state only, "Play Card" becomes "Cancel"
SOCInventoryItem placing = game.getPlacingItem();
if (placing != null)
canCancelInvItemPlay = placing.canCancelPlay;
inventory.setEnabled(false);
playCardBut.setLabel(CANCEL);
playCardBut.setEnabled(canCancelInvItemPlay);
} else {
if (!inventory.isEnabled())
// note, may still visually appear disabled; repaint doesn't fix it
inventory.setEnabled(true);
if (playCardBut.getLabel().equals(CANCEL)) {
// " Play Card "
playCardBut.setLabel(CARD);
playCardBut.setEnabled(!inventoryItems.isEmpty());
}
}
}
}
use of soc.game.SOCInventoryItem in project JSettlers2 by jdmonin.
the class SOCDisplaylessPlayerClient method handleINVENTORYITEMACTION.
/**
* Handle the "inventory item action" message by updating player inventory.
* @param games The hashtable of client's {@link SOCGame}s; key = game name
* @param mes the message
* @return True if this message is a "cannot play this type now" from server for our client player.
* @since 2.0.00
*/
public static boolean handleINVENTORYITEMACTION(Hashtable<String, SOCGame> games, SOCInventoryItemAction mes) {
SOCGame ga = games.get(mes.getGame());
if (ga == null)
return false;
if ((mes.playerNumber == -1) || (mes.action == SOCInventoryItemAction.CANNOT_PLAY))
return true;
SOCPlayer pl = ga.getPlayer(mes.playerNumber);
if (pl == null)
return false;
SOCInventory inv = pl.getInventory();
SOCInventoryItem item = null;
switch(mes.action) {
case SOCInventoryItemAction.ADD_PLAYABLE:
case SOCInventoryItemAction.ADD_OTHER:
inv.addItem(SOCInventoryItem.createForScenario(ga, mes.itemType, (mes.action == SOCInventoryItemAction.ADD_PLAYABLE), mes.isKept, mes.isVP, mes.canCancelPlay));
break;
case SOCInventoryItemAction.PLAYED:
if (mes.isKept)
inv.keepPlayedItem(mes.itemType);
else
item = inv.removeItem(SOCInventory.PLAYABLE, mes.itemType);
if (!SOCInventoryItem.isPlayForPlacement(ga, mes.itemType))
break;
case SOCInventoryItemAction.PLACING_EXTRA:
if (item == null)
item = SOCInventoryItem.createForScenario(ga, mes.itemType, true, mes.isKept, mes.isVP, mes.canCancelPlay);
ga.setPlacingItem(item);
break;
}
return false;
}
use of soc.game.SOCInventoryItem in project JSettlers2 by jdmonin.
the class SOCGameMessageHandler method handleCANCELBUILDREQUEST.
/**
* handle "cancel build request" message.
* Cancel placement and send new game state, if cancel is allowed.
*
* @param c the connection that sent the message
* @param mes the message
* @since 1.0.0
*/
private void handleCANCELBUILDREQUEST(SOCGame ga, Connection c, final SOCCancelBuildRequest mes) {
ga.takeMonitor();
try {
final String gaName = ga.getName();
if (handler.checkTurn(c, ga)) {
final SOCPlayer player = ga.getPlayer(c.getData());
final int pn = player.getPlayerNumber();
final int gstate = ga.getGameState();
final boolean usePlayerElements = (ga.clientVersionLowest >= SOCPlayerElements.MIN_VERSION);
// If true, there was nothing cancelable: Don't call handler.sendGameState
boolean noAction = false;
switch(mes.getPieceType()) {
case SOCPlayingPiece.ROAD:
if ((gstate == SOCGame.PLACING_ROAD) || (gstate == SOCGame.PLACING_FREE_ROAD2)) {
ga.cancelBuildRoad(pn);
if (gstate == SOCGame.PLACING_ROAD) {
if (usePlayerElements) {
srv.messageToGame(gaName, new SOCPlayerElements(gaName, pn, SOCPlayerElement.GAIN, SOCRoad.COST));
} else {
srv.messageToGame(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.CLAY, 1));
srv.messageToGame(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.WOOD, 1));
}
} else {
srv.messageToGameKeyed(ga, true, "action.card.roadbuilding.skip.r", player.getName());
// "{0} skipped placing the second road."
}
} else {
srv.messageToPlayer(c, gaName, /*I*/
"You didn't buy a road.");
noAction = true;
}
break;
case SOCPlayingPiece.SETTLEMENT:
if (gstate == SOCGame.PLACING_SETTLEMENT) {
ga.cancelBuildSettlement(pn);
if (usePlayerElements) {
srv.messageToGame(gaName, new SOCPlayerElements(gaName, pn, SOCPlayerElement.GAIN, SOCSettlement.COST));
} else {
srv.gameList.takeMonitorForGame(gaName);
srv.messageToGameWithMon(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.CLAY, 1));
srv.messageToGameWithMon(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.SHEEP, 1));
srv.messageToGameWithMon(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.WHEAT, 1));
srv.messageToGameWithMon(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.WOOD, 1));
srv.gameList.releaseMonitorForGame(gaName);
}
} else if ((gstate == SOCGame.START1B) || (gstate == SOCGame.START2B) || (gstate == SOCGame.START3B)) {
SOCSettlement pp = new SOCSettlement(player, player.getLastSettlementCoord(), null);
ga.undoPutInitSettlement(pp);
// Re-send to all clients to announce it
srv.messageToGame(gaName, mes);
// (Safe since we've validated all message parameters)
// "{0} cancelled this settlement placement."
srv.messageToGameKeyed(ga, true, "action.built.stlmt.cancel", player.getName());
// The handler.sendGameState below is redundant if client reaction changes game state
} else {
srv.messageToPlayer(c, gaName, /*I*/
"You didn't buy a settlement.");
noAction = true;
}
break;
case SOCPlayingPiece.CITY:
if (gstate == SOCGame.PLACING_CITY) {
ga.cancelBuildCity(pn);
if (usePlayerElements) {
srv.messageToGame(gaName, new SOCPlayerElements(gaName, pn, SOCPlayerElement.GAIN, SOCCity.COST));
} else {
srv.messageToGame(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.ORE, 3));
srv.messageToGame(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.WHEAT, 2));
}
} else {
srv.messageToPlayer(c, gaName, /*I*/
"You didn't buy a city.");
noAction = true;
}
break;
case SOCPlayingPiece.SHIP:
if ((gstate == SOCGame.PLACING_SHIP) || (gstate == SOCGame.PLACING_FREE_ROAD2)) {
ga.cancelBuildShip(pn);
if (gstate == SOCGame.PLACING_SHIP) {
if (usePlayerElements) {
srv.messageToGame(gaName, new SOCPlayerElements(gaName, pn, SOCPlayerElement.GAIN, SOCShip.COST));
} else {
srv.messageToGame(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.SHEEP, 1));
srv.messageToGame(gaName, new SOCPlayerElement(gaName, pn, SOCPlayerElement.GAIN, SOCPlayerElement.WOOD, 1));
}
} else {
srv.messageToGameKeyed(ga, true, "action.card.roadbuilding.skip.s", player.getName());
// "{0} skipped placing the second ship."
}
} else {
srv.messageToPlayer(c, gaName, /*I*/
"You didn't buy a ship.");
noAction = true;
}
break;
case SOCCancelBuildRequest.INV_ITEM_PLACE_CANCEL:
SOCInventoryItem item = null;
if (gstate == SOCGame.PLACING_INV_ITEM)
item = ga.cancelPlaceInventoryItem(false);
if (item != null)
srv.messageToGame(gaName, new SOCInventoryItemAction(gaName, pn, SOCInventoryItemAction.ADD_PLAYABLE, item.itype, item.isKept(), item.isVPItem(), item.canCancelPlay));
if ((item != null) || (gstate != ga.getGameState())) {
srv.messageToGameKeyed(ga, true, "reply.placeitem.cancel", player.getName());
// "{0} canceled placement of a special item."
} else {
srv.messageToPlayerKeyed(c, gaName, "reply.placeitem.cancel.cannot");
// "Cannot cancel item placement."
noAction = true;
}
break;
default:
throw new IllegalArgumentException("Unknown piece type " + mes.getPieceType());
}
if (!noAction) {
handler.sendGameState(ga);
} else {
// bot is waiting for a gamestate reply, not text
final SOCClientData scd = (SOCClientData) c.getAppData();
if ((scd != null) && scd.isRobot)
c.put(SOCGameState.toCmd(gaName, gstate));
}
} else {
// "It's not your turn."
srv.messageToPlayerKeyed(c, gaName, "reply.not.your.turn");
}
} catch (Exception e) {
D.ebugPrintStackTrace(e, "Exception caught");
}
ga.releaseMonitor();
}
use of soc.game.SOCInventoryItem in project JSettlers2 by jdmonin.
the class SOCHandPanel method creation.
/**
* Stuff to do when a SOCHandPanel is created.
* Calls {@link #removePlayer()} as part of creation.
*
* @param pi player interface
* @param pl the player data, cannot be null
* @param in the interactive flag setting
*/
protected void creation(SOCPlayerInterface pi, SOCPlayer pl, boolean in) {
playerInterface = pi;
client = pi.getClient();
game = pi.getGame();
player = pl;
playerNumber = player.getPlayerNumber();
playerIsCurrent = false;
// confirmed by call to removePlayer() at end of method.
playerIsClient = false;
interactive = in;
// Note no AWT layout is used - custom layout, see doLayout().
final Color pcolor = playerInterface.getPlayerColor(playerNumber);
setBackground(pcolor);
setForeground(COLOR_FOREGROUND);
setFont(new Font("SansSerif", Font.PLAIN, 10));
// "One moment..."
blankStandIn = new ColorSquare(pcolor, strings.get("hpan.one.moment"));
blankStandIn.setVisible(false);
// playerinterface.initInterfaceElements will add blankStandIn to its layout, and set its size/position.
faceImg = new SOCFaceButton(playerInterface, playerNumber);
add(faceImg);
pname = new Label();
pname.setFont(new Font("SansSerif", Font.PLAIN, 13));
add(pname);
// Will be calculated at first turn
pnameActiveBG = null;
startBut = new Button(START);
startBut.addActionListener(this);
// this button always enabled
add(startBut);
// "Points: "
vpLab = new Label(strings.get("hpan.points") + " ");
add(vpLab);
vpSq = new ColorSquare(ColorSquare.GREY, 0);
// "Total victory points for this opponent"
vpSq.setTooltipText(strings.get("hpan.points.total.opponent"));
// "Close to winning"
final String vp_close_to_win = strings.get("hpan.points.closetowin");
if (game.vp_winner <= 12) {
// (win checked in SOCGame.checkForWinner)
vpSq.setTooltipHighWarningLevel(vp_close_to_win, game.vp_winner - 2);
} else {
vpSq.setTooltipHighWarningLevel(vp_close_to_win, game.vp_winner - 3);
}
add(vpSq);
if (game.hasSeaBoard) {
// "Special Victory Points, click for details"
final String svp_tt = strings.get("hpan.svp.tt");
// "SVP: "
svpLab = new Label(strings.get("hpan.svp") + " ");
svpLab.setVisible(false);
add(svpLab);
new AWTToolTip(svp_tt, svpLab);
svpLab.addMouseListener(this);
svpSq = new ColorSquare(ColorSquare.GREY, 0);
svpSq.setVisible(false);
svpSq.setTooltipText(svp_tt);
add(svpSq);
svpSq.addMouseListener(this);
} else {
svpLab = null;
svpSq = null;
}
final Font DIALOG_PLAIN_10 = new Font("Dialog", Font.PLAIN, 10);
larmyLab = new JLabel("", SwingConstants.CENTER);
// was bold 12pt SansSerif before v2.0.00 (i18n: needs room for more chars)
larmyLab.setFont(DIALOG_PLAIN_10);
add(larmyLab);
lroadLab = new JLabel("", SwingConstants.RIGHT);
// was bold 12pt SansSerif before v2.0.00
lroadLab.setFont(DIALOG_PLAIN_10);
add(lroadLab);
createAndAddResourceColorSquare(ColorSquare.CLAY, "resources.clay");
clayLab = createColorSqRetLbl;
claySq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.ORE, "resources.ore");
oreLab = createColorSqRetLbl;
oreSq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.SHEEP, "resources.sheep");
sheepLab = createColorSqRetLbl;
sheepSq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.WHEAT, "resources.wheat");
wheatLab = createColorSqRetLbl;
wheatSq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.WOOD, "resources.wood");
woodLab = createColorSqRetLbl;
woodSq = createColorSqRetSq;
// done, clear refs
createColorSqRetLbl = null;
// done, clear refs
createColorSqRetSq = null;
resourceSqDivLine = new ColorSquare(Color.BLACK);
add(resourceSqDivLine);
// cardLab = new Label("Cards:");
// add(cardLab);
inventoryItems = new ArrayList<SOCInventoryItem>();
inventory = new List(0, false);
// support double-click
inventory.addActionListener(this);
add(inventory);
final String pieces_available_to_place = strings.get("hpan.pieces.available");
roadSq = new ColorSquare(ColorSquare.GREY, 0);
add(roadSq);
roadSq.setTooltipText(pieces_available_to_place);
// "Almost out of roads to place"
roadSq.setTooltipLowWarningLevel(strings.get("hpan.roads.almostout"), 2);
// "No more roads available"
roadSq.setTooltipZeroText(strings.get("hpan.roads.out"));
// "Roads:"
roadLab = new JLabel(strings.get("hpan.roads"));
roadLab.setFont(DIALOG_PLAIN_10);
add(roadLab);
settlementSq = new ColorSquare(ColorSquare.GREY, 0);
add(settlementSq);
settlementSq.setTooltipText(pieces_available_to_place);
settlementSq.setTooltipLowWarningLevel(strings.get("hpan.stlmts.almostout"), 1);
settlementSq.setTooltipZeroText(strings.get("hpan.stlmts.out"));
// "Stlmts:"
settlementLab = new JLabel(strings.get("hpan.stlmts"));
settlementLab.setFont(DIALOG_PLAIN_10);
add(settlementLab);
citySq = new ColorSquare(ColorSquare.GREY, 0);
add(citySq);
citySq.setTooltipText(pieces_available_to_place);
citySq.setTooltipLowWarningLevel(strings.get("hpan.cities.almostout"), 1);
citySq.setTooltipZeroText(strings.get("hpan.cities.out"));
// "Cities:"
cityLab = new JLabel(strings.get("hpan.cities"));
cityLab.setFont(DIALOG_PLAIN_10);
add(cityLab);
if (game.hasSeaBoard) {
shipSq = new ColorSquare(ColorSquare.GREY, 0);
add(shipSq);
shipSq.setTooltipText(pieces_available_to_place);
shipSq.setTooltipLowWarningLevel(strings.get("hpan.ships.almostout"), 2);
shipSq.setTooltipZeroText(strings.get("hpan.ships.out"));
// "Ships:"
shipLab = new JLabel(strings.get("hpan.ships"));
shipLab.setFont(DIALOG_PLAIN_10);
add(shipLab);
} else {
// shipSq, shipLab already null
}
if (game.isGameOptionSet(SOCGameOption.K_SC_CLVI)) {
// No trailing space (room for wider colorsquares at left)
clothLab = new JLabel(strings.get("hpan.cloth"));
clothLab.setFont(DIALOG_PLAIN_10);
add(clothLab);
clothSq = new ColorSquare(ColorSquare.GREY, 0);
add(clothSq);
// "Amount of cloth traded from villages"
clothSq.setTooltipText(strings.get("hpan.cloth.amounttraded"));
} else if (game.isGameOptionSet(SOCGameOption.K_SC_WOND)) {
// Blank at wonder level 0; other levels' text set by updateValue(WonderLevel)
wonderLab = new JLabel("");
// same font as larmyLab, lroadLab
wonderLab.setFont(DIALOG_PLAIN_10);
add(wonderLab);
} else {
// clothSq, clothLab, wonderLab already null
}
// No trailing space (room for wider colorsquares at left)
knightsLab = new JLabel(strings.get("hpan.soldiers"));
knightsLab.setFont(DIALOG_PLAIN_10);
add(knightsLab);
knightsSq = new ColorSquare(ColorSquare.GREY, 0);
add(knightsSq);
// "Size of this army"
knightsSq.setTooltipText(strings.get("hpan.soldiers.sizearmy"));
resourceLab = new Label(RESOURCES);
add(resourceLab);
resourceSq = new ColorSquare(ColorSquare.GREY, 0);
add(resourceSq);
// "Amount in hand"
resourceSq.setTooltipText(strings.get("hpan.amounthand"));
// "If 7 is rolled, would discard half these resources"
resourceSq.setTooltipHighWarningLevel(strings.get("hpan.rsrc.roll7discard"), 8);
// "Dev. Cards: "
developmentLab = new Label(strings.get("hpan.devcards") + " ");
add(developmentLab);
developmentSq = new ColorSquare(ColorSquare.GREY, 0);
add(developmentSq);
developmentSq.setTooltipText(strings.get("hpan.amounthand"));
// button text will change soon in updateSeatLockButton()
sittingRobotLockBut = new Button(ROBOTLOCKBUT_U);
sittingRobotLockBut.addActionListener(this);
sittingRobotLockBut.setEnabled(interactive);
add(sittingRobotLockBut);
takeOverBut = new Button(TAKEOVER);
takeOverBut.addActionListener(this);
takeOverBut.setEnabled(interactive);
add(takeOverBut);
sitBut = new Button(SIT);
sitBut.addActionListener(this);
sitBut.setEnabled(interactive);
add(sitBut);
sitButIsLock = false;
robotBut = new Button(ROBOT);
robotBut.addActionListener(this);
robotBut.setEnabled(interactive);
add(robotBut);
playCardBut = new Button(CARD);
playCardBut.addActionListener(this);
playCardBut.setEnabled(interactive);
add(playCardBut);
playerTradingDisabled = game.isGameOptionSet("NT");
giveLab = new Label(GIVE);
add(giveLab);
if (interactive)
new AWTToolTip(strings.get("hpan.trade.igive.tip"), giveLab);
// "Resources to give to other players or the bank"
getLab = new Label(GET);
add(getLab);
if (interactive)
new AWTToolTip(strings.get("hpan.trade.iget.tip"), getLab);
// "Resources to get from other players or the bank"
sqPanel = new SquaresPanel(interactive, this);
add(sqPanel);
// will become visible only for seated client player
sqPanel.setVisible(false);
if (playerTradingDisabled) {
offerBut = null;
offerButTip = null;
} else {
offerBut = new Button(SEND);
offerBut.addActionListener(this);
offerBut.setEnabled(interactive);
add(offerBut);
if (interactive)
offerButTip = new AWTToolTip(OFFERBUTTIP_ENA, offerBut);
}
// clearOfferBut used by bank/port trade, and player trade
clearOfferBut = new Button(CLEAR);
clearOfferBut.addActionListener(this);
clearOfferBut.setEnabled(interactive);
add(clearOfferBut);
bankBut = new Button(BANK);
bankBut.addActionListener(this);
bankBut.setEnabled(interactive);
add(bankBut);
if (interactive)
new AWTToolTip(strings.get("hpan.trade.bankport.tip"), bankBut);
// "Trade these resources with the bank or a port"
bankUndoBut = new Button(BANK_UNDO);
bankUndoBut.addActionListener(this);
bankUndoBut.setEnabled(false);
add(bankUndoBut);
if (playerTradingDisabled) {
// playerSend, playerSendMap, playerSendForPrevTrade already null
} else {
playerSend = new ColorSquare[game.maxPlayers - 1];
playerSendMap = new int[game.maxPlayers - 1];
playerSendForPrevTrade = new boolean[game.maxPlayers - 1];
// set the trade buttons correctly
int cnt = 0;
for (int pn = 0; pn < game.maxPlayers; pn++) {
if (pn != playerNumber) {
Color color = playerInterface.getPlayerColor(pn);
playerSendMap[cnt] = pn;
playerSendForPrevTrade[cnt] = true;
playerSend[cnt] = new ColorSquare(ColorSquare.CHECKBOX, true, color);
playerSend[cnt].setColor(playerInterface.getPlayerColor(pn));
playerSend[cnt].setBoolValue(true);
add(playerSend[cnt]);
cnt++;
}
}
}
// if(playerTradingDisabled)
rollPromptCountdownLab = new Label(" ");
add(rollPromptCountdownLab);
// Nothing yet (no game in progress)
rollPromptInUse = false;
// Nothing yet
autoRollTimerTask = null;
rollBut = new Button(ROLL);
rollBut.addActionListener(this);
rollBut.setEnabled(interactive);
add(rollBut);
doneBut = new Button(DONE);
doneBut.addActionListener(this);
doneBut.setEnabled(interactive);
doneButIsRestart = false;
add(doneBut);
quitBut = new Button(QUIT);
quitBut.addActionListener(this);
quitBut.setEnabled(interactive);
add(quitBut);
offer = new TradeOfferPanel(this, playerNumber);
offer.setVisible(false);
offerIsResetMessage = false;
add(offer);
// Set tooltip appearance to look like rest of SOCHandPanel; currently only this panel uses Swing tooltips
if (!didSwingTooltipDefaults) {
UIManager.put("ToolTip.foreground", COLOR_FOREGROUND);
UIManager.put("ToolTip.background", Color.WHITE);
UIManager.put("ToolTip.font", DIALOG_PLAIN_10);
didSwingTooltipDefaults = true;
}
// set the starting state of the panel
removePlayer();
}
Aggregations