public class DomesticTradeController extends Controller implements IDomesticTradeController, ModelObserver
| Modifier and Type | Class and Description |
|---|---|
private static class |
DomesticTradeController.ResourcePositions |
private static class |
DomesticTradeController.TradeResourceStates |
| Modifier and Type | Field and Description |
|---|---|
private IAcceptTradeOverlay |
acceptOverlay |
private int |
playerIndexToTradeWith |
private boolean |
playersToTradeWithAlreadySet |
private DomesticTradeController.TradeResourceStates[] |
resourceStates |
private int[] |
resourcesToTrade |
private IDomesticTradeOverlay |
tradeOverlay |
private IWaitView |
waitOverlay |
| Constructor and Description |
|---|
DomesticTradeController(IDomesticTradeView tradeView,
IDomesticTradeOverlay tradeOverlay,
IWaitView waitOverlay,
IAcceptTradeOverlay acceptOverlay)
DomesticTradeController constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
acceptTrade(boolean willAccept)
Called by the accept trade overlay when the user either accepts or
rejects a trade.
|
void |
alert()
Notifies an object that something has happened
|
void |
cancelTrade()
Called by the domestic trade overlay when the user cancels a trade.
|
private void |
checkIfTradeIsReady()
Check if the trade is ready, enable and disable the trade button accordingly
|
void |
decreaseResourceAmount(ResourceType resource)
Called by the domestic trade overlay when the user decreases the amount
of a resource.
|
private void |
enableUpDownButtonsForReceiveResource(ResourceType type)
Handles button enabling/disabling for receive resources
|
private void |
enableUpDownButtonsForSendResource(ResourceType type)
Handles button enabling/disabling for send resources
|
IAcceptTradeOverlay |
getAcceptOverlay() |
private int |
getResourceIndex(ResourceType type)
Helper method for converting a resource type into an index of the resource
to trade array
|
IDomesticTradeOverlay |
getTradeOverlay() |
IDomesticTradeView |
getTradeView() |
IWaitView |
getWaitOverlay() |
void |
increaseResourceAmount(ResourceType resource)
Called by the domestic trade overlay when the user increases the amount
of a resource.
|
private void |
initializePlayersToTradeWith() |
private boolean |
playerCanAcceptTrade(int[] resources)
Returns true if the player can accept the trade offer
|
private void |
resetResourcesToTrade()
Just resets the resource to trade each time it's called
|
private void |
resetTradeOverlay() |
private void |
resetTradeResesourceStates()
Researches the internal button states each time it's called, should only be called when
domestic trade modal opens
|
private void |
resetUpDownButtons() |
private boolean |
sendAndReceiveResourcesSet()
Checks to see if send and receive resources are set in the trade
|
void |
sendTradeOffer()
Called by the domestic trade overlay when the user clicks the trade
button.
|
void |
setAcceptOverlay(IAcceptTradeOverlay acceptOverlay) |
void |
setPlayerToTradeWith(int playerIndex)
Called by the domestic trade overlay when the user selects a player to
trade with.
|
void |
setResourceToReceive(ResourceType resource)
Called by the domestic trade overlay when the user selects a resource to
be received.
|
void |
setResourceToSend(ResourceType resource)
Called by the domestic trade overlay when the user selects a resource to
be sent.
|
void |
setTradeOverlay(IDomesticTradeOverlay tradeOverlay) |
void |
setWaitOverlay(IWaitView waitView) |
void |
startTrade()
Called by the domestic trade view when the user clicks the domestic trade
button.
|
void |
unsetResource(ResourceType resource)
Called by the domestic trade overlay when user selects "none" for a
resource.
|
private void |
updateUpDownForResource(ResourceType type)
Called whenever the state of the upDown buttons has changed, disables or enables them
after checking context
|
getViewclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetViewprivate IDomesticTradeOverlay tradeOverlay
private IWaitView waitOverlay
private IAcceptTradeOverlay acceptOverlay
private boolean playersToTradeWithAlreadySet
private int[] resourcesToTrade
private DomesticTradeController.TradeResourceStates[] resourceStates
private int playerIndexToTradeWith
public DomesticTradeController(IDomesticTradeView tradeView, IDomesticTradeOverlay tradeOverlay, IWaitView waitOverlay, IAcceptTradeOverlay acceptOverlay)
tradeView - Domestic trade view (i.e., view that contains the "Domestic Trade" button)tradeOverlay - Domestic trade overlay (i.e., view that lets the user propose a domestic trade)waitOverlay - Wait overlay used to notify the user they are waiting for another player to accept a tradeacceptOverlay - Accept trade overlay which lets the user accept or reject a proposed tradepublic IDomesticTradeView getTradeView()
public IDomesticTradeOverlay getTradeOverlay()
public void setTradeOverlay(IDomesticTradeOverlay tradeOverlay)
public IWaitView getWaitOverlay()
public void setWaitOverlay(IWaitView waitView)
public IAcceptTradeOverlay getAcceptOverlay()
public void setAcceptOverlay(IAcceptTradeOverlay acceptOverlay)
public void alert()
ModelObserveralert in interface ModelObserverprivate boolean playerCanAcceptTrade(int[] resources)
public void startTrade()
IDomesticTradeControllerstartTrade in interface IDomesticTradeControllerprivate void initializePlayersToTradeWith()
private void resetResourcesToTrade()
private void resetTradeResesourceStates()
private void resetTradeOverlay()
private void checkIfTradeIsReady()
private boolean sendAndReceiveResourcesSet()
public void decreaseResourceAmount(ResourceType resource)
IDomesticTradeControllerdecreaseResourceAmount in interface IDomesticTradeControllerresource - The resource whose amount is being decreasedpublic void increaseResourceAmount(ResourceType resource)
IDomesticTradeControllerincreaseResourceAmount in interface IDomesticTradeControllerresource - The resource whose amount is being increasedprivate void resetUpDownButtons()
private void updateUpDownForResource(ResourceType type)
type - private void enableUpDownButtonsForSendResource(ResourceType type)
type - private void enableUpDownButtonsForReceiveResource(ResourceType type)
type - private int getResourceIndex(ResourceType type)
type - public void sendTradeOffer()
IDomesticTradeControllersendTradeOffer in interface IDomesticTradeControllerpublic void setPlayerToTradeWith(int playerIndex)
IDomesticTradeControllersetPlayerToTradeWith in interface IDomesticTradeControllerplayerIndex - The index [0, 3] of the selected trading partner, or -1 if
"None" was selectedpublic void setResourceToReceive(ResourceType resource)
IDomesticTradeControllersetResourceToReceive in interface IDomesticTradeControllerresource - The resource to be receivedpublic void setResourceToSend(ResourceType resource)
IDomesticTradeControllersetResourceToSend in interface IDomesticTradeControllerresource - The resource to be sentpublic void unsetResource(ResourceType resource)
IDomesticTradeControllerunsetResource in interface IDomesticTradeControllerresource - The resource for which "none" was selectedpublic void cancelTrade()
IDomesticTradeControllercancelTrade in interface IDomesticTradeControllerpublic void acceptTrade(boolean willAccept)
IDomesticTradeControlleracceptTrade in interface IDomesticTradeControllerwillAccept - Whether or not the user accepted the trade