BuildUI

Displays a possible action for the player.  BuildUIs sit at the top of the screen just below the ControlsUI and MessageUI.  Each BuildUI represents one type of object the player can build or buy (such as stock items or dev cards), or an action the user can trigger (such as moving a ship or knight).  A bitmap is displayed in the BuildUI representing the action the user can take with that BuildUI.

Each BuildUI is created with a piece of BuildData, located in the loaded RuleSets, that tells the BuildUI how to draw the object it handles, what ILogic updates it, and what IRule to call when the user clicks on the BuildUI to build, buy, or perform the action.  BuildUI can be updated by transmitting a DataObject to the eventBuildUI Event via the Controller.  The transmitted DataObject must have a bool as its first parameter, and the current Game object as its second parameter.  If the bool value is false, the Build hides itself; if the bool value is true, the BuildUI calls its internal ILogic to see if can be shown.  If it can be shown, the color of the displayed bitmap is updated based on the current player in the Game object.  If the player clicks the visible BuildUI, the BuildUI calls the RuleEngine with its internal IRule to execute the player’s action.

Derived From

BaseUI

Project

Cities3D

Include

BuildUI.h

Summary
Displays a possible action for the player.
The BuildUI constructor.
The BuildUI destructor.
Initializes the BuildUI.
The wxWidgets event table declaration.
Paints the BuildUI.
Provides the TraitsUI object for the BuildUI.
Resizes the BuildUI.
Updates the BuildUI.
Handles clicking the displayedbitmap.
Whether the BuildUI is first in a new row of BuildUIs on screen.
The index of the most recently current player when the BuildUI was last updated.
The internal wxWidgets ID of the displayed bitmap.
Pointer to the window the BuildUI is offset from.
The name of the IRule to be called when the BuildUI is clicked.
The name of the ILogic that determines if the BuildUI should be visible.
The displayed bitmap of the object the BuildUI represents.
The bitmap helper that creates the displayed bitmap based on the original BuildData the BuildUI was created with.

Public

Summary
The BuildUI constructor.
The BuildUI destructor.
Initializes the BuildUI.
The wxWidgets event table declaration.

Constructors

BuildUI

BuildUI(wxWindow *parent,
const wxWindow *pResizeLink,
const BuildDataPtr &build,
bool newRow)

The BuildUI constructor.  Stores the IRule and ILogic names to use.  Creates the bitmap handler for display.  Adds OnUpdate as a receiver of the eventBuildUI Event.

Parameters

parentThe parent window.  Must not be NULL.
resizeLinkThe window used to calculate offset properly.  Must not be NULL.
buildThe BuildData used to construct the BuildUI.
newRowWhether this BuildUI is the first in a row of BuildUIs on screen.

Destructor

~BuildUI

~BuildUI()

The BuildUI destructor.  Removes OnUpdate as a receiver of the eventBuildUI Event.

Virtual Functions

InitializeUI

virtual void InitializeUI(const GamePtr &game)

Initializes the BuildUI.  Creates the internal TraitsUI object and then the bitmap window displaying the type of object the BuildUI represents.  Calls ResizeUI to set the size of the UI properly.

Variables

DECLARE_EVENT_TABLE

The wxWidgets event table declaration.

Private

Summary
Paints the BuildUI.
Provides the TraitsUI object for the BuildUI.
Resizes the BuildUI.
Updates the BuildUI.
Handles clicking the displayedbitmap.
Whether the BuildUI is first in a new row of BuildUIs on screen.
The index of the most recently current player when the BuildUI was last updated.
The internal wxWidgets ID of the displayed bitmap.
Pointer to the window the BuildUI is offset from.
The name of the IRule to be called when the BuildUI is clicked.
The name of the ILogic that determines if the BuildUI should be visible.
The displayed bitmap of the object the BuildUI represents.
The bitmap helper that creates the displayed bitmap based on the original BuildData the BuildUI was created with.

Virtual Functions

Paint

virtual void Paint(wxMemoryDC &dc)

Paints the BuildUI.  Fills in the background color and draws the rounded outline.

