2006-04-18

Mu Torere, changing colours

Step 6.
Given that the program can display colours, might as well go ahead and show how to change those colours. But first, the menu
FileSettingsHelp
New gameUndo About Mu Torere...


  
ExitShow Colour Legend  
 
  
 Change Computer Colour...  
 Change User Colour...  
 
  
 AI LevelOff 
  
 
  Low 
  Medium 
  High 
  
 
  Custom AI Level... 


Step 7.
On changing the colour in the Document;
void CMuTorereDoc::OnSettingsChangeXxxx()
Create CColorDialog object.

Set dialog flags.
dlg.m_cc.Flags |= CC_FULLOPEN | CC_RGBINIT;
dlg.m_cc.rgbResult = ((CMuTorereApp*)AfxGetApp())->getColourXxxx();

If the colour dialog returns IDOK.
{
Set the game's colours.
Set the application's Xxxx colour.

Update View with colour hint.
}


In the View, the Update View function is as follows;
void CMuTorereView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/)
If lHint equals the Document's colour hint.
{
Set the colours in the CInfoDisplay instance.
}

In all cases, Invalidate the window to re-draw.
In my program I set both the User and the Computer colours at the same time. For efficiency, a different hint from the Document should be used for each colour change.

The addition to the View's Draw function is minor (done after the game is drawn);
If the application's m_Display is true, draw the CInfoDisplay instance.

The CinfoDisplay is set up in the View constructor;
Go to the first element in the CInfoDisplay instance.

Add _T("Computer") and the application's computer colour to the first element.
Add _T("User") and the application's user colour the next element.

No comments: