PlayerUI

Displays game information for one player.  The PlayerUI windows start at the top left of the screen and continue down the left side.  PlayerUIs are the most complicated of all the UI pieces.  They display the player’s current resource cards, current development or progress cards, stock items, points from various means, special flags, and modify themselves in different modes of the game.  For instance, the current player in hotseat mode can see their cards, but when the current player changes, the PlayerUIs must update themselves so that only the new current player’s cards are visible.  A PlayerUI is updated by transmitting a DataObject to the eventPlayerUI Event via the Controller.  The transmitted DataObject must have the current Game as its first parameter, and a wxInt32 as its second parameter.  The wxInt32 flag specifys which player’s data needs to be updated, or -1 to update all, or -2 to update which player’s turn it is.

When a PlayerUI is initialized, it queries the IPluginEngine and retrieves all PlayerData objects supplied by the currently loaded RuleSets.  It then takes these pieces of PlayerData and builds a layout of icons representing cards, stock, and point information from them.  Some PlayerData objects may require OpenGL rendered bitmaps, namely the stock items.  In those cases, the associated IDrawObjects are sent to the parent wxSettlersGLCanvas and converted from OpenGL to a wxBitmap.  The PlayerUI keeps track of all of these bits of information and handles laying them out in a more or less generalized fashion so that different RuleSets can add new items to the player display windows without difficulty.

The key idea with PlayerUI is that it knows nothing about any particular piece of knowledge in the game, making it 100% plugin data.  It just takes the PlayerData supplied by the loaded RuleSets, groups it by categories, and lays it out in the window.

Derived From

BaseUI

Project

Cities3D

Include

PlayerUI.h

Summary
Displays game information for one player.
The PlayerUI constructor.
The PlayerUI destructor.
Recalculates the proper width of the PlayerUI.
Initializes the PlayerUI.
Paints the PlayerUI.
Provides the TraitsUI object for the PlayerUI.
Resizes the PlayerUI.
Updates the player UI elements by calling each of their own Update functions.
Updates the player UI color and name if and when the players are reordered during the game.
The index of the player this PlayerUI represnets.
The index of current player.
The color used to draw this player’s text and outline.
The TraitsUI object for this PlayerUI.
The static text control displaying the player’s name.
Pointer to the window the PlayerUI is offset from.
The points in the UI where vertical lines are drawn.
The individual elements in the UI.

Public

Summary
The PlayerUI constructor.
The PlayerUI destructor.
Recalculates the proper width of the PlayerUI.
Initializes the PlayerUI.

Constructors

PlayerUI

PlayerUI(const wxInt32 index,
wxWindow *parent,
const wxWindow *pResizeLink)

The PlayerUI constructor.  Makes the PlayerUI visible and adds OnUpdate as a receiver of the eventPlayerUI Event.  Adds OnPlayerReorder as a receiver of the eventPlayerReorder Event.

Parameters

parentThe parent window.  Must not be NULL.

Destructor

~PlayerUI

~PlayerUI()

The PlayerUI destructor.  Removes OnUpdate as a receiver of the eventPlayerUI Event.

CalculateWidth

void CalculateWidth()

Recalculates the proper width of the PlayerUI.  Takes into account many factors which affect the width.  When finished, sets the Width value in the TraitsUI object.

Virtual Functions

InitializeUI

virtual void InitializeUI(const GamePtr &game)

Initializes the PlayerUI.  Loads all of the PlayerData objects from the <Rulesets> in the IPluginEngine and creates inidividual elements out of them.  Creates the wxBaseStaticText object that holds the player’s name.  Sets the outline color and text colors based on the player’s selected colors.  Then creates the internal TraitsUI object and calls ResizeUI to set the size of the UI properly.

Parameters

gameThe current Game.

Private

Summary
Paints the PlayerUI.
Provides the TraitsUI object for the PlayerUI.
Resizes the PlayerUI.
Updates the player UI elements by calling each of their own Update functions.
Updates the player UI color and name if and when the players are reordered during the game.
The index of the player this PlayerUI represnets.
The index of current player.
The color used to draw this player’s text and outline.
The TraitsUI object for this PlayerUI.
The static text control displaying the player’s name.
Pointer to the window the PlayerUI is offset from.
The points in the UI where vertical lines are drawn.
The individual elements in the UI.

