This repository was archived by the owner on Jun 21, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathpropertiesdialog.cpp
More file actions
238 lines (209 loc) · 12.5 KB
/
Copy pathpropertiesdialog.cpp
File metadata and controls
238 lines (209 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/////////////////////////////////////////////////////////////////////////////
// Name: propertiesdialog.cpp
// Description: ...
// Author: Alexey Orlov (https://github.com/m110h)
// Last modification: 18/08/2020
// Licence: MIT licence
/////////////////////////////////////////////////////////////////////////////
#include "propertiesdialog.h"
#include "properties_singleton.h"
wxDECLARE_EVENT(PROPERTIES_DIALOG_OK_EVENT, wxCommandEvent);
PrefsPageGeneralPanel::PrefsPageGeneralPanel(wxWindow *parent) : wxPanel(parent)
{
sortsOfCellCtrl = new wxSpinCtrl(this, wxID_ANY);
cellEnergyCtrl = new wxSpinCtrl(this, wxID_ANY);
maxDamageCtrl = new wxSpinCtrl(this, wxID_ANY);
//behaviorGenesCtrl = new wxSpinCtrl(this, wxID_ANY);
minEnergyForDivisionCtrl = new wxSpinCtrl(this, wxID_ANY);
maxEnergyForDivisionCtrl = new wxSpinCtrl(this, wxID_ANY);
plantsCtrl = new wxSpinCtrl(this, wxID_ANY);
plantEnergyCtrl = new wxSpinCtrl(this, wxID_ANY);
meatEnergyCtrl = new wxSpinCtrl(this, wxID_ANY);
maxAgeCtrl = new wxSpinCtrl(this, wxID_ANY);
stepsPerSecondCtrl = new wxSpinCtrl(this, wxID_ANY);
plantsPerStepCtrl = new wxSpinCtrl(this, wxID_ANY);
worldWidthCtrl = new wxSpinCtrl(this, wxID_ANY);
worldHeightCtrl = new wxSpinCtrl(this, wxID_ANY);
sortsOfCellCtrl->SetRange(properties.GetMin(wxString("sortsOfCell")),properties.GetMax(wxString("sortsOfCell")));
cellEnergyCtrl->SetRange(properties.GetMin(wxString("cellEnergy")),properties.GetMax(wxString("cellEnergy")));
maxDamageCtrl->SetRange(properties.GetMin(wxString("maxDamage")),properties.GetMax(wxString("maxDamage")));
//behaviorGenesCtrl->SetRange(properties.GetMin(wxString("behaviorGenes")),properties.GetMax(wxString("behaviorGenes")));
minEnergyForDivisionCtrl->SetRange(properties.GetMin(wxString("minEnergyForDivision")),properties.GetMax(wxString("minEnergyForDivision")));
maxEnergyForDivisionCtrl->SetRange(properties.GetMin(wxString("maxEnergyForDivision")),properties.GetMax(wxString("maxEnergyForDivision")));
plantsCtrl->SetRange(properties.GetMin(wxString("plants")),properties.GetMax(wxString("plants")));
plantEnergyCtrl->SetRange(properties.GetMin(wxString("plantEnergy")),properties.GetMax(wxString("plantEnergy")));
meatEnergyCtrl->SetRange(properties.GetMin(wxString("meatEnergy")),properties.GetMax(wxString("meatEnergy")));
maxAgeCtrl->SetRange(properties.GetMin(wxString("maxAge")),properties.GetMax(wxString("maxAge")));
stepsPerSecondCtrl->SetRange(properties.GetMin(wxString("stepsPerSecond")),properties.GetMax(wxString("stepsPerSecond")));
plantsPerStepCtrl->SetRange(properties.GetMin(wxString("plantsPerStep")),properties.GetMax(wxString("plantsPerStep")));
worldWidthCtrl->SetRange(properties.GetMin(wxString("worldWidth")),properties.GetMax(wxString("worldWidth")));
worldHeightCtrl->SetRange(properties.GetMin(wxString("worldHeight")),properties.GetMax(wxString("worldHeight")));
sortsOfCellCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedSortsOfCell, this);
cellEnergyCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedCellEnergy, this);
maxDamageCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedMaxDamage, this);
//behaviorGenesCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedBehaviorGenes, this);
minEnergyForDivisionCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedMinEnergyForDivision, this);
maxEnergyForDivisionCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedMaxEnergyForDivision, this);
plantsCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedPlants, this);
plantEnergyCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedPlantEnergy, this);
meatEnergyCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedMeatEnergy, this);
maxAgeCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedMaxAge, this);
stepsPerSecondCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedStepsPerSecond, this);
plantsPerStepCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedPlantsPerStep, this);
worldWidthCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedWorldWidth, this);
worldHeightCtrl->Bind(wxEVT_SPINCTRL, &PrefsPageGeneralPanel::ChangedWorldHeight, this);
wxGridSizer* propertiesSizer = new wxGridSizer(14, 2, 0, 0);
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Initial quantity of sorts")), wxSizerFlags().Border());
propertiesSizer->Add(sortsOfCellCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Initial cell's energy")), wxSizerFlags().Border());
propertiesSizer->Add(cellEnergyCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Max damage")), wxSizerFlags().Border());
propertiesSizer->Add(maxDamageCtrl, wxSizerFlags().Border().Expand());
//propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Quantity of behavior genes")), wxSizerFlags().Border());
//propertiesSizer->Add(behaviorGenesCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Min energy for division")), wxSizerFlags().Border());
propertiesSizer->Add(minEnergyForDivisionCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Max energy for division")), wxSizerFlags().Border());
propertiesSizer->Add(maxEnergyForDivisionCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Initial quantity of plants")), wxSizerFlags().Border());
propertiesSizer->Add(plantsCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Plant's energy")), wxSizerFlags().Border());
propertiesSizer->Add(plantEnergyCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Meat's energy")), wxSizerFlags().Border());
propertiesSizer->Add(meatEnergyCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Max cell's age")), wxSizerFlags().Border());
propertiesSizer->Add(maxAgeCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Steps per second")), wxSizerFlags().Border());
propertiesSizer->Add(stepsPerSecondCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Plants per step")), wxSizerFlags().Border());
propertiesSizer->Add(plantsPerStepCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Width of cell's world")), wxSizerFlags().Border());
propertiesSizer->Add(worldWidthCtrl, wxSizerFlags().Border().Expand());
propertiesSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Height of cell's world")), wxSizerFlags().Border());
propertiesSizer->Add(worldHeightCtrl, wxSizerFlags().Border().Expand());
SetSizerAndFit(propertiesSizer);
//wxMessageBox(wxString::Format("id: %d", parent->GetId()), wxT("Info"), wxOK | wxICON_INFORMATION, this);
}
bool PrefsPageGeneralPanel::TransferDataToWindow()
{
properties = PropertiesSingleton::getInstance().GetProperties();
sortsOfCellCtrl->SetValue(properties.GetValue(wxString("sortsOfCell")));
cellEnergyCtrl->SetValue(properties.GetValue(wxString("cellEnergy")));
maxDamageCtrl->SetValue(properties.GetValue(wxString("maxDamage")));
//behaviorGenesCtrl->SetValue(properties.GetValue(wxString("behaviorGenes")));
minEnergyForDivisionCtrl->SetValue(properties.GetValue(wxString("minEnergyForDivision")));
maxEnergyForDivisionCtrl->SetValue(properties.GetValue(wxString("maxEnergyForDivision")));
plantsCtrl->SetValue(properties.GetValue(wxString("plants")));
plantEnergyCtrl->SetValue(properties.GetValue(wxString("plantEnergy")));
meatEnergyCtrl->SetValue(properties.GetValue(wxString("meatEnergy")));
maxAgeCtrl->SetValue(properties.GetValue(wxString("maxAge")));
stepsPerSecondCtrl->SetValue(properties.GetValue(wxString("stepsPerSecond")));
plantsPerStepCtrl->SetValue(properties.GetValue(wxString("plantsPerStep")));
worldWidthCtrl->SetValue(properties.GetValue(wxString("worldWidth")));
worldHeightCtrl->SetValue(properties.GetValue(wxString("worldHeight")));
return true;
}
void PrefsPageGeneralPanel::NotifyMainFrame()
{
wxCommandEvent event(PROPERTIES_DIALOG_OK_EVENT);
event.SetEventObject(this);
//event.SetString("Some String Data");
// MyFrame <- wxPreferencesEditor <- PrefsPageGeneral:wxPanel (we are here)
wxPostEvent(GetParent()->GetParent()->GetParent(), event);
}
// Called on platforms with modal preferences dialog to save and apply
// the changes.
bool PrefsPageGeneralPanel::TransferDataFromWindow()
{
PropertiesSingleton::getInstance().UpdateProperties(properties);
NotifyMainFrame();
if (showAdvice)
{
showAdvice = false;
wxMessageBox(wxT("Rebuild the world (use New) to take an effect"), wxT("Information"), wxOK | wxICON_INFORMATION, this);
}
return true;
}
void PrefsPageGeneralPanel::UpdateSettingsIfNecessary()
{
// On some platforms (OS X, GNOME), changes to preferences are applied
// immediately rather than after the OK or Apply button is pressed, so
// we need to take them into account as soon as they happen. On others
// (MSW), we need to wait until the changes are accepted by the user by
// pressing the "OK" button. To reuse the same code for both cases, we
// always update properties object under all platforms, but only
// update the real application settings if necessary here.
if ( wxPreferencesEditor::ShouldApplyChangesImmediately() )
{
PropertiesSingleton::getInstance().UpdateProperties(properties);
NotifyMainFrame();
}
}
void PrefsPageGeneralPanel::ChangedSortsOfCell(wxSpinEvent& e) {
properties.SetValue(wxString("sortsOfCell"), e.GetValue());
UpdateSettingsIfNecessary();
showAdvice = true;
}
void PrefsPageGeneralPanel::ChangedCellEnergy(wxSpinEvent& e) {
properties.SetValue(wxString("cellEnergy"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedMaxDamage(wxSpinEvent& e) {
properties.SetValue(wxString("maxDamage"), e.GetValue());
UpdateSettingsIfNecessary();
}
/*
void PrefsPageGeneralPanel::ChangedBehaviorGenes(wxSpinEvent& e) {
properties.SetValue(wxString("behaviorGenes"), e.GetValue());
UpdateSettingsIfNecessary();
}
*/
void PrefsPageGeneralPanel::ChangedMinEnergyForDivision(wxSpinEvent& e) {
properties.SetValue(wxString("minEnergyForDivision"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedMaxEnergyForDivision(wxSpinEvent& e) {
properties.SetValue(wxString("maxEnergyForDivision"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedPlants(wxSpinEvent& e) {
properties.SetValue(wxString("plants"), e.GetValue());
UpdateSettingsIfNecessary();
showAdvice = true;
}
void PrefsPageGeneralPanel::ChangedPlantEnergy(wxSpinEvent& e) {
properties.SetValue(wxString("plantEnergy"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedMeatEnergy(wxSpinEvent& e) {
properties.SetValue(wxString("meatEnergy"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedMaxAge(wxSpinEvent& e) {
properties.SetValue(wxString("maxAge"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedStepsPerSecond(wxSpinEvent& e) {
properties.SetValue(wxString("stepsPerSecond"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedPlantsPerStep(wxSpinEvent& e) {
properties.SetValue(wxString("plantsPerStep"), e.GetValue());
UpdateSettingsIfNecessary();
}
void PrefsPageGeneralPanel::ChangedWorldWidth(wxSpinEvent& e) {
properties.SetValue(wxString("worldWidth"), e.GetValue());
UpdateSettingsIfNecessary();
showAdvice = true;
}
void PrefsPageGeneralPanel::ChangedWorldHeight(wxSpinEvent& e) {
properties.SetValue(wxString("worldHeight"), e.GetValue());
UpdateSettingsIfNecessary();
showAdvice = true;
}
//
PrefsPageGeneral::PrefsPageGeneral(): wxStockPreferencesPage(Kind_General) {}
wxWindow* PrefsPageGeneral::CreateWindow(wxWindow *parent)
{
return new PrefsPageGeneralPanel(parent);
}