void Menu::ChangeRoom(const sf::Event& ev){ switch (mCurrentRoom){ case MainMenu:{ //Amount of buttons in main menu const int amountOfButtons = 4; for (int i = 0; i < amountOfButtons; i++){ switch (i){ case 0:{ if (mButtons[i]->IsPressed(ev)){ mCurrentRoom = Run; DisableButtons(); } break; } case 1:{ if (mButtons[i]->IsPressed(ev)){ mCurrentRoom = Library; DisableButtons(); } break; } case 2:{ if (mButtons[i]->IsPressed(ev)){ mCurrentRoom = About; DisableButtons(); } break; } case 3:{ if (mButtons[i]->IsPressed(ev)){ mCurrentRoom = Exit; DisableButtons(); } break; } } } break; } case Library:{ if (mButtons[4]->IsPressed(ev)){ mCurrentRoom = MainMenu; DisableButtons(); } break; } case About:{ if (mButtons[4]->IsPressed(ev)){ mCurrentRoom = MainMenu; DisableButtons(); } break; } } };
double SubSectionMenu::WillTransitionOff() { //While the transition is happening, disable the buttons, this prevents them from being pressed DisableButtons(); //Fade out the partially transparent black overlay m_Overlay->SetAlpha(0.0f, SUBSECTION_MENU_TRANSITION_OFF_DURATION); //Do a scale animation for all the buttons const unsigned int buttonCount = WORLD_NUMBER_OF_SUBSECTIONS.x * WORLD_NUMBER_OF_SUBSECTIONS.y; for(unsigned int i = 0; i < buttonCount; i++) { m_Buttons[i]->SetLocalScale(0.0f, 0.0f, SUBSECTION_MENU_BUTTON_SCALE_DURATION, Back::In); } //Return the length of time this off-transition will take return SUBSECTION_MENU_TRANSITION_OFF_DURATION; }
void YahtZFrame::StartNewGame() { Game.Reset(); BonusLabel->SetLabel(wxT("0")); DisableButtons(); ResetLabels(); for (int i = 0; i < 13; i++) { ButtonsEnabled[i] = true; } RollButton->Enable(); RollButton->SetLabel(wxString::Format(wxT("ROLL (%i)"), Game.GetRollCount())); Dice1->SetBitmap(wxBitmap()); Dice2->SetBitmap(wxBitmap()); Dice3->SetBitmap(wxBitmap()); Dice4->SetBitmap(wxBitmap()); Dice5->SetBitmap(wxBitmap()); }
void SubSectionMenu::WillTransitionOn() { //While the transition is happening, disable the buttons, this prevents them from being pressed DisableButtons(); //Fade in the partially transparent black overlay m_Overlay->SetAlpha(0.5f, SUBSECTION_MENU_TRANSITION_ON_DURATION); //Do a scale animation for all the buttons const unsigned int buttonCount = WORLD_NUMBER_OF_SUBSECTIONS.x * WORLD_NUMBER_OF_SUBSECTIONS.y; for(unsigned int i = 0; i < buttonCount; i++) { m_Buttons[i]->SetLocalScale(0.0f, 0.0f); m_Buttons[i]->SetLocalScale(1.0f, 1.0f, SUBSECTION_MENU_BUTTON_SCALE_DURATION, Back::Out); } //Setup a delay method to re-enable the button DelaySceneMethod(&SubSectionMenu::EnableButtons, SUBSECTION_MENU_TRANSITION_ON_DURATION); }
void YahtZFrame::EndRound() { if(Game.isGameOver()) { RollButton->Disable(); wxMessageBox( wxString::Format(wxT("Your Score: %i"), Game.GetScore()), wxT("Game Over"), wxOK); } else { Game.EndRound(); RollButton->SetLabel(wxString::Format(wxT("ROLL (%i)"),Game.GetRollCount())); RollButton->Enable(); DisableButtons(); for(int i = 0; i < 5; i++) { DiceEnabled[i] = true; Game.EnableDice(i+1); } } StatusBar->SetLabel(wxString::Format(wxT("Score: %i"),Game.GetScore())); }
YahtZFrame::YahtZFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) { for(int i = 0; i < 5; i++) DiceEnabled[i] = true; for (int i = 0; i < 13; i++) ButtonsEnabled[i] = true; this->SetSizeHints( wxDefaultSize, wxDefaultSize ); wxFlexGridSizer* MainSizer; MainSizer = new wxFlexGridSizer( 0, 1, 0, 0 ); MainSizer->AddGrowableCol( 0 ); MainSizer->AddGrowableRow( 0 ); MainSizer->SetFlexibleDirection( wxBOTH ); MainSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); TopPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxFlexGridSizer* DiceSizer; DiceSizer = new wxFlexGridSizer( 1, 6, 0, 0 ); DiceSizer->SetFlexibleDirection( wxBOTH ); DiceSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); Dice1 = new wxStaticBitmap( TopPanel, wxID_ANY, wxBitmap(), wxDefaultPosition, wxSize( 64,64 ), 0 ); DiceSizer->Add( Dice1, 0, wxALL, 5 ); Dice2 = new wxStaticBitmap( TopPanel, wxID_ANY, wxBitmap(), wxDefaultPosition, wxSize( 64,64 ), 0 ); DiceSizer->Add( Dice2, 0, wxALL, 5 ); Dice3 = new wxStaticBitmap( TopPanel, wxID_ANY, wxBitmap(), wxDefaultPosition, wxSize( 64,64 ), 0 ); DiceSizer->Add( Dice3, 0, wxALL, 5 ); Dice4 = new wxStaticBitmap( TopPanel, wxID_ANY, wxBitmap(), wxDefaultPosition, wxSize( 64,64 ), 0 ); DiceSizer->Add( Dice4, 0, wxALL, 5 ); Dice5 = new wxStaticBitmap( TopPanel, wxID_ANY, wxBitmap(), wxDefaultPosition, wxSize( 64,64 ), 0 ); DiceSizer->Add( Dice5, 0, wxALL, 5 ); RollButton = new wxButton( TopPanel, wxID_ANY, wxString::Format(wxT("ROLL (%i)"),Game.GetRollCount()), wxDefaultPosition, wxDefaultSize, wxNO_BORDER ); DiceSizer->Add( RollButton, 0, wxALL|wxEXPAND, 5 ); TopPanel->SetSizer( DiceSizer ); TopPanel->Layout(); DiceSizer->Fit( TopPanel ); MainSizer->Add( TopPanel, 1, wxEXPAND, 5 ); BottomPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxFlexGridSizer* ScoreSizer; ScoreSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); ScoreSizer->AddGrowableCol( 0 ); ScoreSizer->AddGrowableCol( 1 ); ScoreSizer->SetFlexibleDirection( wxBOTH ); ScoreSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); wxFlexGridSizer* FirstScoreSizer; FirstScoreSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); FirstScoreSizer->AddGrowableCol( 1 ); FirstScoreSizer->SetFlexibleDirection( wxBOTH ); FirstScoreSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); OneButton = new wxButton( BottomPanel, wxID_ANY, wxT("One's"), wxDefaultPosition, wxDefaultSize, 0 ); FirstScoreSizer->Add( OneButton, 0, wxALL, 5 ); OneLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); OneLabel->Wrap( -1 ); OneLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( OneLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); TwoButton = new wxButton( BottomPanel, wxID_ANY, wxT("Two's"), wxDefaultPosition, wxDefaultSize, 0 ); FirstScoreSizer->Add( TwoButton, 0, wxALL, 5 ); TwoLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); TwoLabel->Wrap( -1 ); TwoLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( TwoLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); ThreeButton = new wxButton( BottomPanel, wxID_ANY, wxT("Three's"), wxDefaultPosition, wxDefaultSize, 0 ); FirstScoreSizer->Add( ThreeButton, 0, wxALL, 5 ); ThreeLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); ThreeLabel->Wrap( -1 ); ThreeLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( ThreeLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); FourButton = new wxButton( BottomPanel, wxID_ANY, wxT("Four's"), wxDefaultPosition, wxDefaultSize, 0 ); FirstScoreSizer->Add( FourButton, 0, wxALL, 5 ); FourLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); FourLabel->Wrap( -1 ); FourLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( FourLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); FiveButton = new wxButton( BottomPanel, wxID_ANY, wxT("Five's"), wxDefaultPosition, wxDefaultSize, 0 ); FirstScoreSizer->Add( FiveButton, 0, wxALL, 5 ); FiveLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); FiveLabel->Wrap( -1 ); FiveLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( FiveLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); SixButton = new wxButton( BottomPanel, wxID_ANY, wxT("Six's"), wxDefaultPosition, wxDefaultSize, 0 ); FirstScoreSizer->Add( SixButton, 0, wxALL, 5 ); SixLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); SixLabel->Wrap( -1 ); SixLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( SixLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); BonusTxt = new wxStaticText( BottomPanel, wxID_ANY, wxT("Bonus:"), wxDefaultPosition, wxDefaultSize, 0 ); BonusTxt->Wrap( -1 ); BonusTxt->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) ); FirstScoreSizer->Add( BonusTxt, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 10 ); BonusLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("0"), wxDefaultPosition, wxDefaultSize, 0 ); BonusLabel->Wrap( -1 ); BonusLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); FirstScoreSizer->Add( BonusLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 10 ); ScoreSizer->Add( FirstScoreSizer, 1, wxEXPAND, 5 ); wxFlexGridSizer* SecScoreSizer; SecScoreSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); SecScoreSizer->AddGrowableCol( 1 ); SecScoreSizer->SetFlexibleDirection( wxBOTH ); SecScoreSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); ThreeKindButton = new wxButton( BottomPanel, wxID_ANY, wxT("3 of a Kind"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( ThreeKindButton, 0, wxALL, 5 ); ThreeKindLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); ThreeKindLabel->Wrap( -1 ); ThreeKindLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( ThreeKindLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); FourKindButton = new wxButton( BottomPanel, wxID_ANY, wxT("4 of a Kind"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( FourKindButton, 0, wxALL, 5 ); FourKindLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); FourKindLabel->Wrap( -1 ); FourKindLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( FourKindLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); SmStraightButton = new wxButton( BottomPanel, wxID_ANY, wxT("Sm Straight"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( SmStraightButton, 0, wxALL, 5 ); SmStraightLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); SmStraightLabel->Wrap( -1 ); SmStraightLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( SmStraightLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); LgStraightButton = new wxButton( BottomPanel, wxID_ANY, wxT("Lg Straight"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( LgStraightButton, 0, wxALL, 5 ); LgStraightLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); LgStraightLabel->Wrap( -1 ); LgStraightLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( LgStraightLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); FullHouseButton = new wxButton( BottomPanel, wxID_ANY, wxT("Full House"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( FullHouseButton, 0, wxALL, 5 ); FullHouseLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); FullHouseLabel->Wrap( -1 ); FullHouseLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( FullHouseLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); ChanceButton = new wxButton( BottomPanel, wxID_ANY, wxT("Chance"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( ChanceButton, 0, wxALL, 5 ); ChanceLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); ChanceLabel->Wrap( -1 ); ChanceLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( ChanceLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); YahtzeeButton = new wxButton( BottomPanel, wxID_ANY, wxT("Yahtzee"), wxDefaultPosition, wxDefaultSize, 0 ); SecScoreSizer->Add( YahtzeeButton, 0, wxALL, 5 ); YahtzeeLabel = new wxStaticText( BottomPanel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0 ); YahtzeeLabel->Wrap( -1 ); YahtzeeLabel->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) ); SecScoreSizer->Add( YahtzeeLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); ScoreSizer->Add( SecScoreSizer, 1, wxEXPAND, 5 ); BottomPanel->SetSizer( ScoreSizer ); BottomPanel->Layout(); ScoreSizer->Fit( BottomPanel ); MainSizer->Add( BottomPanel, 1, wxEXPAND, 5 ); this->SetSizer( MainSizer ); this->Layout(); MenuBar = new wxMenuBar( 0 ); FileMenu = new wxMenu(); wxMenuItem* NewGameItem; NewGameItem = new wxMenuItem( FileMenu, wxID_ANY, wxString( wxT("&New Game") ) , wxEmptyString, wxITEM_NORMAL ); FileMenu->Append( NewGameItem ); wxMenuItem* HighScoresItem; HighScoresItem = new wxMenuItem( FileMenu, wxID_ANY, wxString( wxT("&High Scores") ) , wxEmptyString, wxITEM_NORMAL ); FileMenu->Append( HighScoresItem ); FileMenu->AppendSeparator(); wxMenuItem* ExitItem; ExitItem = new wxMenuItem( FileMenu, wxID_ANY, wxString( wxT("&Exit") ) , wxEmptyString, wxITEM_NORMAL ); FileMenu->Append( ExitItem ); MenuBar->Append( FileMenu, wxT("&File") ); HelpMenu = new wxMenu(); wxMenuItem* HowToItem; HowToItem = new wxMenuItem( HelpMenu, wxID_ANY, wxString( wxT("How to &Play") ) , wxEmptyString, wxITEM_NORMAL ); HelpMenu->Append( HowToItem ); HelpMenu->AppendSeparator(); wxMenuItem* AboutItem; AboutItem = new wxMenuItem( HelpMenu, wxID_ANY, wxString( wxT("&About") ) , wxEmptyString, wxITEM_NORMAL ); HelpMenu->Append( AboutItem ); MenuBar->Append( HelpMenu, wxT("&Help") ); this->SetMenuBar( MenuBar ); StatusBar = this->CreateStatusBar( 1, 0, wxID_ANY ); this->Centre( wxBOTH ); DisableButtons(); StatusBar->SetLabel(wxT("Welcome to YahtZ! Press the ROLL button to start the game!")); // Connect Events Dice1->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( YahtZFrame::Dice1Click ), NULL, this ); Dice2->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( YahtZFrame::Dice2Click ), NULL, this ); Dice3->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( YahtZFrame::Dice3Click ), NULL, this ); Dice4->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( YahtZFrame::Dice4Click ), NULL, this ); Dice5->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( YahtZFrame::Dice5Click ), NULL, this ); RollButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::RollClick ), NULL, this ); OneButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::OneClick ), NULL, this ); OneButton->Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( YahtZFrame::OneHover ), NULL, this ); OneButton->Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( YahtZFrame::OneOut ), NULL, this ); TwoButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::TwoClick ), NULL, this ); ThreeButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::ThreeClick ), NULL, this ); FourButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::FourClick ), NULL, this ); FiveButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::FiveClick ), NULL, this ); SixButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::SixClick ), NULL, this ); ThreeKindButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::ThreeKindClick ), NULL, this ); FourKindButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::FourKindClick ), NULL, this ); SmStraightButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::SmStraightClick ), NULL, this ); LgStraightButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::LgStraightClick ), NULL, this ); FullHouseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::FullHouseClick ), NULL, this ); ChanceButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::ChanceClick ), NULL, this ); YahtzeeButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( YahtZFrame::YahtzeeClick ), NULL, this ); this->Connect( NewGameItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( YahtZFrame::NewGameClick ) ); this->Connect( HighScoresItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( YahtZFrame::HighScoresClick ) ); this->Connect( ExitItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( YahtZFrame::ExitClick ) ); this->Connect( HowToItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( YahtZFrame::HowToClick ) ); this->Connect( AboutItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( YahtZFrame::AboutClick ) ); }