Virtual Functions

Paint

virtual void Paint(wxMemoryDC &dc)

Paints the PlayerUI.  Fills in the background color and draws the rounded outline.  Erases overlapping parts when it draws the player tab, and adds separater lines between sections.

Parameters

dcThe memory dc to draw into.

GetTraitsUI

virtual const TraitsUIPtr &GetTraitsUI()

Provides the TraitsUI object for the PlayerUI.

Returns

A const reference to the TraitsUI object.

ResizeUI

virtual void ResizeUI()

Resizes the PlayerUI.  Uses the internal TraitsUI object to set the width and height for the entire UI.  Adjusts every single element in the UI to new dimensions based on its type and recomputes the layout.  \ Recalculates the fonts for all the elements and for the player’s name.

Game Event Functions

OnUpdate

void OnUpdate(DataObject object)

Updates the player UI elements by calling each of their own Update functions.  Each player UI element is responsible for showing/hiding itself and updating its color and counter properly.  Shows and hides various components if required by a change in turn.

Parameters

objectThe DataObject containing the update information.  Must have a Game object as its first parameter, and a wxInt32 as the second parameter.

OnPlayerReorder

void OnPlayerReorder(GamePtr game)

Updates the player UI color and name if and when the players are reordered during the game.

Parameters

gameThe current Game.

Variables

mIndex

wxInt32 mIndex

The index of the player this PlayerUI represnets.

mDrawIndex

wxInt32 mDrawIndex

The index of current player.  If it is the same as mIndex, the PlayerUI is outlined with the player’s color to indicate that it is their turn.

mTextColor

wxColour mTextColor

The color used to draw this player’s text and outline.

mTraitsUI

TraitsUIPtr mTraitsUI

The TraitsUI object for this PlayerUI.

mpName

boost::shared_ptr<wxStaticText> mpName

The static text control displaying the player’s name.

mResizeLink

const wxWindow *mResizeLink

Pointer to the window the PlayerUI is offset from.  This is the PlayerUI directly above it if it is not the first player, or NULL if it is the first player.  Queried in ResizeUI to make sure that the proper offset distance from the UI anchor point is maintained.

mLineList

PointList mLineList

The points in the UI where vertical lines are drawn.

mElements

ElementHash mElements

The individual elements in the UI.  Stored in an integer hash so that they can be grouped together by category (resources, cards, stock, points, special)

PlayerUI(const wxInt32 index,
wxWindow *parent,
const wxWindow *pResizeLink)
The PlayerUI constructor.
~PlayerUI()
The PlayerUI destructor.
void CalculateWidth()
Recalculates the proper width of the PlayerUI.
virtual void InitializeUI(const GamePtr &game)
Initializes the PlayerUI.
virtual void Paint(wxMemoryDC &dc)
Paints the PlayerUI.
virtual const TraitsUIPtr &GetTraitsUI()
Provides the TraitsUI object for the PlayerUI.
Manages internal element sizes for a BaseUI-derived object.
virtual void ResizeUI()
Resizes the PlayerUI.
void OnUpdate(DataObject object)
Updates the player UI elements by calling each of their own Update functions.
void OnPlayerReorder(GamePtr game)
Updates the player UI color and name if and when the players are reordered during the game.
wxInt32 mIndex
The index of the player this PlayerUI represnets.
wxInt32 mDrawIndex
The index of current player.
wxColour mTextColor
The color used to draw this player’s text and outline.
TraitsUIPtr mTraitsUI
The TraitsUI object for this PlayerUI.
boost::shared_ptr<wxStaticText> mpName
The static text control displaying the player’s name.
const wxWindow *mResizeLink
Pointer to the window the PlayerUI is offset from.
PointList mLineList
The points in the UI where vertical lines are drawn.
ElementHash mElements
The individual elements in the UI.
A generic container for passing any kind of data around.
A generic implementation of the Observer design pattern.
The communication mechanism between the View and the Model.
Still volatile.
The interface of the plugin engine.
Describes a piece of information that needs to be displayed in the PlayerUI.
A repository of all things rules-related.
The interface for objects that are drawn on screen.
Renders all game objects in OpenGL.
A base class for all main screen UI.
Cities3D is a cross-platform implementation of the board game Settlers of Catan with all expansions, including Seafarers, and Cities & Knights.
A basic static text window.