wxPlayerTreeCtrl

Displays all of the players in the current Game in a tree control, with full drag and drop support.  All of the colors in the system are displayed as tree nodes.  If a player is in the game, the color that they are assigned to has their player name next to it in the tree.  If a node in the tree does not have a player name next to it, that color is available for any player to select.

The class wxPlayerTreeCtrl is a drop target for any drag and drop operation that uses Player objects.  The drop targets are the color nodes themselves, so that a user’s color may be directly selected with a drag/drop.  Not only that, but wxPlayerTreeCtrl is also drag initiator for itself, meaning that a user may alter the color of a player in the game by selecting the player with the left mouse button, holding down the mouse, dragging the player to a new color, and then releasing the left mouse button.

Derived From

wxBaseTreeCtrl IPlayerDropTarget

Project

Cities3D

Include

PlayerTreeCtrl.h

Summary
Displays all of the players in the current Game in a tree control, with full drag and drop support.
The wxPlayerTreeCtrl constructor.
The wxPlayerTreeCtrl destructor.
Handles the drag event when the mouse is over the control.
Handles a drop event.
The wxWidgets event table declaration.
Creates color nodes in the tree of all possible game colors.
Sets player names for all Players in the Game next to the node with their color.
Handles a left mouse down event.
Handles a double-click in the player list.
The tree ID of the player name being dragged.

Public

Summary
The wxPlayerTreeCtrl constructor.
The wxPlayerTreeCtrl destructor.
Handles the drag event when the mouse is over the control.
Handles a drop event.
The wxWidgets event table declaration.

Constructors

wxPlayerTreeCtrl

wxPlayerTreeCtrl(wxWindow *parent, 
wxWindowID id, 
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize)

The wxPlayerTreeCtrl constructor.  Calls the base wxBaseTreeCtrl constructor, creates all of the color nodes in the tree, registers itself as a drop target, then adds OnUpdatePlayers to the Controller as a receiver of the eventPreGame Event.

Parameters

parentThe parent window.
idThe message handling ID.  Should be a unique (to the parent window) ID, if the parent window wants to receive messages from the control.
posThe list control position in window coordinates.
sizeThe list control size.

Destructor

~wxPlayerTreeCtrl

~wxPlayerTreeCtrl()

The wxPlayerTreeCtrl destructor.  Removes OnUpdatePlayers as a receiver of the eventPreGame Event.

Virtual Functions

OnDragOver

virtual void OnDragOver(wxCoord x,
wxCoord y)

Handles the drag event when the mouse is over the control.  Overridden from IPlayerDropTarget.  Does a hit test with the given coordinates and selects any color node that may be underneath the potential drop position.

Parameters

xThe x coordinate of the drag position.
yThe y coordinate of the drag position.

OnData

virtual void OnData(wxCoord x,
wxCoord y,
const Player &player)

Handles a drop event.  Occurs when the player has released the mouse button over the control with a valid Player data object to drop.  First checks to ensure that the drop position is valid and then does a combination of three things.  Adds the player to the game if the player is not already in the tree, and/or changes the color of the player if they were already in the tree, and/or removes a player from the game if they were already at the dropped color.

Parameters

xThe x coordinate of the drop position.
yThe y coordinate of the drop position.
playerThe Player to set to the color.

Variables

DECLARE_EVENT_TABLE

The wxWidgets event table declaration.

Private

Summary
Creates color nodes in the tree of all possible game colors.
Sets player names for all Players in the Game next to the node with their color.
Handles a left mouse down event.
Handles a double-click in the player list.
The tree ID of the player name being dragged.

Functions

CreateColors

void CreateColors()

Creates color nodes in the tree of all possible game colors.

Game Event Functions

OnUpdatePlayers

void OnUpdatePlayers(GamePtr game)

Sets player names for all Players in the Game next to the node with their color.  Triggered by the eventPreGame Event.

Parameters

gameThe current Game.

Event Message Handling

OnLeftDown

void OnLeftDown(wxMouseEvent &event)

Handles a left mouse down event.  Checks to see if the mouse landed on a color node with a player name.  If so, sets the item to selected and then creates a new wxPlayerDataObject with the Player data for the selected player name.  Finally, creates a wxDropSource object for doing drag and drop in wxWidgets.

Parameters

eventThe mouse event.

OnItemDoubleClick

void OnItemDoubleClick(wxTreeEvent &event)

Handles a double-click in the player list.  If a player name is selected, the RuleUIRemovePlayer Rule is executed and the Player data corresponding to the selected player name is removed from the game.

Parameters

eventThe list control event.

Variables

mDragID

wxTreeItemId mDragID

The tree ID of the player name being dragged.  Used to determine if a drag/drop is happening from within the tree itself as opposed to starting from an outside source.

Still volatile.
wxPlayerTreeCtrl(wxWindow *parent, 
wxWindowID id, 
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize)
The wxPlayerTreeCtrl constructor.
~wxPlayerTreeCtrl()
The wxPlayerTreeCtrl destructor.
virtual void OnDragOver(wxCoord x,
wxCoord y)
Handles the drag event when the mouse is over the control.
virtual void OnData(wxCoord x,
wxCoord y,
const Player &player)
Handles a drop event.
void CreateColors()
Creates color nodes in the tree of all possible game colors.
void OnUpdatePlayers(GamePtr game)
Sets player names for all Players in the Game next to the node with their color.
Still volatile.
void OnLeftDown(wxMouseEvent &event)
Handles a left mouse down event.
void OnItemDoubleClick(wxTreeEvent &event)
Handles a double-click in the player list.
wxTreeItemId mDragID
The tree ID of the player name being dragged.
A basic tree control.
An interface for Player data drag and drop operations.
Cities3D is a cross-platform implementation of the board game Settlers of Catan with all expansions, including Seafarers, and Cities & Knights.
The communication mechanism between the View and the Model.
A generic implementation of the Observer design pattern.
A data object for Player drag and drop operations.
The default implementation of IRule for normal Game actions.