| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (C) 2006-2009 by Guy Rutenberg * |
|---|
| 3 | * guyrutenberg@gmail.com * |
|---|
| 4 | * * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify * |
|---|
| 6 | * it under the terms of the GNU General Public License as published by * |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
|---|
| 8 | * (at your option) any later version. * |
|---|
| 9 | * * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, * |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 13 | * GNU General Public License for more details. * |
|---|
| 14 | * * |
|---|
| 15 | * You should have received a copy of the GNU General Public License * |
|---|
| 16 | * along with this program; if not, write to the * |
|---|
| 17 | * Free Software Foundation, Inc., * |
|---|
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|---|
| 19 | ***************************************************************************/ |
|---|
| 20 | /**\file MainFrame.h |
|---|
| 21 | *\brief Header file for MainFrame class. |
|---|
| 22 | * |
|---|
| 23 | * This File contains the declaration of the class MainFrame |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #ifndef OPENYAHTZEE_MAIN_FRAME_INC |
|---|
| 28 | #define OPENYAHTZEE_MAIN_FRAME_INC |
|---|
| 29 | #include <memory> |
|---|
| 30 | #include <boost/scoped_ptr.hpp> |
|---|
| 31 | #include "ScoreDice.h" |
|---|
| 32 | #include "configuration.h" |
|---|
| 33 | #include "statistics.h" |
|---|
| 34 | |
|---|
| 35 | namespace main_frame { |
|---|
| 36 | |
|---|
| 37 | /// MainFrame class - the main window |
|---|
| 38 | /** |
|---|
| 39 | The Main Frame class is a derieved class from wxFrame which is responsible to |
|---|
| 40 | the main window of the application. This class also hold all the functions |
|---|
| 41 | that process the dice and handles the gameplay. This function are called as |
|---|
| 42 | event handlers. |
|---|
| 43 | */ |
|---|
| 44 | class MainFrame : public wxFrame |
|---|
| 45 | { |
|---|
| 46 | public: |
|---|
| 47 | // Constructor |
|---|
| 48 | MainFrame(const wxString& title, const wxSize& size, long style); |
|---|
| 49 | ~MainFrame(); |
|---|
| 50 | |
|---|
| 51 | // Event handlers |
|---|
| 52 | void OnQuit(wxCommandEvent& event); |
|---|
| 53 | void OnAbout(wxCommandEvent& event); |
|---|
| 54 | void OnNewGame (wxCommandEvent& event); |
|---|
| 55 | void OnUndo (wxCommandEvent& event); |
|---|
| 56 | void OnShowHighscore (wxCommandEvent& event); |
|---|
| 57 | void OnStatistics (wxCommandEvent& event); |
|---|
| 58 | void OnSettings (wxCommandEvent& event); |
|---|
| 59 | void OnSendComment (wxCommandEvent& event); |
|---|
| 60 | void OnHelpMenuLink (wxCommandEvent& event); |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * Prevent accidental roll of the dice by double clicking the button. |
|---|
| 64 | * \param event The event that was send to the ::OnRollButton() |
|---|
| 65 | */ |
|---|
| 66 | void DoubleRollLock(wxCommandEvent& event); |
|---|
| 67 | |
|---|
| 68 | void OnUpperButtons (wxCommandEvent& event); |
|---|
| 69 | void On3ofakindButton (wxCommandEvent& event); |
|---|
| 70 | void On4ofakindButton (wxCommandEvent& event); |
|---|
| 71 | void OnFullHouseButton (wxCommandEvent& event); |
|---|
| 72 | void OnSmallSequenceButton (wxCommandEvent& event); |
|---|
| 73 | void OnLargeSequenceButton (wxCommandEvent& event); |
|---|
| 74 | void OnYahtzeeButton (wxCommandEvent& event); |
|---|
| 75 | void OnChanceButton (wxCommandEvent& event); |
|---|
| 76 | void OnDiceClick (wxCommandEvent& event); |
|---|
| 77 | void OnKeepClick (wxCommandEvent& event); |
|---|
| 78 | |
|---|
| 79 | void OnScoreMouseEnter (wxMouseEvent& event); |
|---|
| 80 | void OnScoreMouseLeave (wxMouseEvent& event); |
|---|
| 81 | |
|---|
| 82 | bool IsValidDice(); |
|---|
| 83 | |
|---|
| 84 | ScoreDice m_score_dice; |
|---|
| 85 | |
|---|
| 86 | boost::scoped_ptr<configuration::Configuration> m_config; |
|---|
| 87 | boost::scoped_ptr<statistics::Statistics> m_stats; |
|---|
| 88 | |
|---|
| 89 | private: |
|---|
| 90 | void ClearDiceHash(); |
|---|
| 91 | void ResetRolls(); |
|---|
| 92 | void YahtzeeBonus(); |
|---|
| 93 | bool YahtzeeJoker(); |
|---|
| 94 | void EndofGame(); |
|---|
| 95 | void HighScoreHandler(int score); |
|---|
| 96 | inline void EnableUndo(int id); |
|---|
| 97 | void PostScore(int id); |
|---|
| 98 | void CalculateSubTotal(); |
|---|
| 99 | void Relayout(); |
|---|
| 100 | void AddMenus(); |
|---|
| 101 | void ConnectEventTable(); |
|---|
| 102 | void AddControlsAndLayout(); |
|---|
| 103 | /** |
|---|
| 104 | * Check if a click on a score button is valid or should |
|---|
| 105 | * be ignored. |
|---|
| 106 | * \returns true if the click is valid and should be scored. |
|---|
| 107 | */ |
|---|
| 108 | bool IsValidClick(); |
|---|
| 109 | |
|---|
| 110 | void OnRollButton (); |
|---|
| 111 | |
|---|
| 112 | wxStaticBoxSizer *uppersection, *lowersection; |
|---|
| 113 | wxBoxSizer *sectionsSizer; |
|---|
| 114 | |
|---|
| 115 | //pointers to hold bitmap data for the dices |
|---|
| 116 | wxBitmap *bitmap_dice[6]; |
|---|
| 117 | |
|---|
| 118 | short int m_rolls; //holds how many rolls left |
|---|
| 119 | short int m_numofplaysleft; //holds how many times the user got to score untill the end of the game |
|---|
| 120 | bool m_yahtzee; |
|---|
| 121 | bool m_yahtzeebonus; //tells the undo if there is also an yahtzee bonus to undo |
|---|
| 122 | |
|---|
| 123 | short int m_lastmove; //stores the ID of the last button pressed. |
|---|
| 124 | short int m_rollsundo; //holds the number of remaining rolls for use with the undo option |
|---|
| 125 | |
|---|
| 126 | class MainFrameEvtHandler *m_evt_handler; |
|---|
| 127 | }; |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * This class handles events for windows in MainFrame where it hasn't been |
|---|
| 131 | * possible to use the regular event handler. |
|---|
| 132 | */ |
|---|
| 133 | class MainFrameEvtHandler : public wxEvtHandler |
|---|
| 134 | { |
|---|
| 135 | public: |
|---|
| 136 | MainFrameEvtHandler(MainFrame *main_frame) { m_main_frame = main_frame;} |
|---|
| 137 | void OnScoreMouseEnter (wxMouseEvent& event); |
|---|
| 138 | void OnScoreMouseLeave (wxMouseEvent& event); |
|---|
| 139 | private: |
|---|
| 140 | MainFrame *m_main_frame; |
|---|
| 141 | |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | enum { |
|---|
| 145 | ID_PANEL, |
|---|
| 146 | ID_SHOWHIGHSCORE, |
|---|
| 147 | ID_STATISTICS, |
|---|
| 148 | ID_SETTINGS, |
|---|
| 149 | ID_THEMES, |
|---|
| 150 | ID_HOWTOPLAY, |
|---|
| 151 | ID_FAQ, |
|---|
| 152 | ID_SENDCOMMENT, |
|---|
| 153 | |
|---|
| 154 | ID_ACES, |
|---|
| 155 | ID_TWOS, |
|---|
| 156 | ID_THREES, |
|---|
| 157 | ID_FOURS, |
|---|
| 158 | ID_FIVES, |
|---|
| 159 | ID_SIXES, |
|---|
| 160 | ID_THREEOFAKIND, |
|---|
| 161 | ID_FOUROFAKIND, |
|---|
| 162 | ID_FULLHOUSE, |
|---|
| 163 | ID_SMALLSEQUENCE, |
|---|
| 164 | ID_LARGESEQUENCE, |
|---|
| 165 | ID_YAHTZEE, |
|---|
| 166 | ID_CHANCE, |
|---|
| 167 | |
|---|
| 168 | ID_ACESTEXT, |
|---|
| 169 | ID_TWOSTEXT, |
|---|
| 170 | ID_THREESTEXT, |
|---|
| 171 | ID_FOURSTEXT, |
|---|
| 172 | ID_FIVESTEXT, |
|---|
| 173 | ID_SIXESTEXT, |
|---|
| 174 | ID_THREEOFAKINDTEXT, |
|---|
| 175 | ID_FOUROFAKINDTEXT, |
|---|
| 176 | ID_FULLHOUSETEXT, |
|---|
| 177 | ID_SMALLSEQUENCETEXT, |
|---|
| 178 | ID_LARGESEQUENCETEXT, |
|---|
| 179 | ID_YAHTZEETEXT, |
|---|
| 180 | ID_CHANCETEXT, |
|---|
| 181 | ID_YAHTZEEBONUSTEXT, |
|---|
| 182 | |
|---|
| 183 | ID_UPPERSECTIONTOTAL, |
|---|
| 184 | ID_BONUS, |
|---|
| 185 | ID_UPPERTOTAL, |
|---|
| 186 | ID_LOWERTOTAL, |
|---|
| 187 | ID_GRANDTOTAL, |
|---|
| 188 | |
|---|
| 189 | ID_ROLL, |
|---|
| 190 | ID_DICE1, |
|---|
| 191 | ID_DICE2, |
|---|
| 192 | ID_DICE3, |
|---|
| 193 | ID_DICE4, |
|---|
| 194 | ID_DICE5, |
|---|
| 195 | |
|---|
| 196 | ID_DICE1KEEP, |
|---|
| 197 | ID_DICE2KEEP, |
|---|
| 198 | ID_DICE3KEEP, |
|---|
| 199 | ID_DICE4KEEP, |
|---|
| 200 | ID_DICE5KEEP, |
|---|
| 201 | }; |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | #endif |
|---|