source: trunk/OpenYahtzee/src/SettingsDialog.cpp @ 127

Last change on this file since 127 was 127, checked in by guyru, 6 years ago

score hints settings dialog entry

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1// $Header$
2/***************************************************************************
3 *   Copyright (C) 2006-2007 by Guy Rutenberg   *
4 *   guy@Guy_Computer   *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 *   This program is distributed in the hope that it will be useful,       *
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14 *   GNU General Public License for more details.                          *
15 *                                                                         *
16 *   You should have received a copy of the GNU General Public License     *
17 *   along with this program; if not, write to the                         *
18 *   Free Software Foundation, Inc.,                                       *
19 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20 ***************************************************************************/
21
22#include "SettingsDialog.h"
23#include "MainFrame.h"
24
25#include "Icon.h"
26
27SettingsDialog::SettingsDialog(wxWindow* parent, int id):
28    wxDialog(parent, wxID_ANY, wxT("Settings Dialog"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
29{
30
31        SetIcon(wxIcon(ICON));
32
33        label_1 = new wxStaticText(this, -1, wxT("High score table size:"));
34        spin_ctrl = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS,0,1024,20);
35        checkbox_reset = new wxCheckBox(this, ID_RESETHIGHSCORE, wxT("Reset high score table"));
36        animate_checkbox = new wxCheckBox(this, ID_ANIMATECHECKBOX, wxT("Animate dice"));
37        subtotal_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Calculate "
38                "sub-total score for the upper and lower sections"));
39        score_hints_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Display "
40                "score hints."));
41        horizontal_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Enable horizontal layout for user interface."));
42
43        ConnectEventTable();
44        DoLayout();
45}
46
47
48void SettingsDialog::ConnectEventTable()
49{
50        Connect(ID_RESETHIGHSCORE,wxEVT_COMMAND_CHECKBOX_CLICKED,wxCommandEventHandler(SettingsDialog::OnResetHighScore));
51}
52
53
54void SettingsDialog::DoLayout()
55{
56        wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL);
57        wxBoxSizer* highscoresizer = new wxBoxSizer(wxHORIZONTAL);
58
59        highscoresizer->Add(label_1, 0, wxALL, 5);
60        highscoresizer->Add(spin_ctrl, 0, wxALL, 5);
61        top_sizer->Add(highscoresizer, 0, 0, 0);
62        top_sizer->Add(checkbox_reset, 0,wxALL, 5);
63
64        top_sizer->Add(animate_checkbox,0,wxALL,5);
65        top_sizer->Add(subtotal_checkbox,0,wxALL,5);
66        top_sizer->Add(score_hints_checkbox,0,wxALL,5);
67        top_sizer->Add(horizontal_checkbox,0,wxALL,5);
68
69        top_sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 1, wxBOTTOM, 10);
70        SetAutoLayout(true);
71        SetSizer(top_sizer);
72        top_sizer->Fit(this);
73        top_sizer->SetSizeHints(this);
74        Layout();
75}
76
77
78void SettingsDialog::OnResetHighScore(wxCommandEvent& event)
79{
80        if(!checkbox_reset->GetValue()){
81                checkbox_reset->SetValue(0);
82                return;
83        }
84       
85        int answer = wxMessageBox(wxT("Are you sure you want to reset the high "
86                "score table? After reseting the high score table, you won't be"
87                " able to restore it!\n\nThe new high score table size will be "
88                "as specified in this dialog."), wxT("High-score table reset"),
89                wxYES_NO|wxICON_EXCLAMATION,this);
90
91        if(answer==wxNO)
92                checkbox_reset->SetValue(0);
93}
94
95void SettingsDialog::SetData(SettingsDialogData data)
96{
97        spin_ctrl->SetValue(data.highscoresize);
98        animate_checkbox->SetValue(data.animate);
99        subtotal_checkbox->SetValue(data.subtotal);
100        score_hints_checkbox->SetValue(data.score_hints);
101        horizontal_checkbox->SetValue(data.horizontal);
102}
103
104SettingsDialogData SettingsDialog::GetData()
105{
106        SettingsDialogData data;
107        data.highscoresize = spin_ctrl->GetValue();
108        data.reset = checkbox_reset->GetValue();
109        data.animate = animate_checkbox->GetValue();
110        data.subtotal = subtotal_checkbox->GetValue();
111        data.score_hints = score_hints_checkbox->GetValue();
112        data.horizontal = horizontal_checkbox->GetValue();
113        return data;
114}
Note: See TracBrowser for help on using the repository browser.