Parameters

dcThe memory dc to draw into.

GetTraitsUI

virtual const TraitsUIPtr &GetTraitsUI()

Provides the TraitsUI object for the BuildUI.

Returns

A const reference to the TraitsUI object.

ResizeUI

virtual void ResizeUI()

Resizes the BuildUI.  Uses the internal TraitsUI object to set the width and height for the entire UI.  Sets the offset amount properly based on the resize link.  Resizes the displayed bitmap based on the TraitsUI size information.

Game Event Functions

OnUpdate

void OnUpdate(DataObject object)

Updates the BuildUI.  Triggered by the eventBuildUI Event.  The given DataObject must have a bool as its first parameter.  If the bool is true, the BuildUI calls its internal ILogic to see if it can be shown on screen.  If so, updates the color of its bitmap and redisplays it, then shows itself.

Parameters

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

Event Message Handling

OnButton

void OnButton(wxCommandEvent &event)

Handles clicking the displayedbitmap.  Calls the RuleEngine with the internal IRule.

Parameters

eventThe button click event.

Variables

mNewRow

bool mNewRow

Whether the BuildUI is first in a new row of BuildUIs on screen.  Used for properly calculating the offset.

mLastIndex

wxInt32 mLastIndex

The index of the most recently current player when the BuildUI was last updated.  Used as an optimization to avoid recreating the displayed bitmap every time OnUpdate is called.

mButtonID

wxInt32 mButtonID

The internal wxWidgets ID of the displayed bitmap.  Used as a workaround to wxWidgets not allowing the same ID to be used for all bitmaps in Release mode.

mResizeLink

const wxWindow *mResizeLink

Pointer to the window the BuildUI is offset from.  Queried in ResizeUI to make sure that the proper offset distance from the UI anchor point is maintained.

mRule

wxString mRule

The name of the IRule to be called when the BuildUI is clicked.

mLogic

wxString mLogic

The name of the ILogic that determines if the BuildUI should be visible.

mBitmap

boost::shared_ptr<wxBitmapButton> mBitmap

The displayed bitmap of the object the BuildUI represents.

mBuildBitmap

BuildBitmapPtr mBuildBitmap

The bitmap helper that creates the displayed bitmap based on the original BuildData the BuildUI was created with.

BuildUI(wxWindow *parent,
const wxWindow *pResizeLink,
const BuildDataPtr &build,
bool newRow)
The BuildUI constructor.
~BuildUI()
The BuildUI destructor.
virtual void InitializeUI(const GamePtr &game)
Initializes the BuildUI.
virtual void Paint(wxMemoryDC &dc)
Paints the BuildUI.
virtual const TraitsUIPtr &GetTraitsUI()
Provides the TraitsUI object for the BuildUI.
Manages internal element sizes for a BaseUI-derived object.
virtual void ResizeUI()
Resizes the BuildUI.
void OnUpdate(DataObject object)
Updates the BuildUI.
void OnButton(wxCommandEvent &event)
Handles clicking the displayedbitmap.
bool mNewRow
Whether the BuildUI is first in a new row of BuildUIs on screen.
wxInt32 mLastIndex
The index of the most recently current player when the BuildUI was last updated.
wxInt32 mButtonID
The internal wxWidgets ID of the displayed bitmap.
const wxWindow *mResizeLink
Pointer to the window the BuildUI is offset from.
wxString mRule
The name of the IRule to be called when the BuildUI is clicked.
The interface for a single game rule.
wxString mLogic
The name of the ILogic that determines if the BuildUI should be visible.
The interface of a single piece of game logic.
boost::shared_ptr<wxBitmapButton> mBitmap
The displayed bitmap of the object the BuildUI represents.
BuildBitmapPtr mBuildBitmap
The bitmap helper that creates the displayed bitmap based on the original BuildData the BuildUI was created with.
RulesCore
Displays a set of buttons for user turn actions.
Displays game-related messages to the user.
A repository of all things rules-related.
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 default implementation of the IRuleEngine interface.
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.