///////////////////////////////////////////////////////////////////////////// // Name: player.cpp // tag: display a player on the table // Author: David Roundy // Modified by: // Created: 21/07/97 // RCS-ID: $Id: player.cpp,v 1.5 2002/02/21 13:29:08 droundy Exp $ // Copyright: (c) 2001,2002 David Roundy // Licence: GPL /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes . #include #ifndef WX_PRECOMP #include #include #include #endif #include "colors.h" #include "player.h" #include "game.h" #include "globals.h" #include "blurbwin.h" #include "card.h" #include "debug.h" #include "speech.h" #include "prefmacros.h" //------------------------------------------------------------// // The Player class: a players name (and maybe later picture) // //------------------------------------------------------------// BEGIN_EVENT_TABLE(Player, wxPanel) EVT_SET_FOCUS(Player::SetTalkFocus) EVT_BUTTON(SIT_BUTTON_ID,Player::Sit) EVT_BUTTON(SUBSTITUTE_BUTTON_ID,Player::Substitute) EVT_BUTTON(PLAYERPIC_BUTTON_ID,Player::ShowInfo) END_EVENT_TABLE() Player::Player(wxWindow* parent, Seat seat, int x, int y, int w, int h) : wxPanel(parent, -1, wxPoint(x, y), wxSize(w, h)) { m_playerpic_button = new wxBitmapButton(this, PLAYERPIC_BUTTON_ID, GetPlayerBitmap("")); m_button = new wxButton(this,SIT_BUTTON_ID, "Sit " + Seat2String(seat), wxPoint(-1,-1)); // buttons should be made before doing the background color, so they'll // have a nice gray background. wxColor oldback = GetBackgroundColour(); SetBackgroundColour(aBridgeBackgroundColour()); SetForegroundColour(aBridgeTextColour()); wxFont oldfont = GetFont(); SetFont(aBridgeFont()); if (w >= h) { m_horizontal = 1; } else { m_horizontal = 0; } wxLayoutConstraints *c; m_name = ""; // m_name_label = new wxStaticText(this, -1, m_name,wxPoint(0,0)); m_name_label = new wxStaticText(this, -1, m_name,wxPoint(-1,-1)); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 5); if (m_horizontal) { c->right.LeftOf(m_button, 5); } else { c->right.SameAs(this, wxRight, 5); } c->top.SameAs(this, wxTop, 3); c->height.AsIs(); // c->width.AsIs(); m_name_label->SetConstraints(c); // m_reminder = new wxStaticText(this, -1, "",wxPoint(5,15)); m_reminder = new wxStaticText(this, -1, "",wxPoint(-1,-1)); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); if (m_horizontal) { c->right.LeftOf(m_button, 5); } else { c->right.SameAs(this, wxRight, 5); } c->top.Below(m_name_label, 3); c->height.AsIs(); // c->width.AsIs(); m_reminder->SetConstraints(c); // m_mybid = new wxStaticText(this, -1, "",wxPoint(10,30)); m_mybid = new wxStaticText(this, -1, "hello world",wxPoint(-1,-1)); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); // c->right.LeftOf(m_playerpic_button, 10); c->width.AsIs(); c->top.Below(m_reminder, 3); c->height.AsIs(); m_mybid->SetConstraints(c); m_mybid->Show(false); wxBitmap bid_bits(16,16); wxMemoryDC tmpdc; tmpdc.SelectObject(bid_bits); tmpdc.SetBackground( aBridgeBackgroundBrush() ); tmpdc.Clear(); //DrawSuit(tmpdc, m_bid, 0,0,16,16); m_mybid_bits = new wxStaticBitmap(this, -1, bid_bits,wxPoint(-1,-1)); c = new wxLayoutConstraints; c->left.RightOf(m_mybid, 5); // c->right.LeftOf(m_playerpic_button, 10); c->width.AsIs(); c->centreY.SameAs(m_mybid, wxCentreY, 0); c->height.AsIs(); m_mybid_bits->SetConstraints(c); m_mybid_bits->Show(false); // m_button constraints c = new wxLayoutConstraints; c->width.AsIs(); c->height.AsIs(); if (m_horizontal) { c->right.LeftOf(m_playerpic_button, 5); // c->top.Below(m_mybid, 5); c->top.SameAs(this, wxTop, 5); } else { c->centreX.SameAs(this, wxCentreX, 0); //c->top.SameAs(this, wxTop, 5); c->top.Below(m_mybid, 5); } m_button->SetConstraints(c); SetBackgroundColour(oldback); SetFont(oldfont); m_substitute_button = new wxButton(this,SUBSTITUTE_BUTTON_ID, "Sit temporarily", wxPoint(-1,-1)); if (m_substitute_button->GetRect().GetWidth() > w) { m_substitute_button->SetLabel("Sit\nTemporarily"); wxSize mysize = m_substitute_button->GetBestSize(); if (mysize.GetWidth() > w) mysize.SetWidth(w); #ifdef __WXMAC__ mysize.SetHeight((int) (mysize.GetHeight()*1.5)); #endif m_substitute_button->SetSize(mysize); } SetFont(aBridgeFont()); SetBackgroundColour(aBridgeBackgroundColour()); // m_substitute_button constraints c = new wxLayoutConstraints; c->width.AsIs(); c->height.AsIs(); c->top.Below(m_button, 5); if (m_horizontal) { c->right.LeftOf(m_playerpic_button, 5); } else { c->centreX.SameAs(m_button, wxCentreX, 0); } m_substitute_button->SetConstraints(c); // m_playerpic_button constraints c = new wxLayoutConstraints; c->width.AsIs(); c->height.AsIs(); if (m_horizontal) { c->right.SameAs(this, wxRight, 0); c->top.SameAs(this, wxTop, 1); } else { c->right.SameAs(this, wxRight, 10); //c->top.SameAs(this, wxTop, 5); c->top.Below(m_button, 5); } m_playerpic_button->SetConstraints(c); m_playerpic_button->Show(false); m_seat = seat; m_my_turn = FALSE; m_played_by_me = false; Layout(); SetAutoLayout( TRUE ); } void Player::YourTurn(bool val) { m_my_turn = val; if (m_my_turn) { m_reminder->SetLabel("It's your turn!"); } else { m_reminder->SetLabel(""); } } Player::~Player() { if (m_button) delete m_button; } void Player::HandleSit(const wxString& who, bool substitute) { m_name = who; m_name_label->SetLabel(who); wxBitmap the_bits = GetPlayerBitmap(who); m_playerpic_button->SetBitmapLabel(the_bits); m_playerpic_button->SetBitmapSelected(the_bits); m_playerpic_button->SetBitmapFocus(the_bits); m_playerpic_button->Show(true); if (who.IsSameAs(player_name())) { m_button->SetLabel("Stand"); m_substitute_button->Show(false); m_played_by_me = true; } else { if (substitute) { // these should normally be redundant, but I can imagine race // conditions in which they'd be relevant. m_button->SetLabel("Sit"); m_button->Show(true); } else { m_button->Show(false); } m_substitute_button->Show(false); m_played_by_me = false; } } void Player::HandleGetUp() { m_button->SetLabel("Sit " + Seat2String(m_seat)); m_button->Show(true); m_substitute_button->Show(true); m_name = ""; m_name_label->SetLabel(""); m_playerpic_button->Show(false); m_played_by_me = false; } void Player::Sit(wxCommandEvent& evt) { if (m_played_by_me) { GameEvent my_event( this, "STAND", Seat2String(m_seat)); if ( GetParent()->GetEventHandler()->ProcessEvent( my_event ) == FALSE ) wxLogWarning( "Player: Could not process stand event!" ); } else { GameEvent my_event( this, "SIT", Seat2String(m_seat)); if ( GetParent()->GetEventHandler()->ProcessEvent( my_event ) == FALSE ) wxLogWarning( "Player: Could not process sitevent!" ); } } void Player::Substitute(wxCommandEvent& evt) { GameEvent my_event( this, "SUBSTITUTE", Seat2String(m_seat)); if ( GetParent()->GetEventHandler()->ProcessEvent( my_event ) == FALSE ) wxLogWarning( "Player: Could not process sub event!" ); } void Player::ShowInfo(wxCommandEvent& evt) { BlurbWin *my_blurb = new BlurbWin(this, m_name, GetPlayerBlurb(m_name)); my_blurb->Show(true); } void Player::BlankBid() { m_mybid->SetLabel(""); m_mybid_bits->Show(false); } void Player::SayBid(const wxString &bid) { m_mybid->SetForegroundColour(*wxBLACK); m_mybid_bits->Show(false); wxString pronounce = bid; if (bid.Matches("Pass") || bid.Matches("Double") || bid.Matches("Redouble")) { m_mybid->SetLabel(bid); } else { DebugMsg("About to find out suit in Player::SayBid..."); Suit mysuit = String2Suit(bid.AfterFirst(' ')); if (mysuit == diamonds || mysuit == hearts) { m_mybid->SetForegroundColour(*wxRED); } if (mysuit != notrump) { DebugMsg("About to find out number in Player::SayBid..."); m_mybid->SetLabel(bid.BeforeFirst(' ')); DebugMsg("About to get bitmap in Player::SayBid..."); wxBitmap bid_bits(16,16,-1); wxMemoryDC tmpdc; tmpdc.SelectObject(bid_bits); tmpdc.SetBackground( aBridgeBackgroundBrush() ); tmpdc.Clear(); DrawSuit(tmpdc, mysuit, 0, 0,0,16,16); m_mybid_bits->SetBitmap(bid_bits); Layout(); m_mybid_bits->Show(true); } else { m_mybid->SetLabel(bid); } pronounce = bid.BeforeFirst(' ') + " " + Suit2String(mysuit); } if (wxConfig::Get()->Read("/Speech/Bids", 1)) { speak_string(pronounce); } Layout(); m_mybid->Show(true); } void Player::SetTalkFocus(wxFocusEvent& evt) { GetParent()->GetEventHandler()->ProcessEvent(evt); }