1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#include "main.h"
19#include "automagic_settings.h"
20#include "settings.h"
21#include "gui.h"
22
23BEGIN_EVENT_TABLE(AutomagicSettingsDialog, wxDialog)
24 EVT_BUTTON(wxID_OK, AutomagicSettingsDialog::OnClickOK)
25 EVT_BUTTON(wxID_CANCEL, AutomagicSettingsDialog::OnClickCancel)
26 EVT_CHECKBOX(wxID_ANY, AutomagicSettingsDialog::OnAutomagicCheck)
27 EVT_CLOSE(AutomagicSettingsDialog::OnClose)
28END_EVENT_TABLE()
29
30AutomagicSettingsDialog::AutomagicSettingsDialog(wxWindow* parent) :
31 wxDialog(parent, wxID_ANY, "Automagic Settings", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
32{
33 // Create main sizer
34 wxBoxSizer* main_sizer = newd wxBoxSizer(wxVERTICAL);
35
36 // Create a static box for the settings
37 wxStaticBoxSizer* settings_sizer = newd wxStaticBoxSizer(wxVERTICAL, this, "Border Settings");
38
39 // Create checkboxes
40 automagic_enabled_checkbox = newd wxCheckBox(this, wxID_ANY, "Enable Automagic");
41 automagic_enabled_checkbox->SetValue(g_settings.getBoolean(Config::USE_AUTOMAGIC));
42 automagic_enabled_checkbox->SetToolTip("Automatically apply borders and wall connections when editing");
43 settings_sizer->Add(automagic_enabled_checkbox, 0, wxALL, 5);
44
45 same_ground_type_checkbox = newd wxCheckBox(this, wxID_ANY, "Same Ground Type Border");
46 same_ground_type_checkbox->SetValue(g_settings.getBoolean(Config::SAME_GROUND_TYPE_BORDER));
47 same_ground_type_checkbox->SetToolTip("Preserve existing borders and only apply borders for the current ground type");
48 same_ground_type_checkbox->Enable(automagic_enabled_checkbox->GetValue());
49 settings_sizer->Add(same_ground_type_checkbox, 0, wxALL, 5);
50
51 walls_repel_borders_checkbox = newd wxCheckBox(this, wxID_ANY, "Walls Repel Borders");
52 walls_repel_borders_checkbox->SetValue(g_settings.getBoolean(Config::WALLS_REPEL_BORDERS));
53 walls_repel_borders_checkbox->SetToolTip("When enabled, walls will block border generation, preventing borders from crossing through walls");
54 walls_repel_borders_checkbox->Enable(automagic_enabled_checkbox->GetValue());
55 settings_sizer->Add(walls_repel_borders_checkbox, 0, wxALL, 5);
56
57 layer_carpets_checkbox = newd wxCheckBox(this, wxID_ANY, "Layer Carpets");
58 layer_carpets_checkbox->SetValue(g_settings.getBoolean(Config::LAYER_CARPETS));
59 layer_carpets_checkbox->SetToolTip("When enabled, carpet brushes will be placed on top of existing carpets instead of replacing them");
60 layer_carpets_checkbox->Enable(automagic_enabled_checkbox->GetValue());
61 settings_sizer->Add(layer_carpets_checkbox, 0, wxALL, 5);
62
63 borderize_delete_checkbox = newd wxCheckBox(this, wxID_ANY, "Borderize on Delete");
64 borderize_delete_checkbox->SetValue(g_settings.getBoolean(Config::BORDERIZE_DELETE));
65 borderize_delete_checkbox->SetToolTip("When enabled, deleting items will trigger automatic bordering of surrounding tiles");
66 borderize_delete_checkbox->Enable(automagic_enabled_checkbox->GetValue());
67 settings_sizer->Add(borderize_delete_checkbox, 0, wxALL, 5);
68
69 // Create custom border controls
70 wxBoxSizer* custom_border_sizer = newd wxBoxSizer(wxHORIZONTAL);
71
72 custom_border_checkbox = newd wxCheckBox(this, wxID_ANY, "Use Custom Border");
73 custom_border_checkbox->SetValue(g_settings.getBoolean(Config::CUSTOM_BORDER_ENABLED));
74 custom_border_checkbox->SetToolTip("Override automatic border selection with a specific border ID");
75 custom_border_checkbox->Enable(automagic_enabled_checkbox->GetValue());
76 custom_border_sizer->Add(custom_border_checkbox, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
77
78 custom_border_id_label = newd wxStaticText(this, wxID_ANY, "Border ID:");
79 custom_border_id_label->Enable(custom_border_checkbox->GetValue() && automagic_enabled_checkbox->GetValue());
80 custom_border_sizer->Add(custom_border_id_label, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
81
82 custom_border_id_field = newd wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(80, -1));
83 custom_border_id_field->SetRange(1, 65535);
84 custom_border_id_field->SetValue(g_settings.getInteger(Config::CUSTOM_BORDER_ID) > 0 ?
85 g_settings.getInteger(Config::CUSTOM_BORDER_ID) : 1);
86 custom_border_id_field->Enable(custom_border_checkbox->GetValue() && automagic_enabled_checkbox->GetValue());
87 custom_border_id_field->SetToolTip("The ID of the border to use when drawing any tile");
88 custom_border_sizer->Add(custom_border_id_field, 0, wxALIGN_CENTER_VERTICAL);
89
90 settings_sizer->Add(custom_border_sizer, 0, wxALL, 5);
91
92 // Add description text
93 wxStaticText* description = newd wxStaticText(this, wxID_ANY,
94 "When 'Same Ground Type Border' is enabled, the editor will:\n"
95 "- Preserve existing borders on tiles\n"
96 "- Only apply borders for the current ground type\n"
97 "- Respect Z-axis positioning of existing borders\n"
98 "- Allow multiple border layering\n\n"
99 "When 'Walls Repel Borders' is enabled, the editor will:\n"
100 "- Prevent borders from crossing through walls\n"
101 "- Treat walls as barriers for border generation\n"
102 "- Preserve the structure of buildings and houses\n\n"
103 "When 'Layer Carpets' is enabled, the editor will:\n"
104 "- Place new carpets on top of existing carpets\n"
105 "- Allow creating multi-layered carpet designs\n\n"
106 "When 'Use Custom Border' is enabled, the editor will:\n"
107 "- Override automatic border selection with the specified border ID\n"
108 "- Apply the same border pattern around any tile you draw\n"
109 "- Ignore terrain type border transitions");
110 settings_sizer->Add(description, 0, wxALL, 5);
111
112 main_sizer->Add(settings_sizer, 0, wxEXPAND | wxALL, 10);
113
114 // Create buttons
115 buttons_sizer = newd wxStdDialogButtonSizer();
116 ok_button = newd wxButton(this, wxID_OK, "OK");
117 cancel_button = newd wxButton(this, wxID_CANCEL, "Cancel");
118
119 buttons_sizer->AddButton(ok_button);
120 buttons_sizer->AddButton(cancel_button);
121 buttons_sizer->Realize();
122
123 main_sizer->Add(buttons_sizer, 0, wxALIGN_CENTER | wxALL, 10);
124
125 // Set sizer and fit
126 SetSizer(main_sizer);
127 Fit();
128 Centre();
129}
130
131AutomagicSettingsDialog::~AutomagicSettingsDialog() {
132 // Nothing to clean up
133}
134
135bool AutomagicSettingsDialog::IsAutomagicEnabled() const {
136 return automagic_enabled_checkbox->GetValue();
137}
138
139bool AutomagicSettingsDialog::IsSameGroundTypeBorderEnabled() const {
140 return same_ground_type_checkbox->GetValue();
141}
142
143bool AutomagicSettingsDialog::IsWallsRepelBordersEnabled() const {
144 return walls_repel_borders_checkbox->GetValue();
145}
146
147bool AutomagicSettingsDialog::IsLayerCarpetsEnabled() const {
148 return layer_carpets_checkbox->GetValue();
149}
150
151bool AutomagicSettingsDialog::IsBorderizeDeleteEnabled() const {
152 return borderize_delete_checkbox->GetValue();
153}
154
155bool AutomagicSettingsDialog::IsCustomBorderEnabled() const {
156 return custom_border_checkbox->GetValue();
157}
158
159int AutomagicSettingsDialog::GetCustomBorderId() const {
160 return custom_border_id_field->GetValue();
161}
162
163void AutomagicSettingsDialog::OnClickOK(wxCommandEvent& event) {
164 // Save settings
165 g_settings.setInteger(Config::USE_AUTOMAGIC, IsAutomagicEnabled() ? 1 : 0);
166 g_settings.setInteger(Config::BORDER_IS_GROUND, IsAutomagicEnabled() ? 1 : 0);
167 g_settings.setInteger(Config::SAME_GROUND_TYPE_BORDER, IsSameGroundTypeBorderEnabled() ? 1 : 0);
168 g_settings.setInteger(Config::WALLS_REPEL_BORDERS, IsWallsRepelBordersEnabled() ? 1 : 0);
169 g_settings.setInteger(Config::LAYER_CARPETS, IsLayerCarpetsEnabled() ? 1 : 0);
170 g_settings.setInteger(Config::BORDERIZE_DELETE, IsBorderizeDeleteEnabled() ? 1 : 0);
171
172 // Save custom border settings
173 g_settings.setInteger(Config::CUSTOM_BORDER_ENABLED, IsCustomBorderEnabled() ? 1 : 0);
174 g_settings.setInteger(Config::CUSTOM_BORDER_ID, GetCustomBorderId());
175
176 // Update status text
177 if (IsAutomagicEnabled()) {
178 g_gui.SetStatusText("Automagic enabled.");
179 } else {
180 g_gui.SetStatusText("Automagic disabled.");
181 }
182
183 EndModal(wxID_OK);
184}
185
186void AutomagicSettingsDialog::OnClickCancel(wxCommandEvent& event) {
187 // Don't save settings
188 EndModal(wxID_CANCEL);
189}
190
191void AutomagicSettingsDialog::OnAutomagicCheck(wxCommandEvent& event) {
192 // Get the checkbox that triggered the event
193 wxCheckBox* checkbox = dynamic_cast<wxCheckBox*>(event.GetEventObject());
194
195 // Update all checkbox states based on automagic checkbox
196 bool automagic_enabled = automagic_enabled_checkbox->GetValue();
197
198 // If this is the automagic checkbox, update all dependent checkboxes
199 if (checkbox == automagic_enabled_checkbox) {
200 same_ground_type_checkbox->Enable(automagic_enabled);
201 walls_repel_borders_checkbox->Enable(automagic_enabled);
202 layer_carpets_checkbox->Enable(automagic_enabled);
203 borderize_delete_checkbox->Enable(automagic_enabled);
204 custom_border_checkbox->Enable(automagic_enabled);
205 }
206
207 // Always update the custom border fields based on both checkboxes
208 bool custom_border_enabled = custom_border_checkbox->GetValue() && automagic_enabled;
209 custom_border_id_label->Enable(custom_border_enabled);
210 custom_border_id_field->Enable(custom_border_enabled);
211}
212
213void AutomagicSettingsDialog::OnClose(wxCloseEvent& event) {
214 // Same as cancel
215 EndModal(wxID_CANCEL);
216}