-
Notifications
You must be signed in to change notification settings - Fork 224
/
palette_creature.cpp
300 lines (256 loc) · 9.3 KB
/
palette_creature.cpp
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "settings.h"
#include "brush.h"
#include "gui.h"
#include "palette_creature.h"
#include "creature_brush.h"
#include "spawn_brush.h"
#include "materials.h"
// ============================================================================
// Creature palette
BEGIN_EVENT_TABLE(CreaturePalettePanel, PalettePanel)
EVT_CHOICE(PALETTE_CREATURE_TILESET_CHOICE, CreaturePalettePanel::OnTilesetChange)
EVT_LISTBOX(PALETTE_CREATURE_LISTBOX, CreaturePalettePanel::OnListBoxChange)
EVT_TOGGLEBUTTON(PALETTE_CREATURE_BRUSH_BUTTON, CreaturePalettePanel::OnClickCreatureBrushButton)
EVT_TOGGLEBUTTON(PALETTE_SPAWN_BRUSH_BUTTON, CreaturePalettePanel::OnClickSpawnBrushButton)
EVT_SPINCTRL(PALETTE_CREATURE_SPAWN_TIME, CreaturePalettePanel::OnChangeSpawnTime)
EVT_SPINCTRL(PALETTE_CREATURE_SPAWN_SIZE, CreaturePalettePanel::OnChangeSpawnSize)
END_EVENT_TABLE()
CreaturePalettePanel::CreaturePalettePanel(wxWindow* parent, wxWindowID id) :
PalettePanel(parent, id),
handling_event(false)
{
wxSizer* topsizer = newd wxBoxSizer(wxVERTICAL);
wxSizer* sidesizer = newd wxStaticBoxSizer(wxVERTICAL, this, "Creatures");
tileset_choice = newd wxChoice(this, PALETTE_CREATURE_TILESET_CHOICE, wxDefaultPosition, wxDefaultSize, (int)0, (const wxString*)nullptr);
sidesizer->Add(tileset_choice, 0, wxEXPAND);
creature_list = newd SortableListBox(this, PALETTE_CREATURE_LISTBOX);
sidesizer->Add(creature_list, 1, wxEXPAND);
topsizer->Add(sidesizer, 1, wxEXPAND);
// Brush selection
sidesizer = newd wxStaticBoxSizer(newd wxStaticBox(this, wxID_ANY, "Brushes", wxDefaultPosition, wxSize(150, 200)), wxVERTICAL);
//sidesizer->Add(180, 1, wxEXPAND);
wxFlexGridSizer* grid = newd wxFlexGridSizer(3, 10, 10);
grid->AddGrowableCol(1);
grid->Add(newd wxStaticText(this, wxID_ANY, "Spawntime"));
creature_spawntime_spin = newd wxSpinCtrl(this, PALETTE_CREATURE_SPAWN_TIME, i2ws(g_settings.getInteger(Config::DEFAULT_SPAWNTIME)), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS, 0, 3600, g_settings.getInteger(Config::DEFAULT_SPAWNTIME));
grid->Add(creature_spawntime_spin, 0, wxEXPAND);
creature_brush_button = newd wxToggleButton(this, PALETTE_CREATURE_BRUSH_BUTTON, "Place Creature");
grid->Add(creature_brush_button, 0, wxEXPAND);
grid->Add(newd wxStaticText(this, wxID_ANY, "Spawn size"));
spawn_size_spin = newd wxSpinCtrl(this, PALETTE_CREATURE_SPAWN_SIZE, i2ws(5), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS, 1, g_settings.getInteger(Config::MAX_SPAWN_RADIUS), g_settings.getInteger(Config::CURRENT_SPAWN_RADIUS));
grid->Add(spawn_size_spin, 0, wxEXPAND);
spawn_brush_button = newd wxToggleButton(this, PALETTE_SPAWN_BRUSH_BUTTON, "Place Spawn");
grid->Add(spawn_brush_button, 0, wxEXPAND);
sidesizer->Add(grid, 0, wxEXPAND);
topsizer->Add(sidesizer, 0, wxEXPAND);
SetSizerAndFit(topsizer);
OnUpdate();
}
CreaturePalettePanel::~CreaturePalettePanel()
{
////
}
PaletteType CreaturePalettePanel::GetType() const
{
return TILESET_CREATURE;
}
void CreaturePalettePanel::SelectFirstBrush()
{
SelectCreatureBrush();
}
Brush* CreaturePalettePanel::GetSelectedBrush() const
{
if(creature_brush_button->GetValue()) {
if(creature_list->GetCount() == 0) {
return nullptr;
}
Brush* brush = reinterpret_cast<Brush*>(creature_list->GetClientData(creature_list->GetSelection()));
if(brush && brush->isCreature()) {
g_gui.SetSpawnTime(creature_spawntime_spin->GetValue());
return brush;
}
} else if(spawn_brush_button->GetValue()) {
g_settings.setInteger(Config::CURRENT_SPAWN_RADIUS, spawn_size_spin->GetValue());
g_settings.setInteger(Config::DEFAULT_SPAWNTIME, creature_spawntime_spin->GetValue());
return g_gui.spawn_brush;
}
return nullptr;
}
bool CreaturePalettePanel::SelectBrush(const Brush* whatbrush)
{
if(!whatbrush)
return false;
if(whatbrush->isCreature()) {
int current_index = tileset_choice->GetSelection();
if(current_index != wxNOT_FOUND) {
const TilesetCategory* tsc = reinterpret_cast<const TilesetCategory*>(tileset_choice->GetClientData(current_index));
// Select first house
for(BrushVector::const_iterator iter = tsc->brushlist.begin(); iter != tsc->brushlist.end(); ++iter) {
if(*iter == whatbrush) {
SelectCreature(whatbrush->getName());
return true;
}
}
}
// Not in the current display, search the hidden one's
for(size_t i = 0; i < tileset_choice->GetCount(); ++i) {
if(current_index != (int)i) {
const TilesetCategory* tsc = reinterpret_cast<const TilesetCategory*>(tileset_choice->GetClientData(i));
for(BrushVector::const_iterator iter = tsc->brushlist.begin();
iter != tsc->brushlist.end();
++iter)
{
if(*iter == whatbrush) {
SelectTileset(i);
SelectCreature(whatbrush->getName());
return true;
}
}
}
}
} else if(whatbrush->isSpawn()) {
SelectSpawnBrush();
return true;
}
return false;
}
int CreaturePalettePanel::GetSelectedBrushSize() const
{
return spawn_size_spin->GetValue();
}
void CreaturePalettePanel::OnUpdate()
{
tileset_choice->Clear();
g_materials.createOtherTileset();
for(TilesetContainer::const_iterator iter = g_materials.tilesets.begin(); iter != g_materials.tilesets.end(); ++iter) {
const TilesetCategory* tsc = iter->second->getCategory(TILESET_CREATURE);
if(tsc && tsc->size() > 0) {
tileset_choice->Append(wxstr(iter->second->name), const_cast<TilesetCategory*>(tsc));
} else if(iter->second->name == "NPCs" || iter->second->name == "Others") {
Tileset* ts = const_cast<Tileset*>(iter->second);
TilesetCategory* rtsc = ts->getCategory(TILESET_CREATURE);
tileset_choice->Append(wxstr(ts->name), rtsc);
}
}
SelectTileset(0);
}
void CreaturePalettePanel::OnUpdateBrushSize(BrushShape shape, int size)
{
return spawn_size_spin->SetValue(size);
}
void CreaturePalettePanel::OnSwitchIn()
{
g_gui.ActivatePalette(GetParentPalette());
g_gui.SetBrushSize(spawn_size_spin->GetValue());
}
void CreaturePalettePanel::SelectTileset(size_t index)
{
ASSERT(tileset_choice->GetCount() >= index);
creature_list->Clear();
if(tileset_choice->GetCount() == 0) {
// No tilesets :(
creature_brush_button->Enable(false);
} else {
const TilesetCategory* tsc = reinterpret_cast<const TilesetCategory*>(tileset_choice->GetClientData(index));
// Select first house
for(BrushVector::const_iterator iter = tsc->brushlist.begin();
iter != tsc->brushlist.end();
++iter)
{
creature_list->Append(wxstr((*iter)->getName()), *iter);
}
creature_list->Sort();
SelectCreature(0);
tileset_choice->SetSelection(index);
}
}
void CreaturePalettePanel::SelectCreature(size_t index)
{
// Save the old g_settings
ASSERT(creature_list->GetCount() >= index);
if(creature_list->GetCount() > 0) {
creature_list->SetSelection(index);
}
SelectCreatureBrush();
}
void CreaturePalettePanel::SelectCreature(std::string name)
{
if(creature_list->GetCount() > 0) {
if(!creature_list->SetStringSelection(wxstr(name))) {
creature_list->SetSelection(0);
}
}
SelectCreatureBrush();
}
void CreaturePalettePanel::SelectCreatureBrush()
{
if(creature_list->GetCount() > 0) {
creature_brush_button->Enable(true);
creature_brush_button->SetValue(true);
spawn_brush_button->SetValue(false);
} else {
creature_brush_button->Enable(false);
SelectSpawnBrush();
}
}
void CreaturePalettePanel::SelectSpawnBrush()
{
//g_gui.house_exit_brush->setHouse(house);
creature_brush_button->SetValue(false);
spawn_brush_button->SetValue(true);
}
void CreaturePalettePanel::OnTilesetChange(wxCommandEvent& event)
{
SelectTileset(event.GetSelection());
g_gui.ActivatePalette(GetParentPalette());
g_gui.SelectBrush();
}
void CreaturePalettePanel::OnListBoxChange(wxCommandEvent& event)
{
SelectCreature(event.GetSelection());
g_gui.ActivatePalette(GetParentPalette());
g_gui.SelectBrush();
}
void CreaturePalettePanel::OnClickCreatureBrushButton(wxCommandEvent& event)
{
SelectCreatureBrush();
g_gui.ActivatePalette(GetParentPalette());
g_gui.SelectBrush();
}
void CreaturePalettePanel::OnClickSpawnBrushButton(wxCommandEvent& event)
{
SelectSpawnBrush();
g_gui.ActivatePalette(GetParentPalette());
g_gui.SelectBrush();
}
void CreaturePalettePanel::OnChangeSpawnTime(wxSpinEvent& event)
{
g_gui.ActivatePalette(GetParentPalette());
g_gui.SetSpawnTime(event.GetPosition());
}
void CreaturePalettePanel::OnChangeSpawnSize(wxSpinEvent& event)
{
if(!handling_event) {
handling_event = true;
g_gui.ActivatePalette(GetParentPalette());
g_gui.SetBrushSize(event.GetPosition());
handling_event = false;
}
}