Changeset 58


Ignore:
Timestamp:
26/01/07 22:18:07 (8 years ago)
Author:
guyru
Message:

calculate subtotal score

Location:
trunk/OpenYahtzee
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/OpenYahtzee/openyahtzee.kdevses

    r57 r58  
    22<!DOCTYPE KDevPrjSession> 
    33<KDevPrjSession> 
    4  <DocsAndViews NumberOfDocuments="17" > 
     4 <DocsAndViews NumberOfDocuments="16" > 
    55  <Doc0 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDB.h" > 
    66   <View0 Type="Source" /> 
     
    1010  </Doc1> 
    1111  <Doc2 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/MainFrame.cpp" > 
    12    <View0 line="121" Type="Source" /> 
     12   <View0 line="407" Type="Source" /> 
    1313  </Doc2> 
    1414  <Doc3 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/ObjectsID.h" > 
    15    <View0 line="30" Type="Source" /> 
     15   <View0 Type="Source" /> 
    1616  </Doc3> 
    1717  <Doc4 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/MainFrame.h" > 
    18    <View0 line="52" Type="Source" /> 
     18   <View0 line="95" Type="Source" /> 
    1919  </Doc4> 
    2020  <Doc5 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/DBwrapper.h" > 
     
    2525  </Doc6> 
    2626  <Doc7 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDialog.cpp" > 
    27    <View0 Type="Source" /> 
     27   <View0 line="93" Type="Source" /> 
    2828  </Doc7> 
    2929  <Doc8 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDB.cpp" > 
     
    3636   <View0 Type="Source" /> 
    3737  </Doc10> 
    38   <Doc11 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/Icon.h" > 
    39    <View0 Type="Source" /> 
     38  <Doc11 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDialog.h" > 
     39   <View0 line="39" Type="Source" /> 
    4040  </Doc11> 
    41   <Doc12 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDialog.h" > 
     41  <Doc12 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.cpp" > 
    4242   <View0 Type="Source" /> 
    4343  </Doc12> 
    44   <Doc13 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.cpp" > 
     44  <Doc13 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/DBwrapper.cpp" > 
    4545   <View0 Type="Source" /> 
    4646  </Doc13> 
    47   <Doc14 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/DBwrapper.cpp" > 
     47  <Doc14 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.h" > 
    4848   <View0 Type="Source" /> 
    4949  </Doc14> 
    50   <Doc15 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.h" > 
    51    <View0 Type="Source" /> 
     50  <Doc15 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/openyahtzee.rc" > 
     51   <View0 line="0" Type="Source" /> 
    5252  </Doc15> 
    53   <Doc16 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/openyahtzee.rc" > 
    54    <View0 line="0" Type="Source" /> 
    55   </Doc16> 
    5653 </DocsAndViews> 
    5754 <pluginList> 
     
    6158  <kdevbookmarks> 
    6259   <bookmarks> 
    63     <bookmark url="/home/guy/workspace/OpenYahztee/src/MainFrame.cpp" > 
    64      <mark line="596" /> 
     60    <bookmark url="/home/guy/workspace/OpenYahtzee/src/MainFrame.cpp" > 
     61     <mark line="108" /> 
    6562    </bookmark> 
    6663   </bookmarks> 
  • trunk/OpenYahtzee/src/MainFrame.cpp

    r57 r58  
    8686                m_animate = true; 
    8787        } 
     88        if (m_settingsdb->GetKey("calculatesubtotal") == "Yes") { 
     89                m_calculatesubtotal = true; 
     90        } else if (m_settingsdb->GetKey("calculatesubtotal") == "No") { 
     91                m_calculatesubtotal = false; 
     92        } else { 
     93                m_settingsdb->SetKey("calculatesubtotal", "Yes"); 
     94                m_calculatesubtotal = true; 
     95        } 
    8896 
    8997        // END Database initialization 
     
    145153        wxSizer *lowersection = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Lower Section") ), wxVERTICAL); 
    146154         
    147         wxFlexGridSizer* uppergrid = new wxFlexGridSizer(9, 2, 0, 0); 
    148         wxFlexGridSizer* lowergrid = new wxFlexGridSizer(9, 2, 0, 0); 
     155        wxFlexGridSizer* uppergrid = new wxFlexGridSizer(2, 0, 10); 
     156        wxFlexGridSizer* lowergrid = new wxFlexGridSizer(2, 0, 10); 
    149157 
    150158         
     
    343351        } 
    344352 
     353        //recalculate the subtotals 
     354        CalculateSubTotal(); 
     355 
    345356        (GetMenuBar()->FindItem(ID_UNDO))->Enable(false); 
    346357        //cancel the counting for the choice that was canceled 
     
    371382 
    372383        data.animate = (m_settingsdb->GetKey("animate")=="Yes")?true:false; 
     384        data.subtotal = (m_settingsdb->GetKey("calculatesubtotal")=="Yes")?true:false; 
    373385         
    374386        dialog->SetData(data); 
     
    391403                        m_settingsdb->SetKey("animate","No"); 
    392404                        m_animate = false; 
     405                } 
     406                if (data.subtotal){ 
     407                        m_settingsdb->SetKey("calculatesubtotal","Yes"); 
     408                        m_calculatesubtotal = true; 
     409                         
     410                } else { 
     411                        m_settingsdb->SetKey("calculatesubtotal","No"); 
     412                        m_calculatesubtotal = false; 
    393413                } 
    394414 
     
    757777        ResetRolls(); 
    758778 
     779        CalculateSubTotal(); 
     780 
    759781        //and disable the button 
    760782        FindWindow(id)->Enable(false); 
     
    762784        EnableUndo(id); 
    763785        EndofGame(); 
     786} 
     787 
     788void MainFrame::CalculateSubTotal() 
     789{ 
     790        if (!m_calculatesubtotal) 
     791                return; 
     792        long upperscore = 0; 
     793        long lowerscore = 0; 
     794        wxString tempstr; 
     795        long temp; 
     796 
     797 
     798        for (int i = ID_ACESTEXT; i<=ID_SIXESTEXT; i++){ 
     799                tempstr = ((wxTextCtrl*) FindWindow(i)) -> GetValue(); 
     800                tempstr.ToLong(&temp,10); 
     801                upperscore +=temp; 
     802        } 
     803         
     804        tempstr.Printf(wxT("%i"),upperscore); 
     805        ((wxTextCtrl*) FindWindow(ID_UPPERSECTIONTOTAL)) -> SetValue(tempstr); 
     806 
     807        for (int i = ID_THREEOFAKINDTEXT; i<=ID_YAHTZEEBONUSTEXT; i++) { 
     808                tempstr = ((wxTextCtrl*) FindWindow(i)) -> GetValue(); 
     809                tempstr.ToLong(&temp,10); 
     810                lowerscore +=temp; 
     811        } 
     812         
     813        tempstr.Printf(wxT("%i"),lowerscore); 
     814        ((wxTextCtrl*) FindWindow(ID_LOWERTOTAL)) -> SetValue(tempstr); 
    764815} 
    765816 
  • trunk/OpenYahtzee/src/MainFrame.h

    r57 r58  
    7474        inline void EnableUndo(int id); 
    7575        void PostScore(int id); 
     76        void CalculateSubTotal(); 
    7677        void LaunchBrowser (wxString link); 
    7778 
     
    9394 
    9495        bool m_animate; //sets whether to animate the dice. 
     96        bool m_calculatesubtotal; //sets whether to calculate the subtotal after every score or not 
    9597 
    9698}; 
  • trunk/OpenYahtzee/src/SettingsDialog.cpp

    r51 r58  
    3838        checkbox_reset = new wxCheckBox(this, ID_RESETHIGHSCORE, wxT("Reset high score table")); 
    3939        animate_checkbox = new wxCheckBox(this, ID_ANIMATECHECKBOX, wxT("Animate dice")); 
     40        subtotal_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Calculate sub-total score for the upper and lower sections")); 
     41 
    4042 
    4143        connect_event_table(); 
     
    5658        wxBoxSizer* highscoresizer = new wxBoxSizer(wxHORIZONTAL); 
    5759 
    58         highscoresizer->Add(label_1, 0, wxALL|wxADJUST_MINSIZE, 5); 
    59         highscoresizer->Add(spin_ctrl, 0, wxALL|wxADJUST_MINSIZE, 5); 
     60        highscoresizer->Add(label_1, 0, wxALL, 5); 
     61        highscoresizer->Add(spin_ctrl, 0, wxALL, 5); 
    6062        top_sizer->Add(highscoresizer, 0, 0, 0); 
    6163        top_sizer->Add(checkbox_reset, 0,wxALL, 5); 
    6264 
    6365        top_sizer->Add(animate_checkbox,0,wxALL,5); 
     66        top_sizer->Add(subtotal_checkbox,0,wxALL,5); 
    6467 
    6568        top_sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 1, wxBOTTOM, 10); 
     
    8992        spin_ctrl->SetValue(data.highscoresize); 
    9093        animate_checkbox->SetValue(data.animate); 
     94        subtotal_checkbox->SetValue(data.subtotal); 
    9195} 
    9296 
     
    97101        data.reset = checkbox_reset->GetValue(); 
    98102        data.animate = animate_checkbox->GetValue(); 
     103        data.subtotal = subtotal_checkbox->GetValue(); 
    99104        return data; 
    100105} 
  • trunk/OpenYahtzee/src/SettingsDialog.h

    r51 r58  
    3838        bool reset; 
    3939        bool animate; 
     40        bool subtotal; 
    4041}; 
    4142 
     
    6667         
    6768        wxCheckBox* animate_checkbox; 
     69        wxCheckBox* subtotal_checkbox; 
    6870         
    6971}; 
Note: See TracChangeset for help on using the changeset viewer.