Changeset 124


Ignore:
Timestamp:
30/11/07 17:37:49 (7 years ago)
Author:
guyru
Message:

finished the score hinting logic

Location:
trunk/OpenYahtzee/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/OpenYahtzee/src/MainFrame.cpp

    r123 r124  
    7070#define OY_VERSION "1.8.0" 
    7171 
    72 DEFINE_EVENT_TYPE(wxEVT_ENABLE_ROLL) /*just to satisfy kdevelop*/; 
    73 const wxEventType myEVT_FRAME_LOADED = wxNewEventType(); 
    74  
     72const wxEventType wxEVT_ENABLE_ROLL = wxNewEventType(); 
    7573 
    7674MainFrame::MainFrame(const wxString& title, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE) 
     
    292290        Connect(ID_DICE1KEEP,ID_DICE5KEEP, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (MainFrame::OnKeepClick)); 
    293291        //END connecting the scoreboard buttons to the event 
    294          
    295         for (int i = ID_ACES; i<=ID_CHANCE; i++) 
     292 
     293        /* The following code connects the on wxEVT_ENTER_WINDOW and  
     294         * wxEVT_LEAVE_WINDOW events to the score buttons to handle the score 
     295         * hints. For some unknown technical problem we have to directly connect 
     296         * the events, otherwise the wxEVT_LEAVE_WINDOW doesn't get generated. 
     297         * We have to use event handler other than MainFrame's as the regular 
     298         * event handler leads to segmantation fault. 
     299         */ 
     300        wxButton *temp; 
     301        for (int i = ID_ACES; i<=ID_CHANCE; i++) { 
     302                temp = ((wxButton *)FindWindow(i)); 
    296303                ((wxWindow *)FindWindow(i))->PushEventHandler(m_evt_handler); 
    297         m_evt_handler->Connect(ID_ACES, ID_CHANCE, wxEVT_ENTER_WINDOW, 
    298                 wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseEnter)); 
    299         m_evt_handler->Connect(ID_ACES, ID_CHANCE, wxEVT_LEAVE_WINDOW, 
    300                 wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseLeave)); 
     304                ((wxWindow *)FindWindow(i))->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseLeave), temp, m_evt_handler); 
     305                ((wxWindow *)FindWindow(i))->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseEnter), temp, m_evt_handler); 
     306        } 
    301307 
    302308        /*** End of Event Table ***/ 
     
    621627                out.Printf(wxT("%i"),temp); 
    622628                ((wxTextCtrl*) FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT))->SetValue(out); 
     629                ((wxTextCtrl*) FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT))->SetBackgroundColour(*wxWHITE); 
    623630                 
    624631                PostScore(event.GetId()); 
     
    643650        out.Printf(wxT("%i"),m_score_dice.ThreeOfAKind()); 
    644651        ((wxTextCtrl*) FindWindow(ID_THREEOFAKINDTEXT))->SetValue(out); 
     652        ((wxTextCtrl*) FindWindow(ID_THREEOFAKINDTEXT))->SetBackgroundColour(*wxWHITE); 
    645653         
    646654        PostScore(event.GetId()); 
     
    662670        out.Printf(wxT("%i"),m_score_dice.FourOfAKind()); 
    663671        ((wxTextCtrl*) FindWindow(ID_FOUROFAKINDTEXT))->SetValue(out); 
     672        ((wxTextCtrl*) FindWindow(ID_FOUROFAKINDTEXT))->SetBackgroundColour(*wxWHITE); 
    664673         
    665674        PostScore(event.GetId()); 
     
    682691        out.Printf(wxT("%i"), m_score_dice.FullHouse()); 
    683692        ((wxTextCtrl*) FindWindow(ID_FULLHOUSETEXT))->SetValue(out); 
     693        ((wxTextCtrl*) FindWindow(ID_FULLHOUSETEXT))->SetBackgroundColour(*wxWHITE); 
    684694         
    685695        PostScore(event.GetId()); 
     
    703713        out.Printf(wxT("%i"), m_score_dice.SmallSequence()); 
    704714        ((wxTextCtrl*) FindWindow(ID_SMALLSEQUENCETEXT))->SetValue(out); 
     715        ((wxTextCtrl*) FindWindow(ID_SMALLSEQUENCETEXT))->SetBackgroundColour(*wxWHITE); 
    705716         
    706717        PostScore(event.GetId()); 
     
    724735        out.Printf(wxT("%i"), m_score_dice.LargeSequence()); 
    725736        ((wxTextCtrl*) FindWindow(ID_LARGESEQUENCETEXT))->SetValue(out); 
     737        ((wxTextCtrl*) FindWindow(ID_LARGESEQUENCETEXT))->SetBackgroundColour(*wxWHITE); 
    726738         
    727739        PostScore(event.GetId()); 
     
    744756        out.Printf(wxT("%i"), m_score_dice.Yahtzee()); 
    745757        ((wxTextCtrl*) FindWindow(ID_YAHTZEETEXT))->SetValue(out); 
     758        ((wxTextCtrl*) FindWindow(ID_YAHTZEETEXT))->SetBackgroundColour(*wxWHITE); 
    746759 
    747760        PostScore(event.GetId()); 
     
    761774                out.Printf(wxT("%i"),m_score_dice.Chance()); 
    762775                ((wxTextCtrl*) FindWindow(ID_CHANCETEXT))->SetValue(out); 
     776                ((wxTextCtrl*) FindWindow(ID_CHANCETEXT))->SetBackgroundColour(*wxWHITE); 
    763777                 
    764778                PostScore(event.GetId()); 
     
    11971211 
    11981212/** 
     1213 * Check whether the dice should be rolled or if the user already rolled them. 
     1214 * \return true if the dice are valid (rolled). 
     1215 */ 
     1216bool MainFrame::IsValidDice() 
     1217{ 
     1218        if ( m_rolls < 3 ) 
     1219                return true; 
     1220        return false; 
     1221} 
     1222 
     1223/** 
    11991224 * 
    12001225 */ 
    12011226void MainFrameEvtHandler::OnScoreMouseEnter (wxMouseEvent& event) 
    12021227{ 
     1228        int id; 
    12031229        wxTextCtrl *text_control; 
    12041230        wxString out; 
    1205         text_control = ((wxTextCtrl*)m_main_frame->FindWindow(event.GetId()-ID_ACES+ID_ACESTEXT)); 
    1206         switch (event.GetId()) { 
     1231        if (! m_main_frame->IsValidDice()){ 
     1232                event.Skip(); 
     1233                return; 
     1234        } 
     1235         
     1236        id = ((wxWindow *)event.GetEventObject())->GetId(); 
     1237        text_control = ((wxTextCtrl*)m_main_frame->FindWindow(id-ID_ACES+ID_ACESTEXT)); 
     1238        switch (id) { 
    12071239        case ID_ACES: 
    12081240                out.Printf(wxT("%i"), m_main_frame->m_score_dice.Aces()); 
     
    12561288void MainFrameEvtHandler::OnScoreMouseLeave (wxMouseEvent& event) 
    12571289{ 
     1290        //we dont have the id of the control that generated the event 
    12581291        wxTextCtrl *text_control; 
    1259         text_control = ((wxTextCtrl*)m_main_frame->FindWindow(event.GetId()-ID_ACES+ID_ACESTEXT)); 
    1260         text_control->SetDefaultStyle(wxTextAttr(*wxBLACK)); 
    1261         text_control->Clear(); 
    1262 } 
     1292         
     1293        if (! m_main_frame->IsValidDice()){ 
     1294                event.Skip(); 
     1295                return; 
     1296        } 
     1297 
     1298        for (int i = ID_ACESTEXT; i<=ID_CHANCETEXT; i++) { 
     1299                text_control = (wxTextCtrl *)m_main_frame->FindWindow(i); 
     1300                if (text_control->GetBackgroundColour()==wxColour(239,239,239)){ 
     1301                        text_control->Clear(); 
     1302                        text_control->SetBackgroundColour(*wxWHITE); 
     1303                } 
     1304        } 
     1305 
     1306        event.Skip(); //allow default proccesing 
     1307} 
  • trunk/OpenYahtzee/src/MainFrame.h

    r123 r124  
    3030#ifndef MAINFRAME_INC 
    3131#define MAINFRAME_INC 
    32  
    33 DECLARE_EVENT_TYPE(wxEVT_ENABLE_ROLL, -1) /*just to satisfy kdevelop*/; 
    3432 
    3533/// MainFrame class - the main window 
     
    7068        void OnScoreMouseEnter (wxMouseEvent& event); 
    7169        void OnScoreMouseLeave (wxMouseEvent& event); 
    72          
     70 
     71        bool IsValidDice(); 
    7372 
    7473        ScoreDice m_score_dice; 
Note: See TracChangeset for help on using the changeset viewer.